예제 #1
0
        public static int GetClothesProductsPrice(int id, int sex, int type, int slot)
        {
            // Get the products needed for the given clothes
            BusinessClothesModel clothesModel = Constants.BUSINESS_CLOTHES_LIST.Where(c => c.type == type && (c.sex == sex || Constants.SEX_NONE == c.sex) && c.bodyPart == slot && c.clothesId == id).FirstOrDefault();

            return(clothesModel == null ? 0 : clothesModel.products);
        }
예제 #2
0
        public void ClothesItemSelectedEvent(Client player, string clothesJson)
        {
            BusinessClothesModel clothesModel = NAPI.Util.FromJson <BusinessClothesModel>(clothesJson);

            // Get the player's clothes
            int playerId = player.GetData(EntityData.PLAYER_SQL_ID);
            List <ClothesModel> ownedClothes = Globals.GetPlayerClothes(playerId);

            if (ownedClothes.Any(c => c.slot == clothesModel.bodyPart && c.type == clothesModel.type && c.drawable == clothesModel.clothesId && c.texture == clothesModel.texture))
            {
                // The player already has those clothes
                player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_owns_clothes);
                return;
            }

            // Store the data from the purchase
            ClothesModel clothes = new ClothesModel();

            {
                clothes.type     = clothesModel.type;
                clothes.slot     = clothesModel.bodyPart;
                clothes.drawable = clothesModel.clothesId;
                clothes.texture  = clothesModel.texture;
                clothes.player   = playerId;
                clothes.dressed  = true;
            };

            int           businessId = player.GetData(EntityData.PLAYER_BUSINESS_ENTERED);
            int           sex        = player.GetData(EntityData.PLAYER_SEX);
            int           products   = GetClothesProductsPrice(clothesModel.clothesId, sex, clothesModel.type, clothesModel.bodyPart);
            BusinessModel business   = GetBusinessById(businessId);
            int           price      = (int)Math.Round(products * business.multiplier);

            // We check whether the player has enough money
            int playerMoney = player.GetSharedData(EntityData.PLAYER_MONEY);

            if (playerMoney >= price)
            {
                // Substracting paid money
                player.SetSharedData(EntityData.PLAYER_MONEY, playerMoney - price);

                // We substract the product and add funds to the business
                if (business.owner != string.Empty)
                {
                    business.funds    += price;
                    business.products -= products;

                    Task.Factory.StartNew(() => {
                        NAPI.Task.Run(() =>
                        {
                            // Update the business
                            Database.UpdateBusiness(business);
                        });
                    });
                }

                // Undress previous clothes
                Globals.UndressClothes(playerId, clothesModel.type, clothesModel.bodyPart);

                Task.Factory.StartNew(() => {
                    NAPI.Task.Run(() =>
                    {
                        // Storing the clothes into database
                        clothes.id = Database.AddClothes(clothes);
                        Globals.clothesList.Add(clothes);

                        // Confirmation message sent to the player
                        string purchaseMessage = string.Format(InfoRes.business_item_purchased, price);
                        player.SendChatMessage(Constants.COLOR_INFO + purchaseMessage);
                    });
                });
            }
            else
            {
                player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_enough_money);
            }
        }