Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public override bool TakeAction()
        {
            Transaction t      = new Transaction();
            PlayerLogic player = new PlayerLogic();

            player.SetUser(m_UserId);
            PlayerPackageLogic package = new PlayerPackageLogic();

            package.SetUser(m_UserId);
            GearLogic gear = new GearLogic();

            gear.SetGear(m_RequestPacket.GearId[0]);
            int quality = CacheSet.GearTable.GetData(gear.MyGear.TypeId).Quality;

            t.DumpEntity(package.MyPackage);
            t.DumpEntity(player.MyPlayer);
            int costCoin = gear.GetComposeCost(quality);

            if (quality == (int)GearQuality.Orange)
            {
                t.RollBack();
                ErrorCode = (int)ErrorType.CannotOpenChance;
                ErrorInfo = "wrong gearId";
                return(false);
            }

            if (!player.DeductCoin(costCoin))
            {
                t.RollBack();
                ErrorCode = (int)ErrorType.RequireNotMet;
                ErrorInfo = "You don't have enough Coin";
                return(false);
            }
            foreach (int gearId in m_RequestPacket.GearId)
            {
                gear.SetGear(gearId);
                if (quality != CacheSet.GearTable.GetData(gear.MyGear.TypeId).Quality)
                {
                    t.RollBack();
                    ErrorCode = (int)ErrorType.CannotOpenChance;
                    ErrorInfo = "wrong gearId";
                    return(false);
                }
                if (!package.DeductGear(gearId))
                {
                    t.RollBack();
                    ErrorCode = (int)ErrorType.RequireNotMet;
                    ErrorInfo = "You don't have enough Gear";
                    return(false);
                }
                gear.RemoveGear();
            }
            int position = 0;

            if (m_RequestPacket.HasItemId && m_RequestPacket.ItemId != 0)
            {
                if (!package.DeductInventory(new ItemListItem()
                {
                    Id = m_RequestPacket.ItemId, Count = 1
                }))
                {
                    t.RollBack();
                    ErrorCode = (int)ErrorType.RequireNotMet;
                    ErrorInfo = "You don't have enough Item";
                    return(false);
                }
                position = int.Parse(CacheSet.ItemTable.GetData(m_RequestPacket.ItemId).FunctionParams);
                m_ResponsePacket.ItemInfo = new PBItemInfo()
                {
                    Type = m_RequestPacket.ItemId, Count = package.MyPackage.Inventories[m_RequestPacket.ItemId]
                };
            }
            m_ResponsePacket.PlayerInfo = new PBPlayerInfo()
            {
                Id   = player.MyPlayer.Id,
                Coin = player.MyPlayer.Coin
            };
            m_ResponsePacket.RemovedGears.AddRange(m_RequestPacket.GearId);
            Gears newGear = gear.GetComposeResult(quality, position, m_UserId);

            if (newGear == null)
            {
                return(true);
            }
            package.AddGear(newGear.Id, newGear.TypeId);
            m_ResponsePacket.NewGear = new PBGearInfo()
            {
                Id    = newGear.Id,
                Type  = newGear.TypeId,
                Level = newGear.Level
            };
            return(true);
        }
Exemplo n.º 3
0
        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);
        }