Clan:Create

From Intrigues Wiki
Revision as of 06:30, 3 March 2024 by Tayfunwiki (talk | contribs)

Intrigues - Clan Creation

Overview

The Clan class offers methods to create and manage clans with specified attributes. This documentation focuses on the Create method, explaining its parameters, return types, and providing example implementations for creating clans.

Create Method Variants

The Create method is available in two variants, each designed for different scenarios in specifying clan attributes such as culture and policies.

Variant 1: Create with Direct Object References

Description

Creates a new clan with specific attributes using direct object references for the culture and policies. This method is suitable when you have direct references to the culture and policy objects.

Signature

public static Clan Create(string clanName, string description, Culture culture, Sprite icon, params Policy[] policies)

Parameters

  • clanName (string): The name of the clan.
  • description (string): A description of the clan.
  • culture (Culture): The culture associated with the clan.
  • icon (Sprite): A visual representation of the clan.
  • policies (Policy[]): An array of policies the clan adheres to.

Returns

If a clan with the same name exists, it returns the existing clan; otherwise, it creates and returns a new clan.

Example Usage

using Nullframes.Intrigues;
using UnityEngine;

public class Runtime : MonoBehaviour {

    public Sprite icon;

    private void Start() {
        CreatePlayerClan();
    }

    public void CreatePlayerClan() {
        Policy economy = IM.GetPolicy("Economy");
        Policy health = IM.GetPolicy("Health");
        
        Clan clan = Clan.Create("Clan Name", "Description", IM.Player.Culture, icon, economy, health);
        
        IM.Player.JoinClan(clan);
    }
}

Variant 2: Create with Culture and Policies by Name or ID

Description

Facilitates clan creation using the name or ID for culture and policies instead of direct object references. This variant is useful when you prefer to reference culture and policies by identifiers.

Signature

public static Clan Create(string clanName, string description, string cultureNameOrId, Sprite icon, params string[] policyNameOrId)

Parameters

  • clanName (string): The name of the clan.
  • description (string): A description of the clan.
  • cultureNameOrId (string): The name or ID of the culture associated with the clan.
  • icon (Sprite): A visual representation of the clan.
  • policyNameOrId (string[]): Names or IDs of the policies the clan adheres to.

Returns

If a clan with the same name exists, it returns the existing clan; otherwise, it creates and returns a new clan.

Example Usage

using Nullframes.Intrigues;
using UnityEngine;

public class Runtime : MonoBehaviour {

    public Sprite icon;

    private void Start() {
        CreatePlayerClan();
    }

    public void CreatePlayerClan() {
        Clan clan = Clan.Create("Clan Name", "Description", "Varag", icon, "Economy", "Health");
        IM.Player.JoinClan(clan);
    }
}

Remarks

  • Uniqueness Check: Both Create method variants perform a check for the existence of a clan with the provided name to ensure uniqueness within the system. If a clan with the specified name already exists, the method returns the existing clan instead of creating a new one. This mechanism prevents the creation of duplicate clans.
  • Debug Logging: When a duplicate clan name is detected, a debug message is logged to notify the developer of the attempt to create a clan with a name that already exists. This aids in debugging and maintaining the integrity of the clan system.
  • Policy and Culture Validation: For the second variant of the Create method, where culture and policies are specified by name or ID, the method includes validation to ensure that the specified culture and policies exist within the system before creating the clan. If a specified policy or culture does not exist, the method may exclude it from the clan creation process, depending on the implementation details.
  • Dynamic Policy Assignment: The second variant allows for dynamic assignment of policies to a clan by specifying policy names or IDs. This is particularly useful in scenarios where policies are not statically known at compile time but are determined at runtime based on game logic or player choices.
  • Error Handling: It is recommended to implement error handling around the Create method to deal with scenarios where specified cultures or policies do not exist, especially when using the second variant of the method. Proper error handling ensures a robust and error-tolerant implementation.
  • Extensibility: The design of the Create method, with support for optional parameters and multiple overloads, provides flexibility and extensibility. Developers can easily extend the clan creation process to include additional attributes or customization options by modifying the Clan class.