def addShareInvitedUserId(shareUserId, invitedUserId, isNewUser=False): """ 添加分享邀请人信息 :param shareUserId: 分享卡片的分享者 :param invitedUserId: 点击卡片的被邀请者 :param isNewUser: 是否为新用户 """ inviteCount = weakdata.getDayFishData(shareUserId, "inviteCount", 0) if inviteCount < config.getCommonValueByKey("inviteLimitCount", 99999): if not isNewUser: inviteOldUserCount = weakdata.getDayFishData(shareUserId, "inviteOldUserCount", 0) if inviteOldUserCount > config.getCommonValueByKey("inviteLimitOldCount", 99999): return weakdata.incrDayFishData(shareUserId, "inviteOldUserCount", 1) inviteList = gamedata.getGameAttrJson(shareUserId, FISH_GAMEID, GameData.inviteList, []) inviteId = gamedata.incrGameAttr(shareUserId, FISH_GAMEID, GameData.inviteId, 1) inviteData = { "inviteId": inviteId, "userId": invitedUserId, "inviteTime": int(time.time()), "isNewUser": isNewUser, "isAppUser": 1 if util.isAppClient(invitedUserId) else 0 } inviteList.append(inviteData) gamedata.setGameAttr(shareUserId, FISH_GAMEID, GameData.inviteList, json.dumps(inviteList)) weakdata.incrDayFishData(shareUserId, "inviteCount", 1) module_tip.addModuleTipEvent(shareUserId, "invite", inviteId) getShareTaskInfo(shareUserId) from newfish.game import TGFish from newfish.entity.event import InvitedFinishEvent event = InvitedFinishEvent(shareUserId, FISH_GAMEID) TGFish.getEventBus().publishEvent(event)
def getGiftInfo(self): """ 获取礼包信息 """ giftInfo = [] giftConfList = self.getCurrentGiftConf() for giftConf in giftConfList: if giftConf and giftConf[ "minLevelLimit"] <= self.level <= giftConf["maxLevelLimit"]: itemId = giftConf["monthCard"]["name"] userBag = hallitem.itemSystem.loadUserAssets( self.userId).getUserBag() item = userBag.getItemByKindId(itemId) if item and not item.isDied(int(time.time())): # 今日是否已领取月卡奖励 if itemId == config.MONTH_CARD_KINDID: available = 2 if weakdata.getDayFishData( self.userId, WeakData.getMonthCardGift, 0) > 0 else 1 else: available = 2 if weakdata.getDayFishData( self.userId, WeakData.getPermanentMonthCardGift, 0) > 0 else 1 else: available = 0 # 0:未购买月卡 1:未领取 2:已领取 monthCardGift = self.getGiftDetail(giftConf, available) giftInfo.append([monthCardGift, itemId, available]) return giftInfo
def getShareTaskInfo(userId): """ 获取分享有礼信息 """ shareGroupIds = weakdata.getDayFishData(userId, "shareGroupIds", []) shareGroupTotalCount = config.getCommonValueByKey("shareGroupTotalCount") shareGroupCurrentCount = min(len(shareGroupIds), shareGroupTotalCount) groupTask = { "taskId": 0, "progress": [shareGroupCurrentCount, shareGroupTotalCount], # 分享群数/总数 "rewards": config.getCommonValueByKey("shareGroupRewards"), "state": weakdata.getDayFishData(userId, "shareGroupReward", 0) } if groupTask["state"] == 0 or util.isVersionLimit(userId): module_tip.cancelModuleTipEvent(userId, "invite", 0) inviteTasks = [] inviteList = refreshInviteData(userId) for _, inviteData in enumerate(inviteList): name = util.getNickname(inviteData["userId"]) avatar = userdata.getAttr(inviteData["userId"], "purl") if inviteData.get("isAppUser", 0) == 1: continue if inviteData.get("isNewUser"): rewards = config.getCommonValueByKey("newUserInviteFriendRewards") else: rewards = config.getCommonValueByKey("inviteFriendRewards") task = { "taskId": inviteData["inviteId"], "name": name, "avatar": avatar, "vip": hallvip.userVipSystem.getUserVip(userId).vipLevel.level, "state": 2 if inviteData.get("receiveTime") else 1, "rewards": rewards } inviteTasks.append(task) inviteCount = weakdata.getDayFishData(userId, "inviteCount", 0) inviteTotalCount = config.getCommonValueByKey("inviteLimitCount", 99999) inviteCount = min(inviteCount, inviteTotalCount) friendTask = { "progress": [inviteCount, inviteTotalCount], "rewards": config.getCommonValueByKey("inviteFriendRewards"), "newUserRewards": config.getCommonValueByKey("newUserInviteFriendRewards"), "tasks": inviteTasks } message = MsgPack() message.setCmd("share_task_info") message.setResult("gameId", FISH_GAMEID) message.setResult("userId", userId) if not util.isVersionLimit(userId): message.setResult("groupTask", groupTask) message.setResult("friendTask", friendTask) router.sendToUser(message, userId)
def getShareTaskRewards(userId, taskId): """ 领取分享好礼奖励 """ code = 1 chestId = 0 rewards = [] eventId = "BI_NFISH_INVITE_TASK_REWARDS" if taskId == 0: isReceiveReward = weakdata.getDayFishData(userId, "shareGroupReward", 0) shareGroupIds = weakdata.getDayFishData(userId, "shareGroupIds", []) shareGroupTotalCount = config.getCommonValueByKey("shareGroupTotalCount") if isReceiveReward == 1 and len(shareGroupIds) >= shareGroupTotalCount: rewards = config.getCommonValueByKey("shareGroupRewards") from newfish.entity.chest import chest_system for reward in rewards: kindId = reward["name"] if util.isChestRewardId(kindId): chestId = kindId rewards = chest_system.getChestRewards(userId, kindId) code = chest_system.deliveryChestRewards(userId, kindId, rewards, eventId) else: code = util.addRewards(userId, [reward], eventId) weakdata.setDayFishData(userId, WeakData.shareGroupReward, 2) else: inviteList = refreshInviteData(userId) for _, inviteData in enumerate(inviteList): if inviteData["inviteId"] == taskId and not inviteData.get("receiveTime"): if inviteData.get("isAppUser", 0) == 1: continue if inviteData.get("isNewUser"): rewards = config.getCommonValueByKey("newUserInviteFriendRewards") else: rewards = config.getCommonValueByKey("inviteFriendRewards") code = util.addRewards(userId, rewards, eventId) inviteData["receiveTime"] = int(time.time()) break gamedata.setGameAttr(userId, FISH_GAMEID, GameData.inviteList, json.dumps(inviteList)) message = MsgPack() message.setCmd("share_task_receive") message.setResult("gameId", FISH_GAMEID) message.setResult("userId", userId) message.setResult("taskId", taskId) message.setResult("code", code) if code == 0: module_tip.cancelModuleTipEvent(userId, "invite", taskId) message.setResult("chestId", chestId) message.setResult("rewards", rewards) router.sendToUser(message, userId)
def sendGrandPrixInfo(userId): """ 发送大奖赛信息 """ if not isGrandPrixOpenTime(): grandPrixStartTS = 0 grandPrixFireCount = 0 grandPrixTargetFish = {} grandPrixUseSkillTimes = [] grandPrixFishPoint = 0 # grandPrixLevelFpMultiple = [] getPointsInfo = [] todayMaxPoints = 0 freeTimes = 0 saveGrandPrixData(userId, grandPrixStartTS, grandPrixFireCount, grandPrixFishPoint, grandPrixUseSkillTimes, grandPrixTargetFish, getPointsInfo, todayMaxPoints, freeTimes) vipLevel = util.getVipRealLevel(userId) # 大奖赛剩余免费次数 remainFreeTimes = config.getVipConf(vipLevel).get( "grandPrixFreeTimes", 0) - weakdata.getDayFishData( userId, WeakData.grandPrix_freeTimes, 0) mo = MsgPack() mo.setCmd("grand_prix_info") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("remainFreeTimes", remainFreeTimes) mo.setResult("fee", config.getGrandPrixConf("fee")) mo.setResult("openTime", "-".join(config.getGrandPrixConf("openTimeRange"))) mo.setResult("isInOpenTime", 1 if isGrandPrixOpenTime() else 0) mo.setResult( "signUpState", 1 if weakdata.getDayFishData(userId, WeakData.grandPrix_startTS, 0) > 0 else 0) mo.setResult("todayRankType", RankType.TodayGrandPrix) mo.setResult("todayDate", util.timestampToStr(int(time.time()), "%m/%d")) mo.setResult("yesterdayRankType", RankType.LastGrandPrix) mo.setResult("yesterdayDate", util.timestampToStr(int(time.time() - 86400), "%m/%d")) mo.setResult("pointsInfo", getPointInfo(userId)) # 奖励积分 道具Id、道具数量、是否领取了奖励0|1 mo.setResult("todayMaxPoints", weakdata.getDayFishData(userId, WeakData.grandPrix_point, 0)) # 今日最高积分 router.sendToUser(mo, userId)
def doSendLevelGift(userId, clientId): """ 获取升级礼包数据 """ message = MsgPack() message.setCmd("levelGiftData") message.setResult("gameId", FISH_GAMEID) message.setResult("userId", userId) giftInfo = [] if not util.isVersionLimit(userId) and not util.isPurchaseLimit(userId) and util.isFinishAllNewbieTask(userId): levelGiftConf = config.getLevelGiftConf() gunLv = util.getGunLevelVal(userId, config.MULTIPLE_MODE) for giftId, giftConf in levelGiftConf.iteritems(): if _isBought(userId, giftId): continue if not (giftConf["minLevel"] <= gunLv <= giftConf["maxLevel"]): continue now = int(time.time()) timeout = giftConf["showTime"] * 60 data = weakdata.getDayFishData(userId, WeakData.LevelUpCountDownData, []) if not data: weakdata.setDayFishData(userId, WeakData.LevelUpCountDownData, json.dumps([giftId, now])) else: if data[0] == giftId: if timeout - (now - data[1]) > 0: timeout = timeout - (now - data[1]) else: timeout = 0 else: weakdata.setDayFishData(userId, WeakData.LevelUpCountDownData, json.dumps([giftId, now])) giftInfo.append(getGiftDetail(giftConf, util.getLanguage(userId, clientId), timeout)) message.setResult("giftInfo", giftInfo) router.sendToUser(message, userId) return giftInfo
def doSendFishGift(userId, clientId): """ 发送礼包消息 """ message = MsgPack() message.setCmd("fishGift") message.setResult("gameId", FISH_GAMEID) message.setResult("userId", userId) if not util.isVersionLimit(userId): # 提审版本限制 bankruptGift, tip = BankruptGift(userId, clientId).getGiftInfo() # 破产礼包 if bankruptGift: message.setResult("dailyGiftMode", util.getGiftDTestMode(userId)) message.setResult("dailyGift", bankruptGift) # 破产礼包 message.setResult("dailyGiftTxt", tip) # 提示信息 alms = share_system.AlmsCoin(userId) # 救济金分享 gotTimes = alms.shareData[share_system.INDEX_FINISH_COUNT] # 今日领取救济金次数 message.setResult("gotAlmsCoinTimes", gotTimes) enterFishPoolTimes = weakdata.getDayFishData(userId, WeakData.enterFishPoolTimes, 0) # 今日进入渔场次数 message.setResult("enterFishPoolTimes", enterFishPoolTimes) giftTestMode = config.getPublic("giftTestMode", None) # b测试模式 b显示钻石 a显示元 if giftTestMode is None: giftTestMode = "a" message.setResult("testMode", giftTestMode) # 显示钻石或元测试 router.sendToUser(message, userId)
def loginByInvited(userId, shareUserId, isNewPlayer): """ :param userId: 被邀请人 :param shareUserId: 分享者(邀请人) :param isNewPlayer: 是否为新用户 """ isCanInvite = config.getCommonValueByKey("canInvite") isInvite = weakdata.getDayFishData(userId, "isInvited", 0) if not isCanInvite or isInvite: return False userdata.checkUserData(shareUserId) if isNewPlayer: from newfish.game import TGFish from newfish.entity.event import AddInvitedNewUserEvent # 存储邀请人信息 from hall.entity import hallvip from newfish.entity.redis_keys import GameData shareUserVip = int(hallvip.userVipSystem.getUserVip(shareUserId).vipLevel.level) inviterInfo = { "userId": shareUserId, "inviteTime": int(time.time()), "vip": shareUserVip } gamedata.setGameAttr(userId, FISH_GAMEID, GameData.inviterInfo, json.dumps(inviterInfo)) saveKey = "inviteNewPlayers" actionType = NewPlayerAction event = AddInvitedNewUserEvent(shareUserId, FISH_GAMEID, userId) TGFish.getEventBus().publishEvent(event) else: saveKey = "recallPlayers" actionType = RecallPlayerAction user_rpc.addInviteNum(shareUserId, userId, actionType, saveKey, isNewPlayer) return True
def vipAutoSupplyPerDay(userId): """ vip每日自动补足 """ vipLevel = hallvip.userVipSystem.getVipInfo(userId).get("level", 0) key = GameData.autoSupplyKey % config.CHIP_KINDID autoSupplyCount = config.getVipConf(vipLevel).get(key, 0) chips = userchip.getUserChipAll(userId) if autoSupplyCount >= 10000 and chips < autoSupplyCount and weakdata.getDayFishData( userId, key, 0) == 0: weakdata.incrDayFishData(userId, key, 1) lang = util.getLanguage(userId) rewards = [{ "name": config.CHIP_KINDID, "count": (autoSupplyCount - chips) }] message = config.getMultiLangTextConf( "ID_VIP_AUTO_SUPPLY_PER_DAY", lang=lang) % (autoSupplyCount / 10000) mail_system.sendSystemMail(userId, mail_system.MailRewardType.SystemReward, rewards, message) if ftlog.is_debug(): ftlog.debug("vipAutoSupplyPerDay", userId, vipLevel, autoSupplyCount, chips, key, autoSupplyCount - chips)
def checkModuleTip(bigRoomId, userId, mode): """ 检查是否可以玩小游戏 """ subkey = "%s_%d" % (bigRoomId, mode) mgType = config.getSuperBossCommonConf().get(str(subkey), {}).get("mgType", "") key = "%s_%d" % (mgType, mode) isCanPlay = False if mgType in MINIGAME_TYPE_LIST: conf = config.getSuperBossMiniGameConf() superbossPlayedTimes = weakdata.getDayFishData(userId, WeakData.superbossMGPlayedTimes, {}) playedTimes = superbossPlayedTimes.get(key, 0) vipLevel = hallvip.userVipSystem.getUserVip(userId).vipLevel.level maxTimesList = conf.get("info", {}).get(key, {}).get("maxTimes", []) maxTimes = maxTimesList[vipLevel] if maxTimesList and len(maxTimesList) > vipLevel else 0 remainTimes = max(0, maxTimes - playedTimes) if maxTimes >= 0 else -1 items = conf.get("items", {}).get(key, []) isCanPlay = False if remainTimes == -1 or remainTimes > 0: for _item in items: for _val in _item.get("costs"): if util.balanceItem(userId, _val["name"]) < _val["count"]: break else: isCanPlay = True break tipKey = "minigame" if isCanPlay: module_tip.addModuleTipEvent(userId, "superboss", tipKey) if ftlog.is_debug(): ftlog.debug("minigame, userId =", userId, "tipKey =", tipKey, isCanPlay, "key =", key)
def checkModuleTip(mgType, userId, mode): """ 检查是否可以兑换 """ key = "%s_%d" % (mgType, mode) exchangedTimes = weakdata.getDayFishData(userId, WeakData.superbossExchangedTimes, {}) exchangedTimes = exchangedTimes.get(key, {}) conf = config.getSuperBossExchangeConf() exchangeItems = [] isCanExchanged = False for idx, val in enumerate( conf.get("exchange", {}).get(key, {}).get("exchangeItems", [])): remainTimes = val["exchangeTimes"] remainTimes = max(0, remainTimes - exchangedTimes.get( str(val["idx"]), 0)) if remainTimes >= 0 else remainTimes exchangeItems.append({ "costItems": val["costItems"], "gainItems": val["gainItems"], "remainTimes": remainTimes }) if not isCanExchanged and _isExchangeChance(userId, remainTimes, val["costItems"]): isCanExchanged = True tipKey = "convert" if isCanExchanged: module_tip.addModuleTipEvent(userId, "superboss", tipKey)
def accelerateReward(userId): """ 前端通知后端看广告加速 """ luckyTreeConf = config.getLuckyTreeConf() maxAcceleratetimes = luckyTreeConf.get("maxAcceleratetimes") accelerateTimes = weakdata.getDayFishData(userId, "accelerateTimes", 0) curTime = int(time.time()) luckyTreeConf = config.getLuckyTreeConf() luckyTreeData = getLuckyTreeData(userId) rewardTs = luckyTreeData.get("rewardTs") # 当前的可领奖时间 if accelerateTimes < maxAcceleratetimes: code = 0 else: code = 1 return luckyTreeData["rewardTs"], code # 看一次广告加速的时间,单位 /h accelerateTsConf = luckyTreeConf.get("accelerateTime", 1) accelerateTs = accelerateTsConf * 60 * 60 if curTime + accelerateTs < rewardTs: rewardTs = rewardTs - accelerateTs else: rewardTs = curTime luckyTreeData["rewardTs"] = rewardTs weakdata.incrDayFishData(userId, "accelerateTimes", 1) saveLuckyTreeData(userId, luckyTreeData) return luckyTreeData["rewardTs"], code
def _getBuyTimes(self, fishPool): """ 获取d测试中礼包购买次数 """ buyBankruptGift = weakdata.getDayFishData( self.userId, WeakData.buyBankruptGiftTimesPerPool, {}) buyTimes = buyBankruptGift.get(str(fishPool), {}).get("count", 0) return buyTimes
def addShareGroupId(userId, groupId): """ 添加分享到群的群ID """ shareGroupIds = weakdata.getDayFishData(userId, "shareGroupIds", []) if ftlog.is_debug(): ftlog.debug("addShareGroupId", userId, groupId, shareGroupIds) if groupId and groupId not in shareGroupIds: shareGroupIds.append(groupId) weakdata.setDayFishData(userId, WeakData.shareGroupIds, json.dumps(shareGroupIds)) shareGroupTotalCount = config.getCommonValueByKey("shareGroupTotalCount") isReceiveReward = weakdata.getDayFishData(userId, "shareGroupReward", 0) if not isReceiveReward and len(shareGroupIds) >= shareGroupTotalCount: weakdata.setDayFishData(userId, WeakData.shareGroupReward, 1) if not util.isVersionLimit(userId): module_tip.addModuleTipEvent(userId, "invite", 0) getShareTaskInfo(userId)
def _isBought(userId, giftId): """ 礼包是否已购买 """ giftId = int(giftId) boughtGift = weakdata.getDayFishData(userId, WeakData.buyFishDailyGift, []) if giftId in boughtGift: return 1 return 0
def _main(): userId = 116009 import time import json from newfish.entity import config, util, store, weakdata from newfish.entity.redis_keys import GameData, WeakData import freetime.util.log as ftlog data = weakdata.getDayFishData(userId, 'ceshishuju', []) if not data: weakdata.setDayFishData(userId, 'ceshishuju', json.dumps(["7909", time.time()])) weakdata.setDayFishData(userId, 'ceshishuju', json.dumps(["7903", time.time()]))
def updateInvitedState(userId, shareUserId, isNewUser=False): """ 更新邀请状态 :param userId: 被邀请者 :param shareUserId: 分享者 :param isNewUser: 是否为新用户 """ isInvited = weakdata.getDayFishData(userId, "isInvited", 0) if not isInvited: user_rpc.addShareInvitedUserId(shareUserId, userId, isNewUser) weakdata.incrDayFishData(userId, "isInvited", 1)
def sendGrandPrixInfo(self): """ 发送大奖赛信息 大奖赛相关信息(进入渔场后服务器主动推送) """ if not grand_prix.isGrandPrixOpenTime(): # 是否为大奖赛开放时段 00:00 —— 23:00 self._resetGrandPrixData() self._freeTimes = 0 # 免费次数 weakdata.setDayFishData(self.userId, WeakData.grandPrix_getPointsInfo, json.dumps([])) weakdata.setDayFishData(self.userId, WeakData.grandPrix_freeTimes, self._freeTimes) if ftlog.is_debug(): ftlog.debug("sendGrandPrixInfo", self.grandPrixStartTS, self.isGrandPrixMode()) signUpState = 1 if self.isGrandPrixMode() else 0 # 是否已经报名 remainFreeTimes = config.getVipConf(self.vipLevel).get( "grandPrixFreeTimes", 0) - self._freeTimes # 剩余免费次数 openTime = "-".join(config.getGrandPrixConf("openTimeRange")) # 时间范围 mo = MsgPack() mo.setCmd("grand_prix_info") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", self.userId) mo.setResult("seatId", self.seatId) mo.setResult("remainFreeTimes", remainFreeTimes) mo.setResult("fee", config.getGrandPrixConf("fee")) # 报名费 mo.setResult("openTime", openTime) # 00:00 - 23:00 mo.setResult( "isInOpenTime", 1 if grand_prix.isGrandPrixOpenTime() else 0) # 大奖在是否在开放时间段 mo.setResult("signUpState", signUpState) # 是否已报名大奖赛 mo.setResult( "todayRankType", RankType.TodayGrandPrix) # 今日榜Type,使用fish_ranking获取排行榜数据,下同 mo.setResult("todayDate", util.timestampToStr(int(time.time()), "%m/%d")) # 今日榜时间 mo.setResult("yesterdayRankType", RankType.LastGrandPrix) mo.setResult("yesterdayDate", util.timestampToStr(int(time.time() - 86400), "%m/%d")) mo.setResult( "des", config.getMultiLangTextConf( config.getGrandPrixConf("info").get("des"), lang=self.lang)) # 每日积分超过2400送100珍珠,今日榜单每10分钟刷新1次,最终排名00:00公布 mo.setResult("pointsInfo", grand_prix.getPointInfo( self.userId)) # 奖励积分 道具Id、道具数量、是否领取了奖励0|1 mo.setResult("todayMaxPoints", weakdata.getDayFishData(self.userId, WeakData.grandPrix_point, 0)) # 今日最高积分 GameMsg.sendMsg(mo, self.userId) if ftlog.is_debug(): ftlog.debug("FishGrandPrixPlayer, userId =", self.userId, "mo =", mo)
def _loadUserData(self): super(FishGrandPrixPlayer, self)._loadUserData() # 捕鱼积分 self.grandPrixFishPoint = weakdata.getDayFishData( self.userId, WeakData.grandPrix_fishPoint, 0) # 大奖赛剩余开火次数 self.grandPrixFireCount = weakdata.getDayFishData( self.userId, WeakData.grandPrix_fireCount, 0) # 大奖赛剩余技能使用次数 self.grandPrixUseSkillTimes = weakdata.getDayFishData( self.userId, WeakData.grandPrix_useSkillTimes, []) # 大奖赛目标鱼捕获数量 self.grandPrixTargetFish = weakdata.getDayFishData( self.userId, WeakData.grandPrix_targetFish, {}) # 大奖赛火炮等级和倍率 # self.grandPrixLevelFpMultiple = weakdata.getDayFishData(self.userId, WeakData.grandPrix_levelFpMultiple) # 大奖赛开始的时间戳 self.grandPrixStartTS = weakdata.getDayFishData( self.userId, WeakData.grandPrix_startTS, 0) # 大奖赛结束定时器 self.grandPrixEndTimer = None # 大奖赛提示定时器 self.grandPrixTipTimer = None # 大奖赛阶段奖励 self.grandPrixGetPointsInfo = weakdata.getDayFishData( self.userId, WeakData.grandPrix_getPointsInfo, []) self._freeTimes = weakdata.getDayFishData(self.userId, WeakData.grandPrix_freeTimes, 0) self.multipleList = [] # 10、50、200、500 for v in gdata.roomIdDefineMap().values(): roomConf = v.configure if roomConf.get("typeName") not in [config.FISH_FRIEND]: continue self.multipleList.append(roomConf.get("multiple", 1)) self.multipleList.sort() self._rankListCache = [] # 超越玩家的集合 self._surpassUser = {} self.grandPrixSurpassCount = weakdata.getDayFishData( self.userId, WeakData.grandPrix_surpassCount, 0) # 大奖赛超越自己次数 self.bestPoint = weakdata.getDayFishData(self.userId, WeakData.grandPrix_point, 0) self.inGameTimes = 0 # 游戏时长(分钟)
def _incQuestValue(userId, taskType, incVlaue, resetTime=0, fishPool=0, fpMultiple=0, gunX=0): """ 更新每日任务进度并检测;任务是否完成 """ if util.getDayStartTimestamp(resetTime) != util.getDayStartTimestamp(int(time.time())): resetTime = weakdata.getDayFishData(userId, "resetTime") if not resetTime: weakdata.setDayFishData(userId, WeakData.resetTime, int(time.time())) refreshDailyQuestData(userId) key = _getUserDailyQuestKey(userId) newValue = daobase.executeUserCmd(userId, "HINCRBY", key, str(taskType), incVlaue) confs = config.getDailyQuestConfsByType(taskType) todayQuest, _ = getTodayQuest(userId) questInfo = getUserQuestInfoData(userId) update = False for conf in confs: if conf and conf["taskId"] in todayQuest: if isinstance(conf.get("fishPool"), list) and conf.get("fishPool") and fishPool not in conf.get("fishPool"): continue if conf.get("fpMultiple", 0) > 0 and fpMultiple < conf.get("fpMultiple", 0): continue if conf.get("gunX", 0) > 0 and gunX < conf.get("gunX", 0): continue taskId = conf["taskId"] targetsNum = conf.get("targetsNum") process, state = questInfo.get(str(taskId), [0, QuestTaskState.Normal]) # if newValue >= targetsNum and newValue - incVlaue < targetsNum: if state == QuestTaskState.Normal: update = True questInfo[str(taskId)] = [process + incVlaue, state] if process < targetsNum <= process + incVlaue: questInfo[str(taskId)] = [targetsNum, QuestTaskState.Complete] quest = todayQuest[taskId] _sendQuestFinished(userId, quest) module_tip.addModuleTipEvent(userId, "task", taskId) taskLevel = conf.get("taskLevel", 0) # questData = getDailyQuestData(userId) # finishedStar = questData.get("finishedStar", 0) # dailyQuestRewardFinishedStars = config.getDailyQuestRewardFinishedStars() # for star in dailyQuestRewardFinishedStars: # if finishedStar >= star and finishedStar - taskLevel < star: # module_tip.addModuleTipEvent(userId, "task", star) # break # 发送完成任务事件 from newfish.entity.event import DailyTaskFinishEvent from newfish.game import TGFish event = DailyTaskFinishEvent(userId, FISH_GAMEID, int(conf["taskId"]), taskLevel) TGFish.getEventBus().publishEvent(event) bireport.reportGameEvent("BI_NFISH_GE_TASK_FINISHED", userId, FISH_GAMEID, 0, 0, int(conf["taskId"]), int(taskLevel), 0, 0, [], util.getClientId(userId)) if update: setUserQuestInfoData(userId, questInfo)
def getRewardTsAndCopperCount(userId): """ 获取可领奖时间戳和铜币数量 """ curTime = int(time.time()) luckyTreeData = getLuckyTreeData(userId) copperCount = luckyTreeData.get("copperCount", 0) accelerateTimes = weakdata.getDayFishData(userId, "accelerateTimes", 0) # 第一次玩家直接可领 if not luckyTreeData: luckyTreeData["rewardTs"] = curTime luckyTreeData["copperCount"] = 0 luckyTreeData["accelerate"] = 0 saveLuckyTreeData(userId, luckyTreeData) return accelerateTimes, luckyTreeData["rewardTs"], copperCount
def grandPrixEnterRoom(cls, userId): """ 大奖赛房间能否进入 """ startDay = config.getGrandPrixConf("info").get("startDay") currentTime = int(time.time()) if startDay and currentTime < util.getTimestampFromStr(startDay): return cls.ENTER_ROOM_REASON_NOT_OPEN if weakdata.getDayFishData(userId, WeakData.grandPrix_startTS, 0) == 0: dayStartTimestamp = util.getDayStartTimestamp(currentTime) remainGrandPrixTimeSeconds = util.timeStrToInt( config.getGrandPrixConf("openTimeRange")[1]) - ( currentTime - dayStartTimestamp) # 大奖赛剩余时间 if not grand_prix.isGrandPrixOpenTime( ) or remainGrandPrixTimeSeconds < 10: return cls.ENTER_ROOM_REASON_GRAND_PRIX_NOE_OPEN vipLevel = hallvip.userVipSystem.getUserVip(userId).vipLevel.level if config.getVipConf(vipLevel).get("grandPrixFreeTimes", 0) <= \ weakdata.getDayFishData(userId, WeakData.grandPrix_freeTimes, 0): # 用免费次数已经用完 fee = config.getGrandPrixConf("fee")[0] surplusCount = util.balanceItem(userId, fee["name"]) if surplusCount < fee["count"]: return cls.ENTER_ROOM_REASON_GRAND_PRIX_LESS_FEES return cls.ENTER_ROOM_REASON_OK
def playMinigameShow(roomId, userId, idx, mode, userIds): """ 巨龙转盘展示盘面 """ bigRoomId, _ = util.getBigRoomId(roomId) subkey = "%s_%d" % (bigRoomId, mode) mgType = config.getSuperBossCommonConf().get(str(subkey), {}).get("mgType", "") key = "%s_%d" % (mgType, mode) mo = MsgPack() mo.setCmd("superboss_minigame_show") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("roomId", roomId) mo.setResult("mode", mode) mo.setResult("idx", idx) mo.setResult("type", mgType) data = {} code = 1 gainItems = [] if mgType == "dragon": superbossPlayedTimes = weakdata.getDayFishData(userId, WeakData.superbossMGPlayedTimes, {}) playedTimes = superbossPlayedTimes.setdefault(key, 0) conf = config.getSuperBossMiniGameConf() vipLevel = hallvip.userVipSystem.getUserVip(userId).vipLevel.level maxTimesList = conf.get("info", {}).get(key, {}).get("maxTimes", []) isCanPlay = True items = conf.get("game", {}).get(key, []) maxTimes = maxTimesList[vipLevel] if maxTimesList and len(maxTimesList) > vipLevel else 0 if 0 <= idx < len(items) and (maxTimes == -1 or maxTimes > playedTimes) and isCanPlay: costItems = items[idx]["costs"] gainItems = items[idx]["rewards"] for _val in costItems: if util.balanceItem(userId, _val["name"]) < _val["count"]: code = 2 break else: code = 0 turntable_rewards = [] if code == 0: for gainItem in gainItems: for key in gainItem.keys(): if key == "count": turntable_rewards.append(gainItem[key]) data["turntable_rewards"] = turntable_rewards mo.setResult("data", data) mo.setResult("code", code) userIds.append(userId) GameMsg.sendMsg(mo, userIds)
def _initData(self, userId, activityId, inTable): super(OneDayClearActivity, self)._initData(userId, activityId, inTable) self.isCleared = weakdata.getDayFishData(userId, activityId, 0) if self.isCleared == 0: ftlog.debug("OneDayClearActivity_initData") self.isCleared = 1 weakdata.setDayFishData(self.userId, self.activityId, 1) if self.activityType == ActivityType.OneDayClearAc: self.timeDesc = " " else: if self.activityConfig["effectiveTime"]: self.timeDesc = config.getMultiLangTextConf("ID_ACTIVITY_TIME_DESC_2", lang=self.lang) % \ (self.getTimeDescStr(self.activityConfig["effectiveTime"]["start"]), self.getTimeDescStr(self.activityConfig["effectiveTime"]["end"])) else: self.timeDesc = " "
def _getGrade(self, fishPool): """ 获取abc测试中的礼包档位 """ buyBankruptGift = weakdata.getDayFishData( self.userId, WeakData.buyBankruptGiftTimesPerPool, {}) grade = buyBankruptGift.get(str(fishPool), {}).get("grade") # 根据当前的消费能力计算礼包档位. if str(fishPool) not in buyBankruptGift: grade, nextGrade = "low", "mid" else: if grade == "mid" or grade == "high": grade, nextGrade = "mid", "high" else: grade, nextGrade = "low", "mid" return grade, nextGrade
def sendMinigameInfo(roomId, userId, mode): """ 发送小游戏信息 """ bigRoomId, _ = util.getBigRoomId(roomId) subkey = "%s_%d" % (bigRoomId, mode) mgType = config.getSuperBossCommonConf().get(str(subkey), {}).get("mgType", "") key = "%s_%d" % (mgType, mode) mo = MsgPack() mo.setCmd("superboss_minigame_info") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("roomId", roomId) mo.setResult("mode", mode) mo.setResult("type", mgType) data = {} if mgType in MINIGAME_TYPE_LIST: conf = config.getSuperBossMiniGameConf() superbossPlayedTimes = weakdata.getDayFishData(userId, WeakData.superbossMGPlayedTimes, {}) playedTimes = superbossPlayedTimes.get(key, 0) vipLevel = hallvip.userVipSystem.getUserVip(userId).vipLevel.level maxTimesList = conf.get("info", {}).get(key, {}).get("maxTimes", []) maxTimes = maxTimesList[vipLevel] if maxTimesList and len(maxTimesList) > vipLevel else 0 remainTimes = max(0, maxTimes - playedTimes) if maxTimes >= 0 else -1 currencyList = conf.get("info", {}).get(key, {}).get("currencyList", []) items = config.rwcopy(conf.get("game", {}).get(key, [])) gunLevelVal = util.getGunLevelVal(userId, config.MULTIPLE_MODE) lang = util.getLanguage(userId) itemsinfo = [] for item in items: if gunLevelVal >= item["level"]: item["des"] = config.getMultiLangTextConf(item["des"], lang=lang) if item["des"] else "" itemsinfo.append(item) if mgType == "box": for iteminfo in itemsinfo: rewards = iteminfo["rewards"] groupIdx = util.selectIdxByWeight([int(reward.keys()[0]) for reward in rewards]) iteminfo["rewards"] = rewards[groupIdx].values()[0] iteminfo["groupIdx"] = groupIdx mo.setResult("showItemsList", currencyList) data = {"remainTimes": remainTimes, "items": itemsinfo} else: ftlog.warn("minigame, type error, userId =", userId, "roomId =", roomId, "mode =", mode, "mgType =", mgType) mo.setResult("data", data) router.sendToUser(mo, userId) if ftlog.is_debug(): ftlog.debug("minigame, userId =", userId, "mode =", mode, "mo =", mo)
def getQuestInfo(userId, clientId): """ 获取玩家每日任务数据 """ resetTime = weakdata.getDayFishData(userId, "resetTime") if not resetTime: weakdata.setDayFishData(userId, "resetTime", int(time.time())) refreshQuestData(userId) # 重置每日任务存档 dailyQuestData = daily_quest.getDailyQuestData(userId) # 获取玩家每日任务数据 mainQuestData = main_quest.getMainQuestData(userId, clientId) # 获取主线任务数据 mo = MsgPack() mo.setCmd("task") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("action", "update") mo.setResult("dailyTask", dailyQuestData) mo.setResult("mainTask", mainQuestData) router.sendToUser(mo, userId)
def _initData(self, userId, activityId, inTable): """初始化数据""" self.activityId = activityId self.userId = userId self.inTable = inTable # 玩家语言 self.lang = util.getLanguage(userId) # 活动存档 self.activityData = self._getActivityData() # 活动配置 self.activityConfig = config.getActivityConfigById(activityId) # 活动数据是否需要每日重置 self.isDailyReset = self.activityConfig.get("isDailyReset", 0) # 活动数据是否已重置 self.isReset = weakdata.getDayFishData(userId, activityId, 0) if self.isDailyReset else 1 # 活动类型 self.activityType = self.activityConfig.get("type") # 玩家是否在渔场中 self.isPlayerInTable, _, _, _ = util.isInFishTable(userId) # 渔场内任务id self.inTableTaskIds = [] # 渔场外任务id self.outTableTaskIds = [] actTasks = self.activityConfig.get("task") if actTasks: self.inTableTaskIds = [ str(taskId) for taskId, task in actTasks.iteritems() if task["type"] in AcTableTypes ] self.outTableTaskIds = [ str(taskId) for taskId, task in actTasks.iteritems() if task["type"] not in AcTableTypes ] self.desc = None self.timeDesc = None if self.activityConfig.get("effectiveTime"): self.timeDesc = config.getMultiLangTextConf( "ID_ACTIVITY_TIME_DESC_2", lang=self.lang) % ( self.getTimeDescStr( self.activityConfig["effectiveTime"]["start"]), self.getTimeDescStr( self.activityConfig["effectiveTime"]["end"])) self.taskIndex = 0
def _isCanReceiveFromOther(otherUserId, kindId): """ 检查是否可以接收他人赠送招财珠 """ from newfish.entity.config import SILVER_BULLET_KINDID, GOLD_BULLET_KINDID if kindId in [SILVER_BULLET_KINDID, GOLD_BULLET_KINDID]: silverBulletKey = WeakData.vipReceiveCount % SILVER_BULLET_KINDID if userdata.checkUserData(otherUserId): vipLevel = util.getVipRealLevel(otherUserId) dayReceiveCount = weakdata.getDayFishData(otherUserId, silverBulletKey, 0) dayLimitCount = config.getVipConf(vipLevel).get(silverBulletKey, 0) leftReceiveCount = dayLimitCount - dayReceiveCount if leftReceiveCount > 0 and not util.isProtectionLimit(otherUserId): if kindId == GOLD_BULLET_KINDID: leftReceiveCount = leftReceiveCount // 5 return 0, leftReceiveCount # 可以接受赠送 else: return 1, 0 # 不可以接受赠送 return 0, 99999
def sendFishCheckinInfo(userId, continueWindow=0): """ 发送签到详情 :param continueWindow: 0:用户点击签到请求 1:客户端登录时自动请求 """ if util.isVersionLimit(userId): return checkinDay = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.checkinDay) isCheckin = weakdata.getDayFishData(userId, "isCheckin", 0) code = 1 if (continueWindow and isCheckin): code = 2 elif util.isFinishAllNewbieTask(userId): code = 0 if not isCheckin: if checkinDay == len(config.getCheckinConf()): checkinDay = 0 gamedata.setGameAttr(userId, FISH_GAMEID, GameData.checkinDay, checkinDay) module_tip.addModuleTipEvent(userId, "checkin", checkinDay) mo = MsgPack() mo.setCmd("fishCheckin") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("loginDays", gamedata.getGameAttr(userId, FISH_GAMEID, GameData.loginDays)) mo.setResult("day", checkinDay if isCheckin else checkinDay + 1) mo.setResult("checkin", isCheckin) rewards = [] for rewardConf in config.getCheckinConf().values(): if util.isChestRewardId(rewardConf["shareReward"]["name"]): rewards.append(rewardConf["shareReward"]) else: rewards.append(rewardConf["normalReward"]) mo.setResult("rewards", rewards) mo.setResult("continueWindow", continueWindow) mo.setResult("code", code) router.sendToUser(mo, userId)