/// <summary>
        /// Will have two behaviors, either "uses" the weapon at range on the entity if it is capable of accepting that action
        /// Or it will use the weapon itself on the position clicked, regardless of what was there
        /// </summary>
        public void RangedInteraction(IEntity user, IEntity weapon, IEntity attacked, GridCoordinates clickLocation)
        {
            var rangedMsg = new RangedAttackMessage(user, weapon, attacked, clickLocation);

            RaiseEvent(rangedMsg);
            if (rangedMsg.Handled)
            {
                return;
            }

            var rangedAttackBys         = attacked.GetAllComponents <IRangedAttackBy>().ToList();
            var rangedAttackByEventArgs = new RangedAttackByEventArgs
            {
                User = user, Weapon = weapon, ClickLocation = clickLocation
            };

            // See if we have a ranged attack interaction
            foreach (var t in rangedAttackBys)
            {
                if (t.RangedAttackBy(rangedAttackByEventArgs))
                {
                    // If an AttackBy returns a status completion we finish our attack
                    return;
                }
            }

            var afterAtkMsg = new AfterAttackMessage(user, weapon, attacked, clickLocation);

            RaiseEvent(afterAtkMsg);
            if (afterAtkMsg.Handled)
            {
                return;
            }

            var afterAttacks         = weapon.GetAllComponents <IAfterAttack>().ToList();
            var afterAttackEventArgs = new AfterAttackEventArgs
            {
                User = user, ClickLocation = clickLocation, Attacked = attacked
            };

            //See if we have a ranged attack interaction
            foreach (var afterAttack in afterAttacks)
            {
                afterAttack.AfterAttack(afterAttackEventArgs);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Will have two behaviors, either "uses" the weapon at range on the entity if it is capable of accepting that action
        /// Or it will use the weapon itself on the position clicked, regardless of what was there
        /// </summary>
        /// <param name="user"></param>
        /// <param name="weapon"></param>
        /// <param name="attacked"></param>
        public void RangedInteraction(IEntity user, IEntity weapon, IEntity attacked, GridCoordinates clickLocation)
        {
            var rangedMsg = new RangedAttackMessage(user, weapon, attacked, clickLocation);

            RaiseEvent(rangedMsg);
            if (rangedMsg.Handled)
            {
                return;
            }

            List <IRangedAttackBy> rangedusables = attacked.GetAllComponents <IRangedAttackBy>().ToList();

            //See if we have a ranged attack interaction
            for (var i = 0; i < rangedusables.Count; i++)
            {
                if (rangedusables[i].RangedAttackBy(new RangedAttackByEventArgs {
                    User = user, Weapon = weapon, ClickLocation = clickLocation
                }))                                                                                                                               //If an attackby returns a status completion we finish our attack
                {
                    return;
                }
            }

            if (weapon != null)
            {
                var afterAtkMsg = new AfterAttackMessage(user, weapon, attacked, clickLocation);
                RaiseEvent(afterAtkMsg);
                if (afterAtkMsg.Handled)
                {
                    return;
                }

                List <IAfterAttack> afterattacks = weapon.GetAllComponents <IAfterAttack>().ToList();

                //See if we have a ranged attack interaction
                for (var i = 0; i < afterattacks.Count; i++)
                {
                    afterattacks[i].AfterAttack(new AfterAttackEventArgs {
                        User = user, ClickLocation = clickLocation, Attacked = attacked
                    });
                }
            }
        }