예제 #1
0
        public override IEnumerator MoveTo(MultiTile destination)
        {
            PlayMovementAnimation();
            //this is what can be called retarded movement, but i cannot into realistic movement as much as Poland cannot into space ;<\
            // it flies up, then forwards, then down, in straight lines. I know it is bad!

            //turns in one frame currently
            TurnTowards(destination.center);

            //while not up enough, rise
            while (myUnit.transform.position.y < flyHeight)
            {
                FlyUp();
                yield return(null);
            }
            //once we have broke out of the first loop, we will not get back to it (we use yield return, not yield break)

            //while not above the target, fly towards it
            while (!IsAbove(destination.center))
            {
                FlyForward();
                yield return(null);
            }
            while (myUnit.transform.position.y > 0)
            {
                Land();
                yield return(null);
            }
            StopMovementAnimation();
            //HERE we need to pathfind, actually, to get distance etc. to know how many points we lost - I THINK. Or maybe fliers cannot move more that once per turn xD?
            myUnit.statistics.movementPoints = 0;
            myUnit.OnMove(myUnit.currentPosition, destination);
            destination.SetMyObjectTo(myUnit);
            PlayerInput.instance.isInputBlocked = false;
        }
예제 #2
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);
        }
예제 #3
0
 void SetMyPositionTo(MultiTile newPosition)
 {
     currentPosition.SetMyObjectTo(null);
     currentPosition = newPosition;
     currentPosition.SetMyObjectTo(this);
 }