Esempio n. 1
0
            //init the npc manager:
            public void InitNPCMgr()
            {
                //make sure there's a npc manager prefab set:
                if (npcMgr == null)
                {
                    Debug.LogError("[Game Manager]: NPC Manager hasn't been set for NPC faction.");
                    return;
                }

                npcMgrIns = Instantiate(npcMgr.gameObject).GetComponent <NPCManager>();

                //set the faction manager:
                npcMgrIns.FactionMgr = FactionMgr;

                //init the npc manager:
                npcMgrIns.Init();

                if (TypeInfo != null) //if this faction has a valid type.
                {
                    //set the building center regulator (if there's any):
                    if (TypeInfo.centerBuilding != null)
                    {
                        npcMgrIns.territoryManager_NPC.centerRegulator = npcMgrIns.GetBuildingRegulatorAsset(TypeInfo.centerBuilding);
                    }
                    //set the population building regulator (if there's any):
                    if (TypeInfo.populationBuilding != null)
                    {
                        npcMgrIns.populationManager_NPC.populationBuilding = npcMgrIns.GetBuildingRegulatorAsset(TypeInfo.populationBuilding);
                    }

                    //is there extra buildings to add?
                    if (TypeInfo.extraBuildings.Count > 0)
                    {
                        //go through them:
                        foreach (Building b in TypeInfo.extraBuildings)
                        {
                            if (b != null)
                            {
                                npcMgrIns.buildingCreator_NPC.independentBuildingRegulators.Add(npcMgrIns.GetBuildingRegulatorAsset(b));
                            }
                            else
                            {
                                Debug.LogError("[Game Manager]: Faction " + TypeInfo.Name + " (Code: " + TypeInfo.Code + ") has missing building regulator(s) in extra buildings.");
                            }
                        }
                    }
                }
            }
Esempio n. 2
0
        //init the npc manager:
        public void InitNPCMgr(GameManager gameMgr)
        {
            //make sure there's a npc manager prefab set:
            if (npcMgr == null)
            {
                Debug.LogError("[Faction Slot]: NPC Manager hasn't been set for NPC faction.");
                return;
            }

            npcMgrIns = Object.Instantiate(npcMgr.gameObject).GetComponent <NPCManager>();

            //set the faction manager:
            npcMgrIns.FactionMgr = FactionMgr;

            //init the npc manager:
            npcMgrIns.Init(gameMgr);

            if (typeInfo != null) //if this faction has a valid type.
            {
                //set the building center regulator (if there's any):
                if (typeInfo.GetCenterBuilding() != null)
                {
                    npcMgrIns.territoryManager_NPC.centerRegulator = npcMgrIns.GetBuildingRegulatorAsset(typeInfo.GetCenterBuilding());
                }
                //set the population building regulator (if there's any):
                if (typeInfo.GetPopulationBuilding() != null)
                {
                    npcMgrIns.populationManager_NPC.populationBuilding = npcMgrIns.GetBuildingRegulatorAsset(typeInfo.GetPopulationBuilding());
                }

                //is there extra buildings to add?
                foreach (Building b in typeInfo.GetExtraBuildings())
                {
                    if (b != null)
                    {
                        npcMgrIns.buildingCreator_NPC.independentBuildingRegulators.Add(npcMgrIns.GetBuildingRegulatorAsset(b));
                    }
                    else
                    {
                        Debug.LogError($"[Game Manager]: Faction " + typeInfo.GetName() + " (Code: " + typeInfo.GetCode() + ") has missing Building fields in the 'Extra Buildings' list.");
                    }
                }
            }
        }
Esempio n. 3
0
        //a method called that configures NPC faction components in case of a building upgrade:
        private void LaunchNPCBuildingUpgrade(NPCManager npcMgrIns, Building source, Building target)
        {
            //we need access to the NPC Building Creator in order to find the active regulator instance that manages the building type to be upgraded:
            NPCBuildingCreator buildingCreator_NPC = npcMgrIns.buildingCreator_NPC;

            NPCBuildingRegulator buildingRegulator       = npcMgrIns.GetBuildingRegulatorAsset(source);  //will hold the building's regulator that is supposed to be upgraded.
            NPCBuildingRegulator targetBuildingRegulator = npcMgrIns.GetBuildingRegulatorAsset(target);; //will hold the target building's regulator.

            //we expect both above regulators to be valid:
            if (buildingRegulator == null)
            {
                Debug.LogError("[Upgrade Manager] Can not find a valid NPC Building Regulator for the upgrade source.");
                return;
            }
            if (targetBuildingRegulator == null)
            {
                Debug.LogError("[Upgrade Manager] Can not find a valid NPC Building Regulator for the upgrade target.");
                return;
            }

            //destroy the old building regulator
            buildingCreator_NPC.DestroyActiveRegulator(buildingRegulator);

            //if the building to be upgraded was either, the main population building or the main center building
            //then we'll update that as well.
            if (buildingRegulator == npcMgrIns.populationManager_NPC.populationBuilding)
            {
                npcMgrIns.populationManager_NPC.populationBuilding = targetBuildingRegulator;
                npcMgrIns.populationManager_NPC.ActivatePopulationBuilding(); //activate the new population building regulator.
            }
            if (buildingRegulator == npcMgrIns.territoryManager_NPC.centerRegulator)
            {
                npcMgrIns.territoryManager_NPC.centerRegulator = targetBuildingRegulator; //assign new regulator for the center building
                npcMgrIns.territoryManager_NPC.ActivateCenterRegulator();                 //activate the new regulator.
            }

            //activate the new regulator:
            buildingCreator_NPC.ActivateBuildingRegulator(targetBuildingRegulator);
        }