public override bool TakeAction() { PlayerChessLogic playerChess = new PlayerChessLogic(); playerChess.SetUser(m_UserId); Transaction t = new Transaction(); t.DumpEntity(playerChess.MyChess); if (playerChess.MyChess.HP.ContainsKey(playerChess.MyChess.MyTeam[0]) && playerChess.MyChess.HP[playerChess.MyChess.MyTeam[0]] == 0) { m_ResponsePacket.Success = false; return(true); } foreach (int heroId in playerChess.MyChess.MyTeam) { if (playerChess.MyChess.HP.ContainsKey(heroId) && playerChess.MyChess.HP[heroId] == 0) { playerChess.MyChess.MyTeam.Remove(heroId); } } if (playerChess.MyChess.MyTeam.Count == 0) { t.RollBack(); m_ResponsePacket.Success = false; return(true); } m_ResponsePacket.HeroTeam = new PBHeroTeamInfo(); m_ResponsePacket.HeroTeam.HeroType.AddRange(playerChess.MyChess.MyTeam); m_ResponsePacket.Success = true; m_ResponsePacket.InstanceTypeId = 1; return(true); }
public override bool TakeAction() { var allActivities = CacheSet.ActivityTable.GetAllData(); PlayerLogic p = new PlayerLogic(); p.SetUser(m_UserId); foreach (var activity in allActivities) { PBActivityInfo activityInfo = new PBActivityInfo(); activityInfo.Id = activity.Id; activityInfo.Status = LobbyServerUtils.GetActivityStatus(activity, p.MyPlayer.Level); if (activityInfo.Status == (int)ActivityStatusType.Hidden) { continue; } switch ((ActivityType)activity.Id) { case ActivityType.TurnOverChess: PlayerChessLogic pc = new PlayerChessLogic(); pc.SetUser(m_UserId); activityInfo.Progress = pc.MyChess.Count == 0 ? 0 : 1; activityInfo.CountLimit = 1; break; case ActivityType.OfflineArena: PlayerArenaLogic pa = new PlayerArenaLogic(); pa.SetUser(m_UserId); activityInfo.Progress = pa.MyArena.ChallengeCount; activityInfo.CountLimit = GameConsts.Arena.DailyChallengeCount; break; case ActivityType.GearFoundry: PlayerFoundryLogic pf = new PlayerFoundryLogic(); pf.SetUser(m_UserId); activityInfo.Progress = pf.GetProgress(); activityInfo.CountLimit = 1; break; case ActivityType.CosmosCrack: PlayerCosmosCrackLogic pcc = new PlayerCosmosCrackLogic(); pcc.SetUser(m_UserId); var cosmosInfo = pcc.GetCosmosCrackInstanceInfo(); activityInfo.Progress = cosmosInfo == null ? 0 : cosmosInfo.PassedRoundCount; activityInfo.CountLimit = cosmosInfo == null ? 0 : GameConfigs.GetInt("Cosmos_Crack_Round_Limit", 10); break; default: ErrorCode = (int)ErrorType.CannotOpenChance; ErrorInfo = "invalid activity type"; return(false); } m_ResponsePacket.ActivityInfo.Add(activityInfo); } return(true); }
public override bool TakeAction() { PlayerChessLogic playerChess = new PlayerChessLogic(); playerChess.SetUser(m_UserId); if (!RefreshData(playerChess)) { return(false); } if (m_RequestPacket.HasEnemyAnger) { playerChess.SetEnemyAnger(m_RequestPacket.FieldId, m_RequestPacket.EnemyAnger); } if (m_RequestPacket.EnemyHeroesHP.Count > 0) { playerChess.SetEnemyStatus(m_RequestPacket.FieldId, m_RequestPacket.EnemyHeroesHP); } if (m_RequestPacket.HasMyAnger) { playerChess.SetMyAnger(m_RequestPacket.MyAnger); } if (m_RequestPacket.MyHeroesStatus.Count > 0) { playerChess.SetMyHeroStatus(m_RequestPacket.MyHeroesStatus); m_ResponsePacket.MyHeroesStatus.AddRange(m_RequestPacket.MyHeroesStatus); } if (m_RequestPacket.HasBattleWon && !m_RequestPacket.BattleWon) { m_ResponsePacket.Success = true; return(true); } GetReward(playerChess); PlayerLogic player = new PlayerLogic(); player.SetUser(m_UserId); player.MyPlayer.Money += m_GotMoney; player.MyPlayer.Coin += m_GotCoin; m_ResponsePacket.PlayerInfo = new PBPlayerInfo() { Coin = player.MyPlayer.Coin, Money = player.MyPlayer.Money }; return(true); }
public void GetReward(PlayerChessLogic playerChess) { playerChess.MyChess.GotCoin += m_GotCoin; playerChess.MyChess.GotMoney += m_GotMoney; playerChess.MyChess.GotStarEnergy += m_GotStarEnergy; PlayerPackageLogic package = new PlayerPackageLogic(); package.SetUser(m_UserId); PBReceivedItems receivedItems; package.GetItems(m_GotItems, ReceiveItemMethodType.TurnOverChess, out receivedItems); m_ResponsePacket.ReceivedItems = receivedItems; foreach (var gear in m_ResponsePacket.ReceivedItems.GearInfo) { playerChess.MyChess.GotGears.Add(gear.Id); } foreach (var inventory in m_ResponsePacket.ReceivedItems.ItemInfo) { if (playerChess.MyChess.GotItems.ContainsKey(inventory.Type)) { playerChess.MyChess.GotItems[inventory.Type] += inventory.Count; } else { playerChess.MyChess.GotItems.Add(inventory.Type, inventory.Count); } } foreach (var soul in m_ResponsePacket.ReceivedItems.SoulInfo) { playerChess.MyChess.GotSouls.Add(soul.Id); } foreach (var epigraph in m_ResponsePacket.ReceivedItems.EpigraphInfo) { playerChess.MyChess.GotEpigraphs.Add(epigraph.Type); } m_ResponsePacket.Success = true; m_ResponsePacket.RewardCoins = m_GotCoin; m_ResponsePacket.RewardMoney = m_GotMoney; m_ResponsePacket.RewardStarEnergy = m_GotStarEnergy; m_ResponsePacket.FieldId = m_RequestPacket.FieldId; }
public override bool TakeAction() { PlayerChessLogic playerChess = new PlayerChessLogic(); playerChess.SetUser(m_UserId); if (m_RequestPacket.IsReset) { if (!playerChess.Reset()) { ErrorCode = (int)ErrorType.RequireNotMet; ErrorInfo = "have not token"; return(false); } } if (playerChess.MyChess.LastResetTime < DateTime.Today) { playerChess.ResetToken(); } SetResponseData(playerChess.MyChess); return(true); }
public override bool TakeAction() { PlayerChessLogic playerChess = new PlayerChessLogic(); playerChess.SetUser(m_UserId); PlayerHeroLogic playerHero = new PlayerHeroLogic(); playerHero.SetUser(m_UserId); foreach (int heroId in m_RequestPacket.HeroTeamInfo.HeroType) { playerHero.SetHero(heroId); if (playerHero.GetHeroInfo() == null) { ErrorCode = (int)ErrorType.CannotOpenChance; ErrorInfo = "wrong heroId"; return(false); } } playerChess.ChangeTeam(m_RequestPacket.HeroTeamInfo.HeroType); m_ResponsePacket.HeroTeamInfo = new PBHeroTeamInfo(); m_ResponsePacket.HeroTeamInfo.HeroType.AddRange(m_RequestPacket.HeroTeamInfo.HeroType); return(true); }
public override bool TakeAction() { PlayerChessLogic playerChess = new PlayerChessLogic(); playerChess.SetUser(m_UserId); if (!(playerChess.MyChess.ChessBoard[m_RequestPacket.ChessFieldIndex] is BattleChessField)) { m_ResponsePacket.Success = false; return(true); } BattleChessField targetField = playerChess.MyChess.ChessBoard[m_RequestPacket.ChessFieldIndex] as BattleChessField; m_ResponsePacket.Anger = targetField.EnemyAnger; PlayerLogic player = new PlayerLogic(); player.SetUser(targetField.EnemyPlayerId); m_ResponsePacket.EnemyInfo = new PBPlayerInfo() { Id = player.MyPlayer.Id, Name = player.MyPlayer.Name, Level = player.MyPlayer.Level, Might = player.MyPlayer.Might, }; GearLogic gearlogic = new GearLogic(); int i = 0; foreach (var hero in targetField.EnemyPlayerHeroTeam) { PBLobbyHeroInfo enemyHero = new PBLobbyHeroInfo() { Type = hero.HeroType, Level = hero.HeroLv, StarLevel = hero.HeroStarLevel, ConsciousnessLevel = hero.ConsciousnessLevel, ElevationLevel = hero.ElevationLevel, }; enemyHero.SkillLevels.AddRange(hero.SkillLevels); foreach (var gear in hero.Gears) { gearlogic.SetGear(gear.Value); PBGearInfo enemyGear = new PBGearInfo() { Id = gearlogic.MyGear.Id, Type = gearlogic.MyGear.TypeId, Level = gearlogic.MyGear.Level }; enemyHero.GearInfo.Add(enemyGear); } if (targetField.EnemyHeroHP.Count > i) { PBLobbyHeroStatus enemyStatus = new PBLobbyHeroStatus() { Type = hero.HeroType, CurHP = targetField.EnemyHeroHP[i] }; m_ResponsePacket.HeroesStatus.Add(enemyStatus); } m_ResponsePacket.HeroesInfo.Add(enemyHero); m_ResponsePacket.ChessFieldIndex = m_RequestPacket.ChessFieldIndex; i++; } m_ResponsePacket.Success = true; return(true); }
public override bool TakeAction() { PlayerChessLogic chess = new PlayerChessLogic(); chess.SetUser(m_UserId); int coin; int money; int starEnergy; Dictionary <int, int> rewardItems = chess.BombAll(out coin, out money, out starEnergy); if (rewardItems == null) { ErrorCode = (int)ErrorType.RequireNotMet; ErrorInfo = "Money not enough"; return(false); } chess.MyChess.GotCoin += coin; m_ResponsePacket.RewardCoins = coin; chess.MyChess.GotMoney += money; m_ResponsePacket.RewardMoney = money; chess.MyChess.GotStarEnergy += starEnergy; m_ResponsePacket.RewardStarEnergy = starEnergy; PlayerPackageLogic package = new PlayerPackageLogic(); package.SetUser(m_UserId); PBReceivedItems receivedItems; package.GetItems(rewardItems, ReceiveItemMethodType.TurnOverChess, out receivedItems); m_ResponsePacket.ReceivedItems = receivedItems; foreach (var gear in m_ResponsePacket.ReceivedItems.GearInfo) { chess.MyChess.GotGears.Add(gear.Id); } foreach (var inventory in m_ResponsePacket.ReceivedItems.ItemInfo) { if (chess.MyChess.GotItems.ContainsKey(inventory.Type)) { chess.MyChess.GotItems[inventory.Type] += inventory.Count; } else { chess.MyChess.GotItems.Add(inventory.Type, inventory.Count); } } foreach (var soul in m_ResponsePacket.ReceivedItems.SoulInfo) { chess.MyChess.GotSouls.Add(soul.Id); } foreach (var epigraph in m_ResponsePacket.ReceivedItems.EpigraphInfo) { chess.MyChess.GotEpigraphs.Add(epigraph.Type); } m_ResponsePacket.Success = true; PlayerLogic player = new PlayerLogic(); player.SetUser(m_UserId); player.MyPlayer.Coin += coin; player.MyPlayer.Money += money; m_ResponsePacket.PlayerInfo = new PBPlayerInfo() { Coin = player.MyPlayer.Coin, Money = player.MyPlayer.Money }; return(true); }
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); }