Beispiel #1
0
        private NPCBuildingCreator buildingCreator_NPC; //the NPC Building Creator used to create all instances of the buildings regulated here.
        #endregion

        #region Initializing/Terminating
        /// <summary>
        /// NPCBuildingRegulator constructor.
        /// </summary>
        /// <param name="data">Holds information regarding how the building type that will be regulated.</param>
        /// <param name="prefab">Actual Building prefab to regulate.</param>
        /// <param name="gameMgr">GameManager instance of the currently active game.</param>
        /// <param name="npcMgr">NPCManager instance that manages the NPC faction to whome the regulator component belongs.</param>
        /// <param name="buildingCreator_NPC">NPCBuildingCreator instance of the NPC faction that's responsible for creating buildings.</param>
        public NPCBuildingRegulator(NPCBuildingRegulatorData data, Building prefab, GameManager gameMgr, NPCManager npcMgr, NPCBuildingCreator buildingCreator_NPC, Building buildingCenter)
            : base(data, prefab, gameMgr, npcMgr)
        {
            this.Data = data;
            Assert.IsNotNull(this.Data,
                             $"[NPCBuildingRegulator] Initializing without NPCBuildingRegulatorData instance is not allowed!");

            this.buildingCreator_NPC = buildingCreator_NPC;
            Assert.IsNotNull(this.buildingCreator_NPC,
                             $"[NPCBuildingRegulator] Initializing without a reference to the NPCBuildingCreator instance is not allowed!");

            this.Prefab = prefab;
            Assert.IsNotNull(this.Prefab,
                             $"[NPCBuildingRegulator] Initializing without a reference to the building's prefab is not allowed!");

            this.buildingCenter = buildingCenter;
            Assert.IsNotNull(this.Prefab,
                             $"[NPCBuildingRegulator] Initializing without a reference to the regulator's building center is not allowed!");

            //go through all spawned buildings to see if the buildings that should be regulated by this instance are created or not:
            foreach (Building b in this.factionMgr.GetBuildings())
            {
                Add(b);
            }

            //start listening to the required delegate events:
            CustomEvents.BuildingDestroyed      += Remove;
            CustomEvents.BuildingStopPlacement  += Remove;
            CustomEvents.BuildingStartPlacement += AddPending;
            CustomEvents.BuildingPlaced         += Add;
        }
Beispiel #2
0
        public NPCBuildingCreator buildingCreator_NPC; //the NPC Building Creator used to create all instances of the buildings regulated here.

        /* Initializing everything */
        public void Init(NPCManager npcMgr, NPCBuildingCreator buildingCreator_NPC, Building buildingCenter)
        {
            //assign the appropriate faction manager and building creator settings
            base.InitItem(npcMgr);
            this.buildingCreator_NPC = buildingCreator_NPC;
            this.buildingCenter      = buildingCenter;

            //set the building code:
            code = prefabs[0].Code;

            //go through all spawned buildings to see if the buildings that should be regulated by this instance are created or not:
            foreach (Building b in this.factionMgr.Buildings)
            {
                if (b.Code == code)
                {
                    amount++; //increase amount
                    //add to list:
                    currentInstances.Add(b);
                }
            }

            //start listening to the required delegate events:
            CustomEvents.BuildingDestroyed      += OnBuildingDestroyed;
            CustomEvents.BuildingStopPlacement  += OnBuildingStopPlacement;
            CustomEvents.BuildingStartPlacement += OnBuildingStartPlacement;
            CustomEvents.BuildingPlaced         += OnBuildingPlaced;
        }
Beispiel #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);
        }