예제 #1
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>
        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);
            }
        }
예제 #2
0
        /// <summary>
        /// Uses a weapon/object on an entity
        /// Finds components with the AttackBy interface and calls their function
        /// </summary>
        public void Interaction(IEntity user, IEntity weapon, IEntity attacked, GridCoordinates clickLocation)
        {
            var attackMsg = new AttackByMessage(user, weapon, attacked, clickLocation);

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

            var attackBys         = attacked.GetAllComponents <IAttackBy>().ToList();
            var attackByEventArgs = new AttackByEventArgs
            {
                User = user, ClickLocation = clickLocation, AttackWith = weapon
            };

            foreach (var attackBy in attackBys)
            {
                if (attackBy.AttackBy(attackByEventArgs))
                {
                    // 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;
            }

            // If we aren't directly attacking the nearby object, lets see if our item has an after attack we can do
            var afterAttacks         = weapon.GetAllComponents <IAfterAttack>().ToList();
            var afterAttackEventArgs = new AfterAttackEventArgs
            {
                User = user, ClickLocation = clickLocation, Attacked = attacked
            };

            foreach (var afterAttack in afterAttacks)
            {
                afterAttack.AfterAttack(afterAttackEventArgs);
            }
        }
예제 #3
0
        /// <summary>
        ///     We didn't click on any entity, try doing an AfterAttack on the click location
        /// </summary>
        private void InteractAfterAttack(IEntity user, IEntity weapon, GridCoordinates clickLocation)
        {
            var message = new AfterAttackMessage(user, weapon, null, clickLocation);

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

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

            foreach (var afterAttack in afterAttacks)
            {
                afterAttack.AfterAttack(afterAttackEventArgs);
            }
        }