예제 #1
0
 // Token: 0x06001087 RID: 4231 RVA: 0x00075082 File Offset: 0x00073282
 private void GenerateDungeon(ZoneSystem.SpawnMode mode)
 {
     this.PlaceStartRoom(mode);
     this.PlaceRooms(mode);
     this.PlaceEndCaps(mode);
     this.PlaceDoors(mode);
 }
예제 #2
0
    // Token: 0x06001098 RID: 4248 RVA: 0x00075BF4 File Offset: 0x00073DF4
    private bool PlaceRoom(RoomConnection connection, DungeonDB.RoomData roomData, ZoneSystem.SpawnMode mode)
    {
        Room       room       = roomData.m_room;
        Quaternion quaternion = connection.transform.rotation;

        quaternion *= Quaternion.Euler(0f, 180f, 0f);
        RoomConnection connection2 = room.GetConnection(connection);
        Vector3        pos;
        Quaternion     rot;

        this.CalculateRoomPosRot(connection2, connection.transform.position, quaternion, out pos, out rot);
        if (room.m_size.x != 0 && room.m_size.z != 0 && this.TestCollision(room, pos, rot))
        {
            return(false);
        }
        this.PlaceRoom(roomData, pos, rot, connection, mode);
        if (!room.m_endCap)
        {
            if (connection.m_allowDoor)
            {
                DungeonGenerator.m_doorConnections.Add(connection);
            }
            DungeonGenerator.m_openConnections.Remove(connection);
        }
        return(true);
    }
예제 #3
0
    // Token: 0x06001090 RID: 4240 RVA: 0x0007579C File Offset: 0x0007399C
    private void PlaceDoors(ZoneSystem.SpawnMode mode)
    {
        int num = 0;

        foreach (RoomConnection roomConnection in DungeonGenerator.m_doorConnections)
        {
            if (UnityEngine.Random.value <= this.m_doorChance)
            {
                DungeonGenerator.DoorDef doorDef = this.FindDoorType(roomConnection.m_type);
                if (doorDef == null)
                {
                    ZLog.Log("No door type for connection:" + roomConnection.m_type);
                }
                else
                {
                    GameObject obj = UnityEngine.Object.Instantiate <GameObject>(doorDef.m_prefab, roomConnection.transform.position, roomConnection.transform.rotation);
                    if (mode == ZoneSystem.SpawnMode.Ghost)
                    {
                        UnityEngine.Object.Destroy(obj);
                    }
                    num++;
                }
            }
        }
        ZLog.Log("placed " + num + " doors");
    }
예제 #4
0
 /// <summary>
 ///     Output custom location spawns
 /// </summary>
 private void ZoneSystem_SpawnLocation(ZoneSystem.ZoneLocation location, ZoneSystem.SpawnMode mode)
 {
     if (ZoneManager.Instance.Locations.ContainsKey(location.m_prefabName))
     {
         Logger.LogDebug($"spawned {location.m_prefabName}, mode: {mode}");
     }
 }
예제 #5
0
    // Token: 0x06001088 RID: 4232 RVA: 0x000750A0 File Offset: 0x000732A0
    private void GenerateCampGrid(ZoneSystem.SpawnMode mode)
    {
        float   num = Mathf.Cos(0.017453292f * this.m_maxTilt);
        Vector3 a   = base.transform.position + new Vector3((float)(-(float)this.m_gridSize) * this.m_tileWidth * 0.5f, 0f, (float)(-(float)this.m_gridSize) * this.m_tileWidth * 0.5f);

        for (int i = 0; i < this.m_gridSize; i++)
        {
            for (int j = 0; j < this.m_gridSize; j++)
            {
                if (UnityEngine.Random.value <= this.m_spawnChance)
                {
                    Vector3            pos = a + new Vector3((float)j * this.m_tileWidth, 0f, (float)i * this.m_tileWidth);
                    DungeonDB.RoomData randomWeightedRoom = this.GetRandomWeightedRoom(false);
                    if (randomWeightedRoom != null)
                    {
                        if (ZoneSystem.instance)
                        {
                            Vector3             vector;
                            Heightmap.Biome     biome;
                            Heightmap.BiomeArea biomeArea;
                            Heightmap           heightmap;
                            ZoneSystem.instance.GetGroundData(ref pos, out vector, out biome, out biomeArea, out heightmap);
                            if (vector.y < num)
                            {
                                goto IL_FE;
                            }
                        }
                        Quaternion rot = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 16) * 22.5f, 0f);
                        this.PlaceRoom(randomWeightedRoom, pos, rot, null, mode);
                    }
                }
                IL_FE :;
            }
        }
    }
예제 #6
0
    // Token: 0x06001084 RID: 4228 RVA: 0x00074E58 File Offset: 0x00073058
    public void Generate(ZoneSystem.SpawnMode mode)
    {
        int      seed  = WorldGenerator.instance.GetSeed();
        Vector2i zone  = ZoneSystem.instance.GetZone(base.transform.position);
        int      seed2 = seed + zone.x * 4271 + zone.y * 9187;

        this.Generate(seed2, mode);
    }
예제 #7
0
    // Token: 0x06001095 RID: 4245 RVA: 0x00075B08 File Offset: 0x00073D08
    private void PlaceStartRoom(ZoneSystem.SpawnMode mode)
    {
        DungeonDB.RoomData roomData = this.FindStartRoom();
        RoomConnection     entrance = roomData.m_room.GetEntrance();
        Quaternion         rotation = base.transform.rotation;
        Vector3            pos;
        Quaternion         rot;

        this.CalculateRoomPosRot(entrance, base.transform.position, rotation, out pos, out rot);
        this.PlaceRoom(roomData, pos, rot, entrance, mode);
    }
예제 #8
0
 // Token: 0x06001094 RID: 4244 RVA: 0x00075ABC File Offset: 0x00073CBC
 private void PlaceRooms(ZoneSystem.SpawnMode mode)
 {
     for (int i = 0; i < this.m_maxRooms; i++)
     {
         this.PlaceOneRoom(mode);
         if (this.CheckRequiredRooms() && DungeonGenerator.m_placedRooms.Count > this.m_minRooms)
         {
             ZLog.Log("All required rooms have been placed, stopping generation");
             return;
         }
     }
 }
예제 #9
0
            static bool Postfix(bool __result, ZoneSystem.SpawnMode __state, DungeonGenerator __instance)
            {
                if (__result)
                {
                    retries = 0;
                    return(true);
                }
                retries++;

                if (retries > retry_limit)
                {
                    return(false);
                }

                var methodHandler = MethodInvoker.GetHandler(AccessTools.Method(typeof(DungeonGenerator), "PlaceOneRoom"));

                return((bool)methodHandler.Invoke(__instance, __state));
            }
예제 #10
0
    // Token: 0x06001089 RID: 4233 RVA: 0x000751CC File Offset: 0x000733CC
    private void GenerateCampRadial(ZoneSystem.SpawnMode mode)
    {
        float num  = UnityEngine.Random.Range(this.m_campRadiusMin, this.m_campRadiusMax);
        float num2 = Mathf.Cos(0.017453292f * this.m_maxTilt);
        int   num3 = UnityEngine.Random.Range(this.m_minRooms, this.m_maxRooms);
        int   num4 = num3 * 20;
        int   num5 = 0;

        for (int i = 0; i < num4; i++)
        {
            Vector3            vector             = base.transform.position + Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f) * Vector3.forward * UnityEngine.Random.Range(0f, num - this.m_perimeterBuffer);
            DungeonDB.RoomData randomWeightedRoom = this.GetRandomWeightedRoom(false);
            if (randomWeightedRoom != null)
            {
                if (ZoneSystem.instance)
                {
                    Vector3             vector2;
                    Heightmap.Biome     biome;
                    Heightmap.BiomeArea biomeArea;
                    Heightmap           heightmap;
                    ZoneSystem.instance.GetGroundData(ref vector, out vector2, out biome, out biomeArea, out heightmap);
                    if (vector2.y < num2 || vector.y - ZoneSystem.instance.m_waterLevel < this.m_minAltitude)
                    {
                        goto IL_11D;
                    }
                }
                Quaternion campRoomRotation = this.GetCampRoomRotation(randomWeightedRoom, vector);
                if (!this.TestCollision(randomWeightedRoom.m_room, vector, campRoomRotation))
                {
                    this.PlaceRoom(randomWeightedRoom, vector, campRoomRotation, null, mode);
                    num5++;
                    if (num5 >= num3)
                    {
                        break;
                    }
                }
            }
            IL_11D :;
        }
        if (this.m_perimeterSections > 0)
        {
            this.PlaceWall(num, this.m_perimeterSections, mode);
        }
    }
예제 #11
0
    // Token: 0x06001086 RID: 4230 RVA: 0x00075044 File Offset: 0x00073244
    private void GenerateRooms(ZoneSystem.SpawnMode mode)
    {
        switch (this.m_algorithm)
        {
        case DungeonGenerator.Algorithm.Dungeon:
            this.GenerateDungeon(mode);
            return;

        case DungeonGenerator.Algorithm.CampGrid:
            this.GenerateCampGrid(mode);
            return;

        case DungeonGenerator.Algorithm.CampRadial:
            this.GenerateCampRadial(mode);
            return;

        default:
            return;
        }
    }
예제 #12
0
 // Token: 0x06001091 RID: 4241 RVA: 0x0007586C File Offset: 0x00073A6C
 private void PlaceEndCaps(ZoneSystem.SpawnMode mode)
 {
     for (int i = 0; i < DungeonGenerator.m_openConnections.Count; i++)
     {
         RoomConnection roomConnection = DungeonGenerator.m_openConnections[i];
         bool           flag           = false;
         for (int j = 0; j < DungeonGenerator.m_openConnections.Count; j++)
         {
             if (j != i && roomConnection.TestContact(DungeonGenerator.m_openConnections[j]))
             {
                 flag = true;
                 break;
             }
         }
         if (flag)
         {
             ZLog.Log("cyclic detected , cool");
         }
         else
         {
             this.FindEndCaps(roomConnection, DungeonGenerator.m_tempRooms);
             IEnumerable <DungeonDB.RoomData> enumerable = from item in DungeonGenerator.m_tempRooms
                                                           orderby item.m_room.m_endCapPrio descending
                                                           select item;
             bool flag2 = false;
             foreach (DungeonDB.RoomData roomData in enumerable)
             {
                 if (this.PlaceRoom(roomConnection, roomData, mode))
                 {
                     flag2 = true;
                     break;
                 }
             }
             if (!flag2)
             {
                 ZLog.LogWarning("Failed to place end cap " + roomConnection.name + " " + roomConnection.transform.parent.gameObject.name);
             }
         }
     }
 }
예제 #13
0
    // Token: 0x06001096 RID: 4246 RVA: 0x00075B58 File Offset: 0x00073D58
    private bool PlaceOneRoom(ZoneSystem.SpawnMode mode)
    {
        RoomConnection openConnection = this.GetOpenConnection();

        if (openConnection == null)
        {
            return(false);
        }
        for (int i = 0; i < 10; i++)
        {
            DungeonDB.RoomData randomRoom = this.GetRandomRoom(openConnection);
            if (randomRoom == null)
            {
                break;
            }
            if (this.PlaceRoom(openConnection, randomRoom, mode))
            {
                return(true);
            }
        }
        return(false);
    }
예제 #14
0
    // Token: 0x06001085 RID: 4229 RVA: 0x00074EA8 File Offset: 0x000730A8
    public void Generate(int seed, ZoneSystem.SpawnMode mode)
    {
        DateTime now = DateTime.Now;

        this.Clear();
        this.SetupColliders();
        this.SetupAvailableRooms();
        if (ZoneSystem.instance)
        {
            Vector2i zone = ZoneSystem.instance.GetZone(base.transform.position);
            this.m_zoneCenter   = ZoneSystem.instance.GetZonePos(zone);
            this.m_zoneCenter.y = base.transform.position.y;
        }
        ZLog.Log("Available rooms:" + DungeonGenerator.m_availableRooms.Count);
        ZLog.Log("To place:" + this.m_maxRooms);
        DungeonGenerator.m_placedRooms.Clear();
        DungeonGenerator.m_openConnections.Clear();
        DungeonGenerator.m_doorConnections.Clear();
        UnityEngine.Random.State state = UnityEngine.Random.state;
        UnityEngine.Random.InitState(seed);
        this.GenerateRooms(mode);
        this.Save();
        ZLog.Log("Placed " + DungeonGenerator.m_placedRooms.Count + " rooms");
        UnityEngine.Random.state = state;
        SnapToGround.SnappAll();
        if (mode == ZoneSystem.SpawnMode.Ghost)
        {
            foreach (Room room in DungeonGenerator.m_placedRooms)
            {
                UnityEngine.Object.DestroyImmediate(room.gameObject);
            }
        }
        DungeonGenerator.m_placedRooms.Clear();
        DungeonGenerator.m_openConnections.Clear();
        DungeonGenerator.m_doorConnections.Clear();
        UnityEngine.Object.DestroyImmediate(this.m_colliderA);
        UnityEngine.Object.DestroyImmediate(this.m_colliderB);
        DateTime.Now - now;
    }
예제 #15
0
    // Token: 0x0600108B RID: 4235 RVA: 0x000753B8 File Offset: 0x000735B8
    private void PlaceWall(float radius, int sections, ZoneSystem.SpawnMode mode)
    {
        float num  = Mathf.Cos(0.017453292f * this.m_maxTilt);
        int   num2 = 0;
        int   num3 = sections * 20;

        for (int i = 0; i < num3; i++)
        {
            DungeonDB.RoomData randomWeightedRoom = this.GetRandomWeightedRoom(true);
            if (randomWeightedRoom != null)
            {
                Vector3    vector           = base.transform.position + Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f) * Vector3.forward * radius;
                Quaternion campRoomRotation = this.GetCampRoomRotation(randomWeightedRoom, vector);
                if (ZoneSystem.instance)
                {
                    Vector3             vector2;
                    Heightmap.Biome     biome;
                    Heightmap.BiomeArea biomeArea;
                    Heightmap           heightmap;
                    ZoneSystem.instance.GetGroundData(ref vector, out vector2, out biome, out biomeArea, out heightmap);
                    if (vector2.y < num || vector.y - ZoneSystem.instance.m_waterLevel < this.m_minAltitude)
                    {
                        goto IL_E6;
                    }
                }
                if (!this.TestCollision(randomWeightedRoom.m_room, vector, campRoomRotation))
                {
                    this.PlaceRoom(randomWeightedRoom, vector, campRoomRotation, null, mode);
                    num2++;
                    if (num2 >= sections)
                    {
                        break;
                    }
                }
            }
            IL_E6 :;
        }
    }
예제 #16
0
 static void Prefix(ZoneSystem.SpawnMode __0, out ZoneSystem.SpawnMode __state)
 {
     __state = __0;
 }
예제 #17
0
 private static void ZoneSystem_SpawnLocation(ZoneSystem.ZoneLocation location, ZoneSystem.SpawnMode mode) => instance.ZoneSystem_SpawnLocation(location, mode);
예제 #18
0
    // Token: 0x06001099 RID: 4249 RVA: 0x00075CAC File Offset: 0x00073EAC
    private void PlaceRoom(DungeonDB.RoomData room, Vector3 pos, Quaternion rot, RoomConnection fromConnection, ZoneSystem.SpawnMode mode)
    {
        int seed = (int)pos.x * 4271 + (int)pos.y * 9187 + (int)pos.z * 2134;

        UnityEngine.Random.State state = UnityEngine.Random.state;
        UnityEngine.Random.InitState(seed);
        if (mode == ZoneSystem.SpawnMode.Full || mode == ZoneSystem.SpawnMode.Ghost)
        {
            foreach (ZNetView znetView in room.m_netViews)
            {
                znetView.gameObject.SetActive(true);
            }
            foreach (RandomSpawn randomSpawn in room.m_randomSpawns)
            {
                randomSpawn.Randomize();
            }
            Vector3    position   = room.m_room.transform.position;
            Quaternion quaternion = Quaternion.Inverse(room.m_room.transform.rotation);
            using (List <ZNetView> .Enumerator enumerator = room.m_netViews.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ZNetView znetView2 = enumerator.Current;
                    if (znetView2.gameObject.activeSelf)
                    {
                        Vector3    point      = quaternion * (znetView2.gameObject.transform.position - position);
                        Vector3    position2  = pos + rot * point;
                        Quaternion rhs        = quaternion * znetView2.gameObject.transform.rotation;
                        Quaternion rotation   = rot * rhs;
                        GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(znetView2.gameObject, position2, rotation);
                        ZNetView   component  = gameObject.GetComponent <ZNetView>();
                        if (component.GetZDO() != null)
                        {
                            component.GetZDO().SetPGWVersion(ZoneSystem.instance.m_pgwVersion);
                        }
                        if (mode == ZoneSystem.SpawnMode.Ghost)
                        {
                            UnityEngine.Object.Destroy(gameObject);
                        }
                    }
                }
                goto IL_1E9;
            }
        }
        foreach (RandomSpawn randomSpawn2 in room.m_randomSpawns)
        {
            randomSpawn2.Randomize();
        }
IL_1E9:
        foreach (ZNetView znetView3 in room.m_netViews)
        {
            znetView3.gameObject.SetActive(false);
        }
        Room component2 = UnityEngine.Object.Instantiate <GameObject>(room.m_room.gameObject, pos, rot, base.transform).GetComponent <Room>();

        component2.gameObject.name = room.m_room.gameObject.name;
        if (mode != ZoneSystem.SpawnMode.Client)
        {
            component2.m_placeOrder = (fromConnection ? (fromConnection.m_placeOrder + 1) : 0);
            DungeonGenerator.m_placedRooms.Add(component2);
            this.AddOpenConnections(component2, fromConnection);
        }
        UnityEngine.Random.state = state;
    }