public void House_ClientEvent(Client player, string event_name, params object[] args) { switch (event_name) { case "HouseInteract": { if (!player.hasData("HouseMarker_ID")) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("HouseMarker_ID")); if (house == null) { return; } if (string.IsNullOrEmpty(house.Owner)) { // not owned house player.triggerEvent("House_PurchaseMenu", API.toJson(new { Interior = HouseTypes.HouseTypeList[house.Type].Name, Price = house.Price })); } else { // owned house if (house.Locked) { if (house.Owner == player.socialClubName) { house.SendPlayer(player); } else { player.sendNotification("Error", "~r~Only the owner can access this house."); } } else { house.SendPlayer(player); } } break; } case "HousePurchase": { if (!player.hasData("HouseMarker_ID")) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("HouseMarker_ID")); if (house == null) { return; } if (!string.IsNullOrEmpty(house.Owner)) { player.sendNotification("Error", "~r~This house is owned."); return; } if (API.exported.ADRP.GetPlayerMoney(player) < house.Price) { return; } if (PLAYER_HOUSE_LIMIT > 0 && Houses.Count(h => h.Owner == player.socialClubName) >= PLAYER_HOUSE_LIMIT) { player.sendNotification("Error", "~r~You can't own any more houses."); return; } player.sendNotification("House Purchased", "~g~Congratulations, you purchased this house!"); house.SetLock(true); house.SetOwner(player); house.SendPlayer(player); break; } case "HouseMenu": { if (!player.hasData("InsideHouse_ID")) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("InsideHouse_ID")); if (house == null) { return; } if (house.Owner != player.socialClubName) { player.sendNotification("Error", "~r~Only the owner can access house menu."); return; } player.triggerEvent("HouseMenu", API.toJson(house)); break; } case "HouseSetName": { if (!player.hasData("InsideHouse_ID") || args.Length < 1) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("InsideHouse_ID")); if (house == null) { return; } if (house.Owner != player.socialClubName) { player.sendNotification("Error", "~r~Only the owner can do this."); return; } string new_name = args[0].ToString(); if (new_name.Length > 32) { player.sendNotification("Error", "~r~Name can't be more than 32 characters."); return; } house.SetName(new_name); player.sendNotification("Success", string.Format("~g~House name changed to: ~w~\"{0}\"", new_name)); break; } case "HouseSetLock": { if (!player.hasData("InsideHouse_ID") || args.Length < 1) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("InsideHouse_ID")); if (house == null) { return; } if (house.Owner != player.socialClubName) { player.sendNotification("Error", "~r~Only the owner can do this."); return; } bool new_state = Convert.ToBoolean(args[0]); house.SetLock(new_state); player.sendNotification("Success", ((new_state) ? "~g~The house is now locked." : "~g~The house is now unlocked.")); break; } case "HouseSafe": { if (!player.hasData("InsideHouse_ID") || args.Length < 2) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("InsideHouse_ID")); if (house == null) { return; } if (house.Owner != player.socialClubName) { player.sendNotification("Error", "~r~Only the owner can do this."); return; } int type = Convert.ToInt32(args[0]); int amount = 0; if (!int.TryParse(args[1].ToString(), out amount)) { player.sendNotification("Error", "~r~Invalid amount."); return; } if (amount < 1) { return; } if (type == 0) { if (house.Money + amount > HOUSE_MONEY_LIMIT) { player.sendNotification("Error", "~r~House money limit reached."); return; } house.ChangeMoney(amount); player.sendNotification("Success", string.Format("~g~Put ${0:n0} to the house safe.", amount)); player.triggerEvent("HouseUpdateSafe", API.toJson(new { Money = house.Money })); } else { if (house.Money < amount) { player.sendNotification("Error", "~r~The house safe doesn't have that much money."); return; } house.ChangeMoney(-amount); player.sendNotification("Success", string.Format("~g~Took ${0:n0} from the house safe.", amount)); player.triggerEvent("HouseUpdateSafe", API.toJson(new { Money = house.Money })); } break; } case "HouseSell": { if (!player.hasData("InsideHouse_ID")) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("InsideHouse_ID")); if (house == null) { return; } if (house.Owner != player.socialClubName) { player.sendNotification("Error", "~r~Only the owner can do this."); return; } if (house.Money > 0) { player.sendNotification("Error", "~r~Empty the house safe before selling the house."); return; } if (house.Weapons.Count > 0) { player.sendNotification("Error", "~r~Empty the house gun locker before selling the house."); return; } if (house.Furnitures.Count > 0) { player.sendNotification("Error", "~r~Sell the furnitures before selling the house."); return; } int price = (int)Math.Round(house.Price * 0.8); house.RemoveAllPlayers(); house.SetOwner(null); player.sendNotification("Success", string.Format("~g~Sold your house for ${0:n0}.", price)); break; } case "HouseLeave": { if (!player.hasData("InsideHouse_ID")) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("InsideHouse_ID")); if (house == null) { return; } house.RemovePlayer(player); break; } } }
public void House_ClientEvent(Client player, string event_name, params object[] args) { switch (event_name) { case "HouseInteract": { if (!player.hasData("HouseMarker_ID")) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("HouseMarker_ID")); if (house == null) { return; } if (string.IsNullOrEmpty(house.Owner)) { // not owned house player.triggerEvent("House_PurchaseMenu", API.toJson(new { Interior = HouseTypes.HouseTypeList[house.Type].Name, Price = house.Price })); } else { // owned house if (house.Locked) { if (house.Owner == player.name) { house.SendPlayer(player); } else { player.sendNotification("Ошибка\n~r~Это может делать только владелец."); } } else { house.SendPlayer(player); } } break; } case "HousePurchase": { if (!player.hasData("HouseMarker_ID")) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("HouseMarker_ID")); if (house == null) { return; } if (!string.IsNullOrEmpty(house.Owner)) { player.sendNotification("Ошибка\n~r~Этот дом приобретён."); return; } if (house.Price > PlayerFunctions.Player.GetMoney(player)) { player.sendNotification("Ошибка\n~r~Вы не можете позволить себе этот дом."); return; } if (PLAYER_HOUSE_LIMIT > 0 && Houses.Count(h => h.Owner == player.name) >= PLAYER_HOUSE_LIMIT) { player.sendNotification("Ошибка\n~r~Вы не можете иметь больше домов."); return; } player.sendNotification("Дом приобретен\n~g~Поздравляем, вы приобрели этот дом!"); house.SetLock(true); house.SetOwner(player); house.SendPlayer(player); PlayerFunctions.Player.ChangeMoney(player, -house.Price); break; } case "HouseMenu": { if (!player.hasData("InsideHouse_ID")) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("InsideHouse_ID")); if (house == null) { return; } if (house.Owner != player.name) { player.sendNotification("Ошибка\n~r~Только владелец имеет доступ к меню дома."); return; } player.triggerEvent("HouseMenu", API.toJson(house)); break; } case "HouseSetName": { if (!player.hasData("InsideHouse_ID") || args.Length < 1) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("InsideHouse_ID")); if (house == null) { return; } if (house.Owner != player.name) { player.sendNotification("Ошибка\n~r~Это может делать только владелец."); return; } string new_name = args[0].ToString(); if (new_name.Length > 32) { player.sendNotification("Ошибка\n~r~Имя дома не может быть больше 32-ух символов."); return; } house.SetName(new_name); player.sendNotification(string.Format("Успешно\n~g~Имя дома изменено на: ~w~\"{0}\"", new_name)); break; } case "HouseSetLock": { if (!player.hasData("InsideHouse_ID") || args.Length < 1) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("InsideHouse_ID")); if (house == null) { return; } if (house.Owner != player.name) { player.sendNotification("Ошибка/n~r~Это может делать только владелец."); return; } bool new_state = Convert.ToBoolean(args[0]); house.SetLock(new_state); player.sendNotification(((new_state) ? "Успешно/n~g~Дом закрыт." : "~g~Дом открыт.")); break; } case "HouseSafe": { if (!player.hasData("InsideHouse_ID") || args.Length < 2) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("InsideHouse_ID")); if (house == null) { return; } if (house.Owner != player.name) { player.sendNotification("Ошибка/n~r~Это может делать только владелец."); return; } int type = Convert.ToInt32(args[0]); int amount = 0; if (!int.TryParse(args[1].ToString(), out amount)) { player.sendNotification("Ошибка/n~r~Invalid amount."); return; } if (amount < 1) { return; } if (type == 0) { if (PlayerFunctions.Player.GetMoney(player) < amount) { player.sendNotification("Ошибка/n~r~У вас недостаточно денег."); return; } if (house.Money + amount > HOUSE_MONEY_LIMIT) { player.sendNotification("Ошибка/n~r~Достигнут лимит наличия денег в доме."); return; } PlayerFunctions.Player.ChangeMoney(player, -amount); house.ChangeMoney(amount); player.sendNotification(string.Format("Успешно/n~g~Вы положили ${0:n0} в сейф.", amount)); player.triggerEvent("HouseUpdateSafe", API.toJson(new { Money = house.Money })); } else { if (house.Money < amount) { player.sendNotification("Ошибка/n~r~В сейфе нет столько денег."); return; } PlayerFunctions.Player.ChangeMoney(player, +amount); house.ChangeMoney(-amount); player.sendNotification(string.Format("Успешно/n~g~Вы взяли ${0:n0} из сейфа.", amount)); player.triggerEvent("HouseUpdateSafe", API.toJson(new { Money = house.Money })); } break; } case "HouseSell": { if (!player.hasData("InsideHouse_ID")) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("InsideHouse_ID")); if (house == null) { return; } if (house.Owner != player.name) { player.sendNotification("Ошибка/n~r~Это может делать только владелец."); return; } if (house.Money > 0) { player.sendNotification("Ошибка/n~r~Заберите деньги из сейфа перед его продажей."); return; } if (house.Weapons.Count > 0) { player.sendNotification("Ошибка/n~r~Заберите оружие из оружейного шкафчика перед продажей дома."); return; } //if (house.Furnitures.Count > 0) //{ // player.sendNotification("Ошибка/n~r~Продайте мебель перед продажей дома."); // return; //} int price = (int)Math.Round(house.Price * 0.8); PlayerFunctions.Player.ChangeMoney(player, +price); house.RemoveAllPlayers(); house.SetOwner(null); player.sendNotification(string.Format("Успешно/n~g~Дом продан за ${0:n0}.", price)); break; } case "HouseLeave": { if (!player.hasData("InsideHouse_ID")) { return; } House house = Houses.FirstOrDefault(h => h.ID == player.getData("InsideHouse_ID")); if (house == null) { return; } house.RemovePlayer(player); break; } } }