PetSystem - jimdroberts/FishMMO GitHub Wiki

Description

The PetSystem is a server-side system in FishMMO responsible for managing all pet-related logic, including summoning, following, staying, releasing, and persistence. It registers and handles network broadcasts for pet actions, subscribes to character and ability events, manages pet AI initialization, and ensures pet state is synchronized between the server, database, and client.


API Access

Methods

  • public override void InitializeOnce()

    Called once to initialize the pet system. Registers broadcast handlers and subscribes to character and ability events.

  • public override void Destroying()

    Called when the system is being destroyed. Unregisters broadcast handlers and unsubscribes from character and ability events.

  • private void OnPetFollowBroadcastReceived(NetworkConnection conn, PetFollowBroadcast msg, Channel channel)

    Handles pet follow broadcast, updating pet AI to follow the character.

  • private void OnPetStayBroadcastReceived(NetworkConnection conn, PetStayBroadcast msg, Channel channel)

    Handles pet stay broadcast, updating pet AI to stay at its current position.

  • private void OnPetSummonBroadcastReceived(NetworkConnection conn, PetSummonBroadcast msg, Channel channel)

    Handles pet summon broadcast, warping pet to the character's position.

  • private void OnPetReleaseBroadcastReceived(NetworkConnection conn, PetReleaseBroadcast msg, Channel channel)

    Handles pet release broadcast, saving pet state and despawning the pet object.

  • private void CharacterSystem_OnSpawnCharacter(NetworkConnection conn, IPlayerCharacter character, Scene scene)

    Handles character spawn event, loading and spawning the pet for the character if available.

  • private void CharacterSystem_OnDespawnCharacter(NetworkConnection conn, IPlayerCharacter character)

    Handles character despawn event, saving pet state and despawning the pet object if necessary.

  • private void CharacterSystem_OnPetKilled(NetworkConnection conn, IPlayerCharacter character)

    Handles pet killed event, despawning the pet and broadcasting pet removal to the client.

  • private void AbilityObject_OnPetSummon(PetAbilityTemplate petAbilityTemplate, IPlayerCharacter caster)

    Handles pet summoning via ability, spawning the pet at a random position within the bounding box.


Basic Usage

Setup

  1. Requires the server to be running and the pet system to be initialized as part of the server startup.
  2. The system automatically registers broadcast handlers for all pet actions and subscribes to character and ability events.
  3. No manual registration is required unless extending or customizing pet logic.

Example

// Example 1: Summoning a pet (server-side)
// This is handled automatically by the system when a PetSummonBroadcast is received from a client or via ability.
// No manual invocation is required unless extending or customizing the logic.

// Example 2: Releasing a pet (server-side)
// This is handled automatically by the system when a PetReleaseBroadcast is received from a client.
// No manual invocation is required unless extending or customizing the logic.

Best Practices

  • Always validate all pet actions and state changes to prevent exploits and errors.
  • Use the provided broadcast handlers and event subscriptions to extend or customize pet logic if needed.
  • Ensure all pet data is properly synchronized between the server, database, and client.
  • Avoid direct manipulation of pet objects outside of the provided interfaces and system methods.
  • Properly manage pet AI initialization and scene assignment for seamless gameplay experience.
⚠️ **GitHub.com Fallback** ⚠️