Pet - jimdroberts/FishMMO GitHub Wiki

Description

Represents a pet NPC, including owner, abilities, and network payload logic. Used to manage pet entities, their ownership, and abilities in FishMMO.


API Access

Fields

  • 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.

Methods

  • 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.*

Basic Usage

Setup

  1. Create a new Pet instance and assign its PetAbilityTemplate and PetOwner.
  2. Use the Abilities list to manage learned abilities.
  3. Use the network payload methods for multiplayer synchronization.

Example

// 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);

Best Practices

  • 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.
⚠️ **GitHub.com Fallback** ⚠️