def decodeFromDict(self, d): self.conf = d self.level = d.get('level') if not isinstance(self.level, int): raise TYVipConfException(d, 'VipLevel.level must be int') self.name = d.get('name') if not isstring(self.name) or not self.name: raise TYVipConfException(d, 'VipLevel.name must be valid string') self.vipExp = d.get('exp') if not isinstance(self.vipExp, int): raise TYVipConfException(d, 'VipLevel.vipExt must be int') self.pic = d.get('pic', '') if not isstring(self.pic): raise TYVipConfException(d, 'VipLevel.pic must be string') self.desc = d.get('desc', []) if not isinstance(self.desc, list): raise TYVipConfException(d, 'VipLevel.desc must be list') if self.desc: for subDesc in self.desc: if not isstring(subDesc): raise TYVipConfException(d, 'VipLevel.desc.item must be string') rewardContent = d.get('rewardContent') if rewardContent: self.rewardContent = TYContentRegister.decodeFromDict(rewardContent) giftContent = d.get('giftContent') if giftContent: self.giftContent = TYContentRegister.decodeFromDict(giftContent) self.expDesc = d.get('expDesc', '') if not isstring(self.expDesc): raise TYVipConfException(d, 'VipLevel.expDesc must be string') self.nextVipLevelValue = d.get('nextLevel') if (self.nextVipLevelValue is not None and not isinstance(self.nextVipLevelValue, int)): raise TYVipConfException(d, 'VipLevel.nextVipLevelValue must be int') return self
def decodeFromDict(self, d): self.inspector = TYTaskInspectorRegister.decodeFromDict(d['inspector']) self.segment_id = d["segmentId"] reward_content = d.get('rewardContent') reward_multi_rate = d.get("multiReward", {}).get("rewardMultiRate", 0) if not isinstance(reward_multi_rate, (int, float)): raise TYBizConfException(d, 'task.rewardMultiRate must be number') self.totalLimit = d.get('total', 0) if not isinstance(self.totalLimit, int): raise TYBizConfException(d, 'task.totalLimit must be int') if reward_content: multi_reward_content = copy.deepcopy(reward_content) if reward_multi_rate > 0: for item in multi_reward_content.get("items", []): if "count" not in item: continue item["count"] += int(item["count"] * reward_multi_rate) self.reward_content = TYContentRegister.decodeFromDict( reward_content) self.multi_reward_content = TYContentRegister.decodeFromDict( multi_reward_content) self.reward_mail = d.get('rewardMail', '') if not isstring(self.reward_mail): raise TYBizConfException(d, 'task.rewardMail must be string') return self
def _decodeFromDictImpl(self, d): self.topRewardContent = self.bottomRewardContent = self.rewardContent topRewardContent = d.get('topRewardContent') if topRewardContent: self.topRewardContent = TYContentRegister.decodeFromDict(topRewardContent) bottomRewardContent = d.get('bottomRewardContent') if bottomRewardContent: self.bottomRewardContent = TYContentRegister.decodeFromDict(bottomRewardContent)
def _decodeFromDictImpl(self, d): self.topRewardContent = self.bottomRewardContent = self.rewardContent topRewardContent = d.get('topRewardContent') if topRewardContent: self.topRewardContent = TYContentRegister.decodeFromDict( topRewardContent) bottomRewardContent = d.get('bottomRewardContent') if bottomRewardContent: self.bottomRewardContent = TYContentRegister.decodeFromDict( bottomRewardContent)
def _initial(self): _exchanges = {} for info in self._clientConf['config']['exchange']: info2 = copy.copy(info) info2['content'] = TYContentRegister.decodeFromDict(info['content']) costs = [] for costdict in info2['costs']: costs.append(TYContentItem.decodeFromDict(costdict)) if not costs: raise TYBizConfException(info, 'costs is empty!!!') info2['costs'] = costs _exchanges[info2['id']] = info2 # 原始配置填充图片信息 content_items = info2['content'].getItems() assetKind = hallitem.itemSystem.findAssetKind(content_items[0].assetKindId) info['pic'] = assetKind.pic # 原始配置,还需要一个消耗物品的图片 for info in _exchanges.itervalues(): for cost in info['costs']: self.costAssetKindId = cost.assetKindId assetKind = hallitem.itemSystem.findAssetKind(cost.assetKindId) self._clientConf['config']['costAssetPic'] = assetKind.pic break self._exchanges = _exchanges
def _decodeFromDictImpl(self, d): self._prizes = [] self._limitCount = d.get('limitCount', -1) if not isinstance(self._limitCount, int) or self._limitCount < -1: raise TYBizConfException(d, 'limitCount must be int >= -1') self._mail = d.get('mail', '') if not isstring(self._mail): raise TYBizConfException(d, 'mail must be string') self._timeCycle = TimeCycleRegister.decodeFromDict( d.get('limitTimeCycle')) for prize in d.get('prizes', []): payOrder = prize.get('payOrder') if not payOrder or not isinstance(payOrder, dict): raise TYBizConfException(prize, 'prize.payOrder must dict') content = TYContentRegister.decodeFromDict(prize.get('content')) self._prizes.append((payOrder, content)) self._hallGameIds = d.get('hallGameIds', []) if not isinstance(self._hallGameIds, list): raise TYBizConfException(d, 'BuySendPrize.hallGameIds must be list') for hallGameId in self._hallGameIds: if not isinstance(hallGameId, int): raise TYBizConfException( d, 'BuySendPrize.hallGameIds must be int list') return self
def get_skill_level_reward(userId, old_level, new_level): rewards = dizhuconf.getSkillScoreReward().get(str(new_level), {}).get('rewards', None) if not rewards: return None ftlog.debug('get_skill_level_reward->', userId, old_level, new_level, rewards) sitems = TYContentRegister.decodeFromDict(rewards).getItems() ua = hallitem.itemSystem.loadUserAssets(userId) aslist = ua.sendContentItemList(DIZHU_GAMEID, sitems, 1, True, timestamp.getCurrentTimestamp(), 'TASK_MASTER_SCORE_UP_LEVEL_REWARD', 0) items = [] for x in aslist: kindId = hallconf.translateAssetKindIdToOld(x[0].kindId) akind = hallitem.itemSystem.findAssetKind(x[0].kindId) items.append({ 'id': kindId, 'count': x[1], 'name': akind.displayName, 'pic': akind.pic, }) datachangenotify.sendDataChangeNotify( HALL_GAMEID, userId, TYAssetUtils.getChangeDataNames(aslist)) return items
def sendReward(userId, rewardConf, mailstr, eventId, eventParam): """ 通用发货 param: rewardConf 奖励配置 格式: { 'typeId': 'FixedContent', 'items': [{'itemId': 'user:chip', 'count': 100}] } param: mailstr 邮件内容文本字符串,其中包含子串\\${rewardContent} eventId: 哪个事件触发的 eventParam: 事件参数 return: list<(TYAssetKind, consumeCount, final)> """ rewardContent = TYContentRegister.decodeFromDict(rewardConf) userAssets = hallitem.itemSystem.loadUserAssets(userId) assetList = userAssets.sendContent(DIZHU_GAMEID, rewardContent, 1, True, pktimestamp.getCurrentTimestamp(), eventId, eventParam) changeNames = TYAssetUtils.getChangeDataNames(assetList) contents = TYAssetUtils.buildContentsString(assetList) if mailstr: mailstr = strutil.replaceParams(mailstr, {'rewardContent': contents}) message.send(DIZHU_GAMEID, message.MESSAGE_TYPE_SYSTEM, userId, mailstr) changeNames.add('message') datachangenotify.sendDataChangeNotify(DIZHU_GAMEID, userId, changeNames) return assetList
def decodeFromDict(self, d): self.kindId = d.get('kindId') if not isinstance(self.kindId, int): raise TYBizConfException(d, 'YYBGiftKind.kindId must be int') self.rewardContent = TYContentRegister.decodeFromDict(d['reward']) self._decodeFromDict(d) return self
def decodeFromDict(self, d): self.conf = d self.kindId = d.get('kindId') if not isinstance(self.kindId, int): raise TYTaskConfException(d, 'task.kindId must be int') self.name = d.get('name') if not isstring(self.name): raise TYTaskConfException(d, 'task.name must be string') self.count = d.get('count') if not isinstance(self.count, int): raise TYTaskConfException(d, 'task.count must be int') self.totalLimit = d.get('totalLimit', 0) if not isinstance(self.totalLimit, int): raise TYTaskConfException(d, 'task.totalLimit must be int') self.desc = d.get('desc', '') if not isstring(self.desc): raise TYTaskConfException(d, 'task.desc must be string') self.pic = d.get('pic', '') if not isstring(self.pic): raise TYTaskConfException(d, 'task.pic must be string') self.inheritPrevTaskProgress = d.get('inheritPrevTaskProgress', 0) if self.inheritPrevTaskProgress not in (0, 1): raise TYTaskConfException( d, 'task.inheritPrevTaskProgress must be int in (0, 1)') self.star = d.get('star', 0) if not isinstance(self.star, int): raise TYTaskConfException(d, 'task.star must be int') self.shareUrl = d.get('shareUrl', 0) if self.shareUrl not in (0, 1): raise TYTaskConfException(d, 'task.shareUrl must be in (0,1)') rewardContent = d.get('rewardContent') if rewardContent: self.rewardContent = TYContentRegister.decodeFromDict( rewardContent) self.autoSendReward = d.get('autoSendReward', 0) if self.autoSendReward not in (0, 1): raise TYTaskConfException(d, 'task.n must be int int (0, 1)') self.rewardMail = d.get('rewardMail', '') if not isstring(self.rewardMail): raise TYTaskConfException(d, 'task.rewardMail must be string') if 'inspector' in d: inspector = TYTaskInspectorRegister.decodeFromDict( d.get('inspector')) self.inspectors.append(inspector) elif 'inspectors' in d: self.inspectors = TYTaskInspectorRegister.decodeList( d.get('inspectors')) self._decodeFromDictImpl(d) return self
def _reloadConf(self): conf = configure.getGameJson(self.gameId, 'skill.score', {}, configure.DEFAULT_CLIENT_ID) gameName = conf.get('game_name') if not isstring(gameName): raise TYBizConfException( conf, '%s.skill.score.game_name must be string: %s' % (self.gameId, gameName)) desc = conf.get('des', '') if not isstring(desc): raise TYBizConfException( conf, '%s.skill.score.des must be string: %s' % (self.gameId, desc)) titlePic = conf.get('title_pic', '') if not isstring(titlePic): raise TYBizConfException( conf, '%s.skill.score.title_pic must be string: %s' % (self.gameId, titlePic)) levels = [] levelMap = {} levelScores = conf.get('score', []) levelPics = conf.get('level_pic', []) levelBigPics = conf.get('big_level_pic', []) rewardMap = conf.get('reward', {}) if not levelScores: raise TYBizConfException( conf, '%s.skill.score.scores must be not empty list' % (self.gameId)) for i, score in enumerate(levelScores): level = i + 1 scoreRange = (score, -1) if level >= len(levelScores) else ( score, levelScores[level]) pic = levelPics[-1] if level >= len(levelPics) else levelPics[i] bigPic = levelBigPics[-1] if level >= len( levelBigPics) else levelBigPics[i] rewards = rewardMap.get(str(level), {}).get('rewards') rewardContent = None if rewards: rewardContent = TYContentRegister.decodeFromDict(rewards) skillScoreLevel = SkillScoreLevel(self, level, scoreRange, pic, bigPic, rewardContent) levelMap[level] = skillScoreLevel levels.append(skillScoreLevel) self.gameName = gameName self.desc = desc self.titlePic = titlePic self.levels = levels self.levelMap = levelMap self.levelScores = levelScores[:] ftlog.info('GameSkillScore._reloadConf', 'gameId=', self.gameId, 'gameName=', self.gameName, 'titlePic=', self.titlePic, 'levelKeys=', self.levelMap.keys()) return self
def decodeFromDict(self, d): from hall.entity.hallusercond import UserConditionRegister self.conditions = UserConditionRegister.decodeList( d.get('conditions', [])) rewardContent = d.get('rewardContent') if rewardContent: self.items = TYContentRegister.decodeFromDict(rewardContent) self.mail = d.get('mail', '') return self
def decodeFromDict(self, d): from hall.entity.hall_exmall import TimeCycleRegister from hall.entity.hall_exmall import TimeCyclePerDay self.shareId = d.get('shareId', '') if not isinstance(self.shareId, int): raise TYBizConfException(d, 'HallShare.shareId must be int') self.type = d.get('type', '') if not isstring(self.type): raise TYBizConfException(d, 'HallShare.type must be string') self.subType = d.get('subType', '') if not isstring(self.subType): raise TYBizConfException(d, 'HallShare.subType must be string') self.desc = HallShareConfigs().decodeFromDict(d.get('desc', [])) self.smsDesc = d.get('smsDesc', '') if not isstring(self.smsDesc): raise TYBizConfException(d, 'HallShare.smsDesc must be string') self.tips = d.get('tips', '') if not isstring(self.tips): raise TYBizConfException(d, 'HallShare.tips must be string') self.title = HallShareConfigs().decodeFromDict(d.get('title', [])) self.url = HallShareConfigs().decodeFromDict(d.get('url', [])) self.maxRewardCount = d.get('maxRewardCount') if not isinstance(self.maxRewardCount, int): raise TYBizConfException(d, 'HallShare.maxRewardCount must be int') self.rewardContent = None rewardContent = d.get('rewardContent') if rewardContent: self.rewardContent = TYContentRegister.decodeFromDict( rewardContent) self.mail = d.get('mail', '') if not isstring(self.mail): raise TYBizConfException(d, 'HallShare.mail must be string') self.shareIcon = HallShareConfigs().decodeFromDict( d.get('shareIcon', [])) rewardTimeCycleD = d.get('rewardTimeCycle') if rewardTimeCycleD: self.rewardTimeCycle = TimeCycleRegister.decodeFromDict( rewardTimeCycleD) else: self.rewardTimeCycle = TimeCyclePerDay() self._decodeFromDictImpl(d) return self
def decodeFromDict(self, d): self.conf = d self.kindId = d.get('kindId') if not isinstance(self.kindId, int): raise TYTaskConfException(d, 'task.kindId must be int') self.name = d.get('name') if not isstring(self.name): raise TYTaskConfException(d, 'task.name must be string') self.count = d.get('count') if not isinstance(self.count, int): raise TYTaskConfException(d, 'task.count must be int') self.totalLimit = d.get('totalLimit', 0) if not isinstance(self.totalLimit, int): raise TYTaskConfException(d, 'task.totalLimit must be int') self.desc = d.get('desc', '') if not isstring(self.desc): raise TYTaskConfException(d, 'task.desc must be string') self.pic = d.get('pic', '') if not isstring(self.pic): raise TYTaskConfException(d, 'task.pic must be string') self.inheritPrevTaskProgress = d.get('inheritPrevTaskProgress', 0) if self.inheritPrevTaskProgress not in (0, 1): raise TYTaskConfException(d, 'task.inheritPrevTaskProgress must be int in (0, 1)') self.star = d.get('star', 0) if not isinstance(self.star, int): raise TYTaskConfException(d, 'task.star must be int') self.shareUrl = d.get('shareUrl', 0) if self.shareUrl not in (0, 1): raise TYTaskConfException(d, 'task.shareUrl must be in (0,1)') rewardContent = d.get('rewardContent') if rewardContent: self.rewardContent = TYContentRegister.decodeFromDict(rewardContent) self.autoSendReward = d.get('autoSendReward', 0) if self.autoSendReward not in (0, 1): raise TYTaskConfException(d, 'task.n must be int int (0, 1)') self.rewardMail = d.get('rewardMail', '') if not isstring(self.rewardMail): raise TYTaskConfException(d, 'task.rewardMail must be string') if 'inspector' in d: inspector = TYTaskInspectorRegister.decodeFromDict(d.get('inspector')) self.inspectors.append(inspector) elif 'inspectors' in d: self.inspectors = TYTaskInspectorRegister.decodeList(d.get('inspectors')) self._decodeFromDictImpl(d) return self
def decodeFromDict(self, d): self.gameIds = d.get('gameIds', []) self.mail = d.get('mail', '') if not isstring(self.mail): raise TYBizConfException(d, 'GiftConf.mail must be str') self.giftContent = TYContentRegister.decodeFromDict(d.get('content')) self.maxCount = d.get('maxCount', -1) if not isinstance(self.maxCount, int) or self.maxCount < -1: raise TYBizConfException(d, 'GiftConf.maxCount must int >= -1') self.conf = d return self
def reloadConf(self, conf): dailyRewards = [] rewards = conf.get('rewards') if rewards: for reward in rewards: dailyRewards.append(TYContentRegister.decodeFromDict(reward)) mail = conf.get('mail', '') if not isstring(mail): raise TYBizConfException(conf, 'TYDailyCheckinImpl.mail must be string') self._mail = mail self._dailyRewards = dailyRewards ftlog.debug('TYDailyCheckin.reloadConf successed conf=', conf)
def _decodeFromDictImpl(self, d): rewardContent = d.get('rewardContent') if rewardContent: self.rewardContent = TYContentRegister.decodeFromDict( rewardContent) self.mail = d.get('mail', '') if not isstring(self.mail): raise TYBizConfException( d, 'FTTableFinishRecorder._decodeFromDictImpl mail must be string' ) return self
def decodeFromDict(self, d): self.conf = d self.level = d.get('level') if not isinstance(self.level, int): raise TYVipConfException(d, 'VipLevel.level must be int') self.name = d.get('name') if not isstring(self.name) or not self.name: raise TYVipConfException(d, 'VipLevel.name must be valid string') self.vipExp = d.get('exp') if not isinstance(self.vipExp, int): raise TYVipConfException(d, 'VipLevel.vipExt must be int') self.pic = d.get('pic', '') if not isstring(self.pic): raise TYVipConfException(d, 'VipLevel.pic must be string') self.desc = d.get('desc', []) if not isinstance(self.desc, list): raise TYVipConfException(d, 'VipLevel.desc must be list') if self.desc: for subDesc in self.desc: if not isstring(subDesc): raise TYVipConfException( d, 'VipLevel.desc.item must be string') rewardContent = d.get('rewardContent') if rewardContent: self.rewardContent = TYContentRegister.decodeFromDict( rewardContent) giftContent = d.get('giftContent') if giftContent: self.giftContent = TYContentRegister.decodeFromDict(giftContent) self.expDesc = d.get('expDesc', '') if not isstring(self.expDesc): raise TYVipConfException(d, 'VipLevel.expDesc must be string') self.nextVipLevelValue = d.get('nextLevel') if (self.nextVipLevelValue is not None and not isinstance(self.nextVipLevelValue, int)): raise TYVipConfException(d, 'VipLevel.nextVipLevelValue must be int') return self
def decodeFromDict(self, d): from hall.entity.hallusercond import UserConditionRegister self.conditions = UserConditionRegister.decodeList( d.get('conditions', [])) rewardContent = d.get('rewardContent') if rewardContent: self.items = TYContentRegister.decodeFromDict(rewardContent) self.mail = d.get('mail', '') from hall.entity.halluseraction import UserActionRegister self.actions = UserActionRegister.decodeList(d.get('actions', [])) from hall.entity.todotask import TodoTaskRegister self.todotasks = TodoTaskRegister.decodeList(d.get('todotasks', [])) return self
def decodeFromDict(self, d): startRank = d.get('start', -1) endRank = d.get('end', -1) if startRank <= 0 and startRank != -1: raise TYRankingConfException(d, 'rankReward.start must > 0 or == -1') if endRank <= 0 and endRank != -1: raise TYRankingConfException(d, 'rankReward.endRank must > 0 or == -1') if endRank != -1 and endRank < startRank: raise TYRankingConfException(d, 'rankReward.endRank must >= startRank') rewardContent = d.get('rewardContent') if rewardContent is not None: rewardContent = TYContentRegister.decodeFromDict(rewardContent) ret = TYRankingRankReward() ret.startRank = startRank ret.endRank = endRank ret.rewardContent = rewardContent return ret
def decodeFromDict(self, d): self.shareId = d.get('shareId', '') if not isinstance(self.shareId, int): raise TYBizConfException(d, 'HallShare.shareId must be int') self.type = d.get('type', '') if not isstring(self.type): raise TYBizConfException(d, 'HallShare.type must be string') self.subType = d.get('subType', '') if not isstring(self.subType): raise TYBizConfException(d, 'HallShare.subType must be string') self.desc = HallShareConfigs().decodeFromDict(d.get('desc', [])) self.smsDesc = d.get('smsDesc', '') if not isstring(self.smsDesc): raise TYBizConfException(d, 'HallShare.smsDesc must be string') self.tips = d.get('tips', '') if not isstring(self.tips): raise TYBizConfException(d, 'HallShare.tips must be string') self.title = HallShareConfigs().decodeFromDict(d.get('title', [])) self.url = HallShareConfigs().decodeFromDict(d.get('url', [])) self.maxRewardCount = d.get('maxRewardCount') if not isinstance(self.maxRewardCount, int): raise TYBizConfException(d, 'HallShare.maxRewardCount must be int') self.rewardContent = None rewardContent = d.get('rewardContent') if rewardContent: self.rewardContent = TYContentRegister.decodeFromDict(rewardContent) self.mail = d.get('mail', '') if not isstring(self.mail): raise TYBizConfException(d, 'HallShare.mail must be string') self.shareIcon = HallShareConfigs().decodeFromDict(d.get('shareIcon', [])) self._decodeFromDictImpl(d) return self
def decodeFromDict(self, d): self.kindId = d.get('kindId') if not isinstance(self.kindId, int): raise TYBizConfException(d, 'RPTaskKind.kindId must be int') self.name = d.get('name') if not isstring(self.name): raise TYBizConfException(d, 'RPTaskKind.name must be string') self.count = d.get('count') if not isinstance(self.count, int): raise TYBizConfException(d, 'RPTaskKind.count must be int') self.desc = d.get('desc', '') if not isstring(self.desc): raise TYBizConfException(d, 'RPTaskKind.desc must be string') self.pic = d.get('pic', '') if not isstring(self.pic): raise TYBizConfException(d, 'RPTaskKind.pic must be string') inviterReward = d.get('inviterReward', 0) if not isinstance(inviterReward, int) or inviterReward < 0: raise TYBizConfException( d, 'RPTaskKind.inviterReward must be int >= 0') self.inviterReward = inviterReward rewardContent = d.get('rewardContent') if rewardContent: self.rewardContent = TYContentRegister.decodeFromDict( rewardContent) self.rewardMail = d.get('rewardMail', '') if not isstring(self.rewardMail): raise TYBizConfException( d, 'RPTaskKind.rewardMail must be string') self.inspector = TYTaskInspectorRegister.decodeFromDict( d.get('inspector')) todotask = d.get('todotask') if todotask: self.todotaskFac = hallpopwnd.decodeTodotaskFactoryByDict(todotask) self._decodeFromDictImpl(d) return self
def _initial(self): _sources = [] for idx, sourcedict in enumerate(self._serverConf['creditSource']): sourceobj = CreditSourceRegister.decodeFromDict(sourcedict) if sourceobj: sourceobj.attach2act(self, idx) _sources.append(sourceobj) self._sources = _sources _exchanges = {} for info in self._clientConf['config']['exchange']: info2 = copy.copy(info) info2['content'] = TYContentRegister.decodeFromDict(info['content']) _exchanges[info2['id']] = info2 # 原始配置填充图片信息 content_items = info2['content'].getItems() assetKind = hallitem.itemSystem.findAssetKind(content_items[0].assetKindId) info['pic'] = assetKind.pic self._exchanges = _exchanges
def _reloadConf(): global _bindInviterReward global _remindTodotask global _oldRemindTodotask bindInviterReward = None inviteeBindWXRewardCount = 0 remindTodotask = None oldRemindTodotask = None conf = configure.getGameJson(HALL_GAMEID, 'invite', {}, 0) if conf: bindInviterRewardD = conf.get('bindInviterReward') if bindInviterRewardD: bindInviterReward = TYContentRegister.decodeFromDict( bindInviterRewardD) inviteeBindWXRewardCount = conf.get('inviteeBindWXRewardCount', 0) if not isinstance(inviteeBindWXRewardCount, int) or inviteeBindWXRewardCount < 0: raise TYBizConfException( conf, 'inviteeBindWXRewardCount must be int >= 0') remindTodotask = conf.get('remindTodotask') if remindTodotask: remindTodotask = TodoTaskRegister.decodeFromDict(remindTodotask) oldRemindTodotask = conf.get('oldRemindTodotask') if oldRemindTodotask: oldRemindTodotask = TodoTaskRegister.decodeFromDict( oldRemindTodotask) _bindInviterReward = bindInviterReward _remindTodotask = remindTodotask _oldRemindTodotask = oldRemindTodotask ftlog.info('hall_invite._reloadConf ok', 'bindInviterReward=', [item.toDict() for item in _bindInviterReward.getItems()] if _bindInviterReward else None, 'remindTodotask=', _remindTodotask.TYPE_ID if _remindTodotask else None, 'oldRemindTodotask=', _oldRemindTodotask.TYPE_ID if _oldRemindTodotask else None)
def fromDict(self, d): self.cardAssetKindId = d.get('cardAssetKindId') if not self.cardAssetKindId or not isstring(self.cardAssetKindId): raise TYBizConfException(d, 'cardAssetKindId must be not empty string') self.cardPrice = d.get('cardPrice') if not isinstance(self.cardPrice, int) or self.cardPrice <= 0: raise TYBizConfException(d, 'cardPrice must be int > 0') self.cardProductId = d.get('cardProduct') if not self.cardProductId or not isstring(self.cardProductId): raise TYBizConfException(d, 'cardProduct must be not empty string') for roundD in d.get('rounds'): roundConf = RoundConf().fromDict(roundD) if self.roundMap.get(roundConf.nRound): raise TYBizConfException(d, 'Duplicate nRound %s' % (roundConf.nRound)) self.roundMap[roundConf.nRound] = roundConf self.roundList.append(roundConf) for playModeD in d.get('playModes'): playModeConf = PlayModeConf().fromDict(playModeD) for mode in playModeConf.mode: playModeConfMin = PlayModeConfMin().fromDict(mode) if self.playModeMap.get(playModeConfMin.name): raise TYBizConfException(d, 'Duplicate playMode %s' % (playModeConfMin.name)) self.playModeMap[playModeConfMin.name] = playModeConfMin self.playModeList.append(playModeConf) self.inviteShareId = d.get('inviteShareId') if not isinstance(self.inviteShareId, int): raise TYBizConfException(d, 'FTCreatorConf.inviteShare must be int') self.goodCard = d.get('goodCard', 0) if self.goodCard not in (0, 1): raise TYBizConfException(d, 'FTCreatorConf.goodCard must in (0, 1)') bigWinnerRewardContent = d.get('bigWinnerRewardContent') if bigWinnerRewardContent: self.bigWinnerRewardContent = TYContentRegister.decodeFromDict(bigWinnerRewardContent) self.tableExpires = d.get('tableExpires', 86400) if not isinstance(self.tableExpires, int) or self.tableExpires <= 0: raise TYBizConfException(d, 'FTCreatorConf.tableExpires must be int') return self
def decodeFromDict(self, d): startRank = d.get('start', -1) endRank = d.get('end', -1) if startRank <= 0 and startRank != -1: raise TYRankingConfException(d, 'rankReward.start must > 0 or == -1') if endRank <= 0 and endRank != -1: raise TYRankingConfException( d, 'rankReward.endRank must > 0 or == -1') if endRank != -1 and endRank < startRank: raise TYRankingConfException( d, 'rankReward.endRank must >= startRank') rewardContent = d.get('rewardContent') if rewardContent is not None: rewardContent = TYContentRegister.decodeFromDict(rewardContent) ret = TYRankingRankReward() ret.startRank = startRank ret.endRank = endRank ret.rewardContent = rewardContent return ret
def _initial(self): _sources = [] for idx, sourcedict in enumerate(self._serverConf['creditSource']): sourceobj = CreditSourceRegister.decodeFromDict(sourcedict) if sourceobj: sourceobj.attach2act(self, idx) _sources.append(sourceobj) self._sources = _sources _exchanges = {} for info in self._clientConf['config']['exchange']: info2 = copy.copy(info) info2['content'] = TYContentRegister.decodeFromDict( info['content']) _exchanges[info2['id']] = info2 # 原始配置填充图片信息 content_items = info2['content'].getItems() assetKind = hallitem.itemSystem.findAssetKind( content_items[0].assetKindId) info['pic'] = assetKind.pic self._exchanges = _exchanges
def getTaskInfo(self, userId): ''' 新手任务信息,table_info协议调用 ''' if not isNewer(userId): return None kindId, completedList = self.getTaskStatus(userId) if len(completedList) >= self.taskKindCount \ or pktimestamp.getCurrentTimestamp() >= self.getDeadlineTimestamp(userId): return None curTask = self.getTaskByKindId(userId, kindId) if curTask is None: return None if ftlog.is_debug(): ftlog.debug('DizhuNewbieTaskSystem.getTaskInfo', 'userId=', userId, 'kindId=', kindId, 'curTask=', curTask, 'completelist=', completedList, caller=self) finalRewordConf = dizhuconf.getNewbieTaskConf().get('rewardContent', {}) finalRewordContent = TYContentRegister.decodeFromDict(finalRewordConf) tasksInfo = { 'details': self._encodeTaskList(userId, list(set(completedList + [curTask.kindId]))), 'final': self._encodeRewardContent(finalRewordContent), 'count': self.taskKindCount, 'deadline': max( self.getDeadlineTimestamp(userId) - pktimestamp.getCurrentTimestamp(), 0) } return tasksInfo
def userToGetGiftV401(userId, gameId, state, Reward): userAssets = hallitem.itemSystem.loadUserAssets(userId) # if state == 0: # changed = [] # assetKind, _addCount, _final = userAssets.addAsset(9999, 'user:chip', 500, int(time.time()), 'HALL_CHECKIN', 0) # if assetKind.keyForChangeNotify: # changed.append(assetKind.keyForChangeNotify) # datachangenotify.sendDataChangeNotify(gameId, userId, changed) # changed = [] # assetKind, _addCount, _final = userAssets.addAsset(9999, 'item:4167', 1, int(time.time()), 'HALL_CHECKIN', 0) # if assetKind.keyForChangeNotify: # changed.append(assetKind.keyForChangeNotify) changed = set() if Reward: items = TYContentRegister.decodeFromDict(Reward) assetList = userAssets.sendContent(gameId, items, 1, True, pktimestamp.getCurrentTimestamp(), 'HALL_CHECKIN', 0) # 通知更新 changed = TYAssetUtils.getChangeDataNames(assetList) # 更新退出提醒 changed.add('exit_remind') datachangenotify.sendDataChangeNotify(gameId, userId, changed)
def _reloadConf(): global _conf newConf = RPMainConf() conf = configure.getGameJson(HALL_GAMEID, 'red_packet_main', {}) startDT = conf.get('startTime') if startDT is not None: newConf.startDT = datetime.strptime(startDT, '%Y-%m-%d %H:%M:%S') stopDT = conf.get('stopTime') if stopDT is not None: newConf.stopDT = datetime.strptime(stopDT, '%Y-%m-%d %H:%M:%S') inviteTodotaskD = conf.get('inviteTodotask') if inviteTodotaskD is not None: newConf.inviteTodotaskFac = TodoTaskRegister.decodeFromDict(inviteTodotaskD) oldInviteTodotaskD = conf.get('oldInviteTodotask') if oldInviteTodotaskD: newConf.oldInviteTodotaskFac = TodoTaskRegister.decodeFromDict(oldInviteTodotaskD) newConf.rewards = [] for reward in conf.get('rewards', []): cond = None content = None condD = reward.get('condition') if condD: cond = UserConditionRegister.decodeFromDict(condD) content = TYContentRegister.decodeFromDict(reward.get('content')) newConf.rewards.append((cond, content)) _conf = newConf ftlog.info('hall_red_packet_main._reloadConf ok', 'startDT=', newConf.startDT, 'stopDT=', newConf.stopDT, 'inviteTodotaskFac=', newConf.inviteTodotaskFac, 'oldInviteTodotaskFac=', newConf.oldInviteTodotaskFac)
def fromDict(self, d): self.exchangeId = d.get('exchangeId') if not isinstance(self.exchangeId, int) and self.exchangeId <= 0: raise TYBizConfException( d, 'ExchangeItem.exchangeId must be int > 0') self.name = d.get('name') if not isstring(self.name): raise TYBizConfException(d, 'ExchangeItem.name must be string') self.desc = d.get('desc', '') if not isstring(self.desc): raise TYBizConfException(d, 'ExchangeItem.desc must be string') self.pic = d.get('pic') if not isstring(self.pic): raise TYBizConfException(d, 'ExchangeItem.pic must be string') self.cost = d.get('cost') if not isinstance(self.cost, int) and self.cost <= 0: raise TYBizConfException(d, 'ExchangeItem.cost must be int > 0') self.content = TYContentRegister.decodeFromDict(d.get('content')) return self
def decodeFromDict(self, d): content = d.get('content') self.content = TYContentRegister.decodeFromDict(content) self.cycle = RewardCycle().decodeFromDict(d.get('cycle')) return self
def _build_multi_fixedcontent(items_conf, multi): """构建FixedContent""" multi_items_conf = multi_items(items_conf, multi) return TYContentRegister.decodeFromDict(multi_items_conf)
def handleEvent(cls, event): conf = dizhuconf.getActivityConf('month_checkin_gift') monthDayCount = calendar.monthrange(event.checkinDate.year, event.checkinDate.month)[1] giftDayCount = conf.get('giftDayCount', -1) if giftDayCount <= 0: giftDayCount = monthDayCount giftDayCount = min(giftDayCount, monthDayCount) clientId = sessiondata.getClientId(event.userId) hallGameId = strutil.getGameIdFromHallClientId(clientId) if hallGameId != DIZHU_GAMEID: return if ftlog.is_debug(): ftlog.debug('MonthCheckinGift.handleEvent userId=', event.userId, 'gameId=', event.gameId, 'eventType=', type(event), 'checkinDate=', event.checkinDate, 'allCheckinCount=', event.status.allCheckinCount, 'giftDayCount=', giftDayCount, 'monthDayCount=', monthDayCount) giftContent = None try: if not Tool.checkNow(conf.get('datetime_start'), conf.get('datetime_end')): ftlog.debug('MonthCheckinGift.handleEvent outOfDate userId=', event.userId, 'gameId=', event.gameId, 'eventType=', type(event), 'checkinDate=', event.checkinDate, 'allCheckinCount=', event.status.allCheckinCount, 'giftDayCount=', giftDayCount, 'monthDayCount=', monthDayCount) return giftContent = TYContentRegister.decodeFromDict( conf.get('giftContent')) except: ftlog.error('MonthCheckinGift.handleEvent userId=', event.userId, 'gameId=', event.gameId, 'eventType=', type(event), 'checkinDate=', event.checkinDate, 'allCheckinCount=', event.status.allCheckinCount, 'giftDayCount=', giftDayCount, 'monthDayCount=', monthDayCount) return if event.status.allCheckinCount >= giftDayCount: assetList = None if giftContent: userAssets = hallitem.itemSystem.loadUserAssets(event.userId) assetList = userAssets.sendContent( DIZHU_GAMEID, giftContent, 1, True, pktimestamp.getCurrentTimestamp(), 'ACTIVITY_REWARD', cls.ACTIVITY_ID) changed = TYAssetUtils.getChangeDataNames(assetList) mail = conf.get('mail', '') if mail: gotContent = giftContent.desc if giftContent.desc else TYAssetUtils.buildContentsString( assetList) mail = strutil.replaceParams(mail, {'gotContent': gotContent}) message.sendPrivate(HALL_GAMEID, event.userId, 0, mail) changed.add('message') datachangenotify.sendDataChangeNotify(HALL_GAMEID, event.userId, changed) ftlog.info('MonthCheckinGift.statics sendGift userId=', event.userId, 'gameId=', event.gameId, 'eventType=', type(event), 'checkinDate=', event.checkinDate, 'allCheckinCount=', event.status.allCheckinCount, 'giftDayCount=', giftDayCount, 'monthDayCount=', monthDayCount, 'rewards=', [(a[0].kindId, a[1]) for a in assetList] if assetList else None)
def doTreasureBox(gameId, userId, bigRoomId): data = _getTbData(gameId, userId) bigRoomId = data['tbroomid'] if ftlog.is_debug(): ftlog.debug('treasurebox.doTreasureBox', 'gameId=', gameId, 'userId=', userId, 'bigRoomId=', bigRoomId) # 判定房间配置 tbconfiger = getTreasureBoxConf(gameId, bigRoomId) if not tbconfiger or not tbconfiger.get('reward', None): if ftlog.is_debug(): ftlog.debug('treasurebox.doTreasureBox', 'gameId=', gameId, 'userId=', userId, 'err=', 'NotTBoxRoom') return {'ok': 0, 'info': '本房间不支持宝箱,请进入高倍房再使用'} # 判定是否可以领取 tbplaytimes, tblasttime, datas = getUserTbInfo(gameId, userId, bigRoomId) tbplaycount = tbconfiger['playCount'] if tblasttime <= 0 or tbplaytimes < tbplaycount: if ftlog.is_debug(): ftlog.debug('treasurebox.doTreasureBox', 'gameId=', gameId, 'userId=', userId, 'err=', 'CanNotTBox') return { 'ok': 0, 'tbt': min(tbplaytimes, tbplaycount), 'tbc': tbplaycount, 'info': tbconfiger['desc'] } # 更新宝箱状态 datas['tblasttime'] = int(time.time()) datas['tbplaytimes'] = 0 _setTbData(gameId, userId, datas) rewards = tbconfiger['reward'] content = TYContentRegister.decodeFromDict(rewards) sitems = content.getItems() # 活动加成 ditems = _getDoubleInfos(gameId, bigRoomId) if ditems: for si in sitems: kindId = si.assetKindId mutil = ditems.get(kindId, 0) if mutil and mutil > 0: si.count = int(si.count * mutil) # 发送道具 ua = hallitem.itemSystem.loadUserAssets(userId) aslist = ua.sendContentItemList(gameId, sitems, 1, True, timestamp.getCurrentTimestamp(), 'TASK_OPEN_TBOX_REWARD', bigRoomId) addmsg = TYAssetUtils.buildContentsString(aslist) items = [] for x in aslist: kindId = hallconf.translateAssetKindIdToOld(x[0].kindId) items.append({'item': kindId, 'count': x[1], 'total': x[2]}) TYGame(gameId).getEventBus().publishEvent( UserTBoxLotteryEvent(gameId, userId)) data = { 'ok': 1, 'tbt': 0, 'tbc': tbplaycount, 'info': '开启宝箱,获得' + addmsg, 'items': items } if ftlog.is_debug(): ftlog.debug('treasurebox.doTreasureBox', 'gameId=', gameId, 'userId=', userId, 'data=', data) return data
def doTreasureBox(userId, bigRoomId): ftlog.debug('doTreasureBox userId=', userId, 'bigRoomId=', bigRoomId) # 判定房间配置 tbconfiger = dizhuconf.getTreasureBoxInfo(bigRoomId) if not tbconfiger or not tbconfiger.get('reward', None): ftlog.debug('doTreasureBox->userIds=', userId, 'bigRoomId=', bigRoomId, 'not tbox room !') return {'ok': 0, 'info': '本房间不支持宝箱,请进入高倍房再使用'} # 判定是否可以领取 tbplaytimes, tblasttime, datas = getUserTbInfo(userId, bigRoomId) tbplaycount = tbconfiger['playCount'] if tblasttime <= 0 or tbplaytimes < tbplaycount: ftlog.debug('doTreasureBox->userIds=', userId, 'bigRoomId=', bigRoomId, 'can not tbox !') return { 'ok': 0, 'tbt': min(tbplaytimes, tbplaycount), 'tbc': tbplaycount, 'info': tbconfiger['desc'] } # 更新宝箱状态 datas['tblasttime'] = int(time.time()) datas['tbplaytimes'] = 0 _setTbData(userId, datas) rewards = tbconfiger['reward'] content = TYContentRegister.decodeFromDict(rewards) sitems = content.getItems() # 活动加成 ditems = _getDoubleInfos(bigRoomId) if ditems: for si in sitems: kindId = si.assetKindId mutil = ditems.get(kindId, 0) if mutil and mutil > 0: si.count = int(si.count * mutil) # 发送道具 # ua = hallitem.itemSystem.loadUserAssets(userId) # aslist = ua.sendContentItemList(DIZHU_GAMEID, sitems, 1, True, # timestamp.getCurrentTimestamp(), 'TASK_OPEN_TBOX_REWARD', bigRoomId) aslist = dizhu_util.sendRewardItems(userId, sitems, '', 'TASK_OPEN_TBOX_REWARD', bigRoomId) addmsg = TYAssetUtils.buildContentsString(aslist) items = [] for x in aslist: kindId = hallconf.translateAssetKindIdToOld(x[0].kindId) items.append({'item': kindId, 'count': x[1], 'total': x[2]}) if kindId in ['user:coupon', 'COUPON']: # 广播事件 from hall.game import TGHall TGHall.getEventBus().publishEvent( UserCouponReceiveEvent( HALL_GAMEID, userId, x[1], user_coupon_details.USER_COUPON_TABLE_TBBOX)) from dizhu.game import TGDizhu TGDizhu.getEventBus().publishEvent( UserTBoxLotteryEvent(DIZHU_GAMEID, userId)) datas = { 'ok': 1, 'tbt': 0, 'tbc': tbplaycount, 'info': '开启宝箱,获得' + addmsg, 'items': items } ftlog.debug('doTreasureBox->userIds=', userId, 'bigRoomId=', bigRoomId, datas) return datas