Exemplo n.º 1
0
 public static bool tryGetRegion(byte x, byte y, out StructureRegion region)
 {
     region = null;
     if (Regions.checkSafe((int)x, (int)y))
     {
         region = StructureManager.regions[(int)x, (int)y];
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
 private static void updateActivity(CSteamID owner, CSteamID group)
 {
     for (byte b = 0; b < Regions.WORLD_SIZE; b += 1)
     {
         for (byte b2 = 0; b2 < Regions.WORLD_SIZE; b2 += 1)
         {
             StructureRegion region = StructureManager.regions[(int)b, (int)b2];
             StructureManager.updateActivity(region, owner, group);
         }
     }
 }
Exemplo n.º 3
0
 public void tellClearRegionStructures(CSteamID steamID, byte x, byte y)
 {
     if (base.channel.checkServer(steamID))
     {
         if (!Provider.isServer && !StructureManager.regions[(int)x, (int)y].isNetworked)
         {
             return;
         }
         StructureRegion structureRegion = StructureManager.regions[(int)x, (int)y];
         structureRegion.destroy();
     }
 }
Exemplo n.º 4
0
        private static void updateActivity(StructureRegion region, CSteamID owner, CSteamID group)
        {
            ushort num = 0;

            while ((int)num < region.structures.Count)
            {
                StructureData structureData = region.structures[(int)num];
                if (OwnershipTool.checkToggle(owner, structureData.owner, group, structureData.group))
                {
                    structureData.objActiveDate = Provider.time;
                }
                num += 1;
            }
        }
Exemplo n.º 5
0
        private Transform spawnStructure(StructureRegion region, ushort id, Vector3 point, byte angle_x, byte angle_y, byte angle_z, byte hp, ulong owner, ulong group, uint instanceID)
        {
            if (id == 0)
            {
                return(null);
            }
            ItemStructureAsset itemStructureAsset;

            try
            {
                itemStructureAsset = (ItemStructureAsset)Assets.find(EAssetType.ITEM, id);
            }
            catch
            {
                itemStructureAsset = null;
            }
            if (itemStructureAsset != null)
            {
                Transform structure = StructureTool.getStructure(id, hp, owner, group, itemStructureAsset);
                structure.parent   = LevelStructures.models;
                structure.position = point;
                structure.rotation = Quaternion.Euler((float)(angle_x * 2), (float)(angle_y * 2), (float)(angle_z * 2));
                if (!Dedicator.isDedicated && (itemStructureAsset.construct == EConstruct.FLOOR || itemStructureAsset.construct == EConstruct.FLOOR_POLY))
                {
                    LevelGround.bewilder(point);
                }
                region.drops.Add(new StructureDrop(structure, instanceID));
                StructureManager.structureColliders.Clear();
                structure.GetComponentsInChildren <Collider>(StructureManager.structureColliders);
                for (int i = 0; i < StructureManager.structureColliders.Count; i++)
                {
                    if (StructureManager.structureColliders[i] is MeshCollider)
                    {
                        StructureManager.structureColliders[i].enabled = false;
                    }
                    if (StructureManager.structureColliders[i] is MeshCollider)
                    {
                        StructureManager.structureColliders[i].enabled = true;
                    }
                }
                return(structure);
            }
            if (!Provider.isServer)
            {
                Provider.connectionFailureInfo = ESteamConnectionFailureInfo.STRUCTURE;
                Provider.disconnect();
            }
            return(null);
        }
Exemplo n.º 6
0
        public static void save()
        {
            River river = LevelSavedata.openRiver("/Structures.dat", false);

            river.writeByte(StructureManager.SAVEDATA_VERSION);
            river.writeUInt32(Provider.time);
            for (byte b = 0; b < Regions.WORLD_SIZE; b += 1)
            {
                for (byte b2 = 0; b2 < Regions.WORLD_SIZE; b2 += 1)
                {
                    StructureRegion region = StructureManager.regions[(int)b, (int)b2];
                    StructureManager.saveRegion(river, region);
                }
            }
            river.closeRiver();
        }
Exemplo n.º 7
0
 public static bool tryGetRegion(Transform structure, out byte x, out byte y, out StructureRegion region)
 {
     x      = 0;
     y      = 0;
     region = null;
     if (structure == null)
     {
         return(false);
     }
     if (Regions.tryGetCoordinate(structure.position, out x, out y))
     {
         region = StructureManager.regions[(int)x, (int)y];
         return(true);
     }
     return(false);
 }
Exemplo n.º 8
0
 public static void askClearRegionStructures(byte x, byte y)
 {
     if (Provider.isServer)
     {
         if (!Regions.checkSafe((int)x, (int)y))
         {
             return;
         }
         StructureRegion structureRegion = StructureManager.regions[(int)x, (int)y];
         if (structureRegion.structures.Count > 0)
         {
             structureRegion.structures.Clear();
             StructureManager.manager.channel.send("tellClearRegionStructures", ESteamCall.ALL, x, y, StructureManager.STRUCTURE_REGIONS, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
             {
                 x,
                 y
             });
         }
     }
 }
Exemplo n.º 9
0
        private static void saveRegion(River river, StructureRegion region)
        {
            uint   time = Provider.time;
            ushort num  = 0;
            ushort num2 = 0;

            while ((int)num2 < region.structures.Count)
            {
                StructureData structureData = region.structures[(int)num2];
                if ((!Dedicator.isDedicated || Provider.modeConfigData.Structures.Decay_Time == 0u || time < structureData.objActiveDate || time - structureData.objActiveDate < Provider.modeConfigData.Structures.Decay_Time) && structureData.structure.asset.isSaveable)
                {
                    num += 1;
                }
                num2 += 1;
            }
            river.writeUInt16(num);
            ushort num3 = 0;

            while ((int)num3 < region.structures.Count)
            {
                StructureData structureData2 = region.structures[(int)num3];
                if ((!Dedicator.isDedicated || Provider.modeConfigData.Structures.Decay_Time == 0u || time < structureData2.objActiveDate || time - structureData2.objActiveDate < Provider.modeConfigData.Structures.Decay_Time) && structureData2.structure.asset.isSaveable)
                {
                    river.writeUInt16(structureData2.structure.id);
                    river.writeUInt16(structureData2.structure.health);
                    river.writeSingleVector3(structureData2.point);
                    river.writeByte(structureData2.angle_x);
                    river.writeByte(structureData2.angle_y);
                    river.writeByte(structureData2.angle_z);
                    river.writeUInt64(structureData2.owner);
                    river.writeUInt64(structureData2.group);
                    river.writeUInt32(structureData2.objActiveDate);
                }
                num3 += 1;
            }
        }
Exemplo n.º 10
0
        private static void loadRegion(byte version, River river, StructureRegion region)
        {
            ushort num = river.readUInt16();

            for (ushort num2 = 0; num2 < num; num2 += 1)
            {
                ushort  num3   = river.readUInt16();
                ushort  num4   = river.readUInt16();
                Vector3 vector = river.readSingleVector3();
                byte    b      = 0;
                if (version > 4)
                {
                    b = river.readByte();
                }
                byte b2 = river.readByte();
                byte b3 = 0;
                if (version > 4)
                {
                    b3 = river.readByte();
                }
                ulong num5 = 0UL;
                ulong num6 = 0UL;
                if (version > 2)
                {
                    num5 = river.readUInt64();
                    num6 = river.readUInt64();
                }
                uint newObjActiveDate;
                if (version > 3)
                {
                    newObjActiveDate = river.readUInt32();
                    if (Provider.time - StructureManager.serverActiveDate > Provider.modeConfigData.Structures.Decay_Time / 2u)
                    {
                        newObjActiveDate = Provider.time;
                    }
                }
                else
                {
                    newObjActiveDate = Provider.time;
                }
                ItemStructureAsset itemStructureAsset;
                try
                {
                    itemStructureAsset = (ItemStructureAsset)Assets.find(EAssetType.ITEM, num3);
                }
                catch
                {
                    itemStructureAsset = null;
                }
                if (itemStructureAsset != null)
                {
                    if (version < 5)
                    {
                        Vector3 eulerAngles = Quaternion.Euler(-90f, (float)(b2 * 2), 0f).eulerAngles;
                        b  = MeasurementTool.angleToByte((float)(Mathf.RoundToInt(eulerAngles.x / 2f) * 2));
                        b2 = MeasurementTool.angleToByte((float)(Mathf.RoundToInt(eulerAngles.y / 2f) * 2));
                        b3 = MeasurementTool.angleToByte((float)(Mathf.RoundToInt(eulerAngles.z / 2f) * 2));
                    }
                    region.structures.Add(new StructureData(new Structure(num3, num4, itemStructureAsset), vector, b, b2, b3, num5, num6, newObjActiveDate));
                    StructureManager.manager.spawnStructure(region, num3, vector, b, b2, b3, (byte)Mathf.RoundToInt((float)num4 / (float)itemStructureAsset.health * 100f), num5, num6, StructureManager.instanceCount += 1u);
                }
            }
        }
Exemplo n.º 11
0
        public static void load()
        {
            bool flag = false;

            if (LevelSavedata.fileExists("/Structures.dat") && Level.info.type == ELevelType.SURVIVAL)
            {
                River river = LevelSavedata.openRiver("/Structures.dat", true);
                byte  b     = river.readByte();
                if (b > 3)
                {
                    StructureManager.serverActiveDate = river.readUInt32();
                }
                else
                {
                    StructureManager.serverActiveDate = Provider.time;
                }
                if (b > 1)
                {
                    for (byte b2 = 0; b2 < Regions.WORLD_SIZE; b2 += 1)
                    {
                        for (byte b3 = 0; b3 < Regions.WORLD_SIZE; b3 += 1)
                        {
                            StructureRegion region = StructureManager.regions[(int)b2, (int)b3];
                            StructureManager.loadRegion(b, river, region);
                        }
                    }
                }
                if (b < 6)
                {
                    flag = true;
                }
            }
            else
            {
                flag = true;
            }
            if (flag && LevelObjects.buildables != null)
            {
                for (byte b4 = 0; b4 < Regions.WORLD_SIZE; b4 += 1)
                {
                    for (byte b5 = 0; b5 < Regions.WORLD_SIZE; b5 += 1)
                    {
                        List <LevelBuildableObject> list = LevelObjects.buildables[(int)b4, (int)b5];
                        if (list != null && list.Count != 0)
                        {
                            StructureRegion structureRegion = StructureManager.regions[(int)b4, (int)b5];
                            for (int i = 0; i < list.Count; i++)
                            {
                                LevelBuildableObject levelBuildableObject = list[i];
                                if (levelBuildableObject != null)
                                {
                                    ItemStructureAsset itemStructureAsset = levelBuildableObject.asset as ItemStructureAsset;
                                    if (itemStructureAsset != null)
                                    {
                                        Vector3       eulerAngles   = levelBuildableObject.rotation.eulerAngles;
                                        byte          newAngle_X    = MeasurementTool.angleToByte((float)(Mathf.RoundToInt(eulerAngles.x / 2f) * 2));
                                        byte          newAngle_Y    = MeasurementTool.angleToByte((float)(Mathf.RoundToInt(eulerAngles.y / 2f) * 2));
                                        byte          newAngle_Z    = MeasurementTool.angleToByte((float)(Mathf.RoundToInt(eulerAngles.z / 2f) * 2));
                                        Structure     structure     = new Structure(itemStructureAsset.id, itemStructureAsset.health, itemStructureAsset);
                                        StructureData structureData = new StructureData(structure, levelBuildableObject.point, newAngle_X, newAngle_Y, newAngle_Z, 0UL, 0UL, uint.MaxValue);
                                        structureRegion.structures.Add(structureData);
                                        StructureManager.manager.spawnStructure(structureRegion, structure.id, structureData.point, structureData.angle_x, structureData.angle_y, structureData.angle_z, (byte)Mathf.RoundToInt((float)structure.health / (float)itemStructureAsset.health * 100f), 0UL, 0UL, StructureManager.instanceCount += 1u);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Level.isLoadingStructures = false;
        }
Exemplo n.º 12
0
        public void tellTransformStructure(CSteamID steamID, byte x, byte y, uint instanceID, Vector3 point, byte angle_x, byte angle_y, byte angle_z)
        {
            StructureRegion structureRegion;

            if (base.channel.checkServer(steamID) && StructureManager.tryGetRegion(x, y, out structureRegion))
            {
                if (!Provider.isServer && !structureRegion.isNetworked)
                {
                    return;
                }
                StructureData structureData = null;
                StructureDrop structureDrop = null;
                ushort        num           = 0;
                while ((int)num < structureRegion.drops.Count)
                {
                    if (structureRegion.drops[(int)num].instanceID == instanceID)
                    {
                        if (Provider.isServer)
                        {
                            structureData = structureRegion.structures[(int)num];
                        }
                        structureDrop = structureRegion.drops[(int)num];
                        break;
                    }
                    num += 1;
                }
                if (structureDrop == null)
                {
                    return;
                }
                structureDrop.model.position = point;
                structureDrop.model.rotation = Quaternion.Euler((float)(angle_x * 2), (float)(angle_y * 2), (float)(angle_z * 2));
                byte b;
                byte b2;
                if (Regions.tryGetCoordinate(point, out b, out b2) && (x != b || y != b2))
                {
                    StructureRegion structureRegion2 = StructureManager.regions[(int)b, (int)b2];
                    structureRegion.drops.RemoveAt((int)num);
                    if (structureRegion2.isNetworked || Provider.isServer)
                    {
                        structureRegion2.drops.Add(structureDrop);
                    }
                    else if (!Provider.isServer)
                    {
                        Object.Destroy(structureDrop.model.gameObject);
                    }
                    if (Provider.isServer)
                    {
                        structureRegion.structures.RemoveAt((int)num);
                        structureRegion2.structures.Add(structureData);
                    }
                }
                if (Provider.isServer)
                {
                    structureData.point   = point;
                    structureData.angle_x = angle_x;
                    structureData.angle_y = angle_y;
                    structureData.angle_z = angle_z;
                }
            }
        }
Exemplo n.º 13
0
 public static bool tryGetInfo(Transform structure, out byte x, out byte y, out ushort index, out StructureRegion region, out StructureDrop drop)
 {
     x      = 0;
     y      = 0;
     index  = 0;
     region = null;
     drop   = null;
     if (StructureManager.tryGetRegion(structure, out x, out y, out region))
     {
         index = 0;
         while ((int)index < region.drops.Count)
         {
             if (structure == region.drops[(int)index].model)
             {
                 drop = region.drops[(int)index];
                 return(true);
             }
             index += 1;
         }
     }
     return(false);
 }