def take(self): # 获取战斗地图,暂时只支持一个场景关联一张战斗地图 # TODO: 支持一个场景可关联多张战斗地图,根据实际坐标进行获取 if self.battle_map is None: map = Map.template("%s_BTL" % self.subject.scenario.tpl_id) else: map = self.battle_map context.teams[self.object.id] = self.object context.teams[self.subject.id] = self.subject subject_group = self.subject_group if self.subject_group is not None else self.subject.members if self.object.battle is None: silent = self.subject != context.PLAYER.team and self.object != context.PLAYER.team BattleStartAction(map=map, groups=[subject_group, self.object.members], death=self.death, silent=silent).do() else: allies = self.object.battle.allies new_group_index = len(self.object.battle.groups) enemy_group = self.object.battle.groups.index( self.object.leader.group) for al in allies: if enemy_group in al: continue al.append(new_group_index) BattleJoinAction(battle=self.object.battle, group=subject_group, death=self.death, allies=allies).do()
def load(filepath): with open(filepath) as fd: ret = json.loads(fd.read()) context.timestamp = ret["timestamp"] context.timestamp_ = ret["timestamp"] context.explorations = ret["discoveries"] context.script_status = ret["script_status"] context.script_branches = ret["script_branches"] for k, evt in ret["events"].items(): Event.All[k].triggered = evt["triggered"] Event.All[k].active = evt["active"] clean_persons() for k, p_info in ret["persons"].items(): tpl_id = p_info["tpl_id"] if tpl_id not in Entity.Templates: Entity.Templates[tpl_id] = [] if len(Entity.Templates[tpl_id]) == 0: obj = Person() obj.load(**p_info) Entity.Templates[tpl_id].append(obj) Entity.Instances[obj.id] = obj battle_dict = {} for k, b_info in ret["battles"].items(): map = Map.template(b_info["map"]) groups = [] for group in b_info["groups"]: groups.append([Entity.Instances[pid] for pid in group]) allies = b_info["allies"] death = b_info["death"] silent = b_info["silent"] battle = Battle(map=map, groups=groups, allies=allies, silent=silent, death=death) battle.turnidx = b_info["turnidx"] battle.cdmap = b_info["cdmap"] battle.alive = [Entity.Instances[pid] for pid in b_info["alive"]] battle.dead = [Entity.Instances[pid] for pid in b_info["dead"]] battle_dict[b_info["id"]] = battle for k, t_info in ret["teams"].items(): team = Team() team.id = t_info["id"] team.process = t_info["process"] for pid in t_info["members"]: team.include(Entity.Instances[pid]) if t_info["active"]: context.teams[team.id] = team if "battle" in t_info: team.battle = battle_dict[t_info["battle"]] team.scenario = Map.one(t_info["scenario"]) team.scenario.locate(team, t_info["location"]) p = Person.one("PERSON_YANG_LEI") m = Map.one("MAP_WORLD") context.PLAYER = Person.one("PERSON_PLAYER")