MaximilianPs

FactionSystem - Prototype Test for GKC

Jul 23rd, 2021 (edited)
1,215
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class GKC_RepSystem : MonoBehaviour
  6. {
  7.     string[] fac = {"Player", "Rome", "Paris", "Berlin"};
  8.  
  9.     factionSystem factSys;
  10.  
  11.     public GameObject[] npcs;
  12.    
  13.  
  14.     // Start is called before the first frame update
  15.     void Awake()
  16.     {
  17.         Debug.Log("Detecting Faction System Super-Manager");
  18.         factSys = FindObjectOfType(typeof(factionSystem)) as factionSystem;
  19.  
  20.         if(factSys == null)
  21.             Debug.LogError("System Super-Manager *** NOT FOUND ***");
  22.  
  23.  
  24.         factSys.factionList.Clear();
  25.  
  26.         // First we add the factions to the List
  27.         for (int i = 0; i < fac.Length; i++)
  28.         {
  29.             factionSystem.factionInfo factInfo = new factionSystem.factionInfo();
  30.             factInfo.Name = fac[i];
  31.             factInfo.turnToEnemyIfAttack = true;
  32.            
  33.             factSys.factionList.Add(factInfo);
  34.         }
  35.  
  36.         factSys.updateFactionsList();
  37.  
  38.         // Second we fill the Relation with Factions
  39.         foreach (var item in factSys.factionList)
  40.         {
  41.             item.relationWithFactions.Clear();
  42.  
  43.             for (int factIndex = 0; factIndex < factSys.factionList.Count; factIndex++)
  44.             {
  45.                 if (factSys.factionList[factIndex].Name != item.Name)
  46.                 {
  47.                     Debug.Log("adding relationship to " + factSys.factionList[factIndex].Name + " about " + fac[factIndex]);
  48.                     factionSystem.relationInfo relInfo = new factionSystem.relationInfo();
  49.                     relInfo.factionName = fac[factIndex];
  50.  
  51.                     int relInt = Mathf.CeilToInt(Random.Range(0, 100));
  52.  
  53.                     if (relInt < 40)
  54.                         relInfo.relation = factionSystem.relationInfo.relationType.enemy;
  55.                     else if (relInt > 40 && relInt < 50)
  56.                         relInfo.relation = factionSystem.relationInfo.relationType.neutral;
  57.                     else
  58.                         relInfo.relation = factionSystem.relationInfo.relationType.friend;
  59.  
  60.                     relInfo.factionIndex = factIndex;
  61.  
  62.                     item.relationWithFactions.Add(relInfo);
  63.                 }
  64.             }
  65.         }
  66.    
  67.         // Third Assign NPCs to the factions
  68.         foreach (var npc in npcs)
  69.         {
  70.             npc.GetComponentInChildren<characterFactionManager>().getFactionList();
  71.             //npc.GetComponentInChildren<characterFactionManager>().getFactionList();
  72.  
  73.             int factionID = Random.Range(1, fac.Length);
  74.             npc.GetComponentInChildren<characterFactionManager>().factionIndex = factionID;
  75.  
  76.             string name = "Roberto"; //npc.GetComponentInChildren<health>().settings.allyName;
  77.             string faction = npc.GetComponentInChildren<characterFactionManager>().factionName;
  78.             npc.GetComponentInChildren<health>().setAllyNewName(name + " from " + faction);
  79.             npc.GetComponentInChildren<health>().setEnemyNewName(name + " from " + faction);
  80.         }
  81.     }
  82.  
  83.     private void Start()
  84.     {
  85.         // Third Assign NPCs to the factions
  86.         foreach (var npc in npcs)
  87.         {
  88.             npc.GetComponentInChildren<characterFactionManager>().getFactionList();
  89.             //npc.GetComponentInChildren<characterFactionManager>().getFactionList();
  90.  
  91.             int factionID = Random.Range(1, fac.Length);
  92.             npc.GetComponentInChildren<characterFactionManager>().factionIndex = factionID;
  93.  
  94.             string name = "Roberto"; //npc.GetComponentInChildren<health>().settings.allyName;
  95.             string faction = npc.GetComponentInChildren<characterFactionManager>().factionName;
  96.             npc.GetComponentInChildren<health>().setAllyNewName(name + " from " + faction);
  97.             npc.GetComponentInChildren<health>().setEnemyNewName(name + " from " + faction);
  98.         }
  99.     }
  100. }
  101.  
RAW Paste Data