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);
        }
Example #2
0
        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);
        }