def get_reward(self, vip): if vip > self.mc.vip: raise SanguoException( errormsg.VIP_LEVEL_NOT_ENOUGH, self.char_id, "VIP GET REWARD", "vip not enough. {0} < {1}".format(self.mc.vip, vip) ) vips = self.can_reward_vips() if vip not in vips: raise SanguoException( errormsg.VIP_HAS_GOT_REWARD, self.char_id, "VIP GET REWARD", "vip {0} has got reward".format(vip) ) # send reward prepare_drop = get_drop([VIP_REWARD[vip].package]) resource = Resource(self.char_id, "VIP GET REWARD", "vip {0}".format(vip)) standard_drop = resource.add(**prepare_drop) self.mc.vip_has_reward.append(vip) self.mc.save() self.send_notify() return standard_drop_to_attachment_protomsg(standard_drop)
def get_reward(self, vip): if vip > self.mc.vip: raise SanguoException( errormsg.VIP_LEVEL_NOT_ENOUGH, self.char_id, "VIP GET REWARD", "vip not enough. {0} < {1}".format(self.mc.vip, vip) ) vips = self.can_reward_vips() if vip not in vips: raise SanguoException( errormsg.VIP_HAS_GOT_REWARD, self.char_id, "VIP GET REWARD", "vip {0} has got reward".format(vip) ) # send reward prepare_drop = get_drop([VIP_REWARD[vip].package]) resource = Resource(self.char_id, "VIP GET REWARD", "vip {0}".format(vip)) standard_drop = resource.add(**prepare_drop) self.mc.vip_has_reward.append(vip) self.mc.save() self.send_notify() return standard_drop_to_attachment_protomsg(standard_drop)
def checkin(self): if self.c.has_checked: raise SanguoException( errormsg.CHECKIN_ALREADY_CHECKIN, self.char_id, "CheckIn checkin", "already checkin", ) self.c.has_checked = True day = self.c.day self.c.save() resource = Resource(self.char_id, "Daily Checkin", 'checkin reward. day {0}'.format(day)) resource_add = CHECKIN_DATA[str(day)]['package'] resource_add = get_drop_from_raw_package(resource_add) standard_drop = resource.add(**resource_add) msg = CheckInResponse() msg.ret = 0 msg.reward.MergeFrom( standard_drop_to_attachment_protomsg(standard_drop)) self.send_update_notify(day) return msg
def get_hang_reward(self, auto_start=True): """立即保存掉落,并且返回attachment消息""" # if not self.mongo_affairs.hang_city_id: # raise SanguoException( # errormsg.HANG_NOT_EXIST, # self.char_id, # "Get Hang Reward", # "hang not exist" # ) drops = self.get_drop() ac = ActivityEntry(self.char_id, 30004) if ac and ac.is_valid(): drops['gold'] *= 2 resource = Resource(self.char_id, "Hang Reward") standard_drop = resource.add(**drops) if auto_start: # 领取奖励后自动开始 self.start_hang(self.mongo_affairs.hang_city_id, get_reward=False) achievement = Achievement(self.char_id) achievement.trig(28, self.get_hang_obj().passed_time / 3600) achievement.trig(29, drops['exp']) return standard_drop_to_attachment_protomsg(standard_drop)
def checkin(self): if self.c.has_checked: raise SanguoException( errormsg.CHECKIN_ALREADY_CHECKIN, self.char_id, "CheckIn checkin", "already checkin", ) self.c.has_checked = True day = self.c.day self.c.save() resource = Resource(self.char_id, "Daily Checkin", 'checkin reward. day {0}'.format(day)) resource_add = self.checkin_data[str(day)]['package'] resource_add = get_drop_from_raw_package(resource_add) standard_drop = resource.add(**resource_add) msg = CheckInResponse() msg.ret = 0 msg.reward.MergeFrom(standard_drop_to_attachment_protomsg(standard_drop)) self.send_update_notify(day) return msg
def get_reward(self, char_id, condition_id): key = self.make_key(condition_id) try: doc = MongoActivityEnabledCondition.objects.get(id=key) except DoesNotExist: raise SanguoException( errormsg.ACTIVITY_CAN_NOT_GET_REWARD, char_id, "Activity Get Reward", "condition {0} can not get".format(condition_id) ) if doc.value == 1: raise SanguoException( errormsg.ACTIVITY_ALREADY_GOT_REWARD, char_id, "Activity Get Reward", "condition {0} already got".format(condition_id) ) doc.value = 1 doc.save() standard_drop = get_drop([ACTIVITY_STATIC_CONDITIONS[condition_id].package]) resource = Resource(char_id, "Activity Get Reward", "get condition id {0}".format(condition_id)) standard_drop = resource.add(**standard_drop) return standard_drop_to_attachment_protomsg(standard_drop)
def get_reward(self): counter = Counter(self.char_id, 'official_reward') if counter.remained_value <= 0: raise SanguoException( errormsg.OFFICAL_ALREADY_GET_REWARD, self.char_id, "OfficialDailyReward Get Reward", "already got" ) char = Char(self.char_id) official_level = char.mc.official if official_level == 0: raise SanguoException( errormsg.OFFICAL_ZERO_GET_REWARD, self.char_id, "OfficialDailyReward Get Reward", "char official level = 0" ) counter = Counter(self.char_id, 'official_reward') counter.incr() gold = OFFICIAL[official_level].gold resource = Resource(self.char_id, "Daily Official", 'official reward') standard_drop = resource.add(gold=gold) return standard_drop_to_attachment_protomsg(standard_drop)
def save_drop(self): stage_id = self.hang_doing.stage_id actual_seconds = self.hang_doing.actual_seconds times = actual_seconds / 15 stage = STAGES[stage_id] drop_exp = stage.normal_exp * times drop_gold = stage.normal_gold * times drop_gold = self._actual_gold(drop_gold) drop_ids = [int(i) for i in stage.normal_drop.split(',')] prepare_drop = get_drop(drop_ids, multi=times, gaussian=True) prepare_drop['exp'] += drop_exp prepare_drop['gold'] += drop_gold self.hang_doing.delete() self.hang_doing = None self.send_notify() prepare_drop = drop_after_stage_type(stage_id, prepare_drop) resource = Resource(self.char_id, "Hang Reward", "actual seconds = {0}, times = {1}".format(actual_seconds, times)) standard_drop = resource.add(**prepare_drop) achievement = Achievement(self.char_id) achievement.trig(29, drop_exp) return standard_drop_to_attachment_protomsg(standard_drop)
def checkin(self): # 签到 from core.union.union import Union from core.union.battle import UnionBattle if not self.mongo_union_member.joined: raise SanguoException( errormsg.INVALID_OPERATE, self.char_id, "Union Checkin", "not join union" ) if self.mongo_union_member.checkin_times + 1 > self.checkin_total_amount: raise SanguoException( errormsg.UNION_CHECKIN_REACH_MAX_TIMES, self.char_id, "Union Checkin", "reached max times" ) try: c = UNION_CHECKIN[self.mongo_union_member.checkin_times+1] except KeyError: raise SanguoException( errormsg.UNION_CHECKIN_REACH_MAX_TIMES, self.char_id, "Union Checkin", "reached max times. UNION_CHECKIN KeyError: {0}".format(self.mongo_union_member.checkin_times+1) ) if c.cost_type == 1: needs = {'gold': -c.cost_value} else: needs = {'sycee': -c.cost_value} resources = Resource(self.char_id, "Union Checkin") with resources.check(**needs): self.mongo_union_member.checkin_times += 1 self.mongo_union_member.last_checkin_timestamp = arrow.utcnow().timestamp self.add_coin(c.got_coin, send_notify=False) self.add_contribute_points(c.got_contributes, send_notify=False) self.mongo_union_member.save() self.send_personal_notify() Union(self.char_id).add_contribute_points(c.got_contributes) UnionBattle(self.char_id).send_notify() doc = MongoUnion._get_collection().find_one( {'_id': self.mongo_union_member.joined}, {'owner': 1} ) owner = doc['owner'] UnionBattle(owner).send_notify() drop = make_standard_drop_from_template() drop['union_coin'] = c.got_coin drop['union_contribute_points'] = c.got_contributes return standard_drop_to_attachment_protomsg(drop)
def save_drop(self): stage_id = self.hang_doing.stage_id actual_seconds = self.hang_doing.actual_seconds times = actual_seconds / 15 stage = STAGES[stage_id] drop_exp = stage.normal_exp * times drop_gold = stage.normal_gold * times drop_gold = self._actual_gold(drop_gold) drop_ids = [int(i) for i in stage.normal_drop.split(',')] prepare_drop = get_drop(drop_ids, multi=times, gaussian=True) prepare_drop['exp'] += drop_exp prepare_drop['gold'] += drop_gold self.hang_doing.delete() self.hang_doing = None self.send_notify() prepare_drop = drop_after_stage_type(stage_id, prepare_drop) resource = Resource( self.char_id, "Hang Reward", "actual seconds = {0}, times = {1}".format(actual_seconds, times)) standard_drop = resource.add(**prepare_drop) achievement = Achievement(self.char_id) achievement.trig(29, drop_exp) return standard_drop_to_attachment_protomsg(standard_drop)
def levy(request): l = Levy(request._char_id) drop = l.levy() msg = LevyResponse() msg.ret = 0 msg.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop)) return pack_msg(msg)
def levy(request): l = Levy(request._char_id) drop = l.levy() msg = LevyResponse() msg.ret = 0 msg.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop)) return pack_msg(msg)
def release(self, _id): p = self._abandon(_id, action="Prisoner Release") got_gold = p.gold got_treasure = random.choice(PRISONER_RELEASE_GOT_TREASURE[HEROS[p.oid].quality]) resource = Resource(self.char_id, "Prisoner Release") standard_drop = resource.add(gold=got_gold, stuffs=[(got_treasure, 1)]) return standard_drop_to_attachment_protomsg(standard_drop)
def get_hang_reward(self, auto_start=True): """立即保存掉落,并且返回attachment消息""" if not self.mongo_affairs.hang_city_id: raise SanguoException(errormsg.HANG_NOT_EXIST, self.char_id, "Get Hang Reward", "hang not exist") ho = self.get_hang_obj() battle_data = BATTLES[self.mongo_affairs.hang_city_id] percent = ho.passed_time / float(ho.max_time) * 100 for _pre, _add in HANG_REWARD_ADDITIONAL: if percent >= _pre: break else: _add = 1 char = Char(self.char_id) vip_level = char.mc.vip vip_add = VIP_FUNCTION[vip_level].hang_addition passed_time = int(ho.passed_time * _add * (1 + vip_add / 100.0)) reward_gold = passed_time / 15 * battle_data.normal_gold reward_gold = self.get_real_gold(reward_gold, self.mongo_affairs.logs) reward_exp = passed_time / 15 * battle_data.normal_exp if battle_data.normal_drop: # 模拟损失物品 drop_time = passed_time for log in self.mongo_affairs.logs: if log.tp == 1: drop_time -= PLUNDER_GET_DROPS_MINUTES * 60 drop_time_adjusted = max(int(passed_time * 0.25), drop_time) drops = get_drop( [int(i) for i in battle_data.normal_drop.split(',')], multi=drop_time_adjusted / 15) else: drops = make_standard_drop_from_template() drops['exp'] += reward_exp drops['gold'] += reward_gold resource = Resource(self.char_id, "Hang Reward") standard_drop = resource.add(**drops) if auto_start: # 领取奖励后自动开始 self.start_hang(self.mongo_affairs.hang_city_id, get_reward=False) achievement = Achievement(self.char_id) achievement.trig(28, ho.passed_time / 3600) achievement.trig(29, reward_exp) return standard_drop_to_attachment_protomsg(standard_drop)
def release(self, _id): p = self._abandon(_id, action="Prisoner Release") got_gold = p.gold got_treasure = random.choice( PRISONER_RELEASE_GOT_TREASURE[HEROS[p.oid].quality]) resource = Resource(self.char_id, "Prisoner Release") standard_drop = resource.add(gold=got_gold, stuffs=[(got_treasure, 1)]) return standard_drop_to_attachment_protomsg(standard_drop)
def get_attachment(request): mail_id = request._proto.id m = Mail(request._char_id) attachment = m.get_attachment(mail_id) response = GetAttachmentResponse() response.ret = 0 response.attachment.MergeFrom(standard_drop_to_attachment_protomsg(attachment)) return pack_msg(response)
def get_attachment(request): mail_id = request._proto.id m = Mail(request._char_id) attachment = m.get_attachment(mail_id) response = GetAttachmentResponse() response.ret = 0 response.attachment.MergeFrom( standard_drop_to_attachment_protomsg(attachment)) return pack_msg(response)
def arena_battle(request): char_id = request._char_id arena = Arena(char_id) msg, drop = arena.battle() response = ArenaResponse() response.ret = 0 response.battle.MergeFrom(msg) response.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop)) return pack_msg(response)
def arena_battle(request): char_id = request._char_id arena = Arena(char_id) msg, drop = arena.battle() response = ArenaResponse() response.ret = 0 response.battle.MergeFrom(msg) response.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop)) return pack_msg(response)
def plunder(request): char_id = request._char_id p = Plunder(char_id) msg, drop = p.plunder() response = PlunderResponse() response.ret = 0 response.battle.MergeFrom(msg) response.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop)) return pack_msg(response)
def plunder(request): char_id = request._char_id p = Plunder(char_id) msg, drop = p.plunder() response = PlunderResponse() response.ret = 0 response.battle.MergeFrom(msg) response.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop)) return pack_msg(response)
def get_reward(self, _id): try: this_task = TASKS[_id] except KeyError: raise SanguoException( errormsg.TASK_NOT_EXIST, self.char_id, "Task Get Reward", "Task {0} not exist".format(_id) ) if _id not in self.task.finished: raise SanguoException( errormsg.TASK_NOT_FINISH, self.char_id, "Task Get Reward", "Task {0} not finish".format(_id) ) if _id in self.task.complete: raise SanguoException( errormsg.TASK_ALREADY_GOT_REWARD, self.char_id, "Task Get Reward", "Task {0} already got reward".format(_id) ) sycee = this_task.sycee if this_task.sycee else 0 gold = this_task.gold if this_task.gold else 0 resource = Resource(self.char_id, "Task Reward", "task {0}".format(_id)) standard_drop = resource.add(gold=gold, sycee=sycee) if this_task.next_task: next_task = TASKS[this_task.next_task] if self.task.tasks[str(this_task.tp)] >= next_task.times: self.task.finished.append(this_task.next_task) index = self.task.doing.index(_id) self.task.doing.pop(index) self.task.doing.insert(index, this_task.next_task) self.task.finished.remove(_id) self.task.complete.append(_id) self.task.save() self.send_notify() if self.all_complete(): achievement = Achievement(self.char_id) achievement.trig(30, 1) return standard_drop_to_attachment_protomsg(standard_drop)
def kill(self, _id): p = self._abandon(_id, action="Prisoner Kill") soul_amount = random.randint(3, 10) souls = [(p.oid, soul_amount)] resource = Resource(self.char_id, "Prisoner Kill") standard_drop = resource.add(souls=souls) achievement = Achievement(self.char_id) achievement.trig(15, 1) return standard_drop_to_attachment_protomsg(standard_drop)
def get_reward(self, achievement_id): try: ach = ACHIEVEMENTS[achievement_id] except KeyError: raise SanguoException( errormsg.ACHIEVEMENT_NOT_EXIST, self.char_id, "Achievement Get Reward", "{0} not exist".format(achievement_id) ) if achievement_id not in self.achievement.display: raise SanguoException( errormsg.ACHIEVEMENT_NOT_FINISH, self.char_id, "Achievement Get Reward", "{0} not in display".format(achievement_id) ) if achievement_id not in self.achievement.finished: raise SanguoException( errormsg.ACHIEVEMENT_NOT_FINISH, self.char_id, "Achievement Get Reward", "{0} not finished".format(achievement_id) ) self.achievement.finished.remove(achievement_id) self.achievement.complete.append(achievement_id) updated_achs = [ach] if ach.next: index = self.achievement.display.index(achievement_id) self.achievement.display[index] = ach.next updated_achs.append(ACHIEVEMENTS[ach.next]) if ach.next in self.achievement.finished: attachment = Attachment(self.char_id) attachment.save_to_prize(4) self.achievement.save() for up_ach in updated_achs: msg = UpdateAchievementNotify() self._fill_up_achievement_msg(msg.achievement, up_ach) publish_to_char(self.char_id, pack_msg(msg)) standard_drop = self.send_reward(achievement_id, ach.sycee, ach.package) return standard_drop_to_attachment_protomsg(standard_drop)
def checkin(self): # 签到 from core.union.union import Union from core.union.battle import UnionBattle if not self.mongo_union_member.joined: raise SanguoException(errormsg.INVALID_OPERATE, self.char_id, "Union Checkin", "not join union") if self.mongo_union_member.checkin_times + 1 > self.checkin_total_amount: raise SanguoException(errormsg.UNION_CHECKIN_REACH_MAX_TIMES, self.char_id, "Union Checkin", "reached max times") try: c = UNION_CHECKIN[self.mongo_union_member.checkin_times + 1] except KeyError: raise SanguoException( errormsg.UNION_CHECKIN_REACH_MAX_TIMES, self.char_id, "Union Checkin", "reached max times. UNION_CHECKIN KeyError: {0}".format( self.mongo_union_member.checkin_times + 1)) if c.cost_type == 1: needs = {'gold': -c.cost_value} else: needs = {'sycee': -c.cost_value} resources = Resource(self.char_id, "Union Checkin") with resources.check(**needs): self.mongo_union_member.checkin_times += 1 self.mongo_union_member.last_checkin_timestamp = arrow.utcnow( ).timestamp self.add_coin(c.got_coin, send_notify=False) self.add_contribute_points(c.got_contributes, send_notify=False) self.mongo_union_member.save() self.send_personal_notify() Union(self.char_id).add_contribute_points(c.got_contributes) UnionBattle(self.char_id).send_notify() doc = MongoUnion._get_collection().find_one( {'_id': self.mongo_union_member.joined}, {'owner': 1}) owner = doc['owner'] UnionBattle(owner).send_notify() drop = make_standard_drop_from_template() drop['union_coin'] = c.got_coin drop['union_contribute_points'] = c.got_contributes return standard_drop_to_attachment_protomsg(drop)
def kill(self, _id): p = self._abandon(_id, action="Prisoner Kill") quality = HEROS[p.oid].quality souls = [(22, PRISONER_KILL_GOT_SOUL[quality])] treasures = [(random.choice(PRISONER_KILL_GOT_TREASURE[quality]), 1)] stuffs = [] stuffs.extend(souls) stuffs.extend(treasures) resource = Resource(self.char_id, "Prisoner Kill") standard_drop = resource.add(stuffs=stuffs) return standard_drop_to_attachment_protomsg(standard_drop)
def kill(self, _id): p = self._abandon(_id, action="Prisoner Kill") quality = HEROS[p.oid].quality souls = [(22, PRISONER_KILL_GOT_SOUL[quality])] treasures = [(random.choice(PRISONER_KILL_GOT_TREASURE[quality]), 1)] stuffs = [] stuffs.extend(souls) stuffs.extend(treasures) resource = Resource(self.char_id, "Prisoner Kill") standard_drop = resource.add(stuffs=stuffs) return standard_drop_to_attachment_protomsg(standard_drop)
def arena_battle(request): char_id = request._char_id arena = Arena(char_id) msg, adding_score = arena.battle() response = ArenaResponse() response.ret = 0 response.battle.MergeFrom(msg) drop = make_standard_drop_from_template() drop["stuffs"] = [(1001, adding_score)] response.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop)) return pack_msg(response)
def elite_pve(request): req = request._proto stage = EliteStage(request._char_id) battle_msg = stage.battle(req.stage_id) if battle_msg.self_win: drop = stage.save_drop() else: drop = {} response = protomsg.ElitePVEResponse() response.ret = 0 response.stage_id = req.stage_id response.battle.MergeFrom(battle_msg) if drop: response.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop)) return pack_msg(response)
def send_notify(self): msg = protomsg.MailNotify() for k, v in self.mail.mails.iteritems(): m = msg.mails.add() m.id = int(k) m.name = v.name m.content = v.content m.has_read = v.has_read if v.attachment: m.attachment.MergeFrom( standard_drop_to_attachment_protomsg(json.loads(v.attachment)) ) m.start_at = arrow.get(v.create_at, "YYYY-MM-DD HH:mm:ss").timestamp m.max_days = MAIL_KEEP_DAYS publish_to_char(self.char_id, pack_msg(msg))
def pve(request): req = request._proto stage = Stage(request._char_id) battle_msg = stage.battle(req.stage_id) if battle_msg.self_win: drop = stage.save_drop(req.stage_id, first=stage.first, star=stage.first_star) else: drop = {} response = protomsg.PVEResponse() response.ret = 0 response.stage_id = req.stage_id response.battle.MergeFrom(battle_msg) if drop: response.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop)) return pack_msg(response)
def get_reward(self, _id): try: this_task = TASKS[_id] except KeyError: raise SanguoException(errormsg.TASK_NOT_EXIST, self.char_id, "Task Get Reward", "Task {0} not exist".format(_id)) if _id not in self.task.finished: raise SanguoException(errormsg.TASK_NOT_FINISH, self.char_id, "Task Get Reward", "Task {0} not finish".format(_id)) if _id in self.task.complete: raise SanguoException(errormsg.TASK_ALREADY_GOT_REWARD, self.char_id, "Task Get Reward", "Task {0} already got reward".format(_id)) sycee = this_task.sycee if this_task.sycee else 0 gold = this_task.gold if this_task.gold else 0 resource = Resource(self.char_id, "Task Reward", "task {0}".format(_id)) standard_drop = resource.add(gold=gold, sycee=sycee) if this_task.next_task: next_task = TASKS[this_task.next_task] if self.task.tasks[str(this_task.tp)] >= next_task.times: self.task.finished.append(this_task.next_task) index = self.task.doing.index(_id) self.task.doing.pop(index) self.task.doing.insert(index, this_task.next_task) self.task.finished.remove(_id) self.task.complete.append(_id) self.task.save() self.send_notify() if self.all_complete(): achievement = Achievement(self.char_id) achievement.trig(30, 1) return standard_drop_to_attachment_protomsg(standard_drop)
def send_notify(self): msg = protomsg.MailNotify() for k, v in self.mail.mails.iteritems(): m = msg.mails.add() m.id = int(k) m.name = v.name m.content = v.content m.has_read = v.has_read if v.attachment: m.attachment.MergeFrom( standard_drop_to_attachment_protomsg( json.loads(v.attachment))) m.start_at = arrow.get(v.create_at, "YYYY-MM-DD HH:mm:ss").timestamp m.max_days = MAIL_KEEP_DAYS publish_to_char(self.char_id, pack_msg(msg))
def activity_pve(request): req = request._proto stage = ActivityStage(request._char_id) battle_msg = stage.battle(req.stage_id) if battle_msg.self_win: drop = stage.save_drop() else: drop = {} response = protomsg.ActivityStagePVEResponse() response.ret = 0 response.stage_id = req.stage_id response.battle.MergeFrom(battle_msg) if drop: response.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop)) return pack_msg(response)
def get_reward(self, achievement_id): try: ach = ACHIEVEMENTS[achievement_id] except KeyError: raise SanguoException(errormsg.ACHIEVEMENT_NOT_EXIST, self.char_id, "Achievement Get Reward", "{0} not exist".format(achievement_id)) if achievement_id not in self.achievement.display: raise SanguoException(errormsg.ACHIEVEMENT_NOT_FINISH, self.char_id, "Achievement Get Reward", "{0} not in display".format(achievement_id)) if achievement_id not in self.achievement.finished: raise SanguoException(errormsg.ACHIEVEMENT_NOT_FINISH, self.char_id, "Achievement Get Reward", "{0} not finished".format(achievement_id)) self.achievement.finished.remove(achievement_id) self.achievement.complete.append(achievement_id) updated_achs = [ach] if ach.next: index = self.achievement.display.index(achievement_id) self.achievement.display[index] = ach.next updated_achs.append(ACHIEVEMENTS[ach.next]) if ach.next in self.achievement.finished: attachment = Attachment(self.char_id) attachment.save_to_prize(4) self.achievement.save() for up_ach in updated_achs: msg = UpdateAchievementNotify() self._fill_up_achievement_msg(msg.achievement, up_ach) publish_to_char(self.char_id, pack_msg(msg)) standard_drop = self.send_reward(achievement_id, ach.sycee, ach.package) return standard_drop_to_attachment_protomsg(standard_drop)
def send_mail_notify(self): msg = protomsg.MailNotify() for k, v in self.mail.mails.iteritems(): m = msg.mails.add() m.id = int(k) m.name = v.name m.content = v.content m.has_read = v.has_read if v.attachment: m.attachment.MergeFrom( standard_drop_to_attachment_protomsg(json.loads(v.attachment), is_prepare=True) ) create_at = datetime.datetime.strptime(v.create_at, FORMAT) m.start_at = int(create_at.strftime('%s')) # m.start_at = v.create_at m.max_days = MAIL_KEEP_DAYS publish_to_char(self.char_id, pack_msg(msg))
def get_reward(self, char_id, condition_id): key = self.reward_key(condition_id) if not key: raise SanguoException( errormsg.ACTIVITY_CAN_NOT_GET_REWARD, self.char_id, "Activity Get Reward", "condition {0} can not get".format(condition_id) ) standard_drop = get_drop([ACTIVITY_STATIC_CONDITIONS[condition_id].package]) resource = Resource(self.char_id, "Activity Get Reward", "get condition id {0}".format(condition_id)) standard_drop = resource.add(**standard_drop) MongoKeyRecord._get_collection().update( {'_id': key}, {'$set': {'value': 1}} ) return standard_drop_to_attachment_protomsg(standard_drop)
def stuff_use(self, _id, amount): from core.attachment import get_drop, standard_drop_to_attachment_protomsg, is_empty_drop from core.resource import Resource try: s = STUFFS[_id] except KeyError: raise SanguoException( errormsg.STUFF_NOT_EXIST, self.char_id, "Stuff Use", "stuff {0} not exist".format(_id) ) # XXX if s.tp != 3: raise SanguoException( errormsg.STUFF_CAN_NOT_USE, self.char_id, "Stuff Use", "stuff {0} tp is {1}. Can not use".format(_id, s.tp) ) # XXX 忽略amount,只能一个一个用 self.stuff_remove(_id, amount) packages = s.packages if not packages: return None package_ids = [int(i) for i in packages.split(',')] prepare_drop = get_drop(package_ids) if is_empty_drop(prepare_drop) and s.default_package: package_ids = [s.default_package] prepare_drop = get_drop(package_ids) resource = Resource(self.char_id, "Stuff Use", "use {0}".format(_id)) standard_drop = resource.add(**prepare_drop) return standard_drop_to_attachment_protomsg(standard_drop)
def stuff_use(self, _id, amount): from core.attachment import standard_drop_to_attachment_protomsg, is_empty_drop, merge_drop from core.resource import Resource try: s = STUFFS[_id] except KeyError: raise SanguoException(errormsg.STUFF_NOT_EXIST, self.char_id, "Stuff Use", "stuff {0} not exist".format(_id)) # XXX if s.tp != 3: raise SanguoException( errormsg.STUFF_CAN_NOT_USE, self.char_id, "Stuff Use", "stuff {0} tp is {1}. Can not use".format(_id, s.tp)) # XXX 忽略amount,只能一个一个用 self.stuff_remove(_id, amount) # 活动 10001 additional_drop_1 = ActivityEntry(self.char_id, 10001).get_additional_drop(_id) additional_drop_2 = ActivityEntry(self.char_id, 12001).get_additional_drop(_id) additional_drop_3 = ActivityEntry(self.char_id, 15001).get_additional_drop(_id) prepare_drop = self.get_sutff_drop(_id) drop = merge_drop([ prepare_drop, additional_drop_1, additional_drop_2, additional_drop_3 ]) if is_empty_drop(drop): return None resource = Resource(self.char_id, "Stuff Use", "use {0}".format(_id)) standard_drop = resource.add(**drop) return standard_drop_to_attachment_protomsg(standard_drop)
def stuff_use(self, _id, amount): from core.attachment import standard_drop_to_attachment_protomsg, is_empty_drop, merge_drop from core.resource import Resource try: s = STUFFS[_id] except KeyError: raise SanguoException( errormsg.STUFF_NOT_EXIST, self.char_id, "Stuff Use", "stuff {0} not exist".format(_id) ) # XXX if s.tp != 3: raise SanguoException( errormsg.STUFF_CAN_NOT_USE, self.char_id, "Stuff Use", "stuff {0} tp is {1}. Can not use".format(_id, s.tp) ) # XXX 忽略amount,只能一个一个用 self.stuff_remove(_id, amount) # 活动 10001 additional_drop_1 = ActivityEntry(self.char_id, 10001).get_additional_drop(_id) additional_drop_2 = ActivityEntry(self.char_id, 12001).get_additional_drop(_id) additional_drop_3 = ActivityEntry(self.char_id, 15001).get_additional_drop(_id) prepare_drop = self.get_sutff_drop(_id) drop = merge_drop([prepare_drop, additional_drop_1, additional_drop_2, additional_drop_3]) if is_empty_drop(drop): return None resource = Resource(self.char_id, "Stuff Use", "use {0}".format(_id)) standard_drop = resource.add(**drop) return standard_drop_to_attachment_protomsg(standard_drop)
def after_battle(self, boss_id, damage, kill=False): # 每次打完给予奖励 member = Member(self.char_id) boss = UNION_BOSS[boss_id] contribute_points = int( float(damage)/boss.hp * boss.contribute_points ) lowest = 1 highest = int(boss.contribute_points * 0.05) if contribute_points < lowest: contribute_points = lowest if contribute_points > highest: contribute_points = highest coin = 9 + contribute_points member.add_coin(coin, send_notify=False) member.add_contribute_points(contribute_points, send_notify=True) if not kill: self.union.add_contribute_points(contribute_points) drop = make_standard_drop_from_template() drop['union_coin'] = coin drop['union_contribute_points'] = contribute_points return standard_drop_to_attachment_protomsg(drop)
def activity_pve(request): req = request._proto stage = ActivityStage(request._char_id) s = STAGE_ACTIVITY[req.stage_id] if s.tp == 1: battle_msg = stage.battle_type_one(req.stage_id) else: battle_msg = stage.battle_type_two(req.stage_id) if battle_msg.self_win: drop = stage.save_drop() else: drop = {} response = protomsg.ActivityStagePVEResponse() response.ret = 0 response.stage_id = req.stage_id response.battle.MergeFrom(battle_msg) if drop: response.drop.MergeFrom(standard_drop_to_attachment_protomsg(drop)) return pack_msg(response)
def after_battle(self, boss_id, damage, kill=False): # 每次打完给予奖励 member = Member(self.char_id) boss = UNION_BOSS[boss_id] contribute_points = int( float(damage) / boss.hp * boss.contribute_points) lowest = 1 highest = int(boss.contribute_points * 0.05) if contribute_points < lowest: contribute_points = lowest if contribute_points > highest: contribute_points = highest coin = 9 + contribute_points member.add_coin(coin, send_notify=False) member.add_contribute_points(contribute_points, send_notify=True) if not kill: self.union.add_contribute_points(contribute_points) drop = make_standard_drop_from_template() drop['union_coin'] = coin drop['union_contribute_points'] = contribute_points return standard_drop_to_attachment_protomsg(drop)
def get_hang_reward(self, auto_start=True): """立即保存掉落,并且返回attachment消息""" # if not self.mongo_affairs.hang_city_id: # raise SanguoException( # errormsg.HANG_NOT_EXIST, # self.char_id, # "Get Hang Reward", # "hang not exist" # ) drops = self.get_drop() resource = Resource(self.char_id, "Hang Reward") standard_drop = resource.add(**drops) if auto_start: # 领取奖励后自动开始 self.start_hang(self.mongo_affairs.hang_city_id, get_reward=False) achievement = Achievement(self.char_id) achievement.trig(28, self.get_hang_obj().passed_time / 3600) achievement.trig(29, drops['exp']) return standard_drop_to_attachment_protomsg(standard_drop)
def get_reward(self, tp): if not self.mongo_plunder.target_char: raise SanguoException(errormsg.PLUNDER_GET_REWARD_NO_TARGET, self.char_id, "Plunder Get Reward", "no Target char") if tp in self.mongo_plunder.got_reward: raise SanguoException(errormsg.PLUNDER_GET_REWARD_ALREADY_GOT, self.char_id, "Plunder Get Reward", "tp {0} already got".format(tp)) need_points = PLUNDER_REWARD_NEEDS_POINT[tp] if self.mongo_plunder.points < need_points: raise SanguoException( errormsg.PLUNDER_GET_REWARD_POINTS_NOT_ENOUGH, self.char_id, "Plunder Get Reward", "points not enough. {0} < {1}".format( self.mongo_plunder.points, need_points)) self.mongo_plunder.points -= need_points self.mongo_plunder.got_reward.append(tp) self.mongo_plunder.save() standard_drop = make_standard_drop_from_template() plunder_gold = self.mongo_plunder.chars[str( self.mongo_plunder.target_char)].gold char = Char(self.char_id).mc vip_plus = VIP_FUNCTION[char.vip].plunder_addition got_hero_id = 0 if tp == PLUNDER_HERO: f = Formation(self.mongo_plunder.target_char) heros = f.in_formation_hero_original_ids() got_hero_id = random.choice([hid for hid in heros if hid]) p = Prison(self.char_id) p.prisoner_add(got_hero_id, plunder_gold / 2) elif tp == PLUNDER_STUFF: stage = Stage(self.mongo_plunder.target_char) max_star_stage = stage.stage.max_star_stage if not max_star_stage: max_star_stage = 1 drop_ids = [ int(i) for i in STAGES[max_star_stage].normal_drop.split(',') ] drop = get_drop(drop_ids, multi=int(PLUNDER_GOT_ITEMS_HOUR * 3600 * (1 + vip_plus / 100.0) / 15)) standard_drop.update(drop) elif tp == PLUNDER_GOLD: standard_drop['gold'] = int(plunder_gold * (1 + vip_plus / 100.0)) resource = Resource(self.char_id, "Plunder Reward") resource.add(**standard_drop) self.send_notify() if got_hero_id: standard_drop['heros'] = [got_hero_id] return standard_drop_to_attachment_protomsg(standard_drop)
def get_reward_done(self, char_id, condition_id): standard_drop = get_drop([ACTIVITY_STATIC_CONDITIONS[condition_id].package]) resource = Resource(char_id, "Activity Get Reward", "get condition id {0}".format(condition_id)) standard_drop = resource.add(**standard_drop) return standard_drop_to_attachment_protomsg(standard_drop)
def get_reward(self, tp): if not self.mongo_plunder.target_char: raise SanguoException( errormsg.PLUNDER_GET_REWARD_NO_TARGET, self.char_id, "Plunder Get Reward", "no Target char" ) if tp in self.mongo_plunder.got_reward: raise SanguoException( errormsg.PLUNDER_GET_REWARD_ALREADY_GOT, self.char_id, "Plunder Get Reward", "tp {0} already got".format(tp) ) need_points = PLUNDER_REWARD_NEEDS_POINT[tp] if self.mongo_plunder.points < need_points: raise SanguoException( errormsg.PLUNDER_GET_REWARD_POINTS_NOT_ENOUGH, self.char_id, "Plunder Get Reward", "points not enough. {0} < {1}".format(self.mongo_plunder.points, need_points) ) self.mongo_plunder.points -= need_points self.mongo_plunder.got_reward.append(tp) self.mongo_plunder.save() standard_drop = make_standard_drop_from_template() plunder_gold = self.mongo_plunder.chars[str(self.mongo_plunder.target_char)].gold char = Char(self.char_id).mc vip_plus = VIP_FUNCTION[char.vip].plunder_addition got_hero_id = 0 if tp == PLUNDER_HERO: f = Formation(self.mongo_plunder.target_char) heros = f.in_formation_hero_original_ids() got_hero_id = random.choice([hid for hid in heros if hid]) p = Prison(self.char_id) p.prisoner_add(got_hero_id, plunder_gold/2) elif tp == PLUNDER_STUFF: stage = Stage(self.mongo_plunder.target_char) max_star_stage = stage.stage.max_star_stage if not max_star_stage: max_star_stage = 1 drop_ids = [int(i) for i in STAGES[max_star_stage].normal_drop.split(',')] drop = get_drop(drop_ids, multi=int(PLUNDER_GOT_ITEMS_HOUR * 3600 * (1+vip_plus/100.0) / 15)) standard_drop.update(drop) elif tp == PLUNDER_GOLD: standard_drop['gold'] = int(plunder_gold * (1+vip_plus/100.0)) resource = Resource(self.char_id, "Plunder Reward") resource.add(**standard_drop) self.send_notify() if got_hero_id: standard_drop['heros'] = [got_hero_id] return standard_drop_to_attachment_protomsg(standard_drop)