public static bool UpgradeHouse(House house, InventoryItem deed) { int newModel = 0; switch (deed.Id_nb) { case "housing_alb_cottage_deed": newModel = 1; break; case "housing_alb_house_deed": newModel = 2; break; case "housing_alb_villa_deed": newModel = 3; break; case "housing_alb_mansion_deed": newModel = 4; break; case "housing_mid_cottage_deed": newModel = 5; break; case "housing_mid_house_deed": newModel = 6; break; case "housing_mid_villa_deed": newModel = 7; break; case "housing_mid_mansion_deed": newModel = 8; break; case "housing_hib_cottage_deed": newModel = 9; break; case "housing_hib_house_deed": newModel = 10; break; case "housing_hib_villa_deed": newModel = 11; break; case "housing_hib_mansion_deed": newModel = 12; break; } if (newModel == 0) return false; // remove all players from the home before we upgrade it foreach (GamePlayer player in house.GetAllPlayersInHouse()) { player.LeaveHouse(); } // if there is a consignment merchant, we have to re-initialize since we changed the house var merchant = GameServer.Database.SelectObject<HouseConsignmentMerchant>("HouseNumber = '" + house.HouseNumber + "'"); long oldMerchantMoney = 0; if (merchant != null) { oldMerchantMoney = merchant.Money; } RemoveHouseItems(house); // change the model of the house house.Model = newModel; // re-add the merchant if there was one if (merchant != null) { house.AddConsignment(oldMerchantMoney); } // save the house, and broadcast an update house.SaveIntoDatabase(); house.SendUpdate(); return true; }
public static void RemoveHouse(House house) { // try and get the houses for the given region Dictionary<int, House> housesByRegion; _houseList.TryGetValue(house.RegionID, out housesByRegion); if (housesByRegion == null) return; // remove all players from the house foreach (GamePlayer player in house.GetAllPlayersInHouse()) { player.LeaveHouse(); } // remove the house for all nearby players foreach (GamePlayer player in WorldMgr.GetPlayersCloseToSpot(house, WorldMgr.OBJ_UPDATE_DISTANCE)) { player.Out.SendRemoveHouse(house); player.Out.SendGarden(house); } if (house.Model > 0) log.WarnFormat("Removing house #{0} owned by {1}!", house.HouseNumber, house.DatabaseItem.Name); else log.WarnFormat("Lotmarker #{0} owned by {1} had rent due, lot now for sale!", house.HouseNumber, house.DatabaseItem.Name); RemoveHouseItems(house); RemoveHousePermissions(house); ResetHouseData(house); house.OwnerID = ""; house.KeptMoney = 0; house.Name = ""; // not null ! house.DatabaseItem.CreationTime = DateTime.Now; house.DatabaseItem.LastPaid = DateTime.MinValue; // saved the cleared house in the database house.SaveIntoDatabase(); // remove the house from the list of houses in the region housesByRegion.Remove(house.HouseNumber); // spawn a lot marker for the now-empty lot GameLotMarker.SpawnLotMarker(house.DatabaseItem); }
public static void AddHouse(House house) { // try and get the houses for the given region Dictionary<int, House> housesByRegion; _houseList.TryGetValue(house.RegionID, out housesByRegion); if (housesByRegion == null) return; // if the house doesn't exist yet, add it if (!housesByRegion.ContainsKey(house.HouseNumber)) { housesByRegion.Add(house.HouseNumber, house); } else { // replace the existing lot with our new house housesByRegion[house.HouseNumber] = house; } if (house.Model == 0) { // if this is a lot marker purchase then reset all permissions and customization RemoveHouseItems(house); RemoveHousePermissions(house); ResetHouseData(house); } else { // create a new set of permissions for (int i = HousingConstants.MinPermissionLevel; i < HousingConstants.MaxPermissionLevel + 1; i++) { if (house.PermissionLevels.ContainsKey(i)) { var oldPermission = house.PermissionLevels[i]; if (oldPermission != null) { GameServer.Database.DeleteObject(oldPermission); } } // create a new, blank permission var permission = new DBHousePermissions(house.HouseNumber, i); house.PermissionLevels.Add(i, permission); // add the permission to the database GameServer.Database.AddObject(permission); } } // save the house, broadcast an update house.SaveIntoDatabase(); house.SendUpdate(); }