public void RemovePlayerFromHouseList(Client player) { if (player.hasData("InsideHouse_ID")) { House house = Houses.FirstOrDefault(h => h.ID == player.getData("InsideHouse_ID")); if (house == null) { return; } house.RemovePlayer(player, false); } }
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("Error", "~r~Apenas o proprietário pode acessar esta casa."); } } 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~Esta casa já tem dono."); return; } if (house.Price > player.getMoney()) { player.sendNotification("Error", "~r~Você não tem dinheiro suficiente."); return; } if (PLAYER_HOUSE_LIMIT > 0 && Houses.Count(h => h.Owner == player.name) >= PLAYER_HOUSE_LIMIT) { player.sendNotification("Error", "~r~Você não pode ter mais casas."); return; } player.sendNotification("House Purchased", "~g~Parabéns, você comprou a casa!"); house.SetLock(true); house.SetOwner(player); house.SendPlayer(player); player.giveMoney(-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("Error", "~r~Apenas o proprietário pode acessar o menu da casa."); 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("Error", "~r~Apenas o dono pode fazer isto."); return; } string new_name = args[0].ToString(); if (new_name.Length > 32) { player.sendNotification("Error", "~r~O nome da casa não pode ter mais que 32 caracteres."); return; } house.SetName(new_name); player.sendNotification("Success", string.Format("~g~Nome da casa alterado para: ~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("Error", "~r~Apenas o dono pode fazer isto."); return; } bool new_state = Convert.ToBoolean(args[0]); house.SetLock(new_state); player.sendNotification("Success", ((new_state) ? "~g~A casa agora está trancada." : "~g~A casa agora está destrancada.")); 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("Error", "~r~Apenas o dono pode fazer isto."); return; } int type = Convert.ToInt32(args[0]); int amount = 0; if (!int.TryParse(args[1].ToString(), out amount)) { player.sendNotification("Error", "~r~Quantidade inválida."); return; } if (amount < 1) { return; } if (type == 0) { if (player.getMoney() < amount) { player.sendNotification("Error", "~r~Você não tem dinheiro suficiente."); return; } if (house.Money + amount > HOUSE_MONEY_LIMIT) { player.sendNotification("Error", "~r~O cofre está cheio."); return; } player.giveMoney(-amount); house.ChangeMoney(amount); player.sendNotification("Success", string.Format("~g~Você colocou ${0:n0} no cofre.", amount)); player.triggerEvent("HouseUpdateSafe", API.toJson(new { Money = house.Money })); } else { if (house.Money < amount) { player.sendNotification("Error", "~r~O cofre não possui esta quantia."); return; } player.giveMoney(amount); house.ChangeMoney(-amount); player.sendNotification("Success", string.Format("~g~Você tirou ${0:n0} do cofre.", 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("Error", "~r~Apenas o dono pode fazer isto."); return; } if (house.Money > 0) { player.sendNotification("Error", "~r~Esvazie o cofre antes de vender."); return; } if (house.Weapons.Count > 0) { player.sendNotification("Error", "~r~Esvazie o armário de armas antes de vender."); return; } if (house.Furnitures.Count > 0) { player.sendNotification("Error", "~r~Venda os móveis antes de vender."); return; } int price = (int)Math.Round(house.Price * 0.8); player.giveMoney(price); house.RemoveAllPlayers(); house.SetOwner(null); player.sendNotification("Success", string.Format("~g~Casa vendida por ${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; } } }