Ejemplo n.º 1
0
        public bool SelectRandomAvailableUnit()
        {
            List <int> availableIDList = new List <int>();

            for (int i = 0; i < allUnitList.Count; i++)
            {
                if (!allUnitList[i].IsAllActionCompleted() && !allUnitList[i].IsStunned())
                {
                    availableIDList.Add(i);
                }
            }

            if (availableIDList.Count > 0)
            {
                selectedUnitID = availableIDList[Random.Range(0, availableIDList.Count)];
                Debug.Log("selectedUnitID " + selectedUnitID);
                if (allUnitList[selectedUnitID].isAIUnit)
                {
                    AIManager.MoveUnit(allUnitList[selectedUnitID]);
                }
                else
                {
                    GameControl.SelectUnit(allUnitList[selectedUnitID], false);
                }
                //GameControl.SelectUnit(allUnitList[selectedUnitID]);
                return(true);
            }

            GameControl.ClearSelectedUnit();

            return(false);
        }
Ejemplo n.º 2
0
        //loop through all unit, select the first one that hasnt complete all action
        //used in FactionPerTurn, FreeMove order only
        public bool SelectFirstAvailableUnit()
        {
            int index = -1;

            for (int i = 0; i < allUnitList.Count; i++)
            {
                //skipped stunned unit
                //if(!allUnitList[i].IsAllActionCompleted() && allUnitList[i].IsStunned()){
                if (!allUnitList[i].IsAllActionCompleted())
                {
                    index = i;                break;
                }
            }

            if (index >= 0)
            {
                selectedUnitID = index;
                GameControl.SelectUnit(allUnitList[selectedUnitID]);
                return(true);
            }

            GameControl.ClearSelectedUnit();

            return(false);
        }
Ejemplo n.º 3
0
		public void _OnTile(Tile tile){
			if(!FactionManager.IsPlayerTurn()) return;
			
			if(tile.unit!=null){
				if(attackableTileList.Contains(tile)) GameControl.GetSelectedUnit().Attack(tile.unit);
				else GameControl.SelectUnit(tile.unit);
			}
			//if the tile is within the move range of current selected unit, move to it
			else if(walkableTileList.Contains(tile)){
				ClearWalkableHostileList();	//in case the unit move into the destination and has insufficient ap to attack
				GameControl.GetSelectedUnit().Move(tile);
			}
			
			ClearHoveredTile();	//clear the hovered tile so all the UI overlay will be cleared
		}
Ejemplo n.º 4
0
        //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);
        }
Ejemplo n.º 5
0
		public void _EndTurn_UnitPerTurn(){
			selectedUnitID+=1;
			if(selectedUnitID>=allUnitList.Count) selectedUnitID=0;
			
			selectedFactionID=allUnitList[selectedUnitID].factionID;
			
			bool isUnitActive=allUnitList[selectedUnitID].NewTurn();	//in case unit is destroyed by damage over time effect
			if(isUnitActive){
				// Debug.LogWarning(allUnitList[selectedUnitID].unitName + " "  + allUnitList[selectedUnitID].canDrawCards);
				if (allUnitList[selectedUnitID].canDrawCards) {
					Unit.AbilitySelection abilitySelection = Unit.DrawCard(allUnitList.Where(u => u.factionID == selectedFactionID).ToList());
					if (abilitySelection != null){
						abilitySelection.cardOwner.AddAbility(abilitySelection.abilityId);
					}
				}
			} else {
				_EndTurn_UnitPerTurn();
				return;
			}
			
			if(allUnitList[selectedUnitID].isAIUnit) AIManager.MoveUnit(allUnitList[selectedUnitID]);
			else GameControl.SelectUnit(allUnitList[selectedUnitID], false);
		}
Ejemplo n.º 6
0
        IEnumerator _ApplyAbilityEffect(Tile targetTile, Ability ability, int type, Unit srcUnit = null, float critMult = 1.0f)
        {
            if (targetTile != null && ability.effectObject != null)
            {
                if (!ability.autoDestroyEffect)
                {
                    ObjectPoolManager.Spawn(ability.effectObject, targetTile.GetPos(), Quaternion.identity);
                }
                else
                {
                    ObjectPoolManager.Spawn(ability.effectObject, targetTile.GetPos(), Quaternion.identity, ability.effectObjectDuration);
                }
            }

            if (!ability.useDefaultEffect)
            {
                yield break;
            }
            if (ability.effectDelayDuration > 0)
            {
                yield return(new WaitForSeconds(ability.effectDelayDuration));
            }

            if (type == 1)              //_AbilityType.Generic

            {
                List <Tile> tileList = new List <Tile>();
                if (targetTile != null)
                {
                    if (ability.aoeRange > 0)
                    {
                        tileList = GridManager.GetTilesWithinDistance(targetTile, ability.aoeRange);
                    }
                    tileList.Add(targetTile);
                }
                else
                {
                    if (ability.effTargetType == _EffectTargetType.Tile)
                    {
                        tileList = GridManager.GetTileList();
                    }
                    else
                    {
                        List <Unit> unitList = FactionManager.GetAllUnit();
                        for (int i = 0; i < unitList.Count; i++)
                        {
                            tileList.Add(unitList[i].tile);
                        }
                    }
                }

                if (ability.effTargetType == _EffectTargetType.AllUnit)
                {
                    for (int i = 0; i < tileList.Count; i++)
                    {
                        if (tileList[i].unit == null)
                        {
                            continue;
                        }
                        tileList[i].unit.ApplyEffect(ability.CloneEffect(critMult), srcUnit);
                        SpawnEffectObjTarget(ability, tileList[i]);
                    }
                }
                else if (ability.effTargetType == _EffectTargetType.HostileUnit)
                {
                    for (int i = 0; i < tileList.Count; i++)
                    {
                        if (tileList[i].unit == null)
                        {
                            continue;
                        }
                        if (tileList[i].unit.factionID == ability.factionID)
                        {
                            continue;
                        }
                        tileList[i].unit.ApplyEffect(ability.CloneEffect(critMult), srcUnit);
                        SpawnEffectObjTarget(ability, tileList[i]);
                    }
                }
                else if (ability.effTargetType == _EffectTargetType.FriendlyUnit)
                {
                    for (int i = 0; i < tileList.Count; i++)
                    {
                        if (tileList[i].unit == null)
                        {
                            continue;
                        }
                        if (tileList[i].unit.factionID != ability.factionID)
                        {
                            continue;
                        }
                        tileList[i].unit.ApplyEffect(ability.CloneEffect(critMult), srcUnit);
                        SpawnEffectObjTarget(ability, tileList[i]);
                    }
                }
                else if (ability.effTargetType == _EffectTargetType.Tile)
                {
                    for (int i = 0; i < tileList.Count; i++)
                    {
                        tileList[i].ApplyEffect(ability.CloneEffect(critMult));
                        SpawnEffectObjTarget(ability, tileList[i]);
                    }
                }
            }
            else if (type == 2)                 //_AbilityType.SpawnNew
            {
                Quaternion rot     = srcUnit != null ? srcUnit.thisT.rotation : Quaternion.identity;
                GameObject unitObj = (GameObject)Instantiate(ability.spawnUnit.gameObject, targetTile.GetPos(), rot);
                Unit       unit    = unitObj.GetComponent <Unit>();

                unitObj.transform.position = targetTile.GetPos();
                if (srcUnit != null)
                {
                    unitObj.transform.rotation = srcUnit.thisT.rotation;
                }
                else
                {
                    Faction faction = FactionManager.GetFaction(ability.factionID);
                    if (faction != null)
                    {
                        unitObj.transform.rotation = Quaternion.Euler(0, faction.spawnDirection, 0);
                    }
                }

                FactionManager.InsertUnit(unit, ability.factionID);
                unit.SetNewTile(targetTile);
                //if(GridManager.GetDistance(targetTile, srcUnit.tile)<=srcUnit.GetMoveRange()) GameControl.SelectUnit(srcUnit);
            }
            else if (type == 3)                 //_AbilityType.ScanFogOfWar)
            {
                List <Tile> targetTileList = GridManager.GetTilesWithinDistance(targetTile, ability.GetAOERange());
                targetTileList.Add(targetTile);
                for (int i = 0; i < targetTileList.Count; i++)
                {
                    targetTileList[i].ForceVisible(ability.effect.duration);
                }
            }
            else if (type == 4)                 //_AbilityType.Overwatch
            {
                targetTile.unit.Overwatch(ability.CloneEffect(critMult));
            }
            else if (type == 5)                 //_AbilityType.Teleport
            {
                Quaternion wantedRot = Quaternion.LookRotation(targetTile.GetPos() - ability.unit.tile.GetPos());
                ability.unit.thisT.rotation = wantedRot;

                GameControl.ClearSelectedUnit();
                ability.unit.SetNewTile(targetTile);
                GameControl.SelectUnit(srcUnit);
            }



            else if (type == 6)                 //charge attack
            {
                List <Tile> tileList = GridManager.GetTilesInALine(srcUnit.tile, targetTile, ability.GetRange());

                for (int i = 0; i < tileList.Count; i++)
                {
                    while (true)
                    {
                        float dist = Vector3.Distance(srcUnit.thisT.position, tileList[i].GetPos());
                        if (dist < 0.05f)
                        {
                            if (tileList[i].unit != null)
                            {
                                tileList[i].unit.ApplyEffect(ability.CloneEffect(critMult));
                                SpawnEffectObjTarget(ability, tileList[i]);
                            }
                            break;
                        }

                        Quaternion wantedRot = Quaternion.LookRotation(tileList[i].GetPos() - srcUnit.thisT.position);
                        srcUnit.thisT.rotation = Quaternion.Slerp(srcUnit.thisT.rotation, wantedRot, Time.deltaTime * srcUnit.moveSpeed * 6);

                        Vector3 dir = (tileList[i].GetPos() - srcUnit.thisT.position).normalized;
                        srcUnit.thisT.Translate(dir * Mathf.Min(srcUnit.moveSpeed * 2 * Time.deltaTime, dist), Space.World);
                        yield return(null);
                    }
                }

                srcUnit.tile.unit = null;
                srcUnit.tile      = tileList[tileList.Count - 1];
                tileList[tileList.Count - 1].unit = srcUnit;
                GameControl.ReselectUnit();
            }
            else if (type == 7)                 //attack all unit in a straight line
            {
                List <Tile> tileList = GridManager.GetTilesInALine(srcUnit.tile, targetTile, ability.GetRange());
                for (int i = 0; i < tileList.Count; i++)
                {
                    if (tileList[i].unit == null)
                    {
                        continue;
                    }
                    tileList[i].unit.ApplyEffect(ability.CloneEffect(critMult));
                    SpawnEffectObjTarget(ability, tileList[i]);
                }
            }
            else
            {
                Debug.LogWarning("Error, unknown ability type (" + type + ")");
            }

            yield return(null);
        }