def reset(self): self._n_process = -1 self._enter_state = ENTER_STATE_OUTSIDE #向客户端同步高塔信息 net_trans.send_data(self._c_owner._hid, message.MSG_NET_GET_TOWER_INFO, self.get_info())
def battle_end(self, is_win, reward): if is_win: #已结束 if not self._n_process: curr_process = config.MAX_FLOOR_NUM - 1 self._n_auto_timer = -1 self._b_in_auto_tower = False self._n_des_process = -1 else: #月光之城通关 if self._n_des_process == config.MAX_FLOOR_NUM - 1 and self._n_process == -1: curr_process = config.MAX_FLOOR_NUM - 1 else: curr_process = self._n_process - 1 self._dict_auto_battle_result[curr_process] = { "win": is_win, "result": reward } if curr_process < self._n_des_process: self._n_auto_timer = timer.set_timer(config.AUTO_TOWER_TIME, \ repeat_count=1, \ callback=self.auto_battle) else: self._n_auto_timer = -1 self._b_in_auto_tower = False self._n_des_process = -1 else: curr_process = self._n_process # 战斗失败,结束自动战斗 self._dict_auto_battle_result[curr_process] = { "win": is_win, "result": reward } self._n_auto_timer = -1 self._b_in_auto_tower = False self._n_des_process = -1 net_trans.send_data(self._c_owner._hid, message.MSG_NET_AUTO_TOWER_SETTLE, \ self._dict_auto_battle_result) self._dict_auto_battle_result.clear()
def auto_battle(self): if self._n_auto_timer == -1: self._b_in_auto_tower = True self._n_auto_timer = timer.set_timer(config.AUTO_TOWER_TIME, \ repeat_count=1, \ callback=self.auto_battle) else: #扣钱 self._c_owner.change_money(-config.GOLD_PER_FLOOR, item_cfg.MONEY_YUANBAO, log_info.LOG_MONEY_CHG_AUTO_TOWER) curr_process = self._n_process #需动态检测格子数 check_resp = self._c_owner._bag.check_grid_enough( config.FREE_BAG_GRID_NUM) if check_resp["err_code"] != err_code.ERR_OK: #背包剩余格子数不够, 结束自动战斗 self._dict_auto_battle_result[curr_process] = { "win": False, "result": {}, "bag_grid": [ self._c_owner._bag.get_free_grid_num(), check_resp["detail"] ] } self._n_auto_timer = -1 self._b_in_auto_tower = False net_trans.send_data(self._c_owner._hid, message.MSG_NET_AUTO_TOWER_SETTLE,\ self._dict_auto_battle_result) self._dict_auto_battle_result.clear() return battle_ins.get_manager().auto_launch_battle_in_tower(self._c_owner._uid,\ self.get_npc(),\ instance.tower_cfg[self._n_process]["name"],\ self.battle_end) return {"process": self._n_process}
def battle_end(self, is_win, reward): if is_win: #已结束 if not self._n_process: curr_process = config.MAX_FLOOR_NUM - 1 self._n_auto_timer = -1 self._b_in_auto_tower = False self._n_des_process = -1 else: #月光之城通关 if self._n_des_process == config.MAX_FLOOR_NUM - 1 and self._n_process == -1: curr_process = config.MAX_FLOOR_NUM - 1 else: curr_process = self._n_process - 1 self._dict_auto_battle_result[curr_process] = {"win":is_win, "result":reward} if curr_process < self._n_des_process: self._n_auto_timer = timer.set_timer(config.AUTO_TOWER_TIME, \ repeat_count=1, \ callback=self.auto_battle) else: self._n_auto_timer = -1 self._b_in_auto_tower = False self._n_des_process = -1 else: curr_process = self._n_process # 战斗失败,结束自动战斗 self._dict_auto_battle_result[curr_process] = {"win":is_win, "result":reward} self._n_auto_timer = -1 self._b_in_auto_tower = False self._n_des_process = -1 net_trans.send_data(self._c_owner._hid, message.MSG_NET_AUTO_TOWER_SETTLE, \ self._dict_auto_battle_result) self._dict_auto_battle_result.clear()
def auto_battle(self): if self._n_auto_timer == -1: self._b_in_auto_tower = True self._n_auto_timer = timer.set_timer(config.AUTO_TOWER_TIME, \ repeat_count=1, \ callback=self.auto_battle) else: #扣钱 self._c_owner.change_money(-config.GOLD_PER_FLOOR, item_cfg.MONEY_YUANBAO, log_info.LOG_MONEY_CHG_AUTO_TOWER) curr_process = self._n_process #需动态检测格子数 check_resp = self._c_owner._bag.check_grid_enough(config.FREE_BAG_GRID_NUM) if check_resp["err_code"] != err_code.ERR_OK: #背包剩余格子数不够, 结束自动战斗 self._dict_auto_battle_result[curr_process] = {"win":False, "result":{}, "bag_grid":[self._c_owner._bag.get_free_grid_num(), check_resp["detail"]]} self._n_auto_timer = -1 self._b_in_auto_tower = False net_trans.send_data(self._c_owner._hid, message.MSG_NET_AUTO_TOWER_SETTLE,\ self._dict_auto_battle_result) self._dict_auto_battle_result.clear() return battle_ins.get_manager().auto_launch_battle_in_tower(self._c_owner._uid,\ self.get_npc(),\ instance.tower_cfg[self._n_process]["name"],\ self.battle_end) return {"process":self._n_process}
def finish_process(self, battle_detail): global saved_battles """战斗调用接口 - 战斗结束后调用""" result = self.generate_award() #改变任务状态 self._c_owner._quest_mgr.add_quest_count_after_action( quest_cfg.QUEST_ACTION_FINISH_TOWER) #推倒Boss if (not (self._n_process + 1) % 10) and (self._n_process != -1): first_kill_uids = [] for i in xrange(3): save_key = "tower_" + str(self._n_process) + "_" + str(i) if not saved_battles.has_key(save_key): #前三名击杀 launcher_id = self._c_owner.uid() im = battle_detail["im"] #是否为自动战斗 #如果未位于前三名之列,保存其记录 #自动战斗不保存战报 if launcher_id not in first_kill_uids and not im: battle_id = battle_detail["ins"].get_id() battle_name = battle_detail["name"] battle_pack = battle_detail["msg"]["launcher"][ "struct"]["pack"] saved_battles[save_key] = { "launcher_id": launcher_id, "battle_id": battle_id, "battle_name": battle_name } #将战斗相关信息写进文件数据库 #保存映射 db_ins.gm_fdbm.write( save_key, common.my_encode(saved_battles[save_key])) #保存战斗信息 db_ins.gm_fdbm.write(str(battle_id), common.my_encode(battle_pack)) db_ins.sync_fdbm() break else: first_kill_uids.append( saved_battles[save_key]["launcher_id"]) if self._n_process != config.MAX_FLOOR_NUM - 1: if config.FLOOR_CHAPTER_MAP.has_key(self._n_process): chapter_id = config.FLOOR_CHAPTER_MAP[self._n_process] #第一次打通本章 if chapter_id not in self._list_active_chapters: self._list_active_chapters.append( config.FLOOR_CHAPTER_MAP[self._n_process]) self._trigger_event_floor_clearance() if self._n_process > self._max_floor: self._max_floor = self._n_process #进军下一层 self._n_process += 1 if self._n_process == 5: self._c_owner._quest_mgr.add_quest_count_after_action( quest_cfg.QUEST_ACTION_FINISH_TOWER_5) elif self._n_process == 10: self._c_owner._quest_mgr.add_quest_count_after_action( quest_cfg.QUEST_ACTION_FINISH_TOWER_10) elif self._n_process == 20: self._c_owner._quest_mgr.add_quest_count_after_action( quest_cfg.QUEST_ACTION_FINISH_TOWER_20) elif self._n_process == 35: self._c_owner._quest_mgr.add_quest_count_after_action( quest_cfg.QUEST_ACTION_FINISH_TOWER_35) elif self._n_process == 50: self._c_owner._quest_mgr.add_quest_count_after_action( quest_cfg.QUEST_ACTION_FINISH_TOWER_50) elif self._n_process == 100: self._c_owner._quest_mgr.add_quest_count_after_action( quest_cfg.QUEST_ACTION_FINISH_TOWER_100) elif self._n_process == 200: self._c_owner._quest_mgr.add_quest_count_after_action( quest_cfg.QUEST_ACTION_FINISH_TOWER_200) elif self._n_process == 300: self._c_owner._quest_mgr.add_quest_count_after_action( quest_cfg.QUEST_ACTION_FINISH_TOWER_300) else: pass else: if self._n_process > self._max_floor: self._max_floor = self._n_process self._trigger_event_floor_clearance_all() #通关,重新回到入口 self._n_process = -1 self._enter_state = ENTER_STATE_OUTSIDE self._c_owner._quest_mgr.add_quest_count_after_action( quest_cfg.QUEST_ACTION_FINISH_TOP_TOWER) self._c_owner._quest_mgr.add_quest_count_after_action( quest_cfg.QUEST_ACTION_FINISH_TOWER_300) #获得物品,公告 if len(result): self._trigger_event_get_item(result) #向客户端同步高塔信息 net_trans.send_data(self._c_owner._hid, message.MSG_NET_GET_TOWER_INFO, self.get_info()) return result
def finish_process(self, battle_detail): global saved_battles """战斗调用接口 - 战斗结束后调用""" result = self.generate_award() #改变任务状态 self._c_owner._quest_mgr.add_quest_count_after_action(quest_cfg.QUEST_ACTION_FINISH_TOWER) #推倒Boss if (not (self._n_process + 1)% 10) and (self._n_process != -1): first_kill_uids = [] for i in xrange(3): save_key = "tower_" + str(self._n_process) + "_" + str(i) if not saved_battles.has_key(save_key): #前三名击杀 launcher_id = self._c_owner.uid() im = battle_detail["im"] #是否为自动战斗 #如果未位于前三名之列,保存其记录 #自动战斗不保存战报 if launcher_id not in first_kill_uids and not im: battle_id = battle_detail["ins"].get_id() battle_name = battle_detail["name"] battle_pack = battle_detail["msg"]["launcher"]["struct"]["pack"] saved_battles[save_key] = {"launcher_id":launcher_id, "battle_id":battle_id, "battle_name":battle_name} #将战斗相关信息写进文件数据库 #保存映射 db_ins.gm_fdbm.write(save_key, common.my_encode(saved_battles[save_key])) #保存战斗信息 db_ins.gm_fdbm.write(str(battle_id), common.my_encode(battle_pack)) db_ins.sync_fdbm() break else: first_kill_uids.append(saved_battles[save_key]["launcher_id"]) if self._n_process != config.MAX_FLOOR_NUM - 1: if config.FLOOR_CHAPTER_MAP.has_key(self._n_process): chapter_id = config.FLOOR_CHAPTER_MAP[self._n_process] #第一次打通本章 if chapter_id not in self._list_active_chapters: self._list_active_chapters.append(config.FLOOR_CHAPTER_MAP[self._n_process]) self._trigger_event_floor_clearance() if self._n_process > self._max_floor: self._max_floor = self._n_process #进军下一层 self._n_process += 1 if self._n_process == 5: self._c_owner._quest_mgr.add_quest_count_after_action(quest_cfg.QUEST_ACTION_FINISH_TOWER_5) elif self._n_process == 10: self._c_owner._quest_mgr.add_quest_count_after_action(quest_cfg.QUEST_ACTION_FINISH_TOWER_10) elif self._n_process == 20: self._c_owner._quest_mgr.add_quest_count_after_action(quest_cfg.QUEST_ACTION_FINISH_TOWER_20) elif self._n_process == 35: self._c_owner._quest_mgr.add_quest_count_after_action(quest_cfg.QUEST_ACTION_FINISH_TOWER_35) elif self._n_process == 50: self._c_owner._quest_mgr.add_quest_count_after_action(quest_cfg.QUEST_ACTION_FINISH_TOWER_50) elif self._n_process == 100: self._c_owner._quest_mgr.add_quest_count_after_action(quest_cfg.QUEST_ACTION_FINISH_TOWER_100) elif self._n_process == 200: self._c_owner._quest_mgr.add_quest_count_after_action(quest_cfg.QUEST_ACTION_FINISH_TOWER_200) elif self._n_process == 300: self._c_owner._quest_mgr.add_quest_count_after_action(quest_cfg.QUEST_ACTION_FINISH_TOWER_300) else: pass else: if self._n_process > self._max_floor: self._max_floor = self._n_process self._trigger_event_floor_clearance_all() #通关,重新回到入口 self._n_process = -1 self._enter_state = ENTER_STATE_OUTSIDE self._c_owner._quest_mgr.add_quest_count_after_action(quest_cfg.QUEST_ACTION_FINISH_TOP_TOWER) self._c_owner._quest_mgr.add_quest_count_after_action(quest_cfg.QUEST_ACTION_FINISH_TOWER_300) #获得物品,公告 if len(result): self._trigger_event_get_item(result) #向客户端同步高塔信息 net_trans.send_data(self._c_owner._hid, message.MSG_NET_GET_TOWER_INFO, self.get_info()) return result