diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c0c1f5..dae82e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 0.5.0 + +The sidekick and the later parts of four specials. + +- **The sidekick.** A critter with 10 hours out with you has a 1 in 10 chance each day of becoming your sidekick, rolled once a day while it's out. It comes out on its own when you join, change worlds or it's rested, doesn't count toward your posse, and stays when you click it in the Bunkhouse menu, use the menu's bell or ring the dinnerbell. One per player. Admins can set or clear it with `/mobsquad sidekick `. +- **Time together** is counted per critter and saved as an eighth field on its line in the player's file; older files read as 0. +- **From level 25:** the chicken lays speedy eggs, the bee's sting makes hostile mobs glow, the fox pounces for a double first hit, and the skeleton shares arrows when you carry a bow or crossbow. Each gets stronger at the later milestones; see the README. +- Not yet: travelling with your sidekick through a gate (that waits for the Waystation hook) and the small model of your sidekick above the Bunkhouse. + ## 0.4.0 La Ménagerie and the Critterbook. diff --git a/README.md b/README.md index 64e99fd..1dd11fc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Coax mobs into critters for Paper: they follow you, fight only hostile mobs, and live safely in a shared Bunkhouse. No client mods. Gotta coax em all... Pokemob! -**Status:** 0.4.0. La Ménagerie, the journal, with Critterbook numbers. Passed with bots on throwaway Paper 26.1.2 and 26.2 servers (147 checks each). On 26.3 the bots can't use blocks, so the Bunkhouse menu and everything sent out from it didn't run there (65 checks ran). Bots can't crouch where the server sees it, so the creeper and fox puzzles were tested with a test-only stand-in for crouching; real crouching is untested. The skeleton's longer range and the enderman's teleport out of trouble have no bot test yet. Nothing has been seen in a real game client yet, including how the journal looks. +**Status:** 0.5.0. The sidekick, and the later parts of four specials. Passed with bots on throwaway Paper 26.1.2 and 26.2 servers (164 checks each). On 26.3 the bots can't use blocks, so the Bunkhouse menu and everything sent out from it didn't run there (75 checks ran). Bots can't crouch where the server sees it, so the creeper and fox puzzles were tested with a test-only stand-in for crouching; real crouching is untested. The daily sidekick roll is covered by unit tests only, since it needs 10 hours out. Nothing has been seen in a real game client yet. ## What it does @@ -10,16 +10,17 @@ Coax mobs into critters for Paper: they follow you, fight only hostile mobs, and - **Fighting.** Critters fight hostile mobs only: the ones after you or your critters, and other hostile mobs near you that aren't neutral or named. They never hurt players, pets, villagers or farm animals. The skeleton shoots and the allay never fights. - **Levels.** Each critter has its own level, 1 to 100. It earns experience for every hostile mob it helps beat (the mob's max health, so 20 for a zombie) and 2 for every minute out with you. Health, attack and speed grow a little each level and slow near the top: at level 100 a critter has four times its health, three times its attack and a fifth more speed. The Bunkhouse menu shows each critter's level, how far it is from the next and its special. - **Specials.** Every critter has one, and it grows at levels 25, 50, 75 and 100. - - Chicken: you fall slowly while it's out. + - Chicken: you fall slowly while it's out. From level 25 it lays a speedy egg at your feet every 5 minutes (a minute sooner at each later milestone); right-click it for Speed II for 10 seconds, Speed III from level 75. - Axolotl: water breathing and regeneration while you're within 6 blocks of it. It goes after drowned and guardians first, and plays dead and heals when it's badly hurt. - - Bee: crops near it grow faster, one crop a second. - - Fox: fetches items you drop or leave behind (drops from blocks you break and mobs you beat), after they've lain 5 seconds. It never touches anyone else's. + - Bee: crops near it grow faster, one crop a second. From level 25 its sting makes a hostile mob glow, so you can see it through walls. + - Fox: fetches items you drop or leave behind (drops from blocks you break and mobs you beat), after they've lain 5 seconds. It never touches anyone else's. From level 25 it pounces on a hostile mob that isn't after it, for a double first hit. - Allay: right-click it holding an ore, a raw ore or a gem, and it flies to the nearest matching ore within 8 blocks of you. - Creeper: a blast that hurts only the hostile mobs around its target and breaks nothing. It never goes off with a player within 6 blocks. - Enderman: right-click it, then swing at a block within 8 blocks, and it fetches it for you. Only blocks an enderman can carry, and only where you could dig yourself, so claims say no. When it's badly hurt, it teleports to you. - - Skeleton: covering fire from 15 blocks, reaching further and shooting faster at each milestone. + - Skeleton: covering fire from 15 blocks, reaching further and shooting faster at each milestone. From level 25 it shares two arrows every 2 minutes while you carry a bow or crossbow. - Iron golem: takes a quarter of any hostile mob's hit on you within 8 blocks, and throws the mobs it hits back. - **La Ménagerie.** Your journal, with a page for each critter: its Critterbook number, a line about it, how to coax it and its special. A page opens the first time you're within 10 blocks of that critter and can see it, or when you get one. `/mobsquad journal` or the book in the Bunkhouse menu opens it. Critterbook numbers follow the order each mob first appeared in Minecraft Java Edition, so the creeper is No. 1 and the allay No. 75. Every mob in the game has a number already, and the numbers never change. +- **The sidekick.** A critter that has spent 10 hours out with you has a 1 in 10 chance each day of becoming your sidekick. It goes everywhere with you: it comes out when you join, after a world change and after a rest, and the Bunkhouse menu, its bell and the dinnerbell leave it be. It doesn't count toward your posse. One per player. - **Vittles.** Right-click them to perk up a tuckered-out critter on the spot. Craft two from bread, a carrot and sweet berries. - **Bunkhouses.** An admin marks a vault block as a Bunkhouse. Anyone who right-clicks it sees only their own critters. Click one to send it out or call it back. Critters never exist as items, so they can't be dropped, traded or duplicated. - **Following.** A critter out with you walks after you and steps beside you if it's left more than 24 blocks behind. @@ -48,6 +49,7 @@ Settings are in `plugins/MobSquad/config.yml`: worlds where MobSquad is off, the | `/mobsquad vittles [amount]` | admins | Gives vittles. | | `/mobsquad xp ` | admins | Sets a player's Wranglin' experience. | | `/mobsquad level ` | admins | Sets every critter of that kind a player has to a level. | +| `/mobsquad sidekick ` | admins | Makes a player's critter of that kind their sidekick, or clears it. | | `/mobsquad reload` | admins | Rereads config.yml. | `/ms` works too. Permissions: `mobsquad.use` (everyone) and `mobsquad.admin` (ops). diff --git a/build.gradle.kts b/build.gradle.kts index db300c1..15815e1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { } group = "com.extantape" -version = "0.4.0" +version = "0.5.0" java { toolchain.languageVersion.set(JavaLanguageVersion.of(25)) diff --git a/docs/decisions.md b/docs/decisions.md index ea8d35a..472a556 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -29,3 +29,8 @@ Dated decisions for this repo, newest last. - 2026-11-15: Critterbook numbers come from the first Java Edition entry in each mob's History section on the Minecraft Wiki, including experimental snapshots (the camel, sniffer, breeze, bogged and creaking first appeared behind experiments). A texture added before the mob doesn't count (piglin, silverfish). Mobs from the same version are ordered by first snapshot, then alphabetically by entity id. The 88 numbered are the mobs the wiki lists as current in Java Edition, without unused, removed, joke, Education or upcoming ones. The list is `src/main/resources/critterbook.txt`; numbers never change, and new mobs get the next numbers. - 2026-11-15: a page opens when you're within 10 blocks of a living launch critter (anyone's, or wild) and have a clear line of sight, checked every 2 seconds, or when a critter is added to your Bunkhouse. Owning a critter always opens its page. - 2026-11-15, written by the lead, for the owner's say: the eight page lines other than the creeper's, which is the owner's own (brief, "Voice"). +- 2026-11-15, owner (ops D204), in the chief's chat: "Keep all eight" for the page lines, so they stand as written; and "Sidekick + later specials" as the next release. +- 2026-11-15: the sidekick's "long time" is 10 hours out together and its "small daily chance" is 1 in 10, rolled once per calendar day (server time) per player, only while an eligible critter is out, so a day without one doesn't use the roll up. The longest-serving eligible critter out is the one rolled for. +- 2026-11-15: until the Waystation hook exists, a sidekick never goes into the Bunkhouse on a player's say. It still leaves the world like any critter when its owner leaves, the server stops, or it's tuckered out, and comes back on its own when it can. A disabled world or a locked tier keeps it home. +- 2026-11-15: the brief's "later" parts of four specials unlock at level 25, the first milestone, and grow at the next ones: speedy eggs (first one 30 seconds after going out, then every 5 minutes, a minute sooner per later milestone; Speed II, III from level 75), the glowing sting (10 seconds, 5 more per later milestone), the pounce (a leap of up to 6 blocks at a mob not targeting the fox, double damage on the first hit, every 8 seconds, a second sooner per later milestone) and shared arrows (two every 2 minutes while carrying a bow or crossbow, one more and 20 seconds sooner per later milestone). +- 2026-11-15: speedy eggs can be picked up only by the chicken's owner and are used, never thrown, so they can't hatch chickens. diff --git a/docs/test-audit.md b/docs/test-audit.md index a714c51..273c1dd 100644 --- a/docs/test-audit.md +++ b/docs/test-audit.md @@ -2,6 +2,14 @@ Kept by this repo's owning session, per `~/Code/CLAUDE.md`, "Test self-audits". Newest first. +## 2026-11-15: 0.5.0 + +- Promises added: README "The sidekick" and the level 25 additions to four specials, CHANGELOG 0.5.0, the sidekick and later-specials decisions. +- Covered by unit tests (ModelTest): 10 hours needed; a day with nobody eligible doesn't use the roll; the roll is small and once a day; one sidekick per player, only from critters out; sidekick, roll day and minutes round-trip; a sidekick not in the list is dropped; minutes out add up with their experience. +- Covered by bots (164 checks on 26.1.2 and 26.2, 75 on 26.3): an admin sets and clears a sidekick; it comes out on its own and is saved; it doesn't count toward the posse; the menu, its bell and the dinnerbell leave it out (the menu parts on 26.1.2 and 26.2); it goes when its owner leaves and comes back when they return; tuckered out, it rests and comes back once rested; cleared, the dinnerbell calls it home. From level 25: the bee's sting makes a husk glow; the fox's first hit is double; the chicken lays a speedy egg at your feet, and using it gives speed without throwing it; the skeleton shares two arrows when you carry a bow. +- Gaps skipped: the real daily roll (needs 10 hours out; the logic is unit tested and the server only feeds it the day and the critters out); milestone growth of the four additions (plain numbers from the stage, same path as covered); a sidekick following through a world change (the same keep-beside-you loop as rejoining, which is covered). +- Gaps for later: travelling with a sidekick through a gate, when the Waystation hook lands. + ## 2026-11-15: 0.4.0 - Promises added: README "La Ménagerie", the journal command, CHANGELOG 0.4.0, the Critterbook decisions. diff --git a/src/main/java/com/extantape/mobsquad/MobSquadPlugin.java b/src/main/java/com/extantape/mobsquad/MobSquadPlugin.java index 07d819b..7b19bac 100644 --- a/src/main/java/com/extantape/mobsquad/MobSquadPlugin.java +++ b/src/main/java/com/extantape/mobsquad/MobSquadPlugin.java @@ -119,6 +119,13 @@ public void onLoad(EntitiesLoadEvent e) { for (Species s : Species.values()) if (s.id().startsWith(b.getRemainingLowerCase())) b.suggest(s.id()); return b.buildFuture(); }).then(Commands.argument("level", IntegerArgumentType.integer(1, Growth.MAX)).executes(this::level))))) + .then(Commands.literal("sidekick").requires(src -> src.getSender().hasPermission("mobsquad.admin")) + .then(Commands.argument("player", ArgumentTypes.player()) + .then(Commands.argument("critter", StringArgumentType.word()).suggests((c, b) -> { + b.suggest("none"); + for (Species s : Species.values()) if (s.id().startsWith(b.getRemainingLowerCase())) b.suggest(s.id()); + return b.buildFuture(); + }).executes(this::sidekick)))) .then(Commands.literal("reload").requires(src -> src.getSender().hasPermission("mobsquad.admin")).executes(this::reload)) .build(), "Your critters, the dinnerbell, and admin tools for Bunkhouses.", List.of("ms"))); @@ -283,6 +290,31 @@ private int level(CommandContext c) throws CommandSyntaxExce return n == 0 ? 0 : Command.SINGLE_SUCCESS; } + /** Makes a player's first critter of a kind their sidekick, or clears it with "none". */ + private int sidekick(CommandContext c) throws CommandSyntaxException { + Player p = c.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(c.getSource()).getFirst(); + Wrangler w = squads.get(p); + if (w == null) { + say(c, p.getName() + "'s Bunkhouse list can't be read right now; see the server log.", NamedTextColor.RED); + return 0; + } + String kind = c.getArgument("critter", String.class); + if (kind.equals("none")) { + squads.setSidekick(p, null); + say(c, "[MobSquad] " + p.getName() + " has no sidekick now.", NamedTextColor.GREEN); + return Command.SINGLE_SUCCESS; + } + Species s = Species.byId(kind); + Critter pick = s == null ? null : w.critters.stream().filter(cr -> cr.species() == s).findFirst().orElse(null); + if (pick == null) { + say(c, p.getName() + " has no " + kind.replace('_', ' ') + ".", NamedTextColor.YELLOW); + return 0; + } + squads.setSidekick(p, pick); + say(c, "[MobSquad] " + pick.name() + " is " + p.getName() + "'s sidekick now.", NamedTextColor.GREEN); + return Command.SINGLE_SUCCESS; + } + private int reload(CommandContext c) { reloadConfig(); squads.settings(Settings.read(getConfig(), getLogger())); diff --git a/src/main/java/com/extantape/mobsquad/Squads.java b/src/main/java/com/extantape/mobsquad/Squads.java index 3e4206f..4e6a14a 100644 --- a/src/main/java/com/extantape/mobsquad/Squads.java +++ b/src/main/java/com/extantape/mobsquad/Squads.java @@ -33,6 +33,7 @@ public Squads(Store store, Logger log, Settings settings) { public void posse(Posse posse) { this.posse = posse; + posse.sidekicks(id -> online.values().stream().anyMatch(w -> id.equals(w.sidekick))); } public void settings(Settings settings) { @@ -115,12 +116,66 @@ public void critterXp(Posse.Out o, long xp) { posse.update(n); if (n.level() == c.level()) return; save(w); + leveled(p, c, n); + } + + private void leveled(Player p, Critter c, Critter n) { p.sendMessage(Component.text(n.name() + " is now level " + n.level() + ".", NamedTextColor.GOLD)); if (com.extantape.mobsquad.model.Growth.stage(n.level()) > com.extantape.mobsquad.model.Growth.stage(c.level())) p.sendMessage(Component.text("Its special grows stronger: " + n.species().special, NamedTextColor.LIGHT_PURPLE)); p.playSound(p.getLocation(), org.bukkit.Sound.ENTITY_PLAYER_LEVELUP, 0.6f, 1.4f); } + public boolean isSidekick(UUID owner, UUID critter) { + Wrangler w = online.get(owner); + return w != null && critter.equals(w.sidekick); + } + + /** A minute out: time together and walking experience, then today's sidekick roll. */ + public void minuteOut(Player p, java.util.List out) { + Wrangler w = get(p); + if (w == null || out.isEmpty()) return; + java.util.List ids = new java.util.ArrayList<>(); + for (Posse.Out o : out) { + Critter c = w.find(o.critter().id()); + if (c == null) continue; + ids.add(c.id()); + Critter n = c.minuteOut(com.extantape.mobsquad.model.Growth.WALK_XP); + w.replace(n); + posse.update(n); + if (n.level() > c.level()) leveled(p, c, n); + } + long day = java.time.LocalDate.now().toEpochDay(); + Critter chosen = com.extantape.mobsquad.model.Sidekicks.roll(w, ids, day, java.util.concurrent.ThreadLocalRandom.current()::nextDouble); + if (chosen != null) { + p.sendMessage(Component.text(chosen.name() + " has decided you're its favorite person. It's your sidekick now: it goes everywhere with you and doesn't count toward your posse.", NamedTextColor.GOLD)); + p.playSound(p.getLocation(), org.bukkit.Sound.UI_TOAST_CHALLENGE_COMPLETE, 0.7f, 1.2f); + } + save(w); + } + + /** Makes someone a player's sidekick, or nobody (admins). */ + public void setSidekick(Player p, Critter c) { + Wrangler w = get(p); + if (w == null) return; + w.sidekick = c == null ? null : c.id(); + save(w); + } + + /** Puts each online player's sidekick beside them whenever it can be: after joining, a world change, a rest. */ + public void keepSidekicks() { + long now = System.currentTimeMillis(); + for (Player p : Bukkit.getOnlinePlayers()) { + Wrangler w = online.get(p.getUniqueId()); + if (w == null || w.sidekick == null || posse.isOut(w.sidekick)) continue; + Critter c = w.find(w.sidekick); + if (c == null || c.resting(now) || p.isDead() || p.getGameMode() == org.bukkit.GameMode.SPECTATOR) continue; + if (!settings.enabledIn(p.getWorld().getName()) || !p.hasPermission("mobsquad.use") || !Levels.unlocked(c.species().tier, wranglinLevel(p))) continue; + posse.send(p, c); + p.sendActionBar(Component.text(c.name() + " is at your side.", NamedTextColor.GOLD)); + } + } + /** Out of health: back to the Bunkhouse to rest a few real minutes. */ public void tucker(Posse.Out o) { posse.back(o.critter().id()); diff --git a/src/main/java/com/extantape/mobsquad/model/Critter.java b/src/main/java/com/extantape/mobsquad/model/Critter.java index d6df8d4..d575b91 100644 --- a/src/main/java/com/extantape/mobsquad/model/Critter.java +++ b/src/main/java/com/extantape/mobsquad/model/Critter.java @@ -5,10 +5,11 @@ /** * A bonded mob. It lives in its owner's Bunkhouse list; out in the world it's a mob that's never saved with the world. * {@code tuckeredUntil} is when it's rested enough to go out again, in epoch milliseconds (0 when it's ready). + * {@code minutes} is how long it has spent out with its owner, which counts toward becoming their sidekick. */ -public record Critter(UUID id, Species species, String name, int level, long xp, long tuckeredUntil) { +public record Critter(UUID id, Species species, String name, int level, long xp, long tuckeredUntil, long minutes) { public static Critter fresh(Species species) { - return new Critter(UUID.randomUUID(), species, species.title(), 1, 0, 0); + return new Critter(UUID.randomUUID(), species, species.title(), 1, 0, 0, 0); } public boolean resting(long now) { @@ -17,10 +18,15 @@ public boolean resting(long now) { /** With new experience; the level follows from it. */ public Critter withXp(long newXp) { - return new Critter(id, species, name, Growth.level(newXp), newXp, tuckeredUntil); + return new Critter(id, species, name, Growth.level(newXp), newXp, tuckeredUntil, minutes); } public Critter tuckered(long until) { - return new Critter(id, species, name, level, xp, until); + return new Critter(id, species, name, level, xp, until, minutes); + } + + /** One more minute out, with the experience that comes with it. */ + public Critter minuteOut(long walkXp) { + return new Critter(id, species, name, level >= Growth.MAX ? level : Growth.level(xp + walkXp), level >= Growth.MAX ? xp : xp + walkXp, tuckeredUntil, minutes + 1); } } diff --git a/src/main/java/com/extantape/mobsquad/model/Sidekicks.java b/src/main/java/com/extantape/mobsquad/model/Sidekicks.java new file mode 100644 index 0000000..d863cb7 --- /dev/null +++ b/src/main/java/com/extantape/mobsquad/model/Sidekicks.java @@ -0,0 +1,33 @@ +package com.extantape.mobsquad.model; + +import java.util.Collection; +import java.util.UUID; +import java.util.function.DoubleSupplier; + +/** + * The sidekick (brief, "The posse"): a critter you've spent a long time with has a small daily chance of becoming your + * sidekick, one per player. "A long time" is {@link #MINUTES} minutes out together, ten hours; the chance is + * {@link #CHANCE}, rolled at most once a day per player, while an eligible critter is out with them. + */ +public final class Sidekicks { + public static final long MINUTES = 600; + public static final double CHANCE = 0.10; + + private Sidekicks() {} + + /** + * Today's roll for a player, given which critters are out with them. Returns the new sidekick, or null. Marks the + * day as rolled only when there was a critter to roll for, so a day without one doesn't use the chance up. + */ + public static Critter roll(Wrangler w, Collection out, long day, DoubleSupplier random) { + if (w.sidekick != null || w.sidekickRoll >= day) return null; + Critter best = null; + for (Critter c : w.critters) + if (out.contains(c.id()) && c.minutes() >= MINUTES && (best == null || c.minutes() > best.minutes())) best = c; + if (best == null) return null; + w.sidekickRoll = day; + if (random.getAsDouble() >= CHANCE) return null; + w.sidekick = best.id(); + return best; + } +} diff --git a/src/main/java/com/extantape/mobsquad/model/Wrangler.java b/src/main/java/com/extantape/mobsquad/model/Wrangler.java index 0f6a441..d857ff5 100644 --- a/src/main/java/com/extantape/mobsquad/model/Wrangler.java +++ b/src/main/java/com/extantape/mobsquad/model/Wrangler.java @@ -10,6 +10,9 @@ public final class Wrangler { public long wranglinXp; public final List critters = new ArrayList<>(); /** The La Ménagerie pages this player has opened. */ + /** This player's sidekick, if they have one, and the last day (epoch day) they rolled for one. */ + public UUID sidekick; + public long sidekickRoll; public final java.util.Set pages = java.util.EnumSet.noneOf(Species.class); public Wrangler(UUID player) { diff --git a/src/main/java/com/extantape/mobsquad/store/Store.java b/src/main/java/com/extantape/mobsquad/store/Store.java index 4891b17..1e0cdb2 100644 --- a/src/main/java/com/extantape/mobsquad/store/Store.java +++ b/src/main/java/com/extantape/mobsquad/store/Store.java @@ -19,10 +19,12 @@ * wranglin 150 * critter 6b1f... chicken 1 0 0 Clucky * page chicken + * sidekick 6b1f... + * sidekick-roll 20407 * * * A critter line is its id, species, level, experience, when it's rested (epoch milliseconds, 0 when ready) and its - * name, URL-encoded. A page line is a La Ménagerie page the player has opened; owning a critter opens its page too. Written to a temporary file and moved into place, so a crash leaves the old file or the new one. + * name, URL-encoded, then its minutes out with its owner (missing in files from before 0.5.0, read as 0). A page line is a La Ménagerie page the player has opened; owning a critter opens its page too. Written to a temporary file and moved into place, so a crash leaves the old file or the new one. * Lines that can't be read are skipped and counted, never guessed at. */ public final class Store { @@ -54,8 +56,10 @@ public Loaded load(UUID player) throws IOException { Species s = Species.byId(p[2]); if (s == null || p.length < 7) throw new IllegalArgumentException(); w.critters.add(new Critter(UUID.fromString(p[1]), s, URLDecoder.decode(p[6], StandardCharsets.UTF_8), - Integer.parseInt(p[3]), Long.parseLong(p[4]), Long.parseLong(p[5]))); + Integer.parseInt(p[3]), Long.parseLong(p[4]), Long.parseLong(p[5]), p.length > 7 ? Long.parseLong(p[7]) : 0)); } + case "sidekick" -> w.sidekick = UUID.fromString(p[1]); + case "sidekick-roll" -> w.sidekickRoll = Long.parseLong(p[1]); case "page" -> { Species s = Species.byId(p[1]); if (s == null) throw new IllegalArgumentException(); @@ -67,7 +71,8 @@ public Loaded load(UUID player) throws IOException { skipped++; } } - for (Critter c : w.critters) w.pages.add(c.species()); // files from before 0.4.0 have no page lines + for (Critter c : w.critters) w.pages.add(c.species()); + if (w.sidekick != null && w.find(w.sidekick) == null) w.sidekick = null; // never a sidekick that isn't in the list // files from before 0.4.0 have no page lines return new Loaded(w, skipped); } @@ -78,7 +83,9 @@ public void save(Wrangler w) throws IOException { for (Critter c : w.critters) sb.append("critter ").append(c.id()).append(' ').append(c.species().id()).append(' ').append(c.level()).append(' ') .append(c.xp()).append(' ').append(c.tuckeredUntil()).append(' ') - .append(URLEncoder.encode(c.name(), StandardCharsets.UTF_8)).append('\n'); + .append(URLEncoder.encode(c.name(), StandardCharsets.UTF_8)).append(' ').append(c.minutes()).append('\n'); + if (w.sidekick != null) sb.append("sidekick ").append(w.sidekick).append('\n'); + if (w.sidekickRoll > 0) sb.append("sidekick-roll ").append(w.sidekickRoll).append('\n'); for (Species s : w.pages) sb.append("page ").append(s.id()).append('\n'); Path tmp = dir.resolve(w.player + ".txt.tmp"); Files.writeString(tmp, sb.toString(), StandardCharsets.UTF_8); diff --git a/src/main/java/com/extantape/mobsquad/world/BunkhouseMenu.java b/src/main/java/com/extantape/mobsquad/world/BunkhouseMenu.java index 61645fc..647c313 100644 --- a/src/main/java/com/extantape/mobsquad/world/BunkhouseMenu.java +++ b/src/main/java/com/extantape/mobsquad/world/BunkhouseMenu.java @@ -100,7 +100,7 @@ private void draw(Holder h, Wrangler w, Player p) { h.slots.clear(); long now = System.currentTimeMillis(); int level = squads.wranglinLevel(p); - int out = squads.posse().of(p.getUniqueId()).size(); + int out = squads.posse().counted(p.getUniqueId()); for (int i = 0; i < Math.min(CRITTER_SLOTS, w.critters.size()); i++) { Critter c = w.critters.get(i); h.slots.add(c.id()); @@ -132,9 +132,10 @@ static ItemStack item(Material m, Component name, List lore) { return it; } - private static ItemStack icon(Critter c, boolean out, long now) { + private ItemStack icon(Critter c, boolean out, long now) { Material egg = Material.matchMaterial(c.species().entity + "_SPAWN_EGG"); List lore = new ArrayList<>(); + if (squads.posse().isSidekick(c.id())) lore.add(line("Your sidekick", NamedTextColor.GOLD)); lore.add(line(c.species().title() + ", level " + c.level(), NamedTextColor.GRAY)); if (c.level() < com.extantape.mobsquad.model.Growth.MAX) lore.add(line(String.format(java.util.Locale.US, "%,d experience to level %d", com.extantape.mobsquad.model.Growth.xpFor(c.level() + 1) - c.xp(), c.level() + 1), NamedTextColor.DARK_GRAY)); @@ -171,8 +172,7 @@ public void onClick(InventoryClickEvent event) { return; } if (slot == CALL_BACK_SLOT) { - int n = squads.posse().of(p.getUniqueId()).size(); - squads.posse().backAll(p.getUniqueId()); + int n = squads.posse().recall(p.getUniqueId()); // a sidekick stays p.sendMessage(Component.text(n == 0 ? "Nobody's out with you." : "Everyone's back in the Bunkhouse.", NamedTextColor.GREEN)); } else if (slot < h.slots.size()) { Critter c = w.find(h.slots.get(slot)); @@ -182,6 +182,10 @@ public void onClick(InventoryClickEvent event) { } private void toggle(Player p, Critter c) { + if (squads.posse().isOut(c.id()) && squads.posse().isSidekick(c.id())) { + p.sendMessage(Component.text(c.name() + " won't leave your side. A sidekick only uses the Bunkhouse to travel through a gate.", NamedTextColor.YELLOW)); + return; + } if (squads.posse().isOut(c.id())) { squads.posse().back(c.id()); p.sendMessage(Component.text(c.name() + " is back in the Bunkhouse.", NamedTextColor.GREEN)); @@ -205,7 +209,7 @@ String whyNot(Player p, Critter c) { if (!Levels.unlocked(c.species().tier, level)) return c.name() + " is a " + c.species().tier.title + " critter. It can go out from Wranglin' level " + c.species().tier.level + "."; int max = Levels.posse(level); - if (squads.posse().of(p.getUniqueId()).size() >= max) + if (squads.posse().counted(p.getUniqueId()) >= max) return "You can have " + max + (max == 1 ? " critter" : " critters") + " out at once at Wranglin' level " + level + ". Call one back first."; return null; } diff --git a/src/main/java/com/extantape/mobsquad/world/Dinnerbell.java b/src/main/java/com/extantape/mobsquad/world/Dinnerbell.java index 40346f6..e728b79 100644 --- a/src/main/java/com/extantape/mobsquad/world/Dinnerbell.java +++ b/src/main/java/com/extantape/mobsquad/world/Dinnerbell.java @@ -51,8 +51,7 @@ public void onRing(PlayerInteractEvent event) { if (!is(event.getItem())) return; event.setCancelled(true); Player p = event.getPlayer(); - int n = squads.posse().of(p.getUniqueId()).size(); - squads.posse().backAll(p.getUniqueId()); + int n = squads.posse().recall(p.getUniqueId()); // a sidekick stays p.playSound(p.getLocation(), Sound.BLOCK_BELL_USE, 0.8f, 1.2f); p.sendMessage(Component.text(n == 0 ? "Nobody's out with you." : n == 1 ? "Your critter is headed home." : "All " + n + " critters are headed home.", NamedTextColor.GREEN)); } diff --git a/src/main/java/com/extantape/mobsquad/world/Fights.java b/src/main/java/com/extantape/mobsquad/world/Fights.java index adb8cad..2bf5303 100644 --- a/src/main/java/com/extantape/mobsquad/world/Fights.java +++ b/src/main/java/com/extantape/mobsquad/world/Fights.java @@ -32,7 +32,8 @@ public final class Fights { private final Posse posse; private final Map targets = new HashMap<>(); private final Map lastHit = new HashMap<>(); - private final Map lastBlast = new HashMap<>(); + private final Map lastBlast = new HashMap<>(), lastPounce = new HashMap<>(); + private final Map pounced = new HashMap<>(); static final long PROVOKED_MS = 30_000; private final Map provoked = new HashMap<>(); private final Map provokedOwner = new HashMap<>(); @@ -110,7 +111,16 @@ boolean step(Posse.Out o, Player owner) { double power = s.attack * Growth.attack(level); if (s == Species.CREEPER && m.getLocation().distance(t.getLocation()) <= 3 && blast(o, t, power, stage)) return true; double reach = 1.6 + (m.getWidth() + t.getWidth()) / 2; - if (m.getLocation().distance(t.getLocation()) > reach) { + double gap = m.getLocation().distance(t.getLocation()); + if (s == Species.FOX && stage >= 1 && gap > reach && gap <= 6 && !m.equals(t instanceof Mob tm ? tm.getTarget() : null) && m.isOnGround() + && System.currentTimeMillis() - lastPounce.getOrDefault(id, 0L) >= 8000 - 1000L * (stage - 1)) { + lastPounce.put(id, System.currentTimeMillis()); // from hiding: a leap at a mob that isn't after it, and a double hit + pounced.put(id, Boolean.TRUE); + org.bukkit.util.Vector leap = t.getLocation().toVector().subtract(m.getLocation().toVector()); + m.setVelocity(leap.setY(0).normalize().multiply(Math.min(1.2, gap * 0.22)).setY(0.45)); + return true; + } + if (gap > reach) { m.getPathfinder().moveTo(t, 1.3); } else { long now = System.currentTimeMillis(); @@ -118,7 +128,10 @@ boolean step(Posse.Out o, Player owner) { lastHit.put(id, now); m.lookAt(t); m.swingMainHand(); - t.damage(power, DamageSource.builder(DamageType.MOB_ATTACK).withCausingEntity(m).withDirectEntity(m).build()); + boolean pounce = pounced.remove(id) != null; + t.damage(pounce ? power * 2 : power, DamageSource.builder(DamageType.MOB_ATTACK).withCausingEntity(m).withDirectEntity(m).build()); + if (s == Species.BEE && stage >= 1 && t.isValid()) // a sting that makes it glow + t.addPotionEffect(new org.bukkit.potion.PotionEffect(org.bukkit.potion.PotionEffectType.GLOWING, 20 * (10 + 5 * (stage - 1)), 0)); if (s == Species.IRON_GOLEM && t.isValid()) { // throws it back org.bukkit.util.Vector away = t.getLocation().toVector().subtract(m.getLocation().toVector()).setY(0); if (away.lengthSquared() > 0) away.normalize(); @@ -204,5 +217,7 @@ void forget(UUID critter) { targets.remove(critter); lastHit.remove(critter); lastBlast.remove(critter); + lastPounce.remove(critter); + pounced.remove(critter); } } diff --git a/src/main/java/com/extantape/mobsquad/world/Posse.java b/src/main/java/com/extantape/mobsquad/world/Posse.java index 2db1b5c..bb90494 100644 --- a/src/main/java/com/extantape/mobsquad/world/Posse.java +++ b/src/main/java/com/extantape/mobsquad/world/Posse.java @@ -35,6 +35,7 @@ public final class Posse implements Runnable { private boolean catchingUp; private final Fights fights = new Fights(this); private Specials specials; + private java.util.function.Predicate sidekick = id -> false; /** A critter out with its owner: which one, whose, and the mob standing in for it. */ public record Out(UUID owner, Critter critter, Mob mob) {} @@ -68,6 +69,29 @@ public Fights fights() { return fights; } + /** Tells the posse which critters are sidekicks: they don't count toward the posse and don't answer a recall. */ + public void sidekicks(java.util.function.Predicate isSidekick) { + this.sidekick = isSidekick; + } + + public boolean isSidekick(UUID critter) { + return sidekick.test(critter); + } + + /** The critters out with a player that count toward their posse: everyone but a sidekick. */ + public int counted(UUID owner) { + int n = 0; + for (Out o : of(owner)) if (!sidekick.test(o.critter().id())) n++; + return n; + } + + /** Calls a player's critters home, all but a sidekick. Returns how many went. */ + public int recall(UUID owner) { + int n = 0; + for (Out o : of(owner)) if (!sidekick.test(o.critter().id())) { back(o.critter().id()); n++; } + return n; + } + public void specials(Specials specials) { this.specials = specials; } diff --git a/src/main/java/com/extantape/mobsquad/world/Specials.java b/src/main/java/com/extantape/mobsquad/world/Specials.java index 746941d..2f23e9c 100644 --- a/src/main/java/com/extantape/mobsquad/world/Specials.java +++ b/src/main/java/com/extantape/mobsquad/world/Specials.java @@ -70,7 +70,7 @@ public final class Specials implements Runnable, Listener { private final Plugin plugin; private final Squads squads; - private final NamespacedKey fetchFor, fetched; + private final NamespacedKey fetchFor, fetched, speedy; /** Critters busy with a special right now, and what they're doing. */ private final Map jobs = new HashMap<>(); /** Which critters hit a hostile mob, and when. */ @@ -92,6 +92,7 @@ public Specials(Plugin plugin, Squads squads) { this.squads = squads; this.fetchFor = new NamespacedKey(plugin, "fetch-for"); this.fetched = new NamespacedKey(plugin, "fetched"); + this.speedy = new NamespacedKey(plugin, "speedy"); } private Posse posse() { @@ -126,14 +127,76 @@ public void run() { Player p = Bukkit.getPlayer(o.owner()); if (p == null || !o.mob().isValid()) continue; switch (o.critter().species()) { - case CHICKEN -> p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 50, 0, true, false, true)); + case CHICKEN -> { + p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 50, 0, true, false, true)); + speedyEgg(o, p, now); + } + case SKELETON -> shareArrows(o, p, now); case AXOLOTL -> axolotl(o, p); case BEE -> bee(o); case FOX -> fox(o, p); default -> {} } - if (minute) squads.critterXp(o, Growth.WALK_XP); } + if (minute) for (Player p : Bukkit.getOnlinePlayers()) squads.minuteOut(p, posse().of(p.getUniqueId())); + squads.keepSidekicks(); + } + + /** When a critter's next gift is due (the chicken's egg, the skeleton's arrows), by critter. */ + private final Map nextGift = new HashMap<>(); + /** The first gift comes this long after a critter goes out. */ + static final long FIRST_GIFT_MS = 30_000; + + private boolean giftDue(Posse.Out o, long now, long everyMs) { + Long due = nextGift.get(o.critter().id()); + if (due == null) { nextGift.put(o.critter().id(), now + FIRST_GIFT_MS); return false; } + if (now < due) return false; + nextGift.put(o.critter().id(), now + everyMs); + return true; + } + + /** + * From level 25, the chicken lays a speedy egg every 5 minutes, a minute sooner at each later milestone. Using one + * gives you Speed II for 10 seconds, Speed III from level 75. Only its owner can pick it up. + */ + private void speedyEgg(Posse.Out o, Player p, long now) { + int s = stage(o); + if (s < 1 || !giftDue(o, now, (300 - 60L * (s - 1)) * 1000)) return; + ItemStack egg = new ItemStack(Material.EGG); + egg.editMeta(m -> { + m.customName(Component.text("Speedy egg", NamedTextColor.YELLOW).decoration(net.kyori.adventure.text.format.TextDecoration.ITALIC, false)); + m.lore(List.of(Component.text("Right-click for a burst of speed.", NamedTextColor.GRAY).decoration(net.kyori.adventure.text.format.TextDecoration.ITALIC, false))); + m.getPersistentDataContainer().set(speedy, PersistentDataType.INTEGER, s >= 3 ? 2 : 1); + }); + Item dropped = p.getWorld().dropItem(p.getLocation(), egg); // at your feet, so nobody has to hunt for it + dropped.setOwner(p.getUniqueId()); + o.mob().getWorld().playSound(o.mob().getLocation(), Sound.ENTITY_CHICKEN_EGG, 1f, 1f); + } + + @EventHandler(priority = EventPriority.HIGH) + public void onEgg(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return; + ItemStack hand = event.getItem(); + if (hand == null || hand.getType() != Material.EGG || !hand.hasItemMeta()) return; + Integer amp = hand.getItemMeta().getPersistentDataContainer().get(speedy, PersistentDataType.INTEGER); + if (amp == null) return; + event.setCancelled(true); // eaten for speed, never thrown + Player p = event.getPlayer(); + if (p.getGameMode() != org.bukkit.GameMode.CREATIVE) hand.subtract(); + p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, amp, false, true, true)); + p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 0.6f, 1.6f); + } + + /** + * From level 25, the skeleton shares arrows when you carry a bow or crossbow: two every 2 minutes, one more and 20 + * seconds sooner at each later milestone. + */ + private void shareArrows(Posse.Out o, Player p, long now) { + int s = stage(o); + if (s < 1 || !giftDue(o, now, (120 - 20L * (s - 1)) * 1000)) return; + if (!p.getInventory().contains(Material.BOW) && !p.getInventory().contains(Material.CROSSBOW)) return; + give(p, new ItemStack(Material.ARROW, 1 + s)); + p.sendActionBar(Component.text(o.critter().name() + " shares " + (1 + s) + " arrows.", NamedTextColor.GRAY)); } /** Water breathing and regeneration within 6 blocks, 2 more at each milestone; regeneration II from level 75. */ @@ -447,6 +510,7 @@ private boolean hasFox(Player p) { void forget(UUID critter) { jobs.remove(critter); + nextGift.remove(critter); cooldowns.keySet().removeIf(k -> k.startsWith(critter.toString())); armed.values().removeIf(a -> a.critter.equals(critter)); } diff --git a/src/main/java/com/extantape/mobsquad/world/Vittles.java b/src/main/java/com/extantape/mobsquad/world/Vittles.java index 626138e..475610b 100644 --- a/src/main/java/com/extantape/mobsquad/world/Vittles.java +++ b/src/main/java/com/extantape/mobsquad/world/Vittles.java @@ -92,7 +92,7 @@ public void onUse(PlayerInteractEvent event) { if (p.getGameMode() != GameMode.CREATIVE) hand.subtract(); p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 0.8f, 1.3f); int max = Levels.posse(squads.wranglinLevel(p)); - boolean room = squads.settings().enabledIn(p.getWorld().getName()) && squads.posse().of(p.getUniqueId()).size() < max + boolean room = squads.settings().enabledIn(p.getWorld().getName()) && squads.posse().counted(p.getUniqueId()) < max && Levels.unlocked(ready.species().tier, squads.wranglinLevel(p)); if (room) { Posse.Out o = squads.posse().send(p, ready); diff --git a/src/test/java/com/extantape/mobsquad/ModelTest.java b/src/test/java/com/extantape/mobsquad/ModelTest.java index 06bfed4..914fc80 100644 --- a/src/test/java/com/extantape/mobsquad/ModelTest.java +++ b/src/test/java/com/extantape/mobsquad/ModelTest.java @@ -4,6 +4,7 @@ import com.extantape.mobsquad.model.Critter; import com.extantape.mobsquad.model.Critterbook; +import com.extantape.mobsquad.model.Sidekicks; import com.extantape.mobsquad.model.Growth; import com.extantape.mobsquad.model.Levels; import com.extantape.mobsquad.model.Species; @@ -49,7 +50,7 @@ void aPlayersFileRoundTrips(@TempDir Path dir) throws Exception { UUID p = UUID.randomUUID(); Wrangler w = new Wrangler(p); w.wranglinXp = 150; - w.critters.add(new Critter(UUID.randomUUID(), Species.CHICKEN, "Clucky McCluckface", 3, 42, 0)); + w.critters.add(new Critter(UUID.randomUUID(), Species.CHICKEN, "Clucky McCluckface", 3, 42, 0, 77)); w.critters.add(Critter.fresh(Species.IRON_GOLEM).tuckered(123456789L)); store.save(w); Store.Loaded back = store.load(p); @@ -160,4 +161,70 @@ void anOlderFileOpensPagesForCrittersYouHave(@TempDir Path dir) throws Exception assertEquals(0, l.skipped()); assertEquals(java.util.Set.of(Species.BEE), l.wrangler().pages); } + + private static Critter withMinutes(Species s, long minutes) { + Critter c = Critter.fresh(s); + return new Critter(c.id(), s, c.name(), 1, 0, 0, minutes); + } + + @Test + void aSidekickNeedsTenHoursOutTogether() { + Wrangler w = new Wrangler(UUID.randomUUID()); + Critter young = withMinutes(Species.FOX, Sidekicks.MINUTES - 1); + w.critters.add(young); + assertNull(Sidekicks.roll(w, java.util.List.of(young.id()), 100, () -> 0.0)); + assertEquals(0, w.sidekickRoll, "a day with nobody eligible doesn't use the roll up"); + } + + @Test + void theRollIsSmallAndOnceADay() { + Wrangler w = new Wrangler(UUID.randomUUID()); + Critter old = withMinutes(Species.FOX, Sidekicks.MINUTES); + w.critters.add(old); + assertNull(Sidekicks.roll(w, java.util.List.of(old.id()), 100, () -> Sidekicks.CHANCE)); + assertEquals(100, w.sidekickRoll); + assertNull(Sidekicks.roll(w, java.util.List.of(old.id()), 100, () -> 0.0), "already rolled today"); + assertEquals(old, Sidekicks.roll(w, java.util.List.of(old.id()), 101, () -> 0.0)); + assertEquals(old.id(), w.sidekick); + } + + @Test + void oneSidekickAndOnlyFromCrittersOut() { + Wrangler w = new Wrangler(UUID.randomUUID()); + Critter home = withMinutes(Species.BEE, 5000), out = withMinutes(Species.FOX, 700); + w.critters.add(home); + w.critters.add(out); + assertEquals(out, Sidekicks.roll(w, java.util.List.of(out.id()), 5, () -> 0.0)); + assertNull(Sidekicks.roll(w, java.util.List.of(home.id(), out.id()), 6, () -> 0.0), "one per player"); + } + + @Test + void sidekickAndMinutesRoundTrip(@TempDir Path dir) throws Exception { + Store store = new Store(dir); + UUID p = UUID.randomUUID(); + Wrangler w = new Wrangler(p); + Critter c = withMinutes(Species.SKELETON, 612); + w.critters.add(c); + w.sidekick = c.id(); + w.sidekickRoll = 20407; + store.save(w); + Wrangler back = store.load(p).wrangler(); + assertEquals(612, back.critters.getFirst().minutes()); + assertEquals(c.id(), back.sidekick); + assertEquals(20407, back.sidekickRoll); + } + + @Test + void aSidekickNotInTheListIsDropped(@TempDir Path dir) throws Exception { + UUID p = UUID.randomUUID(); + Files.writeString(dir.resolve(p + ".txt"), "wranglin 0\nsidekick " + UUID.randomUUID() + "\n"); + assertNull(new Store(dir).load(p).wrangler().sidekick); + } + + @Test + void minutesOutAddUpAndEarnExperience() { + Critter c = Critter.fresh(Species.FOX).minuteOut(2).minuteOut(2); + assertEquals(2, c.minutes()); + assertEquals(4, c.xp()); + } } diff --git a/test/suite.mjs b/test/suite.mjs index b157b5d..0b648bc 100644 --- a/test/suite.mjs +++ b/test/suite.mjs @@ -674,6 +674,34 @@ else if (want('specials')) { check('with a player close by it never blasts, only hits one at a time', firstHurt && firstHurt.some(h => h === 20), firstHurt) await s.ask(`tp Neighbor ${X - 20} ${Y} ${Z + 20}`, 300) + // the later parts of four specials, from level 25 + await s.ask('mobsquad give Wrangler skeleton', 250) + for (const k of ['chicken', 'bee', 'fox', 'skeleton']) await s.ask(`mobsquad level Wrangler ${k} 25`, 250) + await sendOnly('bee') + await s.ask(`summon husk ${X + 3} ${Y} ${Z - 3} {Tags:["foe"],PersistenceRequired:1b,NoAI:1b}`, 300) + check('from level 25 the bee\'s sting makes a hostile mob glow', await until(async () => /glowing/.test(await effects('@e[tag=foe,limit=1]')), 15000, 500)) + await sendOnly('fox') + await stand(me, 'Wrangler', X, Z, 0, 20) + await s.ask(`summon husk ${X} ${Y} ${Z - 6} {Tags:["foe"],PersistenceRequired:1b,NoAI:1b,attributes:[{id:"minecraft:armor",base:0}]}`, 200) + const drops = []; let last = 20 + await until(async () => { const h = await health('@e[tag=foe,limit=1]'); if (h === null) return true; if (h < last) { drops.push(+(last - h).toFixed(2)); last = h } return drops.length >= 2 }, 20000, 150) + check('from level 25 the fox pounces for a double first hit', drops.length >= 2 && drops[0] > 1.7 * drops[1], drops.join(', ')) + await sendOnly('chicken') + await s.ask('clear Wrangler', 200) + check('from level 25 the chicken lays a speedy egg at your feet', await until(() => me.inventory.items().some(i => i.name === 'egg'), 45000, 500)) + if (me.inventory.items().some(i => i.name === 'egg')) { + await me.equip(me.inventory.items().find(i => i.name === 'egg'), 'hand') + await s.ask('effect clear Wrangler', 200) + me.activateItem(); await sleep(600) + check('using it gives a burst of speed, and it isn\'t thrown', /speed/.test(await effects('Wrangler')) && await s.count('@e[type=chicken]') === 1 && !me.inventory.items().some(i => i.name === 'egg')) + } + await sendOnly('skeleton') + await s.ask('clear Wrangler', 200) + await s.ask('give Wrangler minecraft:bow', 300) + check('from level 25 the skeleton shares arrows when you carry a bow', await until(() => (me.inventory.items().find(i => i.name === 'arrow')?.count ?? 0) === 2, 45000, 500), + me.inventory.items().map(i => i.name + 'x' + i.count).join(',')) + await s.ask('clear Wrangler', 200) + // the iron golem: experience, levels and its guard await sendOnly('iron_golem') await s.ask(`summon husk ${X + 3} ${Y} ${Z - 3} {Tags:["foe"],PersistenceRequired:1b,NoAI:1b}`, 600) @@ -762,6 +790,59 @@ if (want('journal')) { await quit(scout) } +// ---------- the sidekick ---------- +if (want('sidekick')) { + section('The sidekick') + await config({ 'recovery-minutes': 0 }) + let buddy = await bot('Buddy', { physics: PHYSICS }) + await uuidOf('Buddy') + await s.ask('gamemode creative Buddy', 200) + await stand(buddy, 'Buddy', X - 3, Z, 0, 20) + await s.ask(`kill @e[type=!player,x=${X},y=${Y},z=${Z},distance=..30]`, 300) + await s.ask('kill @e[type=bee]', 200); await s.ask('kill @e[type=chicken]', 200) // wild ones left by the coaxing section (name= matches them too) + for (const k of ['bee', 'chicken']) await s.ask(`mobsquad give Buddy ${k}`, 250) + const near = async (kind) => s.count(`@e[type=${kind},name=${kind === 'bee' ? 'Bee' : 'Chicken'},x=${X - 3},y=${Y},z=${Z},distance=..12]`) // critters carry their name; wild ones from coaxing don't + let out = (await s.ask('mobsquad sidekick Buddy bee', 400)).join(' ') + check('an admin can make a critter someone\'s sidekick', /is Buddy's sidekick now/.test(out), out) + check('the sidekick comes out on its own', await until(async () => await near('bee') === 1, 5000, 300)) + check('it\'s saved', /^sidekick /m.test(file('Buddy')), file('Buddy')) + if (MENU) { + await openBunkhouse(buddy, vault) + const lines = critterLines('Buddy'), slot = k => lines.map(l => l.split(' ')[2] === k).indexOf(true) + let from = buddy.chatLog.length + await buddy.clickWindow(slot('chicken'), 0, 0); await sleep(500) + check('it doesn\'t count toward the posse', await waitSaid(buddy, /is out with you/, 3000, from), buddy.chatLog.slice(from).join(' | ')) + from = buddy.chatLog.length + await buddy.clickWindow(slot('bee'), 0, 0); await sleep(500) + check('it won\'t go back into the Bunkhouse', await waitSaid(buddy, /won't leave your side/, 3000, from) && await near('bee') === 1, buddy.chatLog.slice(from).join(' | ')) + await buddy.clickWindow(53, 0, 0); await sleep(600); await closeMenu(buddy) + check('the call-back bell leaves it out', await near('bee') === 1 && await near('chicken') === 0) + } + buddy.chat('/mobsquad dinnerbell') + await until(() => buddy.inventory.items().some(i => i.name === 'warped_fungus_on_a_stick'), 4000) + const bell = buddy.inventory.items().find(i => i.name === 'warped_fungus_on_a_stick') + if (bell) { + await buddy.equip(bell, 'hand'); buddy.activateItem(); await sleep(600); buddy.deactivateItem() + check('so does the dinnerbell', await near('bee') === 1) + } + await s.ask('kick Buddy', 300); await quit(buddy); await sleep(1000) // a kick, because a 26.3 bot's own disconnect can take a while to land + const gone = (await s.ask('list', 300)).join(' ') + check('it goes when you leave', await until(async () => await s.count('@e[type=bee,name=Bee]') === 0, 6000, 300), gone) + await sleep(61000) // GriefPrevention makes a brand-new player wait a minute before logging in again + buddy = await bot('Buddy', { physics: PHYSICS }) + await stand(buddy, 'Buddy', X - 3, Z, 0, 20) + check('and comes back when you return', await until(async () => await near('bee') === 1, 6000, 300)) + let from = buddy.chatLog.length + await s.ask(`damage @e[type=bee,name=Bee,x=${X - 3},y=${Y},z=${Z},distance=..12,limit=1] 500 minecraft:generic`, 600) + check('tuckered out, it rests', await waitSaid(buddy, /tuckered out/, 4000, from)) + check('and comes back on its own once rested', await until(async () => await near('bee') === 1, 6000, 300)) + out = (await s.ask('mobsquad sidekick Buddy none', 400)).join(' ') + check('an admin can clear it', /has no sidekick now/.test(out), out) + await buddy.equip(buddy.inventory.items().find(i => i.name === 'warped_fungus_on_a_stick'), 'hand'); buddy.activateItem(); await sleep(600); buddy.deactivateItem() + check('then the dinnerbell calls it home like anyone', await until(async () => await near('bee') === 0, 3000, 300)) + await quit(buddy) +} + // ---------- vittles ---------- if (!MENU) skip('vittles') else if (want('vittles')) {