private void EnergyTanks_Detach(EnergyTanks entity) { this.SendPropertyChanging(); entity.Games = null; }
public static void InsertWorld( AsyncRPGDataContext db_context, World world) { Dictionary<int, Portal> portalIdMap = new Dictionary<int, Portal>(); Dictionary<int, int> portalIdRemapping = new Dictionary<int, int>(); Dictionary<int, int> reversePortalIdRemapping = new Dictionary<int, int>(); // Insert all the rooms and portals with their initial IDs { foreach (Room room in world.Rooms) { // Save each room into the database { Rooms dbRoom = new Rooms { X = room.room_key.x, Y = room.room_key.y, Z = room.room_key.z, GameID = world.GameID, RandomSeed = room.random_seed, StaticData = JsonMapper.ToJson(room.static_room_data) }; db_context.Rooms.InsertOnSubmit(dbRoom); db_context.SubmitChanges(); } // Save each portal into the database foreach (Portal portal in room.portals) { Portals dbPortal = new Portals { PortalType = (int)portal.portal_type, TargetPortalID = -1, GameID = world.GameID, RoomX = portal.room_x, RoomY = portal.room_y, RoomZ = portal.room_z, RoomSide = (int)portal.room_side, BboxX0 = portal.bounding_box.Min.x, BboxY0 = portal.bounding_box.Min.y, BboxX1 = portal.bounding_box.Max.x, BboxY1 = portal.bounding_box.Max.y }; db_context.Portals.InsertOnSubmit(dbPortal); db_context.SubmitChanges(); portalIdMap.Add(portal.portal_id, portal); portalIdRemapping.Add(portal.portal_id, dbPortal.PortalID); reversePortalIdRemapping.Add(dbPortal.PortalID, portal.portal_id); // Portal ID assignment has to happen after all the portals are inserted } // Save each mob spawner to the database foreach (MobSpawner spawner in room.mobSpawners) { MobSpawners dbMobSpawner = new MobSpawners { GameID = world.GameID, RoomX = room.room_key.x, RoomY = room.room_key.y, RoomZ = room.room_key.z, X = spawner.Position.x, Y = spawner.Position.y, Z = spawner.Position.z, MobSpawnerTableID = spawner.SpawnTable.ID, RemainingSpawnCount = spawner.RemainingSpawnCount, RandomSeed = spawner.RandomSeed }; db_context.MobSpawners.InsertOnSubmit(dbMobSpawner); db_context.SubmitChanges(); // Assign an id once the spawner has been inserted into the DB spawner.ID = dbMobSpawner.MobSpawnerID; } // Save each energy tank to the database if (room is RoomLayout) { RoomLayout roomLayout = (RoomLayout)room; foreach (EnergyTank energyTank in roomLayout.energyTanks) { EnergyTanks dbEnergyTank = new EnergyTanks { GameID = world.GameID, RoomX = room.room_key.x, RoomY = room.room_key.y, RoomZ = room.room_key.z, X = energyTank.Position.x, Y = energyTank.Position.y, Z = energyTank.Position.z, Ownership = (int)energyTank.Faction, Energy = energyTank.Energy }; db_context.EnergyTanks.InsertOnSubmit(dbEnergyTank); db_context.SubmitChanges(); // Assign an id once the energy tank has been inserted into the DB energyTank.ID = dbEnergyTank.EnergyTankID; } // Drop the energy tanks now that we've saved them roomLayout.energyTanks = null; } } } // Fix up portal IDs { // Fixed the cached portal ids to match the ids in the database var query = from dbPortal in db_context.Portals where dbPortal.GameID == world.GameID select dbPortal; foreach (Portals dbPortal in query) { // Find the cache portal id from the db portal id using the reverse mapping int cachePortalId = reversePortalIdRemapping[dbPortal.PortalID]; // Get the cached portal using the cached portal Portal cachePortal = portalIdMap[cachePortalId]; // Remap the cached portal's target id to be a db portal id int dbTargetPortalId = portalIdRemapping[cachePortal.target_portal_id]; // Set the target portal id in the database dbPortal.TargetPortalID = dbTargetPortalId; // Fix-up the portal ids on the cached portal cachePortal.portal_id = dbPortal.PortalID; cachePortal.target_portal_id = dbTargetPortalId; } db_context.SubmitChanges(); } }
private void EnergyTanks_Attach(EnergyTanks entity) { this.SendPropertyChanging(); entity.Games = this; }
public static EnergyTank CreateEnergyTank(EnergyTanks dbEnergyTank) { EnergyTank newEnergyTank = new EnergyTank(); newEnergyTank.m_room_key = new RoomKey(dbEnergyTank.GameID, dbEnergyTank.RoomX, dbEnergyTank.RoomY, dbEnergyTank.RoomZ); newEnergyTank.m_energy_tank_id = dbEnergyTank.EnergyTankID; newEnergyTank.m_position = new Point3d(dbEnergyTank.X, dbEnergyTank.Y, dbEnergyTank.Z); newEnergyTank.m_energy = dbEnergyTank.Energy; newEnergyTank.m_faction = (GameConstants.eFaction)dbEnergyTank.Ownership; return newEnergyTank; }