コード例 #1
0
        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);
        }
コード例 #2
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;
            }));
        }
コード例 #3
0
ファイル: OnUsed.cs プロジェクト: zunath/Freescape
        public bool Run(params object[] args)
        {
            NWObject oPC = NWObject.Wrap(_.GetLastUsedBy());

            oPC.AssignCommand(() => _.ActionAttack(Object.OBJECT_SELF));
            return(true);
        }
コード例 #4
0
        public void AdjustEnmity(NWCreature npc, NWCreature attacker, int volatileAdjust, int cumulativeAdjust = 0)
        {
            if (!npc.IsNPC)
            {
                return;
            }

            bool adjustVolatile   = volatileAdjust != 0;
            bool adjustCumulative = cumulativeAdjust != 0;

            float effectiveEnmityRate = 1.0f;

            if (attacker.IsPlayer)
            {
                NWPlayer player         = (attacker.Object);
                var      effectiveStats = _playerStat.GetPlayerItemEffectiveStats(player);
                effectiveEnmityRate = effectiveStats.EnmityRate;
            }

            volatileAdjust   = (int)(effectiveEnmityRate * volatileAdjust);
            cumulativeAdjust = (int)(effectiveEnmityRate * cumulativeAdjust);

            var table = GetEnmityTable(npc);

            // If this is the first creature to go on the enmity table, immediately attack them so they aren't
            // waiting around to do something the next time their AI runs.
            if (table.Count <= 0)
            {
                npc.AssignCommand(() =>
                {
                    _.ActionAttack(attacker);
                });
            }

            var enmity = GetEnmity(npc, attacker);

            if (adjustVolatile)
            {
                enmity.VolatileAmount += volatileAdjust;
            }
            if (adjustCumulative)
            {
                enmity.CumulativeAmount += cumulativeAdjust;
            }
        }