Esempio n. 1
0
        /// <summary>
        /// Checks if the attack hit a player.
        /// </summary>
        /// <param name="a_npcs">List of all active NPCs on the map.</param>
        /// <param name="a_char">The player position, sent by reference.</param>
        public void CheckCollision(ref List <Entities.NPCBad> a_npcs, ref Entities.Player a_char)
        {
            int counter = 0;
            int damage  = 0;

            if (a_npcs != null)
            {
                foreach (Entities.NPCBad a in a_npcs)
                {
                    if (this.IsActive())
                    {
                        if (new Rectangle((int)m_position.X, (int)m_position.Y, m_anim[m_currentframe].Width, m_anim[m_currentframe].Height)
                            .Intersects(a_npcs[counter].GetRectangle()) && !this.ToPlayer())
                        {
                            bool melee = false;
                            if (a_char.GetClass() == Entities.Player.Class.Warrior)
                            {
                                melee = true;
                            }
                            if (a_npcs[counter].IsAlive())
                            {
                                damage = CombatControl.DealDamage(a_char, a_npcs[counter], melee, (int)m_modifier);
                                a_npcs[counter].ReduceCurrentHP(damage);
                                if (!a_npcs[counter].IsAlive())
                                {
                                    a_char.GainExp(a_npcs[counter].GetExpForKill());
                                }
                                this.Die();
                            }
                        }
                        if (new Rectangle((int)m_position.X, (int)m_position.Y, m_anim[m_currentframe].Width, m_anim[m_currentframe].Height)
                            .Intersects(a_char.GetRectangle()) && this.ToPlayer())
                        {
                            bool melee = true;
                            damage = CombatControl.DealDamage(a_npcs[counter], a_char, melee, 1);
                            a_char.ReduceCurrentHP(damage);
                            this.Die();
                        }
                    }
                    counter++;
                }
            }
        }