Exemplo n.º 1
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            if (npcContext == null)
            {
                return;
            }
            BaseNpc animal      = (BaseNpc)null;
            float   sqrDistance = 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)sqrDistance)
                {
                    sqrDistance = animalInfo.SqrDistance;
                    animal      = animalInfo.Animal;
                }
            }
            if (Object.op_Inequality((Object)animal, (Object)null) && AnimalReasoner.IsNearby(npcContext.Domain, sqrDistance))
            {
                npcContext.Memory.RememberPrimaryAnimal(animal);
                npcContext.SetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.NearbyAnimal, true, true, true, true);
            }
            else
            {
                npcContext.SetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.NearbyAnimal, false, true, true, true);
            }
        }
Exemplo n.º 2
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            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);
            }
        }
 private static bool EvaluateAdvancement(
     IHTNAgent npc,
     ScientistJunkpileContext 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);
 }
Exemplo n.º 4
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            NavMeshHit navMeshHit;
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            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.Domain.SqrDistanceToSpawn() > npcContext.Domain.SqrMovementRadius)
                {
                    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);
                        return;
                    }
                }
            }
            else if (npcContext.IsFact(Facts.CanSeeEnemy) || time - npcContext.Body.lastAttackedTime < 2f || npcContext.IsFact(Facts.AtLocationHome))
            {
                npcContext.SetFact(Facts.IsReturningHome, false, true, true, true);
            }
        }
        private static bool EvaluateRetreat(
            IHTNAgent npc,
            ScientistJunkpileContext 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)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            if (npcContext == null)
            {
                return;
            }
            float num = AI.npc_junkpile_dist_aggro_gate * AI.npc_junkpile_dist_aggro_gate;

            for (int index = 0; index < npc.AiDomain.NpcContext.EnemyPlayersInRange.Count; ++index)
            {
                NpcPlayerInfo npcPlayerInfo = npc.AiDomain.NpcContext.EnemyPlayersInRange[index];
                if (!Object.op_Equality((Object)npcPlayerInfo.Player, (Object)null) && !Object.op_Equality((Object)((Component)npcPlayerInfo.Player).get_transform(), (Object)null))
                {
                    if (Mathf.Approximately(npcPlayerInfo.SqrDistance, 0.0f))
                    {
                        ref NpcPlayerInfo local        = ref npcPlayerInfo;
                        Vector3           vector3      = Vector3.op_Subtraction(((Component)npcPlayerInfo.Player).get_transform().get_position(), npc.BodyPosition);
                        double            sqrMagnitude = (double)((Vector3) ref vector3).get_sqrMagnitude();
                        local.SqrDistance = (float)sqrMagnitude;
                        npc.AiDomain.NpcContext.EnemyPlayersInRange[index] = npcPlayerInfo;
                    }
                    if ((double)npcPlayerInfo.SqrDistance < (double)num)
                    {
                        npcContext.Memory.MarkEnemy(npcPlayerInfo.Player);
                    }
                }
            }
 public void Tick(IHTNAgent npc, float deltaTime, float time)
 {
     ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;
     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 (ScientistJunkpileDomain.JunkpileCanNavigateToCoverLocation.Try(CoverTactic.Retreat, npcContext))
         {
             Vector3 coverPosition = ScientistJunkpileDomain.JunkpileNavigateToCover.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);
         }
     }
 }
        public static bool IsAtPreferredRange(
            ScientistJunkpileContext 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);
            }
        }
        public static bool IsAtPreferredRange(ScientistJunkpileContext 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);
        }
 private static bool EvaluateAdvancement(IHTNAgent npc, ScientistJunkpileContext 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);
 }
Exemplo n.º 11
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            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.ScientistJunkpile.Facts.NearbyExplosives, true, true, true, true);
                        npcContext.IncrementFact(Rust.Ai.HTN.ScientistJunkpile.Facts.Alertness, 2, true, true, true);
                        return;
                    }
                }
            }
            npcContext.SetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.NearbyExplosives, false, true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            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)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            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) || !AnimalReasoner.IsNearby(npcContext.Domain, sqrDistance))
            {
                npcContext.SetFact(Facts.NearbyAnimal, false, true, true, true);
                return;
            }
            npcContext.Memory.RememberPrimaryAnimal(animal);
            npcContext.SetFact(Facts.NearbyAnimal, true, true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            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)
            {
                if (npcContext.Memory.MarkedEnemies.Contains(npcPlayerInfo2.Player))
                {
                    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)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            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)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            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.ScientistJunkpile.Facts.AtLocationPreferredFightingRange, 1, true, true, true);
            }
            else
            {
                npcContext.SetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.AtLocationPreferredFightingRange, 0, true, true, true);
            }
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            if (npcContext == null)
            {
                return;
            }
            float npcJunkpileDistAggroGate = ConVar.AI.npc_junkpile_dist_aggro_gate * ConVar.AI.npc_junkpile_dist_aggro_gate;

            for (int i = 0; i < npc.AiDomain.NpcContext.EnemyPlayersInRange.Count; i++)
            {
                NpcPlayerInfo item = npc.AiDomain.NpcContext.EnemyPlayersInRange[i];
                if (!(item.Player == null) && !(item.Player.transform == null))
                {
                    if (Mathf.Approximately(item.SqrDistance, 0f))
                    {
                        Vector3 player = item.Player.transform.position - npc.BodyPosition;
                        item.SqrDistance = player.sqrMagnitude;
                        npc.AiDomain.NpcContext.EnemyPlayersInRange[i] = item;
                    }
                    if (item.SqrDistance < npcJunkpileDistAggroGate)
                    {
                        npcContext.Memory.MarkEnemy(item.Player);
                    }
                }
            }
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

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

            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);
            }
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            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)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            if (npcContext == null)
            {
                return;
            }
            npcContext.SetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.HasNearbyCover, npcContext.CoverPoints.Count > 0 ? 1 : 0, true, true, true);
            if (!npcContext.IsFact(Rust.Ai.HTN.ScientistJunkpile.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);
                            }
                        }
                    }
                }
            }
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            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);
            }
Exemplo n.º 23
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

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

            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);
        }
Exemplo n.º 25
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            if (npcContext == null)
            {
                return;
            }
            if (npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player != null && (ScientistJunkpileDomain.JunkpileNavigateToLastKnownLocationOfPrimaryEnemyPlayer.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);
        }
Exemplo n.º 26
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            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);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

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

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

            if (heldEntity)
            {
                BaseProjectile baseProjectile = heldEntity as BaseProjectile;
                float          sqrDistance    = Single.MaxValue;
                if (npcContext.PrimaryEnemyPlayerInLineOfSight.Player != null)
                {
                    sqrDistance = npcContext.PrimaryEnemyPlayerInLineOfSight.SqrDistance;
                    if (Mathf.Approximately(sqrDistance, 0f))
                    {
                        sqrDistance = Single.MaxValue;
                    }
                }
                else if (npcContext.Memory.PrimaryKnownAnimal.Animal != null)
                {
                    sqrDistance = npcContext.Memory.PrimaryKnownAnimal.SqrDistance;
                    if (Mathf.Approximately(sqrDistance, 0f))
                    {
                        sqrDistance = Single.MaxValue;
                    }
                }
                if (heldEntity.attackLengthMin < 0f || sqrDistance > npcContext.Body.AiDefinition.Engagement.SqrCloseRangeFirearm(baseProjectile))
                {
                    fireTactic = (heldEntity.attackLengthMin <0f || sqrDistance> npcContext.Body.AiDefinition.Engagement.SqrMediumRangeFirearm(baseProjectile) ? FireTactic.Single : FireTactic.Burst);
                }
                else
                {
                    fireTactic = FireTactic.FullAuto;
                }
            }
            npcContext.SetFact(Facts.FireTactic, fireTactic, true, true, true);
        }
Exemplo n.º 28
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            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.ScientistJunkpile.Facts.AmmoState, AmmoState.FullClip, true, true, true);
                        return;
                    }
                    if ((double)num > 0.600000023841858)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.AmmoState, AmmoState.HighClip, true, true, true);
                        return;
                    }
                    if ((double)num > 0.170000001788139)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.AmmoState, AmmoState.MediumClip, true, true, true);
                        return;
                    }
                    if ((double)num > 0.0)
                    {
                        npcContext.SetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.AmmoState, AmmoState.LowAmmo, true, true, true);
                        return;
                    }
                    npcContext.SetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.AmmoState, AmmoState.EmptyClip, true, true, true);
                    return;
                }
            }
            npcContext.SetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.AmmoState, AmmoState.DontRequireAmmo, true, true, true);
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext;

            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.ScientistJunkpile.Facts.Vulnerability) || (double)time - (double)this._lastVulnerabilityDecrementTime <= 2.0))
            {
                return;
            }
            this._lastVulnerabilityDecrementTime = time;
            npcContext.IncrementFact(Rust.Ai.HTN.ScientistJunkpile.Facts.Vulnerability, -1, true, true, true);
        }
        private static bool EvaluateRetreat(IHTNAgent npc, ScientistJunkpileContext c, ref float bestScore, ref BaseNpcMemory.EnemyPlayerInfo enemyInfo, CoverPoint option, Vector3 dirCover, Vector3 dirDanger, ref float directness)
        {
            float single = dirCover.sqrMagnitude;

            if (directness <= -0.2f)
            {
                float allowedCoverRangeSqr = c.Domain.GetAllowedCoverRangeSqr();
                float single1 = directness * -1f + (allowedCoverRangeSqr - single) / allowedCoverRangeSqr + option.Score;
                if (single1 > bestScore)
                {
                    bestScore          = single1;
                    c.BestRetreatCover = option;
                    return(true);
                }
            }
            return(false);
        }