public void ClientActionReceived(MultiplayerClient client, MultiplayerAction action) { switch (action.action) { case MultiplayerAction.Action.AVATAR_MOVE: { int objectId = Int32.Parse(action.GetParameter(0)); Vector3 pos = new Vector3( Single.Parse(action.GetParameter(1)), Single.Parse(action.GetParameter(2)), Single.Parse(action.GetParameter(3))); Vector3 rot = new Vector3( Single.Parse(action.GetParameter(4)), Single.Parse(action.GetParameter(5)), Single.Parse(action.GetParameter(6))); if (objectId == client.id) { Avatar avatar = world.avatarManager.GetAvatarByObjectId(objectId); avatar.position = pos; avatar.rotation = rot; server.SendToEveryone(action, client.id); } break; } case MultiplayerAction.Action.TILE_CREATE: { byte tileType = byte.Parse(action.GetParameter(0)); TilePosition pos = new TilePosition( Int32.Parse(action.GetParameter(1)), Int32.Parse(action.GetParameter(2)), Int32.Parse(action.GetParameter(3))); CreateTile(pos, tileType); break; } case MultiplayerAction.Action.TILE_CLICKED: { TilePosition pos = new TilePosition( Int32.Parse(action.GetParameter(0)), Int32.Parse(action.GetParameter(1)), Int32.Parse(action.GetParameter(2))); this.TileClicked(pos); break; } case MultiplayerAction.Action.TILE_HIT: { string itemId = action.GetParameter(0); TilePosition pos = new TilePosition( Int32.Parse(action.GetParameter(1)), Int32.Parse(action.GetParameter(2)), Int32.Parse(action.GetParameter(3))); this.TileHit(pos, world.itemManager.GetItemDefinitionById(itemId)); break; } } }
public void ClientActionReceived(MultiplayerClient client, MultiplayerAction action) { switch (action.action) { case MultiplayerAction.Action.INITIAL_DATA: initializationDataReceived = true; initializationData = action.extraData; break; case MultiplayerAction.Action.AVATAR_MOVE: { int objectId = Int32.Parse(action.GetParameter(0)); Vector3 pos = new Vector3( Single.Parse(action.GetParameter(1)), Single.Parse(action.GetParameter(2)), Single.Parse(action.GetParameter(3))); Vector3 rot = new Vector3( Single.Parse(action.GetParameter(4)), Single.Parse(action.GetParameter(5)), Single.Parse(action.GetParameter(6))); Avatar avatar = world.avatarManager.GetAvatarByObjectId(objectId); avatar.position = pos; avatar.rotation = rot; break; } case MultiplayerAction.Action.AVATAR_CREATE: { int objectId = Int32.Parse(action.GetParameter(0)); string avatarDefinitionId = action.GetParameter(1); Vector3 pos = new Vector3( Single.Parse(action.GetParameter(2)), Single.Parse(action.GetParameter(3)), Single.Parse(action.GetParameter(4))); Vector3 rot = new Vector3( Single.Parse(action.GetParameter(5)), Single.Parse(action.GetParameter(6)), Single.Parse(action.GetParameter(7))); Avatar avatar = world.avatarManager.CreateAvatar(world.avatarManager.GetAvatarDefinitionById(avatarDefinitionId), objectId, pos, true); avatar.rotation = rot; break; } case MultiplayerAction.Action.AVATAR_DESTROY: { int objectId = Int32.Parse(action.GetParameter(0)); world.avatarManager.DestroyAvatar(world.avatarManager.GetAvatarByObjectId(objectId)); break; } case MultiplayerAction.Action.TILE_INVALIDATED: { MemoryStream ms = new MemoryStream(action.extraData); BinaryReader br = new BinaryReader(ms); int n = br.ReadInt32(); Tile tile = new Tile(); for (int i = 0; i < n; i++) { TilePosition pos = SerializationUtils.ReadTilePosition(br); tile.Deserialize(br.ReadUInt32()); if (tile.tileType != world.tileManager.GetTileType(pos)) { world.tileManager.SetTileType(pos, tile.tileType); } if (tile.OnFire != world.tileManager.GetTileOnFire(pos)) { world.tileManager.SetTileOnFire(pos, tile.OnFire); } if (tile.ExtraData != world.tileManager.GetTileExtraData(pos)) { world.tileManager.SetTileExtraData(pos, tile.ExtraData); } if (tile.Energy != world.tileManager.GetTileEnergy(pos)) { world.tileManager.SetTileEnergy(pos, tile.Energy); } } break; } } }
public void ClientActionReceived(MultiplayerClient client, MultiplayerAction action) { switch (action.action) { case MultiplayerAction.Action.AVATAR_MOVE: { int objectId = Int32.Parse(action.GetParameter(0)); Vector3 pos = new Vector3( Single.Parse(action.GetParameter(1)), Single.Parse(action.GetParameter(2)), Single.Parse(action.GetParameter(3))); Vector3 rot = new Vector3( Single.Parse(action.GetParameter(4)), Single.Parse(action.GetParameter(5)), Single.Parse(action.GetParameter(6))); if (objectId == client.id) { Avatar avatar = world.avatarManager.GetAvatarByObjectId(objectId); avatar.position = pos; avatar.rotation = rot; server.SendToEveryone(action, client.id); } break; } case MultiplayerAction.Action.TILE_CREATE: { byte tileType = byte.Parse(action.GetParameter(0)); TilePosition pos = new TilePosition( Int32.Parse(action.GetParameter(1)), Int32.Parse(action.GetParameter(2)), Int32.Parse(action.GetParameter(3))); CreateTile(pos, tileType); break; } case MultiplayerAction.Action.TILE_CLICKED: { TilePosition pos = new TilePosition( Int32.Parse(action.GetParameter(0)), Int32.Parse(action.GetParameter(1)), Int32.Parse(action.GetParameter(2))); this.TileClicked(pos); break; } case MultiplayerAction.Action.TILE_HIT: { string itemId = action.GetParameter(0); TilePosition pos = new TilePosition( Int32.Parse(action.GetParameter(1)), Int32.Parse(action.GetParameter(2)), Int32.Parse(action.GetParameter(3))); this.TileHit(pos, world.itemManager.GetItemDefinitionById(itemId)); break; } } }
public void ClientActionReceived(MultiplayerClient client, MultiplayerAction action) { switch (action.action) { case MultiplayerAction.Action.INITIAL_DATA: initializationDataReceived = true; initializationData = action.extraData; break; case MultiplayerAction.Action.AVATAR_MOVE: { int objectId = Int32.Parse(action.GetParameter(0)); Vector3 pos = new Vector3( Single.Parse(action.GetParameter(1)), Single.Parse(action.GetParameter(2)), Single.Parse(action.GetParameter(3))); Vector3 rot = new Vector3( Single.Parse(action.GetParameter(4)), Single.Parse(action.GetParameter(5)), Single.Parse(action.GetParameter(6))); Avatar avatar = world.avatarManager.GetAvatarByObjectId(objectId); avatar.position = pos; avatar.rotation = rot; break; } case MultiplayerAction.Action.AVATAR_CREATE: { int objectId = Int32.Parse(action.GetParameter(0)); string avatarDefinitionId = action.GetParameter(1); Vector3 pos = new Vector3( Single.Parse(action.GetParameter(2)), Single.Parse(action.GetParameter(3)), Single.Parse(action.GetParameter(4))); Vector3 rot = new Vector3( Single.Parse(action.GetParameter(5)), Single.Parse(action.GetParameter(6)), Single.Parse(action.GetParameter(7))); Avatar avatar = world.avatarManager.CreateAvatar(world.avatarManager.GetAvatarDefinitionById(avatarDefinitionId), objectId, pos, true); avatar.rotation = rot; break; } case MultiplayerAction.Action.AVATAR_DESTROY: { int objectId = Int32.Parse(action.GetParameter(0)); world.avatarManager.DestroyAvatar(world.avatarManager.GetAvatarByObjectId(objectId)); break; } case MultiplayerAction.Action.TILE_INVALIDATED: { MemoryStream ms = new MemoryStream(action.extraData); BinaryReader br = new BinaryReader(ms); int n = br.ReadInt32(); Tile tile = new Tile(); for (int i = 0; i < n; i++) { TilePosition pos = SerializationUtils.ReadTilePosition(br); tile.Deserialize(br.ReadUInt32()); if (tile.tileType != world.tileManager.GetTileType(pos)) world.tileManager.SetTileType(pos, tile.tileType); if (tile.OnFire != world.tileManager.GetTileOnFire(pos)) world.tileManager.SetTileOnFire(pos, tile.OnFire); if (tile.ExtraData != world.tileManager.GetTileExtraData(pos)) world.tileManager.SetTileExtraData(pos, tile.ExtraData); if (tile.Energy != world.tileManager.GetTileEnergy(pos)) world.tileManager.SetTileEnergy(pos, tile.Energy); } break; } } }