public CacheDictionary <int, int> CompleteDailyQuest(int id) { var aData = CacheSet.DailyQuestTable.GetData(id); PlayerPackageLogic pp = new PlayerPackageLogic(); pp.SetUser(m_UserId); if (!pp.CheckPackageSlot(aData.RewardItems)) { return(null); } if (aData == null) { TraceLog.WriteError("DataTable Error: can not find Id:" + id.ToString()); return(null); } if (!m_DailyQuestInfo.TrackingDailyQuests.ContainsKey(id)) { TraceLog.WriteError("You don not have this quest, Id:" + id.ToString()); return(null); } var completedQuest = m_DailyQuestInfo.TrackingDailyQuests[id]; if (completedQuest.Progress < completedQuest.RequiredProgress) { TraceLog.WriteError("You have not completed this achievement, Id:" + id.ToString()); return(null); } m_DailyQuestInfo.CompletedDailyQuests.Add(id); m_DailyQuestInfo.TrackingDailyQuests.Remove(id); return(aData.RewardItems); }
public ItemListItem OpenMail(int Id) { if (!m_Mails.Mails.ContainsKey(Id)) { return(null); } if (m_Mails.Mails[Id].ExpireTime < DateTime.UtcNow.Ticks) { return(null); } PlayerPackageLogic pp = new PlayerPackageLogic(); pp.SetUser(m_UserId); ItemListItem reward = new ItemListItem(); reward.Id = m_Mails.Mails[Id].AttachedId; reward.Count = m_Mails.Mails[Id].AttachedCount; if (!pp.CheckPackageSlot(new Dictionary <int, int>() { { reward.Id, reward.Count } })) { return(null); } m_Mails.Mails.Remove(Id); return(reward); }
public List <PBDropInfo> EnterInstance(int instanceId) { if (m_InstanceDrop != null) { CacheSet.InstanceDropCache.Delete(m_InstanceDrop); } List <PBDropInfo> dropInfo; m_InstanceDrop = new PlayerInstanceDrop(); m_InstanceDrop.UserId = m_UserId; m_InstanceDrop.InstanceId = instanceId; DTInstance instanceData = CacheSet.InstanceTable.GetData(instanceId); m_InstanceDrop.ChestList.AddRange(instanceData.InInstanceChests); m_InstanceDrop.DropList = GenerateDropList(instanceId, false, out dropInfo); PlayerPackageLogic pp = new PlayerPackageLogic(); pp.SetUser(m_UserId); if (!pp.CheckPackageSlot(m_InstanceDrop.DropList)) { return(null); } CacheSet.InstanceDropCache.Add(m_InstanceDrop); return(dropInfo); //RedisConnectionPool.Process(c => c.Expire("$Genesis.GameServer.LobbyServer.PlayerInstanceDrop", 3600)); }
public override bool TakeAction() { PlayerChanceLogic pc = new PlayerChanceLogic(); pc.SetUserAndType(m_UserId, m_RequestPacket.ChanceType); PlayerPackageLogic pp = new PlayerPackageLogic(); pp.SetUser(m_UserId); Dictionary <int, int> dropDict = new Dictionary <int, int>(); if (!pp.CheckPackageSlot(dropDict)) { ErrorCode = (int)ErrorType.PackageSlotFull; ErrorInfo = "package is full"; return(false); } var items = pc.OpenAllChance(); if (items == null) { ErrorCode = (int)ErrorType.CannotOpenChance; ErrorInfo = "you can not open this"; return(false); } m_ResponsePacket.ChanceType = m_RequestPacket.ChanceType; PlayerLogic p = new PlayerLogic(); p.SetUser(m_UserId); m_ResponsePacket.PlayerInfo = new PBPlayerInfo() { Id = p.MyPlayer.Id, Coin = p.MyPlayer.Coin, Money = p.MyPlayer.Money, }; foreach (var iteminfo in items) { m_ResponsePacket.OpenedIndex.Add(iteminfo.Key); m_ResponsePacket.OpenedGoodInfo.Add(new PBItemInfo() { Type = iteminfo.Value.ItemId, Count = iteminfo.Value.ItemCount }); GetItems(iteminfo.Value); } ReceiveItemMethodType type = m_RequestPacket.ChanceType == (int)ChanceType.Money ? ReceiveItemMethodType.CoinChance : ReceiveItemMethodType.MoneyChance; PBReceivedItems receivedItems; pp.GetItems(m_DropItems, type, out receivedItems); m_ResponsePacket.ReceivedItems = receivedItems; return(true); }
public CacheDictionary <int, int> CompleteAchievement(int id, out TrackingAchievement newAchievement) { newAchievement = null; var aData = CacheSet.AchievementTable.GetData(id); PlayerPackageLogic pp = new PlayerPackageLogic(); pp.SetUser(m_UserId); if (!pp.CheckPackageSlot(aData.RewardItems)) { return(null); } if (aData == null) { TraceLog.WriteError("DataTable Error: can not find Id:" + id.ToString()); return(null); } if (!m_AchievementInfo.TrackingAchievements.ContainsKey(aData.AchievementType)) { TraceLog.WriteError("You don not have this achievement, Id:" + id.ToString()); return(null); } var completedAchievement = m_AchievementInfo.TrackingAchievements[aData.AchievementType]; if (completedAchievement.Id != id) { TraceLog.WriteError("You don not have this achievement, Id:" + id.ToString()); return(null); } if (completedAchievement.Progress < completedAchievement.RequiredProgress) { TraceLog.WriteError("You have not completed this achievement, Id:" + id.ToString()); return(null); } m_AchievementInfo.CompletedAchievements.Add(id); var nextAchievementData = CacheSet.AchievementTable.GetData(a => a.PreAchievementId == id); m_AchievementInfo.TrackingAchievements.Remove(aData.AchievementType); if (nextAchievementData != null) { TrackingAchievement ta = new TrackingAchievement() { Id = nextAchievementData.Id, RequiredProgress = nextAchievementData.TargetProgressCount, }; ta.Params.AddRange(nextAchievementData.Params); m_AchievementIniters[nextAchievementData.AchievementType](ta); newAchievement = ta; m_AchievementInfo.TrackingAchievements.Add(nextAchievementData.AchievementType, ta); } return(aData.RewardItems); }
public override bool TakeAction() { PlayerChanceLogic pc = new PlayerChanceLogic(); pc.SetUserAndType(m_UserId, m_RequestPacket.ChanceType); PlayerPackageLogic pp = new PlayerPackageLogic(); pp.SetUser(m_UserId); Dictionary <int, int> dropDict = new Dictionary <int, int>(); if (!pp.CheckPackageSlot(dropDict)) { ErrorCode = (int)ErrorType.PackageSlotFull; ErrorInfo = "package is full"; return(false); } var item = pc.OpenChance(m_RequestPacket.OpenIndex, m_RequestPacket.UseFree); if (item == null) { ErrorCode = (int)ErrorType.CannotOpenChance; ErrorInfo = "you can not open this"; return(false); } m_ResponsePacket.ChanceType = m_RequestPacket.ChanceType; m_ResponsePacket.OpenedIndex = m_RequestPacket.OpenIndex; m_ResponsePacket.OpenedGoodInfo = new PBItemInfo() { Type = item.ItemId, Count = item.ItemCount }; PlayerLogic p = new PlayerLogic(); p.SetUser(m_UserId); m_ResponsePacket.PlayerInfo = new PBPlayerInfo() { Id = p.MyPlayer.Id, Coin = p.MyPlayer.Coin, Money = p.MyPlayer.Money, }; m_ResponsePacket.NextFreeTime = pc.MyChance.NextFreeTime; GetReward(item); return(true); }
public override bool TakeAction() { PlayerFoundryLogic pf = new PlayerFoundryLogic(); pf.SetUser(m_UserId); int[] drops = GameConsts.Foundry.FoundryRewardDropPackageId[m_RequestPacket.Level]; RandomDropLogic random = RandomDropLogic.GetInstance(); CacheDictionary <int, int> dropDict = new CacheDictionary <int, int>(); foreach (int dropId in drops) { DTDrop dataRow = CacheSet.DropTable.GetData(dropId); random.GetDropDict(dataRow, dropDict); } PlayerPackageLogic pp = new PlayerPackageLogic(); pp.SetUser(m_UserId); if (!pp.CheckPackageSlot(dropDict)) { ErrorCode = (int)ErrorType.PackageSlotFull; ErrorInfo = "package is full"; return(false); } if (!pf.GetReward(m_RequestPacket.Level)) { ErrorCode = (int)ErrorType.RequireNotMet; ErrorInfo = "You can not get this reward"; return(false); } PBReceivedItems receivedItems; pp.GetItems(dropDict, ReceiveItemMethodType.GearFoundry, out receivedItems); m_ResponsePacket.ReceivedItems = receivedItems; m_ResponsePacket.RewardFlags.AddRange(pf.MyFoundry.CanReceiveRewards); return(true); }
public override bool TakeAction() { InstanceProgressLogic ip = new InstanceProgressLogic(); ip.SetUser(m_UserId); if (!(ip.GetInstanceProgress()).ContainsKey(m_RequestPacket.InstanceId)) { ErrorCode = (int)ErrorType.RequireNotMet; ErrorInfo = "You have not passed this instance"; return(false); } PlayerInstanceLogic pi = new PlayerInstanceLogic(); pi.SetUser(m_UserId); CacheDictionary <int, int> dropItems = new CacheDictionary <int, int>(); for (int i = 0; i < m_RequestPacket.Count; i++) { PBInstanceDrop instanceDrop = new PBInstanceDrop(); List <PBDropInfo> dropList = new List <PBDropInfo>(); List <PBDropInfo> dropPack; var dropDict = pi.GenerateDropList(m_RequestPacket.InstanceId, true, out dropPack); GameUtils.MergeItemDict(dropItems, dropDict); foreach (var dropItem in dropDict) { PBDropInfo item = new PBDropInfo() { DropId = dropItem.Key, DropCount = dropItem.Value }; instanceDrop.Items.Add(item); } m_ResponsePacket.Drops.Add(instanceDrop); } PlayerPackageLogic pp = new PlayerPackageLogic(); pp.SetUser(m_UserId); if (!pp.CheckPackageSlot(dropItems)) { ErrorCode = (int)ErrorType.PackageSlotFull; ErrorInfo = "Package full"; return(false); } PlayerLogic p = new PlayerLogic(); p.SetUser(m_UserId); int energy = PlayerInstanceLogic.GetInstanceEnergy(m_RequestPacket.InstanceId); long nextRecoverTime; if (!p.DeductEnergy(energy * m_RequestPacket.Count, out nextRecoverTime)) { ErrorCode = (int)ErrorType.RequireNotMet; ErrorInfo = "You have not enough energy"; return(false); } PBReceivedItems receivedItems; pp.GetItems(dropItems, ReceiveItemMethodType.CompleteInstance, out receivedItems); m_ResponsePacket.ReceivedItems = receivedItems; DTInstance instanceData = PlayerInstanceLogic.GetInstanceData(m_RequestPacket.InstanceId); p.AddCoin(instanceData.Coin * m_RequestPacket.Count); p.AddExp(instanceData.PlayerExp * m_RequestPacket.Count); m_ResponsePacket.Count = m_RequestPacket.Count; m_ResponsePacket.InstanceId = m_RequestPacket.InstanceId; m_ResponsePacket.PlayerInfo = new PBPlayerInfo() { Id = m_UserId, Coin = p.MyPlayer.Coin, Exp = p.MyPlayer.Exp, Level = p.MyPlayer.Level, Energy = p.MyPlayer.Energy, NextEnergyRecoveryTime = nextRecoverTime }; HeroTeamLogic heroTeam = new HeroTeamLogic(); heroTeam.SetUser(m_UserId); PlayerHeroLogic playerHero = new PlayerHeroLogic(); playerHero.SetUser(m_UserId); foreach (int heroId in heroTeam.MyHeroTeam.Team) { if (heroId == 0) { continue; } //playerHero.SetHero(heroId).AddExp(instanceData.HeroExp); m_ResponsePacket.LobbyHeroInfo.Add(new PBLobbyHeroInfo() { Type = heroId, Exp = playerHero.MyHeros.Heros[heroId].HeroExp, Level = playerHero.MyHeros.Heros[heroId].HeroLv }); } PlayerDailyQuestLogic.GetInstance(m_UserId).UpdateDailyQuest(DailyQuestType.CleanOutInstance, m_RequestPacket.Count); 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); }
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); }