def init_hero(player): # ========================================== runts = {} d = random.sample(range(1, 11), 2) runt_nos = game_configs.stone_config.get('stones').keys() for a in xrange(1, 5): type_info = {} # for b in xrange(1, 11): for b in d: c = random.randint(0, len(runt_nos)-1) runt_id = runt_nos[c] main_attr, minor_attr = player.runt.get_attr(runt_id) runt_info = [get_uuid(), runt_id, main_attr, minor_attr] type_info[b] = runt_info runts[a] = type_info # =============================================== for k, val in game_configs.hero_config.items(): if val.type == 0: hero1 = player.hero_component.add_hero_without_save(k) hero1.hero_no = k hero1.level = 1 hero1.break_level = 0 hero1.exp = 0 hero1 = player.hero_component.add_hero_without_save(10045) hero1.break_level = 7 hero1.level = 35 hero1.runt = runts hero1.refine = 1001020
def add_equipment(self, equipment_no, lucky_attr=0): """添加装备 """ character_id = self.owner.base_info.id equipment_id = get_uuid() equipment_obj = Equipment(character_id, equipment_id, '', equipment_no) self._equipments_obj[equipment_id] = equipment_obj equipment_obj.add_data(self.owner.base_info.id, lucky_attr) equ_conf = game_configs.equipment_config.get(equipment_no) cid = 0 color = equ_conf.color color_num = 0 star6_num = 0 if equ_conf.color == 1: cid = CONDITIONId.GREEN_EQU elif equ_conf.color == 2: cid = CONDITIONId.BLUE_EQU for _, equ_obj in self._equipments_obj.items(): e_conf = game_configs.equipment_config. \ get(equ_obj.base_info.equipment_no) if e_conf.color == color and cid: color_num += 1 if e_conf.quality == 6: star6_num += 1 if color_num: hook_task(self.owner, cid, color_num) if star6_num: hook_task(self.owner, CONDITIONId.STAR6_EQU, star6_num) return equipment_obj
def add_mail(self, sender_id, sender_name, title, content, mail_type, send_time, prize, sender_icon=0): """添加邮件""" if mail_type == 1: # 领取体力邮件不能超过15个 mails = self.get_mails_by_type(1) if len(mails) == 15: return mail_id = get_uuid() character_id = self.owner.base_info.id mail = Mail(mail_id=mail_id, character_id=character_id, sender_id=sender_id, sender_name=sender_name, sender_icon=sender_icon, title=title, content=content, mail_type=mail_type, send_time=send_time, prize=prize) self._mails[mail_id] = mail self.new_mail_data(mail) self.save_data() return mail
def add_equipment(self, equipment_no): """添加装备 """ equipment_id = get_uuid() equipment_obj = Equipment(equipment_id, '', equipment_no) self._equipments_obj[equipment_id] = equipment_obj equipment_obj.add_data(self.owner.base_info.id) return equipment_obj
def add_runt(self, runt_id): # if len(self._m_runt) + 1 > game_configs.base_config.get('totemStash'): # return 0 runt_no = get_uuid() mainAttr, minorAttr = self.get_attr(runt_id) if self._m_runt.get(runt_no): return 0 else: self._m_runt[runt_no] = [runt_id, mainAttr, minorAttr] return runt_no
def add_runt(self, runt_id): if len(self._m_runt) + 1 > game_configs.base_config.get('totemStash'): return 0 runt_no = get_uuid() mainAttr, minorAttr = self.get_attr(runt_id) if self._m_runt.get(runt_no): return 0 else: self._m_runt[runt_no] = [runt_id, mainAttr, minorAttr] return runt_no
def add_mail(self, mail): """添加邮件""" mails = self.get_mails_by_type(mail.mail_type) if mail.mail_type != 2 and len(mails) >= 50: last_mail = [0, time.time()] for mail_pb in mails: if mail_pb.send_time < last_mail[1]: last_mail = [mail_pb.mail_id, mail_pb.send_time] self.delete_mail(last_mail[0]) mail.mail_id = get_uuid() mail.receive_id = self.owner.base_info.id self._mails[mail.mail_id] = mail self._new_mail_data(mail)
def refresh_runt_844(data, player): """打造刷新""" response = RefreshRuntResponse() need_gold = 0 # 0 免费,1 招募令,2 元宝 refresh_times = copy.copy(player.runt.refresh_times) if time.localtime(player.runt.refresh_times[1]).tm_year == time.localtime().tm_year \ and time.localtime(player.runt.refresh_times[1]).tm_yday == time.localtime().tm_yday: refresh_times[0] += 1 if game_configs.base_config.get('totemRefreshFreeTimes') <= player.runt.refresh_times[0]: need_gold = 1 else: # player.runt.refresh_times = [1, int(time.time())] refresh_times = [1, int(time.time())] need_item = game_configs.base_config.get('totemRefreshItem') if need_gold == 1 and not is_afford(player, need_item).get('result'): need_gold = 2 if need_gold == 2 and player.finance.gold < game_configs.base_config.get('totemRefreshPrice'): response.res.result = False response.res.result_no = 102 # 充值币不足 return response.SerializeToString() if need_gold == 1: consume(player, need_item, const.RUNT_REFRESH) if need_gold == 2: player.finance.consume_gold(game_configs.base_config.get('totemRefreshPrice'), const.RUNT_REFRESH) player.runt.refresh_times = refresh_times while True: new_refresh_id = player.runt.build_refresh() if player.runt.refresh_runt: if not player.runt.refresh_runt[1] == new_refresh_id: break else: break runt_no = get_uuid() mainAttr, minorAttr = player.runt.get_attr(new_refresh_id) player.runt.refresh_runt = [runt_no, new_refresh_id, mainAttr, minorAttr] player.runt.deal_runt_pb(runt_no, new_refresh_id, mainAttr, minorAttr, response.refresh_runt) player.finance.save_data() player.runt.save() response.res.result = True return response.SerializeToString()
def refresh_tasks(self): """刷新押运列表""" items = {} self._tasks = {} for _, item in game_configs.guild_task_config.items(): items[item.id] = item.weights task_num = game_configs.base_config.get('EscortTaskShowQuantity') task_nos = random_multi_pick(items, task_num) for task_no in task_nos: task = {} task_id = get_uuid() task["task_id"] = task_id task["task_no"] = task_no task["state"] = 0 self._tasks[task_id] = task
def add_guild_boss(self, stage_id, blue_units, boss_type, trigger_player_id, trigger_player_name): """docstring for add_boss""" logger.debug("add boss %s %s" % (blue_units, stage_id)) boss = GuildBoss() boss._boss_id = get_uuid() boss.blue_units = blue_units boss.stage_id = stage_id boss.trigger_time = int(get_current_timestamp()) boss.hp_max = boss.hp boss.boss_type = boss_type boss.trigger_player_id = trigger_player_id boss.trigger_player_name = trigger_player_name self._guild_boss = boss self._guild_boss_trigger_times = self._guild_boss_trigger_times + 1 self.save_data() return boss
def init_equipment(player): return character_id = player.base_info.id for equip_no, val in game_configs.equipment_config.items(): equipment_obj = Equipment(character_id, get_uuid(), '', equip_no) player.equipment_component.add_exist_equipment(equipment_obj) equipment_obj.attribute.strengthen_lv = 1 equipment_obj.save_data() return equipment_obj = Equipment(get_uuid(), '', 100001) player.equipment_component.add_exist_equipment(equipment_obj) equipment_obj.attribute.strengthen_lv = 2 equipment_obj.attribute.awakening_lv = 2 equipment_obj.save_data() equipment_obj = Equipment(get_uuid(), '', 100002) player.equipment_component.add_exist_equipment(equipment_obj) equipment_obj.attribute.strengthen_lv = 2 equipment_obj.attribute.awakening_lv = 2 equipment_obj.save_data() equipment_obj = Equipment(get_uuid(), '', 100003) player.equipment_component.add_exist_equipment(equipment_obj) equipment_obj.attribute.strengthen_lv = 2 equipment_obj.attribute.awakening_lv = 2 equipment_obj.save_data() equipment_obj = Equipment(get_uuid(), '', 100004) player.equipment_component.add_exist_equipment(equipment_obj) equipment_obj.attribute.strengthen_lv = 2 equipment_obj.attribute.awakening_lv = 2 equipment_obj.save_data() equipment_obj = Equipment(get_uuid(), '', 100005) player.equipment_component.add_exist_equipment(equipment_obj) equipment_obj.attribute.strengthen_lv = 2 equipment_obj.attribute.awakening_lv = 2 equipment_obj.save_data() equipment_obj = Equipment(get_uuid(), '', 100006) player.equipment_component.add_exist_equipment(equipment_obj) equipment_obj.attribute.strengthen_lv = 2 equipment_obj.attribute.awakening_lv = 2 equipment_obj.save_data() player.equipment_component.save_data()
def build_runt_846(data, player): """打造""" response = BuildRuntResponse() refresh_runt = player.runt.refresh_runt if not refresh_runt: response.res.result = False response.res.result_no = 828 return response.SerializeToString() runt_conf = game_configs.stone_config.get('stones').get(refresh_runt[1]) [need_stone1, need_stone2, need_coin] = runt_conf.price if player.runt.stone1 < need_stone1 or player.runt.stone2 < need_stone2 or player.finance.coin < need_coin: response.res.result = False response.res.result_no = 826 return response.SerializeToString() player.runt.stone1 -= need_stone1 player.runt.stone2 -= need_stone2 player.finance.coin -= need_coin if len(player.runt.m_runt) + 1 > game_configs.base_config.get('totemStash'): response.res.result = False response.res.result_no = 824 return response.SerializeToString() [runt_no, runt_id, main_attr, minor_attr] = player.runt.refresh_runt player.runt.m_runt[runt_no] = [runt_id, main_attr, minor_attr] while True: new_refresh_id = player.runt.build_refresh() if not player.runt.refresh_runt[1] == new_refresh_id: break runt_no = get_uuid() mainAttr, minorAttr = player.runt.get_attr(new_refresh_id) player.runt.refresh_runt = [runt_no, new_refresh_id, mainAttr, minorAttr] player.runt.deal_runt_pb(runt_no, new_refresh_id, mainAttr, minorAttr, response.refresh_runt) player.runt.save() player.finance.save_data() response.res.result = True return response.SerializeToString()
def create_guild(self, p_id, name): self._name = name uuid = get_uuid() self._g_id = uuid self._p_list = {1: [p_id]} # fund 资金 data = { 'id': self._g_id, 'info': { 'name': self._name, 'p_num': self._p_num, 'level': self._level, 'exp': self._exp, 'fund': self._fund, 'call': self._call, 'record': self._record, 'p_list': self._p_list, 'apply': self._apply } } tb_guild_info.new(data)
def init_hero(player): # ========================================== runts = {} d = random.sample(range(1, 11), 10) #runt_nos = game_configs.stone_config.get('stones').keys() runt_nos = [150101, 150201, 150301, 150401] for a in xrange(1, 5): type_info = {} # for b in xrange(1, 11): for b in d: temp = None runt_no = None while a != temp: c = random.randint(0, len(runt_nos)-1) runt_no = runt_nos[c] temp = game_configs.stone_config.get("stones").get(runt_no).get("type") main_attr, minor_attr = player.runt.get_attr(runt_no) runt_info = [get_uuid(), runt_no, main_attr, minor_attr] type_info[b] = runt_info runts[a] = type_info # =============================================== for k, val in game_configs.hero_config.items(): if val.type == 0: hero1 = player.hero_component.add_hero(k) hero1.hero_no = k hero1.level = 1 hero1.break_level = 0 hero1.exp = 0 hero1.save_data() heros = [10045, 10046, 10048, 10053, 10056, 10061] for no in heros: init_single_hero(player, runts, no)
def stage_sweep(stage_id, times, player, sweep_type): response = stage_response_pb2.StageSweepResponse() res = response.res stage_obj = player.stage_component.get_stage(stage_id) # 关于关卡挑战次数 if time.localtime(player.stage_component.stage_up_time ).tm_yday != time.localtime().tm_yday: player.stage_component.stage_up_time = int(time.time()) player.stage_component.update_stage_times() player.stage_component.save_data() # vip等级够不够 if times == 1: if not game_configs.vip_config.get( player.base_info.vip_level).openSweep: logger.error('result_no = 803') res.result = False res.result_no = 803 return response.SerializePartialToString() if times > 1: if not game_configs.vip_config.get( player.base_info.vip_level).openSweepTen: logger.error('result_no = 803') res.result = False res.result_no = 803 return response.SerializePartialToString() # 关卡打开没有 state = player.stage_component.check_stage_state(stage_id) if state != 1: logger.error('result_no = 803') res.result = False res.result_no = 803 return response.SerializePartialToString() stage_config = game_configs.stage_config.get('stages').get(stage_id) # 限制次数够不够 if stage_obj.attacks + times > stage_config.limitTimes: logger.error('result_no = 810') res.result = False res.result_no = 810 return response.SerializePartialToString() # 花费 if sweep_type == 1: # 扫荡卷 sweep_item = game_configs.base_config.get('sweepNeedItem') elif sweep_type == 2: sweep_item = game_configs.base_config.get('price_sweep') else: logger.error('result_no = 800 ,sweep type error===========') res.result = False res.result_no = 800 return response.SerializePartialToString() result = is_afford(player, sweep_item, multiple=times) # 校验 if not result.get('result'): logger.error('result_no = 839 ,===========') res.result = False res.result_no = 839 return response.SerializePartialToString() need_gold = get_consume_gold_num(sweep_item, times) tlog_event_id = get_uuid() def func(): # 武将乱入 fight_cache_component = player.fight_cache_component fight_cache_component.stage_id = stage_id red_units, blue_units, drop_num, monster_unpara = fight_cache_component.fighting_start( ) multiple, part_multiple = get_drop_activity( player, player.fight_cache_component.stage_id, 1, stage_obj.star_num) for _ in range(times): drop = [] drops = response.drops.add() low = stage_config.low high = stage_config.high drop_num = random.randint(low, high) for __ in range(drop_num): common_bag = BigBag(stage_config.commonDrop) common_drop = common_bag.get_drop_items() drop.extend(common_drop) fight_cache_component.get_stage_drop(stage_config, drop) data = gain(player, drop, const.STAGE_SWEEP, event_id=tlog_event_id, multiple=multiple, part_multiple=part_multiple) get_return(player, data, drops) # 乱入武将按概率获取碎片 break_stage_id = player.fight_cache_component.break_stage_id if break_stage_id: break_stage_info = game_configs.stage_break_config.get( break_stage_id) ran = random.random() if ran <= break_stage_info.reward_odds: # logger.debug("break_stage_info=============%s %s" % (break_stage_info.reward, 1)) data = gain(player, break_stage_info.reward, const.STAGE_SWEEP) get_return(player, data, drops) player.finance.consume(const.STAMINA, stage_config.vigor, const.STAGE_SWEEP) # 经验 for (slot_no, lineUpSlotComponent ) in player.line_up_component.line_up_slots.items(): hero = lineUpSlotComponent.hero_slot.hero_obj if hero: beforelevel = hero.level hero.upgrade(stage_config.HeroExp, player.base_info.level) afterlevel = hero.level changelevel = afterlevel - beforelevel hero.save_data() if changelevel: tlog_action.log('HeroUpgrade', player, hero.hero_no, changelevel, afterlevel, 3, 0, 0, 0, 0) # 玩家金钱 player.finance.coin += stage_config.currency # 玩家经验 player.base_info.addexp(stage_config.playerExp, const.STAGE_SWEEP) # 更新等级相关属性 player.set_level_related() # hook task hook_task(player, CONDITIONId.ANY_STAGE, times) logger.debug("sweep time %s %s" % (times, sweep_item)) return_data = consume(player, sweep_item, const.STAGE_SWEEP, multiple=times) get_return(player, return_data, response.consume) player.stage_component.get_stage(stage_id).attacks += times player.stage_component.save_data() player.stamina.save_data() player.base_info.save_data() player.finance.save_data() player.pay.pay(need_gold, const.STAGE_SWEEP, func) # 触发黄巾起义 hjqy_stage_id = trigger_hjqy(player, result, times) response.hjqy_stage_id = hjqy_stage_id if hjqy_stage_id: tlog_action.log('TriggerHJQY', player, stage_id, hjqy_stage_id) res.result = True tlog_action.log('SweepFlow', player, stage_id, times, tlog_event_id) return response.SerializePartialToString()