Example #1
0
        public bool Run(object[] args)
        {
            NWCreature self  = (NWCreature)args[0];
            var        table = _enmity.GetEnmityTable(self);

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

            foreach (var enmity in table.ToArray())
            {
                var val    = enmity.Value;
                var target = val.TargetObject;

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

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

                // Reduce volatile enmity every tick
                _enmity.GetEnmityTable(self)[target.GlobalID].VolatileAmount--;
            }

            return(true);
        }
        public BehaviourTreeBuilder Build(BehaviourTreeBuilder builder, params object[] args)
        {
            NWCreature self = (NWCreature)args[0];

            return(builder.Do("CleanUpEnmity", t =>
            {
                foreach (var enmity in _enmity.GetEnmityTable(self).ToArray())
                {
                    var val = enmity.Value;
                    var target = val.TargetObject;

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

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

                    // Reduce volatile enmity every tick
                    _enmity.GetEnmityTable(self)[target.GlobalID].VolatileAmount--;
                }

                return BehaviourTreeStatus.Running;
            }));
        }