def triggerWinCmpttTaskEvent(event): """ 夺宝赛获奖事件 """ bigRoomId, _ = util.getBigRoomId(event.roomId) fishPool = util.getFishPoolByBigRoomId(bigRoomId) userId = event.userId _incQuestValue(userId, TaskType.WinTask, 1, fishPool=fishPool)
def triggerFireEvent(event): """ 开火事件 """ bigRoomId, _ = util.getBigRoomId(event.roomId) fishPool = util.getFishPoolByBigRoomId(bigRoomId) fpMultiple = event.fpMultiple if hasattr(event, "fpMultiple") else 0 userId = event.userId _incQuestValue(userId, TaskType.FireNum, 1, fishPool=fishPool, fpMultiple=fpMultiple)
def triggerWinBonusTaskEvent(event): """ 奖金赛获奖事件 """ bigRoomId, _ = util.getBigRoomId(event.roomId) fishPool = util.getFishPoolByBigRoomId(bigRoomId) userId = event.userId rank = event.rank _incQuestValue(userId, TaskType.WinTask, 1, fishPool=fishPool)
def getCurrentGiftConf(self): """ 获取当前可显示礼包的配置 """ isIn, roomId, _, _ = util.isInFishTable(self.userId) if not isIn: return [], "" mode = util.getGiftDTestMode(self.userId) fishPool = util.getFishPoolByBigRoomId(util.getBigRoomId(roomId)[0]) grade, nextGrade = self._getGrade(fishPool) # 获取礼包档位 giftAbcTestConf = config.getGiftAbcTestConf(self.clientId) giftListConf = giftAbcTestConf.get("data", {}).get( str(fishPool), {}).get(grade, {}).get("giftList", {}).get(mode, []) nextGiftListConf = giftAbcTestConf.get("data", {}).get( str(fishPool), {}).get(nextGrade, {}).get("giftList", {}).get(mode, []) buyTimes = self._getBuyTimes(fishPool) recommonGift = [] # 当前房间可以使用的破产礼包列表. for idx, giftGroup in enumerate(zip(giftListConf, nextGiftListConf)): if not set(self.availableGift) & set(giftGroup): # 优先展示可领取的礼包 continue if buyTimes - 1 != idx: continue for giftId in giftGroup: giftConf = giftAbcTestConf.get("gift", {}).get(str(giftId)) if not giftConf: continue recommonGift.append(giftConf) if ftlog.is_debug(): ftlog.debug("BankruptGift_getCurrentGiftConf", fishPool, giftListConf, nextGiftListConf, grade, nextGrade, recommonGift) # 没有可领取礼包则按照已购买次数显示礼包. if not recommonGift: if 0 <= buyTimes < len(giftListConf): listConf2 = giftAbcTestConf.get("data", {}).get( str(fishPool), {}).get(nextGrade, {}).get("giftList", {}).get(mode, []) giftId1, giftId2 = giftListConf[buyTimes], listConf2[buyTimes] recommonGift = [ giftAbcTestConf.get("gift", {}).get(str(giftId1)), giftAbcTestConf.get("gift", {}).get(str(giftId2)) ] lang = util.getLanguage(self.userId, self.clientId) remainTimes = max(0, len(giftListConf) - buyTimes) if recommonGift: gamedata.setGameAttr(self.userId, FISH_GAMEID, GameData.bankruptGiftInfo, json.dumps([fishPool, grade, nextGrade])) tip = config.getMultiLangTextConf("ID_BANKRUPT_GIFT_TIP", lang=lang).format(remainTimes) else: tip = "" return recommonGift, tip
def triggerUseSkillEvent(event): """ 使用技能事件 """ bigRoomId, _ = util.getBigRoomId(event.roomId) fishPool = util.getFishPoolByBigRoomId(bigRoomId) fpMultiple = event.fpMultiple if hasattr(event, "fpMultiple") else 0 userId = event.userId skillId = event.skillId _incQuestValue(userId, TaskType.SkillUseNum, 1, fishPool=fishPool, fpMultiple=fpMultiple)
def triggerEnterTableEvent(event): """ 进入渔场事件(参加回馈赛) """ if event.reconnect: return userId = event.userId bigRoomId, isMatch = util.getBigRoomId(event.roomId) if isMatch: _incQuestValue(userId, TaskType.EnterMatchTimes, 1) fishPool = util.getFishPoolByBigRoomId(bigRoomId) _incQuestValue(userId, TaskType.EnterFishPool, 1, fishPool=fishPool)
def spin(self, weightList, fpMultiple): """ 转动轮盘 """ fishPool = str(self.fishPool) prizeConf = self.getPrizeConf(fishPool, fpMultiple) pwData = self._getData(fishPool, fpMultiple) try: # 获取轮盘结果 idx = util.selectIdxByWeight(weightList) rewards = prizeConf["wheel"][idx]["rewards"] ratioList = self._buildRetData(fishPool, fpMultiple, rewards) pwData[PWValueSlot.RET] = ratioList except: code = 1 self._resetPrizeWheelState(fishPool, fpMultiple) ftlog.error("prize_wheel, userId =", self.userId) return code else: code = 0 _idx = len(pwData[PWValueSlot.TAKEN]) if _idx >= len(self.pwConf["energy"]): _idx = -1 pwData[PWValueSlot.TAKEN].append(idx) # 扣除可用抽奖次数. if not self.isEnergyStorageMode: pwData[PWValueSlot.SPINTIMES] = 0 else: pwData[PWValueSlot.SPINTIMES] -= 1 pwData[PWValueSlot.SPINTIMES] = max( 0, pwData[PWValueSlot.SPINTIMES]) pwData[PWValueSlot.STATE] = PWState.NOT_TAKE_REWARD self.sendEnergyProgress(self.fishPool, fpMultiple, self.roomId, -1) # 给其他渔场充能 addEnergy = self.pwConf["energy"][_idx].get(fishPool, {}).get("add", {}) for roomId, val in addEnergy.iteritems(): roomId = int(roomId) bigRoomId, _ = util.getBigRoomId(roomId) fp = util.getFishPoolByBigRoomId(bigRoomId) if self._addEnergy(fp, fpMultiple, val): self.sendEnergyProgress(fp, fpMultiple, roomId, val) self._setData(fishPool, fpMultiple) from newfish.game import TGFish event = PrizeWheelSpinEvent(self.userId, config.FISH_GAMEID, self.roomId) TGFish.getEventBus().publishEvent(event) return code
def triggerCatchEvent(event): """捕获事件""" bigRoomId, _ = util.getBigRoomId(event.roomId) typeName = util.getRoomTypeName(event.roomId) fishPool = util.getFishPoolByBigRoomId(bigRoomId) fpMultiple = event.fpMultiple if hasattr(event, "fpMultiple") else 0 userId = event.userId fishTypes = event.fishTypes gain_chip = event.gainChip resetTime = event.resetTime gunX = event.gunX * event.gunSkinMul fish_boss_num = 0 fish_multiple_num = 0 terror_num = 0 all_fish_num = len(fishTypes) for fishType in fishTypes: fishConf = config.getFishConf(fishType, typeName) if fishConf["type"] in config.BOSS_FISH_TYPE: # Boss fish_boss_num += 1 elif fishConf["type"] in config.ROBBERY_BOSS_FISH_TYPE: # 招财Boss fish_boss_num += 1 all_fish_num -= 1 elif fishConf["type"] in config.MULTIPLE_FISH_TYPE: # 倍率鱼 fish_multiple_num += 1 elif fishConf["type"] in config.ROBBERY_MULTIPLE_FISH_TYPE: # 招财倍率鱼 fish_multiple_num += 1 all_fish_num -= 1 if fishConf["type"] in config.TERROR_FISH_TYPE: # 特殊鱼 terror_num += 1 if fish_boss_num: _incQuestValue(userId, TaskType.GunYBossFishNum, fish_boss_num, resetTime, fishPool=fishPool, fpMultiple=fpMultiple, gunX=gunX) if fish_multiple_num: _incQuestValue(userId, TaskType.GunYMultipleFishNum, fish_multiple_num, resetTime, fishPool=fishPool, fpMultiple=fpMultiple, gunX=gunX) if all_fish_num: _incQuestValue(userId, TaskType.GunYFishNum, all_fish_num, resetTime, fishPool=fishPool, fpMultiple=fpMultiple, gunX=gunX) _incQuestValue(userId, TaskType.FishNum, all_fish_num, resetTime, fishPool=fishPool, fpMultiple=fpMultiple) if gain_chip: _incQuestValue(userId, TaskType.CoinNum, gain_chip, resetTime, fishPool=fishPool, fpMultiple=fpMultiple) if terror_num: _incQuestValue(userId, TaskType.GunYTerrorFishNum, terror_num, resetTime, fishPool=fishPool, fpMultiple=fpMultiple, gunX=gunX) _incQuestValue(userId, TaskType.TerrorFishNum, terror_num, resetTime, fishPool=fishPool, fpMultiple=fpMultiple)
def getInfo(self, fpMultiple, action=0): """ 获取轮盘数据 """ fishPool = str(self.fishPool) pwData = self._getData(fishPool, fpMultiple) code = 1 mo = MsgPack() mo.setCmd("prize_wheel_info") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", self.userId) mo.setResult("act", action) prizeConf = self.getPrizeConf(fishPool, fpMultiple) info = {} # 获取转盘奖励数据 prizeList = [] weightList = [] info["prizeList"] = prizeList if self._enable(fishPool, fpMultiple): for idx, item in enumerate(prizeConf.get("wheel", [])): prizeList.append({ "name": item["rewards"]["name"], "count": item["rewards"]["count"] }) enable = 1 if idx not in pwData[PWValueSlot.TAKEN] else 0 prizeList[-1].update({"enable": enable}) weightList.append(item["rate"] if enable else 0) if action == 0: # 查询 code = 0 elif action == 1 and prizeList and weightList and sum(weightList) \ and pwData[PWValueSlot.SPINTIMES] > 0 and pwData[PWValueSlot.STATE] == PWState.NOT_SPIN: # 抽奖 code = self.spin(weightList, fpMultiple) # 更新数据. pwData = self._getData(fishPool, fpMultiple) if pwData[PWValueSlot.STATE] in [ PWState.NOT_TAKE_REWARD, PWState.FAIL_SPIN ]: if code == 0: consumeDiamond, rewards = self.getConsumeDiamond(pwData) info["rewards"] = [rewards] info["paidInfo"] = { "name": config.DIAMOND_KINDID, "count": consumeDiamond } info["ratioList"] = pwData[PWValueSlot.RET] # 如果没有设置倍数则直接领取当前奖励. if action == 1 and len(info["ratioList"]) == 1: self.setRewards(fpMultiple, 1, "bet") if pwData[PWValueSlot.STATE] == PWState.FAIL_SPIN: info["betFail"] = pwData[PWValueSlot.BET] else: info["rewards"] = [] info["ratioList"] = [] else: info["rewards"] = [] info["ratioList"] = [] mo.setResult("info", info) mo.setResult("code", code) mo.setResult("state", pwData[PWValueSlot.STATE]) mo.setResult("curRemainTimes", pwData[PWValueSlot.SPINTIMES]) nextRoomId = prizeConf.get("nextRoomId", 0) if nextRoomId: bigRoomId, _ = util.getBigRoomId(nextRoomId) nextFishPool = util.getFishPoolByBigRoomId(bigRoomId) mo.setResult("nextRoomId", nextRoomId) mo.setResult("nextRoomMultiple", prizeConf.get("nextRoomMultiple", 0)) mo.setResult("nextProgressPct", self._getEnergyPct(nextFishPool, fpMultiple)) mo.setResult( "nextRemainTimes", self._getData(nextFishPool, fpMultiple)[PWValueSlot.SPINTIMES]) GameMsg.sendMsg(mo, self.userId) if ftlog.is_debug(): ftlog.debug("prize_wheel, userId =", self.userId, "fishPool =", fishPool, "fpMultiple =", fpMultiple, "msg =", mo)