def __init__(self, player, fireRange, idleRange, leaveRange): self.player = player self.userId = player.userId self.player.table.clip_add(player.userId, player.seatId) ftlog.debug("__init__", player.userId, player.chip, player.clip) self.fireInterval = config.getGunLevelConf(self.nowGunLevel, self.player.table.gameMode).get("interval", 0.3) self.updateTimer = None self.updateTimer = FTLoopTimer(5, -1, self._update) self.updateTimer.start() self.fireTimer = None self.fireTargetPos = [0, 0] self.bulletId = 0 # 空闲次数 self.idleCount = 0 # 开火次数 self.fireCount = 0 # 等待离开 self.waitLeaveCount = 0 # 表情 self.exp = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] self.fireRange = fireRange self.idleRange = idleRange self.leaveRange = leaveRange self.updateCount = 0 self.needClear = False # 全是机器人的计数 self.allRobotCount = 0
def getUpgradeItemsConf(userId, gunLevel, mode=CLASSIC_MODE): """ 获取升级材料配置 """ upgradeItems = config.getGunLevelConf(gunLevel, mode).get("upgradeItems", {}) return upgradeItems
def matchEnterRoom(cls, roomId, uLevel, gunLevel, userChip, gameMode): """是否满足推荐房间准入条件""" roomConf = gdata.roomIdDefineMap()[roomId].configure minLevel = roomConf.get("minLevel", 1) gunLevelVal = config.getGunLevelConf(gunLevel, gameMode).get("levelValue", 1) minGunLevelVal = roomConf.get("minGunLevelVal", 0) minCoin = roomConf.get("minCoin", 0) typeName = roomConf.get("typeName") roomType = config.CLASSIC_MODE_ROOM_TYPE if gameMode == config.MULTIPLE_MODE: roomType = config.MULTIPLE_MODE_ROOM_TYPE if typeName in roomType: if uLevel >= minLevel and gunLevelVal >= minGunLevelVal and userChip >= minCoin: return True return False
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 gunChange(self, gLv): """ 切换火炮等级 """ reason = 0 if gLv > self.gunLevel or not config.getGunLevelConf( gLv, self.table.gameMode): reason = 1 else: if gLv < self.table.runConfig.minGunLevel: return elif gLv > self.tableMaxGunLevel(): return elif self.getUsingSkillInfo(): # 技能处于使用中时,升级炮台,炮台等级需等技能状态结束后才会切换更新 self.nowGunLevel = gLv return gunMultiple = config.getGunConf(self.gunId, self.clientId, self.gunLv, self.table.gameMode).get( "multiple", 1) retMsg = MsgPack() retMsg.setCmd("gchg") retMsg.setResult("gameId", config.FISH_GAMEID) retMsg.setResult("gLv", gLv) retMsg.setResult("userId", self.userId) retMsg.setResult("seatId", self.seatId) retMsg.setResult("gunMultiple", gunMultiple) retMsg.setResult("gameMode", self.table.gameMode) retMsg.setResult("reason", reason) retMsg.setResult("tableMaxGunLevel", self.tableMaxGunLevel()) GameMsg.sendMsg(retMsg, self.userId) if reason == 0: self.nowGunLevel = gLv result = retMsg.getKey("result") del result["reason"] GameMsg.sendMsg(retMsg, self.table.getBroadcastUids(self.userId)) from newfish.game import TGFish event = ChangeGunLevelEvent(self.userId, config.FISH_GAMEID, self.table.bigRoomId, self.nowGunLevel) TGFish.getEventBus().publishEvent(event) self.syncSkillSlots()
def doBuyLevelGift(userId, clientId, buyType, productId, itemId=0): """ 购买升级礼包 """ levelGift = config.getLevelGiftConf() giftId = 0 for val in levelGift.values(): if val.get("productId") == productId: giftId = val["giftId"] break if giftId == 0: return levelGiftConf = levelGift.get(str(giftId), {}) commonRewards = [] if _isBought(userId, giftId): code = 1 elif buyType == config.BT_DIAMOND: price = levelGiftConf.get("discountPrice", 0) price, isSucc = store.getUseRebateItemPrice(userId, itemId, price, buyType, productId, clientId) code = 0 if price > 0: consumeCount = 0 if isSucc: # 用优惠券 store.autoConvertVoucherToDiamond(userId, price) consumeCount, final = userchip.incrDiamond(userId, FISH_GAMEID, -abs(price), 0, "BI_NFISH_BUY_LEVEL_GIFT_CONSUME", int(config.DIAMOND_KINDID), util.getClientId(userId), param01=productId) if not isSucc or abs(consumeCount) != price: code = 2 _sendBuyLevelGiftRet(userId, clientId, productId, code, commonRewards) return else: code = 4 else: code = 3 if code == 0: # 记录存档 boughtGift = gamedata.getGameAttrJson(userId, FISH_GAMEID, GameData.buyLevelGift, []) boughtGift.append(int(giftId)) gamedata.setGameAttr(userId, FISH_GAMEID, GameData.buyLevelGift, json.dumps(boughtGift)) # 升级炮倍率 gunLv = util.getGunLevelVal(userId, config.MULTIPLE_MODE) if gunLv < levelGiftConf["levelUp"]: gunLevel = gunLv for level in config.getGunLevelKeysConf(config.MULTIPLE_MODE): value = config.getGunLevelConf(level, config.MULTIPLE_MODE) if value["levelValue"] == levelGiftConf["levelUp"]: gunLevel = level break gamedata.setGameAttr(userId, FISH_GAMEID, GameData.gunLevel_m, gunLevel) from newfish.game import TGFish from newfish.entity.event import GunLevelUpEvent event = GunLevelUpEvent(userId, FISH_GAMEID, gamedata.getGameAttr(userId, FISH_GAMEID, GameData.level), gunLevel, config.MULTIPLE_MODE) TGFish.getEventBus().publishEvent(event) bireport.reportGameEvent("BI_NFISH_GE_LEVEL_UP", userId, FISH_GAMEID, 0, 0, 0, config.MULTIPLE_MODE, 0, 0, [gunLevel], util.getClientId(userId)) # 发奖励 rewards = levelGiftConf.get("rewards", []) # 资产/道具 code = util.addRewards(userId, rewards, "BI_NFISH_BUY_ITEM_GAIN", int(giftId), param01=int(giftId)) commonRewards.extend(rewards) _sendBuyLevelGiftRet(userId, clientId, productId, code, commonRewards) util.addProductBuyEvent(userId, productId, clientId)
def upgradeGun(userId, protect, mode, byGift=False, upToLevel=0): """ 升级普通炮 """ def consume(items, level): """消耗升级所需道具""" _consumeList = [] for kindId, count in items.iteritems(): if int(kindId) == config.PURPLE_CRYSTAL_KINDID: _consumeList.extend( consumeBindOrNotBindItem(userId, config.BIND_PURPLE_CRYSTAL_KINDID, config.PURPLE_CRYSTAL_KINDID, count)) elif int(kindId) == config.YELLOW_CRYSTAL_KINDID: _consumeList.extend( consumeBindOrNotBindItem(userId, config.BIND_YELLOW_CRYSTAL_KINDID, config.YELLOW_CRYSTAL_KINDID, count)) else: _consume = {"name": int(kindId), "count": count} _consumeList.append(_consume) util.consumeItems(userId, _consumeList, "ITEM_USE", level) gunLevelKey = GameData.gunLevel if mode == CLASSIC_MODE else GameData.gunLevel_m gunLevel, level = gamedata.getGameAttrs(userId, FISH_GAMEID, [gunLevelKey, GameData.level]) if not gunLevel or gunLevel >= config.getMaxGunLevel(mode): return False nextGunLevel = config.getNextGunLevel(gunLevel, mode) if nextGunLevel == -1: ftlog.error("gunLevel error! userId =", userId, "gunLevel =", gunLevel, "mode =", mode) return False nextGunLevelConf = config.getGunLevelConf(nextGunLevel, mode) upgradeItemsConf = getUpgradeItemsConf(userId, nextGunLevel, mode=mode) returnRewards = None levelUpRewards = None if not byGift: if isEnough(userId, upgradeItemsConf): # 判断升级所需物品是否足够 if nextGunLevelConf["successRate"] >= 10000: # 是否100%成功 consume(upgradeItemsConf, level) # 消耗升级所需物品 code = 0 # 升级成功 else: if protect: # 是否使用五彩水晶 if isEnough( userId, nextGunLevelConf["protectItems"]): # 判断五彩水晶是否足够 consume(upgradeItemsConf, level) # 消耗升级所需物品 consume(nextGunLevelConf["protectItems"], level) # 消耗五彩水晶 code = 0 else: code = 99 # 五彩水晶物品不足 else: consume(upgradeItemsConf, level) # 消耗升级所需物品 randInt = random.randint(1, 10000) if randInt <= nextGunLevelConf["successRate"]: code = 0 else: randInt = random.randint(1, 10000) for item in nextGunLevelConf["returnItems"]: if item["probb"][0] <= randInt <= item["probb"][1]: returnRewards = [{ "name": item["kindId"], "count": item["count"] }] break code = 1 # 升级失败,返还道具 else: code = 99 # 升级所需物品不足 else: if upToLevel > gunLevel: code = 0 else: code = 1 if code == 0: # level += 1 # gunLevel += 1 # gamedata.setGameAttrs(userId, FISH_GAMEID, [GameData.level, GameData.gunLevel], [level, gunLevel]) # gunLevel += 1 if "levelRewards" in nextGunLevelConf and nextGunLevelConf[ "levelRewards"] > 0: levelUpRewards = [{ "name": config.CHIP_KINDID, "count": nextGunLevelConf["levelRewards"] }] gunLevel = nextGunLevel if not byGift else upToLevel gamedata.setGameAttr(userId, FISH_GAMEID, gunLevelKey, gunLevel) from newfish.game import TGFish from newfish.entity.event import GunLevelUpEvent event = GunLevelUpEvent(userId, FISH_GAMEID, level, gunLevel, mode) TGFish.getEventBus().publishEvent(event) bireport.reportGameEvent("BI_NFISH_GE_LEVEL_UP", userId, FISH_GAMEID, 0, 0, int(level), mode, 0, 0, [byGift, upToLevel, gunLevel], util.getClientId(userId)) mo = MsgPack() mo.setCmd("gun_up") # 升级普通炮 mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("level", level) mo.setResult("gunLevel", gunLevel) mo.setResult("gameMode", mode) mo.setResult("code", code) if returnRewards: util.addRewards(userId, returnRewards, "ASSEMBLE_ITEM", level) mo.setResult("returnRewards", returnRewards) if levelUpRewards: util.addRewards(userId, levelUpRewards, "ASSEMBLE_ITEM", level) mo.setResult("levelUpRewards", levelUpRewards) router.sendToUser(mo, userId) sendGunInfoMsg(userId, mode) # 发送普通炮信息 return code == 0
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