private bool IsValidCoupleIfExist(int man, int wife) { bool result; lock (this.Mutex) { int manIdx; if (!this.SyncData.ThisWeek.RoleIndex.TryGetValue(man, out manIdx)) { manIdx = -1; } int wifeIdx; if (!this.SyncData.ThisWeek.RoleIndex.TryGetValue(wife, out wifeIdx)) { wifeIdx = -1; } if (manIdx != wifeIdx) { result = false; } else { if (manIdx != -1) { CoupleWishCoupleDataK coupleData = this.SyncData.ThisWeek.RankList[manIdx]; if ((coupleData.Man.RoleId != man || coupleData.Wife.RoleId != wife) && (coupleData.Man.RoleId != wife || coupleData.Wife.RoleId != man)) { return(false); } } result = true; } } return(result); }
/// <summary> /// 是否是有效的情侣组合,如何不存在,认为有效(首次) /// </summary> /// <param name="man"></param> /// <param name="wife"></param> /// <returns></returns> private bool IsValidCoupleIfExist(int man, int wife) { lock (Mutex) { int manIdx, wifeIdx; if (!this.SyncData.ThisWeek.RoleIndex.TryGetValue(man, out manIdx)) { manIdx = -1; } if (!this.SyncData.ThisWeek.RoleIndex.TryGetValue(wife, out wifeIdx)) { wifeIdx = -1; } // 丈夫和妻子存储的数据位置不同,即不是同一个数据 if (manIdx != wifeIdx) { return(false); } if (manIdx != -1) { // 如果有数据,检查数据正确性 CoupleWishCoupleDataK coupleData = this.SyncData.ThisWeek.RankList[manIdx]; if (coupleData.Man.RoleId != man || coupleData.Wife.RoleId != wife) { return(false); } } return(true); } }
public bool WriteCoupleData(int week, CoupleWishCoupleDataK coupleData) { bool result; try { string sql = string.Format("INSERT INTO t_couple_wish_group(`couple_id`,`man_rid`,`man_zoneid`,`man_rname`,`wife_rid`,`wife_zoneid`,`wife_rname`,`be_wish_num`,`rank`,`week`,`man_selector`,`wife_selector`) VALUES({0},{1},{2},'{3}',{4},{5},'{6}',{7},{8},{9},@man_selector,@wife_selector) ON DUPLICATE KEY UPDATE `man_rname`='{3}',`wife_rname`='{6}',`be_wish_num`={7},`rank`={8},`man_selector`=@man_selector,`wife_selector`=@wife_selector;", new object[] { coupleData.DbCoupleId, coupleData.Man.RoleId, coupleData.Man.ZoneId, coupleData.Man.RoleName, coupleData.Wife.RoleId, coupleData.Wife.ZoneId, coupleData.Wife.RoleName, coupleData.BeWishedNum, coupleData.Rank, week }); DbHelperMySQL.ExecuteSqlInsertImg(sql, new List <Tuple <string, byte[]> > { new Tuple <string, byte[]>("man_selector", coupleData.ManSelector), new Tuple <string, byte[]>("wife_selector", coupleData.WifeSelector) }); result = true; } catch (Exception ex) { LogManager.WriteLog(LogTypes.Error, string.Format("CoupleWish FlushRandList2Db failed, couple_id={0},man={1},wife={2}", coupleData.DbCoupleId, coupleData.Man.RoleId, coupleData.Wife.RoleId), ex, true); result = false; } return(result); }
private void HandleGetMainDataCommand(GameClient client, int nID, byte[] bytes, string[] cmdParams) { if (this.IsGongNengOpened(client)) { DateTime now = TimeUtil.NowDateTime(); CoupleWishMainData mainData = new CoupleWishMainData(); lock (this.Mutex) { mainData.RankList = new List <CoupleWishCoupleData>(this.ThisWeekTopNList); mainData.CanGetAwardId = this.CheckGiveAward(client); int idx; if (this.SyncData.ThisWeek.RoleIndex.TryGetValue(client.ClientData.RoleID, out idx)) { CoupleWishCoupleDataK coupleDataK = this.SyncData.ThisWeek.RankList[idx]; if (coupleDataK.Man.RoleId == client.ClientData.RoleID || coupleDataK.Wife.RoleId == client.ClientData.RoleID) { mainData.MyCoupleRank = coupleDataK.Rank; mainData.MyCoupleBeWishNum = coupleDataK.BeWishedNum; } } } mainData.MyCoupleManSelector = Global.sendToDB <RoleData4Selector, int>(10232, client.ClientData.RoleID, client.ServerId); if (MarryLogic.IsMarried(client.ClientData.RoleID)) { mainData.MyCoupleWifeSelector = Global.sendToDB <RoleData4Selector, int>(10232, client.ClientData.MyMarriageData.nSpouseID, client.ServerId); } if (client.ClientData.RoleSex == 1) { DataHelper2.Swap <RoleData4Selector>(ref mainData.MyCoupleManSelector, ref mainData.MyCoupleWifeSelector); } client.sendCmd <CoupleWishMainData>(nID, mainData, false); } }
public int CoupleWishPreDivorce(int man, int wife) { int result; lock (this.Mutex) { DateTime now = TimeUtil.NowDateTime(); if (!this.IsValidCoupleIfExist(man, wife)) { int week; if (!this._Config.IsInWishTime(now, out week)) { result = 1; } else { result = -11003; } } else { int week; if (this._Config.IsInWishTime(now, out week)) { int idx; if (this.SyncData.ThisWeek.RoleIndex.TryGetValue(man, out idx)) { CoupleWishCoupleDataK data = this.SyncData.ThisWeek.RankList[idx]; if (!this.Persistence.ClearCoupleData(data.DbCoupleId)) { return(-15); } this.SyncData.ThisWeek.RankList.RemoveAt(idx); this.SyncData.ThisWeek.BuildIndex(); this.IsNeedSort = true; } } if (this.SyncData.Statue.DbCoupleId > 0 && this.SyncData.Statue.Man != null && this.SyncData.Statue.Wife != null) { if (this.SyncData.Statue.Man.RoleId == man && this.SyncData.Statue.Wife.RoleId == wife && this.SyncData.Statue.IsDivorced != 1) { int oldDivorced = this.SyncData.Statue.IsDivorced; this.SyncData.Statue.IsDivorced = 1; if (!this.Persistence.WriteStatueData(this.SyncData.Statue)) { this.SyncData.Statue.IsDivorced = oldDivorced; return(-15); } this.SyncData.Statue.ModifyTime = now; } } result = 1; } } return(result); }
/// <summary> /// 从数据库加载排行榜 /// </summary> /// <returns></returns> public List <CoupleWishCoupleDataK> LoadRankFromDb(int week) { MySqlDataReader sdr = null; List <CoupleWishCoupleDataK> result = new List <CoupleWishCoupleDataK>(); try { string sql = string.Format("SELECT `couple_id`,`man_rid`,`man_zoneid`,`man_rname`,`man_selector`,`wife_rid`,`wife_zoneid`,`wife_rname`,`wife_selector`,`be_wish_num`,`rank` " + "FROM t_couple_wish_group WHERE `week`={0} ORDER BY `rank`;", week); sdr = DbHelperMySQL.ExecuteReader(sql); while (sdr != null && sdr.Read()) { CoupleWishCoupleDataK data = new CoupleWishCoupleDataK(); data.DbCoupleId = Convert.ToInt32(sdr["couple_id"]); data.Man = new KuaFuRoleMiniData(); data.Man.RoleId = Convert.ToInt32(sdr["man_rid"]); data.Man.ZoneId = Convert.ToInt32(sdr["man_zoneid"]); data.Man.RoleName = sdr["man_rname"].ToString(); if (!sdr.IsDBNull(sdr.GetOrdinal("man_selector"))) { data.ManSelector = (byte[])(sdr["man_selector"]); } data.Wife = new KuaFuRoleMiniData(); data.Wife.RoleId = Convert.ToInt32(sdr["wife_rid"]); data.Wife.ZoneId = Convert.ToInt32(sdr["wife_zoneid"]); data.Wife.RoleName = sdr["wife_rname"].ToString(); if (!sdr.IsDBNull(sdr.GetOrdinal("wife_selector"))) { data.WifeSelector = (byte[])(sdr["wife_selector"]); } data.BeWishedNum = Convert.ToInt32(sdr["be_wish_num"]); data.Rank = Convert.ToInt32(sdr["rank"]); result.Add(data); } } catch (Exception ex) { LogManager.WriteExceptionUseCache(ex.Message); } finally { if (sdr != null) { sdr.Close(); } } return(result); }
/// <summary> /// 离婚前清除数据 /// </summary> /// <param name="man"></param> /// <param name="wife"></param> /// <returns></returns> public int CoupleWishPreDivorce(int man, int wife) { lock (Mutex) { // 是否是有效的夫妻 if (!IsValidCoupleIfExist(man, wife)) { return(StdErrorCode.Error_Server_Internal_Error); } // 非祝福活动时间,离婚不影响排行榜 int week; DateTime now = TimeUtil.NowDateTime(); if (_Config.IsInWishTime(now, out week)) { int idx; if (this.SyncData.ThisWeek.RoleIndex.TryGetValue(man, out idx)) { CoupleWishCoupleDataK data = this.SyncData.ThisWeek.RankList[idx]; // 清除本周数据 if (!Persistence.ClearCoupleData(data.DbCoupleId)) { return(StdErrorCode.Error_DB_Faild); } this.SyncData.ThisWeek.RankList.RemoveAt(idx); this.SyncData.ThisWeek.BuildIndex(); this.IsNeedSort = true; } } if (SyncData.Statue.DbCoupleId > 0 && SyncData.Statue.Man != null && SyncData.Statue.Wife != null) { if (SyncData.Statue.Man.RoleId == man && SyncData.Statue.Wife.RoleId == wife && SyncData.Statue.IsDivorced != 1) { int oldDivorced = SyncData.Statue.IsDivorced; SyncData.Statue.IsDivorced = 1; if (!Persistence.WriteStatueData(SyncData.Statue)) { SyncData.Statue.IsDivorced = oldDivorced; return(StdErrorCode.Error_DB_Faild); } SyncData.Statue.ModifyTime = now; } } return(StdErrorCode.Error_Success); } }
/// <summary> /// 玩家查看情侣祝福主界面 /// </summary> /// <param name="client"></param> /// <param name="nID"></param> /// <param name="bytes"></param> /// <param name="cmdParams"></param> private void HandleGetMainDataCommand(GameClient client, int nID, byte[] bytes, string[] cmdParams) { if (!IsGongNengOpened(client)) { return; } DateTime now = TimeUtil.NowDateTime(); CoupleWishMainData mainData = new CoupleWishMainData(); lock (Mutex) { mainData.RankList = new List <CoupleWishCoupleData>(ThisWeekTopNList); mainData.CanGetAwardId = CheckGiveAward(client); int idx; if (SyncData.ThisWeek.RoleIndex.TryGetValue(client.ClientData.RoleID, out idx)) { CoupleWishCoupleDataK coupleDataK = SyncData.ThisWeek.RankList[idx]; if (coupleDataK.Man.RoleId == client.ClientData.RoleID || coupleDataK.Wife.RoleId == client.ClientData.RoleID) { mainData.MyCoupleRank = coupleDataK.Rank; mainData.MyCoupleBeWishNum = coupleDataK.BeWishedNum; } } } mainData.MyCoupleManSelector = Global.sendToDB <RoleData4Selector, string>((int)TCPGameServerCmds.CMD_SPR_GETROLEUSINGGOODSDATALIST, string.Format("{0}", client.ClientData.RoleID), client.ServerId); if (MarryLogic.IsMarried(client.ClientData.RoleID)) { mainData.MyCoupleWifeSelector = Global.sendToDB <RoleData4Selector, string>((int)TCPGameServerCmds.CMD_SPR_GETROLEUSINGGOODSDATALIST, string.Format("{0}", client.ClientData.MyMarriageData.nSpouseID), client.ServerId); } if (client.ClientData.RoleSex == (int)ERoleSex.Girl) { DataHelper2.Swap(ref mainData.MyCoupleManSelector, ref mainData.MyCoupleWifeSelector); } client.sendCmd(nID, mainData); }
public int CoupleWishWishRole(CoupleWishWishRoleReq req) { DateTime now = TimeUtil.NowDateTime(); long nowMs = now.Ticks / 10000L; int result; try { lock (this.Mutex) { if (this.SyncData.ThisWeek.Week != this.CurrRankWeek(now)) { result = -11000; } else { CoupleWishTypeConfig wishCfg = this._Config.WishTypeCfgList.Find((CoupleWishTypeConfig _w) => _w.WishType == req.WishType); if (wishCfg == null) { result = -3; } else { if (wishCfg.CooldownTime > 0) { if (this.WishCdControls.ContainsKey(req.WishType) && nowMs - this.WishCdControls[req.WishType] < (long)(wishCfg.CooldownTime * 1000)) { return(-30); } } CoupleWishCoupleDataK coupleData; if (req.IsWishRank) { int idx; if (!this.SyncData.ThisWeek.CoupleIdex.TryGetValue(req.ToCoupleId, out idx)) { return(-11); } coupleData = this.SyncData.ThisWeek.RankList[idx]; coupleData.BeWishedNum += wishCfg.GetWishNum; if (req.ToManSelector != null && req.ToWifeSelector != null) { coupleData.Man = req.ToMan; coupleData.ManSelector = req.ToManSelector; coupleData.Wife = req.ToWife; coupleData.WifeSelector = req.ToWifeSelector; this.Persistence.WriteCoupleData(this.SyncData.ThisWeek.Week, coupleData); } } else { if (req.ToManSelector == null || req.ToWifeSelector == null) { return(-11003); } if (!this.IsValidCoupleIfExist(req.ToMan.RoleId, req.ToWife.RoleId)) { return(-11003); } bool bFirstCreate = false; int idx; if (!this.SyncData.ThisWeek.RoleIndex.TryGetValue(req.ToMan.RoleId, out idx)) { bFirstCreate = true; coupleData = new CoupleWishCoupleDataK(); coupleData.DbCoupleId = this.Persistence.GetNextDbCoupleId(); coupleData.Rank = this.SyncData.ThisWeek.RankList.Count + 1; } else { coupleData = this.SyncData.ThisWeek.RankList[idx]; } coupleData.Man = req.ToMan; coupleData.ManSelector = req.ToManSelector; coupleData.Wife = req.ToWife; coupleData.WifeSelector = req.ToWifeSelector; coupleData.BeWishedNum += wishCfg.GetWishNum; if (!this.Persistence.WriteCoupleData(this.SyncData.ThisWeek.Week, coupleData)) { coupleData.BeWishedNum -= wishCfg.GetWishNum; return(-15); } if (bFirstCreate) { this.SyncData.ThisWeek.RankList.Add(coupleData); this.SyncData.ThisWeek.BuildIndex(); } } this.IsNeedSort = true; if (this.SyncData.ThisWeek.RankList.Count <= CoupleWishConsts.MaxRankNum || this.SyncData.ThisWeek.RankList.Last <CoupleWishCoupleDataK>().Rank <= CoupleWishConsts.MaxRankNum) { this.CheckSortRank(); } this.WishCdControls[req.WishType] = nowMs; this.WishRecordMgr.AddWishRecord(req.From, req.WishType, req.WishTxt, coupleData.DbCoupleId, coupleData.Man, coupleData.Wife); result = 1; } } } } catch (Exception ex) { LogManager.WriteExceptionUseCache(ex.Message); result = -11003; } return(result); }
/// <summary> /// 祝福情侣 /// </summary> /// <param name="req"></param> /// <returns></returns> public int CoupleWishWishRole(CoupleWishWishRoleReq req) { DateTime now = TimeUtil.NowDateTime(); long nowMs = now.Ticks / TimeSpan.TicksPerMillisecond; try { lock (Mutex) { if (this.SyncData.ThisWeek.Week != CurrRankWeek(now)) { return(StdErrorCode.Error_Server_Busy); } CoupleWishTypeConfig wishCfg = _Config.WishTypeCfgList.Find(_w => _w.WishType == req.WishType); if (wishCfg == null) { return(StdErrorCode.Error_Config_Fault); } if (wishCfg.CooldownTime > 0) { if (WishCdControls.ContainsKey(req.WishType) && nowMs - WishCdControls[req.WishType] < wishCfg.CooldownTime * 1000) { return(StdErrorCode.Error_Wish_Type_Is_In_CD); } } CoupleWishCoupleDataK coupleData = null; if (req.IsWishRank) { int idx; if (!SyncData.ThisWeek.CoupleIdex.TryGetValue(req.ToCoupleId, out idx)) { return(StdErrorCode.Error_Operation_Faild); } coupleData = SyncData.ThisWeek.RankList[idx]; coupleData.BeWishedNum += wishCfg.GetWishNum; if (req.ToManSelector != null && req.ToWifeSelector != null) { // 排行榜祝福,如果祝福者和被祝福者是同一服务器的,那么也会更新被祝福者的形象 coupleData.Man = req.ToMan; coupleData.ManSelector = req.ToManSelector; coupleData.Wife = req.ToWife; coupleData.WifeSelector = req.ToWifeSelector; Persistence.WriteCoupleData(this.SyncData.ThisWeek.Week, coupleData); } } else { // 本服祝福 if (req.ToManSelector == null || req.ToWifeSelector == null) { return(StdErrorCode.Error_Server_Internal_Error); } if (!IsValidCoupleIfExist(req.ToMan.RoleId, req.ToWife.RoleId)) { return(StdErrorCode.Error_Server_Internal_Error); } bool bFirstCreate = false; int idx; if (!this.SyncData.ThisWeek.RoleIndex.TryGetValue(req.ToMan.RoleId, out idx)) { // 首次被祝福 bFirstCreate = true; coupleData = new CoupleWishCoupleDataK(); coupleData.DbCoupleId = Persistence.GetNextDbCoupleId(); coupleData.Rank = this.SyncData.ThisWeek.RankList.Count + 1; } else { coupleData = this.SyncData.ThisWeek.RankList[idx]; } // 本服祝福会更新被祝福者形象 coupleData.Man = req.ToMan; coupleData.ManSelector = req.ToManSelector; coupleData.Wife = req.ToWife; coupleData.WifeSelector = req.ToWifeSelector; coupleData.BeWishedNum += wishCfg.GetWishNum; // 本服祝福,保证把形象更新到db if (!Persistence.WriteCoupleData(this.SyncData.ThisWeek.Week, coupleData)) { coupleData.BeWishedNum -= wishCfg.GetWishNum; return(StdErrorCode.Error_DB_Faild); } if (bFirstCreate) { this.SyncData.ThisWeek.RankList.Add(coupleData); this.SyncData.ThisWeek.BuildIndex(); } } this.IsNeedSort = true; if (this.SyncData.ThisWeek.RankList.Count <= CoupleWishConsts.MaxRankNum || this.SyncData.ThisWeek.RankList.Last().Rank <= CoupleWishConsts.MaxRankNum) { // 不足20名时,立即刷新 this.CheckSortRank(); } WishCdControls[req.WishType] = nowMs; WishRecordMgr.AddWishRecord(req.From, req.WishType, req.WishTxt, coupleData.DbCoupleId, coupleData.Man, coupleData.Wife); return(StdErrorCode.Error_Success); } } catch (Exception ex) { LogManager.WriteExceptionUseCache(ex.Message); return(StdErrorCode.Error_Server_Internal_Error); } }
/// <summary> /// 检测发奖 /// </summary> /// <param name="client"></param> /// <returns></returns> private int CheckGiveAward(GameClient client) { if (client == null) { return(0); } DateTime now = TimeUtil.NowDateTime(); int awardWeek; if (!_Config.IsInAwardTime(now, out awardWeek)) { return(0); } lock (Mutex) { string szAwardFlag = Global.GetRoleParamByName(client, RoleParamName.CoupleWishWeekAward); string[] fields = string.IsNullOrEmpty(szAwardFlag) ? null : szAwardFlag.Split(','); if (fields != null && fields.Length == 2 && Convert.ToInt32(fields[0]) == awardWeek) { return(0); } if (awardWeek != SyncData.LastWeek.Week) { return(0); } int idx; if (!SyncData.LastWeek.RoleIndex.TryGetValue(client.ClientData.RoleID, out idx)) { return(0); } CoupleWishCoupleDataK coupleData = SyncData.LastWeek.RankList[idx]; if (coupleData == null) { return(0); } if (coupleData.Man.RoleId != client.ClientData.RoleID && coupleData.Wife.RoleId != client.ClientData.RoleID) { return(0); } var wishAward = _Config.RankAwardCfgList.Find(_r => coupleData.Rank >= _r.StartRank && (_r.EndRank <= 0 || coupleData.Rank <= _r.EndRank)); if (wishAward == null) { return(0); } List <GoodsData> goodsList = new List <GoodsData>(); goodsList.AddRange(wishAward.GoodsOneTag as List <GoodsData>); goodsList.AddRange((wishAward.GoodsTwoTag as List <GoodsData>).FindAll(_g => Global.IsCanGiveRewardByOccupation(client, _g.GoodsID))); if (Global.CanAddGoodsDataList(client, goodsList)) { foreach (var goodsData in goodsList) { Global.AddGoodsDBCommand_Hook(Global._TCPManager.TcpOutPacketPool, client, goodsData.GoodsID, goodsData.GCount, goodsData.Quality, goodsData.Props, goodsData.Forge_level, goodsData.Binding, 0, goodsData.Jewellist, true, 1, "情侣排行榜", false, goodsData.Endtime, goodsData.AddPropIndex, goodsData.BornIndex, goodsData.Lucky, goodsData.Strong, goodsData.ExcellenceInfo, goodsData.AppendPropLev, goodsData.ChangeLifeLevForEquip, true); } } else { Global.UseMailGivePlayerAward3(client.ClientData.RoleID, goodsList, "情侣祝福榜", string.Format("情侣祝福榜第{0}名奖励,请查收!", coupleData.Rank), 0); } Global.SaveRoleParamsStringToDB(client, RoleParamName.CoupleWishWeekAward, string.Format("{0},{1}", awardWeek, wishAward.Id), true); CheckTipsIconState(client); return(wishAward.Id); } return(0); }
/// <summary> /// 玩家请求祝福他人 /// </summary> /// <param name="client"></param> /// <param name="nID"></param> /// <param name="bytes"></param> /// <param name="cmdParams"></param> private void HandleWishOtherRoleCommand(GameClient client, int nID, byte[] bytes, string[] cmdParams) { var cliReq = DataHelper.BytesToObject <CoupleWishWishReqData>(bytes, 0, bytes.Length); DateTime now = TimeUtil.NowDateTime(); if (client.ClientSocket.IsKuaFuLogin) { client.sendCmd(nID, StdErrorCode.Error_Operation_Denied.ToString()); return; } if (cliReq.CostType != (int)CoupleWishWishReqData.ECostType.Goods && cliReq.CostType != (int)CoupleWishWishReqData.ECostType.ZuanShi) { client.sendCmd(nID, StdErrorCode.Error_Invalid_Params.ToString()); return; } // 是否是活动时间 int wishWeek; if (!_Config.IsInWishTime(now, out wishWeek)) { client.sendCmd(nID, StdErrorCode.Error_Wish_In_Balance_Time.ToString()); return; } // 祝福类型检查 CoupleWishTypeConfig wishCfg = _Config.WishTypeCfgList.Find(_w => _w.WishType == cliReq.WishType); if (wishCfg == null) { client.sendCmd(nID, StdErrorCode.Error_Config_Fault.ToString()); return; } // 道具检查 if (cliReq.CostType == (int)CoupleWishWishReqData.ECostType.Goods && wishCfg.CostGoodsId > 0 && wishCfg.CostGoodsNum > 0 && Global.GetTotalGoodsCountByID(client, wishCfg.CostGoodsId) < wishCfg.CostGoodsNum) { client.sendCmd(nID, StdErrorCode.Error_Goods_Not_Enough.ToString()); return; } // 钻石检查 if (cliReq.CostType == (int)CoupleWishWishReqData.ECostType.ZuanShi && wishCfg.CostZuanShi > 0 && client.ClientData.UserMoney < wishCfg.CostZuanShi) { client.sendCmd(nID, StdErrorCode.Error_ZuanShi_Not_Enough.ToString()); return; } // 祝福寄语检查 if (!string.IsNullOrEmpty(cliReq.WishTxt)) { if (wishCfg.CanHaveWishTxt != 1) { client.sendCmd(nID, StdErrorCode.Error_Cannot_Have_Wish_Txt.ToString()); return; } else if (cliReq.WishTxt.Length > CoupleWishConsts.MaxWishTxtLen) { client.sendCmd(nID, StdErrorCode.Error_Wish_Txt_Length_Limit.ToString()); return; } } CoupleWishWishRoleReq centerReq = new CoupleWishWishRoleReq(); centerReq.From.RoleId = client.ClientData.RoleID; centerReq.From.ZoneId = client.ClientData.ZoneID; centerReq.From.RoleName = client.ClientData.RoleName; centerReq.WishType = cliReq.WishType; centerReq.WishTxt = cliReq.WishTxt; RoleData4Selector toManSelector = null; RoleData4Selector toWifeSelector = null; CoupleWishCoupleDataK rankCoupleData = null; if (cliReq.IsWishRankRole) { centerReq.IsWishRank = true; // 跨服排行榜祝福 lock (Mutex) { int coupleIdx; if (!this.SyncData.ThisWeek.CoupleIdex.TryGetValue(cliReq.ToRankCoupleId, out coupleIdx)) { client.sendCmd(nID, StdErrorCode.Error_Operation_Denied.ToString()); return; } rankCoupleData = this.SyncData.ThisWeek.RankList[coupleIdx]; if (rankCoupleData == null || rankCoupleData.DbCoupleId != cliReq.ToRankCoupleId || rankCoupleData.Rank > CoupleWishConsts.MaxRankNum * 2) { // 因为客户端看到的不是实时的数据,客户端看到的时候某对情侣可能处于前20名,但是当祝福的时候,可能已经不是前20名了,优化下体验,如果是前40名就允许 client.sendCmd(nID, StdErrorCode.Error_Operation_Denied.ToString()); return; } centerReq.ToCoupleId = cliReq.ToRankCoupleId; // 赠送排行榜情侣,检测是否是本服的情侣,尝试更新角色形象 toManSelector = Global.sendToDB <RoleData4Selector, string>((int)TCPGameServerCmds.CMD_SPR_GETROLEUSINGGOODSDATALIST, string.Format("{0}", rankCoupleData.Man.RoleId), client.ServerId); toWifeSelector = Global.sendToDB <RoleData4Selector, string>((int)TCPGameServerCmds.CMD_SPR_GETROLEUSINGGOODSDATALIST, string.Format("{0}", rankCoupleData.Wife.RoleId), client.ServerId); if (toManSelector == null || toWifeSelector == null || toManSelector.RoleID <= 0 || toWifeSelector.RoleID <= 0) { toManSelector = toWifeSelector = null; } } } else { // 本服祝福 int toRoleId = -1; if (!string.IsNullOrEmpty(cliReq.ToLocalRoleName)) { toRoleId = RoleName2IDs.FindRoleIDByName(cliReq.ToLocalRoleName, true); } if (toRoleId <= 0) { client.sendCmd(nID, StdErrorCode.Error_Wish_Player_Not_Exist.ToString()); return; } if (toRoleId == client.ClientData.RoleID) { client.sendCmd(nID, StdErrorCode.Error_Cannot_Wish_Self.ToString()); return; } int nSpouseId = MarryLogic.GetSpouseID(toRoleId); if (nSpouseId <= 0) { client.sendCmd(nID, StdErrorCode.Error_Wish_Player_Not_Marry.ToString()); return; } toManSelector = Global.sendToDB <RoleData4Selector, string>((int)TCPGameServerCmds.CMD_SPR_GETROLEUSINGGOODSDATALIST, string.Format("{0}", toRoleId), client.ServerId); toWifeSelector = Global.sendToDB <RoleData4Selector, string>((int)TCPGameServerCmds.CMD_SPR_GETROLEUSINGGOODSDATALIST, string.Format("{0}", nSpouseId), client.ServerId); if (toManSelector == null || toWifeSelector == null || toManSelector.RoleSex == toWifeSelector.RoleSex) { client.sendCmd(nID, StdErrorCode.Error_DB_Faild.ToString()); return; } if (toManSelector.RoleSex == (int)ERoleSex.Girl) { DataHelper2.Swap(ref toManSelector, ref toWifeSelector); } } if (toManSelector != null && toWifeSelector != null) { // 不管是排行榜赠送还是选中好友赠送,都尝试更新被赠送者形象数据 // 排行榜赠送时,toManSelector和toWifeSelector可能都为null,或者都不为null // 选中好友赠送,toManSelector和toWifeSelector一定都不为null centerReq.ToMan.RoleId = toManSelector.RoleID; centerReq.ToMan.ZoneId = toManSelector.ZoneId; centerReq.ToMan.RoleName = toManSelector.RoleName; centerReq.ToManSelector = DataHelper.ObjectToBytes <RoleData4Selector>(toManSelector); centerReq.ToWife.RoleId = toWifeSelector.RoleID; centerReq.ToWife.ZoneId = toWifeSelector.ZoneId; centerReq.ToWife.RoleName = toWifeSelector.RoleName; centerReq.ToWifeSelector = DataHelper.ObjectToBytes <RoleData4Selector>(toWifeSelector); } int ec = TianTiClient.getInstance().CoupleWishWishRole(centerReq); if (ec < 0) { client.sendCmd(nID, ec.ToString()); return; } // 扣除物品 if (cliReq.CostType == (int)CoupleWishWishReqData.ECostType.Goods && wishCfg.CostGoodsId > 0 && wishCfg.CostGoodsNum > 0) { bool oneUseBind = false; bool oneUseTimeLimit = false; Global.UseGoodsBindOrNot(client, wishCfg.CostGoodsId, wishCfg.CostGoodsNum, true, out oneUseBind, out oneUseTimeLimit); } // 扣除钻石 if (cliReq.CostType == (int)CoupleWishWishReqData.ECostType.ZuanShi && wishCfg.CostZuanShi > 0) { GameManager.ClientMgr.SubUserMoney(Global._TCPManager.MySocketListener, Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, client, wishCfg.CostZuanShi, "情侣祝福"); } // 增加本服祝福特效 if (wishCfg.IsHaveEffect == 1) { CoupleWishNtfWishEffectData effectData = new CoupleWishNtfWishEffectData(); effectData.From = centerReq.From; effectData.WishType = cliReq.WishType; effectData.WishTxt = cliReq.WishTxt; effectData.To = new List <KuaFuRoleMiniData>(); if (cliReq.IsWishRankRole) { effectData.To.Add(rankCoupleData.Man); effectData.To.Add(rankCoupleData.Wife); } else { if (centerReq.ToMan.RoleName == cliReq.ToLocalRoleName) { effectData.To.Add(centerReq.ToMan); } else { effectData.To.Add(centerReq.ToWife); } } lock (Mutex) { // 这里必须锁住,不然多个人同时祝福,都有可能修改所有在线玩家的奖励数据 HandleWishEffect(effectData); } } client.sendCmd(nID, StdErrorCode.Error_Success.ToString()); }
private int CheckGiveAward(GameClient client) { int result; if (client == null) { result = 0; } else { DateTime now = TimeUtil.NowDateTime(); int awardWeek; if (!this._Config.IsInAwardTime(now, out awardWeek)) { result = 0; } else { lock (this.Mutex) { string szAwardFlag = Global.GetRoleParamByName(client, "29"); string[] fields = string.IsNullOrEmpty(szAwardFlag) ? null : szAwardFlag.Split(new char[] { ',' }); int idx; if (fields != null && fields.Length == 2 && Convert.ToInt32(fields[0]) == awardWeek) { result = 0; } else if (awardWeek != this.SyncData.LastWeek.Week) { result = 0; } else if (!this.SyncData.LastWeek.RoleIndex.TryGetValue(client.ClientData.RoleID, out idx)) { result = 0; } else { CoupleWishCoupleDataK coupleData = this.SyncData.LastWeek.RankList[idx]; if (coupleData == null) { result = 0; } else if (coupleData.Man.RoleId != client.ClientData.RoleID && coupleData.Wife.RoleId != client.ClientData.RoleID) { result = 0; } else { CoupleWishRankAwardConfig wishAward = this._Config.RankAwardCfgList.Find((CoupleWishRankAwardConfig _r) => coupleData.Rank >= _r.StartRank && (_r.EndRank <= 0 || coupleData.Rank <= _r.EndRank)); if (wishAward == null) { result = 0; } else { List <GoodsData> goodsList = new List <GoodsData>(); goodsList.AddRange(wishAward.GoodsOneTag as List <GoodsData>); goodsList.AddRange((wishAward.GoodsTwoTag as List <GoodsData>).FindAll((GoodsData _g) => Global.IsCanGiveRewardByOccupation(client, _g.GoodsID))); if (Global.CanAddGoodsDataList(client, goodsList)) { foreach (GoodsData goodsData in goodsList) { Global.AddGoodsDBCommand_Hook(Global._TCPManager.TcpOutPacketPool, client, goodsData.GoodsID, goodsData.GCount, goodsData.Quality, goodsData.Props, goodsData.Forge_level, goodsData.Binding, 0, goodsData.Jewellist, true, 1, "情侣排行榜", false, goodsData.Endtime, goodsData.AddPropIndex, goodsData.BornIndex, goodsData.Lucky, goodsData.Strong, goodsData.ExcellenceInfo, goodsData.AppendPropLev, goodsData.ChangeLifeLevForEquip, true, null, null, "1900-01-01 12:00:00", 0, true); } } else { Global.UseMailGivePlayerAward3(client.ClientData.RoleID, goodsList, GLang.GetLang(479, new object[0]), string.Format(GLang.GetLang(480, new object[0]), coupleData.Rank), 0, 0, 0); } Global.SaveRoleParamsStringToDB(client, "29", string.Format("{0},{1}", awardWeek, wishAward.Id), true); this.CheckTipsIconState(client); result = wishAward.Id; } } } } } } return(result); }
private void HandleWishOtherRoleCommand(GameClient client, int nID, byte[] bytes, string[] cmdParams) { CoupleWishWishReqData cliReq = DataHelper.BytesToObject <CoupleWishWishReqData>(bytes, 0, bytes.Length); DateTime now = TimeUtil.NowDateTime(); int wishWeek; if (client.ClientSocket.IsKuaFuLogin) { client.sendCmd(nID, -12); } else if (cliReq.CostType != 1 && cliReq.CostType != 2) { client.sendCmd(nID, -18); } else if (!this._Config.IsInWishTime(now, out wishWeek)) { client.sendCmd(nID, -31); } else { CoupleWishTypeConfig wishCfg = this._Config.WishTypeCfgList.Find((CoupleWishTypeConfig _w) => _w.WishType == cliReq.WishType); if (wishCfg == null) { client.sendCmd(nID, -3); } else if (cliReq.CostType == 1 && wishCfg.CostGoodsId > 0 && wishCfg.CostGoodsNum > 0 && Global.GetTotalGoodsCountByID(client, wishCfg.CostGoodsId) < wishCfg.CostGoodsNum) { client.sendCmd(nID, -6, false); } else if (cliReq.CostType == 2 && wishCfg.CostZuanShi > 0 && client.ClientData.UserMoney < wishCfg.CostZuanShi) { client.sendCmd(nID, -10, false); } else { if (!string.IsNullOrEmpty(cliReq.WishTxt)) { if (wishCfg.CanHaveWishTxt != 1) { client.sendCmd(nID, -25, false); return; } if (cliReq.WishTxt.Length > CoupleWishConsts.MaxWishTxtLen) { client.sendCmd(nID, -26, false); return; } } CoupleWishWishRoleReq centerReq = new CoupleWishWishRoleReq(); centerReq.From.RoleId = client.ClientData.RoleID; centerReq.From.ZoneId = client.ClientData.ZoneID; centerReq.From.RoleName = client.ClientData.RoleName; centerReq.WishType = cliReq.WishType; centerReq.WishTxt = cliReq.WishTxt; RoleData4Selector toManSelector = null; RoleData4Selector toWifeSelector = null; CoupleWishCoupleDataK rankCoupleData = null; if (cliReq.IsWishRankRole) { centerReq.IsWishRank = true; lock (this.Mutex) { int coupleIdx; if (!this.SyncData.ThisWeek.CoupleIdex.TryGetValue(cliReq.ToRankCoupleId, out coupleIdx)) { client.sendCmd(nID, -12, false); return; } rankCoupleData = this.SyncData.ThisWeek.RankList[coupleIdx]; if (rankCoupleData == null || rankCoupleData.DbCoupleId != cliReq.ToRankCoupleId || rankCoupleData.Rank > CoupleWishConsts.MaxRankNum * 2) { client.sendCmd(nID, -12, false); return; } centerReq.ToCoupleId = cliReq.ToRankCoupleId; toManSelector = Global.sendToDB <RoleData4Selector, int>(10232, rankCoupleData.Man.RoleId, client.ServerId); toWifeSelector = Global.sendToDB <RoleData4Selector, int>(10232, rankCoupleData.Wife.RoleId, client.ServerId); if (toManSelector == null || toWifeSelector == null || toManSelector.RoleID <= 0 || toWifeSelector.RoleID <= 0) { toWifeSelector = (toManSelector = null); } } } else { int toRoleId = -1; if (!string.IsNullOrEmpty(cliReq.ToLocalRoleName)) { toRoleId = RoleName2IDs.FindRoleIDByName(cliReq.ToLocalRoleName, true); } if (toRoleId <= 0) { client.sendCmd(nID, -28, false); return; } if (toRoleId == client.ClientData.RoleID) { client.sendCmd(nID, -27, false); return; } int nSpouseId = MarryLogic.GetSpouseID(toRoleId); if (nSpouseId <= 0) { client.sendCmd(nID, -29, false); return; } toManSelector = Global.sendToDB <RoleData4Selector, int>(10232, toRoleId, client.ServerId); toWifeSelector = Global.sendToDB <RoleData4Selector, int>(10232, nSpouseId, client.ServerId); if (toManSelector == null || toWifeSelector == null) { client.sendCmd(nID, -15, false); return; } if (!MarryLogic.SameSexMarry(false)) { if (toManSelector.RoleSex == toWifeSelector.RoleSex) { client.sendCmd(nID, -15, false); return; } if (toManSelector.RoleSex == 1) { DataHelper2.Swap <RoleData4Selector>(ref toManSelector, ref toWifeSelector); } } } if (toManSelector != null && toWifeSelector != null) { centerReq.ToMan.RoleId = toManSelector.RoleID; centerReq.ToMan.ZoneId = toManSelector.ZoneId; centerReq.ToMan.RoleName = toManSelector.RoleName; centerReq.ToManSelector = DataHelper.ObjectToBytes <RoleData4Selector>(toManSelector); centerReq.ToWife.RoleId = toWifeSelector.RoleID; centerReq.ToWife.ZoneId = toWifeSelector.ZoneId; centerReq.ToWife.RoleName = toWifeSelector.RoleName; centerReq.ToWifeSelector = DataHelper.ObjectToBytes <RoleData4Selector>(toWifeSelector); } int ec = TianTiClient.getInstance().CoupleWishWishRole(centerReq); if (ec < 0) { client.sendCmd(nID, ec); } else { if (cliReq.CostType == 1 && wishCfg.CostGoodsId > 0 && wishCfg.CostGoodsNum > 0) { bool oneUseBind = false; bool oneUseTimeLimit = false; Global.UseGoodsBindOrNot(client, wishCfg.CostGoodsId, wishCfg.CostGoodsNum, true, out oneUseBind, out oneUseTimeLimit); } if (cliReq.CostType == 2 && wishCfg.CostZuanShi > 0) { GameManager.ClientMgr.SubUserMoney(Global._TCPManager.MySocketListener, Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, client, wishCfg.CostZuanShi, "情侣祝福", true, true, false, DaiBiSySType.None); } if (wishCfg.IsHaveEffect == 1) { CoupleWishNtfWishEffectData effectData = new CoupleWishNtfWishEffectData(); effectData.From = centerReq.From; effectData.WishType = cliReq.WishType; effectData.WishTxt = cliReq.WishTxt; effectData.To = new List <KuaFuRoleMiniData>(); if (cliReq.IsWishRankRole) { effectData.To.Add(rankCoupleData.Man); effectData.To.Add(rankCoupleData.Wife); } else if (centerReq.ToMan.RoleName == cliReq.ToLocalRoleName) { effectData.To.Add(centerReq.ToMan); } else { effectData.To.Add(centerReq.ToWife); } lock (this.Mutex) { this.HandleWishEffect(effectData); } } client.sendCmd(nID, 1); } } } }