public static RewardChessField GetRewardChessField(int userId, ChessFieldColor color, Random r) { RewardChessField field = new RewardChessField(); field.Color = color; field.IsOpened = false; field.IsFree = false; field.ParentId = -1; field.RewardCoin = 0; field.RewardMoney = 0; if (color != ChessFieldColor.Empty) { PlayerLogic p = new PlayerLogic(); p.SetUser(userId); double baseRewardCoin = GetBaseRewardCoin(p.MyPlayer.Level); field.RewardCoin = r.Next((int)Math.Round(baseRewardCoin * 0.5), (int)Math.Round(baseRewardCoin * 1.5)); } if (color == ChessFieldColor.RewardGray) { RandomDropLogic rd = RandomDropLogic.GetInstance(); var dropDict = new CacheDictionary <int, int>(); if (r.Next(100) < GameConsts.PlayerChess.TopRewardRate) { var dropData = CacheSet.DropTable.GetData(GameConsts.PlayerChess.TopRewardDropId); rd.GetDropDict(dropData, dropDict); } else { var dropData = CacheSet.DropTable.GetData(GameConsts.PlayerChess.MidRewardDropId); rd.GetDropDict(dropData, dropDict); } if (dropDict.ContainsKey((int)GiftItemType.Money)) { field.RewardMoney += dropDict[(int)GiftItemType.Money]; dropDict.Remove((int)GiftItemType.Money); } foreach (var kv in dropDict) { field.RewardItems.Add(kv); } } return(field); }
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); }
private bool RefreshData(PlayerChessLogic playerChess) { int costFieldCount = 0; int freeFieldCount = 0; int totalCostFreeCount = 0; Transaction t = new Transaction(); t.DumpEntity(playerChess.MyChess); PlayerPackageLogic package = new PlayerPackageLogic(); package.SetUser(m_UserId); foreach (var field in m_RequestPacket.ModifiedChessField) { var oldField = playerChess.MyChess.ChessBoard[field.Index]; int oldColor = oldField.Color == ChessFieldColor.Empty || oldField.Color == ChessFieldColor.EmptyGray || oldField.Color == ChessFieldColor.RewardGray ? (int)ChessFieldColor.EmptyGray : (int)oldField.Color; if (field.Color != oldColor) { t.RollBack(); ErrorCode = (int)ErrorType.CannotOpenChance; ErrorInfo = "illegal params"; return(false); } if (field.Color == (int)ChessFieldColor.EmptyGray) { RewardChessField oldRewardField = oldField as RewardChessField; if (!oldRewardField.IsOpened && field.IsOpened) { if (!oldRewardField.IsFree) { if (m_RequestPacket.ModifiedChessField.Count == 1) { costFieldCount += 1; } else { freeFieldCount += 1; } } else { freeFieldCount += 1; } m_GotCoin += oldRewardField.RewardCoin; m_GotMoney += oldRewardField.RewardMoney; m_GotStarEnergy += oldRewardField.RewardStarEnergy; foreach (var reward in oldRewardField.RewardItems) { if (m_GotItems.ContainsKey(reward.Key)) { m_GotItems[reward.Key] += reward.Value; } else { m_GotItems.Add(reward); } } PlayerPackageLogic pp = new PlayerPackageLogic(); pp.SetUser(m_UserId); if (!pp.CheckPackageSlot(m_GotItems)) { ErrorCode = (int)ErrorType.PackageSlotFull; ErrorInfo = "item count if full"; return(false); } playerChess.DeductOpenCount(); } oldRewardField.IsFree = field.IsFree; oldRewardField.IsOpened = field.IsOpened; oldRewardField.ParentId = field.Parent; } else { BattleChessField oldBattleField = oldField as BattleChessField; if (!oldBattleField.IsOpened && field.IsOpened) { m_ResponsePacket.FreeCount = oldBattleField.Count; costFieldCount += 1; oldBattleField.IsOpened = field.IsOpened; PlayerDailyQuestLogic.GetInstance(m_UserId).UpdateDailyQuest(DailyQuestType.WinTurnOverChessBattle, 1); } else { if (field.FreeCount < 0 || field.FreeCount > oldBattleField.Count) { ErrorCode = (int)ErrorType.CannotOpenChance; ErrorInfo = "illegal params"; return(false); } totalCostFreeCount += oldBattleField.Count - field.FreeCount; oldBattleField.Count = field.FreeCount; } oldBattleField.ChildrenId.AddRange(field.Children); } } if (freeFieldCount != totalCostFreeCount) { t.RollBack(); ErrorCode = (int)ErrorType.CannotOpenChance; ErrorInfo = "illegal params"; return(false); } if (costFieldCount > 1) { t.RollBack(); ErrorCode = (int)ErrorType.CannotOpenChance; ErrorInfo = "illegal params"; return(false); } playerChess.MyChess.Count -= costFieldCount; return(true); }