//Game state methods: //call when a faction is defeated (its capital building has fallen): public void OnFactionDefeated(int FactionID) { Factions [FactionID].Lost = true; //ofc. ActiveFactions--; //decrease the amount of active factions: if (Events) { Events.OnFactionEliminated(Factions[FactionID]); //call the custom event. } if (FactionID == PlayerFactionID) { //If the player is defeated then: LooseGame(); } else { //If one of the other factions was defeated: //Check if only the player was left undefeated! if (ActiveFactions == 1) { WinGame(); //Win the game! if (Events) { Events.OnFactionWin(Factions[FactionID]); //call the custom event. } } } }
//called locally when a faction is defeated (its capital building has fallen): public void OnFactionDefeatedLocal(int factionID) { //Show UI message. UIMgr.ShowPlayerMessage(factions[factionID].GetName() + " (Faction ID:" + factionID.ToString() + ") has been defeated.", UIManager.MessageTypes.info); //Destroy all buildings and kill all units: if (factions[factionID].IsNPCFaction() == true) //if his is a NPC faction //destroy the active instance of the NPC Manager component: { Destroy(factions[factionID].GetNPCMgrIns().gameObject); } //go through all the units/buildings that this faction owns and destroy them //because we'll be modifying the source list by destroying the buildings, we need to create a temporary list List <FactionEntity> factionEntities = factions[factionID].FactionMgr.GetFactionEntities().ToList(); foreach (FactionEntity entity in factionEntities) { entity.EntityHealthComp.DestroyFactionEntityLocal(false); } factions[factionID].Disable(); //mark the faction slot as disabled activefactionsAmount--; //decrease the amount of active factions: CustomEvents.OnFactionEliminated(factions[factionID]); //call the custom event. if (factionID == PlayerFactionID) { //If the player is defeated then: LooseGame(); } //If one of the other factions was defeated: //Check if only the player was left undefeated! else if (activefactionsAmount == 1) { WinGame(); //Win the game! CustomEvents.OnFactionWin(factions[factionID]); //call the custom event. } }
//Game state methods: //call when a faction is defeated (its capital building has fallen): public void OnFactionDefeated(int FactionID) { //Destroy all buildings and kill all units: //faction manager of the one that has been defeated. FactionManager FactionMgr = Factions[FactionID].FactionMgr; //go through all the units that this faction owns while (FactionMgr.Units.Count > 0) { if (FactionMgr.Units[0] != null) { FactionMgr.Units[0].DestroyUnitLocal(); } else { FactionMgr.Units.RemoveAt(0); } } //go through all the buildings that this faction owns while (FactionMgr.Buildings.Count > 0) { if (FactionMgr.Buildings[0] != null) { FactionMgr.Buildings[0].DestroyBuildingLocal(false); } else { FactionMgr.Buildings.RemoveAt(0); } } //if this is a single player game and this is a NPC faction if (FactionID != GameManager.PlayerFactionID && GameManager.MultiplayerGame == false) { //Disable the NPC managers: if (FactionMgr.BuildingMgr != null) { FactionMgr.BuildingMgr.enabled = false; } if (FactionMgr.ResourceMgr != null) { FactionMgr.ResourceMgr.enabled = false; } if (FactionMgr.ArmyMgr != null) { FactionMgr.ArmyMgr.enabled = false; } } Factions[FactionID].Lost = true; //ofc. ActiveFactions--; //decrease the amount of active factions: if (Events) { Events.OnFactionEliminated(Factions[FactionID]); //call the custom event. } if (FactionID == PlayerFactionID) { //If the player is defeated then: LooseGame(); } else { //If one of the other factions was defeated: //Check if only the player was left undefeated! if (ActiveFactions == 1) { WinGame(); //Win the game! if (Events) { Events.OnFactionWin(Factions[FactionID]); //call the custom event. } } } }
//Game state methods: //call when a faction is defeated (its capital building has fallen): public void OnFactionDefeated(int FactionID) { //Destroy all buildings and kill all units: if (MultiplayerGame == false || FactionID == PlayerFactionID) //only if this a multiplayer game or this is the local player { //faction manager of the one that has been defeated. FactionManager FactionMgr = Factions[FactionID].FactionMgr; //go through all the units that this faction owns while (FactionMgr.Units.Count > 0) { if (FactionMgr.Units[0] != null) { FactionMgr.Units[0].DestroyUnitLocal(); } else { FactionMgr.Units.RemoveAt(0); } } //go through all the buildings that this faction owns while (FactionMgr.Buildings.Count > 0) { if (FactionMgr.Buildings[0] != null) { FactionMgr.Buildings[0].DestroyBuildingLocal(false); } else { FactionMgr.Buildings.RemoveAt(0); } } } if (Factions[FactionID].IsNPCFaction() == true) //if his is a NPC faction { //destroy the active instance of the NPC Manager component: Destroy(Factions[FactionID].GetNPCMgrIns()); } Factions[FactionID].Lost = true; //ofc. activeFactionsAmount--; //decrease the amount of active factions: if (Events) { Events.OnFactionEliminated(Factions[FactionID]); //call the custom event. } if (FactionID == PlayerFactionID) { //If the player is defeated then: LooseGame(); } else { //If one of the other factions was defeated: //Check if only the player was left undefeated! if (activeFactionsAmount == 1) { WinGame(); //Win the game! if (Events) { Events.OnFactionWin(Factions[FactionID]); //call the custom event. } } } }