public static async Task <(ErrorCode, Goods, CharacterInfo)> UpgradePowerLevel(Session session, int character_id)
        {
            var character_data = ACDC.CharacterData[character_id];

            if (character_data == null || character_data == default(JCharacterData))
            {
                Log.Information($"UpgradePowerLevel cannot find character_id:{character_id}, user_name:{session.user_name}");
                return(ErrorCode.WrongParam, null, null);
            }

            var           level_table    = character_data.LevelTable;
            var           goods          = new Goods();
            CharacterInfo character_info = null;

            await using (var mylock = await RedLock.CreateLockAsync($"lock:session:{session.session_id}"))
            {
                await using (var user = await UserCache.GetUser(session.member_no, session.user_no, true, true, false))
                    await using (var character = await CharacterCache.Instance.GetEntity(session.member_no, session.user_no, character_id, true, true, false))
                    {
                        if (character == null || character == default(Models.Character))
                        {
                            Log.Information($"UpgradePowerLevel cannot find character_id:{character_id}, user_name:{session.user_name}");
                            return(ErrorCode.WrongParam, null, null);
                        }

                        JPowerLevel_TableData power_level_data;
                        if (level_table.TryGetValue(character.character_level, out power_level_data) == false)
                        {
                            return(ErrorCode.OverLimit, null, null);
                        }

                        if (character.piece < power_level_data.Req_Piece)
                        {
                            return(ErrorCode.NotEnough, null, null);
                        }

                        if (Inventory.UseGoods(session, user, power_level_data.Pricetype, power_level_data.Req_PriceValue, new LogReason("S_UPGRADE_SMASHER", character_id.ToString())) == false)
                        {
                            return(ErrorCode.NotEnough, null, null);
                        }

                        character.piece           -= power_level_data.Req_Piece;
                        character.character_level += 1;
                        character.IsDirty          = true;

                        goods.Set(user);

                        character_info = CharacterManager.CreateCharacterInfo(character, character_data);

                        var game_item_data = ACDC.GameItemData.Values.Where(x => x.Item_Type == (int)GameItemType.CharacterPiece && x.LinkId == character_id).FirstOrDefault();
                        var item_id        = game_item_data.id;
                        var item_count     = power_level_data.Req_Piece;
                        _ = LogProxy.writeItemLog(session, game_item_data.Item_Type.ToString(), item_id.ToString(), "y", "", item_count, "", 0, 0, "add", "S_UPGRADE_SMASHER", character_id.ToString(), "").ConfigureAwait(false);
                        _ = LogProxy.writeActionLog(session, "캐릭터", "업그레이드", character.character_type.ToString()).ConfigureAwait(false);

                        History.Info(session.member_no, session.user_no, session.character_no, HistoryLogAction.UseItem, (byte)HistoryLogReason.UpgradePowerLevel, item_id, item_count, "", "");
                    }
            }
            return(ErrorCode.Success, goods, character_info);
        }
Ejemplo n.º 2
0
        public static async Task <bool> Insert(Session session, Models.User user, Models.Character character, int item_id, int item_count, LogReason reason, GameService.ItemList item = null, string sParam1 = "", string sParam2 = "")
        {
            var game_item_data = ACDC.GameItemData[item_id];

            if (game_item_data == null || game_item_data == default(JGameItemData))
            {
                Log.Error($"cannot find item:{item_id}, user_name:{session.user_name}");
                return(false);
            }

            switch ((GameItemType)game_item_data.Item_Type)
            {
            case GameItemType.Goods:
            {
                user[item_id] += item_count;

                user.IsDirty = true;

                if (item != null)
                {
                    item.Items.Add(new GameService.ItemInfo()
                        {
                            ItemId = item_id, ItemCount = item_count
                        });
                }
            }
            break;

            case GameItemType.Medal_Charging:
            {
                user.medal_charge      = (int)MedalChargeConst.MaxCharge;
                user.medal_charge_time = DateTime.UtcNow;

                user.IsDirty = true;

                if (item != null)
                {
                    item.Items.Add(new GameService.ItemInfo()
                        {
                            ItemId = item_id, ItemCount = item_count
                        });
                }
            }
            break;

            case GameItemType.Character:
            {
                if (await CharacterManager.InsertCharacter(session.member_no, session.user_no, session.user_name, session.player_id, game_item_data.LinkId) == null)
                {
                    return(false);
                }

                if (item != null)
                {
                    item.Items.Add(new GameService.ItemInfo()
                        {
                            ItemId = item_id, ItemCount = item_count
                        });
                }

                _ = LogProxy.writeActionLog(session, "캐릭터", "획득", game_item_data.LinkId.ToString()).ConfigureAwait(false);
            }
            break;

            case GameItemType.CharacterPiece:
            {
                if (await CharacterManager.AddCharacterPiece(session, character, game_item_data.LinkId, item_count) == false)
                {
                    return(false);
                }

                if (item != null)
                {
                    item.Items.Add(new GameService.ItemInfo()
                        {
                            ItemId = item_id, ItemCount = item_count
                        });
                }

                _ = LogProxy.writeActionLog(session, "캐릭터", "조각획득", game_item_data.LinkId.ToString()).ConfigureAwait(false);
            }
            break;

            case GameItemType.Gacha:
            {
                if (await GachaBox.Progress(session, user, character, game_item_data, item, reason) == false)
                {
                    return(false);
                }
            }
            break;

            default:
                return(false);
            }

            await MissionManager.OnTrigger(session, MissionUserAction.GetItem, item_id, item_count);

            //History.Info(session.member_no, session.user_no, session.character_no, HistoryLogAction.GainItem, (byte)reason, (int)item_id, (int)item_count, sParam1, sParam2);

            if (reason != null)
            {
                if ((GameItemType)game_item_data.Item_Type == GameItemType.Goods)
                {
                    _ = LogProxy.writeResourceLog(session, reason.paid, item_id.ToString(), item_count, 0, user[item_id], "add", reason.reason, reason.sub_reason).ConfigureAwait(false);
                }
                else
                {
                    _ = LogProxy.writeItemLog(session, game_item_data.Item_Type.ToString(), item_id.ToString(), "y", "", item_count, "", 0, 0, "add", reason.reason, reason.sub_reason, "").ConfigureAwait(false);
                }
            }

            return(true);
        }