Example #1
0
    public MinionPreAttackEvent OnMinionPreAttack(Minion minion, Character target)
    {
        MinionPreAttackEvent minionPreAttackEvent = new MinionPreAttackEvent()
        {
            Minion = minion,
            Target = target
        };

        MinionPreAttackHandler.OnNext(minionPreAttackEvent);

        foreach (Minion battlefieldMinion in GameManager.Instance.GetAllMinions())
        {
            battlefieldMinion.Buffs.OnMinionPreAttack.OnNext(minionPreAttackEvent);
        }

        return(minionPreAttackEvent);
    }
Example #2
0
    public override void Attack(Character target)
    {
        Debugger.LogMinion(this, "starting attack to " + target.GetName());

        // Removing stealth of the Minion
        IsStealth = false;

        // Checking if minion is Forgetful
        if (IsForgetful)
        {
            // Checking if there's more than 1 enemy (hero + minions)
            if (Player.Enemy.Minions.Count > 0)
            {
                // Random 50% chance
                if (RNG.RandomBool())
                {
                    // TODO : Play forgetful trigger animation

                    // Creating a list of possible targets
                    List <Character> possibleTargets = new List <Character>();

                    // Adding the enemy hero to the list
                    possibleTargets.Add(Player.Enemy.Hero);

                    // Adding all enemy minions to the list
                    foreach (Minion enemyMinion in Player.Enemy.Minions)
                    {
                        possibleTargets.Add(enemyMinion);
                    }

                    // Removing the current target from the possible targets list
                    possibleTargets.Remove(target);

                    // Selecting a target by random
                    int randomTarget = Random.Range(0, possibleTargets.Count);

                    // Setting the current target as the random target
                    target = possibleTargets[randomTarget];

                    Debugger.LogMinion(this, "switched target to " + target.TypeName() + " (forgetful)");
                }
            }
        }

        // Firing OnPreAttack events
        Buffs.OnPreAttack.OnNext(null);
        MinionPreAttackEvent minionPreAttackEvent = EventManager.Instance.OnMinionPreAttack(this, target);

        // Checking if the Attack was not cancelled
        if (minionPreAttackEvent.Status != PreStatus.Cancelled)
        {
            // Adding 1 to the current turn attacks counter
            CurrentTurnAttacks++;

            // Redefining target in case it changed when firing events
            target = minionPreAttackEvent.Target;

            // Getting both characters current attack
            int attackerAttack = CurrentAttack;
            int targetAttack   = target.CurrentAttack;

            Debugger.LogMinion(this, "attacking " + target.GetName());

            if (target.IsHero())
            {
                target.Damage(this, attackerAttack);
            }
            else if (target.IsMinion())
            {
                Minion targetMinion = target.As <Minion>();

                // Checking if both minions are still alive
                if (this.IsAlive() && target.IsAlive())
                {
                    // Damaging both minions
                    this.Damage(target, targetAttack);
                    target.Damage(this, attackerAttack);

                    // Checking the death of both characters
                    this.CheckDeath();
                    target.CheckDeath();

                    // Checking for poison on both minions
                    if (this.HasPoison)
                    {
                        if (attackerAttack > 0)
                        {
                            Debugger.LogMinion(this, "killed by posion of " + targetMinion.GetName());

                            EventManager.Instance.OnMinionPoisoned(targetMinion, this);

                            Destroy();
                        }
                    }

                    if (targetMinion.HasPoison)
                    {
                        if (targetAttack > 0)
                        {
                            Debugger.LogMinion(targetMinion, "killed by posion of " + this.GetName());

                            EventManager.Instance.OnMinionPoisoned(this, targetMinion);

                            Destroy();
                        }
                    }
                }
            }

            // Firing OnAttacked events
            Buffs.OnAttacked.OnNext(null);
            EventManager.Instance.OnMinionAttacked(this, target);
        }

        Controller.UpdateSprites();
    }