public override bool TakeAction() { PlayerPackageLogic pp = new PlayerPackageLogic(); pp.SetUser(m_UserId); PlayerLogic player = new PlayerLogic(); player.SetUser(m_UserId); int totalCoin = 0; foreach (var item in m_RequestPacket.SoldItems) { ItemListItem tmpItem = new ItemListItem() { Id = item.Type, Count = item.Count }; if (!pp.DeductInventory(tmpItem)) { ErrorCode = (int)ErrorType.RequireNotMet; ErrorInfo = "You have not enough item"; return(false); } DTItem itemData = CacheSet.ItemTable.GetData(item.Type); totalCoin += item.Count * itemData.Price; m_ResponsePacket.ItemInfo.Add(item); } foreach (var gear in m_RequestPacket.SoldGears) { if (!pp.DeductGear(gear.Id)) { ErrorCode = (int)ErrorType.RequireNotMet; ErrorInfo = "You have not this gear"; return(false); } DTGear gearData = CacheSet.GearTable.GetData(gear.Type); totalCoin += gearData.Price; m_ResponsePacket.GearInfo.Add(gear); } player.AddCoin(totalCoin); m_ResponsePacket.PlayerInfo = new PBPlayerInfo() { Id = player.MyPlayer.Id, Coin = player.MyPlayer.Coin }; return(true); }
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() { PlayerHeroLogic playerHero = new PlayerHeroLogic(); playerHero.SetUser(m_UserId).SetHero(m_RequestPacket.HeroType); if (!playerHero.DataCheck()) { ErrorCode = (int)ErrorType.CannotOpenChance; ErrorInfo = "wrong HeroId"; return(false); } PlayerPackageLogic package = new PlayerPackageLogic(); package.SetUser(m_UserId); Hero myHero = playerHero.GetHeroInfo(); DTHeroElevationBase heroElevationData = CacheSet.HeroElevationBaseTable.GetData(myHero.ElevationLevel); if (heroElevationData.LevelUpItemId == -1) { ErrorCode = (int)ErrorType.RequireNotMet; ErrorInfo = "reached max level"; return(false); } ItemListItem item = new ItemListItem() { Id = heroElevationData.LevelUpItemId, Count = heroElevationData.LevelUpItemCount }; if (!package.DeductInventory(item)) { ErrorCode = (int)ErrorType.RequireNotMet; ErrorInfo = "not enough piece"; return(false); } for (int i = 0; i < GameConsts.Hero.ElevationLevelUpGearCount; i++) { if (heroElevationData.LevelUpGearType[i] == -1 || heroElevationData.LevelUpGearMinQuality[i] == -1) { break; } int gearTypeId = 0; if (package.MyPackage.Gears.ContainsKey(m_RequestPacket.GearId[i])) { gearTypeId = package.MyPackage.Gears[m_RequestPacket.GearId[i]]; } else { ErrorCode = (int)ErrorType.RequireNotMet; ErrorInfo = "do not have this gear"; return(false); } DTGear gear = CacheSet.GearTable.GetData(gearTypeId); if (gear.Type == heroElevationData.LevelUpGearType[i] && gear.Quality >= heroElevationData.LevelUpGearMinQuality[i]) { package.DeductGear(m_RequestPacket.GearId[i]); } else { ErrorCode = (int)ErrorType.CannotOpenChance; ErrorInfo = "gear" + i.ToString() + " do not match this slot"; return(false); } } playerHero.ElevationLevelUp(); var heroInfo = playerHero.GetHeroInfo(); m_ResponsePacket.LobbyHeroInfo = new PBLobbyHeroInfo() { Type = heroInfo.HeroType, ElevationLevel = heroInfo.ElevationLevel, Might = heroInfo.Might, }; m_ResponsePacket.RemovedGears.AddRange(m_RequestPacket.GearId); m_ResponsePacket.ItemInfo = new PBItemInfo() { Type = item.Id, Count = package.MyPackage.Inventories[item.Id] }; return(true); }