def doGoldLottery(userId, gameId, clientId, number): ''' 金盘抽奖 ''' if number <= 0 or number > 50: ftlog.error('doGoldLottery number best be > 0 or <= 50, the msg is fake') return if ftlog.is_debug(): ftlog.debug('hallroulette.doGoldLottery userId:', userId, ' gameId:', gameId, ' clientId:', clientId, ' number:', number ) # 减少钻石 result = {} count = -(number * 20) trueDelta, _finalCount = userchip.incrDiamond(userId, gameId, count, daoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, 'HALL_ROULETTE', 0, 0) if not trueDelta: # 消费失败 return toShop() # 将抽奖数进行存储,满足bigRewardNumber,使用大奖概率,否则使用小奖概率 addBigRewardToPool(userId, gameId, clientId, number) # 抽奖 items = [] for _num in range(0, number): items.append(doRouletteLottery(userId, gameId, clientId)) result['items'] = items # 对抽奖进行修改,连抽的话进行统一的数据库操作 sendGiftsToUser(userId, gameId, clientId, items) # 更新钻石 datachangenotify.sendDataChangeNotify(gameId, userId, ['udata']) # 抽奖成功,进行小兵的下发 for _ in range(0, number): daobase.executeMixCmd('RPUSH', CURKEY, userId) # 统计需求 ftlog.hinfo('doGoldLottery.userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'number=', number, 'rouletteType=', 2, 'rewardItem=', items) TGHall.getEventBus().publishEvent(TYEventRouletteDiamond(userId, gameId, number)) return result
def doGoldLottery(userId, gameId, clientId, number): ''' 金盘抽奖 ''' if number <= 0 or number > 50: ftlog.error( 'doGoldLottery number best be > 0 or <= 50, the msg is fake') return if ftlog.is_debug(): ftlog.debug('hallroulette.doGoldLottery userId:', userId, ' gameId:', gameId, ' clientId:', clientId, ' number:', number) # 减少钻石 result = {} count = -(number * 20) trueDelta, _finalCount = userchip.incrDiamond( userId, gameId, count, daoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, 'HALL_ROULETTE', 0, 0) if not trueDelta: # 消费失败 return toShop() # 将抽奖数进行存储,满足bigRewardNumber,使用大奖概率,否则使用小奖概率 addBigRewardToPool(userId, gameId, clientId, number) # 抽奖 items = [] for _num in range(0, number): items.append(doRouletteLottery(userId, gameId, clientId)) result['items'] = items # 对抽奖进行修改,连抽的话进行统一的数据库操作 sendGiftsToUser(userId, gameId, clientId, items) # 更新钻石 datachangenotify.sendDataChangeNotify(gameId, userId, ['udata']) # 抽奖成功,进行小兵的下发 for _ in range(0, number): daobase.executeMixCmd('RPUSH', CURKEY, userId) # 统计需求 ftlog.hinfo('doGoldLottery.userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'number=', number, 'rouletteType=', 2, 'rewardItem=', items) TGHall.getEventBus().publishEvent( TYEventRouletteDiamond(userId, gameId, number)) return result
def doGdssAddUserDiamond(self, userId, gameId, deltaCount, intEventParam): mo = MsgPack() mo.setResult('userId', userId) mo.setResult('gameId', gameId) mo.setResult('adjustDelta', deltaCount) mo.setResult('trueDelta', 0) mo.setResult('final', 0) ec, result = self.checkCode() if ec == 0: if deltaCount > 100000: mo.setError(1, 'coupon deltaCount to much !!') else: if userdata.checkUserData(userId): trueDelta, final = userchip.incrDiamond(userId, gameId, deltaCount, daoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, 'GM_ADJUST', intEventParam, configure.CLIENTID_SYSCMD) mo.setResult('trueDelta', trueDelta) mo.setResult('final', final) else: mo.setError(2, 'userId error !!') if ec != 0: mo.setError(ec, result) return mo
def doBuyGift(userId, clientId, giftId, buyType, itemId=0): """ 购买礼包 """ if ftlog.is_debug(): ftlog.debug("doBuyGift===>", userId, clientId, giftId, buyType) giftConf = config.getDailyGiftConf(clientId).get(str(giftId), {}) continuousDay = _getContinuousDay(userId, giftId) dayIdx = _getGiftDayIdx(clientId, giftId, continuousDay) lang = util.getLanguage(userId, clientId) commonRewards = [] chestRewards = [] chestId = 0 giftName = config.getMultiLangTextConf(giftConf["giftName"], lang=lang) # 使用其他货币(非direct)购买 if giftConf.get("otherBuyType", {}).get(buyType): price = giftConf.get("otherBuyType", {}).get(buyType) # 代购券购买礼包 if buyType == BT_VOUCHER: _consume = [{"name": VOUCHER_KINDID, "count": abs(price)}] _ret = util.consumeItems(userId, _consume, "BI_NFISH_BUY_ITEM_CONSUME", intEventParam=int(giftId), param01=int(giftId)) if not _ret: code = 1 _sendBuyGiftRet(userId, clientId, giftId, code, chestId, commonRewards, chestRewards) return else: code = 0 vip_system.addUserVipExp(FISH_GAMEID, userId, abs(price) * 10, "BUY_PRODUCT", pokerconf.productIdToNumber( giftConf["productId"]), giftConf["productId"], rmbs=abs(price)) # message = u"您使用%s代购券,购买商品【%s】, 获得%s" % (price, giftConf["giftName"], giftConf["giftName"]) message = config.getMultiLangTextConf( "ID_BUY_GIFT_RET_BY_VOUCHER", lang=lang).format(price, giftName, giftName) GameMsg.sendPrivate(FISH_GAMEID, userId, 0, message) else: code = 1 _sendBuyGiftRet(userId, clientId, giftId, code, chestId, commonRewards, chestRewards) return elif buyType == config.BT_DIAMOND: price = giftConf.get("price", 0) price, isSucc = store.getUseRebateItemPrice(userId, itemId, price, buyType, giftId, 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_ITEM_CONSUME", int(giftId), util.getClientId(userId), param01=giftId) if not isSucc or abs(consumeCount) != price: code = 1 _sendBuyGiftRet(userId, clientId, giftId, code, chestId, commonRewards, chestRewards) return else: code = 0 # message = u"您购买商品【%s】, 获得%s" % (giftConf["giftName"], giftConf["giftName"]) message = config.getMultiLangTextConf("ID_BUY_GIFT_RET_BY_DRIECT", lang=lang).format( giftName, giftName) GameMsg.sendPrivate(FISH_GAMEID, userId, 0, message) # 记录存档 boughtGift = weakdata.getDayFishData(userId, WeakData.buyFishDailyGift, []) boughtGift.append(giftId) weakdata.setDayFishData(userId, WeakData.buyFishDailyGift, json.dumps(boughtGift)) # 记录每日礼包购买次数. buyFishDailyGiftTimes = gamedata.getGameAttrJson( userId, FISH_GAMEID, GameData.buyFishDailyGiftTimes, {}) buyFishDailyGiftTimes.setdefault(str(giftId), 0) buyFishDailyGiftTimes[str(giftId)] += 1 gamedata.setGameAttr(userId, FISH_GAMEID, GameData.buyFishDailyGiftTimes, json.dumps(buyFishDailyGiftTimes)) purchaseData = gamedata.getGameAttrJson(userId, FISH_GAMEID, GameData.continuousPurchase, {}) data = purchaseData.get(str(giftId), [0, 0]) if util.getDayStartTimestamp( data[0]) + 24 * 60 * 60 < util.getDayStartTimestamp( int(time.time())): data[1] = 1 else: data[1] += 1 data[0] = int(time.time()) purchaseData[str(giftId)] = data gamedata.setGameAttr(userId, FISH_GAMEID, GameData.continuousPurchase, json.dumps(purchaseData)) # 发奖励 mail_rewards = [] giftInfo = giftConf.get("giftInfo", []) for gift in giftInfo: if gift["day_idx"] == dayIdx: for item in gift.get("items", []): if util.isChestRewardId(item["itemId"]): # 宝箱 chestId = item["itemId"] rewards = chest_system.getChestRewards(userId, chestId) if buyType == BT_VOUCHER or buyType == config.BT_DIAMOND: code = chest_system.deliveryChestRewards( userId, chestId, rewards, "BI_NFISH_BUY_ITEM_GAIN") else: code = 0 gamedata.incrGameAttr(userId, FISH_GAMEID, GameData.openChestCount, 1) bireport.reportGameEvent("BI_NFISH_GE_CHEST_OPEN", userId, FISH_GAMEID, 0, 0, int(chestId), 0, 0, 0, [], util.getClientId(userId)) chestRewards.extend(rewards) mail_rewards.extend([{"name": item["itemId"], "count": 1}]) else: # 资产/道具 rewards = [{ "name": item["itemId"], "count": item["count"] }] if buyType == BT_VOUCHER or buyType == config.BT_DIAMOND: code = util.addRewards(userId, rewards, "BI_NFISH_BUY_ITEM_GAIN", int(giftId), param01=int(giftId)) else: code = 0 commonRewards.extend(rewards) mail_rewards.extend(rewards) break if buyType == BT_VOUCHER or buyType == config.BT_DIAMOND: _sendBuyGiftRet(userId, clientId, giftId, code, chestId, commonRewards, chestRewards) else: message = config.getMultiLangTextConf("ID_DO_BUY_GIFT_MSG", lang=lang) % giftName title = config.getMultiLangTextConf("ID_MAIL_TITLE_DAILY_GIFT", lang=lang) mail_system.sendSystemMail(userId, mail_system.MailRewardType.SystemReward, mail_rewards, message, title) doSendGift(userId, clientId) # 购买礼包事件 from newfish.game import TGFish from newfish.entity.event import GiftBuyEvent event = GiftBuyEvent(userId, FISH_GAMEID, giftConf["productId"], buyType, giftId) TGFish.getEventBus().publishEvent(event) util.addProductBuyEvent(userId, giftConf["productId"], clientId)
def setRewards(self, fpMultiple, bet, betType=None): """ 确定转盘奖励结果 """ rewards = [] fishPool = str(self.fishPool) pwData = self._getData(fishPool, fpMultiple) prizeConf = self.getPrizeConf(fishPool, fpMultiple) weightList = [] if self._enable(fishPool, fpMultiple): for idx, item in enumerate(prizeConf.get("wheel", [])): enable = 1 if idx not in pwData[PWValueSlot.TAKEN] else 0 weightList.append(item["rate"] if enable else 0) code = 1 if pwData[PWValueSlot.STATE] in [ PWState.NOT_TAKE_REWARD, PWState.FAIL_SPIN ] and len(pwData[PWValueSlot.RET]) > 0: consumeDiamond, _rewards = self.getConsumeDiamond(pwData) if pwData[PWValueSlot. STATE] == PWState.FAIL_SPIN and betType == "paid": diamondCount = userchip.getDiamond(self.userId) if diamondCount >= consumeDiamond: code = 0 clientId = util.getClientId(self.userId) userchip.incrDiamond(self.userId, config.FISH_GAMEID, -consumeDiamond, self.roomId, "BI_NFISH_BUY_ITEM_CONSUME", config.DIAMOND_KINDID, clientId, param01="prize_wheel") datachangenotify.sendDataChangeNotify( FISH_GAMEID, self.userId, ["chip"]) ratioList = self._buildRetData(fishPool, fpMultiple, _rewards) pwData[PWValueSlot.RET] = ratioList pwData[PWValueSlot.STATE] = PWState.NOT_TAKE_REWARD self._setData(fishPool, fpMultiple) self.getInfo(fpMultiple) elif pwData[PWValueSlot. STATE] == PWState.FAIL_SPIN and betType == "give_up": code = 0 self._resetPrizeWheelState(fishPool, fpMultiple) if ftlog.is_debug(): ftlog.debug("prize_wheel, giveup, userId =", self.userId, "fishPool =", self.fishPool, pwData[PWValueSlot.STATE]) elif pwData[PWValueSlot. STATE] == PWState.NOT_TAKE_REWARD and betType == "bet": for item in pwData[PWValueSlot.RET]: if item["ratio"] != bet: continue try: rewards = [item["rewards"][item["ret"]]] code = 0 if rewards and rewards[0].get("count", 0) > 0: # 抽奖成功,获得奖励 code = util.addRewards( self.userId, rewards, "BI_NFISH_PRIZE_WHEEL_REWARDS", int(fishPool), self.roomId, fpMultiple) self.addRoomLotteryProfitCoin(rewards) self._resetPrizeWheelState(fishPool, fpMultiple) else: # 抽奖失败,谢谢参与 pwData[PWValueSlot.STATE] = PWState.FAIL_SPIN pwData[PWValueSlot.BET] = bet self._setData(fishPool, fpMultiple) self.getInfo(fpMultiple) except: ftlog.error("prize_wheel, userId =", self.userId, "fishPool =", fishPool, "bet =", bet, code, "data =", pwData[PWValueSlot.RET]) break self._setData(fishPool, fpMultiple) mo = MsgPack() mo.setCmd("prize_wheel_bet") mo.setResult("betType", betType) mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", self.userId) mo.setResult("code", code) mo.setResult("bet", bet) mo.setResult("rewards", rewards) GameMsg.sendMsg(mo, self.userId) self.sendEnergyProgress(self.fishPool, fpMultiple, self.roomId, 0)
def buyFishVipGift(userId, level, clientId, buyType=None, itemId=0): """ 购买特定VIP等级的礼包 """ mo = MsgPack() mo.setCmd("buy_fish_vip_gift") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("level", level) vipLevel = hallvip.userVipSystem.getUserVip(userId).vipLevel.level vipGiftBought = gamedata.getGameAttrJson(userId, FISH_GAMEID, GameData.vipGiftBought, []) code = 1 commonRewards = [] chestRewards = [] buyType = buyType if buyType else config.BT_DIAMOND from newfish.entity import store from newfish.entity.gun import gun_system if vipLevel < level or level in vipGiftBought: mo.setResult("code", code) router.sendToUser(mo, userId) return vipConf = config.getVipConf(level) if vipConf: price = vipConf["price"] vipGiftRewards = vipConf["vipGift"] price, isSucc = store.getUseRebateItemPrice(userId, itemId, price, buyType, vipConf["productId"], clientId) # 满减券之后的钻石 满减券 consumeCount = 0 if price > 0 and isSucc: store.autoConvertVoucherToDiamond(userId, price) # 代购券 consumeCount, final = userchip.incrDiamond( userId, FISH_GAMEID, -abs(price), 0, "BI_NFISH_BUY_ITEM_CONSUME", int(config.DIAMOND_KINDID), util.getClientId(userId), param01=vipConf["productId"]) if not isSucc or abs(consumeCount) != price: code = 2 else: eventId = "BI_NFISH_BUY_ITEM_GAIN" for item in vipGiftRewards: if item["type"] == 1: # 宝箱 chestId = item["name"] from newfish.entity.chest import chest_system rewards = chest_system.getChestRewards(userId, chestId) code = chest_system.deliveryChestRewards( userId, chestId, rewards, eventId) chestRewards.extend(rewards) elif item["type"] == 2: # 等级 from newfish.entity.gift.gift_system import _makeUserLevelUp _makeUserLevelUp(userId, item["count"]) code = 0 elif item["type"] == 3: # 资产/道具 rewards = [{"name": item["name"], "count": item["count"]}] code = util.addRewards(userId, rewards, eventId, int(level), param01=int(level)) commonRewards.extend(rewards) elif item["type"] == 5: # 皮肤炮皮肤 skinId = item["name"] ret = gun_system.addEquipGunSkinSkin( userId, skinId, clientId) if ret: code = 0 rewards = [{ "name": item["name"], "count": item["count"], "type": item["type"] }] commonRewards.extend(rewards) elif item["type"] == 6: # 直升炮台 upToLevel = item["count"] success = gun_system.upgradeGun(userId, False, MULTIPLE_MODE, byGift=True, upToLevel=upToLevel) if success: code = 0 vipGiftBought.append(level) gamedata.setGameAttr(userId, FISH_GAMEID, GameData.vipGiftBought, json.dumps(vipGiftBought)) if code == 0: mo.setResult("rewards", vipGiftRewards) mo.setResult("code", code) router.sendToUser(mo, userId)
def buyPiggyBank(userId, clientId, productId, buyType=None, itemId=0): """ 购买存钱罐 """ code = 3 rewards = [] product = config.getPiggyBankProduct(clientId, productId) if product is None: mo = MsgPack() mo.setCmd("piggyBankBuy") mo.setResult("gameId", config.FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("productId", productId) mo.setResult("code", code) router.sendToUser(mo, userId) ftlog.warn("piggy_bank, userId =", userId, "productId =", productId, "buyType =", buyType, "code =", code) return # if buyType: # if buyType not in product.get("otherBuyType", {}): # return # else: # buyType = product.get("buyType") type = product.get("type") key = UserData.piggyBankData % (FISH_GAMEID, userId) piggyBankData = daobase.executeUserCmd(userId, "HGET", key, type) dailyMaxTimes = product.get("dailyTimes", 0) if piggyBankData: piggyBankData = json.loads(piggyBankData) else: piggyBankData = {} ts = int(time.time()) / 60 * 60 if piggyBankData.get(GameData.pb_enable, 0) == 0 and weakdata.getDayFishData( userId, "pb_buyTimes", 0) < dailyMaxTimes: isSucc = False if buyType in product.get("otherBuyType", {}): price = product["otherBuyType"].get(buyType, 0) if buyType == config.BT_VOUCHER and price > 0: _consume = [{ "name": config.VOUCHER_KINDID, "count": abs(price) }] _ret = util.consumeItems( userId, _consume, "BI_NFISH_BUY_ITEM_CONSUME", pokerconf.productIdToNumber(productId), param01=productId) vip_system.addUserVipExp( config.FISH_GAMEID, userId, abs(price) * 10, "BUY_PRODUCT", pokerconf.productIdToNumber(productId), productId, rmbs=abs(price)) if _ret: isSucc = True else: code = 2 else: isSucc = True elif buyType == config.BT_DIRECT or config.isThirdBuyType(buyType): isSucc = True elif buyType == config.BT_DIAMOND: price = product.get("price_diamond", 0) price, _ret = store.getUseRebateItemPrice(userId, itemId, price, buyType, productId, clientId) # 满减券之后的钻石 满减券 if price > 0: consumeCount = 0 if _ret: store.autoConvertVoucherToDiamond(userId, price) # 代购券 consumeCount, final = userchip.incrDiamond( userId, FISH_GAMEID, -abs(price), 0, "BI_NFISH_BUY_ITEM_CONSUME", int(config.DIAMOND_KINDID), util.getClientId(userId), param01=productId) if not _ret or abs(consumeCount) != price: code = 2 else: isSucc = True if isSucc: piggyBankData[GameData.pb_enable] = 1 # piggyBankData[GameData.pb_saveMoneyTS] = ts piggyBankData[GameData.pb_getMoneyTS] = 0 # piggyBankData[GameData.pb_moneyCount] = conf.get("initVal", 0) pb_buyTimes = weakdata.incrDayFishData(userId, "pb_buyTimes", 1) # piggyBankData[GameData.pb_buyTimes] = piggyBankData.get(GameData.pb_buyTimes, 0) + 1 daobase.executeUserCmd(userId, "HSET", key, type, json.dumps(piggyBankData)) code, rewards = getMoney(userId, clientId, productId) mo = MsgPack() mo.setCmd("piggyBankBuy") mo.setResult("gameId", config.FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("productId", productId) mo.setResult("code", code) if code == 0: util.addProductBuyEvent(userId, productId, clientId) mo.setResult("reward", rewards) router.sendToUser(mo, userId) vipLevel = hallvip.userVipSystem.getVipInfo(userId).get("level", 0) ftlog.debug("piggy_bank, userId =", userId, "vip =", vipLevel, "type =", type, "code =", code, "piggyBankData =", piggyBankData, util.timestampToStr(ts), product) getPiggyBankInfo(userId, clientId)
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 doBuyFishGift(userId, clientId, giftId, buyType=None, itemId=0): """ 购买礼包 """ if ftlog.is_debug(): ftlog.debug("doBuyFishGift===>", userId, clientId, giftId, buyType, itemId) giftConf = getGiftConf(clientId, giftId) if not giftConf: return buyType = buyType or giftConf.get("buyType") # 使用钻石购买 if buyType == config.BT_DIAMOND: price = giftConf.get("discountPrice", 0) price, isSucc = store.getUseRebateItemPrice(userId, itemId, price, buyType, giftId, clientId) # 满减券之后的钻石 满减券 if price > 0: consumeCount = 0 if isSucc: store.autoConvertVoucherToDiamond(userId, price) # 代购券 consumeCount, final = userchip.incrDiamond( userId, FISH_GAMEID, -abs(price), 0, "BI_NFISH_BUY_ITEM_CONSUME", int(giftId), util.getClientId(userId), param01=giftId) if not isSucc or abs(consumeCount) != price: _sendBuyFishGiftRet(userId, clientId, giftId, 1) # 钻石购买结果 return # 使礼包变为可领取状态 code, extraRwards = 1, None if giftConf["giftType"] == GiftType.BANKRUPT: # 破产礼包 code = BankruptGift(userId, clientId).addGiftData(int(giftId)) if code == 0: # 购买成功后更新破产礼包购买次数并存储礼包等级. bankruptGiftInfo = gamedata.getGameAttrJson( userId, FISH_GAMEID, GameData.bankruptGiftInfo, []) if bankruptGiftInfo: fishPool, grade = bankruptGiftInfo[:2] buyBankruptGift = weakdata.getDayFishData( userId, WeakData.buyBankruptGiftTimesPerPool, {}) buyBankruptGift.setdefault(str(fishPool), {}).setdefault("count", 0) buyBankruptGift[str(fishPool)]["count"] += 1 # 购买次数 buyBankruptGift[str(fishPool)]["grade"] = grade # 购买等级 weakdata.setDayFishData(userId, WeakData.buyBankruptGiftTimesPerPool, json.dumps(buyBankruptGift)) gamedata.delGameAttr(userId, FISH_GAMEID, GameData.bankruptGiftInfo) elif giftConf["giftType"] == GiftType.MONTHCARD: # 月卡|永久月卡礼包 code, extraRwards = MonthCardGift(userId, clientId).addGiftData(int(giftId)) _sendBuyFishGiftRet(userId, clientId, giftId, code, extraRwards) # 购买礼包事件 if code != 0: return from newfish.game import TGFish from newfish.entity.event import GiftBuyEvent event = GiftBuyEvent(userId, FISH_GAMEID, giftConf["productId"], buyType, giftId) TGFish.getEventBus().publishEvent(event) util.addProductBuyEvent(userId, giftConf["productId"], clientId)
def setRewards(self, level, bet, betType=None): """ 确定转盘奖励结果 :param level: 段位1、2、3、4、5 :param bet: 倍率1、2、3、4 :param betType: 'paid' 重新抽奖 'give_up': 放弃 'bet' 直接领取 """ rewards = [] level = str(self.getEnergyIdx()[1]) # 可领奖的等级 fpMultiple = 1 pwData = self._getData(level, fpMultiple) prizeConf = self.getPrizeConf(level, fpMultiple) weightList = [] if self._enable(level, fpMultiple): for idx, item in enumerate(prizeConf.get("wheel", [])): enable = 1 if idx not in pwData[PWValueSlot.TAKEN] else 0 weightList.append(item["rate"] if enable else 0) # 奖励概率 code = 1 if pwData[PWValueSlot.STATE] in [ PWState.NOT_TAKE_REWARD, PWState.FAIL_SPIN ] and len(pwData[PWValueSlot.RET]) > 0: consumeDiamond, _rewards = self.getConsumeDiamond(pwData) if pwData[ PWValueSlot. STATE] == PWState.FAIL_SPIN and betType == "paid": # 重新抽奖 diamondCount = userchip.getDiamond(self.userId) if diamondCount >= consumeDiamond: code = 0 clientId = util.getClientId(self.userId) userchip.incrDiamond(self.userId, config.FISH_GAMEID, -consumeDiamond, self.roomId, "BI_NFISH_BUY_ITEM_CONSUME", config.DIAMOND_KINDID, clientId, param01="level_prize_wheel") datachangenotify.sendDataChangeNotify( FISH_GAMEID, self.userId, ["chip"]) ratioList = self._buildRetData(level, fpMultiple, _rewards) pwData[PWValueSlot.RET] = ratioList pwData[PWValueSlot.STATE] = PWState.NOT_TAKE_REWARD self._setData(level, fpMultiple) self.getInfo(fpMultiple) elif pwData[ PWValueSlot. STATE] == PWState.FAIL_SPIN and betType == "give_up": # 放弃 code = 0 self._resetPrizeWheelState(level, fpMultiple) if ftlog.is_debug(): ftlog.debug("lpw_give_up, giveup, userId =", self.userId, "level =", level, pwData[PWValueSlot.STATE]) elif pwData[ PWValueSlot. STATE] == PWState.NOT_TAKE_REWARD and betType == "bet": # 抽奖 for item in pwData[PWValueSlot.RET]: if item["ratio"] != bet: continue try: rewards = [item["rewards"][item["ret"]]] if rewards[0].get("name") == 0 and rewards[0].get( "count") == 0: # 转盘转到谢谢参与的奖励 code = 0 self._resetPrizeWheelState(level, fpMultiple) else: if rewards and rewards[0].get("count", 0) > 0: # 抽奖成功,获得奖励 code = util.addRewards( self.userId, rewards, "BI_NFISH_LEVEL_PRIZE_WHEEL_REWARDS", int(level), self.roomId, fpMultiple) self._resetPrizeWheelState(level, fpMultiple) else: # 抽奖失败,谢谢参与 code = 0 pwData[PWValueSlot.STATE] = PWState.FAIL_SPIN pwData[PWValueSlot.BET] = bet self._setData(level, fpMultiple) self.getInfo(fpMultiple) except: ftlog.error("lpw_bet_m, userId =", self.userId, "level =", level, "bet =", bet, code, "data =", pwData[PWValueSlot.RET]) break self._setData(level, fpMultiple) mo = MsgPack() mo.setCmd("prize_wheel_bet_m") mo.setResult("betType", betType) mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", self.userId) mo.setResult("code", code) mo.setResult("bet", bet) mo.setResult("rewards", rewards) GameMsg.sendMsg(mo, self.userId) lv = self.getEnergyIdx()[0] # 重新计算当前转盘的段位 self.sendEnergyProgress(lv, fpMultiple, self.roomId, 0)
def do_xq_creat_new_user(snsId, chessExp, totalNum, winNum, loseNum, drawNum): uid = daobase.executeMixCmd('incrby', 'global.userid', 1) #assert(uid > 148670897) ct = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') datas = { 'password' : 'ty' + str(random.randint(100000, 999999)), 'mdevid' : '', 'isbind' : 1, 'snsId' : snsId, 'name' : '', 'source' : '', 'purl' : 'http://ddz.image.tuyoo.com/avatar/head_china.png', 'address' : '', 'sex' : 0, 'state' : 0, 'payCount' : 0, 'snsinfo' : '', 'vip' : 0, 'dayang' : 0, 'idcardno' : '', 'phonenumber' : '', 'truename' : '', 'detect_phonenumber' : '', 'email' : '', 'createTime' : ct, 'userAccount' : '', 'clientId' : PCCLIENTID, 'appId' : 9999, 'bindMobile' : '', 'mac' : '', 'idfa' : '', 'imei' : '', 'androidId' : '', 'uuid' : '', 'userId' : uid, "lang" : '', "country" : "", "signature" : "", "agreeAddFriend" : 1, # "aliveTime" : ct, # "exp" : 0, # "charm" : 0, # "diamond" : 0, # "chip" : 3000, # "coin" : 0 } # attrlist = [] # valuelist = [] # for k, v in datas.items() : # attrlist.append(k) # valuelist.append(v) ftlog.info('PCXQ_USER', 'creat new user of->', uid, snsId) # userdata._setAttrsForce(uid, datas) userdata.setAttrs(uid, datas) userchip.incrChip(uid, 3, 3000, daoconst.CHIP_NOT_ENOUGH_OP_MODE_CLEAR_ZERO, 'SYSTEM_REPAIR', 0, PCCLIENTID) userchip.incrCoin(uid, 3, 0, daoconst.CHIP_NOT_ENOUGH_OP_MODE_CLEAR_ZERO, 'SYSTEM_REPAIR', 0, PCCLIENTID) userchip.incrDiamond(uid, 3, 0, daoconst.CHIP_NOT_ENOUGH_OP_MODE_CLEAR_ZERO, 'SYSTEM_REPAIR', 0, PCCLIENTID) userchip.incrCoupon(uid, 3, 0, daoconst.CHIP_NOT_ENOUGH_OP_MODE_CLEAR_ZERO, 'SYSTEM_REPAIR', 0, PCCLIENTID) userdata.incrCharm(uid, 0) userdata.incrExp(uid, 0) ikey = 'item2:9999:' + str(uid) for k, v in itemdatas.items() : daobase.executeUserCmd(uid, 'hset', ikey, k, v) daobase._executeKeyMapCmd('set', 'snsidmap:' + str(snsId), uid) creat_gamedata(uid, chessExp, totalNum, winNum, loseNum, drawNum)
def doGoldLottery(userId, gameId, clientId, number): ''' 金盘抽奖 ''' if number <= 0 or number > 50: ftlog.error( 'doGoldLottery number best be > 0 or <= 50, the msg is fake') return if ftlog.is_debug(): ftlog.debug('hallroulette.doGoldLottery userId:', userId, ' gameId:', gameId, ' clientId:', clientId, ' number:', number) # 添加关于部分情况下每日抽奖次数限制的功能 addLottoryNum = 0 # 0:初始值 1:增加数量1或者隔天后重新开始,初值设置为1 #add50LottoryOrReset = 0 # 0:初始值 1:增加数量1或者隔天后重新开始,初值设置为1 now_time = pktimestamp.getCurrentTimestamp() isSuitableClient = isSuitableClientID(userId, gameId, clientId) if isSuitableClient: tempResult = getWeightConfTemplate(userId, gameId, clientId) lastDoLottoryTime = pkgamedata.getGameAttrInt(userId, HALL_GAMEID, 'LastDoLottoryTime') if not pktimestamp.is_same_day(now_time, lastDoLottoryTime): resetDailyRouletteData(userId, now_time) if 10 == number: dailyDo10LottoryNum = pkgamedata.getGameAttrInt( userId, HALL_GAMEID, 'Do10LottoryNum') do10LottoryMaxTimes = tempResult.get('roulette_10_max_daily_num', 1000) if dailyDo10LottoryNum >= do10LottoryMaxTimes: ftlog.debug( 'hallroulette.doGoldLottery dailyDo10LottoryNum >= do10LottoryMaxTimes, beyond max limit', 'dailyDo10LottoryNum', dailyDo10LottoryNum, 'do10LottoryMaxTimes', do10LottoryMaxTimes) return reach10MaxTimes() else: addLottoryNum = 1 if 50 == number: dailyDo50LottoryNum = pkgamedata.getGameAttrInt( userId, HALL_GAMEID, 'Do50LottoryNum') do50LottoryMaxTimes = tempResult.get('roulette_50_max_daily_num', 1000) if dailyDo50LottoryNum >= do50LottoryMaxTimes: ftlog.debug( 'hallroulette.doGoldLottery dailyDo50LottoryNum >= do50LottoryMaxTimes, beyond max limit', 'dailyDo50LottoryNum', dailyDo50LottoryNum, 'do50LottoryMaxTimes', do50LottoryMaxTimes) return reach50MaxTimes() else: addLottoryNum = 1 # 减少钻石 result = {} count = -(number * 20) trueDelta, _finalCount = userchip.incrDiamond( userId, gameId, count, daoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, 'HALL_ROULETTE', 0, 0) if not trueDelta: # 消费失败 return toShop() #在扣除砖石后做每日抽奖次数限制的功能的数值设定0 if isSuitableClient: tempResult = getWeightConfTemplate(userId, gameId, clientId) if 1 == addLottoryNum: if 10 == number: pkgamedata.incrGameAttr(userId, HALL_GAMEID, 'Do10LottoryNum', 1) pkgamedata.setGameAttr(userId, HALL_GAMEID, 'LastDoLottoryTime', now_time) if 50 == number: pkgamedata.incrGameAttr(userId, HALL_GAMEID, 'Do50LottoryNum', 1) pkgamedata.setGameAttr(userId, HALL_GAMEID, 'LastDoLottoryTime', now_time) result['10lottoryNum'] = pkgamedata.getGameAttrInt( userId, HALL_GAMEID, 'Do10LottoryNum') result['50lottoryNum'] = pkgamedata.getGameAttrInt( userId, HALL_GAMEID, 'Do50LottoryNum') result['10MaxNum'] = tempResult.get('roulette_10_max_daily_num', 1000) result['50MaxNum'] = tempResult.get('roulette_50_max_daily_num', 1000) ftlog.debug('after change diamond, roulette limit data, 10lottoryNum', result['10lottoryNum'], '50lottoryNum', result['50lottoryNum'], '10MaxNum', result['10MaxNum'], '50MaxNum', result['50MaxNum']) #将抽奖数进行存储,满足bigRewardNumber,使用大奖概率,否则使用小奖概率 addBigRewardToPool(userId, gameId, clientId, number) # 抽奖 items = [] for _num in range(0, number): items.append(doRouletteLottery(userId, gameId, clientId)) result['items'] = items #对抽奖进行修改,连抽的话进行统一的数据库操作 sendGiftsToUser(userId, gameId, clientId, items) #更新钻石 datachangenotify.sendDataChangeNotify(gameId, userId, ['udata']) #抽奖成功,进行小兵的下发 for _ in range(0, number): daobase.executeMixCmd('RPUSH', CURKEY, userId) #统计需求 ftlog.hinfo('doGoldLottery.userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'number=', number, 'rouletteType=', 2, 'rewardItem=', items) TGHall.getEventBus().publishEvent( TYEventRouletteDiamond(userId, gameId, number)) return result
def doBuyLevelFunds(userId, clientId, buyType, productId, rebateItemId=0): """ 购买成长基金 """ # 根据商品Id确定游戏模式. mode = config.CLASSIC_MODE for _m in [config.CLASSIC_MODE, config.MULTIPLE_MODE]: fundsConf = config.getLevelFundsConf(clientId, _m) for val in fundsConf.get("funds"): if val.get("productId") == productId: mode = _m break fundsConf = config.getLevelFundsConf(clientId, mode) funds = fundsConf.get("funds") productConf = None canBuyIdxs = fundsConf.get("canBuyIdx") for val in funds: if val.get("idx") in canBuyIdxs and val.get("productId") == productId: productConf = val break if not productConf: sendBuyLevelFundsRet(userId, clientId, productId, 0, 5, mode) return buyType = buyType or productConf.get("buyType") lf_funds = daobase.executeUserCmd(userId, "HGET", _getRdKey(userId, mode), GameData.lf_funds) or "[]" lf_funds = json.loads(lf_funds) lf_types = [val.get("type") for val in funds if val.get("idx") in lf_funds] if productConf.get("idx") in lf_funds or productConf.get("type") in lf_types: # 重复购买同一商品或是同一类型的商品. sendBuyLevelFundsRet(userId, clientId, productId, 0, 6, mode) return lang = util.getLanguage(userId, clientId) productName = config.getMultiLangTextConf(productConf["name"], lang=lang) if buyType == BT_DIRECT or config.isThirdBuyType(buyType): # 直充购买或者三方渠道支付 message = config.getMultiLangTextConf("ID_BUY_GIFT_RET_BY_DRIECT", lang=lang).format(productName, productName) GameMsg.sendPrivate(FISH_GAMEID, userId, 0, message) code = 0 else: # 使用代购券购买 if productConf.get("otherBuyType", {}).get(buyType): price = productConf.get("otherBuyType", {}).get(buyType) if buyType == BT_VOUCHER: _consume = [{"name": VOUCHER_KINDID, "count": abs(price)}] _ret = util.consumeItems(userId, _consume, "BI_NFISH_BUY_ITEM_CONSUME", param01=productId) if not _ret: code = 2 else: vip_system.addUserVipExp(FISH_GAMEID, userId, abs(price) * 10, "BUY_PRODUCT", pokerconf.productIdToNumber(productId), productId, rmbs=abs(price)) message = config.getMultiLangTextConf("ID_BUY_GIFT_RET_BY_VOUCHER", lang=lang).format(price, productName, productName) GameMsg.sendPrivate(FISH_GAMEID, userId, 0, message) code = 0 else: code = 3 # 使用钻石购买 elif buyType == config.BT_DIAMOND: # 钻石购买 price = productConf["price_diamond"] price, isSucc = store.getUseRebateItemPrice(userId, rebateItemId, price, buyType, productId, clientId) # 不能出现使用满减券后不需要花钱的情况!!! if price > 0 and isSucc: store.autoConvertVoucherToDiamond(userId, price) # 钻石足够优先使用钻石、在使用代购券 consumeCount, final = userchip.incrDiamond(userId, FISH_GAMEID, -abs(price), 0, "BI_NFISH_BUY_LEVEL_FUNDS_CONSUME", int(config.DIAMOND_KINDID), clientId, param01=productId) if abs(consumeCount) != price: code = 4 else: code = 0 else: code = 5 else: code = 6 if code == 0: util.addProductBuyEvent(userId, productId, clientId) lf_funds.append(productConf.get("idx")) daobase.executeUserCmd(userId, "HSET", _getRdKey(userId, mode), GameData.lf_funds, json.dumps(lf_funds)) sendBuyLevelFundsRet(userId, clientId, productId, productConf.get("idx"), code, mode)