Ejemplo n.º 1
0
        private static void _Progress(Dictionary <int, int> gacha_results, List <Models.Character> characters, int group_id, GameService.ItemList item = null, bool isBonus = false)
        {
            var gacha_table = ACDC.Gacha_TableData.Values.Where(x => x.GroupId == group_id && characters.IsAvailable(x.ItemID)).ToList();

            if (gacha_table.Count == 0)
            {
                return;
            }

            int rate = MathHelpers.GetRandomInt(gacha_table.Sum(x => x.get_rate));
            int gacha_item_id = 0, gacha_item_count = 0;

            foreach (var gacha_data in gacha_table)
            {
                if (rate < gacha_data.get_rate)
                {
                    gacha_item_id    = gacha_data.ItemID;
                    gacha_item_count = MathHelpers.GetRandomInt(gacha_data.Count_min, gacha_data.Count_max + 1);
                    break;
                }
                rate -= gacha_data.get_rate;
            }

            if (gacha_item_id == 0)
            {
                return;
            }

            if (!gacha_results.ContainsKey(gacha_item_id))
            {
                gacha_results.Add(gacha_item_id, gacha_item_count);
            }
            else
            {
                gacha_results[gacha_item_id] += gacha_item_count;
            }

            if ((GameItemType)ACDC.GameItemData[gacha_item_id].Item_Type == GameItemType.Character)
            {
                characters.Add(new Models.Character()
                {
                    character_type = ACDC.GameItemData[gacha_item_id].LinkId
                });
            }

            if (item != null)
            {
                item.Items.Add(new GameService.ItemInfo()
                {
                    ItemId = gacha_item_id, ItemCount = gacha_item_count, IsBonus = isBonus
                });
            }
        }
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);
        }
Ejemplo n.º 3
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);
        }