Beispiel #1
0
        public static void TickLineOfSightTest(IHTNAgent npc, ref NpcPlayerInfo info)
        {
            BearDomain aiDomain = npc.AiDomain as BearDomain;

            if (Object.op_Equality((Object)aiDomain, (Object)null))
            {
                return;
            }
            bool isStanding = aiDomain.BearContext.IsFact(Rust.Ai.HTN.Bear.Facts.IsStandingUp);

            info.HeadVisible = false;
            info.BodyVisible = false;
            if ((double)info.SqrDistance >= (double)aiDomain.BearDefinition.SqrAggroRange(isStanding) || (double)info.ForwardDotDir <= (double)npc.AiDefinition.Sensory.FieldOfViewRadians)
            {
                return;
            }
            float maxDistance = aiDomain.BearDefinition.AggroRange(isStanding);
            Ray   ray1        = BearEnemyPlayersLineOfSightSensor.AimAtBody(npc, ref info);

            if (info.Player.IsVisible(ray1, maxDistance))
            {
                info.BodyVisible = true;
                npc.AiDomain.NpcContext.EnemyPlayersInLineOfSight.Add(info);
            }
            else
            {
                Ray ray2 = BearEnemyPlayersLineOfSightSensor.AimAtHead(npc, ref info);
                if (!info.Player.IsVisible(ray2, maxDistance))
                {
                    return;
                }
                info.HeadVisible = true;
                npc.AiDomain.NpcContext.EnemyPlayersInLineOfSight.Add(info);
            }
        }
Beispiel #2
0
        public static void TickLineOfSightTest(IHTNAgent npc, ref NpcPlayerInfo info)
        {
            BearDomain aiDomain = npc.AiDomain as BearDomain;

            if (aiDomain == null)
            {
                return;
            }
            bool flag = aiDomain.BearContext.IsFact(Facts.IsStandingUp);

            info.HeadVisible = false;
            info.BodyVisible = false;
            if (info.SqrDistance < aiDomain.BearDefinition.SqrAggroRange(flag) && info.ForwardDotDir > npc.AiDefinition.Sensory.FieldOfViewRadians)
            {
                float single = aiDomain.BearDefinition.AggroRange(flag);
                Ray   ray    = BearEnemyPlayersLineOfSightSensor.AimAtBody(npc, ref info);
                if (info.Player.IsVisible(ray, single))
                {
                    info.BodyVisible = true;
                    npc.AiDomain.NpcContext.EnemyPlayersInLineOfSight.Add(info);
                    return;
                }
                ray = BearEnemyPlayersLineOfSightSensor.AimAtHead(npc, ref info);
                if (info.Player.IsVisible(ray, single))
                {
                    info.HeadVisible = true;
                    npc.AiDomain.NpcContext.EnemyPlayersInLineOfSight.Add(info);
                }
            }
        }
Beispiel #3
0
        public static Ray AimAtBody(IHTNAgent npc, ref NpcPlayerInfo info)
        {
            HTNPlayer npc1 = npc as HTNPlayer;

            if (Object.op_Inequality((Object)npc1, (Object)null))
            {
                return(BearEnemyPlayersLineOfSightSensor.AimAtBody(npc1, ref info));
            }
            HTNAnimal npc2 = npc as HTNAnimal;

            if (Object.op_Inequality((Object)npc2, (Object)null))
            {
                return(BearEnemyPlayersLineOfSightSensor.AimAtBody(npc2, ref info));
            }
            return((Ray)null);
        }
Beispiel #4
0
        public static Ray AimAtHead(IHTNAgent npc, ref NpcPlayerInfo info)
        {
            HTNPlayer hTNPlayer = npc as HTNPlayer;

            if (hTNPlayer != null)
            {
                return(BearEnemyPlayersLineOfSightSensor.AimAtHead(hTNPlayer, ref info));
            }
            HTNAnimal hTNAnimal = npc as HTNAnimal;

            if (hTNAnimal != null)
            {
                return(BearEnemyPlayersLineOfSightSensor.AimAtHead(hTNAnimal, ref info));
            }
            return(new Ray());
        }
Beispiel #5
0
        public static void TickStatic(IHTNAgent npc)
        {
            npc.AiDomain.NpcContext.EnemyPlayersInLineOfSight.Clear();
            List <NpcPlayerInfo> enemyPlayersInRange = npc.AiDomain.NpcContext.EnemyPlayersInRange;

            for (int index = 0; index < enemyPlayersInRange.Count; ++index)
            {
                NpcPlayerInfo info = enemyPlayersInRange[index];
                if (Object.op_Equality((Object)info.Player, (Object)null) || Object.op_Equality((Object)((Component)info.Player).get_transform(), (Object)null) || (info.Player.IsDestroyed || info.Player.IsDead()))
                {
                    enemyPlayersInRange.RemoveAt(index);
                    --index;
                }
                else
                {
                    BearEnemyPlayersLineOfSightSensor.TickLineOfSightTest(npc, ref info);
                }
            }
        }
Beispiel #6
0
        public static void TickStatic(IHTNAgent npc)
        {
            npc.AiDomain.NpcContext.EnemyPlayersInLineOfSight.Clear();
            List <NpcPlayerInfo> enemyPlayersInRange = npc.AiDomain.NpcContext.EnemyPlayersInRange;

            for (int i = 0; i < enemyPlayersInRange.Count; i++)
            {
                NpcPlayerInfo item = enemyPlayersInRange[i];
                if (item.Player == null || item.Player.transform == null || item.Player.IsDestroyed || item.Player.IsDead())
                {
                    enemyPlayersInRange.RemoveAt(i);
                    i--;
                }
                else
                {
                    BearEnemyPlayersLineOfSightSensor.TickLineOfSightTest(npc, ref item);
                }
            }
        }
Beispiel #7
0
 public void Tick(IHTNAgent npc, float deltaTime, float time)
 {
     BearEnemyPlayersLineOfSightSensor.TickStatic(npc);
 }