def refreshQuestState(userId, questType, totalValue): """ 刷新指定任务类型的任务状态 """ isComplete = False clientId = util.getClientId(userId) for taskConf in config.getMainQuestTaskConf(clientId).values(): if questType == taskConf["type"] and totalValue >= taskConf["num"]: state = getTask(userId, taskConf["taskId"])[QuestIndex.State] if state == QuestState.Default: setTask(userId, clientId, taskConf["taskId"], [QuestState.Completed, int(time.time())]) isComplete = True if isComplete: refreshQuestModuleTip(userId, clientId) isIn, roomId, tableId, seatId = util.isInFishTable(userId) if isIn: mo = MsgPack() mo.setCmd("table_call") mo.setParam("action", "task_update") mo.setParam("gameId", FISH_GAMEID) mo.setParam("clientId", util.getClientId(userId)) mo.setParam("userId", userId) mo.setParam("roomId", roomId) mo.setParam("tableId", tableId) mo.setParam("seatId", seatId) router.sendTableServer(mo, roomId)
def endGrandPrix(self): """ 大奖赛结束 """ if self.userId == 0: return if self.grandPrixEndTimer: self.grandPrixEndTimer.cancel() self.grandPrixEndTimer = None if not self.isGrandPrixMode(): return grandPrixFinalPoint = self.saveGrandPrixPoint() # 完成大奖赛事件 event = FinishGrandPrixEvent(self.userId, FISH_GAMEID, self.table.bigRoomId, grandPrixFinalPoint) TGFish.getEventBus().publishEvent(event) bireport.reportGameEvent("BI_NFISH_GRAND_PRIX_END", self.userId, FISH_GAMEID, 0, 0, grandPrixFinalPoint, 0, 0, 0, [], util.getClientId(self.userId)) if self.inGameTimes: bireport.reportGameEvent("BI_NFISH_GRAND_PRIX_INGAMETIMES", self.userId, FISH_GAMEID, 0, 0, self.grandPrixStartTS, self.inGameTimes, 0, 0, [], util.getClientId(self.userId)) self.inGameTimes = 0 self.cancelUsingSkills() # 恢复技能数据 取消处于使用中的技能 self.unloadSkills() # 下载所有技能 self._resetGrandPrixData() # 重置数据存档 self.loadAllSkillData() # 重新加载技能 读取并初始化所有技能数据 self.syncSkillSlots() # 同步技能槽消息 rank, rankRewards = ranking_system.getUserRankAndRewards( RankType.TodayGrandPrix, self.userId) if ftlog.is_debug(): ftlog.debug("endGrandPrix", self.grandPrixStartTS, self.grandPrixFireCount, self.grandPrixFishPoint) mo = MsgPack() mo.setCmd("end_grand_prix") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", self.userId) mo.setResult("seatId", self.seatId) mo.setResult("fishPoint", grandPrixFinalPoint) mo.setResult("rank", rank) mo.setResult("rankRewards", rankRewards) mo.setResult("fee", config.getGrandPrixConf("fee")) mo.setResult( "tabs", ranking_system.getRankingTabs(self.userId, util.getClientId(self.userId), RankType.TodayGrandPrix, rankDetail=True)) GameMsg.sendMsg(mo, self.userId) self.sendGrandPrixInfo() self.table.clearPlayer(self) # 从桌子中踢掉玩家
def reportOwnGunsAndGunSkins(event): """报告拥有的火炮和火炮皮肤""" ownGuns = gamedata.getGameAttrJson(event.userId, FISH_GAMEID, GameData.ownGunSkins, []) bireport.reportGameEvent("BI_NFISH_GE_ADD_GUN_ID", event.userId, FISH_GAMEID, 0, 0, 0, 0, 0, 0, ownGuns, util.getClientId(event.userId)) ownGunSkinSkinsKey = GameData.ownGunSkinSkins ownGunSkinSkins = gamedata.getGameAttrJson(event.userId, FISH_GAMEID, ownGunSkinSkinsKey, []) bireport.reportGameEvent("BI_NFISH_GE_ADD_GUN_SKIN", event.userId, FISH_GAMEID, 0, 0, 0, 0, 0, 0, ownGunSkinSkins, util.getClientId(event.userId))
def pushHonor(userId, honorId): """ 获得称号时推送 """ mo = MsgPack() mo.setCmd("honor_push") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) # mo.setResult("honors", getHonorList(userId)) router.sendToUser(mo, userId) isIn, roomId, tableId, seatId = util.isInFishTable(userId) if isIn: mo = MsgPack() mo.setCmd("table_call") mo.setParam("action", "honor_push") mo.setParam("gameId", FISH_GAMEID) mo.setParam("clientId", util.getClientId(userId)) mo.setParam("userId", userId) mo.setParam("roomId", roomId) mo.setParam("tableId", tableId) mo.setParam("seatId", seatId) router.sendTableServer(mo, roomId) from newfish.game import TGFish event = GetHonorEvent(userId, FISH_GAMEID, honorId) TGFish.getEventBus().publishEvent(event)
def sendWelcomeMail(userId): """ 发送欢迎邮件 """ message = None welcomeMailConfs = config.getCommonValueByKey("ignoreConf") clientId = util.getClientId(userId) ftlog.debug("sendWelcomeMail", userId, "clientId = ", clientId) lang = util.getLanguage(userId) rewards = config.getCommonValueByKey("welcomeMailRewards") for welcomeMailConf in welcomeMailConfs: if clientId in welcomeMailConf.get("clientIds", []): # 不可显示实物、人民币相关描述 message = config.getMultiLangTextConf( "ID_CONFIG_BAN_ENTITY_WELCOME_MSG", lang=lang) else: # 可显示实物、人民币相关描述 message = config.getMultiLangTextConf( "ID_CONFIG_ALLOW_ENTITY_WELCOME_MSG", lang=lang) if message: mail_system.sendSystemMail(userId, mail_system.MailRewardType.SystemReward, rewards, message=message, title=config.getMultiLangTextConf( "ID_MAIL_TITLE_HOT_WELCOME", lang=lang))
def checkSkillUpgrade(userId): """ 检查技能能否升级升星 """ upSkills = [] for skillId in config.getAllSkillId(): skillId = int(skillId) if not config.getSkillStarConf(skillId, 1, config.MULTIPLE_MODE): continue code, skill = checkSkillStatus(userId, skillId) if code != 0: continue if skill[INDEX_ORIGINAL_LEVEL] < MAX_ORIGINAL_LEVEL: skillGradeConf = config.getSkillGradeCommonConf( skillId, skill[INDEX_ORIGINAL_LEVEL] + 1) if checkUpgradeSkillItemCount(userId, skillGradeConf["consume"]): upSkills.append(skillId) if skill[INDEX_STAR_LEVEL] > 0 and skill[ INDEX_STAR_LEVEL] < MAX_STAR_LEVEL: skillStarConf = config.getSkillStarCommonConf( skillId, skill[INDEX_STAR_LEVEL] + 1) if checkUpgradeSkillItemCount(userId, skillStarConf["consume"]): upSkills.append(skillId) bireport.reportGameEvent( "BI_NFISH_GE_SKILL_UPGRADE", userId, FISH_GAMEID, 0, 0, skillId, 0, 0, 0, [skill[INDEX_STAR_LEVEL], skill[INDEX_ORIGINAL_LEVEL]], util.getClientId(userId)) module_tip.resetModuleTip(userId, "upskill") if upSkills: module_tip.addModuleTipEvent(userId, "upskill", upSkills) else: module_tip.resetModuleTipEvent(userId, "upskill")
def getAllGuns(userId, mode): """ 获得所有皮肤炮数据 """ clientId = util.getClientId(userId) assert isinstance(userId, int) and userId > 0 _key = _buildUserGunKey(userId, mode) value = daobase.executeUserCmd(userId, "HGETALL", _key) if value: gunInfos = {} savaData = [] for index in xrange(0, len(value), 2): gunId = value[index] if gunId in config.getAllGunIds(clientId, mode): gunData = strutil.loads(value[index + 1], False, True) if len(gunData) <= 2: gunConfig = config.getGunConf(gunId, clientId, gunData[INDEX_LEVEL], mode) gunData.append(gunConfig["skins"][0]) savaData.append(gunId) savaData.append(strutil.dumps(gunData)) gunInfos[gunId] = gunData if savaData: daobase.executeUserCmd(userId, "HMSET", _key, *savaData) return gunInfos return {}
def changeGunSkin(userId, gunId, skinId, mode): """ 切换火炮皮肤 """ if ftlog.is_debug(): ftlog.debug("changeGunSkin, userId =", userId, "gunId =", gunId, "skinId =", skinId, "mode =", mode) mo = MsgPack() mo.setCmd("gun_change_skin") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("gunId", gunId) mo.setResult("skinId", skinId) mo.setResult("gameMode", mode) clientId = util.getClientId(userId) skins = config.getGunConf(gunId, clientId, mode=mode).get("skins") ownGunSkinSkinsKey = GameData.ownGunSkinSkins ownGunSkinSkins = gamedata.getGameAttrJson(userId, FISH_GAMEID, ownGunSkinSkinsKey, []) if skinId not in ownGunSkinSkins and skinId != skins[0]: mo.setResult("code", 1) # 未获得 router.sendToUser(mo, userId) return False if skinId not in skins: mo.setResult("code", 2) # 皮肤不在该火炮下属的皮肤列表中 router.sendToUser(mo, userId) return False equipGunSkin(userId, gunId, skinId, mode) mo.setResult("code", 0) router.sendToUser(mo, userId) return True
def _triggerUseSkillEvent(event): if util.getRoomTypeName(event.roomId) not in config.NORMAL_ROOM_TYPE: return userId = event.userId clientId = util.getClientId(userId) ftlog.debug("piggy_bank, userId =", userId, "chip =", event.chip) vipLevel = hallvip.userVipSystem.getVipInfo(userId).get("level", 0) fireCostChip(userId, clientId, vipLevel, event.chip)
def _triggerGameTimeEvent(event): userId = event.userId ftlog.debug("piggy_bank, userId =", userId) vipLevel = hallvip.userVipSystem.getVipInfo(userId).get("level", 0) clientId = util.getClientId(userId) conf = config.getPiggyBankConf(clientId, vipLevel) for k, v in conf.iteritems(): addCount = v.get("inroom", 0) if addCount > 0: addMoneyToPiggyBank(userId, clientId, k, addCount)
def updateGun(userId, gunId, mode): """ 更新新增炮数据 """ clientId = util.getClientId(userId) assert int(gunId) in config.getAllGunIds(clientId, mode) gunConf = config.getGunConf(gunId, clientId, mode=mode) gunInfo = [1, 0, gunConf["skins"][0]] # 皮肤炮熟练等级 | 经验 | 默认皮肤 daobase.executeUserCmd(userId, "HSETNX", _buildUserGunKey(userId, mode), str(gunId), json.dumps(gunInfo))
def isFinishAllTask(userId, questType): """ 是否已完成指定类型的所有任务 """ clientId = util.getClientId(userId) for _, taskConf in config.getMainQuestTaskConf(clientId).iteritems(): if questType == taskConf["type"]: state = getTask(userId, taskConf["taskId"])[QuestIndex.State] if state == QuestState.Default: return False return True
def _triggerLevelUpEvent(event): userId = event.userId userLevel = event.level levels = gamedata.getGameAttrJson(userId, config.FISH_GAMEID, GameData.levelRewards, []) clientId = util.getClientId(userId) levelRewards = config.getLevelRewards(clientId) for level, rewards in levelRewards.iteritems(): if rewards and level not in levels: if level <= userLevel: module_tip.addModuleTipEvent(userId, "levelRewards", level) break
def isUnlock(userId, gunId, gunConf, mode): """ 皮肤炮是否已解锁 """ # 先判断当前模式是否解锁 _isUnlocked = _isUnlockGun(userId, gunConf, mode) # 如果当前模式未达到解锁条件则检测另一个模式是否已达到解锁条件.(经典/千炮) if not _isUnlocked: clientId = util.getClientId(userId) _mode = MULTIPLE_MODE if mode == CLASSIC_MODE else CLASSIC_MODE _gunConf = config.getGunConf(gunId, clientId, mode=_mode) _isUnlocked = _isUnlockGun(userId, _gunConf, _mode) return _isUnlocked
def refreshReturnerMissionData(userId, lastLoginTime): """ 刷新回归豪礼数据 """ currTime = int(time.time()) lastLoginTime = util.getDayStartTimestamp(lastLoginTime) returnerMissionConf = config.getReturnerMissionConf() # 判断是否激活回归豪礼 if currTime - lastLoginTime >= returnerMissionConf["daysLost"] * 24 * 3600: returnerMission = gamedata.getGameAttrJson(userId, FISH_GAMEID, GameData.returnerMission, {}) lastActiveTime = util.getDayStartTimestamp(returnerMission.get("lastActiveTime", currTime)) isActive = False if returnerMission: if currTime - lastActiveTime >= returnerMissionConf["daysBetween"] * 24 * 3600: isActive = True else: isActive = True if isActive: userLevel = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.level) vipLevel = hallvip.userVipSystem.getUserVip(userId).vipLevel.level vipExp = hallvip.userVipSystem.getUserVip(userId).vipExp returnerMission = {} returnerMission["lastActiveTime"] = currTime returnerMission["userLevel"] = userLevel returnerMission["vipExp"] = vipExp returnerMission["tasks"] = initTaskData() gamedata.setGameAttr(userId, FISH_GAMEID, GameData.returnerMission, json.dumps(returnerMission)) bireport.reportGameEvent("BI_NFISH_GE_RETURNER_MISSION", userId, FISH_GAMEID, vipLevel, vipExp, userLevel, 0, 0, 0, [], util.getClientId(userId)) returnerMission = getReturnerMissionData(userId) if returnerMission: # 解锁新任务 lastActiveTime = util.getDayStartTimestamp(returnerMission["lastActiveTime"]) fewDays = (datetime.fromtimestamp(currTime) - datetime.fromtimestamp(lastActiveTime)).days + 1 fewDays = max(1, min(fewDays, len(returnerMission["tasks"]))) # 第N天之前的任务都会解锁 isUnlock = False taskIds = [] for _index, taskConf in enumerate(config.getReturnerMissionConf("tasks")): if taskConf["taskId"] in returnerMission["tasks"]: if _index < fewDays and returnerMission["tasks"][taskConf["taskId"]]["state"] == 0: returnerMission["tasks"][taskConf["taskId"]]["state"] = 1 isUnlock = True elif returnerMission["tasks"][taskConf["taskId"]]["state"] == 2: taskIds.append(taskConf["taskId"]) if isUnlock: gamedata.setGameAttr(userId, FISH_GAMEID, GameData.returnerMission, json.dumps(returnerMission)) if taskIds: module_tip.addModuleTipEvent(userId, "returnerMission", taskIds) else: module_tip.resetModuleTipEvent(userId, "returnerMission")
def addUserVipExp(gameId, userId, toAddExp, eventId, intEventParam, productId, rmbs=-1, isAddVipExp=True): """ 增加VIP经验值 """ rmbs = int(rmbs) if rmbs == -1 and toAddExp >= 10: rmbs = toAddExp / 10 if isAddVipExp: hallvip.userVipSystem.addUserVipExp(gameId, userId, toAddExp, eventId, intEventParam) else: # 自己处理vip升级事件. from hall.game import TGHall from hall.entity.hallvip import TYUserVipLevelUpEvent vipExp = hallvip.userVipSystem.getUserVip(userId).vipExp oldVipLevel = hallvip.vipSystem.findVipLevelByVipExp(vipExp - toAddExp) userVip = hallvip.userVipSystem.getUserVip(userId) if oldVipLevel.level != userVip.vipLevel.level: lv_event = TYUserVipLevelUpEvent(FISH_GAMEID, userId, oldVipLevel, userVip, [], 0, 0) TGHall.getEventBus().publishEvent(lv_event) # vip经验发生变化. from newfish.game import TGFish event = UserVipExpChangeEvent(userId, gameId, toAddExp) TGFish.getEventBus().publishEvent(event) if ftlog.is_debug(): ftlog.debug("addUserVipExp----->event", gameId, userId, toAddExp, eventId, intEventParam, rmbs, isAddVipExp) # 上报购买商品事件. loginDays = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.loginDays) userLevel = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.level) isIn, roomId, tableId, _ = util.isInFishTable(userId) if isIn: from newfish.servers.table.rpc import table_remote table_remote.buyProduct(roomId, tableId, userId, intEventParam, userLevel, loginDays) else: from poker.entity.biz import bireport userChip = userchip.getUserChipAll(userId) bireport.reportGameEvent("BI_NFISH_BUY_PRODUCT", userId, FISH_GAMEID, roomId, intEventParam, userLevel, 0, 0, 0, [], util.getClientId(userId), loginDays, userChip) # ftlog.debug("BI_NFISH_BUY_PRODUCT", userId, roomId, intEventParam, userLevel, util.getClientId(userId), userChip) updateUserDataByRecharge(userId, productId, rmbs)
def reportBILogOnLogin(userId): """ 首次登录上报BI数据 """ # 上报玩家火炮剩余天数 timestamp = int(time.time()) userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag() clientId = util.getClientId(userId) for mode in config.GAME_MODES: for itemId in config.getAllGunIds(clientId, mode): item = userBag.getItemByKindId(itemId) if item and not item.isDied(timestamp): bireport.reportGameEvent("BI_NFISH_GE_GUN_SKIN", userId, FISH_GAMEID, 0, 0, int(itemId), item.balance(timestamp), mode, 0, [], clientId)
def triggerGainChestEvent(event): """ 宝箱奖励事件 """ userId = event.userId chestFrom = event.chestFrom from newfish.entity.quest import quest_system from newfish.entity.chest.chest_system import ChestFromType if chestFrom in (ChestFromType.Daily_Quest_Daily_Chest, ChestFromType.Daily_Quest_Week_Chest): incrQuestTypeData(userId, QuestType.ReceiveDailyChest, 1) if chestFrom == ChestFromType.Daily_Quest_Week_Chest: incrQuestTypeData(userId, QuestType.ReceiveWeekChest, 1) quest_system.getQuestInfo(userId, util.getClientId(userId))
def clearTimer(self): """清理提示和结束的定时器""" super(FishGrandPrixPlayer, self).clearTimer() if self.grandPrixEndTimer: self.grandPrixEndTimer.cancel() self.grandPrixEndTimer = None if self.grandPrixTipTimer: self.grandPrixTipTimer.cancel() self.grandPrixTipTimer = None if self.inGameTimes: bireport.reportGameEvent("BI_NFISH_GRAND_PRIX_INGAMETIMES", self.userId, FISH_GAMEID, 0, 0, self.grandPrixStartTS, self.inGameTimes, 0, 0, [], util.getClientId(self.userId))
def getLevelRewards(userId, level): """ 领取等级奖励 """ clientId = util.getClientId(userId) module_tip.cancelModuleTipEvent(userId, "levelrewards", level) code = 1 userLevel = util.getUserLevel(userId) levels = gamedata.getGameAttrJson(userId, config.FISH_GAMEID, GameData.levelRewards, []) levelRewards = config.getLevelRewards(clientId, level) rewards = [] chestRewards = {} if levelRewards and level not in levels and level <= userLevel: for val in levelRewards.get("rewards", []): itemId = val["name"] if util.isChestRewardId(itemId): chestRewards["chestId"] = itemId chestRewards["rewards"] = chest_system.getChestRewards( userId, itemId) code = chest_system.deliveryChestRewards( userId, itemId, chestRewards["rewards"], "BI_NFISH_GET_LEVEL_REWARDS") else: r = [{"name": val["name"], "count": val["count"]}] rewards.extend(r) code = util.addRewards(userId, r, "BI_NFISH_GET_LEVEL_REWARDS", level) if levelRewards.get("rechargeBonus", 0) > 0: util.incrUserRechargeBonus(userId, levelRewards.get("rechargeBonus", 0)) levels.append(level) gamedata.setGameAttr(userId, config.FISH_GAMEID, GameData.levelRewards, json.dumps(levels)) mo = MsgPack() mo.setCmd("levelRewards") mo.setResult("gameId", config.FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("code", code) mo.setResult("level", level) mo.setResult("rewards", rewards) mo.setResult("chestRewards", chestRewards) router.sendToUser(mo, userId) ftlog.debug("level_rewards, userId =", userId, "code =", code, "level =", level, "userLevel =", userLevel, "rewards =", rewards, "levels =", levels) getLevelRewardsData(userId)
def _triggerItemChangeEvent(event): # 只有通过渔场外增加的资产,且用户在渔场内时才需要刷新用户数据 if event.type == 0 and (event.changed.get("ud") or event.changed.get("items")): isIn, roomId, tableId, seatId = util.isInFishTable(event.userId) if isIn: mo = MsgPack() mo.setCmd("table_call") mo.setParam("action", "refresh_user_data") mo.setParam("gameId", FISH_GAMEID) mo.setParam("clientId", util.getClientId(event.userId)) mo.setParam("userId", event.userId) mo.setParam("roomId", roomId) mo.setParam("tableId", tableId) mo.setParam("seatId", seatId) router.sendTableServer(mo, roomId)
def initGun(userId): """ 初始化炮数据 """ clientId = util.getClientId(userId) for mode in config.GAME_MODES: for gunId in config.getAllGunIds(clientId, mode): updateGun(userId, gunId, mode) gunData = getGunData(userId, gunId, mode) skinId = gunData[INDEX_SKINID] skins = config.getGunConf(gunId, clientId, mode=mode).get("skins") # 配置炮的皮肤 if skinId not in skins: gunData[INDEX_SKINID] = skins[0] setGunData(userId, gunId, gunData, mode)
def setGunData(userId, gunId, gunInfo, mode): """ 存储单个炮数据 """ clientId = util.getClientId(userId) assert int(gunId) in config.getAllGunIds(clientId, mode) assert isinstance(gunInfo, list) and len(gunInfo) == 3 skins = config.getGunConf(gunId, clientId, mode=mode).get("skins") if gunInfo[INDEX_SKINID] not in skins: ftlog.error("setGunData, not find skin, userId =", userId, "gunId =", gunId, "gunInfo =", gunInfo, "skins =", skins, "mode =", mode, "clientId =", clientId) gunInfo[INDEX_SKINID] = skins[0] daobase.executeUserCmd(userId, "HSET", _buildUserGunKey(userId, mode), str(gunId), json.dumps(gunInfo))
def getSectionTasksInfo(userId, sectionId=None): """ 获取该章节下的所有任务信息 """ sectionId = sectionId or gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.currSectionId) tasks = [] if sectionId: clientId = util.getClientId(userId) lang = util.getLanguage(userId) sectionConf = config.getMainQuestSectionConf(clientId, sectionId) for taskId in sectionConf["taskIds"]: taskDict = getTaskInfo(userId, clientId, taskId, lang) tasks.append(taskDict) return tasks
def getGunData(userId, gunId, mode): """ 获得单个皮肤炮数据 """ clientId = util.getClientId(userId) assert int(gunId) in config.getAllGunIds(clientId, mode) gunConf = config.getGunConf(gunId, clientId, mode=mode) value = daobase.executeUserCmd(userId, "HGET", _buildUserGunKey(userId, mode), str(gunId)) if value: value = strutil.loads(value, False, True) if len(value) <= 2: value.append(gunConf["skins"][0]) # 默认皮肤 return value # 获取初始化的值 return [1, 0, gunConf["skins"][0]]
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 buyProduct(roomId, tableId, userId, productId, level, loginDays): """购买商品""" try: room = gdata.rooms()[roomId] table = room.maptable[tableId] player = table.getPlayer(userId) if player: from poker.entity.biz import bireport bireport.reportGameEvent("BI_NFISH_BUY_PRODUCT", userId, FISH_GAMEID, roomId, productId, level, 0, 0, 0, [], util.getClientId(userId), loginDays, player.allChip) # ftlog.debug("BI_NFISH_BUY_PRODUCT", userId, roomId, productId, level, player.chip, player.allChip, player.tableChip) except Exception, e: ftlog.error("buyProduct error", roomId, tableId, userId, productId, level, loginDays, traceback.format_exc())
def _triggerLevelUpEvent(event): """ 炮台升级/升倍率事件弹出升级礼包 """ userId = event.userId clientId = util.getClientId(userId) mode = event.gameMode if mode != 1: return gunLv = util.getGunLevelVal(userId, mode) levelGiftConf = config.getLevelGiftConf() for giftId, giftConf in levelGiftConf.iteritems(): if not giftConf["minLevel"] <= gunLv <= giftConf["maxLevel"]: continue if not _isBought(userId, giftId): doSendLevelGift(userId, clientId) break
def getGunIds(userId, mode): """ 玩家当前拥有的火炮ID """ clientId = util.getClientId(userId) gunIds = [0] userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag() ownGunSkinSkinsKey = GameData.ownGunSkinSkins ownGunSkinSkins = gamedata.getGameAttrJson(userId, FISH_GAMEID, ownGunSkinSkinsKey, []) for kindId in config.getAllGunIds(clientId, mode): item = userBag.getItemByKindId(kindId) gunConf = config.getGunConf(kindId, clientId, mode=mode) if gunConf["skins"][0] in ownGunSkinSkins: # 是否拥有皮肤炮默认永久皮肤 gunIds.append(kindId) elif item and not item.isDied(int(time.time())): # 皮肤炮是否过期 没过期 gunIds.append(kindId) return gunIds
def _triggerTYOpenItemEvent(event): userId = event.userId itemKind = event.item.itemKind lang = util.getLanguage(userId) for key, value in config.getChestConf().iteritems(): if value["kindId"] == itemKind.kindId: from hall.entity import halluser from hall.entity.todotask import TodoTaskShowInfo, TodoTaskHelper from newfish.entity import mail_system message = config.getMultiLangTextConf("ID_OPEN_ITEM_GET_REWARD_MSG", lang=lang) % value["name"] GameMsg.sendPrivate(FISH_GAMEID, userId, 0, message) todoTask = TodoTaskShowInfo(message) TodoTaskHelper.sendTodoTask(FISH_GAMEID, userId, todoTask) halluser.ensureGameDataExists(userId, FISH_GAMEID, util.getClientId(userId)) message = config.getMultiLangTextConf("ID_USE_ITEM_GET_REWARD_MSG", lang=lang).format(itemKind.displayName, value["name"]) rewards = [{"name": value["chestId"], "count": 1}] mail_system.sendSystemMail(userId, mail_system.MailRewardType.ChestReward, rewards, message) break