public static void BuyHouse(Client player, HouseModel house) { if (house.status != Constants.HOUSE_STATE_BUYABLE) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.house_not_buyable); return; } if (player.GetSharedData(EntityData.PLAYER_BANK) < house.price) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.house_not_money); return; } int bank = player.GetSharedData(EntityData.PLAYER_BANK) - house.price; var message = string.Format(InfoRes.house_buy, house.name, house.price); var labelText = GetHouseLabelText(house); player.SendChatMessage(Constants.COLOR_INFO + message); player.SetSharedData(EntityData.PLAYER_BANK, bank); house.status = Constants.HOUSE_STATE_NONE; house.houseLabel.Text = GetHouseLabelText(house); house.owner = player.Name; house.locked = true; Task.Factory.StartNew(() => { // Update the house DBHouseCommands.UpdateHouse(house); }); }
public void UnrentCommand(Client player) { int rentedHouse = player.GetData(EntityData.PLAYER_RENT_HOUSE); // Check if the house has any rented house if (rentedHouse == 0) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_rented_house); return; } // Get the house where the player is rented var house = GetHouseById(rentedHouse); if (player.Position.DistanceTo2D(house.position) > 2.5f) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_in_house_door); return; } // Remove player's rental player.SetData(EntityData.PLAYER_RENT_HOUSE, 0); house.tenants++; Task.Factory.StartNew(() => { // Update house's tenants DBHouseCommands.UpdateHouse(house); }); // Send the message to the player var message = string.Format(InfoRes.house_rent_stop, house.name); player.SendChatMessage(Constants.COLOR_INFO + message); }
public static void LoadDatabaseHouses() { houseList = DBHouseCommands.LoadAllHouses(); foreach (var houseModel in houseList) { var houseLabelText = GetHouseLabelText(houseModel); houseModel.houseLabel = NAPI.TextLabel.CreateTextLabel(houseLabelText, houseModel.position, 20.0f, 0.75f, 4, new Color(255, 255, 255), false, houseModel.dimension); } }
public void RentableCommand(Client player, int amount = 0) { if (player.GetData(EntityData.PLAYER_HOUSE_ENTERED) == 0) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_in_house); } else { int houseId = player.GetData(EntityData.PLAYER_HOUSE_ENTERED); var house = GetHouseById(houseId); if (house == null || house.owner != player.Name) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_house_owner); } else if (amount > 0) { house.rental = amount; house.status = Constants.HOUSE_STATE_RENTABLE; house.tenants = 2; // Update house's textlabel house.houseLabel.Text = GetHouseLabelText(house); Task.Factory.StartNew(() => { // Update the house DBHouseCommands.UpdateHouse(house); }); // Message sent to the player var message = string.Format(InfoRes.house_state_rent, amount); player.SendChatMessage(Constants.COLOR_INFO + message); } else if (house.status == Constants.HOUSE_STATE_RENTABLE) { house.status = Constants.HOUSE_STATE_NONE; house.tenants = 2; // Update house's textlabel house.houseLabel.Text = GetHouseLabelText(house); Task.Factory.StartNew(() => { // Update the house Database.KickTenantsOut(house.id); DBHouseCommands.UpdateHouse(house); }); // Message sent to the player player.SendChatMessage(Constants.COLOR_INFO + InfoRes.house_rent_cancel); } else { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.price_positive); } } }
public void RentCommand(Client player) { // Check if the player has a rented house if (player.GetData(EntityData.PLAYER_RENT_HOUSE) > 0) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_house_rented); return; } // Get the closes house var house = GetClosestHouse(player); if (house == null) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_house_near); return; } if (house.status != Constants.HOUSE_STATE_RENTABLE) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.house_not_rentable); return; } // Get the player's money on hand int playerMoney = player.GetSharedData(EntityData.PLAYER_MONEY); if (playerMoney < house.rental) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_rent_money); return; } // Rent the house to the player player.SetSharedData(EntityData.PLAYER_MONEY, playerMoney - house.rental); player.SetData(EntityData.PLAYER_RENT_HOUSE, house.id); house.tenants--; if (house.tenants == 0) { house.status = Constants.HOUSE_STATE_NONE; house.houseLabel.Text = GetHouseLabelText(house); } Task.Factory.StartNew(() => { // Update house's tenants DBHouseCommands.UpdateHouse(house); }); // Send the message to the player var message = string.Format(InfoRes.house_rent, house.name, house.rental); player.SendChatMessage(Constants.COLOR_INFO + message); }