/// <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>
        /// 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);
            }
        }
        /// <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);
            }
        }
Beispiel #4
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
                    });
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// We didn't click on any entity, try doing an afterattack on the click location
        /// </summary>
        /// <param name="user"></param>
        /// <param name="weapon"></param>
        /// <param name="clicklocation"></param>
        public void InteractAfterattack(IEntity user, IEntity weapon, GridCoordinates clicklocation)
        {
            var message = new AfterAttackMessage(user, weapon, null, clicklocation);

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

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

            for (var i = 0; i < afterattacks.Count; i++)
            {
                afterattacks[i].AfterAttack(new AfterAttackEventArgs {
                    User = user, ClickLocation = clicklocation
                });
            }
        }
Beispiel #6
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
                });
            }
        }
        /// <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);
            }
        }