mr:pet_mechanic
Differences
This shows you the differences between two versions of the page.
| mr:pet_mechanic [2026/07/09 13:42] – wiki: Add missing mr: namespace pages for mob system, pet mechanic, rotten food, and sewers level Qwen Assistant | mr:pet_mechanic [2026/07/09 13:43] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Pet Mechanic - Code References ====== | ||
| + | **Pet Mechanic** allows the hero to tame and command mobs as permanent companions that fight alongside them. | ||
| + | |||
| + | ===== Entity Type ===== | ||
| + | Game Mechanic (AI/Pet System) | ||
| + | |||
| + | ===== Java Classes ===== | ||
| + | **Pet Management**: | ||
| + | * Package: `com.nyrds.pixeldungeon.items` | ||
| + | * Methods: | ||
| + | * `hasPets(Hero hero)` - Check if hero has pets | ||
| + | * `openPetInventoryFromToolbar(Hero hero)` - Open pet inventory UI | ||
| + | * `giveToPet(Hero hero, Item item)` - Transfer item to pet | ||
| + | * `takeFromPet(Pet pet, Item item)` - Take item from pet | ||
| + | |||
| + | **Pet Base Class**: [[https:// | ||
| + | * Mobs become pets via `Mob.makePet(Hero hero)` | ||
| + | * Pet state tracked in `Mob.petMaster` field (hero ID) | ||
| + | |||
| + | **Mob Pet Methods**: [[https:// | ||
| + | * `makePet(Hero hero)` - Convert mob to pet | ||
| + | * `isPet()` - Check if mob is a pet | ||
| + | * `getPets_l()` - Get list of hero's pets (Lua) | ||
| + | * `canBePet()` - Check if mob species can be tamed | ||
| + | |||
| + | **AI States**: [[https:// | ||
| + | * `ControlledAi` - Direct player control state | ||
| + | * `Hunting` - Pet follows and attacks enemies | ||
| + | * `Wandering` - Idle behavior near hero | ||
| + | * `Fleeing` - Low health retreat | ||
| + | |||
| + | **UI**: [[https:// | ||
| + | * Pet inventory button (index 10, tinted) | ||
| + | * Opens `WndPetInventory` window | ||
| + | |||
| + | **Windows**: | ||
| + | * Pet inventory management UI | ||
| + | * Actions: Give, Take, Equip, Unequip | ||
| + | |||
| + | **Actions**: | ||
| + | * `AC_GIVE_TO_PET` - Give item to pet | ||
| + | * `AC_TAKE_FROM_PET` - Take item from pet | ||
| + | |||
| + | ===== JSON Configuration ===== | ||
| + | **Mob Pet Property**: In `mobsDesc/< | ||
| + | <code json> | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | ... | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Mobs with `" | ||
| + | * Rat, Snail, Crab, Bat, Spider, etc. | ||
| + | * Boss mobs: `false` | ||
| + | * Hostile NPCs: `false` | ||
| + | |||
| + | ===== String Resources ===== | ||
| + | English (values/ | ||
| + | <code xml> | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | </ | ||
| + | |||
| + | Russian (values-ru/ | ||
| + | <code xml> | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | <string name=" | ||
| + | </ | ||
| + | |||
| + | ===== Lua Scripts ===== | ||
| + | * **Pet AI**: `scripts/ | ||
| + | * **Possess Spell**: `scripts/ | ||
| + | * **Raise Dead**: `scripts/ | ||
| + | * **Exhumation**: | ||
| + | * **Summon Beast**: `scripts/ | ||
| + | |||
| + | ===== Related mr Entities ===== | ||
| + | * [[mr: | ||
| + | * [[mr: | ||
| + | * [[mr: | ||
| + | * [[mr: | ||
| + | * [[mr: | ||
| + | * [[mr: | ||
| + | * [[mr: | ||
| + | * [[mr: | ||
| + | * [[mr: | ||
| + | |||
| + | ===== Game Mechanics ===== | ||
| + | * **Taming Methods**: | ||
| + | * Scroll of Taming / Wand of Taming | ||
| + | * Possess Spell (temporary) | ||
| + | * Summon Beast Spell (temporary) | ||
| + | * Raise Dead (undead pets) | ||
| + | * Exhumation (Wraith pets) | ||
| + | * Certain items/ | ||
| + | * **Pet Capabilities**: | ||
| + | * Follow hero automatically | ||
| + | * Attack enemies in range | ||
| + | * Can equip items (weapons, armor, rings) | ||
| + | * Have own inventory (accessible via toolbar) | ||
| + | * Gain experience and level up | ||
| + | * Can be healed with potions/ | ||
| + | * **Pet Limits**: | ||
| + | * Max 3 active pets (configurable) | ||
| + | * Only mobs with `canBePet: true` in JSON | ||
| + | * Pets persist between levels | ||
| + | * **Pet Inventory**: | ||
| + | * Accessible via toolbar button (pet icon) | ||
| + | * Separate from hero inventory | ||
| + | * Can hold equipment and consumables | ||
| + | * Items dropped on pet death | ||
| + | * **Pet Commands** (via Possess): | ||
| + | * Move to position | ||
| + | * Attack target | ||
| + | * Follow/Stay | ||
| + | * Use item | ||
| + | |||
| + | ===== Code Fragments ===== | ||
| + | Taming a mob: | ||
| + | <code java> | ||
| + | // In Mob.java | ||
| + | public void makePet(Hero hero) { | ||
| + | this.petMaster = hero.id(); | ||
| + | hero.pets.add(this); | ||
| + | setState(MobAi.getStateByClass(Hunting.class)); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Pet inventory access: | ||
| + | <code java> | ||
| + | // In PetInventoryManager.java | ||
| + | public static void giveToPet(Hero hero, Item item) { | ||
| + | Pet pet = getSelectedPet(hero); | ||
| + | if (pet != null && pet.collect(item)) { | ||
| + | GLog.p(" | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Lua pet creation: | ||
| + | <code lua> | ||
| + | -- Possess spell | ||
| + | RPD.Mob: | ||
| + | target: | ||
| + | |||
| + | -- Raise Dead | ||
| + | local mob = RPD.MobFactory: | ||
| + | RPD.Mob: | ||
| + | level: | ||
| + | </ | ||
| + | |||
| + | {{tag> rpd mechanics pets ai companions}} | ||
mr/pet_mechanic.txt · Last modified: by 127.0.0.1
