OnMemberLeave

From Intrigues Wiki
Revision as of 19:38, 4 January 2024 by Tayfunwiki (talk | contribs) (Created page with "== <code>onMemberLeave</code> Event in Clan Class == === Overview === The <code>onMemberLeave</code> event in the Clan class is activated when a member leaves the clan. This event is crucial for acknowledging and responding to changes in the clan's composition within the game's world. === Event Definition === <syntaxhighlight lang="c#"> public event Action<Actor> onMemberLeave; </syntaxhighlight> === Description === * Delegate Type: <code>Action<Actor></code> * Purpo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

onMemberLeave Event in Clan Class

Overview

The onMemberLeave event in the Clan class is activated when a member leaves the clan. This event is crucial for acknowledging and responding to changes in the clan's composition within the game's world.

Event Definition

public event Action<Actor> onMemberLeave;

Description

  • Delegate Type: Action<Actor>
  • Purpose: Notifies when a member leaves the clan.
  • Parameters:
    • Actor: The actor who has left the clan.

Functionality

  • The onMemberLeave event is raised whenever an actor ceases to be a member of the clan.
  • It provides the Actor object representing the departing member.
  • This event allows for updating game elements such as clan rosters, adjusting clan resources, or triggering specific gameplay mechanics or narrative elements associated with the change in the clan's size.

Usage

This event is typically used to handle updates or actions within the game when the clan's membership decreases. It can influence gameplay in areas such as clan dynamics, resource management, or storylines that involve clan loyalty and membership.

Example of Usage

public class ClanDepartureHandler : MonoBehaviour {
    void Start() {
        Clan playerClan = IM.Player.Clan;
        if (playerClan != null) {
            playerClan.onMemberLeave += HandleMemberLeaving;
        }
    }

    private void HandleMemberLeaving(Actor departingMember) {
        Debug.Log($"Member left the player's clan: {departingMember.Name}");
    }

    void OnDestroy() {
        if (IM.Player.Clan != null) {
            playerClan.onMemberLeave -= HandleMemberLeaving;
        }
    }
}

Description

  • This example shows how to subscribe to the onMemberLeave event for the player's clan.
  • When a member leaves the clan, the HandleMemberLeaving method is invoked, logging the name of the departing member.
  • It also ensures to unsubscribe from the event upon the destruction of the GameObject to prevent memory leaks or unintended behavior.

Remarks

  • The onMemberLeave event is vital for dynamically managing the clan's composition and responding to its reduction.
  • It offers a mechanism for developers to create gameplay and narrative elements that adjust to the clan's changing demographics.
  • Effective handling of this event is key to maintaining a realistic and engaging clan dynamic within the game.