Pet - jimdroberts/FishMMO GitHub Wiki
Represents a pet NPC, including owner, abilities, and network payload logic. Used to manage pet entities, their ownership, and abilities in FishMMO.
-
public static Action<long, Pet> OnReadID
Event triggered when a pet's owner ID is read from the network payload.
-
public PetAbilityTemplate PetAbilityTemplate
The template defining this pet's abilities and behavior.
-
public ICharacter PetOwner
The character that owns this pet.
-
public List Abilities { get; set; }
The list of ability IDs that this pet has learned.
-
public override void OnAwake()
Called when the pet is awakened. Initializes the abilities list.
-
public override void ResetState(bool asServer)
Resets the pet's state, clearing owner and abilities. Parameters:
-
asServer
(bool): Whether the reset is performed on the server.*
-
-
public override void ReadPayload(NetworkConnection connection, Reader reader)
Reads the pet's payload from the network, including owner ID. Triggers OnReadID event. Parameters:
-
connection
(NetworkConnection): The network connection. -
reader
(Reader): The network reader.*
-
-
public override void WritePayload(NetworkConnection connection, Writer writer)
Writes the pet's payload to the network, including owner ID. Parameters:
-
connection
(NetworkConnection): The network connection. -
writer
(Writer): The network writer.*
-
-
public void LearnAbilities(List abilities)
Allows the pet to learn a set of abilities. (Implementation needed) Parameters:
-
abilities
(List): List of ability IDs to learn.*
-
- Create a new
Pet
instance and assign itsPetAbilityTemplate
andPetOwner
. - Use the
Abilities
list to manage learned abilities. - Use the network payload methods for multiplayer synchronization.
// Example 1: Creating and initializing a pet
Pet pet = new Pet();
pet.PetOwner = playerCharacter;
pet.PetAbilityTemplate = abilityTemplate;
pet.Abilities = new List<int> { 1, 2, 3 };
// Resetting the pet's state
pet.ResetState(true);
- Always clear the
Abilities
list and owner reference when resetting pet state. - Use the
OnReadID
event to handle ownership logic after network deserialization. - Implement the
LearnAbilities
method to support dynamic ability learning for pets. - Assign a valid
PetAbilityTemplate
to define pet behavior and abilities.