/// <summary> /// Removes the equip. /// </summary> /// <param name="managerId">The manager id.</param> /// <param name="teammemberId">The teammember id.</param> /// <returns></returns> public TeammemberResponse RemoveEquipment(Guid managerId, Guid teammemberId) { #region Check //if (teammember == null // || teammember.ManagerId != managerId) // return ResponseHelper.InvalidParameter<TeammemberResponse>(); //if (teammember.UsedEquipment == null) // return ResponseHelper.InvalidParameter<TeammemberResponse>(); var package = ItemCore.Instance.GetPackage(managerId, EnumTransactionType.TeammemberRemoveEquip); if (package == null) { return(ResponseHelper.InvalidParameter <TeammemberResponse>()); } var playerCardItem = package.GetPlayer(teammemberId); if (playerCardItem == null) { return(ResponseHelper.InvalidParameter <TeammemberResponse>()); } var cardProperty = playerCardItem.ItemProperty as PlayerCardProperty; if (cardProperty == null) { return(ResponseHelper.InvalidParameter <TeammemberResponse>()); } var equipEntity = cardProperty.Equipment; if (equipEntity == null) { return(ResponseHelper.InvalidParameter <TeammemberResponse>()); } //在竞技场的阵型上 if (cardProperty.IsMain && cardProperty.MainType > 0) { return(ArenaTeammemberCore.Instance.RemoveEquipment(managerId, teammemberId, package)); } #endregion int mod = ShareUtil.GetTableMod(managerId); var teammember = GetTeammember(managerId, teammemberId); if (package.IsFull) //背包已满 { return(ResponseHelper.Create <TeammemberResponse>(MessageCode.ItemPackageFull)); } var result = package.AddUsedItem(equipEntity); if (result != MessageCode.Success) { return(ResponseHelper.Create <TeammemberResponse>(result)); } cardProperty.Equipment = null; var code = package.Update(playerCardItem); if (code != MessageCode.Success) { return(ResponseHelper.Create <TeammemberResponse>(code)); } TeammemberResponse response = null; if (teammember != null) { teammember.UsedEquipment = new byte[0]; response = SaveSetEquipment(teammember, package, teammember.UsedEquipment, mod); } else { response = ResponseHelper.Create <TeammemberResponse>(MessageCode.Success); } if (response.Code == ShareUtil.SuccessCode) { if (package.Save()) { package.Shadow.Save(); } if (teammember != null) { KpiHandler.Instance.RebuildKpi(managerId, false); response.Data.TotalKpi = ManagerCore.Instance.GetKpi(managerId); package.Shadow.AddShadow(teammember, EnumOperationType.Update); package.Shadow.Save(); response.Data.Package = ItemCore.Instance.BuildPackageData(package); } else { response = new TeammemberResponse(); response.Data = new TeammemberEntity(); response.Data.Package = new ItemPackageData(); var packageItemsEntity = SerializationHelper.FromByte <ItemPackageItemsEntity>(package.NewItemString); if (packageItemsEntity == null || packageItemsEntity.Items == null) { response.Data.Package.Items = new List <ItemInfoEntity>(); } else { response.Data.Package.Items = packageItemsEntity.Items; } response.Data.Package.PackageSize = package.PackageSize; } } return(response); }
/// <summary> /// Sets the teammember equip. /// </summary> /// <param name="managerId">The manager id.</param> /// <param name="teammemberId">The teammember id.</param> /// <param name="itemId">The item id.</param> /// <returns></returns> public TeammemberResponse SetEquip(Guid managerId, Guid teammemberId, Guid itemId) { #region Check //if (teammember == null // || teammember.ManagerId != managerId) // return ResponseHelper.InvalidParameter<TeammemberResponse>(); var package = ItemCore.Instance.GetPackage(managerId, EnumTransactionType.TeammemberSetEquip); if (package == null) { return(ResponseHelper.InvalidParameter <TeammemberResponse>()); } var playerCardItem = package.GetPlayer(teammemberId); if (playerCardItem == null) { return(ResponseHelper.InvalidParameter <TeammemberResponse>()); } var cardProperty = playerCardItem.ItemProperty as PlayerCardProperty; if (cardProperty == null) { return(ResponseHelper.InvalidParameter <TeammemberResponse>()); } //在竞技场的阵型上 if (cardProperty.IsMain && cardProperty.MainType > 0) { return(ArenaTeammemberCore.Instance.SetEquip(managerId, teammemberId, itemId, package)); } var item = package.GetItem(itemId); if (item == null) { return(ResponseHelper.Create <TeammemberResponse>(MessageCode.ItemNotExists)); } #endregion int mod = ShareUtil.GetTableMod(managerId); var teammember = GetTeammember(managerId, teammemberId); try { //删除要穿上的装备 var code = package.Delete(item); if (code != MessageCode.Success) { return(ResponseHelper.Create <TeammemberResponse>(code)); } TeammemberResponse response = ResponseHelper.Create <TeammemberResponse>(MessageCode.Success); var itemDic = CacheFactory.ItemsdicCache.GetItem(item.ItemCode); //装备 if (itemDic.ItemType == (int)EnumItemType.Equipment) { if (teammember != null) { if (teammember.Equipment != null) { var result = package.AddUsedItem(teammember.Equipment); if (result != MessageCode.Success) { return(ResponseHelper.Create <TeammemberResponse>(result)); } } var newEquip = new EquipmentUsedEntity(item); cardProperty.Equipment = newEquip; code = package.Update(playerCardItem); if (code != MessageCode.Success) { return(ResponseHelper.Create <TeammemberResponse>(code)); } response = SetEquipment(teammember, package, item, mod); } else { if (cardProperty.Equipment != null) { var result = package.AddUsedItem(cardProperty.Equipment); if (result != MessageCode.Success) { return(ResponseHelper.Create <TeammemberResponse>(result)); } } var newEquip = new EquipmentUsedEntity(item); cardProperty.Equipment = newEquip; code = package.Update(playerCardItem); if (code != MessageCode.Success) { return(ResponseHelper.Create <TeammemberResponse>(code)); } response = ResponseHelper.Create <TeammemberResponse>(MessageCode.Success); } } if (response.Code == ShareUtil.SuccessCode) { if (teammember != null) { KpiHandler.Instance.RebuildKpi(managerId, true); package.Shadow.AddShadow(teammember, EnumOperationType.Update); package.Shadow.Save(); } else { if (package.Save()) { package.Shadow.Save(); } } if (response.Data == null) { response.Data = new TeammemberEntity(); } response.Data.TotalKpi = ManagerCore.Instance.GetKpi(managerId); response.Data.Package = ItemCore.Instance.BuildPackageData(package); } return(response); } catch (Exception ex) { SystemlogMgr.Error("SetEquip", ex); return(ResponseHelper.Create <TeammemberResponse>(MessageCode.Exception)); } }