示例#1
0
        public bool Run(object[] args)
        {
            NWCreature self = (NWCreature)args[0];

            if (_enmity.IsEnmityTableEmpty(self))
            {
                return(false);
            }
            float aggroRange = self.GetLocalFloat("AGGRO_RANGE");

            if (aggroRange <= 0.0f)
            {
                aggroRange = 10.0f;
            }

            int        nth      = 1;
            NWCreature creature = _.GetNearestObject(OBJECT_TYPE_CREATURE, self, nth);
            var        target   = _enmity.GetEnmityTable(self).OrderByDescending(x => x.Value).First().Value.TargetObject;

            while (creature.IsValid)
            {
                if (creature.IsPlayer == false &&
                    _.GetIsEnemy(creature, self) == FALSE &&
                    !_enmity.IsOnEnmityTable(creature, target) &&
                    _.GetDistanceBetween(self, creature) <= aggroRange &&
                    self.RacialType == creature.RacialType)
                {
                    _enmity.AdjustEnmity(creature, target, 0, 1);
                }
                nth++;
                creature = _.GetNearestObject(OBJECT_TYPE_CREATURE, self, nth);
            }

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

            return(builder.Do("RandomWalk", t =>
            {
                if (self.IsInCombat || !_enmity.IsEnmityTableEmpty(self))
                {
                    if (_.GetCurrentAction(self.Object) == NWScript.ACTION_RANDOMWALK)
                    {
                        self.ClearAllActions();
                    }

                    return BehaviourTreeStatus.Failure;
                }

                if (_.GetCurrentAction(self.Object) == NWScript.ACTION_INVALID &&
                    _.IsInConversation(self.Object) == NWScript.FALSE &&
                    _.GetCurrentAction(self.Object) != NWScript.ACTION_RANDOMWALK &&
                    _random.Random(100) <= 25)
                {
                    self.AssignCommand(() => _.ActionRandomWalk());
                }
                return BehaviourTreeStatus.Running;
            }));
        }
示例#3
0
        public bool Run(object[] args)
        {
            NWCreature self = (NWCreature)args[0];

            if (self.IsInCombat || !_enmity.IsEnmityTableEmpty(self))
            {
                if (_.GetCurrentAction(self.Object) == NWScript.ACTION_RANDOMWALK)
                {
                    self.ClearAllActions();
                }

                return(false);
            }

            if (_.GetCurrentAction(self.Object) == NWScript.ACTION_INVALID &&
                _.IsInConversation(self.Object) == NWScript.FALSE &&
                _.GetCurrentAction(self.Object) != NWScript.ACTION_RANDOMWALK &&
                _random.Random(100) <= 25)
            {
                self.AssignCommand(() => _.ActionRandomWalk());
            }
            return(true);
        }
示例#4
0
        public BehaviourTreeBuilder Build(BehaviourTreeBuilder builder, params object[] args)
        {
            NWCreature self = (NWCreature)args[0];

            return(builder.Do("WarpToTargetIfStuck", t =>
            {
                if (_enmity.IsEnmityTableEmpty(self) ||
                    _.GetMovementRate(self.Object) == 1) // 1 = Immobile
                {
                    if (self.Data.ContainsKey("WarpToTargetIfStuck_Position"))
                    {
                        self.Data.Remove("WarpToTargetIfStuck_Position");
                    }
                    if (self.Data.ContainsKey("WarpToTargetIfStuck_CyclesStuckInPlace"))
                    {
                        self.Data.Remove("WarpToTargetIfStuck_CyclesStuckInPlace");
                    }

                    return BehaviourTreeStatus.Failure;
                }


                Vector previousPosition = new Vector();
                if (self.Data.ContainsKey("WarpToTargetIfStuck_Position"))
                {
                    previousPosition = (Vector)self.Data["WarpToTargetIfStuck_Position"];
                }

                Vector currentPosition = self.Position;
                if (previousPosition.m_X == currentPosition.m_X &&
                    previousPosition.m_Y == currentPosition.m_Y &&
                    previousPosition.m_Z == currentPosition.m_Z)
                {
                    var cyclesStuck = 0;
                    if (self.Data.ContainsKey("WarpToTargetIfStuck_CyclesStuckInPlace"))
                    {
                        cyclesStuck = (int)self.Data["WarpToTargetIfStuck_CyclesStuckInPlace"];
                    }
                    cyclesStuck++;

                    if (cyclesStuck >= 12) // Stuck for 12 seconds - warp to the target if still in the area.
                    {
                        EnmityTable table = _enmity.GetEnmityTable(self);
                        var topTarget = table.Values.OrderByDescending(o => o.TotalAmount).SingleOrDefault();
                        if (topTarget != null && topTarget.TargetObject.IsValid)
                        {
                            var location = topTarget.TargetObject.Location;
                            _.AssignCommand(self.Object, () => _.JumpToLocation(location));
                        }

                        cyclesStuck = 0;
                    }

                    self.Data["WarpToTargetIfStuck_CyclesStuckInPlace"] = cyclesStuck;
                }
                else
                {
                    self.Data["WarpToTargetIfStuck_CyclesStuckInPlace"] = 0;
                }

                self.Data["WarpToTargetIfStuck_Position"] = currentPosition;

                return BehaviourTreeStatus.Running;
            }));
        }
示例#5
0
        public bool Run(object[] args)
        {
            NWCreature self = (NWCreature)args[0];

            if (_enmity.IsEnmityTableEmpty(self) ||
                _.GetMovementRate(self.Object) == 1 ||  // 1 = Immobile
                self.HasAnyEffect(EFFECT_TYPE_DAZED) || // Dazed
                self.RightHand.CustomItemType == CustomItemType.BlasterRifle ||
                self.RightHand.CustomItemType == CustomItemType.BlasterPistol)
            {
                if (self.Data.ContainsKey("WarpToTargetIfStuck_Position"))
                {
                    self.Data.Remove("WarpToTargetIfStuck_Position");
                }
                if (self.Data.ContainsKey("WarpToTargetIfStuck_CyclesStuckInPlace"))
                {
                    self.Data.Remove("WarpToTargetIfStuck_CyclesStuckInPlace");
                }

                return(false);
            }


            Vector previousPosition = new Vector();

            if (self.Data.ContainsKey("WarpToTargetIfStuck_Position"))
            {
                previousPosition = (Vector)self.Data["WarpToTargetIfStuck_Position"];
            }

            Vector currentPosition = self.Position;

            if (previousPosition.m_X == currentPosition.m_X &&
                previousPosition.m_Y == currentPosition.m_Y &&
                previousPosition.m_Z == currentPosition.m_Z)
            {
                var cyclesStuck = 0;
                if (self.Data.ContainsKey("WarpToTargetIfStuck_CyclesStuckInPlace"))
                {
                    cyclesStuck = (int)self.Data["WarpToTargetIfStuck_CyclesStuckInPlace"];
                }
                cyclesStuck++;

                if (cyclesStuck >= 12) // Stuck for 12 seconds - warp to the target if still in the area.
                {
                    EnmityTable table     = _enmity.GetEnmityTable(self);
                    var         topTarget = table.Values.OrderByDescending(o => o.TotalAmount).FirstOrDefault();
                    if (topTarget != null && topTarget.TargetObject.IsValid)
                    {
                        var location = topTarget.TargetObject.Location;
                        _.AssignCommand(self.Object, () => _.JumpToLocation(location));
                    }

                    cyclesStuck = 0;
                }

                self.Data["WarpToTargetIfStuck_CyclesStuckInPlace"] = cyclesStuck;
            }
            else
            {
                self.Data["WarpToTargetIfStuck_CyclesStuckInPlace"] = 0;
            }

            self.Data["WarpToTargetIfStuck_Position"] = currentPosition;

            return(true);
        }