public static void BindCharacterToGame( AsyncRPGDataContext context, int character_id, int new_game_id) { // Get the most recent event that occurred in the new game int last_game_event_id = GameEventQueries.GetLastGameEvent(context, new_game_id); // Tell the character which game they are bound to // and set an initial location var dbCharacter = (from c in context.Characters where c.CharacterID == character_id select c).Single(); dbCharacter.GameID = new_game_id; dbCharacter.RoomX = 0; dbCharacter.RoomY = 0; dbCharacter.RoomZ = 0; dbCharacter.X = 0; dbCharacter.Y = 0; dbCharacter.Z = 0; dbCharacter.Angle = 0; dbCharacter.LastSentEventID = last_game_event_id; dbCharacter.NewEventsPosted = false; context.SubmitChanges(); }
private void PostSpawnedMobEvents( RequestCache requestCache) { // Add a game event for every new mob foreach (Mob mob in m_newMobs) { GameEventQueries.AddEvent( requestCache.DatabaseContext, m_room.room_key.game_id, new GameEvent_MobSpawned() { mob_state = new MobState() { mob_id = mob.ID, mob_type_name = mob.MobType.Name, health = mob.Health, energy = mob.Energy, game_id = mob.RoomKey.game_id, room_x = mob.RoomKey.x, room_y = mob.RoomKey.y, room_z = mob.RoomKey.z, x = mob.Position.x, y = mob.Position.y, z = mob.Position.z, angle = mob.Angle } }); } }
private void PostCharacterPortaledEvent( RequestCache requestCache) { // Add a game event that the player used a portal GameEventQueries.AddEvent( requestCache.DatabaseContext, m_game_id, new GameEvent_CharacterPortaled() { character_id = m_character_id, from_room_x = m_current_room_key.x, from_room_y = m_current_room_key.y, from_room_z = m_current_room_key.z, from_x = m_current_character_position.x, from_y = m_current_character_position.y, from_z = m_current_character_position.z, from_angle = m_current_character_angle, to_room_x = m_opposing_room_key.x, to_room_y = m_opposing_room_key.y, to_room_z = m_opposing_room_key.z, to_x = m_opposing_portal_position.x, to_y = m_opposing_portal_position.y, to_z = m_opposing_portal_position.z, to_angle = m_portal_angle }); }
private void PostCharacterMovedEvent( RequestCache requestCache) { // Add a game event if the player is moving to the portal if (m_move_to_target) { GameEventParameters gameEvent = new GameEvent_CharacterMoved() { character_id = m_character_id, room_x = m_current_room_key.x, room_y = m_current_room_key.y, room_z = m_current_room_key.z, from_x = m_current_character_position.x, from_y = m_current_character_position.y, from_z = m_current_character_position.z, from_angle = m_current_character_angle, to_x = m_energy_tank.Position.x, to_y = m_energy_tank.Position.y, to_z = m_energy_tank.Position.z, to_angle = MathConstants.GetAngleForDirection(MathConstants.eDirection.down) }; GameEventQueries.AddEvent(requestCache.DatabaseContext, m_game_id, gameEvent); m_ai_relevant_events.Add(gameEvent); } }
private void PostCharacterMovedEvent( RequestCache requestCache) { if (m_move_to_target) { // Add a game event if the player is moving to the portal GameEventQueries.AddEvent( requestCache.DatabaseContext, m_game_id, new GameEvent_CharacterMoved() { character_id = m_character_id, room_x = m_current_room_key.x, room_y = m_current_room_key.y, room_z = m_current_room_key.z, from_x = m_current_character_position.x, from_y = m_current_character_position.y, from_z = m_current_character_position.z, from_angle = m_current_character_angle, to_x = m_portal_position.x, to_y = m_portal_position.y, to_z = m_portal_position.z, to_angle = m_portal_angle }); } }
private void PostCharacterLeftGameEvent( RequestCache requestCache) { GameEventQueries.AddEvent( requestCache.DatabaseContext, m_previous_game_id, new GameEvent_CharacterLeftGame() { character_state = m_character_state }); }
private void ComputeMovesForMobs( RequestCache requestCache) { foreach (MobUpdateContext context in m_mobContexts) { // Compute the move for each mob context.ComputeMove(); // Post events that occurred during the move foreach (GameEventParameters game_event in context.output_game_events) { GameEventQueries.AddEvent(requestCache.DatabaseContext, m_world.GameID, game_event); } } }
private void PostCharacterLeftGameEvent( RequestCache requestCache) { GameEventParameters gameEvent = new GameEvent_CharacterLeftGame() { character_state = m_character_state }; // Add a game event if the player is moving to the portal GameEventQueries.AddEvent( requestCache.DatabaseContext, m_character_state.game_id, gameEvent); }
private void PostCharacterJoinedGameEvent( RequestCache requestCache) { // Update the character state to match the new game m_character_state.game_id = m_game_id; m_character_state.game_name = GameQueries.GetGameName(requestCache.DatabaseContext, m_game_id); // Add a note to the game event log that this new character joined the new game GameEventQueries.AddEvent( requestCache.DatabaseContext, m_game_id, new GameEvent_CharacterJoinedGame() { character_state = m_character_state }); }
private void PostEnergyTankDrainedEvent( RequestCache requestCache) { GameEventParameters gameEvent = new GameEvent_EnergyTankDrained() { energy_tank_id = m_energy_tank_id, drainer_id = m_character_id, drainer_faction = GameConstants.eFaction.player, energy_drained = m_energy_tank_old_energy }; // Add a game event if the player is moving to the portal GameEventQueries.AddEvent(requestCache.DatabaseContext, m_game_id, gameEvent); m_ai_relevant_events.Add(gameEvent); }
private void LookupCharacterRecentEvents( RequestCache requestCache) { int new_last_game_event_id = -1; int last_game_event_id = CharacterQueries.GetCharacterLastEventId( requestCache.DatabaseContext, m_character_id); CharacterQueries.ClearCharacterNewEventFlag( requestCache.DatabaseContext, m_character_id); GameEventQueries.GetGameEventsAfterId( requestCache.DatabaseContext, m_current_game_id, last_game_event_id, out m_game_events, out new_last_game_event_id); if (m_has_new_events && new_last_game_event_id != last_game_event_id) { CharacterQueries.UpdateCharacterLastEventId( requestCache.DatabaseContext, m_character_id, new_last_game_event_id); } }
private void PostCharacterMovedEvent( RequestCache requestCache) { GameEventParameters gameEvent = new GameEvent_CharacterMoved() { character_id = m_character_id, room_x = m_current_room_key.x, room_y = m_current_room_key.y, room_z = m_current_room_key.z, from_x = m_current_character_position.x, from_y = m_current_character_position.y, from_z = m_current_character_position.z, from_angle = m_current_character_angle, to_x = m_target_position.x, to_y = m_target_position.y, to_z = m_target_position.z, to_angle = m_target_angle }; // Add a game event if the player is moving to the portal GameEventQueries.AddEvent(requestCache.DatabaseContext, m_game_id, gameEvent); m_ai_relevant_events.Add(gameEvent); }
public static void DeleteGame( AsyncRPGDataContext context, int gameid) { // Detach all of the Characters from the game { var query = from character in context.Characters where character.GameID == gameid select character; foreach (Characters character in query) { character.GameID = -1; character.RoomX = 0; character.RoomY = 0; character.RoomZ = 0; character.X = 0; character.Y = 0; character.Z = 0; character.Angle = 0; } context.SubmitChanges(); } // Free all of the portals { var query = from portal in context.Portals where portal.GameID == gameid select portal; foreach (Portals portal in query) { context.Portals.DeleteOnSubmit(portal); } context.SubmitChanges(); } // Free all of the mobs { var query = from mob in context.Mobs where mob.GameID == gameid select mob; foreach (Mobs mob in query) { context.Mobs.DeleteOnSubmit(mob); } context.SubmitChanges(); } // Free all of the mob spawners { var query = from mobSpawner in context.MobSpawners where mobSpawner.GameID == gameid select mobSpawner; foreach (MobSpawners mobSpawner in query) { context.MobSpawners.DeleteOnSubmit(mobSpawner); } context.SubmitChanges(); } // TODO DeleteGame: Delete loot // Free all of the rooms { var query = from room in context.Rooms where room.GameID == gameid select room; foreach (Rooms room in query) { context.Rooms.DeleteOnSubmit(room); } context.SubmitChanges(); } // Free all of the game_events associated from the game GameEventQueries.DeleteAllEventsForGame(context, gameid); // Finally, Free the game itself { var query = from game in context.Games where game.GameID == gameid select game; foreach (Games game in query) { context.Games.DeleteOnSubmit(game); } context.SubmitChanges(); } }