private void AddGear(int gearType) { GearLogic gear = new GearLogic(); int gearId = gear.AddNewGear(gearType, m_UserId, ReceiveItemMethodType.None); PlayerPackageLogic pp = new PlayerPackageLogic(); pp.SetUser(m_UserId); pp.AddGear(gearId, gearType); m_ResponsePacket.GearInfo = new PBGearInfo() { Id = gearId, Type = gearType, Level = gear.MyGear.Level, StrengthenLevel = gear.MyGear.StrengthenLevel }; }
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); }
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); }