コード例 #1
0
ファイル: DungeonDB.cs プロジェクト: ingvard/valheim-jserver
    // Token: 0x0600107E RID: 4222 RVA: 0x00074C6C File Offset: 0x00072E6C
    private static List <DungeonDB.RoomData> SetupRooms()
    {
        GameObject[] array      = Resources.FindObjectsOfTypeAll <GameObject>();
        GameObject   gameObject = null;

        foreach (GameObject gameObject2 in array)
        {
            if (gameObject2.name == "_Rooms")
            {
                gameObject = gameObject2;
                break;
            }
        }
        if (gameObject == null || (DungeonDB.m_instance && gameObject.activeSelf))
        {
            if (DungeonDB.m_instance)
            {
                DungeonDB.m_instance.m_error = true;
            }
            ZLog.LogError("Rooms are f****d, missing _Rooms or its enabled");
        }
        List <DungeonDB.RoomData> list = new List <DungeonDB.RoomData>();

        for (int j = 0; j < gameObject.transform.childCount; j++)
        {
            Room component = gameObject.transform.GetChild(j).GetComponent <Room>();
            DungeonDB.RoomData roomData = new DungeonDB.RoomData();
            roomData.m_room = component;
            ZoneSystem.PrepareNetViews(component.gameObject, roomData.m_netViews);
            ZoneSystem.PrepareRandomSpawns(component.gameObject, roomData.m_randomSpawns);
            list.Add(roomData);
        }
        return(list);
    }
コード例 #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: 0x0600108D RID: 4237 RVA: 0x00075570 File Offset: 0x00073770
    private void Load()
    {
        if (this.m_nview == null)
        {
            return;
        }
        DateTime now = DateTime.Now;

        ZLog.Log("Loading dungeon");
        ZDO zdo  = this.m_nview.GetZDO();
        int @int = zdo.GetInt("rooms", 0);

        for (int i = 0; i < @int; i++)
        {
            string             text       = "room" + i.ToString();
            int                int2       = zdo.GetInt(text, 0);
            Vector3            vec        = zdo.GetVec3(text + "_pos", Vector3.zero);
            Quaternion         quaternion = zdo.GetQuaternion(text + "_rot", Quaternion.identity);
            DungeonDB.RoomData room       = DungeonDB.instance.GetRoom(int2);
            if (room == null)
            {
                ZLog.LogWarning("Missing room:" + int2);
            }
            else
            {
                this.PlaceRoom(room, vec, quaternion, null, ZoneSystem.SpawnMode.Client);
            }
        }
        ZLog.Log("Dungeon loaded " + @int);
        ZLog.Log("Dungeon load time " + (DateTime.Now - now).TotalMilliseconds + " ms");
    }
コード例 #4
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 :;
            }
        }
    }
コード例 #5
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);
    }
コード例 #6
0
 // Token: 0x0600108A RID: 4234 RVA: 0x0007531C File Offset: 0x0007351C
 private Quaternion GetCampRoomRotation(DungeonDB.RoomData room, Vector3 pos)
 {
     if (room.m_room.m_faceCenter)
     {
         Vector3 vector = base.transform.position - pos;
         vector.y = 0f;
         if (vector == Vector3.zero)
         {
             vector = Vector3.forward;
         }
         vector.Normalize();
         float y = Mathf.Round(Utils.YawFromDirection(vector) / 22.5f) * 22.5f;
         return(Quaternion.Euler(0f, y, 0f));
     }
     return(Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 16) * 22.5f, 0f));
 }
コード例 #7
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);
        }
    }
コード例 #8
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);
    }
コード例 #9
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 :;
        }
    }
コード例 #10
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;
    }