Example #1
0
        public override bool TakeAction()
        {
            if (m_RequestPacket.TakeOffGearId == 0 && m_RequestPacket.PutOnGearId == 0)
            {
                ErrorCode = (int)ErrorType.CannotOpenChance;
                ErrorInfo = "invalid param";
                return(false);
            }
            PlayerPackageLogic package = new PlayerPackageLogic();

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

            playerHero.SetUser(m_UserId);
            GearType position;

            if (m_RequestPacket.PutOnGearId == 0)
            {
                playerHero.SetHero(m_RequestPacket.TakeOffHeroId);
                gear.SetGear(m_RequestPacket.TakeOffGearId);
                DTGear geardata = CacheSet.GearTable.GetData(gear.MyGear.TypeId);
                position = (GearType)geardata.Type;
                if (playerHero.GetHeroInfo().Gears[position] != m_RequestPacket.TakeOffGearId)
                {
                    ErrorCode = (int)ErrorType.CannotOpenChance;
                    ErrorInfo = "wrong take off gear ID";
                    return(false);
                }
                package.AddGear(m_RequestPacket.TakeOffGearId, gear.MyGear.TypeId);
            }
            else if (m_RequestPacket.TakeOffGearId == 0)
            {
                playerHero.SetHero(m_RequestPacket.PutOnHeroId);
                gear.SetGear(m_RequestPacket.PutOnGearId);
                DTGear geardata = CacheSet.GearTable.GetData(gear.MyGear.TypeId);
                position = (GearType)geardata.Type;
                if (m_RequestPacket.TakeOffHeroId == 0)
                {
                    if (!package.MyPackage.Gears.ContainsKey(m_RequestPacket.PutOnGearId))
                    {
                        ErrorCode = (int)ErrorType.CannotOpenChance;
                        ErrorInfo = "wrong put on gear ID";
                        return(false);
                    }
                    package.DeductGear(m_RequestPacket.PutOnGearId);
                }
                else
                {
                    if (playerHero.MyHeros.Heros[m_RequestPacket.TakeOffHeroId].Gears[position] != m_RequestPacket.PutOnGearId)
                    {
                        ErrorCode = (int)ErrorType.CannotOpenChance;
                        ErrorInfo = "wrong put on gear ID";
                        return(false);
                    }
                    playerHero.SetHero(m_RequestPacket.TakeOffHeroId);
                    playerHero.WearGear(position, 0);
                    playerHero.SetHero(m_RequestPacket.PutOnHeroId);
                }
            }
            else
            {
                playerHero.SetHero(m_RequestPacket.PutOnHeroId);
                gear.SetGear(m_RequestPacket.PutOnGearId);
                DTGear geardata = CacheSet.GearTable.GetData(gear.MyGear.TypeId);
                position = (GearType)geardata.Type;
                if (m_RequestPacket.TakeOffHeroId == 0)
                {
                    if (!package.MyPackage.Gears.ContainsKey(m_RequestPacket.PutOnGearId))
                    {
                        ErrorCode = (int)ErrorType.CannotOpenChance;
                        ErrorInfo = "wrong put on gear ID";
                        return(false);
                    }
                    if (playerHero.MyHeros.Heros[m_RequestPacket.PutOnHeroId].Gears[position] != m_RequestPacket.TakeOffGearId)
                    {
                        ErrorCode = (int)ErrorType.CannotOpenChance;
                        ErrorInfo = "wrong take off gear ID";
                        return(false);
                    }
                    package.DeductGear(m_RequestPacket.PutOnGearId);
                }
                else
                {
                    if (playerHero.MyHeros.Heros[m_RequestPacket.TakeOffHeroId].Gears[position] != m_RequestPacket.PutOnGearId)
                    {
                        ErrorCode = (int)ErrorType.CannotOpenChance;
                        ErrorInfo = "wrong put on gear ID";
                        return(false);
                    }
                    if (playerHero.MyHeros.Heros[m_RequestPacket.PutOnHeroId].Gears[position] != m_RequestPacket.TakeOffGearId)
                    {
                        ErrorCode = (int)ErrorType.CannotOpenChance;
                        ErrorInfo = "wrong take off gear ID";
                        return(false);
                    }
                    playerHero.SetHero(m_RequestPacket.TakeOffHeroId);
                    playerHero.WearGear(position, 0);
                    playerHero.SetHero(m_RequestPacket.PutOnHeroId);
                }
                package.AddGear(m_RequestPacket.TakeOffGearId, gear.MyGear.TypeId);
            }
            playerHero.WearGear(position, m_RequestPacket.PutOnGearId);
            m_ResponsePacket.PutOnGearId   = m_RequestPacket.PutOnGearId;
            m_ResponsePacket.TakeOffGearId = m_RequestPacket.TakeOffGearId;
            if (m_RequestPacket.PutOnHeroId > 0)
            {
                m_ResponsePacket.PutOnHeroInfo = new PBLobbyHeroInfo()
                {
                    Type  = m_RequestPacket.PutOnHeroId,
                    Might = playerHero.SetHero(m_RequestPacket.PutOnHeroId).GetHeroInfo().Might
                };
            }
            if (m_RequestPacket.TakeOffHeroId > 0)
            {
                m_ResponsePacket.TakeOffHeroInfo = new PBLobbyHeroInfo()
                {
                    Type  = m_RequestPacket.TakeOffHeroId,
                    Might = playerHero.SetHero(m_RequestPacket.TakeOffHeroId).GetHeroInfo().Might
                };
            }
            return(true);
        }