Esempio n. 1
0
 /// <summary>
 /// 移除Buff,自动提交事务
 /// </summary>
 /// <param name="managerId">经理Id</param>
 /// <param name="srcType">来源类型</param>
 /// <param name="skillCode">技能Code</param>
 /// <param name="srcId">来源Id</param>
 /// <param name="tranMgr">事务对象</param>
 /// <returns></returns>
 public bool RemovePools(Guid managerId, EnumSkillSrcType srcType, string skillCode = "", string srcId = "", TransactionManager tranMgr = null)
 {
     try
     {
         int managerHash = ShareUtil.GetTableMod(managerId);
         if (null == tranMgr)
         {
             tranMgr = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault());
         }
         using (tranMgr)
         {
             if (!tranMgr.IsOpen)
             {
                 tranMgr.BeginTransaction();
             }
             NbManagerbuffpoolMgr.Exclude(managerId, managerHash, (int)srcType, srcId, skillCode, tranMgr.TransactionObject);
             tranMgr.Commit();
         }
         s_buffSync.SyncBuffPools(managerId);
         return(true);
     }
     catch (Exception ex)
     {
         LogHelper.Insert(ex, "BuffPoolCore:AddBuffPools");
         throw ex;
     }
 }
Esempio n. 2
0
 internal bool SyncMembersCore(Guid managerId, EnumArenaType arenaType, DTOBuffMemberView buffData, string siteId = "")
 {
     try
     {
         if (null == buffData)
         {
             return(false);
         }
         if (string.IsNullOrEmpty(siteId))
         {
             int managerHash = ShareUtil.GetTableMod(managerId);
             //var idles = GetIdleMembers(managerId, buffData);
             string mSkills   = FrameConvert.SkillListToText(buffData.ManagerSkills);
             int    errorCode = 0;
             byte[] rowVer    = BitConverter.GetBytes(buffData.UseSyncVersion);
             NbManagerbuffmemberMgr.SyncBatch(managerId, buffData.Kpi, string.Empty, mSkills, rowVer, ref rowVer, ref errorCode);
             if (errorCode != 0)
             {
                 return(false);
             }
             buffData.UseSyncVersion = BitConverter.ToUInt64(rowVer, 0);
         }
         buffData.SyncIdleFlag = false;
         s_memBuffMember.Set(arenaType.ToString() + managerId.ToString(), buffData);
         return(true);
     }
     catch (Exception ex)
     {
         SystemlogMgr.Error(string.Format("BuffDataCore:Sync Manager[{0}]", managerId), ex);
         return(false);
     }
 }
Esempio n. 3
0
        Guid[] GetIdleMembers(Guid managerId, DTOBuffMemberView buffData)
        {
            if (!buffData.SyncIdleFlag)
            {
                return(null);
            }
            var       members = NbManagerbuffmemberMgr.GetByMid(managerId, ShareUtil.GetTableMod(managerId));
            Guid      tid     = Guid.Empty;
            var       dic     = buffData.BuffMembers;
            const int cnt     = 5;
            int       i       = 0;
            var       ary     = new Guid[cnt];

            foreach (var item in members)
            {
                if (i >= cnt)
                {
                    break;
                }
                tid = item.Tid;
                if (!dic.ContainsKey(tid))
                {
                    ary[i++] = tid;
                }
            }
            for (; i < cnt; ++i)
            {
                ary[i] = Guid.Empty;
            }
            return(ary);
        }
Esempio n. 4
0
        DTOBuffMemberView GetMembers4Db(Guid managerId, ManagerSkillUseWrap use, ArenaTeammemberFrame arenaFrame)
        {
            if (!FrameConfig.SWAPBuffDataReadDb ||
                null == use || use.Raw.SyncFlag != 0)
            {
                return(null);
            }
            var rawMembers = BuffUtil.GetRawMembers(managerId, true, arenaFrame);
            var members    = NbManagerbuffmemberMgr.GetByMid(managerId, ShareUtil.GetTableMod(managerId));
            //var extra = NbManagerextraMgr.GetById(managerId);
            var             dic = new Dictionary <Guid, NbManagerbuffmemberEntity>(members.Count);
            DicPlayerEntity cfg = null;

            foreach (var item in members)
            {
                cfg = PlayersdicCache.Instance.GetPlayer(Math.Abs(item.Pid));
                if (null == cfg)
                {
                    continue;
                }
                FillBuffMemberProp(item, cfg);
                item.ReadySkillList = item.ReadySkills.Split(',').ToList();
                item.LiveSkillList  = item.LiveSkills.Split(',').ToList();
            }
            var data = CreateBuffView(managerId, use, rawMembers.ToDictionary(i => i.Idx, i => i));

            data.Kpi          = arenaFrame.Kpi;
            data.SyncIdleFlag = false;
            data.BuffMembers  = dic;
            return(data);
        }
Esempio n. 5
0
 public static void SaveTrainData(TeammemberTrainEntity trainEntity, ref int returnCode, DbTransaction trans = null)
 {
     UpdateData(trainEntity.Idx, trainEntity.Level, trainEntity.EXP, trainEntity.TrainStamina,
                trainEntity.TrainState,
                trainEntity.StartTime, trainEntity.SettleTime, trainEntity.Status,
                ShareUtil.GetTableMod(trainEntity.ManagerId), ref returnCode,
                trans);
 }
Esempio n. 6
0
        public static List <TeammemberEntity> GetRawMembers(Guid managerId, bool syncFlag = true, string siteId = "")
        {
            try
            {
                List <TeammemberEntity> list = null;
                if (syncFlag)
                {
                    list = MemcachedFactory.TeammembersClient.Get <List <TeammemberEntity> >(managerId);
                }
                if (null != list && list.Count > 0)
                {
                    return(list);
                }
                list = TeammemberMgr.GetByManager(managerId, ShareUtil.GetTableMod(managerId), siteId);

                TeammemberGrowEntity grow = null;
                var growList = TeammemberGrowMgr.GetByManager(managerId, siteId);
                foreach (var entity in list)
                {
                    if (!entity.IsHirePlayer)
                    {
                        grow = growList.Find(d => d.Idx == entity.Idx);
                        if (grow != null)
                        {
                            entity.GrowLevel = grow.GrowLevel;
                        }
                    }
                    if (entity.UsedPlayerCard != null && entity.UsedPlayerCard.Length > 0)
                    {
                        entity.PlayerCard = SerializationHelper.FromByte <PlayerCardUsedEntity>(entity.UsedPlayerCard);
                    }
                    if (entity.UsedEquipment != null && entity.UsedEquipment.Length > 0)
                    {
                        entity.Equipment = SerializationHelper.FromByte <EquipmentUsedEntity>(entity.UsedEquipment);
                    }
                    TeammemberDataHelper.CalPropertyCount(entity);
                    if (entity.IsHirePlayer)
                    {
                        TeammemberDataHelper.CalMaxGrow(entity, null);
                    }
                    else
                    {
                        TeammemberDataHelper.CalMaxGrow(entity, grow, siteId);
                    }
                    entity.RawProperty = new TeammemberPropertyEntity(entity);
                }
                if (syncFlag && list.Count > 0)
                {
                    MemcachedFactory.TeammembersClient.Set(managerId, list);
                }
                return(list);
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("GetRawMembers", string.Format("mid:{0}", managerId), ex);
                throw ex;
            }
        }
Esempio n. 7
0
        internal DTOBuffPoolView ReqRawPools(Guid managerId, string siteId = "", bool syncFlag = true)
        {
            int managerHash = ShareUtil.GetTableMod(managerId);

            byte[] verDb     = null;
            var    data      = CreateBuffView();
            var    pools     = NbManagerbuffpoolMgr.GetByMid(managerId, managerHash, siteId);
            var    teamPools = CheckTeamBuffPools(managerId, siteId);

            if (null != teamPools)
            {
                pools.AddRange(teamPools);
            }
            NbManagerbuffpoolMgr.GetVersionByMid(managerId, managerHash, ref verDb, null, siteId);
            ulong verNo = 0;

            if (null != verDb)
            {
                verNo = BitConverter.ToUInt64(verDb, 0);
            }
            DateTime      dtNow      = DateTime.Now;
            DateTime      dtSync     = DATEInfi;
            List <string> liveSkills = null;

            foreach (var item in pools)
            {
                if (dtNow < item.ExpiryTime && item.ExpiryTime < dtSync)
                {
                    dtSync = item.ExpiryTime;
                }
                if (item.LiveFlag != 2)
                {
                    continue;
                }
                if (null == liveSkills)
                {
                    liveSkills = new List <string>();
                }
                liveSkills.Add(BuffCache.Instance().CastSkillKey(item.SkillCode, item.SkillLevel));
            }
            data.BuffPools   = pools;
            data.LiveSkills  = liveSkills;
            data.SyncTime    = dtSync;
            data.SyncVersion = verNo;
            if (syncFlag)
            {
                s_memBuffPool.Set(managerId.ToString(), data);
            }
            return(data);
        }
Esempio n. 8
0
 private void btnCalHashcode_Click(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(txtGuid.Text))
     {
         lblResult.Content = "请输入要计算的guid";
         return;
     }
     try
     {
         lblResult.Content = "结果:" + ShareUtil.GetTableMod(new Guid(txtGuid.Text));
     }
     catch (Exception ex)
     {
         lblResult.Content = "计算出错:" + ex.Message;
     }
 }
        //void UpdateActivitystatisticsDouyuEntity(ActivityDyUserEntity user,
        //    ActivitystatisticsDouyuEntity adEntity)
        //{
        //    if (adEntity == null)
        //    {
        //        adEntity = new ActivitystatisticsDouyuEntity();
        //        adEntity.ManagerId = user.ManagerId;
        //        adEntity.ZoneName = user.ZoneName;
        //        adEntity.ZoneId = user.ZoneId;
        //        adEntity.Account = user.Account;
        //        adEntity.ExctingId = user.ExcitingId;
        //        adEntity.CurData = user.Curdata;
        //        adEntity.Status = user.Status;
        //        adEntity.Strength7 = user.Strength7;
        //        adEntity.Strength9 = user.Strength9;
        //        adEntity.UpdateTime = DateTime.Now;
        //        adEntity.RowTime = DateTime.Now;
        //        ActivitystatisticsDouyuMgr.Insert(adEntity);
        //    }
        //    else
        //    {
        //        adEntity.CurData = user.Curdata;
        //        adEntity.Status = user.Status;
        //        adEntity.Strength7 = user.Strength7;
        //        adEntity.Strength9 = user.Strength9;
        //        adEntity.UpdateTime = DateTime.Now;
        //        ActivitystatisticsDouyuMgr.Update(adEntity);
        //    }
        //}

        void CreateActivityDyUserStrength(string zoneId, ActivityDyUserEntity entity)
        {
            var mod  = ShareUtil.GetTableMod(entity.ManagerId);
            var list = TeammemberMgr.GetByManager(entity.ManagerId, mod, zoneId);

            if (list.Count > 0)
            {
                foreach (var teammemberEntity in list)
                {
                    var playercardEntity = SerializationHelper.FromByte <PlayerCardUsedEntity>(teammemberEntity.UsedPlayerCard);
                    if (playercardEntity != null)
                    {
                        if (playercardEntity.Property.Strength >= 7)
                        {
                            entity.Strength7++;
                            if (playercardEntity.Property.Strength == 9)
                            {
                                entity.Strength9++;
                            }
                        }
                    }
                }
            }
            var package = ItemCore.Instance.GetPackageWithoutShadow(entity.ManagerId, zoneId);
            var items   = package.GetItemsByType((int)EnumItemType.PlayerCard);

            foreach (var item in items)
            {
                int strength = item.GetStrength();
                if (strength >= 7)
                {
                    entity.Strength7++;
                    if (strength == 9)
                    {
                        entity.Strength9++;
                    }
                }
            }
        }
Esempio n. 10
0
        public TransferThread(int domainId)
        {
            _domainId = domainId;
            var transferList = TransferMainMgr.GetTransferList(_domainId);

            _transferDic     = new ConcurrentDictionary <Guid, TransferMainEntity>();
            _tenTransferList = new List <TransferMainEntity>();
            foreach (var item in transferList)
            {
                item.TransferDurationTick = ShareUtil.GetTimeTick(item.TransferDuration);
                item.TransferDurationTick = ShareUtil.GetTimeTick(item.TransferDuration);
                if (DateTime.Now < item.TransferStartTime.AddMinutes(10))
                {
                    var modId = ShareUtil.GetTableMod(item.TransferId);
                    item.ModId = modId;
                    _tenTransferList.Add(item);
                }
                else
                {
                    _transferDic.TryAdd(item.TransferId, item);
                }
            }
            Sort();
        }
Esempio n. 11
0
 /// <summary>
 /// 添加技能Buff,自动提交事务
 /// </summary>
 /// <param name="managerId">经理Id</param>
 /// <param name="srcId">来源Id</param>
 /// <param name="skillCode">技能Code</param>
 /// <param name="skillLevel">技能等级</param>
 /// <param name="tranMgr">事务对象</param>
 /// <returns></returns>
 public bool PostAddPools(Guid managerId, string srcId, string skillCode, int skillLevel = 0, TransactionManager tranMgr = null)
 {
     try
     {
         int  managerHash = ShareUtil.GetTableMod(managerId);
         var  incPools    = BuffCache.Instance().GetPoolIncBuffList(skillCode, skillLevel);
         var  flows       = BuffCache.Instance().GetFirmBuffList(skillCode, skillLevel);
         bool syncFlow    = (null != flows && flows.Count > 0);
         if (null == incPools || incPools.Count == 0)
         {
             if (null != tranMgr && tranMgr.IsOpen)
             {
                 tranMgr.Commit();
             }
             if (syncFlow)
             {
                 s_buffSync.SetBuffMembers(managerId);
             }
             return(true);
         }
         string[] excSkills;
         int[]    excBuffs;
         GetExcSkillBuffs(out excSkills, out excBuffs, skillCode, skillLevel);
         if (null == tranMgr)
         {
             tranMgr = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault());
         }
         using (tranMgr)
         {
             if (!tranMgr.IsOpen)
             {
                 tranMgr.BeginTransaction();
             }
             if (excSkills[0] != string.Empty)
             {
                 NbManagerbuffpoolMgr.ExcludeMulti(managerId, managerHash,
                                                   excSkills[0], excBuffs[0], excSkills[1], excBuffs[1], excSkills[2], excBuffs[2], excSkills[3], excBuffs[3], excSkills[4], excBuffs[4],
                                                   tranMgr.TransactionObject);
             }
             foreach (var cfg in incPools)
             {
                 NbManagerbuffpoolMgr.Include(managerId, managerHash, cfg.SkillCode, cfg.SkillLevel, cfg.BuffSrcType, srcId,
                                              (int)cfg.AsBuffUnitType, cfg.LiveFlag, cfg.BuffNo,
                                              cfg.DstDir, cfg.DstMode, cfg.DstKey, cfg.BuffMap, cfg.BuffVal, cfg.BuffPer,
                                              cfg.ExpiryMinutes, cfg.LimitTimes, cfg.TotalTimes, cfg.RepeatBuffFlag, cfg.RepeatTimeFlag, cfg.RepeatTimesFlag,
                                              tranMgr.TransactionObject);
             }
             tranMgr.Commit();
         }
         s_buffSync.SyncBuffPools(managerId);
         if (syncFlow)
         {
             s_buffSync.SetBuffMembers(managerId);
         }
         return(true);
     }
     catch (Exception ex)
     {
         LogHelper.Insert(ex, "BuffPoolCore:PostAddPools");
         throw ex;
     }
 }
Esempio n. 12
0
        /// <summary>
        /// 开始拍卖
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="zoneName"></param>
        /// <param name="itemId"></param>
        /// <param name="price"></param>
        /// <param name="transferDuration"></param>
        public AuctionItemResponse AuctionItem(Guid managerId, string zoneName, Guid itemId, int price, int transferDuration)
        {
            var response = new AuctionItemResponse();

            response.Data = new AuctionItemEntity();
            try
            {
                DateTime date    = DateTime.Now;
                var      manager = NbManagerMgr.GetById(managerId, zoneName);
                if (manager == null)
                {
                    return(ResponseHelper.Create <AuctionItemResponse>(MessageCode.AdMissManager));
                }
                if (!IsOpen(managerId, zoneName, manager))
                {
                    return(ResponseHelper.Create <AuctionItemResponse>(MessageCode.TransferNotOpen));
                }
                //已经挂牌了多少个
                var number = TransferMainMgr.GetTransferNumber(managerId);
                //最多可以挂牌多少个
                var gambleCountMax = CacheFactory.VipdicCache.GetEffectValue(manager.VipLevel, EnumVipEffect.TransferNumber);
                if (gambleCountMax <= number)
                {
                    return(ResponseHelper.Create <AuctionItemResponse>(MessageCode.TransferNumberMax));
                }
                var package = ItemCore.Instance.GetPackage(managerId, EnumTransactionType.Transfer, zoneName);
                if (package == null)
                {
                    return(ResponseHelper.Create <AuctionItemResponse>(MessageCode.NbNoPackage));
                }

                if (price < 2)
                {
                    return(ResponseHelper.Create <AuctionItemResponse>(MessageCode.StartPriceSmall));
                }
                var item = package.GetItem(itemId);
                if (item == null)
                {
                    return(ResponseHelper.Create <AuctionItemResponse>(MessageCode.ItemNotExists));
                }
                if (!item.IsDeal)
                {
                    return(ResponseHelper.Create <AuctionItemResponse>(MessageCode.NotDeal));
                }
                var strength = item.GetStrength();
                if (strength > 1)
                {
                    return(ResponseHelper.Create <AuctionItemResponse>(MessageCode.NotDeal));
                }
                var iteminfo = CacheFactory.ItemsdicCache.GetItem(item.ItemCode);
                if (iteminfo == null)
                {
                    return(ResponseHelper.Create <AuctionItemResponse>(MessageCode.ItemNotExists));
                }
                //默认86400秒  24小时
                TransferMainEntity entity = new TransferMainEntity(ShareUtil.GenerateComb(), _domainId, item.ItemCode, iteminfo.ItemName,
                                                                   new byte[0], manager.Name, managerId, zoneName, price, "",
                                                                   "", 0, Guid.Empty, date, date.AddDays(1), 0, 0, 0, date, date);

                var messageCode = package.Delete(itemId);
                if (messageCode != MessageCode.Success)
                {
                    return(ResponseHelper.Create <AuctionItemResponse>(messageCode));
                }
                if (!package.Save())
                {
                    return(ResponseHelper.Create <AuctionItemResponse>(MessageCode.NbUpdateFail));
                }
                if (!TransferMainMgr.Insert(entity))
                {
                    messageCode = package.AddItem(item.ItemCode);
                    if (messageCode != MessageCode.Success)
                    {
                        SystemlogMgr.Error("拍卖返还物品失败",
                                           "拍卖返还物品失败,managerId:" + managerId + ",zoneName:" + zoneName + "物品ID:" + item.ItemCode);
                    }
                    return(ResponseHelper.Create <AuctionItemResponse>(MessageCode.NbUpdateFail));
                }
                package.Shadow.Save();
                entity.TransferDurationTick = ShareUtil.GetTimeTick(entity.TransferDuration);
                entity.TransferDurationTick = ShareUtil.GetTimeTick(entity.TransferDuration);
                var modId = ShareUtil.GetTableMod(entity.TransferId);
                entity.ModId = modId;
                _tenTransferList.Add(entity);
                Sort();
                response.Data.MyTransferList     = GetMyTransfer(managerId);
                response.Data.MaxTransferNumber  = gambleCountMax;
                response.Data.HaveTransferNumber = number + 1;
                var goldBarEntity = ScoutingGoldbarMgr.GetById(managerId, zoneName);
                if (goldBarEntity != null)
                {
                    response.Data.MyGoldBar = goldBarEntity.GoldBarNumber;
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("开始拍卖", ex);
                response.Code = (int)MessageCode.NbParameterError;
            }
            return(response);
        }
Esempio n. 13
0
        /// <summary>
        /// 获取拍卖列表
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="zoneName"></param>
        /// <param name="rankRule"></param>
        /// <param name="itemName"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public AuctionItemResponse GetTransferList(Guid managerId, string zoneName, int rankRule, string itemName, int pageSize, int pageIndex)
        {
            AuctionItemResponse response = new AuctionItemResponse();

            response.Data = new AuctionItemEntity();
            try
            {
                if (pageSize <= 0)
                {
                    return(response);
                }
                if (!IsOpen(managerId, zoneName))
                {
                    return(ResponseHelper.Create <AuctionItemResponse>(MessageCode.TransferNotOpen));
                }
                var  list      = new List <TransferMainEntity>();
                var  modId     = ShareUtil.GetTableMod(managerId);
                bool isOrderBy = false;
                if (_tenTransferList != null && _tenTransferList.Count > 0)
                {
                    var modList = _tenTransferList.FindAll(r => r.ModId == modId);
                    if (modList.Count > 0)
                    {
                        isOrderBy = true;
                        list.AddRange(modList);
                    }
                }
                switch (rankRule)
                {
                case 2:     //价格正序
                    list.AddRange(_transferPriceList);
                    if (isOrderBy)
                    {
                        list = list.OrderBy(r => r.Price).ToList();
                    }
                    break;

                case 3:     //价格到序
                    list.AddRange(_transferPriceDescList);
                    if (isOrderBy)
                    {
                        list = list.OrderByDescending(r => r.Price).ToList();
                    }
                    break;

                default:     //默认排序 时间倒序
                    list.AddRange(_transferTimeList);
                    break;
                }
                if (itemName.Trim().Length > 0)
                {
                    if (list.Count > 0)
                    {
                        list = list.Where(r => r.ItemName.IndexOf(itemName) > -1).ToList();
                    }
                }
                response.Data.TotalPageNumber = list.Count / pageSize;
                if (list.Count % pageSize != 0)
                {
                    response.Data.TotalPageNumber = response.Data.TotalPageNumber + 1;
                }
                var resultList = new List <TransferMainEntity>();
                if (list.Count > 0)
                {
                    int index = pageSize * (pageIndex - 1);
                    if (list.Count > index)
                    {
                        resultList = list.Skip(index).Take(pageSize).ToList();
                    }
                }
                response.Data.MyTransferList = resultList;
                var goldBarEntity = ScoutingGoldbarMgr.GetById(managerId, zoneName);
                if (goldBarEntity != null)
                {
                    response.Data.MyGoldBar = goldBarEntity.GoldBarNumber;
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("获取拍卖列表", ex);
                response.Code = (int)MessageCode.NbParameterError;
            }
            return(response);
        }
Esempio n. 14
0
        /// <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);
        }
Esempio n. 15
0
        /// <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));
            }
        }
Esempio n. 16
0
        /// <summary>
        /// 替换上场
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="teammemberId"></param>
        /// <param name="byTeammemberId"></param>
        /// <returns></returns>
        public NBSolutionInfoResponse ReplacePlayer(Guid managerId, Guid teammemberId, Guid byTeammemberId)
        {
            bool isChanagePlayer = false;

            try
            {
                ItemPackageFrame package  = null;
                MessageCode      messCode = MessageCode.Success;
                var soluti = MatchDataHelper.GetSolution(managerId);
                if (soluti == null)
                {
                    return(ResponseHelper.InvalidParameter <NBSolutionInfoResponse>());
                }
                var byteammember = GetTeammember(managerId, byTeammemberId);
                if (byteammember == null || !soluti.PlayerDic.ContainsKey(byteammember.PlayerId))
                {
                    return(ResponseHelper.Create <NBSolutionInfoResponse>((int)MessageCode.TeammemberNotMain));
                }
                var teammember   = GetTeammember(managerId, teammemberId);
                var playerString = "";
                var playerIdList = FrameUtil.CastIntList(soluti.PlayerString, ',');


                if (teammember != null)
                {
                    ExchangePlayer(playerIdList, teammember.PlayerId, byteammember.PlayerId, false, ref playerString);
                    soluti.PlayerString = playerString;
                    if (!NbSolutionMgr.Update(soluti))
                    {
                        return(ResponseHelper.Create <NBSolutionInfoResponse>((int)MessageCode.NbUpdateFail));
                    }
                    MemcachedFactory.SolutionClient.Delete(managerId);
                    KpiHandler.Instance.RebuildKpi(managerId, true);
                    var manager = MatchDataHelper.GetManager(managerId, true, true);
                    if (manager == null)
                    {
                        return(ResponseHelper.Create <NBSolutionInfoResponse>((int)MessageCode.NbParameterError));
                    }

                    var response1 = SolutionAndTeammemberResponse(managerId);
                    return(response1);
                    //换位置
                }
                else //换替补
                {
                    isChanagePlayer = true;
                    package         = ItemCore.Instance.GetPackage(managerId, EnumTransactionType.TeammemberTrans);
                    if (package == null)
                    {
                        return(ResponseHelper.Create <NBSolutionInfoResponse>(MessageCode.NbNoPackage));
                    }
                    var player = package.GetPlayer(teammemberId);
                    if (player.ItemType != (int)EnumItemType.PlayerCard)
                    {
                        return(ResponseHelper.Exception <NBSolutionInfoResponse>());
                    }
                    player.IsDeal = false;
                    var itemInfo = CacheFactory.ItemsdicCache.GetItem(player.ItemCode);
                    //限制金卡
                    if (itemInfo != null && itemInfo.ItemType == (int)EnumItemType.PlayerCard &&
                        itemInfo.PlayerCardLevel == (int)EnumPlayerCardLevel.Gold)
                    {
                        var solution = MatchDataHelper.GetSolutionInfo(managerId);
                        if (solution == null)
                        {
                            return(ResponseHelper.InvalidParameter <NBSolutionInfoResponse>());
                        }
                        if (solution.MaxVeteranCount <= solution.VeteranCount)
                        {
                            return
                                (ResponseHelper.Create <NBSolutionInfoResponse>(
                                     (int)MessageCode.TeammemberVeteranCountOver));
                        }
                    }
                    var pid = player.ItemCode % 100000;

                    //检查是否已有相同pid的球员
                    var linkList = CacheFactory.PlayersdicCache.GetLinkPlayerList(pid);
                    if (linkList != null)
                    {
                        foreach (var link in linkList)
                        {
                            if (playerIdList.Exists(d => d == link))
                            {
                                return(ResponseHelper.Create <NBSolutionInfoResponse>(MessageCode.TeammemberSolutionPlayerRepeat));
                            }
                        }
                    }
                    int teammemberCount = 0;
                    int returnCode      = 0;
                    TeammemberMgr.GetForTransCheck(managerId, pid, ShareUtil.GetTableMod(managerId),
                                                   (int)MessageCode.TeammemberRepeat, ref teammemberCount, ref returnCode);
                    if (returnCode != (int)MessageCode.Success)
                    {
                        return(ResponseHelper.Create <NBSolutionInfoResponse>(returnCode));
                    }
                    messCode = package.ReplacePlayerCard(100000 + byteammember.PlayerId, false,
                                                         byteammember.Strength,
                                                         byteammember.Idx, byteammember.Equipment, player.ItemId, byteammember.Level);
                    ExchangePlayer(playerIdList, pid, byteammember.PlayerId, true, ref playerString);
                    soluti.PlayerString = playerString;
                    if (messCode != MessageCode.Success)
                    {
                        return(ResponseHelper.Create <NBSolutionInfoResponse>(messCode));
                    }
                }
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    messCode = MessageCode.NbUpdateFail;
                    do
                    {
                        if (package != null)
                        {
                            if (!package.SavePlayer(transactionManager.TransactionObject))
                            {
                                break;
                            }
                        }
                        if (!NbSolutionMgr.Update(soluti, transactionManager.TransactionObject))
                        {
                            break;
                        }
                        messCode = MessageCode.Success;
                    } while (false);
                    if (messCode == MessageCode.Success)
                    {
                        transactionManager.Commit();
                        MemcachedFactory.TeammembersClient.Delete(managerId);
                        MemcachedFactory.SolutionClient.Delete(managerId);
                        package.Shadow.Save();
                        int      orangeCount = 0;
                        string[] pIds        = playerString.Split(',');
                        foreach (var pId in pIds)
                        {
                            int id     = ConvertHelper.ConvertToInt(pId);
                            var player = CacheFactory.PlayersdicCache.GetPlayer(id);
                            if (player.CardLevel == (int)EnumPlayerCardLevel.Orange)
                            {
                                orangeCount++;
                            }
                        }
                        ActivityExThread.Instance.TememberColect(managerId, 3, orangeCount);
                    }
                    else
                    {
                        transactionManager.Rollback();
                        return(ResponseHelper.Create <NBSolutionInfoResponse>(messCode));
                    }
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("替换球员上场", ex);
            }
            KpiHandler.Instance.RebuildKpi(managerId, true);

            var response = SolutionAndTeammemberResponse(managerId);

            if (isChanagePlayer)
            {
                var pop = TaskHandler.Instance.SolutionChangePlayer(managerId);
                if (response.Data != null)
                {
                    response.Data.PopMsg = pop;
                }
            }

            return(response);
        }