Ejemplo n.º 1
0
        public Equipment GetQuestRewards()
        {
            int characterId = _characterInfo.GetCharacterId();
            List <QuestEquipmentReward> equipmentRewards = _questAccess.GetQuestEquipmentRewards(characterId);

            if (equipmentRewards != null)
            {
                _questAccess.SetQuestRewarded(characterId);
                if (equipmentRewards.Count > 0)
                {
                    List <int> cumulativeList = new List <int>();
                    cumulativeList.Add(equipmentRewards[0].Chance);
                    for (int i = 1; i < equipmentRewards.Count; i++)
                    {
                        cumulativeList.Add(equipmentRewards[i].Chance + cumulativeList[i - 1]);
                    }
                    Random r            = new Random();
                    int    randomNumber = r.Next(1, 100);
                    for (int i = 0; i < cumulativeList.Count; i++)
                    {
                        if (cumulativeList[i] >= randomNumber)
                        {
                            if (!_inventoryAccess.GetEquipment(characterId).Any(e => e.EquipmentId == equipmentRewards[i].EquipmentId))
                            {
                                _inventoryAccess.AddEquipment(characterId, equipmentRewards[i].EquipmentId);
                                return(equipmentRewards[i].Equipment);
                            }
                            else
                            {
                                _characterManager.AddCoins(200);
                                return(null);
                            }
                        }
                    }
                }
            }
            _characterManager.AddCoins(200);
            return(null);
        }