public void askStructures(CSteamID steamID, byte x, byte y) { StructureRegion structureRegion; if (StructureManager.tryGetRegion(x, y, out structureRegion)) { if (structureRegion.structures.Count > 0) { byte b = 0; int i = 0; int j = 0; while (i < structureRegion.structures.Count) { int num = 0; while (j < structureRegion.structures.Count) { num += 38; j++; if (num > Block.BUFFER_SIZE / 2) { break; } } base.channel.openWrite(); base.channel.write(x); base.channel.write(y); base.channel.write(b); base.channel.write((ushort)(j - i)); while (i < j) { StructureData structureData = structureRegion.structures[i]; base.channel.write(new object[] { structureData.structure.id, structureData.point, structureData.angle_x, structureData.angle_y, structureData.angle_z, structureData.owner, structureData.group, structureRegion.drops[i].instanceID }); base.channel.write((byte)Mathf.RoundToInt((float)structureData.structure.health / (float)structureData.structure.asset.health * 100f)); i++; } base.channel.closeWrite("tellStructures", steamID, ESteamPacket.UPDATE_RELIABLE_CHUNK_BUFFER); b += 1; } } else { base.channel.openWrite(); base.channel.write(x); base.channel.write(y); base.channel.write(0); base.channel.write(0); base.channel.closeWrite("tellStructures", steamID, ESteamPacket.UPDATE_RELIABLE_CHUNK_BUFFER); } } }
public static void dropStructure(Structure structure, Vector3 point, float angle_x, float angle_y, float angle_z, ulong owner, ulong group) { ItemStructureAsset itemStructureAsset = (ItemStructureAsset)Assets.find(EAssetType.ITEM, structure.id); if (itemStructureAsset != null) { Vector3 eulerAngles = Quaternion.Euler(-90f, angle_y, 0f).eulerAngles; angle_x = (float)(Mathf.RoundToInt(eulerAngles.x / 2f) * 2); angle_y = (float)(Mathf.RoundToInt(eulerAngles.y / 2f) * 2); angle_z = (float)(Mathf.RoundToInt(eulerAngles.z / 2f) * 2); byte b; byte b2; StructureRegion structureRegion; if (Regions.tryGetCoordinate(point, out b, out b2) && StructureManager.tryGetRegion(b, b2, out structureRegion)) { StructureData structureData = new StructureData(structure, point, MeasurementTool.angleToByte(angle_x), MeasurementTool.angleToByte(angle_y), MeasurementTool.angleToByte(angle_z), owner, group, Provider.time); structureRegion.structures.Add(structureData); StructureManager.manager.channel.send("tellStructure", ESteamCall.ALL, b, b2, StructureManager.STRUCTURE_REGIONS, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { b, b2, structure.id, structureData.point, structureData.angle_x, structureData.angle_y, structureData.angle_z, owner, group, StructureManager.instanceCount += 1u }); } } }
public void askTransformStructure(CSteamID steamID, byte x, byte y, uint instanceID, Vector3 point, byte angle_x, byte angle_y, byte angle_z) { StructureRegion structureRegion; if (Provider.isServer && StructureManager.tryGetRegion(x, y, out structureRegion)) { Player player = PlayerTool.getPlayer(steamID); if (player == null) { return; } if (player.life.isDead) { return; } if (!player.channel.owner.isAdmin) { return; } StructureManager.manager.channel.send("tellTransformStructure", ESteamCall.ALL, x, y, StructureManager.STRUCTURE_REGIONS, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { x, y, instanceID, point, angle_x, angle_y, angle_z }); } }
public void askSalvageStructure(CSteamID steamID, byte x, byte y, ushort index) { StructureRegion structureRegion; if (Provider.isServer && StructureManager.tryGetRegion(x, y, out structureRegion)) { Player player = PlayerTool.getPlayer(steamID); if (player == null) { return; } if (player.life.isDead) { return; } if ((int)index >= structureRegion.drops.Count) { return; } if (!OwnershipTool.checkToggle(player.channel.owner.playerID.steamID, structureRegion.structures[(int)index].owner, player.quests.groupID, structureRegion.structures[(int)index].group)) { return; } ItemStructureAsset itemStructureAsset = (ItemStructureAsset)Assets.find(EAssetType.ITEM, structureRegion.structures[(int)index].structure.id); if (itemStructureAsset != null) { if (itemStructureAsset.isUnpickupable) { return; } if (structureRegion.structures[(int)index].structure.health == itemStructureAsset.health) { player.inventory.forceAddItem(new Item(structureRegion.structures[(int)index].structure.id, EItemOrigin.NATURE), true); } else if (itemStructureAsset.isSalvageable) { for (int i = 0; i < itemStructureAsset.blueprints.Count; i++) { Blueprint blueprint = itemStructureAsset.blueprints[i]; if (blueprint.outputs.Length == 1 && blueprint.outputs[0].id == itemStructureAsset.id) { ushort id = blueprint.supplies[Random.Range(0, blueprint.supplies.Length)].id; player.inventory.forceAddItem(new Item(id, EItemOrigin.NATURE), true); break; } } } } structureRegion.structures.RemoveAt((int)index); StructureManager.manager.channel.send("tellTakeStructure", ESteamCall.ALL, x, y, StructureManager.STRUCTURE_REGIONS, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { x, y, index, (structureRegion.drops[(int)index].model.position - player.transform.position).normalized * 100f }); } }
public void tellStructure(CSteamID steamID, byte x, byte y, ushort id, Vector3 point, byte angle_x, byte angle_y, byte angle_z, ulong owner, ulong group, uint instanceID) { StructureRegion structureRegion; if (base.channel.checkServer(steamID) && StructureManager.tryGetRegion(x, y, out structureRegion)) { if (!Provider.isServer && !structureRegion.isNetworked) { return; } this.spawnStructure(structureRegion, id, point, angle_x, angle_y, angle_z, 100, owner, group, instanceID); } }
public void tellStructures(CSteamID steamID) { if (base.channel.checkServer(steamID)) { byte x = (byte)base.channel.read(Types.BYTE_TYPE); byte y = (byte)base.channel.read(Types.BYTE_TYPE); StructureRegion structureRegion; if (StructureManager.tryGetRegion(x, y, out structureRegion)) { if ((byte)base.channel.read(Types.BYTE_TYPE) == 0) { if (structureRegion.isNetworked) { return; } } else if (!structureRegion.isNetworked) { return; } structureRegion.isNetworked = true; ushort num = (ushort)base.channel.read(Types.UINT16_TYPE); for (int i = 0; i < (int)num; i++) { object[] array = base.channel.read(new Type[] { Types.UINT16_TYPE, Types.VECTOR3_TYPE, Types.BYTE_TYPE, Types.BYTE_TYPE, Types.BYTE_TYPE, Types.UINT64_TYPE, Types.UINT64_TYPE, Types.UINT32_TYPE }); ulong owner = (ulong)array[5]; ulong group = (ulong)array[6]; uint instanceID = (uint)array[7]; byte hp = (byte)base.channel.read(Types.BYTE_TYPE); this.spawnStructure(structureRegion, (ushort)array[0], (Vector3)array[1], (byte)array[2], (byte)array[3], (byte)array[4], hp, owner, group, instanceID); } Level.isLoadingStructures = false; } } }
public static bool tryGetInfo(Transform structure, out byte x, out byte y, out ushort index, out StructureRegion region) { x = 0; y = 0; index = 0; region = 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) { return(true); } index += 1; } } return(false); }
public void tellStructureHealth(CSteamID steamID, byte x, byte y, ushort index, byte hp) { StructureRegion structureRegion; if (base.channel.checkServer(steamID) && StructureManager.tryGetRegion(x, y, out structureRegion)) { if (!Provider.isServer && !structureRegion.isNetworked) { return; } if ((int)index >= structureRegion.drops.Count) { return; } Interactable2HP component = structureRegion.drops[(int)index].model.GetComponent <Interactable2HP>(); if (component != null) { component.hp = hp; } } }
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; } } }
public void tellTakeStructure(CSteamID steamID, byte x, byte y, ushort index, Vector3 ragdoll) { StructureRegion structureRegion; if (base.channel.checkServer(steamID) && StructureManager.tryGetRegion(x, y, out structureRegion)) { if (!Provider.isServer && !structureRegion.isNetworked) { return; } if ((int)index >= structureRegion.drops.Count) { return; } if (Dedicator.isDedicated || !GraphicsSettings.debris) { Object.Destroy(structureRegion.drops[(int)index].model.gameObject); structureRegion.drops[(int)index].model.position = Vector3.zero; } else { ItemStructureAsset itemStructureAsset = (ItemStructureAsset)Assets.find(EAssetType.ITEM, ushort.Parse(structureRegion.drops[(int)index].model.name)); if (itemStructureAsset != null && itemStructureAsset.construct != EConstruct.FLOOR && itemStructureAsset.construct != EConstruct.ROOF && itemStructureAsset.construct != EConstruct.FLOOR_POLY && itemStructureAsset.construct != EConstruct.ROOF_POLY) { ragdoll.y += 8f; ragdoll.x += Random.Range(-16f, 16f); ragdoll.z += Random.Range(-16f, 16f); ragdoll *= 2f; structureRegion.drops[(int)index].model.parent = Level.effects; MeshCollider component = structureRegion.drops[(int)index].model.GetComponent <MeshCollider>(); if (component != null) { component.convex = true; } structureRegion.drops[(int)index].model.tag = "Debris"; structureRegion.drops[(int)index].model.gameObject.layer = LayerMasks.DEBRIS; Rigidbody rigidbody = structureRegion.drops[(int)index].model.gameObject.GetComponent <Rigidbody>(); if (rigidbody == null) { rigidbody = structureRegion.drops[(int)index].model.gameObject.AddComponent <Rigidbody>(); } rigidbody.useGravity = true; rigidbody.isKinematic = false; rigidbody.AddForce(ragdoll); rigidbody.drag = 0.5f; rigidbody.angularDrag = 0.1f; structureRegion.drops[(int)index].model.localScale *= 0.75f; Object.Destroy(structureRegion.drops[(int)index].model.gameObject, 8f); if (Provider.isServer) { Object.Destroy(structureRegion.drops[(int)index].model.FindChild("Nav").gameObject); } for (int i = 0; i < structureRegion.drops[(int)index].model.childCount; i++) { Transform child = structureRegion.drops[(int)index].model.GetChild(i); if (!(child == null)) { if (child.CompareTag("Logic")) { Object.Destroy(child.gameObject); } } } } else { Object.Destroy(structureRegion.drops[(int)index].model.gameObject); structureRegion.drops[(int)index].model.position = Vector3.zero; } } structureRegion.drops.RemoveAt((int)index); } }
public virtual void read(SteamChannel channel) { this.sequence = (int)channel.read(Types.INT32_TYPE); this.recov = (int)channel.read(Types.INT32_TYPE); this.keys = (ushort)channel.read(Types.UINT16_TYPE); byte b = (byte)channel.read(Types.BYTE_TYPE); if (b > 0) { this.serversideInputs = new Queue <InputInfo>((int)b); for (byte b2 = 0; b2 < b; b2 += 1) { InputInfo inputInfo = new InputInfo(); inputInfo.type = (ERaycastInfoType)((byte)channel.read(Types.BYTE_TYPE)); switch (inputInfo.type) { case ERaycastInfoType.NONE: inputInfo.point = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.normal = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.material = (EPhysicsMaterial)((byte)channel.read(Types.BYTE_TYPE)); break; case ERaycastInfoType.SKIP: inputInfo = null; break; case ERaycastInfoType.OBJECT: { inputInfo.point = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.direction = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.normal = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.material = (EPhysicsMaterial)((byte)channel.read(Types.BYTE_TYPE)); inputInfo.section = (byte)channel.read(Types.BYTE_TYPE); byte x = (byte)channel.read(Types.BYTE_TYPE); byte y = (byte)channel.read(Types.BYTE_TYPE); ushort index = (ushort)channel.read(Types.UINT16_TYPE); LevelObject @object = ObjectManager.getObject(x, y, index); if (@object != null && @object.transform != null && (inputInfo.point - @object.transform.position).sqrMagnitude < 256f) { inputInfo.transform = @object.transform; } else { inputInfo.type = ERaycastInfoType.NONE; } break; } case ERaycastInfoType.PLAYER: { inputInfo.point = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.direction = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.normal = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.limb = (ELimb)((byte)channel.read(Types.BYTE_TYPE)); CSteamID steamID = (CSteamID)channel.read(Types.STEAM_ID_TYPE); Player player = PlayerTool.getPlayer(steamID); if (player != null && (inputInfo.point - player.transform.position).sqrMagnitude < 256f) { inputInfo.material = EPhysicsMaterial.FLESH_DYNAMIC; inputInfo.player = player; inputInfo.transform = player.transform; } else { inputInfo = null; } break; } case ERaycastInfoType.ZOMBIE: { inputInfo.point = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.direction = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.normal = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.limb = (ELimb)((byte)channel.read(Types.BYTE_TYPE)); ushort id = (ushort)channel.read(Types.UINT16_TYPE); Zombie zombie = ZombieManager.getZombie(inputInfo.point, id); if (zombie != null && (inputInfo.point - zombie.transform.position).sqrMagnitude < 256f) { if (zombie.isRadioactive) { inputInfo.material = EPhysicsMaterial.ALIEN_DYNAMIC; } else { inputInfo.material = EPhysicsMaterial.FLESH_DYNAMIC; } inputInfo.zombie = zombie; inputInfo.transform = zombie.transform; } else { inputInfo = null; } break; } case ERaycastInfoType.ANIMAL: { inputInfo.point = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.direction = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.normal = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.limb = (ELimb)((byte)channel.read(Types.BYTE_TYPE)); ushort index2 = (ushort)channel.read(Types.UINT16_TYPE); Animal animal = AnimalManager.getAnimal(index2); if (animal != null && (inputInfo.point - animal.transform.position).sqrMagnitude < 256f) { inputInfo.material = EPhysicsMaterial.FLESH_DYNAMIC; inputInfo.animal = animal; inputInfo.transform = animal.transform; } else { inputInfo = null; } break; } case ERaycastInfoType.VEHICLE: { inputInfo.point = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.normal = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.material = (EPhysicsMaterial)((byte)channel.read(Types.BYTE_TYPE)); uint instanceID = (uint)channel.read(Types.UINT32_TYPE); InteractableVehicle vehicle = VehicleManager.getVehicle(instanceID); if (vehicle != null && (vehicle == channel.owner.player.movement.getVehicle() || (inputInfo.point - vehicle.transform.position).sqrMagnitude < 4096f)) { inputInfo.vehicle = vehicle; inputInfo.transform = vehicle.transform; } else { inputInfo = null; } break; } case ERaycastInfoType.BARRICADE: { inputInfo.point = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.normal = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.material = (EPhysicsMaterial)((byte)channel.read(Types.BYTE_TYPE)); byte x2 = (byte)channel.read(Types.BYTE_TYPE); byte y2 = (byte)channel.read(Types.BYTE_TYPE); ushort plant = (ushort)channel.read(Types.UINT16_TYPE); ushort num = (ushort)channel.read(Types.UINT16_TYPE); BarricadeRegion barricadeRegion; if (BarricadeManager.tryGetRegion(x2, y2, plant, out barricadeRegion) && (int)num < barricadeRegion.drops.Count) { Transform model = barricadeRegion.drops[(int)num].model; if (model != null && (inputInfo.point - model.transform.position).sqrMagnitude < 256f) { inputInfo.transform = model; } else { inputInfo = null; } } else { inputInfo = null; } break; } case ERaycastInfoType.STRUCTURE: { inputInfo.point = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.direction = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.normal = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.material = (EPhysicsMaterial)((byte)channel.read(Types.BYTE_TYPE)); byte x3 = (byte)channel.read(Types.BYTE_TYPE); byte y3 = (byte)channel.read(Types.BYTE_TYPE); ushort num2 = (ushort)channel.read(Types.UINT16_TYPE); StructureRegion structureRegion; if (StructureManager.tryGetRegion(x3, y3, out structureRegion) && (int)num2 < structureRegion.drops.Count) { Transform model2 = structureRegion.drops[(int)num2].model; if (model2 != null && (inputInfo.point - model2.transform.position).sqrMagnitude < 256f) { inputInfo.transform = model2; } else { inputInfo = null; } } else { inputInfo = null; } break; } case ERaycastInfoType.RESOURCE: { inputInfo.point = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.direction = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.normal = (Vector3)channel.read(Types.VECTOR3_TYPE); inputInfo.material = (EPhysicsMaterial)((byte)channel.read(Types.BYTE_TYPE)); byte x4 = (byte)channel.read(Types.BYTE_TYPE); byte y4 = (byte)channel.read(Types.BYTE_TYPE); ushort index3 = (ushort)channel.read(Types.UINT16_TYPE); Transform resource = ResourceManager.getResource(x4, y4, index3); if (resource != null && (inputInfo.point - resource.transform.position).sqrMagnitude < 256f) { inputInfo.transform = resource; } else { inputInfo = null; } break; } } if (inputInfo != null) { this.serversideInputs.Enqueue(inputInfo); } } } }