Esempio n. 1
0
        public void PurchaseTattooEvent(Client player, int tattooZone, int tattooIndex)
        {
            int           sex        = player.GetData(EntityData.PLAYER_SEX);
            int           businessId = player.GetData(EntityData.PLAYER_BUSINESS_ENTERED);
            BusinessModel business   = GetBusinessById(businessId);

            // Getting the tattoo and its price
            BusinessTattooModel businessTattoo = GetBusinessZoneTattoos(sex, tattooZone).ElementAt(tattooIndex);
            int playerMoney = player.GetSharedData(EntityData.PLAYER_MONEY);
            int price       = (int)Math.Round(business.multiplier * businessTattoo.price);

            if (price <= playerMoney)
            {
                TattooModel tattoo = new TattooModel();
                {
                    tattoo.player  = player.GetData(EntityData.PLAYER_SQL_ID);
                    tattoo.slot    = tattooZone;
                    tattoo.library = businessTattoo.library;
                    tattoo.hash    = sex == Constants.SEX_MALE ? businessTattoo.maleHash : businessTattoo.femaleHash;
                }

                Task.Factory.StartNew(() => {
                    NAPI.Task.Run(() =>
                    {
                        if (Database.AddTattoo(tattoo) == true)
                        {
                            // We add the tattoo to the list
                            Globals.tattooList.Add(tattoo);

                            // Substract player 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 -= businessTattoo.price;
                                Database.UpdateBusiness(business);
                            }

                            // Confirmation message sent to the player
                            string playerMessage = string.Format(InfoRes.tattoo_purchased, price);
                            player.SendChatMessage(Constants.COLOR_INFO + playerMessage);

                            // Reload client tattoo list
                            player.TriggerEvent("addPurchasedTattoo", NAPI.Util.ToJson(tattoo));
                        }
                        else
                        {
                            // Player already had that tattoo
                            player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.tattoo_duplicated);
                        }
                    });
                });
            }
            else
            {
                player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_enough_money);
            }
        }
Esempio n. 2
0
        public void PurchaseTattooEvent(Client player, int tattooZone, int tattooIndex)
        {
            int           sex        = NAPI.Data.GetEntitySharedData(player, EntityData.PLAYER_SEX);
            int           businessId = NAPI.Data.GetEntityData(player, EntityData.PLAYER_BUSINESS_ENTERED);
            BusinessModel business   = GetBusinessById(businessId);

            // Getting the tattoo and its price
            BusinessTattooModel businessTattoo = GetBusinessZoneTattoos(sex, tattooZone).ElementAt(tattooIndex);
            int playerMoney = NAPI.Data.GetEntitySharedData(player, EntityData.PLAYER_MONEY);
            int price       = (int)Math.Round(business.multiplier * businessTattoo.price);

            if (price <= playerMoney)
            {
                TattooModel tattoo = new TattooModel();
                tattoo.player  = NAPI.Data.GetEntityData(player, EntityData.PLAYER_SQL_ID);
                tattoo.slot    = tattooZone;
                tattoo.library = businessTattoo.library;
                tattoo.hash    = sex == Constants.SEX_MALE ? businessTattoo.maleHash : businessTattoo.femaleHash;

                Task.Factory.StartNew(() => {
                    if (Database.AddTattoo(tattoo) == true)
                    {
                        // We add the tattoo to the list
                        Globals.tattooList.Add(tattoo);

                        // Substract player money
                        NAPI.Data.SetEntitySharedData(player, 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 -= businessTattoo.price;
                            Database.UpdateBusiness(business);
                        }

                        // Confirmation message sent to the player
                        String playerMessage = String.Format(Messages.INF_TATTOO_PURCHASED, price);
                        NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_INFO + playerMessage);

                        // Reload client tattoo list
                        NAPI.ClientEvent.TriggerClientEvent(player, "addPurchasedTattoo", NAPI.Util.ToJson(tattoo));
                    }
                    else
                    {
                        // Player already had that tattoo
                        NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_ERROR + Messages.ERR_TATTOO_DUPLICATED);
                    }
                });
            }
            else
            {
                NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_ERROR + Messages.ERR_PLAYER_NOT_ENOUGH_MONEY);
            }
        }
Esempio n. 3
0
        public void PurchaseTattooEvent(Client player, params object[] arguments)
        {
            // Obtenemos los datos del tatuaje
            int tattooZone  = Int32.Parse(arguments[0].ToString());
            int tattooIndex = Int32.Parse(arguments[1].ToString());

            // Obtenemos los datos del negocio y sexo
            int           sex        = NAPI.Data.GetEntitySharedData(player, EntityData.PLAYER_SEX);
            int           businessId = NAPI.Data.GetEntityData(player, EntityData.PLAYER_BUSINESS_ENTERED);
            BusinessModel business   = GetBusinessById(businessId);

            // Obtenemos el tatuaje seleccionado y su precio
            BusinessTattooModel businessTattoo = GetBusinessZoneTattoos(sex, tattooZone).ElementAt(tattooIndex);
            int playerMoney = NAPI.Data.GetEntitySharedData(player, EntityData.PLAYER_MONEY);
            int price       = (int)Math.Round(business.multiplier * businessTattoo.price);

            if (price <= playerMoney)
            {
                // Creamos el modelo de datos
                TattooModel tattoo = new TattooModel();
                tattoo.player  = NAPI.Data.GetEntityData(player, EntityData.PLAYER_SQL_ID);
                tattoo.slot    = tattooZone;
                tattoo.library = businessTattoo.library;
                tattoo.hash    = sex == Constants.SEX_MALE ? businessTattoo.maleHash : businessTattoo.femaleHash;

                // Intentamos insertar el tatuaje en la base de datos
                bool inserted = Database.AddTattoo(tattoo);

                if (inserted)
                {
                    // Añadimos el tatuaje a la lista
                    Globals.tattooList.Add(tattoo);

                    // Restamos el dinero al jugador
                    NAPI.Data.SetEntitySharedData(player, EntityData.PLAYER_MONEY, playerMoney - price);

                    // Si el negocio tiene dueño, le damos el dinero y descontamos los productos
                    if (business.owner != String.Empty)
                    {
                        business.funds    += price;
                        business.products -= businessTattoo.price;
                        Database.UpdateBusiness(business);
                    }

                    // Avisamos al jugador
                    String playerMessage = String.Format(Messages.INF_TATTOO_PURCHASED, price);
                    NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_INFO + playerMessage);

                    // Recargamos la lista de tatuajes
                    NAPI.ClientEvent.TriggerClientEvent(player, "addPurchasedTattoo", NAPI.Util.ToJson(tattoo));
                }
                else
                {
                    // El jugador ya tenía ese tatuaje
                    NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_ERROR + Messages.ERR_TATTOO_DUPLICATED);
                }
            }
            else
            {
                NAPI.Chat.SendChatMessageToPlayer(player, Constants.COLOR_ERROR + Messages.ERR_PLAYER_NOT_ENOUGH_MONEY);
            }
        }