예제 #1
0
        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 (house.Price > API.exported.MoneyAPI.GetMoney(player))
                {
                    player.sendNotification("Error", "~r~You can't afford this house.");
                    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);

                API.exported.MoneyAPI.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.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 (API.exported.MoneyAPI.GetMoney(player) < amount)
                    {
                        player.sendNotification("Error", "~r~You don't have that much money.");
                        return;
                    }

                    if (house.Money + amount > HOUSE_MONEY_LIMIT)
                    {
                        player.sendNotification("Error", "~r~House money limit reached.");
                        return;
                    }

                    API.exported.MoneyAPI.ChangeMoney(player, -amount);

                    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;
                    }

                    API.exported.MoneyAPI.ChangeMoney(player, amount);

                    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);
                API.exported.MoneyAPI.ChangeMoney(player, price);

                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;
            }
            }
        }
예제 #2
0
        public void House_Init()
        {
            DimensionID = 1;

            // load settings
            if (API.hasSetting("houseDirName"))
            {
                HOUSE_SAVE_DIR = API.getSetting <string>("houseDirName");
            }

            HOUSE_SAVE_DIR = API.getResourceFolder() + Path.DirectorySeparatorChar + HOUSE_SAVE_DIR;
            if (!Directory.Exists(HOUSE_SAVE_DIR))
            {
                Directory.CreateDirectory(HOUSE_SAVE_DIR);
            }

            if (API.hasSetting("playerHouseLimit"))
            {
                PLAYER_HOUSE_LIMIT = API.getSetting <int>("playerHouseLimit");
            }
            if (API.hasSetting("houseMoneyLimit"))
            {
                HOUSE_MONEY_LIMIT = API.getSetting <int>("houseMoneyLimit");
            }
            if (API.hasSetting("houseWeaponLimit"))
            {
                HOUSE_WEAPON_LIMIT = API.getSetting <int>("houseWeaponLimit");
            }
            if (API.hasSetting("houseFurnitureLimit"))
            {
                HOUSE_FURNITURE_LIMIT = API.getSetting <int>("houseFurnitureLimit");
            }
            if (API.hasSetting("resetDimensionOnDeath"))
            {
                RESET_DIMENSION_ON_DEATH = API.getSetting <bool>("resetDimensionOnDeath");
            }
            if (API.hasSetting("saveInterval"))
            {
                SAVE_INTERVAL = API.getSetting <int>("saveInterval");
            }

            API.consoleOutput("-> Player House Limit: {0}", ((PLAYER_HOUSE_LIMIT == 0) ? "Disabled" : PLAYER_HOUSE_LIMIT.ToString()));
            API.consoleOutput("-> House Safe Limit: ${0:n0}", HOUSE_MONEY_LIMIT);
            API.consoleOutput("-> House Weapon Limit: {0}", ((HOUSE_WEAPON_LIMIT == 0) ? "Disabled" : HOUSE_WEAPON_LIMIT.ToString()));
            API.consoleOutput("-> House Furniture Limit: {0}", ((HOUSE_FURNITURE_LIMIT == 0) ? "Disabled" : HOUSE_FURNITURE_LIMIT.ToString()));
            API.consoleOutput("-> Dimension Reset On Death: {0}", ((RESET_DIMENSION_ON_DEATH) ? "Enabled" : "Disabled"));
            API.consoleOutput("-> Save Interval: {0}", TimeSpan.FromSeconds(SAVE_INTERVAL).ToString(@"hh\:mm\:ss"));

            // load houses
            foreach (string file in Directory.EnumerateFiles(HOUSE_SAVE_DIR, "*.json"))
            {
                House house = JsonConvert.DeserializeObject <House>(File.ReadAllText(file));
                house.Dimension = DimensionID;
                foreach (HouseFurniture furniture in house.Furnitures)
                {
                    furniture.Create(DimensionID);
                }

                Houses.Add(house);
                DimensionID++;
            }

            API.consoleOutput("Loaded {0} houses.", Houses.Count);
        }