public override void OnUse(ControllableObject player, Vector3 pos) { int x2 = (int)(pos.x) / OmniTerrain.chunkSize; int y2 = (int)(pos.y) / OmniTerrain.chunkSize; int x = (int)(pos.x) % OmniTerrain.chunkSize; int y = (int)(pos.y) % OmniTerrain.chunkSize; if(OmniTerrain.chunks.ContainsKey(x2 + y2 * OmniTerrain.Width)) { TerrainChunk ch = OmniTerrain.chunks[x2 + y2 * OmniTerrain.Width]; if (ch.tileMap[x + y * OmniTerrain.chunkSize] == -1) { terrainAddBlock t = new terrainAddBlock(player, this, (int)pos.x, (int)pos.y); OmniTerrain.terrainUpdates.Add(t); } } }
void netEvent(NetworkPlayer player,int tick,string name, byte[] data) { MemoryStream stream = new MemoryStream(data); BinaryReader reader = new BinaryReader(stream); System.Type type = System.Type.GetType(name); if (type == null) return; if (!typeof(NetworkEvent).IsAssignableFrom(type)) return; NetworkEvent eventType = Activator.CreateInstance(type,tick) as NetworkEvent; if (eventType.type == NetworkSendType.Everyone) if (player == Network.player) { return; } eventType.player = player; FieldInfo[] info = type.GetFields(); int mask = reader.ReadInt32(); for (int i = 0; i < info.Length; i++) { if ((mask & (1 << i+1)) == 0) continue; if (info[i].FieldType.Name == "Single") { float val = reader.ReadSingle(); info[i].SetValue(eventType, val); } else if (info[i].FieldType.Name == "Char") { char val = reader.ReadChar(); info[i].SetValue(eventType, val); } else if (info[i].FieldType.Name == "Type") { string nm = reader.ReadString(); Type t = Type.GetType(nm); info[i].SetValue(eventType, t); } else if (info[i].FieldType.Name == "Boolean") { bool val = reader.ReadBoolean(); info[i].SetValue(eventType, val); } else if (info[i].FieldType.Name == "Byte") { byte val = reader.ReadByte(); info[i].SetValue(eventType, val); } else if (info[i].FieldType.Name == "String") { string val = reader.ReadString(); info[i].SetValue(eventType, val); } else if (info[i].FieldType.Name == "Int32") { int val = reader.ReadInt32(); info[i].SetValue(eventType, val); } else if (info[i].FieldType.Name == "Vector2") { Vector2 val = new Vector2(reader.ReadSingle(), reader.ReadSingle()); info[i].SetValue(eventType, val); } else if (info[i].FieldType.Name == "Int32[]") { int len = reader.ReadInt32(); int[] val = new int[len]; for (int j = 0; j < val.Length; j++) val[j] = reader.ReadInt32(); info[i].SetValue(eventType, val); } else if (info[i].FieldType.Name == "tUpdate[]") { int len = reader.ReadInt32(); tUpdate[] val = new tUpdate[len]; for (int j = 0; j < val.Length; j++) { byte t = reader.ReadByte(); if (t == 1) val[j] = new terrainDmg(); else if (t == 2) val[j] = new terrainAddBlock(); FieldInfo[] field = val[j].GetType().GetFields(); for (int k = 0; k < field.Length; k++) { if (field[k].FieldType.Name == "Int32") { int v = reader.ReadInt32(); field[k].SetValue(val[j], v); } } } info[i].SetValue(eventType, val); } else if (typeof(OmniObject).IsAssignableFrom(info[i].FieldType)) { int id = reader.ReadInt32(); info[i].SetValue(eventType, OmniWorld.instance.SpawnedObjectsNew[id]); } else if (typeof(OmniItemType).IsAssignableFrom(info[i].FieldType)) { int id = reader.ReadInt32(); info[i].SetValue(eventType, OmniItems.itemTypes[id]); } } bool flag = false; /* if (Network.isClient) { for (int i = 0; i < OmniEvents.toValidate.Count; i++) { if (type == OmniEvents.toValidate[i].GetType()) { OmniEvents.toValidate[i].validate(eventType); flag = true; } } } * */ if(Network.isClient) eventType.fromServer = true; OmniEvents.AddEvent(eventType); }