public static void IncreaseBattleScore(Models.Character character, int battle_score)
        {
            if (battle_score < 0)
            {
                character.battle_score += battle_score;
                if (character.battle_score < 0)
                {
                    character.battle_score = 0;
                }
            }
            else
            {
                character.battle_score += battle_score;
            }

            var rank_data = ACDC.RankData.GetRank(character.battle_score);

            if (rank_data != null)
            {
                if (character.rank_level < rank_data.Rank)
                {
                    character.rank_level = rank_data.Rank;
                }
            }
        }
Пример #2
0
        static public async Task <bool> Progress(Session session, Models.User user, Models.Character character, JGameItemData game_item_data, GameService.ItemList item, LogReason reason)
        {
            JGacha_Box_BaseData gacha_base = ACDC.Gacha_Box_BaseData[game_item_data.LinkId];

            var characters = await CharacterCache.Instance.GetEntities(session.member_no, session.user_no, true);

            Dictionary <int, int> gacha_results = new Dictionary <int, int>();

            for (int i = 0; i < gacha_base.reward_item_group_id.Length; ++i)
            {
                _Progress(gacha_results, characters, gacha_base.reward_item_group_id[i], item);
            }

            if (gacha_base.bonus_rate != 0 && MathHelpers.GetRandomInt(100) < gacha_base.bonus_rate)
            {
                _Progress(gacha_results, characters, gacha_base.bonus_group_id, item, true);
            }

            foreach (var gacha_result in gacha_results)
            {
                await Inventory.Insert(session, user, character, gacha_result.Key, gacha_result.Value, reason, null, item?.Items.Where(x => x.ItemId == gacha_result.Key).Count().ToString(), game_item_data.id.ToString());
            }

            return(true);
        }
 public static CharacterInfo CreateCharacterInfo(Models.Character character, JCharacterData character_data)
 {
     return(new CharacterInfo()
     {
         CharacterId = character.character_type,
         CharacterBattleScore = character.battle_score,
         CharacterRank = character.rank_level,
         CharacterLevel = character.character_level,
         CharacterPiece = character.piece,
         StrikingPower = character_data.GetStrikingPower(character.character_level),
         HP = character_data.GetCharacterHp(character.character_level),
         RareLabel = character_data.RareLabel,
         UnionType = character_data.UnionType,
         IsPowerLevelUp = character_data.IsPowerLevelUp(character.character_level, character.piece),
     });
 }
        public static async Task <bool> AddCharacterPiece(Session session, Models.Character character, int character_id, int piece_count)
        {
            var find_character = await CharacterCache.Instance.GetEntity(session.member_no, session.user_no, character_id, true, false, false);

            if (find_character == null || find_character == default(Models.Character))
            {
                Log.Error($"CharacterPiece cannot find character_id:{character_id}, user_name:{session.user_name}");
                return(false);
            }

            if (character.character_no == find_character.character_no)
            {
                character.piece  += piece_count;
                character.IsDirty = true;
            }
            else
            {
                find_character.piece += piece_count;
                await CharacterCache.Instance.UpdateEntity(session.member_no, find_character);
            }
            return(true);
        }
Пример #5
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);
        }