public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            float single = npc.healthFraction;

            if (single > 0.9f)
            {
                npcContext.SetFact(Facts.HealthState, HealthState.FullHealth, true, true, true);
                return;
            }
            if (single > 0.6f)
            {
                npcContext.SetFact(Facts.HealthState, HealthState.HighHealth, true, true, true);
                return;
            }
            if (single > 0.3f)
            {
                npcContext.SetFact(Facts.HealthState, HealthState.MediumHealth, true, true, true);
                return;
            }
            if (single > 0f)
            {
                npcContext.SetFact(Facts.HealthState, HealthState.LowHealth, true, true, true);
                return;
            }
            npcContext.SetFact(Facts.HealthState, HealthState.Dead, true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            NavMeshHit       navMeshHit;
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            if (!npcContext.IsFact(Facts.IsReturningHome))
            {
                if (npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player == null || time - npcContext.Memory.PrimaryKnownEnemyPlayer.Time > npcContext.Body.AiDefinition.Memory.NoSeeReturnToSpawnTime)
                {
                    npcContext.SetFact(Facts.IsReturningHome, true, true, true, true);
                    if (NavMesh.SamplePosition(npcContext.Domain.SpawnPosition, out navMeshHit, 1f, npcContext.Domain.NavAgent.areaMask))
                    {
                        npcContext.Domain.SetDestination(navMeshHit.position);
                        npcContext.Body.modelState.ducked = false;
                        npcContext.SetFact(Facts.IsDucking, 0, false, true, true);
                        return;
                    }
                }
            }
            else if (npcContext.IsFact(Facts.CanSeeEnemy) || time - npcContext.Body.lastAttackedTime < 2f || npcContext.IsFact(Facts.AtLocationHome))
            {
                npcContext.SetFact(Facts.IsReturningHome, false, true, true, true);
            }
        }
Beispiel #3
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            npcContext.SetFact(Facts.CanSeeEnemy, npcContext.EnemyPlayersInLineOfSight.Count > 0, true, true, true);
            float         num1           = 0.0f;
            NpcPlayerInfo npcPlayerInfo1 = new NpcPlayerInfo();

            foreach (NpcPlayerInfo npcPlayerInfo2 in npc.AiDomain.NpcContext.EnemyPlayersInLineOfSight)
            {
                float num2 = (float)((1.0 - (double)npcPlayerInfo2.SqrDistance / (double)npc.AiDefinition.Engagement.SqrAggroRange) * 2.0) + (float)(((double)npcPlayerInfo2.ForwardDotDir + 1.0) * 0.5);
                if ((double)num2 > (double)num1)
                {
                    num1           = num2;
                    npcPlayerInfo1 = npcPlayerInfo2;
                }
                NpcPlayerInfo info = npcPlayerInfo2;
                info.VisibilityScore = num2;
                npcContext.Memory.RememberEnemyPlayer(npc, ref info, time, 0.0f, "SEE!");
            }
            npcContext.PrimaryEnemyPlayerInLineOfSight = npcPlayerInfo1;
            if (!Object.op_Inequality((Object)npcPlayerInfo1.Player, (Object)null) || !Object.op_Equality((Object)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player, (Object)null) && (double)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.AudibleScore >= (double)num1)
            {
                return;
            }
            npcContext.Memory.RememberPrimaryEnemyPlayer(npcPlayerInfo1.Player);
            npcContext.IncrementFact(Facts.Alertness, 2, true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            BaseNpc animal      = null;
            float   sqrDistance = Single.MaxValue;

            for (int i = 0; i < npcContext.AnimalsInRange.Count; i++)
            {
                AnimalInfo item = npcContext.AnimalsInRange[i];
                if (item.Animal != null && item.SqrDistance < sqrDistance)
                {
                    sqrDistance = item.SqrDistance;
                    animal      = item.Animal;
                }
            }
            if (animal != null)
            {
                AttackEntity firearm = npcContext.Domain.GetFirearm();
                if (sqrDistance < npc.AiDefinition.Engagement.SqrCloseRangeFirearm(firearm))
                {
                    npcContext.Memory.RememberPrimaryAnimal(animal);
                    npcContext.SetFact(Facts.NearbyAnimal, true, true, true, true);
                    return;
                }
            }
            npcContext.SetFact(Facts.NearbyAnimal, false, true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            if (npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player == null)
            {
                npcContext.SetFact(Facts.EnemyRange, EnemyRange.OutOfRange, true, true, true);
            }
            Vector3      lastKnownPosition = npcContext.Memory.PrimaryKnownEnemyPlayer.LastKnownPosition - npcContext.BodyPosition;
            float        single            = lastKnownPosition.sqrMagnitude;
            AttackEntity firearm           = npcContext.Domain.GetFirearm();

            if (single <= npcContext.Body.AiDefinition.Engagement.SqrCloseRangeFirearm(firearm))
            {
                npcContext.SetFact(Facts.EnemyRange, EnemyRange.CloseRange, true, true, true);
                return;
            }
            if (single <= npcContext.Body.AiDefinition.Engagement.SqrMediumRangeFirearm(firearm))
            {
                npcContext.SetFact(Facts.EnemyRange, EnemyRange.MediumRange, true, true, true);
                return;
            }
            if (single <= npcContext.Body.AiDefinition.Engagement.SqrLongRangeFirearm(firearm))
            {
                npcContext.SetFact(Facts.EnemyRange, EnemyRange.LongRange, true, true, true);
                return;
            }
            npcContext.SetFact(Facts.EnemyRange, EnemyRange.OutOfRange, true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            float healthFraction = npc.healthFraction;

            if ((double)healthFraction > 0.899999976158142)
            {
                npcContext.SetFact(Facts.HealthState, HealthState.FullHealth, true, true, true);
            }
            else if ((double)healthFraction > 0.600000023841858)
            {
                npcContext.SetFact(Facts.HealthState, HealthState.HighHealth, true, true, true);
            }
            else if ((double)healthFraction > 0.300000011920929)
            {
                npcContext.SetFact(Facts.HealthState, HealthState.MediumHealth, true, true, true);
            }
            else if ((double)healthFraction > 0.0)
            {
                npcContext.SetFact(Facts.HealthState, HealthState.LowHealth, true, true, true);
            }
            else
            {
                npcContext.SetFact(Facts.HealthState, HealthState.Dead, true, true, true);
            }
        }
Beispiel #7
0
        public static float GetPreferredRange(ScientistContext context, ref NpcPlayerInfo target, AttackEntity firearm)
        {
            if (firearm == null)
            {
                return(context.Body.AiDefinition.Engagement.CenterOfMediumRangeFirearm(firearm));
            }
            switch (firearm.effectiveRangeType)
            {
            case NPCPlayerApex.WeaponTypeEnum.CloseRange:
            {
                return(context.Body.AiDefinition.Engagement.CloseRangeFirearm(firearm));
            }

            case NPCPlayerApex.WeaponTypeEnum.MediumRange:
            {
                return(context.Body.AiDefinition.Engagement.CenterOfMediumRangeFirearm(firearm));
            }

            case NPCPlayerApex.WeaponTypeEnum.LongRange:
            {
                return(context.Body.AiDefinition.Engagement.LongRangeFirearm(firearm));
            }
            }
            return(context.Body.AiDefinition.Engagement.CenterOfMediumRangeFirearm(firearm));
        }
Beispiel #8
0
        public static bool IsAtPreferredRange(ScientistContext context, ref NpcPlayerInfo target, AttackEntity firearm)
        {
            if (firearm == null)
            {
                return(false);
            }
            switch (firearm.effectiveRangeType)
            {
            case NPCPlayerApex.WeaponTypeEnum.CloseRange:
            {
                return(target.SqrDistance <= context.Body.AiDefinition.Engagement.SqrCloseRangeFirearm(firearm));
            }

            case NPCPlayerApex.WeaponTypeEnum.MediumRange:
            {
                if (target.SqrDistance > context.Body.AiDefinition.Engagement.SqrMediumRangeFirearm(firearm))
                {
                    return(false);
                }
                return(target.SqrDistance > context.Body.AiDefinition.Engagement.SqrCloseRangeFirearm(firearm));
            }

            case NPCPlayerApex.WeaponTypeEnum.LongRange:
            {
                if (target.SqrDistance >= context.Body.AiDefinition.Engagement.SqrLongRangeFirearm(firearm))
                {
                    return(false);
                }
                return(target.SqrDistance > context.Body.AiDefinition.Engagement.SqrMediumRangeFirearm(firearm));
            }
            }
            return(false);
        }
Beispiel #9
0
 private static bool EvaluateAdvancement(
     IHTNAgent npc,
     ScientistContext c,
     ref float bestScore,
     ref BaseNpcMemory.EnemyPlayerInfo enemyInfo,
     CoverPoint option,
     Vector3 dirCover,
     Vector3 dirDanger,
     float directness)
 {
     if ((double)directness >= 0.200000002980232)
     {
         float sqrMagnitude1 = ((Vector3) ref dirCover).get_sqrMagnitude();
         if ((double)sqrMagnitude1 > (double)((Vector3) ref dirDanger).get_sqrMagnitude() || (double)sqrMagnitude1 < 0.5)
         {
             return(false);
         }
         Vector3 vector3_1            = Vector3.op_Subtraction(option.Position, enemyInfo.LastKnownPosition);
         float   sqrMagnitude2        = ((Vector3) ref vector3_1).get_sqrMagnitude();
         float   allowedCoverRangeSqr = c.Domain.GetAllowedCoverRangeSqr();
         float   num = (float)((double)directness + ((double)allowedCoverRangeSqr - (double)sqrMagnitude1) / (double)allowedCoverRangeSqr + (double)option.Score + ((double)sqrMagnitude2 < (double)sqrMagnitude1 ? 1.0 : 0.0));
         if ((double)num > (double)bestScore && (!AI.npc_cover_use_path_distance || npc == null || c.Domain.PathDistanceIsValid(enemyInfo.LastKnownPosition, option.Position, false)))
         {
             Vector3 vector3_2 = Vector3.op_Subtraction(option.Position, enemyInfo.LastKnownPosition);
             if ((double)((Vector3) ref vector3_2).get_sqrMagnitude() < (double)sqrMagnitude1)
             {
                 num *= 0.9f;
             }
             bestScore          = num;
             c.BestAdvanceCover = option;
             return(true);
         }
     }
     return(false);
 }
Beispiel #10
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            HTNPlayer htnPlayer = npc as HTNPlayer;

            if (Object.op_Equality((Object)htnPlayer, (Object)null))
            {
                return;
            }
            FireTactic   fireTactic = FireTactic.Single;
            AttackEntity heldEntity = htnPlayer.GetHeldEntity() as AttackEntity;

            if (Object.op_Implicit((Object)heldEntity))
            {
                BaseProjectile baseProjectile = heldEntity as BaseProjectile;
                float          num            = float.MaxValue;
                if (Object.op_Inequality((Object)npcContext.PrimaryEnemyPlayerInLineOfSight.Player, (Object)null))
                {
                    num = npcContext.PrimaryEnemyPlayerInLineOfSight.SqrDistance;
                    if (Mathf.Approximately(num, 0.0f))
                    {
                        num = float.MaxValue;
                    }
                }
                fireTactic = (double)heldEntity.attackLengthMin <0.0 || (double)num> (double) npcContext.Body.AiDefinition.Engagement.SqrCloseRangeFirearm((AttackEntity)baseProjectile) ? ((double)heldEntity.attackLengthMin <0.0 || (double)num> (double) npcContext.Body.AiDefinition.Engagement.SqrMediumRangeFirearm((AttackEntity)baseProjectile) ? FireTactic.Single : FireTactic.Burst) : FireTactic.FullAuto;
            }
            npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.FireTactic, fireTactic, true, true, true);
        }
Beispiel #11
0
        private static bool EvaluateRetreat(
            IHTNAgent npc,
            ScientistContext c,
            ref float bestScore,
            ref BaseNpcMemory.EnemyPlayerInfo enemyInfo,
            CoverPoint option,
            Vector3 dirCover,
            Vector3 dirDanger,
            ref float directness)
        {
            float sqrMagnitude = ((Vector3) ref dirCover).get_sqrMagnitude();

            if ((double)directness <= -0.200000002980232)
            {
                float allowedCoverRangeSqr = c.Domain.GetAllowedCoverRangeSqr();
                float num = (float)((double)directness * -1.0 + ((double)allowedCoverRangeSqr - (double)sqrMagnitude) / (double)allowedCoverRangeSqr) + option.Score;
                if ((double)num > (double)bestScore)
                {
                    bestScore          = num;
                    c.BestRetreatCover = option;
                    return(true);
                }
            }
            return(false);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            for (int index = 0; index < npcContext.Memory.KnownTimedExplosives.Count; ++index)
            {
                BaseNpcMemory.EntityOfInterestInfo knownTimedExplosive = npcContext.Memory.KnownTimedExplosives[index];
                if (Object.op_Inequality((Object)knownTimedExplosive.Entity, (Object)null))
                {
                    AttackEntity firearm = npcContext.Domain.GetFirearm();
                    Vector3      vector3 = Vector3.op_Subtraction(((Component)knownTimedExplosive.Entity).get_transform().get_position(), npcContext.BodyPosition);
                    if ((double)((Vector3) ref vector3).get_sqrMagnitude() < (double)npcContext.Body.AiDefinition.Engagement.SqrCloseRangeFirearm(firearm))
                    {
                        npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.NearbyExplosives, true, true, true, true);
                        npcContext.IncrementFact(Rust.Ai.HTN.Scientist.Facts.Alertness, 2, true, true, true);
                        return;
                    }
                }
            }
            npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.NearbyExplosives, false, true, true, true);
        }
Beispiel #13
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            if (npcContext.IsFact(Facts.MaintainCover) || npcContext.IsFact(Facts.IsReloading) || npcContext.IsFact(Facts.IsApplyingMedical))
            {
                if (npcContext.ReservedCoverPoint != null && !npcContext.ReservedCoverPoint.IsCompromised && !npcContext.IsFact(Facts.AtLocationCover) && time - npcContext.ReservedCoverTime < 0.8f)
                {
                    return;
                }
                if (!npcContext.IsFact(Facts.CanSeeEnemy) && npcContext.Body.SecondsSinceAttacked - 1f > time - npcContext.ReservedCoverTime)
                {
                    return;
                }
                if (ScientistDomain.CanNavigateToCoverLocation.Try(CoverTactic.Retreat, npcContext))
                {
                    Vector3 coverPosition = ScientistDomain.NavigateToCover.GetCoverPosition(CoverTactic.Retreat, npcContext);
                    npcContext.Domain.SetDestination(coverPosition);
                    npcContext.Body.modelState.ducked = false;
                    npcContext.SetFact(Facts.IsDucking, 0, false, true, true);
                    npcContext.SetFact(Facts.FirearmOrder, FirearmOrders.FireAtWill, false, true, true);
                }
            }
        }
 private static bool EvaluateAdvancement(IHTNAgent npc, ScientistContext c, ref float bestScore, ref BaseNpcMemory.EnemyPlayerInfo enemyInfo, CoverPoint option, Vector3 dirCover, Vector3 dirDanger, float directness)
 {
     if (directness >= 0.2f)
     {
         float single = dirCover.sqrMagnitude;
         if (single > dirDanger.sqrMagnitude || single < 0.5f)
         {
             return(false);
         }
         float position             = (option.Position - enemyInfo.LastKnownPosition).sqrMagnitude;
         float allowedCoverRangeSqr = c.Domain.GetAllowedCoverRangeSqr();
         float single1 = directness + (allowedCoverRangeSqr - single) / allowedCoverRangeSqr + option.Score + (position < single ? 1f : 0f);
         if (single1 > bestScore)
         {
             if (ConVar.AI.npc_cover_use_path_distance && npc != null && !c.Domain.PathDistanceIsValid(enemyInfo.LastKnownPosition, option.Position, false))
             {
                 return(false);
             }
             if ((option.Position - enemyInfo.LastKnownPosition).sqrMagnitude < single)
             {
                 single1 *= 0.9f;
             }
             bestScore          = single1;
             c.BestAdvanceCover = option;
             return(true);
         }
     }
     return(false);
 }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            npcContext.SetFact(Facts.CanSeeEnemy, npcContext.EnemyPlayersInLineOfSight.Count > 0, true, true, true);
            float         single        = 0f;
            NpcPlayerInfo npcPlayerInfo = new NpcPlayerInfo();

            foreach (NpcPlayerInfo enemyPlayersInLineOfSight in npc.AiDomain.NpcContext.EnemyPlayersInLineOfSight)
            {
                float forwardDotDir = (enemyPlayersInLineOfSight.ForwardDotDir + 1f) * 0.5f;
                float sqrDistance   = (1f - enemyPlayersInLineOfSight.SqrDistance / npc.AiDefinition.Engagement.SqrAggroRange) * 2f + forwardDotDir;
                if (sqrDistance > single)
                {
                    single        = sqrDistance;
                    npcPlayerInfo = enemyPlayersInLineOfSight;
                }
                NpcPlayerInfo npcPlayerInfo1 = enemyPlayersInLineOfSight;
                npcPlayerInfo1.VisibilityScore = sqrDistance;
                npcContext.Memory.RememberEnemyPlayer(npc, ref npcPlayerInfo1, time, 0f, "SEE!");
            }
            npcContext.PrimaryEnemyPlayerInLineOfSight = npcPlayerInfo;
            if (npcPlayerInfo.Player != null && (npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player == null || npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.AudibleScore < single))
            {
                npcContext.Memory.RememberPrimaryEnemyPlayer(npcPlayerInfo.Player);
                npcContext.IncrementFact(Facts.Alertness, 2, true, true, true);
            }
        }
        public static bool IsAtPreferredRange(
            ScientistContext context,
            ref NpcPlayerInfo target,
            AttackEntity firearm)
        {
            if (Object.op_Equality((Object)firearm, (Object)null))
            {
                return(false);
            }
            switch (firearm.effectiveRangeType)
            {
            case NPCPlayerApex.WeaponTypeEnum.CloseRange:
                return((double)target.SqrDistance <= (double)context.Body.AiDefinition.Engagement.SqrCloseRangeFirearm(firearm));

            case NPCPlayerApex.WeaponTypeEnum.MediumRange:
                if ((double)target.SqrDistance <= (double)context.Body.AiDefinition.Engagement.SqrMediumRangeFirearm(firearm))
                {
                    return((double)target.SqrDistance > (double)context.Body.AiDefinition.Engagement.SqrCloseRangeFirearm(firearm));
                }
                return(false);

            case NPCPlayerApex.WeaponTypeEnum.LongRange:
                if ((double)target.SqrDistance < (double)context.Body.AiDefinition.Engagement.SqrLongRangeFirearm(firearm))
                {
                    return((double)target.SqrDistance > (double)context.Body.AiDefinition.Engagement.SqrMediumRangeFirearm(firearm));
                }
                return(false);

            default:
                return(false);
            }
        }
Beispiel #17
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            BaseNpc animal = (BaseNpc)null;
            float   num    = float.MaxValue;

            for (int index = 0; index < npcContext.AnimalsInRange.Count; ++index)
            {
                AnimalInfo animalInfo = npcContext.AnimalsInRange[index];
                if (Object.op_Inequality((Object)animalInfo.Animal, (Object)null) && (double)animalInfo.SqrDistance < (double)num)
                {
                    num    = animalInfo.SqrDistance;
                    animal = animalInfo.Animal;
                }
            }
            if (Object.op_Inequality((Object)animal, (Object)null))
            {
                AttackEntity firearm = npcContext.Domain.GetFirearm();
                if ((double)num < (double)npc.AiDefinition.Engagement.SqrCloseRangeFirearm(firearm))
                {
                    npcContext.Memory.RememberPrimaryAnimal(animal);
                    npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.NearbyAnimal, true, true, true, true);
                    return;
                }
            }
            npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.NearbyAnimal, false, true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            if (!npcContext.IsFact(Facts.IsReturningHome))
            {
                if (!Object.op_Equality((Object)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player, (Object)null) && (double)time - (double)npcContext.Memory.PrimaryKnownEnemyPlayer.Time <= (double)npcContext.Body.AiDefinition.Memory.NoSeeReturnToSpawnTime)
                {
                    return;
                }
                npcContext.SetFact(Facts.IsReturningHome, true, true, true, true);
                NavMeshHit navMeshHit;
                if (!NavMesh.SamplePosition(npcContext.Domain.SpawnPosition, ref navMeshHit, 1f, npcContext.Domain.NavAgent.get_areaMask()))
                {
                    return;
                }
                npcContext.Domain.SetDestination(((NavMeshHit) ref navMeshHit).get_position());
                npcContext.Body.modelState.set_ducked(false);
                npcContext.SetFact(Facts.IsDucking, 0, false, true, true);
            }
            else
            {
                if (!npcContext.IsFact(Facts.CanSeeEnemy) && (double)time - (double)npcContext.Body.lastAttackedTime >= 2.0 && !npcContext.IsFact(Facts.AtLocationHome))
                {
                    return;
                }
                npcContext.SetFact(Facts.IsReturningHome, false, true, true, true);
            }
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            NpcPlayerInfo enemyPlayerTarget = npcContext.GetPrimaryEnemyPlayerTarget();

            if (!Object.op_Inequality((Object)enemyPlayerTarget.Player, (Object)null))
            {
                return;
            }
            AttackEntity firearm = npcContext.Domain.GetFirearm();

            if (PreferredFightingRangeReasoner.IsAtPreferredRange(npcContext, ref enemyPlayerTarget, firearm))
            {
                npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.AtLocationPreferredFightingRange, 1, true, true, true);
            }
            else
            {
                npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.AtLocationPreferredFightingRange, 0, true, true, true);
            }
        }
Beispiel #20
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            npcContext.SetFact(Facts.HasEnemyTarget, npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player != null, true, true, true);
        }
Beispiel #21
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null || !npcContext.IsFact(Facts.Frustration) || (double)time - (double)this._lastFrustrationDecrementTime <= 5.0)
            {
                return;
            }
            this._lastFrustrationDecrementTime = time;
            npcContext.IncrementFact(Facts.Frustration, -1, true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            npcContext.SetFact(Facts.HasNearbyCover, (npcContext.CoverPoints.Count > 0 ? 1 : 0), true, true, true);
            if (!npcContext.IsFact(Facts.HasEnemyTarget))
            {
                npcContext.ReserveCoverPoint(null);
                return;
            }
            HTNPlayer hTNPlayer = npc as HTNPlayer;

            if (hTNPlayer == null)
            {
                return;
            }
            float single  = 0f;
            float single1 = 0f;
            float single2 = 0f;

            foreach (CoverPoint coverPoint in npcContext.CoverPoints)
            {
                if (coverPoint.IsCompromised || coverPoint.IsReserved && !coverPoint.ReservedFor.EqualNetID(hTNPlayer))
                {
                    continue;
                }
                float single3 = -0.8f;
                BaseNpcMemory.EnemyPlayerInfo primaryKnownEnemyPlayer = npcContext.Memory.PrimaryKnownEnemyPlayer;
                if (!coverPoint.ProvidesCoverFromPoint(primaryKnownEnemyPlayer.LastKnownPosition, single3))
                {
                    continue;
                }
                Vector3 position          = coverPoint.Position - npc.transform.position;
                Vector3 lastKnownPosition = primaryKnownEnemyPlayer.LastKnownPosition - npc.transform.position;
                float   single4           = Vector3.Dot(position.normalized, lastKnownPosition.normalized);
                if (single < 1f)
                {
                    CoverPointsReasoner.EvaluateAdvancement(npc, npcContext, ref single, ref primaryKnownEnemyPlayer, coverPoint, position, lastKnownPosition, single4);
                }
                if (single2 < 1f)
                {
                    CoverPointsReasoner.EvaluateRetreat(npc, npcContext, ref single2, ref primaryKnownEnemyPlayer, coverPoint, position, lastKnownPosition, ref single4);
                }
                if (single1 >= 1f)
                {
                    continue;
                }
                CoverPointsReasoner.EvaluateFlanking(npc, npcContext, ref single1, ref primaryKnownEnemyPlayer, coverPoint, position, lastKnownPosition, single4);
            }
        }
Beispiel #23
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.HasNearbyCover, npcContext.CoverPoints.Count > 0 ? 1 : 0, true, true, true);
            if (!npcContext.IsFact(Rust.Ai.HTN.Scientist.Facts.HasEnemyTarget))
            {
                npcContext.ReserveCoverPoint((CoverPoint)null);
            }
            else
            {
                HTNPlayer htnPlayer = npc as HTNPlayer;
                if (Object.op_Equality((Object)htnPlayer, (Object)null))
                {
                    return;
                }
                float bestScore1 = 0.0f;
                float bestScore2 = 0.0f;
                float bestScore3 = 0.0f;
                foreach (CoverPoint coverPoint in npcContext.CoverPoints)
                {
                    if (!coverPoint.IsCompromised && (!coverPoint.IsReserved || coverPoint.ReservedFor.EqualNetID((BaseNetworkable)htnPlayer)))
                    {
                        float arcThreshold = -0.8f;
                        BaseNpcMemory.EnemyPlayerInfo knownEnemyPlayer = npcContext.Memory.PrimaryKnownEnemyPlayer;
                        if (coverPoint.ProvidesCoverFromPoint(knownEnemyPlayer.LastKnownPosition, arcThreshold))
                        {
                            Vector3 dirCover   = Vector3.op_Subtraction(coverPoint.Position, npc.transform.get_position());
                            Vector3 dirDanger  = Vector3.op_Subtraction(knownEnemyPlayer.LastKnownPosition, npc.transform.get_position());
                            float   directness = Vector3.Dot(((Vector3) ref dirCover).get_normalized(), ((Vector3) ref dirDanger).get_normalized());
                            if ((double)bestScore1 < 1.0)
                            {
                                CoverPointsReasoner.EvaluateAdvancement(npc, npcContext, ref bestScore1, ref knownEnemyPlayer, coverPoint, dirCover, dirDanger, directness);
                            }
                            if ((double)bestScore3 < 1.0)
                            {
                                CoverPointsReasoner.EvaluateRetreat(npc, npcContext, ref bestScore3, ref knownEnemyPlayer, coverPoint, dirCover, dirDanger, ref directness);
                            }
                            if ((double)bestScore2 < 1.0)
                            {
                                CoverPointsReasoner.EvaluateFlanking(npc, npcContext, ref bestScore2, ref knownEnemyPlayer, coverPoint, dirCover, dirDanger, directness);
                            }
                        }
                    }
                }
            }
        }
Beispiel #24
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            Vector3 vector3 = Vector3.op_Subtraction(npcContext.BodyPosition, npcContext.Domain.SpawnPosition);

            if ((double)((Vector3) ref vector3).get_sqrMagnitude() < 3.0)
            {
                npcContext.SetFact(Facts.AtLocationHome, true, true, true, true);
            }
Beispiel #25
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            if (npcContext.IsFact(Facts.Frustration) && time - this._lastFrustrationDecrementTime > 5f)
            {
                this._lastFrustrationDecrementTime = time;
                npcContext.IncrementFact(Facts.Frustration, -1, true, true, true);
            }
        }
Beispiel #26
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            if (npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player != null && (ScientistDomain.NavigateToLastKnownLocationOfPrimaryEnemyPlayer.GetDestination(npcContext) - npcContext.Body.transform.position).sqrMagnitude < 1f)
            {
                npcContext.SetFact(Facts.AtLocationLastKnownLocationOfPrimaryEnemyPlayer, 1, true, true, true);
                return;
            }
            npcContext.SetFact(Facts.AtLocationLastKnownLocationOfPrimaryEnemyPlayer, 0, true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            if ((npcContext.BodyPosition - npcContext.Domain.SpawnPosition).sqrMagnitude < 3f)
            {
                npcContext.SetFact(Facts.AtLocationHome, true, true, true, true);
                return;
            }
            npcContext.SetFact(Facts.AtLocationHome, false, true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            HTNPlayer hTNPlayer = npc as HTNPlayer;

            if (hTNPlayer == null)
            {
                return;
            }
            AttackEntity heldEntity = hTNPlayer.GetHeldEntity() as AttackEntity;

            if (heldEntity)
            {
                BaseProjectile baseProjectile = heldEntity as BaseProjectile;
                if (baseProjectile != null)
                {
                    float single = (float)baseProjectile.primaryMagazine.contents / (float)baseProjectile.primaryMagazine.capacity;
                    if (single > 0.9f)
                    {
                        npcContext.SetFact(Facts.AmmoState, AmmoState.FullClip, true, true, true);
                        return;
                    }
                    if (single > 0.6f)
                    {
                        npcContext.SetFact(Facts.AmmoState, AmmoState.HighClip, true, true, true);
                        return;
                    }
                    if (single > 0.17f)
                    {
                        npcContext.SetFact(Facts.AmmoState, AmmoState.MediumClip, true, true, true);
                        return;
                    }
                    if (single > 0f)
                    {
                        npcContext.SetFact(Facts.AmmoState, AmmoState.LowAmmo, true, true, true);
                        return;
                    }
                    npcContext.SetFact(Facts.AmmoState, AmmoState.EmptyClip, true, true, true);
                    return;
                }
            }
            npcContext.SetFact(Facts.AmmoState, AmmoState.DontRequireAmmo, true, true, true);
        }
Beispiel #29
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            HTNPlayer htnPlayer = npc as HTNPlayer;

            if (Object.op_Equality((Object)htnPlayer, (Object)null))
            {
                return;
            }
            AttackEntity heldEntity = htnPlayer.GetHeldEntity() as AttackEntity;

            if (Object.op_Implicit((Object)heldEntity))
            {
                BaseProjectile baseProjectile = heldEntity as BaseProjectile;
                if (Object.op_Inequality((Object)baseProjectile, (Object)null))
                {
                    float num = (float)baseProjectile.primaryMagazine.contents / (float)baseProjectile.primaryMagazine.capacity;
                    if ((double)num > 0.899999976158142)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.AmmoState, AmmoState.FullClip, true, true, true);
                        return;
                    }
                    if ((double)num > 0.600000023841858)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.AmmoState, AmmoState.HighClip, true, true, true);
                        return;
                    }
                    if ((double)num > 0.170000001788139)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.AmmoState, AmmoState.MediumClip, true, true, true);
                        return;
                    }
                    if ((double)num > 0.0)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.AmmoState, AmmoState.LowAmmo, true, true, true);
                        return;
                    }
                    npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.AmmoState, AmmoState.EmptyClip, true, true, true);
                    return;
                }
            }
            npcContext.SetFact(Rust.Ai.HTN.Scientist.Facts.AmmoState, AmmoState.DontRequireAmmo, true, true, true);
        }
Beispiel #30
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistContext npcContext = npc.AiDomain.NpcContext as ScientistContext;

            if (npcContext == null)
            {
                return;
            }
            HTNPlayer htnPlayer = npc as HTNPlayer;

            if (Object.op_Equality((Object)htnPlayer, (Object)null) || (double)time - (double)htnPlayer.lastAttackedTime <= 3.0 || (!npcContext.IsFact(Rust.Ai.HTN.Scientist.Facts.Vulnerability) || (double)time - (double)this._lastVulnerabilityDecrementTime <= 2.0))
            {
                return;
            }
            this._lastVulnerabilityDecrementTime = time;
            npcContext.IncrementFact(Rust.Ai.HTN.Scientist.Facts.Vulnerability, -1, true, true, true);
        }