Esempio n. 1
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"));

            // 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);
        }
Esempio n. 2
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.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;
            }
            }
        }
Esempio n. 3
0
        public void HouseWeapons_EventTrigger(Client player, string event_name, params object[] args)
        {
            switch (event_name)
            {
            case "HousePutGun":
            {
                if (!player.hasData("InsideHouse_ID"))
                {
                    return;
                }

                House house = Main.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;
                }

                WeaponHash weapon = player.currentWeapon;
                if (WeaponBlacklist.Contains(weapon))
                {
                    player.sendNotification("Error", "~r~Não pode armazenar esta arma.");
                    return;
                }

                if (Main.HOUSE_WEAPON_LIMIT > 0 && house.Weapons.Count >= Main.HOUSE_WEAPON_LIMIT)
                {
                    player.sendNotification("Error", "~r~Limite de armas atingido.");
                    return;
                }

                house.Weapons.Add(new HouseWeapon(weapon, player.getWeaponAmmo(weapon), player.getWeaponTint(weapon), player.GetAllWeaponComponents(weapon)));
                house.Save();

                player.sendNotification("Success", string.Format("~g~Guardou um(a) {0} com {1:n0} balas.", weapon, player.getWeaponAmmo(weapon)));
                player.removeWeapon(weapon);

                player.triggerEvent("HouseUpdateWeapons", API.toJson(house.Weapons));
                break;
            }

            case "HouseTakeGun":
            {
                if (!player.hasData("InsideHouse_ID") || args.Length < 1)
                {
                    return;
                }

                House house = Main.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 idx = Convert.ToInt32(args[0]);
                if (idx < 0 || idx >= house.Weapons.Count)
                {
                    return;
                }

                HouseWeapon weapon = house.Weapons[idx];
                house.Weapons.RemoveAt(idx);
                house.Save();

                player.giveWeapon(weapon.Hash, weapon.Ammo, true, false);
                foreach (WeaponComponent comp in weapon.Components)
                {
                    player.setWeaponComponent(weapon.Hash, comp);
                }
                player.setWeaponTint(weapon.Hash, weapon.Tint);

                player.sendNotification("Success", string.Format("~g~Retirou um(a) {0} com {1:n0} balas.", weapon.Hash, weapon.Ammo));

                player.triggerEvent("HouseUpdateWeapons", API.toJson(house.Weapons));
                break;
            }
            }
        }