Example #1
0
        public static void ExitAbilityTargetMode()
        {
            if (!targetMode)
            {
                return;
            }

            TBTK.OnFactionABTargetMode();
            TBTK.OnUnitABTargetMode();                          //clear ability select mode for UI

            targetMode = false;

            instance.abilityIndex = 0;

            instance.targetModeTileList = new List <Tile>();

            OverlayManager.EnableTileCursor();
            OverlayManager.ClearAbilityTargetIndicator();
            OverlayManager.ClearAbilityRangeIndicator();

            GridManager.ClearTargetSelectMode();

            GameControl.ReselectUnit();

            if (instance.exitTargetCallBack != null)
            {
                instance.exitTargetCallBack();
            }

            TBTK.OnAbilityTargetMode(false);
        }
Example #2
0
		void Update() {
			
			invalidCursor=false;
			//cursorID=-1;
			cursorPosition=Input.mousePosition;
			
			if(Input.touchCount>1) invalidCursor=true;
			else if(Input.touchCount==1){
				cursorPosition=TBTK.GetFirstTouchPosition();
				//cursorID=0;
			}
			
			
			if(!invalidCursor){
				Tile newTile=GetTileOnCursor(cursorPosition);
				if(newTile!=hoveredTile){
					if(newTile==null && hoveredTile!=null) ClearHoveredTile();
					else{
						ClearHoveredTile();
						NewHoveredTile(newTile);
						
						//for debug
						//DebugDrawNeighbour(hoveredTile);
						//CoverSystem.GetCoverType(GameControl.GetSelectedUnit().tile, hoveredTile, true);
					}
				}
			}
		}
Example #3
0
		void _NewHoveredTile(Tile tile){
			hoveredTile=tile;
			
			if(AbilityManager.InTargetMode()){
				SetTargetModeHoveredTile(tile);
				return;
			}
			
			bool isWalkable=walkableTileList.Contains(tile);
			
			bool isSelectedUnitTile=GameControl.GetSelectedUnit()==null ? false : true;
			if(isSelectedUnitTile) isSelectedUnitTile=GameControl.GetSelectedUnit().tile!=tile ? false : true ;
			
			//show cover overlay if cover-system is enabled
			if(GameControl.EnableCover() && (isWalkable || isSelectedUnitTile)){
				OverlayManager.ShowCoverOverlay(tile);
			}
			
			//highlight potential target for the unit to be moved into this tile
			if(isWalkable && GameControl.GetSelectedUnit().CanAttack()){
				SetWalkableHostileList(tile);
			}
			
			TBTK.OnHoverTile(tile);
		}
Example #4
0
        public static bool HasObstacle(Tile tile1, Tile tile2)
        {
            Vector3 pos1 = tile1.GetPos();
            Vector3 pos2 = tile2.GetPos();

            float   dist      = Vector3.Distance(pos2, pos1);
            Vector3 dir       = (pos2 - pos1).normalized;
            Vector3 dirO      = new Vector3(-dir.z, 0, dir.x).normalized;
            float   posOffset = GridManager.GetTileSize() * GridManager.GetGridToTileSizeRatio() * 0.4f;

            LayerMask mask = 1 << TBTK.GetLayerObstacleFullCover() | 1 << TBTK.GetLayerObstacleHalfCover();

            if (Physics.Raycast(pos1, dir, dist, mask))
            {
                return(true);
            }
            if (Physics.Raycast(pos1 + dirO * posOffset, dir, dist, mask))
            {
                return(true);
            }
            if (Physics.Raycast(pos1 - dirO * posOffset, dir, dist, mask))
            {
                return(true);
            }

            return(false);
        }
Example #5
0
        //********************************************************************************************************************************
        //these section are related to FogOfWar

        //to set the visibility of the tile after checking fog-of-war
        public void SetVisible(bool flag)
        {
            if (forcedVisibleDuration.duration > 0 && !flag)
            {
                return;
            }

            visible = flag;
            if (fogOfWarObj != null)
            {
                fogOfWarObj.SetActive(!visible);
            }

            if (!flag)
            {
                if (unit != null)
                {
                    unit.gameObject.layer = TBTK.GetLayerUnitInvisible();
                    Utilities.SetLayerRecursively(unit.transform, TBTK.GetLayerUnitInvisible());
                }
            }
            else
            {
                if (unit != null)
                {
                    unit.gameObject.layer = TBTK.GetLayerUnit();
                    Utilities.SetLayerRecursively(unit.transform, TBTK.GetLayerUnit());
                }
            }
        }
Example #6
0
        public static void GainCurrency(int value)
        {
            instance.perkCurrency += value;

            TBTK.OnPerkCurrency(instance.perkCurrency);
            instance.SavePerkCurrency();
        }
Example #7
0
        public void _PerkUnlockNewAbility(List <int> unitIDList, int abID, int abIDSub)
        {
            int dbIndex = GetAbilityDBIndex(abID);

            if (dbIndex == -1 && abIDSub == -1)
            {
                return;
            }

            List <Unit> unitList = FactionManager.GetAllUnit();

            for (int i = 0; i < unitList.Count; i++)
            {
                Unit unit = unitList[i];
                if (unit.isAIUnit)
                {
                    continue;
                }

                if (unitIDList == null || unitIDList.Contains(unit.prefabID))
                {
                    int replaceIndex = -1;
                    if (abIDSub >= 0)
                    {
                        for (int n = 0; n < unit.abilityList.Count; n++)
                        {
                            if (unit.abilityList[n].prefabID == abIDSub)
                            {
                                replaceIndex = n;                               //cached the replaceIndex to be used for adding the new ability later
                                break;
                            }
                        }
                    }

                    if (dbIndex >= 0)                                                                                           //add the new ability
                    {
                        UnitAbility unitAbility = unitAbilityDBList[dbIndex].Clone();
                        unitAbility.Init(unit);
                        if (replaceIndex >= 0)                                                                          //if we need to replacing something that alreayd existed
                        {
                            unit.abilityIDList[replaceIndex] = abID;
                            unit.abilityList[replaceIndex]   = unitAbility;
                        }
                        else                                                                                                                    //otherwise just add the new ability
                        {
                            unit.abilityIDList.Add(abID);
                            unit.abilityList.Add(unitAbility);
                        }
                    }
                }
            }

            GameControl.ReselectUnit();                 //reselect current unit to refresh the UI

            if (dbIndex >= 0)
            {
                TBTK.OnNewUnitAbility(unitAbilityDBList[dbIndex].Clone());
            }
        }
Example #8
0
        public static void ClearSelectedUnit()
        {
            selectedUnit = null;
            GridManager.ClearAllTile();
            FactionManager.SelectUnit();

            TBTK.OnUnitSelected(null);
        }
Example #9
0
 //called to indicate that an action has been started, prevent any other action from starting
 public static void ActionCommenced()
 {
     if (actionInProgress == 0)
     {
         TBTK.OnGameInAction(true);
     }
     actionInProgress += 1;
 }
Example #10
0
        public static void SpendCurrency(int value)
        {
            instance.perkCurrency -= value;
            instance.perkCurrency  = Mathf.Max(0, instance.perkCurrency);

            TBTK.OnPerkCurrency(instance.perkCurrency);
            instance.SavePerkCurrency();
        }
Example #11
0
		public static Tile GetTileOnCursor(Vector3 cursorPos){
			LayerMask mask=1<<TBTK.GetLayerTile() | 1<<TBTK.GetLayerTerrain();
			Ray ray = Camera.main.ScreenPointToRay(cursorPos);
			RaycastHit hit;
			if(Physics.Raycast(ray, out hit, Mathf.Infinity, mask)){
				//Debug.Log(hit.collider.gameObject);
				return GetTileOnPos(hit.point);
			}
			return null;
		}
Example #12
0
 public static void ReselectUnit()
 {
     //Debug.Log("ReselectUnit");
     if (selectedUnit != null)
     {
         GridManager.SelectUnit(selectedUnit);
         FactionManager.SelectUnit();
         TBTK.OnUnitSelected(selectedUnit);
     }
 }
Example #13
0
		public void _UndeployUnit(Unit unit){
			if(!deployedUnitList.Contains(unit)) return;
			deployedUnitList.Remove(unit);
			unit.tile.unit=null;
			unit.tile=null;
			unit.gameObject.SetActive(false);
			if(deployingUnitID==0) factionList[deployingFactionID].startingUnitList.Add(unit);
			else factionList[deployingFactionID].startingUnitList.Insert(deployingUnitID-1, unit);
			//if(onUnitDeployedE!=null) onUnitDeployedE(null);
			TBTK.OnUnitDeployed(null);
		}
Example #14
0
 public void _StartGame()
 {
     if (turnMode == _TurnMode.FactionPerTurn && moveOrder != _MoveOrder.Free)
     {
         FactionManager.EndTurn_FactionPerTurn();
         TBTK.OnNewTurn(IsPlayerTurn());
     }
     else
     {
         EndTurn();
     }
 }
Example #15
0
		public static float GetAngleFromTileToCursor(Tile targetTile){
			float angle=0;
			LayerMask mask=1<<TBTK.GetLayerTile();
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			RaycastHit hit;
			if(Physics.Raycast(ray, out hit, Mathf.Infinity, mask)){
				Vector3 dir=(hit.point-targetTile.GetPos());
				if(GetTileType()==_TileType.Hex) angle=90-Utilities.VectorToAngle60(new Vector2(dir.x, dir.z));
				if(GetTileType()==_TileType.Square) angle=90-Utilities.VectorToAngle90(new Vector2(dir.x, dir.z));
			}
			return angle;
		}
Example #16
0
        IEnumerator _ActionCompleted(float delay = 0)
        {
            if (delay > 0)
            {
                yield return(new WaitForSeconds(delay));
            }
            actionInProgress = Mathf.Max(0, actionInProgress -= 1);
            //yield return null;

            if (actionInProgress == 0)
            {
                TBTK.OnGameInAction(false);
            }
        }
Example #17
0
        void Edit(Event current)
        {
            if (!enableEditing)
            {
                return;
            }
            if (rotatingView)
            {
                return;
            }

            LayerMask  mask = 1 << TBTK.GetLayerTile();
            Ray        ray  = HandleUtility.GUIPointToWorldRay(current.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask))
            {
                Tile tile = null;
                if (instance.gridColliderType == GridManager._GridColliderType.Individual)
                {
                    tile = hit.transform.gameObject.GetComponent <Tile>();
                }
                else if (instance.gridColliderType == GridManager._GridColliderType.Master)
                {
                    tile = instance._GetTileOnPos(hit.point);
                }

                if (tile == null)
                {
                    return;
                }

                Undo.RecordObject(tile, "tile");

                if (editMode == _EditMode.Tile)
                {
                    EditTileState(tile, current.button, hit.point);
                }
                else if (editMode == _EditMode.Unit)
                {
                    EditTileUnit(tile, current.button, hit.point);
                }
                else if (editMode == _EditMode.Collectible)
                {
                    EditTileCollectible(tile, current.button, hit.point);
                }

                EditorUtility.SetDirty(tile);
            }
        }
Example #18
0
		void _ClearHoveredTile(){
			if(hoveredTile!=null){
				ClearWalkableHostileList();
			}
			
			ShowHostileIndicator(attackableTileList);
			
			hoveredTile=null;
			
			OverlayManager.HideCoverOverlay();
			
			if(AbilityManager.InTargetMode()) ClearTargetModeHoveredTile();
			
			TBTK.OnHoverTile(null);
		}
Example #19
0
        public static void FitGridToTerrain(List <Tile> tileList, float baseHeight = 0)
        {
            LayerMask  mask = 1 << TBTK.GetLayerTerrain();
            RaycastHit hit;

            for (int i = 0; i < tileList.Count; i++)
            {
                Vector3 castPoint = tileList[i].GetPos();
                castPoint.y = 50;              //Mathf.Infinity;
                if (Physics.Raycast(castPoint, Vector3.down, out hit, Mathf.Infinity, mask))
                {
                    tileList[i].transform.position = hit.point + new Vector3(0, 0.05f, 0);
                }
            }
        }
Example #20
0
        //public static void AbilityTargetSelected(Tile tile){ instance._AbilityTargetSelected(tile); }
        public void AbilityTargetSelected(Tile tile)
        {
            if (targetModeTileList.Count > 0 && !targetModeTileList.Contains(tile))
            {
                GameControl.DisplayMessage("Out of Range");
                return;
            }

            bool invalidFlag = false;

            if (targetModeType == _TargetType.AllUnit)
            {
                invalidFlag = (tile.unit == null);
            }
            else if (targetModeType == _TargetType.HostileUnit)
            {
                int currentFacID = FactionManager.GetSelectedFactionID();
                invalidFlag = (tile.unit == null || tile.unit.factionID == currentFacID);
            }
            else if (targetModeType == _TargetType.FriendlyUnit)
            {
                int currentFacID = FactionManager.GetSelectedFactionID();
                invalidFlag = (tile.unit == null || tile.unit.factionID != currentFacID);
            }
            else if (targetModeType == _TargetType.EmptyTile)
            {
                invalidFlag = (tile.unit != null || !tile.walkable);
            }
            else if (targetModeType == _TargetType.AllTile)
            {
            }

            if (invalidFlag)
            {
                GameControl.DisplayMessage("Invalid target");
            }
            else
            {
                if (targetSelectedCallBack != null)
                {
                    targetSelectedCallBack(tile, abilityIndex);
                }

                TBTK.OnAbilityActivated();

                ExitAbilityTargetMode();
            }
        }
Example #21
0
        public void _ActivateTargetMode(int abIndex, int AOE, _TargetType type, TargetModeCallBack sCallBack, ExitTargetModeCallBack eCallBack)
        {
            GridManager.AbilityTargetSelectMode(this.AbilityTargetSelected, this.SetTargetModeHoveredTile, this.ClearTargetModeHoveredTile);

            targetMode   = true;
            abilityIndex = abIndex;

            targetModeAOE  = AOE;
            targetModeType = type;

            targetSelectedCallBack = sCallBack;
            exitTargetCallBack     = eCallBack;

            OverlayManager.DisableTileCursor();

            TBTK.OnAbilityTargetMode(true);
        }
Example #22
0
        public static void GameOver(int factionID)
        {
            if (FactionManager.IsPlayerFaction(factionID))
            {
                PerkManager.GainPerkCurrencyOnVictory();
            }

            //if(onGameMessageE!=null) onGameMessageE("GameOver");
            TBTK.OnGameMessage("GameOver");

            gamePhase = _GamePhase.Over;

            FactionManager.GameOver();

            //if(onGameOverE!=null) onGameOverE(factionID);
            TBTK.OnGameOver(factionID);
        }
Example #23
0
        public IEnumerator _EndTurn()
        {
            if (GameControl.GetGamePhase() == _GamePhase.Over)
            {
                yield break;
            }

            yield return(new WaitForSeconds(0.2f));

            currentTurnID += 1;

            if (turnMode == _TurnMode.FactionPerTurn)
            {
                if (moveOrder == _MoveOrder.Free)
                {
                    FactionManager.EndTurn_FactionPerTurn();
                }
                else
                {
                    if (FactionManager.SelectNextUnitInFaction_NotFree())
                    {
                        TBTK.OnNewTurn(IsPlayerTurn());
                        yield break;
                    }
                    else
                    {
                        FactionManager.EndTurn_FactionPerTurn();
                    }
                }
            }
            else if (turnMode == _TurnMode.FactionUnitPerTurn)
            {
                CheckPlayerMoveFlag(false);
                FactionManager.EndTurn_FactionUnitPerTurn();
            }

            IterateEndTurn();
            if (turnMode == _TurnMode.UnitPerTurn)
            {
                FactionManager.EndTurn_UnitPerTurn();
            }


            TBTK.OnNewTurn(IsPlayerTurn());
        }
Example #24
0
		public void AutoDeployFaction(int factionID=-1){
			if(factionID==-1) factionID=deployingFactionID;
			
			bool setToInvisible=GameControl.EnableFogOfWar() & !factionList[factionID].isPlayerFaction;
			
			List<Unit> unitList=factionList[factionID].startingUnitList;
			List<Tile> tileList=GridManager.GetDeployableTileList(factionList[factionID].ID);
			
			for(int i=0; i<tileList.Count; i++){
				if(!tileList[i].walkable || tileList[i].unit!=null || tileList[i].obstacleT!=null){ 
					tileList.RemoveAt(i);		i-=1;
				}
			}
			
			int count=0;
			for(int i=0; i<unitList.Count; i++){
				if(tileList.Count==0) break;
				Unit unit=unitList[i];
				
				int rand=Random.Range(0, tileList.Count);
				Tile tile=tileList[rand];
				tileList.RemoveAt(rand);
				tile.unit=unit;
				unit.tile=tile;
				unit.transform.position=tile.GetPos();
				unit.transform.rotation = Quaternion.Euler(0, factionList[factionID].spawnDirection, 0);
				unit.gameObject.SetActive(true);
				
				deployedUnitList.Add(unit);
				
				if(setToInvisible && !tile.IsVisible()){
					unit.gameObject.layer=TBTK.GetLayerUnitInvisible();
					Utilities.SetLayerRecursively(unit.transform, TBTK.GetLayerUnitInvisible());
				}
				
				count+=1;
				
				unit.factionID=factionList[factionID].ID;
			}
			
			for(int i=0; i<count; i++) unitList.RemoveAt(0);
			
			TBTK.OnUnitDeployed(null);
		}
Example #25
0
		public void _CompleteDeployment(){
			if(!_IsDeploymentComplete()) return;
			
			for(int i=0; i<deployedUnitList.Count; i++){
				deployedUnitList[i].factionID=factionList[deployingFactionID].ID;
				factionList[deployingFactionID].allUnitList.Add(deployedUnitList[i]);
			}
			
			deployedUnitList=new List<Unit>();
			deployingUnitID=-1;	
			
			GridManager.FactionDeploymentComplete();
			
			//iterate thru all faction, get the next faction needs unit deployment
			for(int i=deployingFactionID+1; i<factionList.Count; i++){
				if(factionList[i].startingUnitList.Count>0){
					if(factionList[i].isPlayerFaction){
						deployingFactionID=i;
						deployingUnitID=0;	//set to >=0 to indicate there's a player faction needs deployment
						break;
					}
					else{	//if it's an AI faction, automatically deploy it
						AutoDeployFaction(i);
						
						for(int n=0; n<deployedUnitList.Count; n++){
							//deployedUnitList[n].factionID=factionList[i].ID;
							factionList[i].allUnitList.Add(deployedUnitList[n]);
						}
					}
				}
			}
			
			if(deployingUnitID==-1){	//no more faction needs deloyment, start the game
				GameControl.StartGame();
				//if(onUnitDeploymentPhaseE!=null) onUnitDeploymentPhaseE(false);
				TBTK.OnUnitDeployment(false);
			}
			else{							//another player's faction needs deloyment, initiate the process
				GridManager.DeployingFaction(deployingFactionID);
				//if(onUnitDeploymentPhaseE!=null) onUnitDeploymentPhaseE(true);
				TBTK.OnUnitDeployment(true);
			}
		}
Example #26
0
        //call by unit when all action is depleted
        public static void SelectedUnitMoveDepleted()
        {
            if (GameControl.GetGamePhase() == _GamePhase.Over)
            {
                return;
            }

            if (instance.turnMode == _TurnMode.FactionPerTurn)
            {
                //if not in free move order, cant switch to next unit without end turn
                if (instance.moveOrder != _MoveOrder.Free)
                {
                    TBTK.OnAllUnitOutOfMove();
                    if (GameControl.GetSelectedUnit().HP <= 0)
                    {
                        instance.StartCoroutine(instance.AutoEndTurn());
                    }
                }
                else
                {
                    if (!FactionManager.SelectNextUnitInFaction_Free())
                    {
                        TBTK.OnAllUnitOutOfMove();
                    }
                }
            }
            else if (instance.turnMode == _TurnMode.FactionUnitPerTurn)
            {
                TBTK.OnAllUnitOutOfMove();
                if (GameControl.GetSelectedUnit().HP <= 0)
                {
                    instance.StartCoroutine(instance.AutoEndTurn());
                }
            }
            else if (instance.turnMode == _TurnMode.UnitPerTurn)
            {
                TBTK.OnAllUnitOutOfMove();
                if (GameControl.GetSelectedUnit().HP <= 0)
                {
                    instance.StartCoroutine(instance.AutoEndTurn());
                }
            }
        }
Example #27
0
        public void CheckDiagonal()
        {
            LayerMask mask = 1 << TBTK.GetLayerObstacleHalfCover() | 1 << TBTK.GetLayerObstacleFullCover();

            List <Tile> neighbourList = new List <Tile>(aStar.GetNeighbourList());

            for (int n = 0; n < neighbourList.Count; n++)
            {
                Vector3 dir    = neighbourList[n].GetPos() - GetPos();
                float   angleN = Utilities.Vector2ToAngle(new Vector2(dir.x, dir.z));

                if (angleN % 90 != 0)
                {
                    if (Physics.Linecast(GetPos(), neighbourList[n].GetPos(), mask))
                    {
                        aStar.DisconnectNeighbour(neighbourList[n]);
                    }
                }
            }
        }
Example #28
0
		public void _DeployUnitOnTile(Tile tile){
			if(tile.deployAreaID!=factionList[deployingFactionID].ID) return;
			if(factionList[deployingFactionID].startingUnitList.Count<=0) return;
			Unit unit=factionList[deployingFactionID].startingUnitList[deployingUnitID];
			deployedUnitList.Add(unit);
			tile.unit=unit;
			unit.tile=tile;
			
			unit.transform.position=tile.GetPos();
			unit.transform.rotation=Quaternion.Euler(0, factionList[deployingFactionID].spawnDirection, 0);
			
			unit.gameObject.SetActive(true);
			factionList[deployingFactionID].startingUnitList.RemoveAt(deployingUnitID);
			if(factionList[deployingFactionID].startingUnitList.Count<=0) deployingUnitID=0;
			else{
				if(deployingUnitID>=factionList[deployingFactionID].startingUnitList.Count) deployingUnitID-=1;
			}
			//if(onUnitDeployedE!=null) onUnitDeployedE(null);
			TBTK.OnUnitDeployed(null);
		}
Example #29
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 #30
0
        public static void SelectUnit(Unit unit, bool userInitiated = true)
        {
            if (userInitiated && !CanSelectUnit(unit))
            {
                return;
            }

            if (selectedUnit == unit)
            {
                Debug.Log("attempt to select the same unit");
                return;
            }

            selectedUnit = unit;
            GridManager.SelectUnit(unit);
            FactionManager.SelectUnit();

            selectedUnit.PlaySelectAudio();

            TBTK.OnUnitSelected(selectedUnit);
        }