Exemple #1
0
    public HeroPreAttackEvent OnHeroPreAttack(Hero hero, Character target)
    {
        HeroPreAttackEvent heroPreAttackEvent = new HeroPreAttackEvent()
        {
            Hero   = hero,
            Target = target
        };

        HeroPreAttackHandler.OnNext(heroPreAttackEvent);

        foreach (Minion battlefieldMinion in GameManager.Instance.GetAllMinions())
        {
            battlefieldMinion.Buffs.OnHeroPreAttack.OnNext(heroPreAttackEvent);
        }

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

        // Checking if Hero 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 all the enemies to the list
                    foreach (Minion enemyMinion in Player.Enemy.Minions)
                    {
                        possibleTargets.Add(enemyMinion);
                    }
                    possibleTargets.Add(Player.Enemy.Hero);

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

                    // Setting the current target as the random target
                    target = possibleTargets[Random.Range(0, possibleTargets.Count)];

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

        // Firing OnPreAttack events
        HeroPreAttackEvent heroPreAttackEvent = EventManager.Instance.OnHeroPreAttack(this, target);

        // Checking if the Attack was cancelled
        if (heroPreAttackEvent.Status != PreStatus.Cancelled)
        {
            // Redefining target in case it changed when firing events
            target = heroPreAttackEvent.Target;

            // Getting both characters current attack
            int heroAttack   = GetHeroAttack();
            int targetAttack = target.CurrentAttack;

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

            if (target.IsHero())
            {
                target.Damage(this, heroAttack);
            }
            else
            {
                // Damaging both characters
                this.Damage(target, targetAttack);
                target.Damage(this, heroAttack);

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

            // Adding 1 to the current turn attacks counter
            CurrentTurnAttacks++;

            // Using the weapon in case the Player has one
            if (Player.HasWeapon())
            {
                Player.Weapon.Use();
            }

            // Firing OnAttacked events
            EventManager.Instance.OnHeroAttacked(this, target);
        }

        // Updating the Player glows
        Player.UpdateSprites();
    }