Пример #1
0
        public async Task <CharacterCurrency> DropQuantity(CharacterCurrency item)
        {
            var characterCurrency = await _repo.Get((int)item.CharacterCurrencyId);

            if (characterCurrency == null)
            {
                return(characterCurrency);
            }

            if (characterCurrency.Amount >= item.Amount)
            {
                characterCurrency.Amount -= item.Amount;
            }

            try
            {
                await _repo.Update(characterCurrency);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(characterCurrency);
        }
Пример #2
0
        public async Task <CharacterCurrency> Update(CharacterCurrency item)
        {
            var characterCurrency = await _repo.Get((int)item.CharacterCurrencyId);

            if (characterCurrency == null)
            {
                return(characterCurrency);
            }

            characterCurrency.Amount      = item.Amount;
            characterCurrency.SortOrder   = item.SortOrder;
            characterCurrency.Name        = item.Name;
            characterCurrency.BaseUnit    = item.BaseUnit;
            characterCurrency.WeightValue = item.WeightValue;
            characterCurrency.WeightLabel = item.WeightLabel;
            //characterCurrency.CurrencyTypeId = item.CurrencyTypeId;
            //characterCurrency.CharacterId = item.CharacterId;
            try
            {
                await _repo.Update(characterCurrency);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(characterCurrency);
        }
        private void GiveGuildBattleRewardTo(int winnerGuildId)
        {
            GuildWarMapInfo mapInfo = CurrentMapInfo as GuildWarMapInfo;
            string          mailTitle;
            string          mailContent;
            int             rewardGold;

            CurrencyAmount[] rewardCurrencies;
            ItemAmount[]     rewardItems;
            Mail             tempMail;

            foreach (IPlayerCharacterData participant in ServerUserHandlers.GetPlayerCharacters())
            {
                if (participant.GuildId == winnerGuildId)
                {
                    mailTitle        = mapInfo.winMailTitle;
                    mailContent      = mapInfo.winMailContent;
                    rewardGold       = mapInfo.winRewardGold;
                    rewardCurrencies = mapInfo.winRewardCurrencies;
                    rewardItems      = mapInfo.winRewardItems;
                }
                else
                {
                    mailTitle        = mapInfo.participantMailTitle;
                    mailContent      = mapInfo.participantMailContent;
                    rewardGold       = mapInfo.participantRewardGold;
                    rewardCurrencies = mapInfo.participantRewardCurrencies;
                    rewardItems      = mapInfo.participantRewardItems;
                }
                tempMail = new Mail()
                {
                    SenderId   = guildWarMailSenderId,
                    SenderName = guildWarMailSenderName,
                    ReceiverId = participant.UserId,
                    Title      = mailTitle,
                    Content    = mailContent,
                    Gold       = rewardGold,
                };
                foreach (CurrencyAmount currencyAmount in rewardCurrencies)
                {
                    if (currencyAmount.currency == null)
                    {
                        continue;
                    }
                    tempMail.Currencies.Add(CharacterCurrency.Create(currencyAmount.currency.DataId, currencyAmount.amount));
                }
                foreach (ItemAmount itemAmount in rewardItems)
                {
                    if (itemAmount.item == null)
                    {
                        continue;
                    }
                    tempMail.Items.Add(CharacterItem.Create(itemAmount.item, 1, itemAmount.amount));
                }
                ServerMailHandlers.SendMail(tempMail);
            }
        }
 private bool ReadCharacterCurrency(SqliteDataReader reader, out CharacterCurrency result)
 {
     if (reader.Read())
     {
         result        = new CharacterCurrency();
         result.dataId = reader.GetInt32(0);
         result.amount = reader.GetInt32(1);
         return(true);
     }
     result = CharacterCurrency.Empty;
     return(false);
 }
Пример #5
0
        public async Task <CharacterCurrency> Create(CharacterCurrency item)
        {
            var characterCurrency = new CharacterCurrency
            {
                Name           = item.Name,
                Amount         = item.Amount,
                Command        = item.Command,
                BaseUnit       = item.BaseUnit,
                WeightValue    = item.WeightValue,
                WeightLabel    = item.WeightLabel,
                SortOrder      = item.SortOrder,
                IsDeleted      = false,
                CurrencyTypeId = item.CurrencyTypeId,
                CharacterId    = item.CharacterId,
            };

            return(await _repo.Add(characterCurrency));
        }
 public void CreateCharacterCurrency(SqliteTransaction transaction, int idx, string characterId, CharacterCurrency characterCurrency)
 {
     ExecuteNonQuery(transaction, "INSERT INTO charactercurrency (id, idx, characterId, dataId, amount) VALUES (@id, @idx, @characterId, @dataId, @amount)",
                     new SqliteParameter("@id", characterId + "_" + idx),
                     new SqliteParameter("@idx", idx),
                     new SqliteParameter("@characterId", characterId),
                     new SqliteParameter("@dataId", characterCurrency.dataId),
                     new SqliteParameter("@amount", characterCurrency.amount));
 }
Пример #7
0
 public async UniTask CreateCharacterCurrency(MySqlConnection connection, MySqlTransaction transaction, int idx, string characterId, CharacterCurrency characterCurrency)
 {
     await ExecuteNonQuery(connection, transaction, "INSERT INTO charactercurrency (id, idx, characterId, dataId, amount) VALUES (@id, @idx, @characterId, @dataId, @amount)",
                           new MySqlParameter("@id", characterId + "_" + idx),
                           new MySqlParameter("@idx", idx),
                           new MySqlParameter("@characterId", characterId),
                           new MySqlParameter("@dataId", characterCurrency.dataId),
                           new MySqlParameter("@amount", characterCurrency.amount));
 }
Пример #8
0
        public async UniTaskVoid HandleRequestCashShopBuy(
            RequestHandlerData requestHandler, RequestCashShopBuyMessage request,
            RequestProceedResultDelegate <ResponseCashShopBuyMessage> result)
        {
#if UNITY_STANDALONE && !CLIENT_BUILD
            IPlayerCharacterData playerCharacter;
            if (!GameInstance.ServerUserHandlers.TryGetPlayerCharacter(requestHandler.ConnectionId, out playerCharacter))
            {
                result.InvokeError(new ResponseCashShopBuyMessage()
                {
                    message = UITextKeys.UI_ERROR_NOT_LOGGED_IN,
                });
                return;
            }

            if (request.amount <= 0)
            {
                result.InvokeError(new ResponseCashShopBuyMessage()
                {
                    message = UITextKeys.UI_ERROR_INVALID_DATA,
                });
                return;
            }

            CashShopItem cashShopItem;
            if (!GameInstance.CashShopItems.TryGetValue(request.dataId, out cashShopItem))
            {
                result.InvokeError(new ResponseCashShopBuyMessage()
                {
                    message = UITextKeys.UI_ERROR_ITEM_NOT_FOUND,
                });
                return;
            }

            if ((request.currencyType == CashShopItemCurrencyType.CASH && cashShopItem.SellPriceCash <= 0) ||
                (request.currencyType == CashShopItemCurrencyType.GOLD && cashShopItem.SellPriceGold <= 0))
            {
                result.InvokeError(new ResponseCashShopBuyMessage()
                {
                    message = UITextKeys.UI_ERROR_INVALID_ITEM_DATA,
                });
                return;
            }

            int characterGold       = playerCharacter.Gold;
            int userCash            = playerCharacter.UserCash;
            int priceGold           = 0;
            int priceCash           = 0;
            int changeCharacterGold = 0;
            int changeUserCash      = 0;

            // Validate cash
            if (request.currencyType == CashShopItemCurrencyType.CASH)
            {
                priceCash = cashShopItem.SellPriceCash * request.amount;
                if (userCash < priceCash)
                {
                    result.InvokeError(new ResponseCashShopBuyMessage()
                    {
                        message = UITextKeys.UI_ERROR_NOT_ENOUGH_CASH,
                    });
                    return;
                }
                changeUserCash -= priceCash;
            }

            // Validate gold
            if (request.currencyType == CashShopItemCurrencyType.GOLD)
            {
                priceGold = cashShopItem.SellPriceGold * request.amount;
                if (characterGold < priceGold)
                {
                    result.InvokeError(new ResponseCashShopBuyMessage()
                    {
                        message = UITextKeys.UI_ERROR_NOT_ENOUGH_GOLD,
                    });
                    return;
                }
                changeCharacterGold -= priceGold;
            }

            // Increase gold
            if (cashShopItem.ReceiveGold > 0)
            {
                changeCharacterGold += cashShopItem.ReceiveGold * request.amount;
            }

            // Increase items
            List <RewardedItem> rewardItems = new List <RewardedItem>();
            if (cashShopItem.ReceiveItems != null &&
                cashShopItem.ReceiveItems.Length > 0)
            {
                foreach (ItemAmount itemAmount in cashShopItem.ReceiveItems)
                {
                    for (int i = 0; i < request.amount; ++i)
                    {
                        rewardItems.Add(new RewardedItem()
                        {
                            item       = itemAmount.item,
                            level      = 1,
                            amount     = itemAmount.amount,
                            randomSeed = (short)Random.Range(short.MinValue, short.MaxValue),
                        });
                    }
                }
                if (playerCharacter.IncreasingItemsWillOverwhelming(rewardItems))
                {
                    result.InvokeError(new ResponseCashShopBuyMessage()
                    {
                        message = UITextKeys.UI_ERROR_WILL_OVERWHELMING,
                    });
                    return;
                }
            }

            // Increase custom currencies
            List <CharacterCurrency> customCurrencies = new List <CharacterCurrency>();
            if (cashShopItem.ReceiveCurrencies != null &&
                cashShopItem.ReceiveCurrencies.Length > 0)
            {
                foreach (CurrencyAmount currencyAmount in cashShopItem.ReceiveCurrencies)
                {
                    for (int i = 0; i < request.amount; ++i)
                    {
                        customCurrencies.Add(CharacterCurrency.Create(currencyAmount.currency, currencyAmount.amount));
                    }
                }
            }

            // Update currency
            characterGold += changeCharacterGold;
            if (request.currencyType == CashShopItemCurrencyType.CASH)
            {
                AsyncResponseData <CashResp> changeCashResp = await DbServiceClient.ChangeCashAsync(new ChangeCashReq()
                {
                    UserId       = playerCharacter.UserId,
                    ChangeAmount = -priceCash
                });

                if (!changeCashResp.IsSuccess)
                {
                    result.InvokeError(new ResponseCashShopBuyMessage()
                    {
                        message = UITextKeys.UI_ERROR_INTERNAL_SERVER_ERROR,
                    });
                    return;
                }
                userCash = changeCashResp.Response.Cash;
            }
            playerCharacter.Gold     = characterGold;
            playerCharacter.UserCash = userCash;
            playerCharacter.IncreaseItems(rewardItems);
            playerCharacter.IncreaseCurrencies(customCurrencies);
            playerCharacter.FillEmptySlots();

            // Response to client
            result.InvokeSuccess(new ResponseCashShopBuyMessage()
            {
                dataId      = request.dataId,
                rewardGold  = cashShopItem.ReceiveGold,
                rewardItems = rewardItems,
            });
#endif
        }