/// <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 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); } } } }