Exemple #1
0
 private void GetItems(DropItem item)
 {
     if (PlayerPackageLogic.IsItem(item.ItemId))
     {
         var itemData = CacheSet.ItemTable.GetData(item.ItemId);
         if (itemData == null)
         {
             TraceLog.WriteError("Wrong Item ID in drop table : " + item.ItemId.ToString());
         }
         if (itemData.FunctionId == (int)ItemFunctions.AddHero)
         {
             PlayerHeroLogic ph = new PlayerHeroLogic();
             ph.SetUser(m_UserId);
             int          heroId = int.Parse(itemData.FunctionParams);
             ItemListItem piece  = ph.AddNewHero(heroId);
             if (piece == null)
             {
                 Hero newHero = ph.MyHeros.Heros[heroId];
                 m_ResponsePacket.LobbyHeroInfo.Add(new PBLobbyHeroInfo()
                 {
                     Type               = newHero.HeroType,
                     Level              = newHero.HeroLv,
                     Exp                = newHero.HeroExp,
                     ElevationLevel     = newHero.ElevationLevel,
                     ConsciousnessLevel = newHero.ConsciousnessLevel,
                     StarLevel          = newHero.HeroStarLevel
                 });
                 return;
             }
             else
             {
                 AddItem(piece.Id, piece.Count);
                 return;
             }
         }
         AddItem(item.ItemId, item.ItemCount);
         return;
     }
     AddItem(item.ItemId, item.ItemCount);
     return;
 }
Exemple #2
0
        public void ParseRow(string[] rowData)
        {
            int index = 0;

            index++;
            Id = int.Parse(rowData[index++]);
            index++;
            RepeatCount = int.Parse(rowData[index++]);

            while (index < rowData.Length)
            {
                DropItem di = new DropItem();
                di.ItemId = int.Parse(rowData[index++]);
                if (di.ItemId == 0)
                {
                    break;
                }
                di.ItemCount  = int.Parse(rowData[index++]);
                di.ItemWeight = int.Parse(rowData[index++]);
                DropList.Add(di);
            }
            DTDropCache.AddOrUpdate(Id.ToString(), this);
        }
Exemple #3
0
        private void GetReward(DropItem item)
        {
            PlayerPackageLogic pp = new PlayerPackageLogic();

            pp.SetUser(m_UserId);
            var type = m_RequestPacket.ChanceType == (int)ChanceType.Money ? ReceiveItemMethodType.MoneyChance : ReceiveItemMethodType.CoinChance;

            if (PlayerPackageLogic.IsItem(item.ItemId))
            {
                m_ResponsePacket.ReceivedItems = new PBReceivedItems();
                var itemData = CacheSet.ItemTable.GetData(item.ItemId);
                if (itemData.FunctionId == (int)ItemFunctions.AddHero)
                {
                    PlayerHeroLogic ph = new PlayerHeroLogic();
                    ph.SetUser(m_UserId);
                    int          heroId = int.Parse(itemData.FunctionParams);
                    ItemListItem piece  = ph.AddNewHero(heroId, type);
                    if (piece == null)
                    {
                        Hero newHero = ph.MyHeros.Heros[heroId];
                        m_ResponsePacket.LobbyHeroInfo = new PBLobbyHeroInfo()
                        {
                            Type               = newHero.HeroType,
                            Level              = newHero.HeroLv,
                            Exp                = newHero.HeroExp,
                            ElevationLevel     = newHero.ElevationLevel,
                            ConsciousnessLevel = newHero.ConsciousnessLevel,
                            StarLevel          = newHero.HeroStarLevel
                        };
                    }
                    else
                    {
                        pp.AddInventory(piece);
                        m_ResponsePacket.ReceivedItems.ItemInfo.Add(new PBItemInfo()
                        {
                            Type  = piece.Id,
                            Count = pp.MyPackage.Inventories[piece.Id]
                        });
                    }
                }
                else
                {
                    pp.AddInventory(new ItemListItem()
                    {
                        Id = item.ItemId, Count = item.ItemCount
                    });
                    m_ResponsePacket.ReceivedItems.ItemInfo.Add(new PBItemInfo()
                    {
                        Type  = item.ItemId,
                        Count = pp.MyPackage.Inventories[item.ItemId]
                    });
                }
            }
            else
            {
                Dictionary <int, int> itemDict = new Dictionary <int, int>();
                itemDict.Add(item.ItemId, item.ItemCount);
                PBReceivedItems receivedItems;
                pp.GetItems(itemDict, type, out receivedItems);
                m_ResponsePacket.ReceivedItems = receivedItems;
            }
        }
Exemple #4
0
        public DropItem OpenChance(int index, bool isFree)
        {
            if (isFree)
            {
                if (DateTime.UtcNow.Ticks < m_Chance.NextFreeTime)
                {
                    return(null);
                }
                switch (m_Type)
                {
                case ChanceType.Coin:
                    PlayerCoinChance coinChance = m_Chance as PlayerCoinChance;
                    if (coinChance.TotalFreeCount >= GameConsts.Chance.MaxFreeCountForCoinChance)
                    {
                        return(null);
                    }
                    coinChance.TotalFreeCount += 1;
                    m_Chance.NextFreeTime      = DateTime.UtcNow.AddSeconds(GameConsts.Chance.FreeCoinChanceCDSeconds).Ticks;
                    break;

                case ChanceType.Money:
                    m_Chance.NextFreeTime = DateTime.UtcNow.AddSeconds(GameConsts.Chance.FreeMoneyChanceCDSeconds).Ticks;
                    PlayerAchievementLogic.GetInstance(m_UserId).UpdateAchievement(AchievementType.OpenedMoneyChanceCount, 1);
                    break;

                default:
                    return(null);
                }
            }
            else
            {
                var         dataRow = CacheSet.ChanceCostTable.GetData(m_Chance.OpenedChanceRewards.Count + 1);
                PlayerLogic p       = new PlayerLogic();
                p.SetUser(m_UserId);
                switch (m_Type)
                {
                case ChanceType.Coin:
                    if (!p.DeductCoin(dataRow.CoinCost))
                    {
                        return(null);
                    }
                    break;

                case ChanceType.Money:
                    if (!p.DeductMoney(dataRow.MoneyCost))
                    {
                        return(null);
                    }
                    PlayerAchievementLogic.GetInstance(m_UserId).UpdateAchievement(AchievementType.OpenedMoneyChanceCount, 1);
                    break;

                default:
                    return(null);
                }
            }

            RandomDropLogic random = RandomDropLogic.GetInstance();
            int             id     = random.OpenChanceBox(m_Chance.UnopenedChanceRewards);
            DropItem        di     = m_Chance.UnopenedChanceRewards[id];

            try
            {
                m_Chance.OpenedChanceRewards.Add(index, di.Clone() as DropItem);
            }
            catch
            {
                return(null);
            }
            m_Chance.UnopenedChanceRewards.Remove(id);
            return(di);
        }