Example #1
0
    public virtual void InitializeAI()
    {
        T entity = GetEntity();

        entity.HasBrain = true;
        Navigator       = GetComponent <BaseNavigator>();
        if (UseAIDesign)
        {
            AIDesign = new AIDesign();
            AIDesign.SetAvailableStates(GetStateList());
            if (Events == null)
            {
                Events = new AIEvents();
            }
            bool senseFriendlies = MaxGroupSize > 0;
            Senses.Init(entity, SenseRange, TargetLostRange, VisionCone, CheckVisionCone, CheckLOS, IgnoreNonVisionSneakers, ListenRange, HostileTargetsOnly, senseFriendlies, IgnoreSafeZonePlayers, SenseTypes);
            if (DefaultDesignSO == null)
            {
                Debug.LogWarning("Brain on " + base.gameObject.name + " is trying to load a null AI design!");
                return;
            }
            Events.Memory.Position.Set(base.transform.position, 4);
            LoadAIDesign(AIDesigns.GetByNameOrInstance(DefaultDesignSO.Filename, InstanceSpecificDesign), null);
            AIInformationZone forPoint = AIInformationZone.GetForPoint(base.transform.position, false);
            if (forPoint != null)
            {
                forPoint.RegisterSleepableEntity(this);
            }
        }
        BaseEntity.Query.Server.AddBrain(entity);
        StartMovementTick();
    }
Example #2
0
        public override void StateEnter()
        {
            base.StateEnter();
            status = StateStatus.Error;
            brain.Navigator.SetBrakingEnabled(false);
            path = brain.Navigator.Path;
            T entity = GetEntity();

            if (path == null)
            {
                AIInformationZone forPoint = AIInformationZone.GetForPoint(entity.ServerPosition);
                if (forPoint == null)
                {
                    return;
                }
                path = forPoint.GetNearestPath(entity.ServerPosition);
                if (path == null)
                {
                    return;
                }
            }
            currentTargetPoint = path.FindNearestPoint(entity.ServerPosition);
            if (!(currentTargetPoint == null))
            {
                status          = StateStatus.Running;
                currentWaitTime = 0f;
                brain.Navigator.SetDestination(currentTargetPoint.transform.position, BaseNavigator.NavigationSpeed.Slow);
            }
        }
Example #3
0
 public AIInformationZone GetInformationZone(Vector3 pos)
 {
     if (cachedInfoZone == null || UnityEngine.Time.time > nextZoneSearchTime)
     {
         cachedInfoZone     = AIInformationZone.GetForPoint(pos);
         nextZoneSearchTime = UnityEngine.Time.time + 5f;
     }
     return(cachedInfoZone);
 }
Example #4
0
 public AIInformationZone GetInformationZone()
 {
     if (Object.op_Equality((Object)this.cachedInfoZone, (Object)null) || (double)Time.get_time() > (double)this.nextZoneSearchTime)
     {
         this.cachedInfoZone     = AIInformationZone.GetForPoint(this.ServerPosition, (BaseEntity)this);
         this.nextZoneSearchTime = Time.get_time() + 5f;
     }
     return(this.cachedInfoZone);
 }
 public AIInformationZone GetInformationZone()
 {
     if (this.cachedInfoZone == null || UnityEngine.Time.time > this.nextZoneSearchTime)
     {
         this.cachedInfoZone     = AIInformationZone.GetForPoint(this.ServerPosition, this);
         this.nextZoneSearchTime = UnityEngine.Time.time + 5f;
     }
     return(this.cachedInfoZone);
 }
Example #6
0
 public AIInformationZone GetInformationZone(Vector3 pos)
 {
     if (VirtualInfoZone != null)
     {
         return(VirtualInfoZone);
     }
     if (cachedInfoZone == null || Time.time > nextZoneSearchTime)
     {
         cachedInfoZone     = AIInformationZone.GetForPoint(pos);
         nextZoneSearchTime = Time.time + 5f;
     }
     return(cachedInfoZone);
 }
Example #7
0
 public virtual void OnDestroy()
 {
     if (!Rust.Application.isQuitting)
     {
         BaseEntity.Query.Server.RemoveBrain(GetEntity());
         AIInformationZone aIInformationZone = null;
         HumanNPCNew       humanNPCNew       = GetEntity() as HumanNPCNew;
         if (humanNPCNew != null)
         {
             aIInformationZone = humanNPCNew.VirtualInfoZone;
         }
         if (aIInformationZone == null)
         {
             aIInformationZone = AIInformationZone.GetForPoint(base.transform.position);
         }
         if (aIInformationZone != null)
         {
             aIInformationZone.UnregisterSleepableEntity(this);
         }
         LeaveGroup();
     }
 }
Example #8
0
    public override void ServerInit()
    {
        NavMeshBuildSettings settingsByIndex;

        base.ServerInit();
        if (Door.nonWalkableArea < 0)
        {
            Door.nonWalkableArea = NavMesh.GetAreaFromName("Not Walkable");
        }
        if (Door.animalAgentTypeId < 0)
        {
            settingsByIndex        = NavMesh.GetSettingsByIndex(1);
            Door.animalAgentTypeId = settingsByIndex.agentTypeID;
        }
        if (this.NavMeshVolumeAnimals == null)
        {
            this.NavMeshVolumeAnimals      = base.gameObject.AddComponent <NavMeshModifierVolume>();
            this.NavMeshVolumeAnimals.area = Door.nonWalkableArea;
            this.NavMeshVolumeAnimals.AddAgentType(Door.animalAgentTypeId);
            this.NavMeshVolumeAnimals.center = Vector3.zero;
            this.NavMeshVolumeAnimals.size   = Vector3.one;
        }
        if (this.HasSlot(BaseEntity.Slot.Lock))
        {
            this.canNpcOpen = false;
        }
        if (!this.canNpcOpen)
        {
            if (Door.humanoidAgentTypeId < 0)
            {
                settingsByIndex          = NavMesh.GetSettingsByIndex(0);
                Door.humanoidAgentTypeId = settingsByIndex.agentTypeID;
            }
            if (this.NavMeshVolumeHumanoids == null)
            {
                this.NavMeshVolumeHumanoids      = base.gameObject.AddComponent <NavMeshModifierVolume>();
                this.NavMeshVolumeHumanoids.area = Door.nonWalkableArea;
                this.NavMeshVolumeHumanoids.AddAgentType(Door.humanoidAgentTypeId);
                this.NavMeshVolumeHumanoids.center = Vector3.zero;
                this.NavMeshVolumeHumanoids.size   = (Vector3.one + Vector3.up) + Vector3.forward;
            }
        }
        else if (this.NpcTriggerBox == null)
        {
            if (this.isSecurityDoor)
            {
                NavMeshObstacle navMeshObstacle = base.gameObject.AddComponent <NavMeshObstacle>();
                navMeshObstacle.carving = true;
                navMeshObstacle.center  = Vector3.zero;
                navMeshObstacle.size    = Vector3.one;
                navMeshObstacle.shape   = NavMeshObstacleShape.Box;
            }
            this.NpcTriggerBox = (new GameObject("NpcTriggerBox")).AddComponent <NPCDoorTriggerBox>();
            this.NpcTriggerBox.Setup(this);
        }
        AIInformationZone forPoint = AIInformationZone.GetForPoint(base.transform.position, null);

        if (forPoint != null && this.NavMeshLink == null)
        {
            this.NavMeshLink = forPoint.GetClosestNavMeshLink(base.transform.position);
        }
    }
Example #9
0
    public override void ServerInit()
    {
        base.ServerInit();
        if (Door.nonWalkableArea < 0)
        {
            Door.nonWalkableArea = NavMesh.GetAreaFromName("Not Walkable");
        }
        if (Door.animalAgentTypeId < 0)
        {
            NavMeshBuildSettings settingsByIndex = NavMesh.GetSettingsByIndex(1);
            Door.animalAgentTypeId = ((NavMeshBuildSettings) ref settingsByIndex).get_agentTypeID();
        }
        if (Object.op_Equality((Object)this.NavMeshVolumeAnimals, (Object)null))
        {
            this.NavMeshVolumeAnimals = (NavMeshModifierVolume)((Component)this).get_gameObject().AddComponent <NavMeshModifierVolume>();
            this.NavMeshVolumeAnimals.set_area(Door.nonWalkableArea);
            this.NavMeshVolumeAnimals.AddAgentType(Door.animalAgentTypeId);
            this.NavMeshVolumeAnimals.set_center(Vector3.get_zero());
            this.NavMeshVolumeAnimals.set_size(Vector3.get_one());
        }
        if (this.HasSlot(BaseEntity.Slot.Lock))
        {
            this.canNpcOpen = false;
        }
        if (!this.canNpcOpen)
        {
            if (Door.humanoidAgentTypeId < 0)
            {
                NavMeshBuildSettings settingsByIndex = NavMesh.GetSettingsByIndex(0);
                Door.humanoidAgentTypeId = ((NavMeshBuildSettings) ref settingsByIndex).get_agentTypeID();
            }
            if (Object.op_Equality((Object)this.NavMeshVolumeHumanoids, (Object)null))
            {
                this.NavMeshVolumeHumanoids = (NavMeshModifierVolume)((Component)this).get_gameObject().AddComponent <NavMeshModifierVolume>();
                this.NavMeshVolumeHumanoids.set_area(Door.nonWalkableArea);
                this.NavMeshVolumeHumanoids.AddAgentType(Door.humanoidAgentTypeId);
                this.NavMeshVolumeHumanoids.set_center(Vector3.get_zero());
                this.NavMeshVolumeHumanoids.set_size(Vector3.op_Addition(Vector3.op_Addition(Vector3.get_one(), Vector3.get_up()), Vector3.get_forward()));
            }
        }
        else if (Object.op_Equality((Object)this.NpcTriggerBox, (Object)null))
        {
            if (this.isSecurityDoor)
            {
                M0 m0 = ((Component)this).get_gameObject().AddComponent <NavMeshObstacle>();
                ((NavMeshObstacle)m0).set_carving(true);
                ((NavMeshObstacle)m0).set_center(Vector3.get_zero());
                ((NavMeshObstacle)m0).set_size(Vector3.get_one());
                ((NavMeshObstacle)m0).set_shape((NavMeshObstacleShape)1);
            }
            this.NpcTriggerBox = (NPCDoorTriggerBox) new GameObject("NpcTriggerBox").AddComponent <NPCDoorTriggerBox>();
            this.NpcTriggerBox.Setup(this);
        }
        AIInformationZone forPoint = AIInformationZone.GetForPoint(((Component)this).get_transform().get_position(), (BaseEntity)null);

        if (!Object.op_Inequality((Object)forPoint, (Object)null) || !Object.op_Equality((Object)this.NavMeshLink, (Object)null))
        {
            return;
        }
        this.NavMeshLink = forPoint.GetClosestNavMeshLink(((Component)this).get_transform().get_position());
    }