private void DelayDamagePopup()
 {
     PopupTextController.PopupText(delayedMessage, delayedActor.tokenRef.transform);
     CheckForDeath(delayedActor);
     SetState(STATES.AWAITING_INPUT);
     CheckForTurnCompleted();
 }
    // Walk a player or monster token to a space
    private void WalkActor(Actor actor, int xTo, int zTo)
    {
        // Find a path to the desired square, by getting a queue of sqaures to hop over
        LinkedList <TokenWalker.Hop> hopsQueue = Pathfind.FindPath(actor.x, actor.z, xTo, zTo);

        if (hopsQueue != null)
        {
            if (hopsQueue.Count > currentTurnStats.MovementLeft)
            {
                PopupTextController.PopupText("Not Enough Movement", spaces[xTo, zTo].gameSpace.transform);
            }
            else
            {
                // change the token's stored properties to its final position
                spaces[actor.x, actor.z].isBlocked = false;
                actor.x = xTo;
                actor.z = zTo;
                spaces[xTo, zTo].isBlocked = true;

                SetState(STATES.ANIMATING_ACTION);

                // Use the script attached to the token to walk the path
                actor.tokenRef.GetComponent <TokenWalker>().WalkPath(hopsQueue);
            }
        }
        else
        {
            PopupTextController.PopupText("Pathfinding failed", spaces[xTo, zTo].gameSpace.transform);
        }
    }
    // Resolve an attack action
    // Recevied from any arbitrary GameObject with the OnClick-Message script attached
    public void MessageClickedToken(GameObject attackee)
    {
        SetState(STATES.ANIMATING_ACTION);
        if (currentTurnStats.HasAttackHappened)
        {
            PopupTextController.PopupText("Already attacked", attackee.transform);
        }
        else
        {
            GameObject attacker = actors[currentActorTurn].tokenRef;
            if (attackee == attacker)
            {
                PopupTextController.PopupText("Can't attack self", attackee.transform);
            }
            else
            {
                Actor victim = actors.Find(actor => { return(actor.tokenRef == attackee); });
                if (victim == null)
                {
                    PopupTextController.PopupText("ERROR FINDING ACTOR", attackee.transform);
                }
                else
                {
                    if (!victim.IsAlive)
                    {
                        PopupTextController.PopupText("Creature is already dead", attackee.transform);
                    }
                    else
                    {
                        // Check if attack is possible, using A* pathfinding to find range in num squares, manhattan distance
                        if (Pathfind.FindDistance(actors[currentActorTurn].x, actors[currentActorTurn].z, victim.x, victim.z) > actors[currentActorTurn].AttackRange)
                        {
                            PopupTextController.PopupText("Out of range", attackee.transform);
                        }
                        else
                        {
                            // Roll to hit
                            int attackResult = RollDice(1, 20, actors[currentActorTurn].AttackMod);
                            if (attackResult >= victim.AC)
                            {
                                PopupTextController.PopupText("Hit: " + attackResult + " vs. " + victim.AC, attacker.transform);

                                // Animate attack
                                attacker.GetComponent <TokenAttacker>().AttackTowards(attackee.transform);

                                int damageResult = RollDice(actors[currentActorTurn].DamageDieNum, actors[currentActorTurn].DamageDieMagnitude, actors[currentActorTurn].DamageMod);
                                victim.HP -= damageResult;

                                delayedMessage = damageResult + " damage";
                                delayedActor   = victim;
                                Invoke("DelayDamagePopup", 0.5f);
                                return;
                            }
                            else
                            {
                                PopupTextController.PopupText("Miss: " + attackResult + " vs. " + victim.AC, attackee.transform);
                            }

                            // Finalise attack
                            currentTurnStats.HasAttackHappened = true;
                        }
                    }
                }
            }
        }
        SetState(STATES.AWAITING_INPUT);
        CheckForTurnCompleted();
    }