Exemple #1
0
        public override IEnumerator MoveTo(MultiTile newPosition)
        {
            finalPosition = newPosition;
            Queue <MultiTile> path = Pathfinder.instance.GetPathFromTo(myUnit, newPosition);

            if (myUnit.IsExittingCombat(newPosition))
            {
                myUnit.ExitCombat();
                int health = myUnit.statistics.healthPoints;
                foreach (Tile neighbour in myUnit.currentPosition.closeNeighbours)
                {
                    if (myUnit.IsAlive() && neighbour.GetMyObject <Unit>() != null && myUnit.IsEnemyOf(neighbour.GetMyObject <Unit>()))
                    {
                        int damage = DamageCalculator.CalculateDamage(neighbour.GetMyObject <Unit>(), myUnit, 1.5f);
                        neighbour.GetMyObject <Unit>().Backstab(myUnit, damage);
                        health -= damage;
                    }
                }
                if (health > 0)
                {
                    //THe attacks will not kill us, cause calculated :P
                }
                else
                {
                    //rip, abort.
                    yield break;
                }
            }

            BattlescapeGraphics.ColouringTool.UncolourAllTiles();
            PlayMovementAnimation();
            int tileCount = path.Count;

            for (int i = 0; i < tileCount; ++i)
            {
                MultiTile temporaryGoal = path.Dequeue();
                myUnit.OnMove(myUnit.currentPosition, temporaryGoal);
                myUnit.TryToSetMyPositionTo(temporaryGoal);
                //I am aware, that for now we are still just turning into a direction in one frame. If we ever want it any other way, it needs a bit of work to set it otherwise so im not doing it now :D.
                //if we want to slowly turn, we need to ask if we already turned, and if not we turn and if yes we move here.
                TurnTowards(temporaryGoal.center);
                while (Vector3.Distance(myUnit.transform.position, temporaryGoal.center) > 0.0001f)
                {
                    myUnit.transform.position = Vector3.MoveTowards(myUnit.transform.position, temporaryGoal.center, visualSpeed * Time.deltaTime);
                    yield return(null);
                }
                temporaryGoal.SetMyObjectTo(myUnit);
            }
            StopMovementAnimation();
            PlayerInput.instance.isInputBlocked = false;
            if (newPosition.IsProtectedByEnemyOf(myUnit))
            {
                myUnit.statistics.movementPoints = 0;
            }
            else
            {
                myUnit.statistics.movementPoints -= tileCount - 1;
            }
            BattlescapeGraphics.ColouringTool.ColourLegalTilesFor(myUnit);
        }
Exemple #2
0
        //Played BEFORE the first step in the whole movement. Check for ExitCombat here cause it only makes sense here.
        //Returns true if movement is exiting combat
        public bool IsExittingCombat(MultiTile newPosition)
        {
            if (newPosition.IsProtectedByEnemyOf(this))
            {
                return(false);
            }
            if (currentPosition.IsProtectedByEnemyOf(this))
            {
                return(true);
            }

            return(false);
        }
Exemple #3
0
 public void OnTileToMoveHovered(Unit unitToMove, MultiTile targetTile)
 {
     if (targetTile.IsProtectedByEnemyOf(unitToMove))
     {
         SetCursorTo(enterCombatCursor, clickingEnterCombatCursor);
     }
     else if (unitToMove.IsInCombat())
     {
         SetCursorTo(combatExitingMovementCursor, clickingCombatExitingMovementCursor);
     }
     else
     {
         SetCursorTo(walkingCursor, clickingWalkingCursor);
     }
 }
Exemple #4
0
 public void OnMove(MultiTile oldPosition, MultiTile newPosition)
 {
     //played on EVERY change of tile. Two tiles are used here to avoid confusion in using currentPosition - this will work no matter if we use it slightly before or after movement.
     if (oldPosition.IsProtectedByEnemyOf(this) == false && newPosition.IsProtectedByEnemyOf(this))
     {
         //Unit just came from SAFETY to COMBAT, so inform it and all of the enemies around about it.
         OnCombatEnter();
         foreach (Tile neighbour in newPosition.closeNeighbours)
         {
             if (neighbour.GetMyObject <Unit>() != null && IsEnemyOf(neighbour.GetMyObject <Unit>()))
             {
                 neighbour.GetMyObject <Unit>().OnCombatEnter();
             }
         }
     }
 }
Exemple #5
0
 bool IsQuittingCombatIntoCombat(Unit unitToMove, MultiTile position)
 {
     return(unitToMove.IsInCombat() && position.IsProtectedByEnemyOf(unitToMove));
 }