def v2DataTov3Data(userId, clientId): """ v2版本用户属性继承到v3版本 """ # 金币数量调整 totalChip = userchip.getUserChipAll(userId) incrChip = totalChip * 10 - totalChip userchip.incrChip(userId, FISH_GAMEID, incrChip, 0, "BI_NFISH_NEW_USER_REWARDS", 0, clientId) # 处理宝藏相关数据 from newfish.entity import treasure_system treasureList = config.getV2ToV3Conf("treasure") userAssets = hallitem.itemSystem.loadUserAssets(userId) for _, treasureConf in enumerate(treasureList): old_kindId = treasureConf["old_kindId"] new_kindId = treasureConf.get("new_kindId") ratio = treasureConf.get("ratio", 0) convert_kindId = treasureConf.get("convert_kindId") convert_num = treasureConf.get("convert_num", 999999) surplusCount = util.balanceItem(userId, old_kindId, userAssets) if surplusCount > 0: if new_kindId: treasureData = treasure_system.getTreasure(userId, new_kindId) if treasureData[treasure_system.INDEX_LEVEL] == 0: treasureData[treasure_system.INDEX_LEVEL] = 1 treasure_system.setTreasure(userId, new_kindId, treasureData) if convert_kindId: convertNum = min(surplusCount, convert_num) convertNum = int(math.ceil(convertNum * ratio)) rewards = [{"name": convert_kindId, "count": convertNum}] util.addRewards(userId, rewards, "BI_NFISH_NEW_USER_REWARDS", old_kindId, surplusCount) consumeItems = [{"name": old_kindId, "count": surplusCount}] util.consumeItems(userId, consumeItems, "BI_NFISH_NEW_USER_REWARDS") # 处理技能相关数据 skillList = config.getV2ToV3Conf("skill") userAssets = hallitem.itemSystem.loadUserAssets(userId) for _, skillConf in enumerate(skillList): old_kindId = skillConf["old_kindId"] ratio = skillConf.get("ratio", 0) convert_kindId = skillConf.get("convert_kindId") surplusCount = util.balanceItem(userId, old_kindId, userAssets) if surplusCount > 0: if convert_kindId: convertNum = int(math.ceil(surplusCount * ratio)) rewards = [{"name": convert_kindId, "count": convertNum}] util.addRewards(userId, rewards, "BI_NFISH_NEW_USER_REWARDS", old_kindId, surplusCount) consumeItems = [{"name": old_kindId, "count": surplusCount}] util.consumeItems(userId, consumeItems, "BI_NFISH_NEW_USER_REWARDS")
def bindOrNotBindItem(userId, bindKindId, kindId, count): """ 绑定与非绑定是否足够 """ if util.balanceItem(userId, bindKindId) >= count: return True elif util.balanceItem(userId, bindKindId) + util.balanceItem( userId, kindId) >= count: return True elif util.balanceItem(userId, kindId) >= count: return True return False
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 consumeBindOrNotBindItem(userId, bindKindId, kindId, count): """获取消耗的数据""" consumeList = [] if util.balanceItem(userId, bindKindId) >= count: consume = {"name": int(bindKindId), "count": count} elif util.balanceItem(userId, bindKindId) + util.balanceItem( userId, kindId) >= count: bind_count = util.balanceItem(userId, bindKindId) count = count - bind_count consume1 = {"name": int(bindKindId), "count": bind_count} consumeList.append(consume1) consume = {"name": int(kindId), "count": count} else: consume = {"name": int(kindId), "count": count} consumeList.append(consume) return consumeList
def refreshSkillCD(self): """ 刷新技能CD时间 :return: """ if util.balanceItem(self.userId, config.SKILLCD_KINDID) > 0: pass
def refreshQuestTaskId(userId, taskId): """ 手动刷新每日任务 """ code = 1 newTaskId = 0 spareQuests = getSpareQuest(userId) cost = config.getDailyQuestRefreshConf().get("cost") if spareQuests and cost: todayQuest, _ = getTodayQuest(userId) quest = todayQuest.get(taskId, None) if ftlog.is_debug(): ftlog.debug("refreshQuestTaskId", "userId =", userId, "taskId =", taskId, "quest =", quest) if quest: questInfo = getUserQuestInfoData(userId) refreshTimes = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.refreshDailyQuestTimes) process, state = questInfo.get(str(taskId), [0, QuestTaskState.Normal]) if ftlog.is_debug(): ftlog.debug("refreshQuestTaskId", "questInfo =", questInfo, "refreshTimes =", refreshTimes, process, state) if state == QuestTaskState.Normal and refreshTimes < config.getDailyQuestRefreshConf().get("maxTimes", 1): succ = True for item in cost: if util.balanceItem(userId, item["name"]) < item["count"]: succ = False if ftlog.is_debug(): ftlog.debug("refreshQuestTaskId ====>", "资源不足", userId, taskId, item["name"], item["count"]) break else: if not util.consumeItems(userId, cost, "ITEM_USE"): succ = False if succ: code = 0 gamedata.incrGameAttr(userId, FISH_GAMEID, GameData.refreshDailyQuestTimes, 1) import random new = random.choice(spareQuests) newTaskId = new["taskId"] if str(taskId) in questInfo: questInfo.pop(str(taskId)) if ftlog.is_debug(): ftlog.debug("refreshQuestTaskId, pop !", userId, taskId, questInfo) questInfo[str(newTaskId)] = [0, QuestTaskState.Normal] setUserQuestInfoData(userId, questInfo) else: code = 3 else: code = 2 mo = MsgPack() mo.setCmd("task") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("action", "refreshQuest") mo.setResult("taskId", taskId) mo.setResult("code", code) mo.setResult("newTaskId", newTaskId) dailyQuestData = getDailyQuestData(userId) mo.setResult("dailyTask", dailyQuestData) router.sendToUser(mo, userId)
def triggerItemChangeEvent(event): """ 道具/资产变化事件 """ if event.type == 0: userId = event.userId isIn, _, _, _ = util.isInFishTable(userId) if not isIn: coin = userchip.getChip(userId) setQuestTypeData(userId, QuestType.HoldCoin, coin) setQuestTypeData(userId, QuestType.HoldGoldBullet, util.balanceItem(userId, config.GOLD_BULLET_KINDID))
def _isExchangeChance(userId, remainTimes, costItems): """ 判断是否存在兑换机会,兑换材料和次数是否充足 """ isTimeEnough = remainTimes == -1 or remainTimes > 0 if not isTimeEnough: return False isItemEnough = False for _val in costItems: if util.balanceItem(userId, _val["name"]) < _val["count"]: break else: isItemEnough = True return isItemEnough
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 isEnough(userId, items): """ 道具数量是否满足升级所需数量 """ for kindId, count in items.iteritems(): if (int(kindId) == config.PURPLE_CRYSTAL_KINDID and bindOrNotBindItem( userId, config.BIND_PURPLE_CRYSTAL_KINDID, config.PURPLE_CRYSTAL_KINDID, count)): continue elif (int(kindId) == config.YELLOW_CRYSTAL_KINDID and bindOrNotBindItem(userId, config.BIND_YELLOW_CRYSTAL_KINDID, config.YELLOW_CRYSTAL_KINDID, count)): continue if util.balanceItem(userId, kindId) < count: return False return True
def composeGunSkin(userId, gunId, skinId, mode): """ 合成火炮皮肤 """ clientId = util.getClientId(userId) if ftlog.is_debug(): ftlog.debug("composeGunSkin, userId =", userId, "gunId =", gunId, "skinId =", skinId, "clientId =", clientId, "mode =", mode) skinConf = config.getGunSkinConf(skinId, clientId, mode) mo = MsgPack() mo.setCmd("gun_compose_skin") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("gunId", gunId) mo.setResult("skinId", skinId) mo.setResult("gameMode", mode) skins = config.getGunConf(gunId, clientId, mode=mode).get("skins") if skinId not in skins: mo.setResult("code", 99) # 数据不对 router.sendToUser(mo, userId) return False if not skinConf: mo.setResult("code", 99) # 数据不对 router.sendToUser(mo, userId) return False surplusCount = util.balanceItem(userId, skinConf["kindId"]) ownGunSkinSkinsKey = GameData.ownGunSkinSkins ownGunSkinSkins = gamedata.getGameAttrJson(userId, FISH_GAMEID, ownGunSkinSkinsKey, []) if surplusCount < skinConf["consumeCount"]: mo.setResult("code", 1) # 资源不足 return False elif skinId in ownGunSkinSkins: mo.setResult("code", 2) # 已经合成 return False else: # 合成消耗皮肤碎片 _consume = [{ "name": skinConf["kindId"], "count": abs(skinConf["consumeCount"]) }] util.consumeItems(userId, _consume, "ITEM_USE", int(gunId), mode) addEquipGunSkinSkin(userId, skinId, clientId, False) mo.setResult("code", 0) router.sendToUser(mo, userId) return True
def convertTreasure(userId, kindId, count): """ 兑换宝藏碎片 """ code, rewards = 1, None treasureConf = config.getTreasureConf(kindId) convert = treasureConf.get("convert") if convert: surplusCount = util.balanceItem(userId, convert["kindId"]) consumeCount = convert["rate"] * count if surplusCount >= consumeCount: consume = [{"name": convert["kindId"], "count": -abs(consumeCount)}] rewards = [{"name": kindId, "count": count}] consume.extend(rewards) code = util.addRewards(userId, consume, "BI_NFISH_TREASURE_CONVERT", kindId) return code, rewards return code, rewards
def getResComplement(userId, count=0): """ 获得珍珠、紫水晶、黄水晶道具补足 """ effect = {} treasureConf = config.getTreasureConf(effectType=EffectType.ResComplement) if treasureConf: kindId = treasureConf["kindId"] level, levelConf = getTreasureInfo(userId, kindId) if not levelConf: return refreshTreasureState(userId, kindId) treasureData = getTreasure(userId, kindId) if treasureData[INDEX_FINISH_COUNT] >= treasureConf["limitCount"]: return rewards = [] lang = util.getLanguage(userId) for _kindId, _complementCount in levelConf.get("params", {}).iteritems(): _kindId = int(_kindId) _surplusCount = util.balanceItem(userId, _kindId) if _complementCount > _surplusCount: _reward = { "name": _kindId, "count": _complementCount - _surplusCount, "chgCount": [_surplusCount, _complementCount] } rewards.append(_reward) treasureName = config.getMultiLangTextConf(treasureConf["name"], lang=lang) countStr = util.formatScore(_complementCount, lang=lang) message = config.getMultiLangTextConf("ID_CONFIG_TREASURE_SUPPLY_%s" % _kindId, lang=lang) message = message.format(countStr, treasureName, countStr) GameMsg.sendPrivate(FISH_GAMEID, userId, 0, message) if rewards: util.addRewards(userId, rewards, "BI_NFISH_TREASURE_REWARDS", kindId) activeTreasure(userId, kindId, treasureData) effect = { "kindId": kindId, "level": level, "rewards": rewards } return effect
def renameNickname(userId, clientId, nickname): """ 修改玩家昵称 """ lang = util.getLanguage(userId, clientId) surplusCount = util.balanceItem(userId, config.RENAME_KINDID) try: if surplusCount == 0: code = 1 info = config.getMultiLangTextConf("ID_RENAME_CODE_INFO_1", lang=lang) # u"昵称修改失败" elif len(nickname) == 0: code = 2 info = config.getMultiLangTextConf("ID_RENAME_CODE_INFO_2", lang=lang) # u"昵称不能为空,请重新输入!" elif len(nickname.decode("utf-8").encode("gbk", "ignore")) > 16: code = 3 info = config.getMultiLangTextConf("ID_RENAME_CODE_INFO_3", lang=lang) # u"昵称过长,请重新输入!" elif re.search(u"[^\w\u4e00-\u9fff]+", nickname.decode("utf-8")): code = 4 info = config.getMultiLangTextConf("ID_RENAME_CODE_INFO_4", lang=lang) # u"昵称不能含有特殊字符,请重新输入!" elif util.isTextCensorLimit(nickname): code = 5 info = config.getMultiLangTextConf("ID_RENAME_CODE_INFO_5", lang=lang) # u"昵称含有违规内容,请重新输入!" else: _consume = [{"name": config.RENAME_KINDID, "count": 1}] util.consumeItems(userId, _consume, "ITEM_USE") gamedata.setGameAttr(userId, FISH_GAMEID, GameData.nickname, nickname) userdata.setAttr(userId, "name", nickname) code = 0 info = config.getMultiLangTextConf("ID_RENAME_CODE_INFO_0", lang=lang) # u"昵称修改成功" except: ftlog.error() code = 1 info = config.getMultiLangTextConf("ID_RENAME_CODE_INFO_1", lang=lang) # u"昵称修改失败" message = MsgPack() message.setCmd("rename_nickname") message.setResult("gameId", FISH_GAMEID) message.setResult("userId", userId) message.setResult("info", info) message.setResult("code", code) router.sendToUser(message, userId)
def sendGunInfoMsg(userId, mode): """ 发送普通炮信息 """ gunLevelKey = GameData.gunLevel if mode == CLASSIC_MODE else GameData.gunLevel_m gunLevel = gamedata.getGameAttrInt(userId, FISH_GAMEID, gunLevelKey) nextGunLevel = config.getNextGunLevel(gunLevel, mode) if nextGunLevel == -1: return nextGunLevelConf = config.getGunLevelConf(nextGunLevel, mode) mo = MsgPack() mo.setCmd("gun_info") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("gunLevel", gunLevel) # 当前火炮等级 mo.setResult("nextGunLevel", nextGunLevelConf["gunLevel"]) # 下一个等级 if "levelRewards" in nextGunLevelConf and nextGunLevelConf[ "levelRewards"] > 0: mo.setResult("levelUpRewards", nextGunLevelConf["levelRewards"]) # 金币数量 mo.setResult("successRate", nextGunLevelConf["successRate"]) mo.setResult("gameMode", mode) upgradeItemsConf = getUpgradeItemsConf(userId, nextGunLevel, mode=mode) if upgradeItemsConf: upgradeItems = {} for kindId, count in upgradeItemsConf.iteritems(): if int(kindId) == config.PURPLE_CRYSTAL_KINDID: upgradeItems[kindId] = [ util.balanceItem(userId, kindId) + util.balanceItem( userId, config.BIND_PURPLE_CRYSTAL_KINDID), count ] elif int(kindId) == config.YELLOW_CRYSTAL_KINDID: upgradeItems[kindId] = [ util.balanceItem(userId, kindId) + util.balanceItem( userId, config.BIND_YELLOW_CRYSTAL_KINDID), count ] else: upgradeItems[kindId] = [ util.balanceItem(userId, kindId), count ] mo.setResult("upgradeItems", upgradeItems) if nextGunLevelConf.get("protectItems"): protectItems = {} for kindId, count in nextGunLevelConf.get("protectItems").iteritems(): protectItems[kindId] = [util.balanceItem(userId, kindId), count] mo.setResult("protectItems", protectItems) router.sendToUser(mo, userId)
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 _main1(): userId = 10013 ftlog.debug(util.balanceItem(userId, 14177), '11111111111111111')
def reason(self, kindId, fIds, lockFid=0): """是否使用道具""" if kindId not in self.player.skills_item_slots: return 1 if kindId == config.FREEZE_KINDID: frozenNum = 0 for fId in fIds: isOK = self.table.findFish(fId) if not isOK: continue bufferEffect = [ 1 for buffer in self.table.fishMap[fId]["buffer"] if buffer[0] == 5104 and time.time() < buffer[1] ] if len(bufferEffect) > 0 and lockFid != fId: frozenNum += 1 continue if frozenNum >= SkillItem.FREEZE_NUM: return 7 data = self.player.skills_item_slots[kindId] if not data: return 2 if data["state"] == State.USING: if float("%.2f" % time.time()) - data["start_time"] + data[ "progress"][0] < data["progress"][1]: return 4 self.player.end_skill_item(kindId) data = self.player.skills_item_slots[kindId] if data and data["state"] != State.NO_USE: return 5 conf = data["conf"] name = conf["name"] count_0 = conf["count_0"] replace_name = conf["replace_name"] count_1 = conf["count_1"] bind_name = conf["bind_name"] bind_count = conf["bind_count"] # 不是新手阶段或者宝藏不消耗道具阶段 if not (self.table.typeName == config.FISH_NEWBIE or treasure_system.isUseItemFree(self.userId, int(kindId))): if balanceItem( self.userId, bind_name) >= bind_count and bind_count > 0: # 先使用绑定的锁定道具 consumeItems( self.userId, [{ "name": bind_name, "count": bind_count }], "BI_SKILL_ITEM_CONSUME_%s_%s_%s" % (kindId, bind_name, bind_count)) elif balanceItem(self.userId, name) >= count_0 and count_0 > 0: # 在使用锁定道具 consumeItems( self.userId, [{ "name": name, "count": count_0 }], "BI_SKILL_ITEM_CONSUME_%s_%s_%s" % (kindId, name, count_0)) elif balanceItem(self.userId, replace_name) >= count_1 and count_1 > 0: # 使用珍珠 consumeItems( self.userId, [{ "name": replace_name, "count": count_1 }], "BI_SKILL_ITEM_CONSUME_ITEM_%s_%s_%s" % (kindId, replace_name, count_1)) else: return 6 data["state"] = State.USING data["start_time"] = float("%.2f" % time.time()) return 0
def playMinigame(roomId, userId, idx, mode, userIds, groupIdx): """ 点击小游戏 """ 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") 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) code = 1 data = {} gainItems =[] if mgType in MINIGAME_TYPE_LIST: 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", []) maxTimes = maxTimesList[vipLevel] if maxTimesList and len(maxTimesList) > vipLevel else 0 items = conf.get("game", {}).get(key, []) rewards = [] _idx = 0 isCanPlay = True # 只能抽取满足消耗的最高等级抽奖. # if mgType == "queen": # # 抽奖消耗由多到少配置。 # for _idx, _val in enumerate(itemsinfo): # # 检查消耗是否满足条件 # for v in _val["costs"]: # if util.balanceItem(userId, v["name"]) < v["count"]: # break # else: # isCanPlay = (idx == _idx) # break if 0 <= idx < len(items) and (maxTimes == -1 or maxTimes > playedTimes) and isCanPlay: costItems = items[idx]["costs"] if mgType == "box": gainItems = items[idx]["rewards"][groupIdx].values()[0] else: gainItems = items[idx]["rewards"] for _val in costItems: if util.balanceItem(userId, _val["name"]) < _val["count"]: code = 2 break else: _ret = util.consumeItems(userId, costItems, "BI_NFISH_SUPERBOSS_EXCHANGE", bigRoomId, mode) if not _ret: code = 2 else: superbossPlayedTimes[key] += 1 weakdata.setDayFishData(userId, WeakData.superbossMGPlayedTimes, json.dumps(superbossPlayedTimes)) _idx = util.selectIdxByWeight([v["probb"] for v in gainItems]) if _idx >= 0: rewards = [{"name": gainItems[_idx]["name"], "count": gainItems[_idx]["count"]}] isIn, roomId, tableId, _ = util.isInFishTable(userId) if isIn: code = table_remote.addRewardsToTable(roomId, tableId, userId, rewards, "BI_NFISH_SUPERBOSS_BOX", mode) else: code = util.addRewards(userId, rewards, "BI_NFISH_SUPERBOSS_BOX", bigRoomId, mode) if code != 0: ftlog.error("minigame, userId =", userId, "bigRoomId =", key, "idx =", idx, "rewards =", rewards) playedTimes = superbossPlayedTimes.get(key, 0) remainTimes = max(0, maxTimes - playedTimes) if maxTimes >= 0 else -1 data = {"remainTimes": remainTimes, "rewards": rewards, "rewardIndex": _idx} else: ftlog.warn("minigame, type error, userId =", userId, "roomId =", roomId, "mode =", mode, "idx =", idx, "mgType =", mgType) mo.setResult("code", code) turntable_rewards = [] if mgType == "dragon": 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) router.sendToUser(mo, userId) if mgType == "dragon" and code == 0: userIds = userIds GameMsg.sendMsg(mo, userIds) if code == 0: from newfish.game import TGFish event = PlayMiniGame(userId, config.FISH_GAMEID) TGFish.getEventBus().publishEvent(event) checkModuleTip(bigRoomId, userId, mode)
def _exchange(userId, mgType, mode, idx, count): """ 兑换逻辑, 通过mgType+mode+idx可以唯一确定兑换数据. """ code = 1 key = "%s_%d" % (mgType, mode) exchangedTimes = weakdata.getDayFishData(userId, WeakData.superbossExchangedTimes, {}) exchangedTimes.setdefault(key, {}) conf = config.getSuperBossExchangeConf("exchange").get(key, {}) rewards = [] reList = "" costList = "" lang = util.getLanguage(userId) info = config.getMultiLangTextConf("ID_EXCHANGE_ERR_INFO_8", lang=lang) # 根据兑换类型找到bigRoomId,用于bi事件参数. bigRoomId = 0 for _bigRoomId, val in config.getSuperBossCommonConf().iteritems(): if val["mgType"] == mgType: bigRoomId = int(str(_bigRoomId)[0:5]) break for _exchangeItem in conf.get("exchangeItems", []): _id = _exchangeItem["idx"] if _id != idx: continue remainTimes = _exchangeItem["exchangeTimes"] remainTimes = max(0, remainTimes - exchangedTimes[key].get( str(_id), 0)) if remainTimes >= 0 else remainTimes if not (count >= 1 and (remainTimes == -1 or remainTimes >= count)): continue costItems = _exchangeItem.get("costItems", []) gainItems = _exchangeItem.get("gainItems", []) for _val in costItems: _val["count"] *= count kindName = config.getMultiLangTextConf("ID_CONFIG_KINDID_ITEM:%s" % _val["name"], lang=lang) costDes = kindName + "x" + str(_val["count"]) costList = costList + costDes + " " if util.balanceItem(userId, _val["name"]) < _val["count"]: code = 2 break _ret = util.consumeItems(userId, costItems, "BI_NFISH_SUPERBOSS_EXCHANGE", bigRoomId, mode) if not _ret: code = 2 else: code = 0 if remainTimes > 0: exchangedTimes[key][str(_id)] = exchangedTimes[key].setdefault( str(_id), 0) + count weakdata.setDayFishData(userId, WeakData.superbossExchangedTimes, json.dumps(exchangedTimes)) reDict = {} for i in range(count): for val in gainItems: if val.get("minCount", 0) and val.get("maxCount", 0): reDict.setdefault(val["name"], 0) reDict[val["name"]] += random.randint( val["minCount"], val["maxCount"]) for k, v in reDict.iteritems(): rewards.append({"name": k, "count": v}) if k == config.CHIP_KINDID: kindName = config.getMultiLangTextConf( "ID_CONFIG_KINDID_USER:CHIP", lang=lang) else: kindName = config.getMultiLangTextConf( "ID_CONFIG_KINDID_ITEM:%s" % k, lang=lang) reDes = kindName + "x" + str(v) reList = reList + reDes + " " if util.addRewards(userId, rewards, "BI_NFISH_SUPERBOSS_EXCHANGE", bigRoomId, mode) != 0: ftlog.error("item_exchange, userId =", userId, "bigRoomId =", bigRoomId, "mode =", mode, "idx =", idx, "count =", count, "rewards =", rewards, "key =", key) if code == 0: bireport.reportGameEvent("BI_NFISH_GE_ITEM_EXCHANGE", userId, FISH_GAMEID, 0, 0, 0, 0, 0, 0, [userId, mgType, mode, idx], util.getClientId(userId)) from newfish.game import TGFish event = MiniGameBossExchange(userId, config.FISH_GAMEID, count) TGFish.getEventBus().publishEvent(event) info = config.getMultiLangTextConf( "ID_EXCHANGE_RESULT_INFO_1", lang=lang).format(time.strftime("%X", time.localtime()), reList, costList) return code, rewards, info
def canQuickEnterRoom(cls, userId, gameId, roomId, kindId): """ 判断能否进入房间 """ try: if util.isFinishAllNewbieTask(userId): newbieRoomId = config.getCommonValueByKey("newbieRoomId") if gdata.getBigRoomId(roomId) == gdata.getBigRoomId( newbieRoomId): return cls.ENTER_ROOM_REASON_INNER_ERROR else: newbieRoomId = config.getCommonValueByKey("newbieRoomId") if gdata.getBigRoomId(roomId) != gdata.getBigRoomId( newbieRoomId): return cls.ENTER_ROOM_REASON_INNER_ERROR gameMode = util.getRoomGameMode(roomId) isOldPlayerV2 = util.isOldPlayerV2(userId) if gameMode == config.CLASSIC_MODE and not isOldPlayerV2: return cls.ENTER_ROOM_REASON_INNER_ERROR uLevel = util.getUserLevel(userId) gunLevel = util.getGunLevel(userId, gameMode) if not uLevel or not gunLevel: return cls.ENTER_ROOM_REASON_INNER_ERROR gunLevelVal = config.getGunLevelConf(gunLevel, gameMode).get( "levelValue", 1) userChip = userchip.getUserChipAll(userId) vipLevel = hallvip.userVipSystem.getUserVip(userId).vipLevel.level if ftlog.is_debug(): ftlog.debug("canQuickEnterRoom->", gdata.roomIdDefineMap()[roomId].configure) roomConf = gdata.roomIdDefineMap()[roomId].configure fee = roomConf.get("fee_%s" % kindId, {}) or roomConf.get( "fee", {}) minLevel = roomConf.get("minLevel", 1) minGunLevelVal = roomConf.get("minGunLevelVal", 1) minCoin = roomConf.get("minCoin", 1) minVip = roomConf.get("minVip", 0) timeLimit = roomConf.get("timeLimit", []) bulletLimit = roomConf.get("bulletLimit", {}) protectionLimit = roomConf.get("protectionLimit", {}) if fee: surplusCount = util.balanceItem(userId, fee["kindId"]) if surplusCount < fee["count"]: return cls.ENTER_ROOM_REASON_LESS_FEES if bulletLimit and not kindId: isCan = False for kindId in bulletLimit: surplusCount = util.balanceItem(userId, kindId) if surplusCount >= bulletLimit[kindId]: isCan = True break if not isCan: return cls.ENTER_ROOM_REASON_LESS_BULLET if timeLimit: isCan = False currentTime = int(time.time()) for timeRange in timeLimit: startTime = util.getTodayTimestampFromStr(timeRange[0]) endTime = util.getTodayTimestampFromStr(timeRange[1]) if startTime <= currentTime <= endTime: isCan = True break if not isCan: return cls.ENTER_ROOM_REASON_TIME_LIMIT if uLevel < minLevel and not kindId: if roomConf.get("typeName") == config.FISH_ROBBERY: if vipLevel >= minVip: return cls.ENTER_ROOM_REASON_OK return cls.ENTER_ROOM_REASON_LESS_LEVEL if gunLevelVal < minGunLevelVal: return cls.ENTER_ROOM_REASON_LESS_LEVEL if userChip < minCoin: return cls.ENTER_ROOM_REASON_LESS_COIN if protectionLimit: dailyProfitCoin, monthlyProfitCoin = 0, 0 if roomConf.get("typeName") == config.FISH_ROBBERY: dailyProfitCoin, monthlyProfitCoin = util.getRobberyProfitCoin( userId) elif roomConf.get("typeName") == config.FISH_POSEIDON: dailyProfitCoin, monthlyProfitCoin = util.getPoseidonProfitCoin( userId) if (dailyProfitCoin <= protectionLimit["dailyLoss"] or monthlyProfitCoin <= protectionLimit["monthlyLoss"]): return cls.ENTER_ROOM_REASON_EXCESSIVE_LOSS # 检测大奖赛开放时间 if roomConf.get("typeName") in [config.FISH_GRAND_PRIX]: state = cls.grandPrixEnterRoom(userId) if state != cls.ENTER_ROOM_REASON_OK: return state return cls.ENTER_ROOM_REASON_OK except Exception as e: ftlog.error("canQuickEnterRoom error", userId, e) return cls.ENTER_ROOM_REASON_INNER_ERROR