def _recruit_tp_1_mode_1(self): # 金币单抽 config = ConfigStaffRecruit.get(1) def _remove_money(): cost = [(money_text_to_item_id('gold'), config.cost_value_1)] resource_classify = ResourceClassification.classify(cost) resource_classify.check_exist(self.server_id, self.char_id) resource_classify.remove(self.server_id, self.char_id, message="StaffRecruit.recruit:1,1") if not self.gold_free_times: # 没有免费次数了, 就不判断CD,直接扣钱 _remove_money() else: # 有免费次数,先判断是否在CD中, cd_seconds = self.get_cd_seconds(1) if cd_seconds: # 在CD中,扣钱 _remove_money() else: # 免费的 # 设置免费次数, 和时间戳 self.doc['recruit_at']['1'] = arrow.utcnow().timestamp MongoStaffRecruit.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'recruit_at.1': self.doc['recruit_at']['1'] }} ) ValueLogStaffRecruitGoldFreeTimes(self.server_id, self.char_id).record() return 1
def add_score(self, value): self.doc['score'] += value MongoStaffRecruit.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'score': self.doc['score'] }}) self.send_notify()
def add_score(self, value): self.doc['score'] += value MongoStaffRecruit.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'score': self.doc['score'] }} ) self.send_notify()
def remove_score(self, value): new_score = self.check_score(value) self.doc['score'] = new_score MongoStaffRecruit.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'score': new_score }}) self.send_notify()
def remove_score(self, value): new_score = self.check_score(value) self.doc['score'] = new_score MongoStaffRecruit.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'score': new_score }} ) self.send_notify()
def __init__(self, server_id, char_id): self.server_id = server_id self.char_id = char_id self.doc = MongoStaffRecruit.db(self.server_id).find_one({'_id': self.char_id}) if not self.doc: self.doc = MongoStaffRecruit.document() self.doc['_id'] = self.char_id self.doc['score'] = 0 self.doc['point'] = {'1': 0, '2': 0} self.doc['recruit_at'] = {'1': 0, '2': 0} MongoStaffRecruit.db(self.server_id).insert_one(self.doc)
def __init__(self, server_id, char_id): self.server_id = server_id self.char_id = char_id self.doc = MongoStaffRecruit.db(self.server_id).find_one( {'_id': self.char_id}) if not self.doc: self.doc = MongoStaffRecruit.document() self.doc['_id'] = self.char_id self.doc['score'] = 0 self.doc['point'] = {'1': 0, '2': 0} self.doc['recruit_at'] = {'1': 0, '2': 0} MongoStaffRecruit.db(self.server_id).insert_one(self.doc)
def _recruit_tp_2_mode_1(self): # 钻石单抽 config = ConfigStaffRecruit.get(2) cd_seconds = self.get_cd_seconds(2) if cd_seconds: cost = [(money_text_to_item_id('diamond'), config.cost_value_1)] resource_classify = ResourceClassification.classify(cost) resource_classify.check_exist(self.server_id, self.char_id) resource_classify.remove(self.server_id, self.char_id, message="StaffRecruit.recruit:2,1") else: self.doc['recruit_at']['2'] = arrow.utcnow().timestamp MongoStaffRecruit.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'recruit_at.2': self.doc['recruit_at']['2'] }} ) return 1, not bool(cd_seconds)
def _recruit_tp_2_mode_1(self): # 钻石单抽 config = ConfigStaffRecruit.get(2) cd_seconds = self.get_cd_seconds(2) if cd_seconds: cost = [(money_text_to_item_id('diamond'), config.cost_value_1)] resource_classify = ResourceClassification.classify(cost) resource_classify.check_exist(self.server_id, self.char_id) resource_classify.remove(self.server_id, self.char_id, message="StaffRecruit.recruit:2,1") else: self.doc['recruit_at']['2'] = arrow.utcnow().timestamp MongoStaffRecruit.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'recruit_at.2': self.doc['recruit_at']['2'] }}) return 1, not bool(cd_seconds)
def _recruit_tp_1_mode_1(self): # 金币单抽 config = ConfigStaffRecruit.get(1) def _remove_money(): cost = [(money_text_to_item_id('gold'), config.cost_value_1)] resource_classify = ResourceClassification.classify(cost) resource_classify.check_exist(self.server_id, self.char_id) resource_classify.remove(self.server_id, self.char_id, message="StaffRecruit.recruit:1,1") if not self.gold_free_times: # 没有免费次数了, 就不判断CD,直接扣钱 _remove_money() else: # 有免费次数,先判断是否在CD中, cd_seconds = self.get_cd_seconds(1) if cd_seconds: # 在CD中,扣钱 _remove_money() else: # 免费的 # 设置免费次数, 和时间戳 self.doc['recruit_at']['1'] = arrow.utcnow().timestamp MongoStaffRecruit.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'recruit_at.1': self.doc['recruit_at']['1'] }}) ValueLogStaffRecruitGoldFreeTimes(self.server_id, self.char_id).record() return 1
def recruit(self, tp, mode): if tp not in [RECRUIT_GOLD, RECRUIT_DIAMOND]: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) if mode not in [RECRUIT_MODE_1, RECRUIT_MODE_2]: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) # NOTE: 钻石免费单抽 的积分 要单独处理 diamond_single_free = False if tp == RECRUIT_GOLD: if mode == RECRUIT_MODE_1: recruit_times = self._recruit_tp_1_mode_1() else: recruit_times = self._recruit_tp_1_mode_2() ValueLogStaffRecruitGoldTimes(self.server_id, self.char_id).record(value=recruit_times) else: if mode == RECRUIT_MODE_1: recruit_times, diamond_single_free = self._recruit_tp_2_mode_1() else: recruit_times = self._recruit_tp_2_mode_2() ValueLogStaffRecruitDiamondTimes(self.server_id, self.char_id).record(value=recruit_times) if diamond_single_free: converted_tp = 3 else: converted_tp = tp config = ConfigStaffRecruit.get(converted_tp) # times 3 和 2 还是公用的 current_times = self.get_times(tp) + 1 # point 是分开计的 result = RecruitResult(self.get_point(converted_tp)) for i in range(current_times, current_times + recruit_times): res = config.recruit(result.point, i) result.add(res) self.doc['point'][str(converted_tp)] = result.point # 记录次数 ValueLogStaffRecruitTimes(self.server_id, self.char_id).record(sub_id=tp, value=recruit_times) # 处理积分 today_score = ValueLogStaffRecruitScore(self.server_id, self.char_id).count_of_today(sub_id=tp) can_add_score = config.reward_score_day_limit - today_score if can_add_score <= 0: # 今天获得的积分已经达到上限 result.add_score = 0 else: if result.add_score > can_add_score: # 要添加的,大于了 能添加的 result.add_score = can_add_score self.doc['score'] += result.add_score ValueLogStaffRecruitScore(self.server_id, self.char_id).record(sub_id=tp, value=result.add_score) MongoStaffRecruit.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'point.{0}'.format(converted_tp): result.point, 'score': self.doc['score'] }} ) rc = ResourceClassification.classify(result.items) rc.add(self.server_id, self.char_id, message="StaffRecruit.recruit:{0},{1}".format(tp, mode)) if tp == RECRUIT_GOLD: recruit_staff_gold_signal.send( sender=None, server_id=self.server_id, char_id=self.char_id, times=recruit_times, staffs=rc.staff ) else: recruit_staff_diamond_signal.send( sender=None, server_id=self.server_id, char_id=self.char_id, times=recruit_times, staffs=rc.staff ) self.send_notify() # NOTE: 结果不能堆叠 return result.items
def recruit(self, tp, mode): if tp not in [RECRUIT_GOLD, RECRUIT_DIAMOND]: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) if mode not in [RECRUIT_MODE_1, RECRUIT_MODE_2]: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) # NOTE: 钻石免费单抽 的积分 要单独处理 diamond_single_free = False if tp == RECRUIT_GOLD: if mode == RECRUIT_MODE_1: recruit_times = self._recruit_tp_1_mode_1() else: recruit_times = self._recruit_tp_1_mode_2() ValueLogStaffRecruitGoldTimes( self.server_id, self.char_id).record(value=recruit_times) else: if mode == RECRUIT_MODE_1: recruit_times, diamond_single_free = self._recruit_tp_2_mode_1( ) else: recruit_times = self._recruit_tp_2_mode_2() ValueLogStaffRecruitDiamondTimes( self.server_id, self.char_id).record(value=recruit_times) if diamond_single_free: converted_tp = 3 else: converted_tp = tp config = ConfigStaffRecruit.get(converted_tp) # times 3 和 2 还是公用的 current_times = self.get_times(tp) + 1 # point 是分开计的 result = RecruitResult(self.get_point(converted_tp)) for i in range(current_times, current_times + recruit_times): res = config.recruit(result.point, i) result.add(res) self.doc['point'][str(converted_tp)] = result.point # 记录次数 ValueLogStaffRecruitTimes(self.server_id, self.char_id).record(sub_id=tp, value=recruit_times) # 处理积分 today_score = ValueLogStaffRecruitScore( self.server_id, self.char_id).count_of_today(sub_id=tp) can_add_score = config.reward_score_day_limit - today_score if can_add_score <= 0: # 今天获得的积分已经达到上限 result.add_score = 0 else: if result.add_score > can_add_score: # 要添加的,大于了 能添加的 result.add_score = can_add_score self.doc['score'] += result.add_score ValueLogStaffRecruitScore(self.server_id, self.char_id).record(sub_id=tp, value=result.add_score) MongoStaffRecruit.db(self.server_id).update_one( {'_id': self.char_id}, { '$set': { 'point.{0}'.format(converted_tp): result.point, 'score': self.doc['score'] } }) rc = ResourceClassification.classify(result.items) rc.add(self.server_id, self.char_id, message="StaffRecruit.recruit:{0},{1}".format(tp, mode)) if tp == RECRUIT_GOLD: recruit_staff_gold_signal.send(sender=None, server_id=self.server_id, char_id=self.char_id, times=recruit_times, staffs=rc.staff) else: recruit_staff_diamond_signal.send(sender=None, server_id=self.server_id, char_id=self.char_id, times=recruit_times, staffs=rc.staff) self.send_notify() # NOTE: 结果不能堆叠 return result.items
def teardown(self): self.update() MongoStaffRecruit.db(1).delete_one({'_id': self.char_id})