private static FundData FundGetData(GameClient client) { FundData fundData = FundManager.GetFundData(client); bool isOpen = FundManager.IsGongNengOpened(client, false); if (fundData.IsOpen != isOpen) { FundManager.initFundData(client); } return(FundManager.GetFundData(client)); }
public static void initFundData(GameClient client) { lock (client.ClientData.LockFund) { FundData fundData = new FundData(); if (!FundManager.IsGongNengOpened(client, false)) { client.ClientData.MyFundData = fundData; } else { fundData.IsOpen = true; fundData.FundDic.Add(1, FundManager.initFundItem(client, EFund.ChangeLife)); fundData.FundDic.Add(2, FundManager.initFundItem(client, EFund.Login)); fundData.FundDic.Add(3, FundManager.initFundItem(client, EFund.Money)); List <FundDBItem> dbItemList = FundManager.DBFundInfo(client); if (dbItemList == null) { client.ClientData.MyFundData = fundData; } else { foreach (FundDBItem dbItem in dbItemList) { if (fundData.FundDic.ContainsKey(dbItem.FundType) && dbItem.State > 0) { FundItem fundItem = fundData.FundDic[dbItem.FundType]; fundItem.BuyType = 1; fundItem.BuyTime = dbItem.BuyTime; fundItem.FundID = dbItem.FundID; fundItem.AwardID = dbItem.AwardID; fundItem.AwardType = 1; if (fundItem.FundType == 3) { fundItem.Value1 = dbItem.Value1; fundItem.Value2 = dbItem.Value2; } if (fundItem.FundType == 2 && fundItem.BuyTime > DateTime.MinValue) { fundItem.Value1 = Global.GetOffsetDay(TimeUtil.NowDateTime()) - Global.GetOffsetDay(fundItem.BuyTime) + 1; } if (dbItem.State == 1) { FundManager.initFundAwardNext(client, fundItem); } } } client.ClientData.MyFundData = fundData; FundManager.CheckActivityTip(client); } } } }
/// <summary> /// 基金——数据 /// </summary> private static FundData FundGetData(GameClient client) { FundData fundData = GetFundData(client); bool isOpen = IsGongNengOpened(client); if (fundData.IsOpen != isOpen) { initFundData(client); } return(GetFundData(client)); }
public bool ProcessFundInfoCmd(GameClient client, int nID, byte[] bytes, string[] cmdParams) { try { if (!CheckHelper.CheckCmdLengthAndRole(client, nID, cmdParams, 1)) { return(false); } FundData data = FundManager.FundGetData(client); client.sendCmd <FundData>(1032, data, false); return(true); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(client.ClientSocket), false, false); } return(false); }
public bool ProcessFundBuyCmd(GameClient client, int nID, byte[] bytes, string[] cmdParams) { try { if (!CheckHelper.CheckCmdLength(client, nID, cmdParams, 1)) { return(false); } int fundType = int.Parse(cmdParams[0]); FundData data = FundManager.FundBuy(client, fundType); client.sendCmd <FundData>(1033, data, false); return(true); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(client.ClientSocket), false, false); } return(false); }
public static void FundMoneyCost(GameClient client, int moneyCost) { FundData fundData = GetFundData(client); if (fundData == null || !fundData.IsOpen) { return; } if (!fundData.FundDic.ContainsKey((int)EFund.Money)) { return; } FundItem fundItem = fundData.FundDic[(int)EFund.Money]; if (fundItem.BuyType != (int)EFundBuy.Have) { return; } FundDBItem dbItem = new FundDBItem(); dbItem.UserID = client.strUserID; dbItem.RoleID = client.ClientData.RoleID; dbItem.Value1 = 0; dbItem.Value2 = moneyCost; bool result = DBFundMoney(client, dbItem); if (!result) { return; } fundItem.Value2 += moneyCost; FundAwardInfo awardInfo = _fundAwardDic[fundItem.AwardID]; if (fundItem.AwardType == (int)EFundAward.Limit && fundItem.Value1 >= awardInfo.Value1 && fundItem.Value2 >= awardInfo.Value2) { fundItem.AwardType = (int)EFundAward.Can; CheckActivityTip(client); } }
private static void CheckActivityTip(GameClient client) { lock (client.ClientData.LockFund) { FundData fundData = GetFundData(client); if (!fundData.IsOpen) { return; } bool isChange = false; bool isAll = false; List <int> tipTypeList = new List <int>(); foreach (var item in fundData.FundDic.Values) { bool tip = (item.BuyType == (int)EFundBuy.Can || item.AwardType == (int)EFundAward.Can); isAll |= tip; switch (item.FundType) { case (int)EFund.ChangeLife: isChange |= client._IconStateMgr.AddFlushIconState((ushort)ActivityTipTypes.FundChangeLife, tip); break; case (int)EFund.Login: isChange |= client._IconStateMgr.AddFlushIconState((ushort)ActivityTipTypes.FundLogin, tip); break; case (int)EFund.Money: isChange |= client._IconStateMgr.AddFlushIconState((ushort)ActivityTipTypes.FundMoney, tip); break; } } isChange |= client._IconStateMgr.AddFlushIconState((ushort)ActivityTipTypes.Fund, isAll); if (isChange) { client._IconStateMgr.SendIconStateToClient(client); } } }
public bool ProcessFundInfoCmd(GameClient client, int nID, byte[] bytes, string[] cmdParams) { try { bool isCheck = CheckHelper.CheckCmdLengthAndRole(client, nID, cmdParams, 1); if (!isCheck) { return(false); } FundData data = FundGetData(client); client.sendCmd((int)TCPGameServerCmds.CMD_SPR_FUND_INFO, data); return(true); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(client.ClientSocket), false); } return(false); }
public static void FundChangeLife(GameClient client) { FundData fundData = FundManager.GetFundData(client); if (fundData != null && fundData.IsOpen) { if (fundData.FundDic.ContainsKey(1)) { FundItem fundItem = fundData.FundDic[1]; fundItem.Value1 = client.ClientData.ChangeLifeCount; fundItem.Value2 = client.ClientData.Level; if (fundItem.BuyType == 1 && fundItem.AwardType == 3) { FundAwardInfo awardInfo = FundManager._fundAwardDic[fundItem.AwardID]; if (fundItem.Value1 >= awardInfo.Value1 && fundItem.Value2 >= awardInfo.Value2) { fundItem.AwardType = 2; FundManager.CheckActivityTip(client); } } } } }
public bool ProcessFundAwardCmd(GameClient client, int nID, byte[] bytes, string[] cmdParams) { try { bool isCheck = CheckHelper.CheckCmdLength(client, nID, cmdParams, 1); if (!isCheck) { return(false); } int fundType = int.Parse(cmdParams[0]); FundData data = FundAward(client, fundType); client.sendCmd((int)TCPGameServerCmds.CMD_SPR_FUND_AWARD, data); return(true); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(client.ClientSocket), false); } return(false); }
private static void CheckActivityTip(GameClient client) { lock (client.ClientData.LockFund) { FundData fundData = FundManager.GetFundData(client); if (fundData.IsOpen) { bool isChange = false; bool isAll = false; List <int> tipTypeList = new List <int>(); foreach (FundItem item in fundData.FundDic.Values) { bool tip = item.BuyType == 2 || item.AwardType == 2; isAll = (isAll || tip); switch (item.FundType) { case 1: isChange |= client._IconStateMgr.AddFlushIconState(14106, tip); break; case 2: isChange |= client._IconStateMgr.AddFlushIconState(14107, tip); break; case 3: isChange |= client._IconStateMgr.AddFlushIconState(14108, tip); break; } } isChange |= client._IconStateMgr.AddFlushIconState(14109, isAll); if (isChange) { client._IconStateMgr.SendIconStateToClient(client); } } } }
private static FundData FundAward(GameClient client, int fundType) { FundData myData = FundManager.GetFundData(client); FundData result; if (!myData.IsOpen) { result = myData; } else { myData.FundType = fundType; if (!myData.FundDic.ContainsKey(fundType)) { myData.State = -1; result = myData; } else { FundItem myItem = myData.FundDic[fundType]; if (myItem.BuyType != 1) { myData.State = -8; result = myData; } else if (myItem.AwardType == 3) { myData.State = -6; result = myData; } else if (myItem.AwardType == 1) { myData.State = -7; result = myData; } else { DateTime buyTime = TimeUtil.NowDateTime(); FundDBItem dbItem = new FundDBItem(); dbItem.zoneID = client.ClientData.ZoneID; dbItem.UserID = client.strUserID; dbItem.RoleID = client.ClientData.RoleID; dbItem.FundType = myData.FundType; dbItem.FundID = myItem.FundID; dbItem.BuyTime = buyTime; dbItem.AwardID = myItem.AwardID; int fundState = 1; bool isAwardMax = (from info in FundManager._fundAwardDic.Values where info.FundType == myItem.FundType && info.FundID == myItem.FundID && info.AwardID > myItem.AwardID select info).Any <FundAwardInfo>(); bool isFundMax = (from info in FundManager._fundDic.Values where info.FundType == myItem.FundType && info.FundID > myItem.FundID select info).Any <FundInfo>(); if (!isAwardMax && !isFundMax) { fundState = 2; } dbItem.State = fundState; if (!FundManager.DBFundAward(client, dbItem)) { myData.State = -1; result = myData; } else { FundAwardInfo awardInfo = FundManager._fundAwardDic[myItem.AwardID]; if (!FundManager.AddDiamone(client, awardInfo.AwardIsBind, awardInfo.AwardCount)) { myData.State = -1; result = myData; } else { myData.State = 1; if (dbItem.State == 2) { myItem.AwardType = 1; FundManager.CheckActivityTip(client); result = myData; } else { FundManager.initFundAwardNext(client, myItem); FundManager.CheckActivityTip(client); myData.FundType = fundType; result = myData; } } } } } } return(result); }
private static FundData FundBuy(GameClient client, int fundType) { FundData myData = FundManager.GetFundData(client); FundData result; if (!myData.IsOpen) { result = myData; } else { myData.FundType = fundType; if (GameFuncControlManager.IsGameFuncDisabled(GameFuncType.System1Dot9)) { myData.State = -2; result = myData; } else if (!myData.FundDic.ContainsKey(fundType)) { myData.State = -1; result = myData; } else { FundItem myItem = myData.FundDic[fundType]; if (myItem.BuyType == 1) { myData.State = -4; result = myData; } else if (myItem.BuyType == 3) { myData.State = -5; result = myData; } else { FundInfo fundInfo = FundManager._fundDic[myItem.FundID]; if (fundInfo.Price > client.ClientData.UserMoney) { myData.State = -3; result = myData; } else if (!GameManager.ClientMgr.SubUserMoney(Global._TCPManager.MySocketListener, Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, client, fundInfo.Price, "基金购买", true, false, false, DaiBiSySType.None)) { myData.State = -1; result = myData; } else { DateTime buyTime = TimeUtil.NowDateTime(); if (!FundManager.DBFundBuy(client, new FundDBItem { zoneID = client.ClientData.ZoneID, UserID = client.strUserID, RoleID = client.ClientData.RoleID, FundType = myData.FundType, FundID = myItem.FundID, BuyTime = buyTime, State = 1 })) { myData.State = -1; result = myData; } else { myItem.BuyType = 1; myItem.BuyTime = buyTime; if (myItem.FundType == 2) { myItem.Value1 = Global.GetOffsetDay(TimeUtil.NowDateTime()) - Global.GetOffsetDay(myItem.BuyTime) + 1; } FundAwardInfo awardInfo = FundManager._fundAwardDic[myItem.AwardID]; if (myItem.Value1 >= awardInfo.Value1 && myItem.Value2 >= awardInfo.Value2) { myItem.AwardType = 2; } else { myItem.AwardType = 3; } myData.State = 1; myData.FundType = fundType; FundManager.CheckActivityTip(client); result = myData; } } } } } return(result); }
/// <summary> /// 基金——领奖 /// </summary> private static FundData FundAward(GameClient client, int fundType) { FundData myData = GetFundData(client); if (!myData.IsOpen) { return(myData); } myData.FundType = fundType; //类型错误 if (!myData.FundDic.ContainsKey(fundType)) { myData.State = (int)EFundError.Error; return(myData); } //未购买 FundItem myItem = myData.FundDic[fundType]; if (myItem.BuyType != (int)EFundBuy.Have) { myData.State = (int)EFundError.ENoBuy; return(myData); } //未达到领奖条件 if (myItem.AwardType == (int)EFundAward.Limit) { myData.State = (int)EFundError.EAwardLimit; return(myData); } //已经领取 if (myItem.AwardType == (int)EFundAward.Have) { myData.State = (int)EFundError.EAward; return(myData); } //数据库保存 DateTime buyTime = DateTime.Now; FundDBItem dbItem = new FundDBItem(); dbItem.zoneID = client.ClientData.ZoneID; dbItem.UserID = client.strUserID; dbItem.RoleID = client.ClientData.RoleID; dbItem.FundType = myData.FundType; dbItem.FundID = myItem.FundID; dbItem.BuyTime = buyTime; dbItem.AwardID = myItem.AwardID; int fundState = (int)EFundState.Now; //最大奖励 bool isAwardMax = (from info in _fundAwardDic.Values where info.FundType == myItem.FundType && info.FundID == myItem.FundID && info.AwardID > myItem.AwardID select info).Any(); //最大基金 bool isFundMax = (from info in _fundDic.Values where info.FundType == myItem.FundType && info.FundID > myItem.FundID select info).Any(); if (!isAwardMax && !isFundMax) { fundState = (int)EFundState.End; } dbItem.State = fundState; if (!DBFundAward(client, dbItem)) { myData.State = (int)EFundError.Error; return(myData); } //领取奖励 FundAwardInfo awardInfo = _fundAwardDic[myItem.AwardID]; bool isAddDiamond = AddDiamone(client, awardInfo.AwardIsBind, awardInfo.AwardCount); if (!isAddDiamond) { myData.State = (int)EFundError.Error; return(myData); } // myData.State = (int)EFundError.Succ; if (dbItem.State == (int)EFundState.End) { myItem.AwardType = (int)EFundAward.Have; CheckActivityTip(client); return(myData); } initFundAwardNext(client, myItem); CheckActivityTip(client); myData.FundType = fundType; return(myData); }
/// <summary> /// 基金——购买 /// </summary> private static FundData FundBuy(GameClient client, int fundType) { FundData myData = GetFundData(client); if (!myData.IsOpen) { return(myData); } myData.FundType = fundType; // 如果1.9的功能没开放 if (GameFuncControlManager.IsGameFuncDisabled(GameFuncType.System1Dot9)) { myData.State = (int)EFundError.ENoOpen; return(myData); } //类型错误 if (!myData.FundDic.ContainsKey(fundType)) { myData.State = (int)EFundError.Error; return(myData); } //已购买 FundItem myItem = myData.FundDic[fundType]; if (myItem.BuyType == (int)EFundBuy.Have) { myData.State = (int)EFundError.EIsBuy; return(myData); } //vip限制 if (myItem.BuyType == (int)EFundBuy.Limit) { myData.State = (int)EFundError.EVipLimit; return(myData); } //购买钻石不足 FundInfo fundInfo = _fundDic[myItem.FundID]; if (fundInfo.Price > client.ClientData.UserMoney) { myData.State = (int)EFundError.ENoMoney; return(myData); } //扣钱 bool result = GameManager.ClientMgr.SubUserMoney(Global._TCPManager.MySocketListener, Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, client, fundInfo.Price, "基金购买", true, 1, false); if (!result) { myData.State = (int)EFundError.Error; return(myData); } //数据库保存 DateTime buyTime = DateTime.Now; FundDBItem dbItem = new FundDBItem(); dbItem.zoneID = client.ClientData.ZoneID; dbItem.UserID = client.strUserID; dbItem.RoleID = client.ClientData.RoleID; dbItem.FundType = myData.FundType; dbItem.FundID = myItem.FundID; dbItem.BuyTime = buyTime; dbItem.State = (int)EFundState.Now; if (!DBFundBuy(client, dbItem)) { myData.State = (int)EFundError.Error; return(myData); } myItem.BuyType = (int)EFundBuy.Have; myItem.BuyTime = buyTime; if (myItem.FundType == (int)EFund.Login) { myItem.Value1 = Global.GetOffsetDay(DateTime.Now) - Global.GetOffsetDay(myItem.BuyTime) + 1; } //检查奖励 FundAwardInfo awardInfo = _fundAwardDic[myItem.AwardID]; if (myItem.Value1 >= awardInfo.Value1 && myItem.Value2 >= awardInfo.Value2) { myItem.AwardType = (int)EFundAward.Can; } else { myItem.AwardType = (int)EFundAward.Limit; } myData.State = (int)EFundError.Succ; myData.FundType = fundType; CheckActivityTip(client); return(myData); }