bool updateRealItemCnt(string s, ShareRealItemCnt sric) { memoryRealInfoDataModel.HappyData hd = GameConfigMgr.Instance().getHappyData(sric.itemID); if (hd != null) { int MinuteForReflesh = hd.MinuteForReflesh; DateTime now = DateTime.Now; TimeSpan ts = now - sric.preUpdateTime; if (ts.TotalMinutes > MinuteForReflesh) { sric.ModifyLocked(() => { sric.preUpdateTime = now; sric.num = hd.RefleshNum; }); } } else { ConsoleLog.showErrorInfo(0, "RealItemCntUpdate error." + sric.itemID); TraceLog.WriteError("RealItemCntUpdate error." + sric.itemID); } // todo return(true); }
void Init() { var cache = new ShareCacheStruct <ShareRealItemCnt>(); List <int> itemIds = GameConfigMgr.Instance().getHappyDataKeys(); memoryRealInfoDataModel.HappyData hd = null; for (int i = 0; i < itemIds.Count; ++i) { if (null == cache.FindKey(itemIds[i])) // first add { ShareRealItemCnt sric = new ShareRealItemCnt(); hd = GameConfigMgr.Instance().getHappyData(itemIds[i]); sric.itemID = hd.itemID; sric.num = hd.RefleshNum; cache.Add(sric); } } string timestr = GameConfigMgr.Instance().getString("timer_item_cnt", "600000,600000"); string[] tt = timestr.Split(','); int b0 = int.Parse(tt[0]); int b1 = int.Parse(tt[1]); TimerMgr.Singleton().add(typeof(RealItemCntUpdate).ToString(), actionrealItemCnt, b0, b1); bool openDebug = GameConfigMgr.Instance().getInt("timer_open_debug", 0) == 1; if (openDebug) { timestr = GameConfigMgr.Instance().getString("time_hdm_cnt", "600000,600000"); tt = timestr.Split(','); b0 = int.Parse(tt[0]); b1 = int.Parse(tt[1]); TimerMgr.Singleton().add("HappyModeData_EnterNum", action_HappyModeData_enterNum, b0, b1); } else { //每天05点执行 try { timestr = GameConfigMgr.Instance().getString("time_hdm_cnt_timming", "05:15"); } catch { timestr = "05:15"; } TimeListener.Append(PlanConfig.EveryDayPlan(DoEveryDayExecute, "EveryDayTask", timestr)); ConsoleLog.showNotifyInfo("HappyModeData_EnterNum begin:" + timestr); } }
bool checkRefleshReplace(HappyModeData hmd, memoryRealInfoDataModel.HappyData happyData) { List <int> happyKeys = GameConfigMgr.Instance().getHappyDataKeys(); if (happyKeys.Count <= 0) { ConsoleLog.showErrorInfo(0, "checkRefleshReplace: happyKeys.Count"); responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.inner_error; return(false); } // clear the buyItemReflesh. int itemID = requestPack.realItemID; if (hmd.realItemBuyCntInRefleshTime.Count == happyKeys.Count) { // reflesh int buyNumInRefleshTime = int.MaxValue; if (hmd.realItemBuyCntInRefleshTime.ContainsKey(requestPack.realItemID)) { buyNumInRefleshTime = hmd.realItemBuyCntInRefleshTime[itemID].cnt; } if (happyData.timeRefleshCng <= buyNumInRefleshTime) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.error_timeRefleshCnt; return(false); } if (0 == happyData.canReplace) // once time ~~~ { persionRealItemInfo prii = hmd.RealItemInfoLst.Find((o) => { return(o.realItemID == requestPack.realItemID); }); if (null != prii) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.error_replaceBuy; return(false); } } } else { ConsoleLog.showErrorInfo(0, "checkRefleshReplace: hmd.realItemBuyCntInRefleshTime.Count!= happyKeys.Count"); responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.inner_error02; return(false); } return(true); }
public override bool TakeAction() { var cache = new ShareCacheStruct <ShareRealItemCnt>(); var persionCache = new PersonalCacheStruct <HappyModeData>(); int keyId = utils.KeyUInt2Int(requestPack.the3rdUserID); HappyModeData hmd = persionCache.FindKey(keyId.ToString()); List <int> keys = GameConfigMgr.Instance().getHappyDataKeys(); if (hmd != null) { doReflesh(hmd, keys); } for (int i = 0; i < keys.Count; ++i) { memoryRealInfoDataModel.HappyData hd = GameConfigMgr.Instance().getHappyData(keys[i]); ShareRealItemCnt sric = cache.FindKey(keys[i]); if (null != hd && null != sric) { RealItemData rid = new RealItemData(); rid.id = hd.itemID; rid.name = hd.name; rid.happyPoint = hd.needHappyPoint; rid.num = sric.num; rid.timeForReflesh = (sric.preUpdateTime.AddMinutes(hd.MinuteForReflesh) - System.DateTime.Now); rid.uiStatus = 0; if (0 == rid.num) { rid.uiStatus = 1; } if (null != hmd) { bool findIt = false; if (hmd.realItemBuyCntInRefleshTime.ContainsKey(rid.id)) { findIt = hmd.realItemBuyCntInRefleshTime[rid.id].cnt > 0; } bool canReplace = hd.canReplace == 1; if (false == canReplace) { if (hmd.RealItemInfoLst.Exists((o) => { return(o.realItemID == rid.id); })) { rid.uiStatus = 2; } } else { if (findIt) { rid.uiStatus = 2; } } } responsePack.Data.Add(rid); } else { ConsoleLog.showErrorInfo(0, "is null" + (null == hd).ToString() + ":" + (null == sric).ToString()); } } //ConsoleLog.showErrorInfo(0, "responsePack cnt:"+responsePack.Data.Count); responsePack.errorCode = 0; return(true); }
public override bool TakeAction() { int itemIndex = requestPack.realItemID; // int var happyPersionCache = new PersonalCacheStruct <HappyModeData>(); int keyId = utils.KeyUInt2Int(requestPack.the3rdUserID); HappyModeData hmd = happyPersionCache.FindKey(keyId.ToString()); if (hmd == null) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.not_find_happymodedata; return(true); } // happData 01 memoryRealInfoDataModel.HappyData happyData = GameConfigMgr.Instance().getHappyData(requestPack.realItemID); if (null == happyData) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.not_find_happPointConfig; return(true); } // share realitem modify 02 var itemcntCache = new ShareCacheStruct <ShareRealItemCnt>(); ShareRealItemCnt sric = itemcntCache.FindKey(requestPack.realItemID); if (null == sric) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.not_find_item_cnt_data; return(true); } if (false == checkRefleshReplace(hmd, happyData)) { return(true); } int needHappyPoint = happyData.needHappyPoint; // 配置文件总获得 if (hmd.HappyPoint < needHappyPoint) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.not_enought_happyPoint; return(true); } if (sric.num <= 0) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.realitem_is_empty; return(true); } bool buyOK = false; if (sric.num > 0) { sric.ModifyLocked(() => { sric.num -= 1; if (sric.num >= 0) { buyOK = true; } }); } if (false == buyOK) { responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.realitem_is_empty; return(true); } persionRealItemInfo rii = new persionRealItemInfo(); rii.Index = hmd.RealItemInfoLst.Count; rii.UserId = requestPack.UserID; rii.the3rdUserId = utils.KeyUInt2Int(requestPack.the3rdUserID); rii.Identify = requestPack.identify; rii.happyPoint = hmd.HappyPoint; rii.needHappyPoint = needHappyPoint; rii.realItemID = requestPack.realItemID; hmd.RealItemInfoLst.Add(rii); // save to db for .... var shareRealItemCache = new ShareCacheStruct <shareRealItemInfo>(); shareRealItemInfo shareRII = new shareRealItemInfo(); shareRII.Index = (int)shareRealItemCache.GetNextNo(); shareRII.UserId = requestPack.UserID; shareRII.the3rdUserId = utils.KeyUInt2Int(requestPack.the3rdUserID); shareRII.Identify = requestPack.identify; shareRII.happyPoint = hmd.HappyPoint; shareRII.needHappyPoint = needHappyPoint; shareRII.realItemID = requestPack.realItemID; shareRealItemCache.Add(shareRII); hmd.ModifyLocked(() => { hmd.HappyPoint -= needHappyPoint; hmd.realItemBuyCntInRefleshTime[itemIndex].cnt = hmd.realItemBuyCntInRefleshTime[itemIndex].cnt + 1; }); responsePack.errorCode = (byte)Response1009Pack.EnumErrorCode.ok; responsePack.realItemID = rii.realItemID; return(true); }