Exemplo n.º 1
0
        protected void CleanUpEnmity(NWCreature self)
        {
            var table = EnmityService.GetEnmityTable(self);

            if (table.Count <= 0)
            {
                return;
            }

            for (int x = table.Count - 1; x >= 0; x--)
            {
                var enmity = table.ElementAt(x);
                var val    = enmity.Value;
                var target = val.TargetObject;

                // Remove invalid objects from the enmity table
                if (target == null ||
                    !target.IsValid ||
                    target.Area.Resref != self.Area.Resref ||
                    target.CurrentHP <= -11 ||
                    target.IsDead)
                {
                    EnmityService.GetEnmityTable(self).Remove(enmity.Key);
                    continue;
                }

                AdjustReputation(target.Object, self.Object, -100);

                // Reduce volatile enmity every tick
                EnmityService.GetEnmityTable(self)[target.GlobalID].VolatileAmount--;
            }
        }
Exemplo n.º 2
0
        protected void AttackHighestEnmity(NWCreature self)
        {
            var enmityTable = EnmityService.GetEnmityTable(self);
            var target      = enmityTable.Values
                              .OrderByDescending(o => o.TotalAmount)
                              .FirstOrDefault(x => x.TargetObject.IsValid &&
                                              x.TargetObject.Area.Equals(self.Area));
            var currentAttackTarget = GetAttackTarget(self.Object);

            // We have a target and it's not who we're currently attacking. Switch to attacking them.
            if (target != null && currentAttackTarget != target.TargetObject.Object)
            {
                self.AssignCommand(() =>
                {
                    ClearAllActions();
                    ActionAttack(target.TargetObject.Object);
                });
            }
            // We don't have a valid target but we're still attacking someone. We shouldn't be attacking them anymore. Clear all actions.
            else if (target == null && GetCurrentAction(self) == ActionType.AttackObject)
            {
                self.AssignCommand(() =>
                {
                    ClearAllActions();
                });
            }
        }
Exemplo n.º 3
0
        private static void Link(NWCreature self, NWCreature nearby)
        {
            float linkRange = self.GetLocalFloat("LINK_RANGE");

            if (linkRange <= 0.0f)
            {
                linkRange = 12.0f;
            }

            // Check distance. If too far away stop processing.
            if (_.GetDistanceBetween(self, nearby) > linkRange)
            {
                return;
            }

            // Is the nearby object an NPC?
            if (!nearby.IsNPC)
            {
                return;
            }

            // Is the nearby creature dead?
            if (nearby.IsDead)
            {
                return;
            }

            // Is the nearby creature an enemy?
            if (_.GetIsEnemy(nearby, self) == TRUE)
            {
                return;
            }

            // Does the calling creature have the same racial type as the nearby creature?
            if (self.RacialType != nearby.RacialType)
            {
                return;
            }

            // Does the nearby creature have anything on its enmity table?
            var nearbyEnmityTable = EnmityService.GetEnmityTable(nearby).OrderByDescending(x => x.Value).FirstOrDefault();

            if (nearbyEnmityTable.Value == null)
            {
                return;
            }

            var target = nearbyEnmityTable.Value.TargetObject;

            // Is the target dead?
            if (target.IsDead)
            {
                return;
            }

            // Add the target of the nearby creature to this creature's enmity table.
            EnmityService.AdjustEnmity(self, target, 0, 1);
        }
Exemplo n.º 4
0
        protected void AttackHighestEnmity(NWCreature self)
        {
            var enmityTable = EnmityService.GetEnmityTable(self);
            var target      = enmityTable.Values
                              .OrderByDescending(o => o.TotalAmount)
                              .FirstOrDefault(x => x.TargetObject.IsValid &&
                                              x.TargetObject.Area.Equals(self.Area));

            if (target != null)
            {
                self.AssignCommand(() =>
                {
                    if (GetAttackTarget(self.Object) != target.TargetObject.Object)
                    {
                        ClearAllActions();
                        ActionAttack(target.TargetObject.Object);
                    }
                });
            }
        }
Exemplo n.º 5
0
        private void ForceAttackHighestEnmity(NWCreature self)
        {
            if (self.GetLocalInt("CASTING") == 1)
            {
                return;
            }
            var enmityTable = EnmityService.GetEnmityTable(self);
            var target      = enmityTable.Values
                              .OrderByDescending(o => o.TotalAmount)
                              .FirstOrDefault(x => x.TargetObject.IsValid &&
                                              x.TargetObject.Area.Equals(self.Area));

            if (target == null)
            {
                return;
            }
            self.AssignCommand(() =>
            {
                bool bDone = false;

                // See which force feats we have, and pick one to use.
                if (_.GetHasFeat((int)CustomFeatType.ForceLightning, self) == 1)
                {
                    _.ClearAllActions();
                    bDone = UseFeat((int)CustomFeatType.ForceLightning, "ForceLightning", self, target.TargetObject);
                }

                if (!bDone && _.GetHasFeat((int)CustomFeatType.DrainLife, self) == 1)
                {
                    _.ClearAllActions();
                    bDone = UseFeat((int)CustomFeatType.DrainLife, "DrainLife", self, target.TargetObject);
                }

                if (!bDone)
                {
                    // No abilities available right now, run away!
                    _.ActionMoveAwayFromObject(target.TargetObject, 1);
                }
            });
        }