public Dictionary <int, DropItem> OpenAllChance() { Dictionary <int, DropItem> dropItems = new Dictionary <int, DropItem>(); var dataRow = CacheSet.ChanceCostTable.GetData(m_Chance.OpenedChanceRewards.Count + 1); if (dataRow == null) { return(null); } PlayerLogic p = new PlayerLogic(); p.SetUser(m_UserId); switch (m_Type) { case ChanceType.Coin: if (!p.DeductCoin(dataRow.CoinCostAll)) { return(null); } AnnouncementLogic.PushOpenTenCoinChanceAnnouncement(m_UserId); break; case ChanceType.Money: if (!p.DeductMoney(dataRow.MoneyCostAll)) { return(null); } AnnouncementLogic.PushOpenTenMoneyChanceAnnouncement(m_UserId); PlayerAchievementLogic.GetInstance(m_UserId).UpdateAchievement(AchievementType.OpenedMoneyChanceCount, m_Chance.UnopenedChanceRewards.Count); break; default: return(null); } int i = 0; foreach (var item in m_Chance.UnopenedChanceRewards) { while (m_Chance.OpenedChanceRewards.ContainsKey(i)) { i++; } m_Chance.OpenedChanceRewards.Add(i, item.Value.Clone() as DropItem); dropItems.Add(i, item.Value); i++; } m_Chance.UnopenedChanceRewards.Clear(); return(dropItems); }
public bool ResetRewards(bool IsFree) { RandomDropLogic random = RandomDropLogic.GetInstance(); PlayerLogic player = new PlayerLogic(); player.SetUser(m_UserId); m_Chance.OpenedChanceRewards.Clear(); m_Chance.UnopenedChanceRewards.Clear(); switch (m_Type) { case ChanceType.Coin: if (!IsFree) { if (!player.DeductCoin(GameConfigs.GetInt("ChanceRefreshCost0"))) { return(false); } } for (int i = GameConsts.Chance.MinCoinChancePackId; i <= GameConsts.Chance.MaxCoinChancePackId; i++) { m_Chance.UnopenedChanceRewards.Add(i, random.GetChanceRewards(i)); } m_Chance.TotalFreeCount = 0; break; case ChanceType.Money: if (!IsFree) { if (!player.DeductMoney(GameConfigs.GetInt("ChanceRefreshCost1"))) { return(false); } } for (int i = GameConsts.Chance.MinMoneyChancePackId; i <= GameConsts.Chance.MaxMoneyChancePackId; i++) { m_Chance.UnopenedChanceRewards.Add(i - GameConsts.Chance.MaxCoinChancePackId, random.GetChanceRewards(i)); } m_Chance.TotalFreeCount = 0; break; default: break; } m_Chance.OpenedChanceRewards.Clear(); return(true); }
public bool PurchaseItem(int index, int type, int count) { var itemData = m_Shop.ShopItems[index]; if (itemData.ItemType != type || itemData.ItemCount != count || itemData.PurchasedTimes >= 1) { return(false); } PlayerLogic player = new PlayerLogic(); player.SetUser(m_UserId); switch ((GiftItemType)itemData.CurrencyType) { case GiftItemType.Money: if (!player.DeductMoney(itemData.OriginalPrice)) { return(false); } break; case GiftItemType.Coin: if (!player.DeductCoin(itemData.OriginalPrice)) { return(false); } break; case GiftItemType.Spirit: if (!player.DeductSpirit(itemData.OriginalPrice)) { return(false); } break; default: break; } m_Shop.ShopItems[index].PurchasedTimes += 1; return(true); }
public override bool TakeAction() { PlayerVipShopLogic pds = new PlayerVipShopLogic(); pds.SetUser(m_UserId); PlayerLogic p = new PlayerLogic(); p.SetUser(m_UserId); if (!p.DeductMoney(GameConfigs.GetInt("Vip_Shop_Refresh_Cost", 200))) { ErrorCode = (int)ErrorType.RequireNotMet; ErrorInfo = "You have not enough money."; return(false); } pds.ResetShopItems(); var playerShopInfo = pds.GetShopInfo(); foreach (var shopItem in playerShopInfo.ShopItems) { m_ResponsePacket.ShopItems.Add(new PBShopItem() { TypeId = shopItem.ItemType, Count = shopItem.ItemCount, Currency = shopItem.CurrencyType, PurchasedTimes = shopItem.PurchasedTimes, MaxPurchasedTimes = 1, OriginalPrice = shopItem.OriginalPrice, DiscountedPrice = shopItem.DiscountedPrice, }); } m_ResponsePacket.Me = new PBPlayerInfo() { Id = p.MyPlayer.Id, Money = p.MyPlayer.Money }; return(true); }
public override bool TakeAction() { PlayerMeridianLogic playerMeridian = new PlayerMeridianLogic(); playerMeridian.SetUser(m_UserId); PlayerLogic player = new PlayerLogic(); player.SetUser(m_UserId); DTMeridian starData = CacheSet.MeridianTable.GetData(m_RequestPacket.StarId); if (starData == null) { ErrorCode = (int)ErrorType.CannotOpenChance; ErrorInfo = "wrong star Id"; return(false); } if (!player.DeductStarEnergy(starData.CostMeridianEnergy)) { if (!player.DeductMoney(starData.CostMoney)) { ErrorCode = (int)ErrorType.RequireNotMet; ErrorInfo = "have not enough energy or money"; return(false); } } if (!playerMeridian.OpenStar(m_RequestPacket.StarId, starData.Type)) { ErrorCode = (int)ErrorType.RequireNotMet; ErrorInfo = "you can not open this Star yet"; return(false); } player.AddCoin(starData.RewardCoin); player.AddMoney(starData.RewardMoney); m_ResponsePacket.PlayerInfo = new PBPlayerInfo() { Id = m_UserId, Coin = player.MyPlayer.Coin, Money = player.MyPlayer.Money, MeridianEnergy = player.MyPlayer.StarEnergy }; Dictionary <int, int> dropItem = new Dictionary <int, int>(); dropItem.Add(starData.RewardId, starData.RewardCount); PlayerPackageLogic playerPackage = new PlayerPackageLogic(); playerPackage.SetUser(m_UserId); PBReceivedItems receivedItems; playerPackage.GetItems(dropItem, ReceiveItemMethodType.None, out receivedItems); foreach (var gear in receivedItems.GearInfo) { m_ResponsePacket.GearInfo.Add(gear); } foreach (var inventory in receivedItems.ItemInfo) { m_ResponsePacket.ItemInfo.Add(inventory); } foreach (var meridian in playerMeridian.MyMeridian.UnlockedMeridians) { PBMeridianInfo meridianInfo = new PBMeridianInfo() { Id = meridian.Key }; meridianInfo.UnlockedStars.AddRange(meridian.Value.UnlockedStars); m_ResponsePacket.MeridianInfo.Add(meridianInfo); } return(true); }
public Dictionary <int, int> BombAll(out int coin, out int money, out int starEnergy) { coin = 0; money = 0; starEnergy = 0; Dictionary <int, int> rewardItems = new Dictionary <int, int>(); m_Chess.Count = 0; int totalCost = 0; int OpenedCount = 0; foreach (var chessField in m_Chess.ChessBoard) { if ((chessField.Color == ChessFieldColor.EmptyGray || chessField.Color == ChessFieldColor.RewardGray || chessField.Color == ChessFieldColor.Empty)) { if (!chessField.IsOpened) { totalCost += GetOpenCost(OpenedCount++); } } } PlayerLogic p = new PlayerLogic(); p.SetUser(m_UserId); if (!p.DeductMoney(totalCost)) { return(null); } foreach (var chessField in m_Chess.ChessBoard) { if ((chessField.Color == ChessFieldColor.EmptyGray || chessField.Color == ChessFieldColor.RewardGray || chessField.Color == ChessFieldColor.Empty)) { if (!chessField.IsOpened) { RewardChessField rewardField = chessField as RewardChessField; foreach (var reward in rewardField.RewardItems) { if (rewardItems.ContainsKey(reward.Key)) { rewardItems[reward.Key] += reward.Value; } else { rewardItems.Add(reward.Key, reward.Value); } } } } } PlayerPackageLogic pp = new PlayerPackageLogic(); pp.SetUser(m_UserId); pp.CheckPackageSlot(rewardItems); foreach (var chessField in m_Chess.ChessBoard) { if ((chessField.Color == ChessFieldColor.EmptyGray || chessField.Color == ChessFieldColor.RewardGray || chessField.Color == ChessFieldColor.Empty)) { if (!chessField.IsOpened) { RewardChessField rewardField = chessField as RewardChessField; coin += rewardField.RewardCoin; money += rewardField.RewardMoney; starEnergy += rewardField.RewardStarEnergy; rewardField.IsOpened = true; rewardField.ParentId = -1; } } else { BattleChessField battleField = chessField as BattleChessField; battleField.ChildrenId = new CacheList <int>(); } } return(rewardItems); }
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); }