Exemple #1
0
        private async Task <GachaItem> DoGachaAsync(GachaPool.PoolName poolName, int FixedRarity = 0)
        {
            var index  = random_.Next(100);
            var rarity = FixedRarity;

            if (rarity == 0)
            {
                for (int i = 0; i < AllPools[poolName].RarityDistribution.Length; ++i)
                {
                    if (index < AllPools[poolName].RarityDistribution[i])
                    {
                        rarity = i + 1;
                        break;
                    }
                }
            }
            var allItems = await AllItemsAsync();

            var itemsInPool = allItems.Where(r => r.Name == poolName && r.Item.Rarity == rarity).OrderBy(_ => random_.Next());
            int totalWeight = itemsInPool.Sum(p => p.Weight);
            int itemIndex   = random_.Next(totalWeight) + 1; // non-zero
            int current     = 0;

            foreach (var item in itemsInPool)
            {
                current += item.Weight;
                if (current >= itemIndex)
                {
                    return(item.Item);
                }
            }
            // Only possible if no item has the given rarity at this pool.
            throw new ApplicationException("Item exhausted! Bad pool config!");
        }
Exemple #2
0
        private bool ValidatePool(GachaPool.PoolName name)
        {
            if (!AllPools.ContainsKey(name))
            {
                return(false);
            }
            var pool = AllPools[name];

            if (pool.StartTime.HasValue && DateTime.Now < pool.StartTime)
            {
                return(false);
            }
            if (pool.EndTime.HasValue && DateTime.Now > pool.EndTime)
            {
                return(false);
            }
            return(true);
        }
Exemple #3
0
 public PoolCountTitleCondition(GachaPool.PoolName poolName, int count, UserQuest.UserProfession profession)
 {
     Count    = count;
     Title    = profession;
     PoolName = poolName;
 }