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;
            }));
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public BehaviourTreeBuilder Build(BehaviourTreeBuilder builder, params object[] args)
        {
            NWCreature self = (NWCreature)args[0];

            return(builder.Do("AttackHighestEnmity", t =>
            {
                var enmityTable = _enmity.GetEnmityTable(self);

                var target = enmityTable.Values
                             .OrderByDescending(o => o.TotalAmount)
                             .FirstOrDefault(x => x.TargetObject.IsValid &&
                                             x.TargetObject.Area.Equals(self.Area));

                self.AssignCommand(() =>
                {
                    if (target == null)
                    {
                        _.ClearAllActions();
                    }
                    else
                    {
                        if (_.GetAttackTarget(self.Object) != target.TargetObject.Object)
                        {
                            _.ClearAllActions();
                            _.ActionAttack(target.TargetObject.Object);
                        }
                    }
                });

                return BehaviourTreeStatus.Running;
            }));
        }
        public bool Run(object[] args)
        {
            NWCreature self        = (NWCreature)args[0];
            var        enmityTable = _enmity.GetEnmityTable(self);
            var        target      = enmityTable.Values
                                     .OrderByDescending(o => o.TotalAmount)
                                     .FirstOrDefault(x => x.TargetObject.IsValid &&
                                                     x.TargetObject.Area.Equals(self.Area));

            self.AssignCommand(() =>
            {
                if (target == null)
                {
                    _.ClearAllActions();
                }
                else
                {
                    if (_.GetAttackTarget(self.Object) != target.TargetObject.Object)
                    {
                        _.ClearAllActions();
                        _.ActionAttack(target.TargetObject.Object);
                    }
                }
            });

            return(true);
        }
        public void RegisterPCToAllCombatTargetsForSkill(NWPlayer player, SkillType skillType, NWCreature target)
        {
            int skillID = (int)skillType;

            if (!player.IsPlayer)
            {
                return;
            }
            if (skillID <= 0)
            {
                return;
            }

            List <NWPlayer> members = player.PartyMembers.ToList();

            int        nth      = 1;
            NWCreature creature = _.GetNearestCreature(CREATURE_TYPE_IS_ALIVE, 1, player.Object, nth, CREATURE_TYPE_PLAYER_CHAR, 0);

            while (creature.IsValid)
            {
                if (_.GetDistanceBetween(player.Object, creature.Object) > 20.0f)
                {
                    break;
                }

                // Check NPC's enmity table
                EnmityTable enmityTable = _enmity.GetEnmityTable(creature);
                foreach (var member in members)
                {
                    if (enmityTable.ContainsKey(member.GlobalID) || (target != null && target.IsValid && target == creature))
                    {
                        RegisterPCToNPCForSkill(player, creature, skillID);
                        break;
                    }
                }

                nth++;
                creature = _.GetNearestCreature(CREATURE_TYPE_IS_ALIVE, 1, player.Object, nth, CREATURE_TYPE_PLAYER_CHAR, 0);
            }
        }
Beispiel #7
0
        public void OnImpact(NWPlayer oPC, NWObject oTarget)
        {
            NWCreature npc = NWCreature.Wrap(oTarget.Object);
            Effect     vfx = _.EffectVisualEffect(VFX_IMP_CHARM);

            _.ApplyEffectToObject(DURATION_TYPE_INSTANT, vfx, oTarget.Object);

            oPC.AssignCommand(() =>
            {
                _.ActionPlayAnimation(ANIMATION_FIREFORGET_TAUNT, 1f, 1f);
            });

            _enmity.AdjustEnmity(npc, oPC, 120);

            // todo debugging
            EnmityTable table = _enmity.GetEnmityTable(npc);

            foreach (var x in table.Values)
            {
                Console.WriteLine(npc.Name + ", " + x.TargetObject.Name + ": Volatile = " + x.VolatileAmount + ", Cumulative: " + x.CumulativeAmount);
            }
            // todo end debugging
        }
Beispiel #8
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;
            }));
        }
        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);
        }