/// <summary>
        /// Uses a weapon/object on an entity
        /// Finds components with the InteractUsing 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);

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

            var attackBys         = attacked.GetAllComponents <IInteractUsing>().ToList();
            var attackByEventArgs = new InteractUsingEventArgs
            {
                User = user, ClickLocation = clickLocation, Using = weapon, Target = attacked
            };

            // all AttackBys should only happen when in range / unobstructed, so no range check is needed
            if (InteractionChecks.InRangeUnobstructed(attackByEventArgs))
            {
                foreach (var attackBy in attackBys)
                {
                    if (attackBy.InteractUsing(attackByEventArgs))
                    {
                        // If an InteractUsing returns a status completion we finish our attack
                        return;
                    }
                }
            }

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

            RaiseLocalEvent(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 <IAfterInteract>().ToList();
            var afterAttackEventArgs = new AfterInteractEventArgs
            {
                User = user, ClickLocation = clickLocation, Target = attacked
            };

            foreach (var afterAttack in afterAttacks)
            {
                afterAttack.AfterInteract(afterAttackEventArgs);
            }
        }
        /// <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);
            }
        }
Exemple #3
0
        /// <summary>
        /// Uses a weapon/object on an entity
        /// Finds interactable components with the Attackby interface and calls their function
        /// </summary>
        /// <param name="user"></param>
        /// <param name="weapon"></param>
        /// <param name="attacked"></param>
        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;
            }

            List <IAttackBy> interactables = attacked.GetAllComponents <IAttackBy>().ToList();

            for (var i = 0; i < interactables.Count; i++)
            {
                if (interactables[i].AttackBy(new AttackByEventArgs {
                    User = user, ClickLocation = clicklocation, AttackWith = weapon
                }))                                                                                                                       //If an attackby returns a status completion we finish our attack
                {
                    return;
                }
            }

            //Else check damage component to see if we damage if not attackby, and if so can we attack object

            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
            List <IAfterAttack> afterattacks = weapon.GetAllComponents <IAfterAttack>().ToList();

            for (var i = 0; i < afterattacks.Count; i++)
            {
                afterattacks[i].AfterAttack(new AfterAttackEventArgs {
                    User = user, ClickLocation = clicklocation, Attacked = attacked
                });
            }
        }