Ejemplo n.º 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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private float GetLinkRange(NWCreature creature)
        {
            float linkRange = creature.GetLocalFloat("LINK_RANGE");

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

            return(linkRange);
        }
Ejemplo n.º 4
0
        private float GetAggroRange(NWCreature creature)
        {
            float aggroRange = creature.GetLocalFloat("AGGRO_RANGE");

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

            return(aggroRange);
        }
Ejemplo n.º 5
0
        public BehaviourTreeBuilder Build(BehaviourTreeBuilder builder, params object[] args)
        {
            return(builder.Do("AggroTargetBySight", t =>
            {
                NWCreature self = (NWCreature)args[0];

                if (self.IsInCombat)
                {
                    return BehaviourTreeStatus.Failure;
                }

                float aggroRange = self.GetLocalFloat("AGGRO_RANGE");
                if (aggroRange <= 0.0f)
                {
                    aggroRange = 10.0f;
                }
                Location targetLocation = _.Location(
                    self.Area.Object,
                    _biowarePos.GetChangedPosition(self.Position, aggroRange, self.Facing),
                    self.Facing + 180.0f);

                NWCreature creature = NWCreature.Wrap(_.GetFirstObjectInShape(NWScript.SHAPE_SPELLCYLINDER, aggroRange, targetLocation, NWScript.TRUE, NWScript.OBJECT_TYPE_CREATURE, self.Position));
                while (creature.IsValid)
                {
                    if (_.GetIsEnemy(creature.Object, self.Object) == NWScript.TRUE &&
                        !_enmity.IsOnEnmityTable(self, creature) &&
                        _.GetDistanceBetween(self.Object, creature.Object) <= aggroRange &&
                        !creature.HasAnyEffect(NWScript.EFFECT_TYPE_INVISIBILITY, NWScript.EFFECT_TYPE_SANCTUARY))
                    {
                        _enmity.AdjustEnmity(self, creature, 0, 1);
                    }

                    creature = NWCreature.Wrap(_.GetNextObjectInShape(NWScript.SHAPE_SPELLCYLINDER, aggroRange, targetLocation, NWScript.TRUE, NWScript.OBJECT_TYPE_CREATURE, self.Position));
                }

                return BehaviourTreeStatus.Running;
            }));
        }
Ejemplo n.º 6
0
        public BehaviourTreeBuilder Build(BehaviourTreeBuilder builder, params object[] args)
        {
            return(builder.Do("AggroTargetBySound", t =>
            {
                NWCreature self = (NWCreature)args[0];

                if (self.IsInCombat)
                {
                    return BehaviourTreeStatus.Failure;
                }

                float aggroRange = self.GetLocalFloat("AGGRO_RANGE");
                if (aggroRange <= 0.0f)
                {
                    aggroRange = 5.0f;
                }

                int nth = 1;
                NWCreature creature = NWCreature.Wrap(_.GetNearestObject(NWScript.OBJECT_TYPE_CREATURE, self.Object, nth));
                while (creature.IsValid)
                {
                    if (_.GetIsEnemy(creature.Object, self.Object) == NWScript.TRUE &&
                        !_enmity.IsOnEnmityTable(self, creature) &&
                        !creature.HasAnyEffect(NWScript.EFFECT_TYPE_SANCTUARY) &&
                        _.GetDistanceBetween(self.Object, creature.Object) <= aggroRange &&
                        _.LineOfSightObject(self.Object, creature.Object) == NWScript.TRUE)
                    {
                        _enmity.AdjustEnmity(self, creature, 0, 1);
                    }

                    nth++;
                    creature = NWCreature.Wrap(_.GetNearestObject(NWScript.OBJECT_TYPE_CREATURE, self.Object, nth));
                }


                return BehaviourTreeStatus.Running;
            }));
        }
Ejemplo n.º 7
0
        public bool Run(object[] args)
        {
            NWCreature self = (NWCreature)args[0];

            if (self.IsInCombat)
            {
                return(false);
            }

            float aggroRange = self.GetLocalFloat("AGGRO_RANGE");

            if (aggroRange <= 0.0f)
            {
                aggroRange = 10.0f;
            }
            Location targetLocation = _.Location(
                self.Area.Object,
                _biowarePos.GetChangedPosition(self.Position, aggroRange, self.Facing),
                self.Facing + 180.0f);

            NWCreature creature = _.GetFirstObjectInShape(SHAPE_SPELLCYLINDER, aggroRange, targetLocation, TRUE, OBJECT_TYPE_CREATURE, self.Position);

            while (creature.IsValid)
            {
                if (_.GetIsEnemy(creature.Object, self.Object) == TRUE &&
                    !_enmity.IsOnEnmityTable(self, creature) &&
                    _.GetDistanceBetween(self.Object, creature.Object) <= aggroRange &&
                    !creature.HasAnyEffect(EFFECT_TYPE_INVISIBILITY, EFFECT_TYPE_SANCTUARY))
                {
                    _enmity.AdjustEnmity(self, creature, 0, 1);
                }

                creature = _.GetNextObjectInShape(SHAPE_SPELLCYLINDER, aggroRange, targetLocation, TRUE, OBJECT_TYPE_CREATURE, self.Position);
            }

            return(true);
        }
Ejemplo n.º 8
0
        public bool Run(object[] args)
        {
            NWCreature self = (NWCreature)args[0];

            if (self.IsInCombat)
            {
                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.Object, nth);

            while (creature.IsValid)
            {
                if (_.GetIsEnemy(creature.Object, self.Object) == TRUE &&
                    !_enmity.IsOnEnmityTable(self, creature) &&
                    !creature.HasAnyEffect(EFFECT_TYPE_SANCTUARY) &&
                    _.GetDistanceBetween(self.Object, creature.Object) <= aggroRange &&
                    _.LineOfSightObject(self.Object, creature.Object) == TRUE)
                {
                    _enmity.AdjustEnmity(self, creature, 0, 1);
                }

                nth++;
                creature = _.GetNearestObject(OBJECT_TYPE_CREATURE, self.Object, nth);
            }


            return(true);
        }
Ejemplo n.º 9
0
        public void OnCreatureDeath(NWCreature creature)
        {
            CreatureSkillRegistration      reg        = GetCreatureSkillRegistration(creature.GlobalID);
            List <PlayerSkillRegistration> playerRegs = reg.GetAllRegistrations();
            var registration = reg.Registrations.OrderByDescending(o => o.Value.HighestRank).FirstOrDefault();

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

            int partyLevel = registration.Value.HighestRank;

            // Identify base XP using delta between party level and enemy level.
            float cr         = creature.ChallengeRating;
            int   enemyLevel = (int)(cr * 5.0f);
            int   delta      = enemyLevel - partyLevel;
            float baseXP     = 0;

            if (delta >= 6)
            {
                baseXP = 400;
            }
            else if (delta == 5)
            {
                baseXP = 350;
            }
            else if (delta == 4)
            {
                baseXP = 325;
            }
            else if (delta == 3)
            {
                baseXP = 300;
            }
            else if (delta == 2)
            {
                baseXP = 250;
            }
            else if (delta == 1)
            {
                baseXP = 225;
            }
            else if (delta == 0)
            {
                baseXP = 200;
            }
            else if (delta == -1)
            {
                baseXP = 150;
            }
            else if (delta == -2)
            {
                baseXP = 100;
            }
            else if (delta == -3)
            {
                baseXP = 50;
            }
            else if (delta == -4)
            {
                baseXP = 25;
            }

            float bonusXPPercentage = creature.GetLocalFloat("BONUS_XP_PERCENTAGE");

            if (bonusXPPercentage > 1)
            {
                bonusXPPercentage = 1;
            }
            else if (bonusXPPercentage < 0)
            {
                bonusXPPercentage = 0;
            }

            baseXP = baseXP + (baseXP * bonusXPPercentage);

            // Process each player skill registration.
            foreach (PlayerSkillRegistration preg in playerRegs)
            {
                // Rules for acquiring skill XP:
                // Player must be valid.
                // Player must be in the same area as the creature that just died.
                // Player must be within 30 meters of the creature that just died.
                if (!preg.Player.IsValid ||
                    preg.Player.Area.Resref != creature.Area.Resref ||
                    _.GetDistanceBetween(preg.Player.Object, creature.Object) > 40.0f)
                {
                    continue;
                }

                List <Tuple <int, PlayerSkillPointTracker> > skillRegs = preg.GetSkillRegistrationPoints();
                int totalPoints = preg.GetTotalSkillRegistrationPoints();

                // Retrieve all necessary PC skills up front
                int[] skillIDsToSearchFor = skillRegs.Select(x => x.Item2.SkillID).ToArray();

                var pcSkills = GetAllPCSkills(preg.Player)
                               .Where(x => skillIDsToSearchFor.Contains(x.SkillID))
                               .ToList();

                // Grant XP based on points acquired during combat.
                foreach (Tuple <int, PlayerSkillPointTracker> skreg in skillRegs)
                {
                    int skillID   = skreg.Item1;
                    int skillRank = pcSkills.Single(x => x.SkillID == skillID).Rank;

                    int points = skreg.Item2.Points;

                    float percentage = points / (float)totalPoints;
                    float skillLDP   = CalculatePartyLevelDifferencePenalty(partyLevel, skillRank);
                    float adjustedXP = baseXP * percentage * skillLDP;
                    adjustedXP = CalculateRegisteredSkillLevelAdjustedXP(adjustedXP, skillRank, skillRank);

                    GiveSkillXP(preg.Player, skillID, (int)adjustedXP);
                }

                float armorXP          = baseXP * 0.20f;
                int   lightArmorPoints = 0;
                int   heavyArmorPoints = 0;
                int   forceArmorPoints = 0;

                for (int slot = 0; slot < NUM_INVENTORY_SLOTS; slot++)
                {
                    NWItem item = _.GetItemInSlot(slot, preg.Player.Object);
                    if (item.CustomItemType == CustomItemType.LightArmor)
                    {
                        lightArmorPoints++;
                    }
                    else if (item.CustomItemType == CustomItemType.HeavyArmor)
                    {
                        heavyArmorPoints++;
                    }
                    else if (item.CustomItemType == CustomItemType.ForceArmor)
                    {
                        forceArmorPoints++;
                    }
                }
                totalPoints = lightArmorPoints + heavyArmorPoints + forceArmorPoints;
                if (totalPoints <= 0)
                {
                    continue;
                }

                int   armorRank = GetPCSkillRank(preg.Player, SkillType.LightArmor);
                float armorLDP  = CalculatePartyLevelDifferencePenalty(partyLevel, armorRank);
                float percent   = lightArmorPoints / (float)totalPoints;

                GiveSkillXP(preg.Player, SkillType.LightArmor, (int)(armorXP * percent * armorLDP));

                armorRank = GetPCSkillRank(preg.Player, SkillType.HeavyArmor);
                armorLDP  = CalculatePartyLevelDifferencePenalty(partyLevel, armorRank);
                percent   = heavyArmorPoints / (float)totalPoints;

                GiveSkillXP(preg.Player, SkillType.HeavyArmor, (int)(armorXP * percent * armorLDP));

                armorRank = GetPCSkillRank(preg.Player, SkillType.ForceArmor);
                armorLDP  = CalculatePartyLevelDifferencePenalty(partyLevel, armorRank);
                percent   = forceArmorPoints / (float)totalPoints;

                GiveSkillXP(preg.Player, SkillType.ForceArmor, (int)(armorXP * percent * armorLDP));
            }

            _cache.CreatureSkillRegistrations.Remove(creature.GlobalID);
        }