mr:pet_mechanic
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| mr:pet_mechanic [2026/08/25 18:56] – wiki: fix issues in 5 sampled pages (pet_mechanic mr, stone_walking_buff cn, nausea_buff/shattered_ice ru) Bot | mr:pet_mechanic [2026/08/25 18:59] (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.mechanics` | ||
| + | * Methods: | ||
| + | * `hasPets(Hero hero)` - Check if hero has pets | ||
| + | * `openPetInventoryFromToolbar(Hero hero)` - Open pet inventory UI | ||
| + | * `giveItemToPet(Hero hero, Mob pet, Item item)` - Transfer item to pet's backpack | ||
| + | * `takeItemFromPet(Hero hero, Mob pet, Item item)` - Take item from pet's backpack | ||
| + | |||
| + | **Pet Base Class**: [[https:// | ||
| + | * Mobs become pets via static `Mob.makePet(Mob pet, Char owner)` or instance `mob.makePet(Char owner)` | ||
| + | * Pet state tracked via `setOwnerId(ownerId)` on the mob; pet fraction follows the owner' | ||
| + | |||
| + | **Mob Pet Methods**: [[https:// | ||
| + | * `makePet(Char owner)` / `Mob.makePet(Mob, | ||
| + | * `isPet()` - Check if mob is a pet | ||
| + | * `canBePet()` - Check if mob species can be tamed | ||
| + | |||
| + | **Hero Pet List**: [[https:// | ||
| + | * `getPets_l()` - Get list of hero's pets (Lua interface, defined on `Char`) | ||
| + | |||
| + | **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 | ||
| + | * Related windows: `WndPetBag`, | ||
| + | |||
| + | **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 `" | ||
| + | * Boss mobs: `false` (e.g. BeeHive) | ||
| + | * 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: | ||
| + | |||
| + | ===== Game Mechanics ===== | ||
| + | * **Taming Methods**: | ||
| + | * 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 | ||
| + | * Have own inventory (accessible via toolbar) | ||
| + | * Gain experience and level up | ||
| + | * Can be healed with potions/ | ||
| + | * **Pet Rules**: | ||
| + | * Only mobs with `canBePet: true` in JSON can be tamed | ||
| + | * Pets persist between levels (`followOnLevelChanged` returns true for hero-owned pets) | ||
| + | * **Pet Inventory**: | ||
| + | * Accessible via toolbar button (pet icon) | ||
| + | * Separate from hero inventory | ||
| + | * Items are transferred to/from the pet's backpack | ||
| + | |||
| + | ===== Code Fragments ===== | ||
| + | Taming a mob (actual implementation in Mob.java): | ||
| + | <code java> | ||
| + | public static Mob makePet(@NotNull Mob pet, int ownerId) { | ||
| + | var owner = CharsList.getById(ownerId); | ||
| + | if(owner.fraction()==Fraction.HEROES) { | ||
| + | pet.expForKill = 0; | ||
| + | } | ||
| + | if (pet.canBePet()) { | ||
| + | pet.setFraction(owner.fraction()); | ||
| + | pet.setOwnerId(ownerId); | ||
| + | } | ||
| + | return pet; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Lua pet creation: | ||
| + | <code lua> | ||
| + | -- Possess spell | ||
| + | RPD.Mob: | ||
| + | |||
| + | -- 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
