OnActorRoleChanged

From Intrigues Wiki
Revision as of 19:42, 4 January 2024 by Tayfunwiki (talk | contribs) (Created page with "== <code>onActorRoleChanged</code> Event in Clan Class == === Overview === The <code>onActorRoleChanged</code> event in the Clan class is triggered when there is a change in an actor's role within the clan. This event plays a critical role in tracking and responding to changes in the responsibilities and status of clan members. === Event Definition === <syntaxhighlight lang="c#"> public Action<Actor, Role> onActorRoleChanged; </syntaxhighlight> === Description === *...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

onActorRoleChanged Event in Clan Class

Overview

The onActorRoleChanged event in the Clan class is triggered when there is a change in an actor's role within the clan. This event plays a critical role in tracking and responding to changes in the responsibilities and status of clan members.

Event Definition

public Action<Actor, Role> onActorRoleChanged;

Description

  • Delegate Type: Action<Actor, Role>
  • Purpose: Notifies when an actor's role in the clan is changed.
  • Parameters:
    • Actor: The actor whose role has changed.
    • Role: The previous role held by the actor.

Functionality

  • The onActorRoleChanged event is raised when there is a change in the role of an actor within the clan.
  • It provides the Actor object and the Role object, representing the actor and their old role, respectively.
  • This event allows for dynamic updates to game elements such as clan hierarchies, actor profiles, or triggering specific gameplay mechanics or narrative elements associated with role changes.

Usage

This event is essential for scenarios where role assignments within a clan are crucial to gameplay dynamics, resource management, or storyline progression. It ensures that any change in an actor's role is consistently reflected and acted upon throughout the game.

Example of Usage

public class ClanRoleChangeHandler : MonoBehaviour {
    void Start() {
        Clan playerClan = IM.Player.Clan;
        if (playerClan != null) {
            playerClan.onActorRoleChanged += HandleRoleChange;
        }
    }

    private void HandleRoleChange(Actor actor, Role oldRole) {
        string newRoleName = actor.Role.RoleName;
        Debug.Log($"Role change in player's clan: {actor.Name} changed from {oldRole.RoleName} to {newRoleName}");
    }

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

Description

  • This example demonstrates subscribing to the onActorRoleChanged event for the player's clan.
  • When an actor's role changes, the HandleRoleChange method is called, logging the actor's name and their transition from the old role to the new role.
  • It also ensures to unsubscribe from the event upon the destruction of the GameObject to prevent memory leaks or unintended behavior.

Remarks

  • The onActorRoleChanged event is vital for maintaining a realistic portrayal of clan dynamics and hierarchy.
  • It allows for a responsive and immersive gameplay experience, where role changes within a clan can have significant implications.