Role:Create

From Intrigues Wiki

Role Management in Systems

Overview

The Role class facilitates the dynamic creation and integration of roles within a system, providing a structured approach to defining roles with specific attributes. This guide outlines the method for creating roles, emphasizing their uniqueness and the significance of attributes such as gender-specific titles, inheritance, and hierarchical placement.

Method Overview

Create

This method creates a new role or retrieves an existing one based on the provided name, ensuring no duplication within the system. It supports detailed customization, including gender-specific titles and visual representation through icons.

Syntax

public static Role Create(
    string roleName,
    string description,
    Sprite icon = null,
    int capacity = 1,
    string titleForMale = null,
    string titleForFemale = null,
    bool inheritance = false,
    int priority = 0,
    string filterNameOrId = null
)

Parameters

  • roleName: Unique identifier for the role.
  • description: Brief overview of the role's responsibilities or significance.
  • icon: (Optional) Visual representation for the role.
  • capacity: (Optional) Maximum number of actors that can assume the role simultaneously.
  • titleForMale: (Optional) Title for male actors.
  • titleForFemale: (Optional) Title for female actors.
  • inheritance: (Optional) Specifies if the role is inheritable.
  • priority: (Optional) Determines the role's hierarchical rank.
  • filterNameOrId: (Optional) Associates the role with a specific heir filter for inheritance logic.

Returns

An existing role if one with the same name is found; otherwise, a newly instantiated Role object.

Example Usage

In the provided example, a new role named "Leader" is created with distinct titles for male and female actors, an icon for visual representation, a capacity for three individuals to hold the role within any group, and the highest priority level to signify its importance. This role is also inheritable and associated with a specific filter for determining heir eligibility.

using Nullframes.Intrigues;
using UnityEngine;

public class Runtime : MonoBehaviour {
    public Sprite icon;

    private void Start() {
        CreateNewRole();
    }

    private void CreateNewRole() {
        Role role = Role.Create(
            roleName: "Leader", 
            description: "Leads the group and makes critical decisions.", 
            icon: icon, 
            capacity: 3, 
            titleForMale: "King", 
            titleForFemale: "Queen", 
            inheritance: true, 
            priority: 99, 
            filterNameOrId: "Leader Filter"
        );
        
        // Example of setting the role for a player or actor.
        IM.Player.SetRole(role);
    }
}

Conclusion

The Role class and its Create method offer a comprehensive approach to role management within a system, ensuring roles are uniquely identified and correctly integrated. Through detailed attributes, roles can be designed to fit various system requirements, from defining gender-specific titles to establishing inheritance logic and hierarchical order.