Ejemplo n.º 1
0
		public void _OnUnitDestroyed(Unit unit){
			totalUnitCount-=1;
			
			//assume isObjectUnit is the boolean flag
			if(unit.isObjectUnit){
				GameControl.GameOver(0);	//assume 0 is the player unit faction
				return;
			}
			
			//remove unit from allUnitList so it no longers reserve a turn
			if(TurnControl.GetTurnMode()==_TurnMode.UnitPerTurn){
				int ID=allUnitList.IndexOf(unit);
				if(ID<=selectedUnitID){
					selectedUnitID-=1;
				}
				allUnitList.Remove(unit);
			}
			
			//remove the unit from the faction, and if the faction has no active unit remain, the faction itself is remove (out of the game)
			for(int i=0; i<factionList.Count; i++){
				if(factionList[i].ID==unit.factionID){
					factionList[i].RemoveUnit(unit);
					if(factionList[i].allUnitList.Count==0){
						TurnControl.OnFactionDestroyed();	//to track cd on ability and effect
						TBTK.OnFactionDestroyed(factionList[i].ID);
						
						factionList.RemoveAt(i);
						
						if(selectedFactionID>i) selectedFactionID-=1;
						else if(selectedFactionID==i) TurnControl.EndTurn();
					}
					break;
				}
			}
			
			//if there's only 1 faction remain (since faction with no active unit will be removed), then faction has won the game
			if(factionList.Count==1) GameControl.GameOver(factionList[0].ID);
		}