Example #1
0
        //when a unit completes it's move, put an unused indicator on the unit tile
        //this will only be called if the unit in question is player unit
        private void OnUnitMoveDepleted(Unit unit)
        {
            if (TurnControl.GetTurnMode() != _TurnMode.FactionPerTurn)
            {
                return;
            }

            int index = -1;

            for (int i = 0; i < movedIndicatorList.Count; i++)
            {
                if (movedIndicatorList[i].gameObject.activeInHierarchy)
                {
                    index = i;
                    break;                    //continue;
                }
            }

            if (index == -1)
            {
                Transform moveIndicatorT = (Transform)Instantiate(movedIndicatorList[0]);
                moveIndicatorT.parent = transform;
                movedIndicatorList.Add(moveIndicatorT);
                index = movedIndicatorList.Count - 1;
            }

            movedIndicatorList[index].position = unit.tile.GetPos();
            movedIndicatorList[index].gameObject.SetActive(true);
        }
Example #2
0
		void _SetupFaction(){
			for(int i=0; i<factionList.Count; i++){
				if(factionList[i].isPlayerFaction){
					playerFactionIDList.Add(factionList[i].ID);
					
					for(int n=0; n<factionList[i].allUnitList.Count; n++){
						UpdateHostileUnitTriggerStatus(factionList[i].allUnitList[n]);
					}
				}
				
				if(TurnControl.GetTurnMode()!=_TurnMode.UnitPerTurn){
					if(TurnControl.GetMoveOrder()!=_MoveOrder.Random){
						factionList[i].allUnitList=ArrangeUnitListToMovePriority(factionList[i].allUnitList);
					}
				}
				
				factionList[i].NewTurn(true);	//pass true to call new turn on all unit
				//for(int n=0; n<factionList[i].allUnitList.Count; n++) factionList[i].allUnitList[n].ResetUnitTurnData();
				
				totalUnitCount+=factionList[i].allUnitList.Count;
			}
			
			if(factionList.Count==playerFactionIDList.Count) hasAIInGame=false;
			
			Debug.Log("SetupFaction  "+TurnControl.GetTurnMode());
			if(TurnControl.GetTurnMode()==_TurnMode.UnitPerTurn){
				for(int i=0; i<factionList.Count; i++){
					for(int n=0; n<factionList[i].allUnitList.Count; n++) allUnitList.Add(factionList[i].allUnitList[n]);
				}
				
				allUnitList=ArrangeUnitListToMovePriority(allUnitList);
				Debug.Log("SetupFaction  allUnitList");
			}
			
		}
Example #3
0
 void OnFactionDestroyed(int facID)
 {
     if (TurnControl.GetTurnMode() == _TurnMode.UnitPerTurn)
     {
         return;
     }
     IterateDuration();
 }
Example #4
0
 void OnUnitDestroyed(Unit unit)
 {
     if (TurnControl.GetTurnMode() != _TurnMode.UnitPerTurn)
     {
         return;
     }
     IterateDuration();
 }
Example #5
0
 public static void OnUnitDestroyed()
 {
     if (TurnControl.GetTurnMode() != _TurnMode.UnitPerTurn)
     {
         return;
     }
     instance.IterateEndTurn();
 }
Example #6
0
		public void _UnitMoveDepleted(Unit unit){
			if(TurnControl.GetTurnMode()!=_TurnMode.FactionPerTurn){
				for(int i=0; i<factionList.Count; i++){
					if(factionList[i].ID==unit.factionID){
						factionList[i].UnitMoveDepleted(unit);
					}
				}
			}
		}
Example #7
0
		public List<Unit> _GetAllUnit(){
			if(TurnControl.GetTurnMode()==_TurnMode.UnitPerTurn) return allUnitList;
			else{
				List<Unit> list=new List<Unit>();
				for(int i=0; i<factionList.Count; i++){
					for(int n=0; n<factionList[i].allUnitList.Count; n++) list.Add(factionList[i].allUnitList[n]);
				}
				return list;
			}
		}
Example #8
0
 private void ResetTurnCounter()
 {
     if (TurnControl.GetTurnMode() == _TurnMode.UnitPerTurn)
     {
         turnCounter = FactionManager.GetTotalUnitCount();
     }
     else
     {
         turnCounter = FactionManager.GetTotalFactionCount();
     }
 }
Example #9
0
		public void _UnitTurnPriorityChanged(List<int> facIDList){
			if(TurnControl.GetTurnMode()==_TurnMode.UnitPerTurn){
				allUnitList=ArrangeUnitListToMovePriority(allUnitList);
			}
			else if(TurnControl.GetMoveOrder()!=_MoveOrder.Random){
				for(int i=0; i<factionList.Count; i++){
					if(facIDList.Contains(factionList[i].ID)){
						factionList[i].allUnitList=ArrangeUnitListToMovePriority(factionList[i].allUnitList);
					}
				}
			}
		}
Example #10
0
        //new turn, clear all indicator
        private void OnNewTurn()
        {
            if (TurnControl.GetTurnMode() != _TurnMode.FactionPerTurn)
            {
                return;
            }

            for (int i = 0; i < movedIndicatorList.Count; i++)
            {
                movedIndicatorList[i].gameObject.SetActive(false);
            }
        }
Example #11
0
 public static bool CanSelectUnit(Unit unit)
 {
     if (TurnControl.GetMoveOrder() != _MoveOrder.Free)
     {
         return(false);
     }
     if (TurnControl.GetTurnMode() == _TurnMode.FactionUnitPerTurn && TurnControl.HasMoved())
     {
         return(false);
     }
     if (TurnControl.GetTurnMode() == _TurnMode.UnitPerTurn)
     {
         return(false);
     }
     if (FactionManager.GetSelectedFactionID() != unit.factionID)
     {
         return(false);
     }
     return(true);
 }
        //for FactionPerTurn mode, breakWhenExceedLimit is set to true, where selectUnitID resets when it reachs end
        //for FactionUnitPerTurn mode, breakWhenExceedLimit is set to false, where selectUnitID loops forever
        public bool SelectNextUnitInQueue(bool breakWhenExceedLimit = false)
        {
            //if(TurnControl.GetMoveOrder()==_MoveOrder.Free) return true;

            selectedUnitID += 1;

            //skipped stunned unit
            //while(allUnitList[selectedUnitID].IsStunned()){
            //	selectedUnitID+=1;
            //	if(selectedUnitID>=allUnitList.Count) break;
            //}
            if (selectedUnitID >= allUnitList.Count)
            {
                if (breakWhenExceedLimit)                       //for FactionPerTurn mode, reset the ID
                {
                    selectedUnitID = -1;
                    return(true);
                }
                selectedUnitID = 0;
            }

            if (TurnControl.GetTurnMode() != _TurnMode.FactionPerTurn)
            {
                bool isUnitActive = allUnitList[selectedUnitID].NewTurn();                      //in case unit is destroyed by damage over time effect
                if (!isUnitActive)
                {
                    return(SelectNextUnitInQueue());
                }
            }

            if (allUnitList[selectedUnitID].isAIUnit)
            {
                AIManager.MoveUnit(allUnitList[selectedUnitID]);
            }
            else
            {
                GameControl.SelectUnit(allUnitList[selectedUnitID], false);
            }

            return(false);
        }
Example #13
0
		public void _InsertUnit(Unit unit, int factionID=0){ 
			unit.factionID=factionID;

			unit.InitUnitAbility();
			
			for(int i=0; i<factionList.Count; i++){
				if(factionList[i].ID==factionID){
					factionList[i].allUnitList.Add(unit);
					unit.isAIUnit=!factionList[i].isPlayerFaction;
				}
			}
			
			if(TurnControl.GetTurnMode()==_TurnMode.UnitPerTurn) allUnitList.Add(unit);
			
			_UnitTurnPriorityChanged( new List<int>{ unit.factionID} );
			
			unit.UpdateVisibility();
			
			//if(onInsertUnitE!=null) onInsertUnitE(unit);
			TBTK.OnNewUnit(unit);
		}
Example #14
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);
		}
        //called by FactionManager.SelectNextFaction in FactionPerTurn mode (resetSelectedID=true)
        public void NewTurn(bool processUnit = false)
        {
            selectedUnitID = -1;
            movedUnitList  = new List <Unit>();

            if (abilityInfo != null)
            {
                abilityInfo.energy = Mathf.Min(abilityInfo.energy + abilityInfo.energyGainPerTurn, abilityInfo.energyFull);
            }

            if (processUnit)
            {
                for (int i = 0; i < allUnitList.Count; i++)
                {
                    allUnitList[i].NewTurn();
                }
            }

            if (TurnControl.GetTurnMode() == _TurnMode.UnitPerTurn)
            {
                return;
            }

            if (TurnControl.GetMoveOrder() == _MoveOrder.Random)
            {
                //random order, shuffle the unit order
                List <Unit> newList = new List <Unit>();
                while (allUnitList.Count > 0)
                {
                    int rand = Random.Range(0, allUnitList.Count);
                    newList.Add(allUnitList[rand]);
                    allUnitList.RemoveAt(rand);
                }
                allUnitList = newList;
            }
        }
Example #16
0
        public void Init()
        {
            if (init)
            {
                return;
            }
            init = true;

            thisT = transform;

            Transform deploymentIndicator = null;
            Transform moveableIndicator   = null;
            Transform hostileIndicator    = null;
            Transform abRangeIndicator    = null;
            Transform abTargetIndicator   = null;

            if (GridManager.GetTileType() == _TileType.Hex)
            {
                deploymentIndicator = hexDeployment;
                moveableIndicator   = hexMoveable;
                hostileIndicator    = hexHostile;
                abRangeIndicator    = hexAbRange;
                abTargetIndicator   = hexAbTarget;
                cursorIndicatorF    = (Transform)Instantiate(hexCursorF);
                cursorIndicatorH    = (Transform)Instantiate(hexCursorH);
                selectIndicator     = (Transform)Instantiate(hexSelected);
            }
            else if (GridManager.GetTileType() == _TileType.Square)
            {
                deploymentIndicator = sqDeployment;
                moveableIndicator   = sqMoveable;
                hostileIndicator    = sqHostile;
                abRangeIndicator    = sqAbRange;
                abTargetIndicator   = sqAbTarget;
                cursorIndicatorF    = (Transform)Instantiate(sqCursorF);
                cursorIndicatorH    = (Transform)Instantiate(sqCursorH);
                selectIndicator     = (Transform)Instantiate(sqSelected);
            }


            cursorIndicatorF.parent = thisT;
            cursorIndicatorH.parent = thisT;
            selectIndicator.parent  = thisT;


            for (int i = 0; i < 20; i++)
            {
                deploymentIndicatorList.Add((Transform)Instantiate(deploymentIndicator));
                deploymentIndicatorList[i].gameObject.SetActive(false);
                deploymentIndicatorList[i].parent = thisT;
            }
            for (int i = 0; i < 20; i++)
            {
                moveableIndicatorList.Add((Transform)Instantiate(moveableIndicator));
                moveableIndicatorList[i].gameObject.SetActive(false);
                moveableIndicatorList[i].parent = thisT;
            }
            for (int i = 0; i < 10; i++)
            {
                hostileIndicatorList.Add((Transform)Instantiate(hostileIndicator));
                hostileIndicatorList[i].gameObject.SetActive(false);
                hostileIndicatorList[i].parent = thisT;
            }

            for (int i = 0; i < 20; i++)
            {
                abRangeIndicatorList.Add((Transform)Instantiate(abRangeIndicator));
                abRangeIndicatorList[i].gameObject.SetActive(false);
                abRangeIndicatorList[i].parent = thisT;
            }
            for (int i = 0; i < 20; i++)
            {
                abTargetIndicatorList.Add((Transform)Instantiate(abTargetIndicator));
                abTargetIndicatorList[i].gameObject.SetActive(false);
                abTargetIndicatorList[i].parent = thisT;
            }


            if (TurnControl.GetTurnMode() == _TurnMode.FactionPerTurn)
            {
                //create the moved indicator
                for (int i = 0; i < 10; i++)
                {
                    movedIndicatorList.Add((Transform)Instantiate(movedIndicator));
                    movedIndicatorList[i].gameObject.SetActive(false);
                    movedIndicatorList[i].parent = thisT;
                }
            }


            if (GameControl.EnableFogOfWar())
            {
                Transform fogObj = null;

                if (GridManager.GetTileType() == _TileType.Hex)
                {
                    fogObj = hexFogObj;
                }
                else if (GridManager.GetTileType() == _TileType.Square)
                {
                    fogObj = sqFogObj;
                }

                List <Tile> tileList = GridManager.GetTileList();
                for (int i = 0; i < tileList.Count; i++)
                {
                    //if(!tileList[i].walkable) continue;
                    tileList[i].SetFogOfWarObj((Transform)Instantiate(fogObj));
                }
            }

            if (GameControl.EnableCover())
            {
                float scaleOffset = GridManager.GetTileType() == _TileType.Hex ? 0.5f : 0.8f;
                float tileSize    = GridManager.GetTileSize();

                for (int i = 0; i < 5; i++)
                {
                    coverOverlayHList.Add((Transform)Instantiate(coverOverlayH));
                    coverOverlayFList.Add((Transform)Instantiate(coverOverlayF));

                    coverOverlayHList[i].localScale *= tileSize * scaleOffset;
                    coverOverlayHList[i].parent      = thisT;
                    coverOverlayHList[i].gameObject.SetActive(false);

                    coverOverlayFList[i].localScale *= tileSize * scaleOffset;
                    coverOverlayFList[i].parent      = thisT;
                    coverOverlayFList[i].gameObject.SetActive(false);
                }
            }
        }