Example #1
0
 private void resolveAttack(Entity other)
 {
     // TODO: Add a timer-thing, so this method is not called every frame. Maybe use Coroutines.
     bool kill = other.TakeDamage(_entity.Stats.Attack);
     if (kill) // Prevent the enemy from hurting the player, if the player kills it first.
     {
         disengageAttack(other);
         other.Die();
         _entity.Stats.ScoreValue += other.Stats.ScoreValue;
         _entity.Stats.Experience += other.Stats.Experience;
         return;
     }
     bool died = _entity.TakeDamage(other.Stats.Attack);
     if (died) _entity.Die();
 }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        //  Update the locations of the players.
        g_Fighter.transform.position = new Vector3(20 + 8 * Fighter.position, 0, 0);
        g_Thief.transform.position = new Vector3(20 + 8 * Thief.position, 0, 0);
        g_Wizard.transform.position = new Vector3(20 + 8 * Wizard.position, 0, 0);

        // Count down any delays.
        if (delay > 0.0) {
            delay -= Time.deltaTime;
            delaying = true;
            return;
        }

        delaying = false;

        // TODO: Remove
        {
            Fighter.position = (Fighter.position + 1) % 3;
            Thief.position = (Thief.position + 1) % 3;
            Wizard.position = (Wizard.position + 1) % 3;
            Log("Printing: " + ++count);
            delay = 2f;
            delaying = true;
            return;
        }

        while (toremove.Contains(waiting.Peek()))
            waiting.Dequeue();

        switch (state) {
            case State.Playing:
                target = null;
                if (waiting.Peek().type == Entity.Type.Enemy) {
                    acting = waiting.Dequeue();
                    delay = EnemyDecideDelay;
                    delaying = true;
                    state = State.EnemyThinking;
                }
                else if (waiting.Peek().type == Entity.Type.Fighter) {
                    acting = waiting.Dequeue();
                    delay = EnemyDecideDelay;
                    delaying = true;
                    state = State.FighterThinking;
                }
                else if (waiting.Peek().type == Entity.Type.Thief) {
                    acting = waiting.Dequeue();
                    delay = EnemyDecideDelay;
                    delaying = true;
                    state = State.ThiefThinking;
                }
                else if (waiting.Peek().type == Entity.Type.Wizard) {
                    acting = waiting.Dequeue();
                    delay = EnemyDecideDelay;
                    delaying = true;
                    state = State.WizardThinking;
                }
                break;
            case State.EnemyThinking:
                // Choose target.
                if (FighterIntercept) {
                    target = Fighter;
                }
                else {
                    var chance = (int)(Random.value * 100);
                    if (chance < 66) {
                        target = GetPlayer(0);
                    }
                    else if (chance < 90) {
                        target = GetPlayer(1);
                    }
                    else {
                        target = GetPlayer(2);
                    }
                }

                // Attack target.
                delay = ActionResultDelay;
                delaying = true;
                state = State.Acting;
                break;
            case State.FighterThinking :
                target = null;
                break;
            case State.ThiefThinking :
                target = null;
                break;
            case State.WizardThinking :
                target = null;
                break;
            case State.Acting :
                if (target != null) {
                    int damage = acting.Attack(0, target);

                    Log(string.Format(S_DAMAGED, acting.name, target.name, damage));

                    if (target.HP < 0) {
                        var drop = target.Die();
                        GameObject.Destroy(target.parent);

                        // TODO: Add drop to player inv.
                    }
                }
                break;
            case State.Won :
                target = null;
                break;
            case State.Lost :
                target = null;
                break;
        }
    }