def skill(obj, grey=False): style_map = { "Boji": "搏击", "Jianfa": "剑法", "Daofa": "刀法", "Changbing": "长兵", "Duanbing": "短柄", "Ruansuo": "软索", "Anqi": "暗器", "Yueqi": "乐曲" } effe_str = [] for effe in obj.effects: effe_str.append(effectname(effe)) if len(effe_str) == 0: effe_str = "无" else: effe_str = "、".join(effe_str) yinyang_str = ui.colored(["阴性", "调和", "阳性"][obj.yinyang + 1], color=["cyan", None, "yellow"][obj.yinyang + 1]) style_str = [] for style in style_map.keys(): if style in obj.style: style_str.append(style_map[style]) style_str = "兼".join(style_str) normal_str = "威力:%s,耗气:%s,范围:%s%s,冷却:%s回合,特效:" % \ (obj.power, obj.mp, obj.shape.showword, {"Friends": "友方", "Enemies": "敌方", "All": "不分敌友", "Grids": ""}[obj.targets], obj.cd) if grey: normal_str = ui.colored(normal_str, color="grey", attrs=["bold"]) return ",".join([style_str, yinyang_str, normal_str + effe_str])
def status(obj, grey=False): ret = None if obj.name is not None and len(obj.name) > 0: ret = "%s" % effectname(obj) if grey: ret += ui.colored(":", color="grey", attrs=["bold"]) else: ret += ":" comment = "" if obj.source is not None: #comment += "来源:" if obj.exertor is not None: comment += obj.exertor.name if "Neigong" in obj.source.tags: #comment += rank(obj.source.belongs, txt="【%s】" % obj.source.belongs.name) comment += "【%s】" % obj.source.belongs.name else: #comment += rank(obj.source, txt="【%s】" % obj.source.name) comment += "【%s】" % obj.source.name if obj.leftturn > 0: comment += ",剩余%s回合" % obj.leftturn if obj.description is None: description = "" else: description = obj.description description += "(%s)" % comment if grey: ret += ui.colored(description, color="grey", attrs=["bold"]) else: ret += description return ret
def _render(self, entities=None): t1 = time.time() if entities is None: entities = [] entity_info = {} for p in entities: loc = p["location"] entity_info[loc] = p grids = self.map.xy plines = [] for j in range(self.map.y): content_line = (self.gwidth // 2 + 1) * (j % 2) * " " for i in range(self.map.x): g = grids[i][j] content = "" terran_char, terran_color = self.colorvision(g) if len(content) == 0 and (i, j) in entity_info: if not entity_info[(i, j)]["player"]: content += ui.colored("P", color="cyan", attrs=["bold"]) else: content += ui.colored("P", color="white", on_color="on_red", attrs=["bold"]) elif len(content) == 0 and g.object is not None: content += ui.colored(g.object.thumbnail, **g.object.vision) content_line += ui.fixed(self.gwidth, n=content, bg=terran_char, **terran_color) content_line += ui.fixed((self.gwidth // 2 + 1) * ((j + 1) % 2), bg=" ") plines.append(content_line) ui.echo(plines)
def render(self, entities=None): """ 对略缩图渲染速率进行少量优化 """ #t1 = time.time() if entities is None: entities = [] entity_info = {} for p in entities: loc = p["location"] entity_info[loc] = p grids = self.map.xy plines = [] for j in range(self.map.y): content_line = (self.gwidth // 2) * (j % 2) * " " fix_count = 0 last_g = None last_content = None for i in range(self.map.x): g = grids[i][j] content = "" if len(content) == 0 and (i, j) in entity_info: if not entity_info[(i, j)]["player"]: content += ui.colored("P", color="cyan", attrs=["bold"]) else: content += ui.colored("P", on_color="on_red", attrs=["bold"]) elif len(content) == 0 and g.object is not None: content += ui.colored(g.object.thumbnail, **g.object.vision) elif (i, j) in self.map.transport_locs: if self.map.transport_locs[(i, j)] == "MAP_WORLD": content += ui.colored("出", on_color="on_cyan") else: content += ui.colored("场", on_color="on_cyan") if last_g is not None: if content != last_content or g.object is not None or \ g.terran != last_g.terran or (i, j) in self.map.transport_locs: terran_char, terran_color = self.colorvision(last_g) content_line += ui.fixed(self.gwidth * fix_count, n=last_content, bg=terran_char, **terran_color) fix_count = 0 fix_count += 1 last_g = g last_content = content terran_char, terran_color = self.colorvision(last_g) content_line += ui.fixed(self.gwidth * fix_count, n=last_content, bg=terran_char, **terran_color) content_line += ui.fixed((self.gwidth // 2) * ((j + 1) % 2), bg=" ") plines.append(content_line) ui.echo(plines)
def rank(obj, txt=None, grey=False): if txt is None: txt = obj.name ranks = [None, "green", "cyan", "magenta", "yellow"] return ui.colored(txt, color=ranks[obj.rank], attrs=["dark"] if grey else ["bold"])
def effect(obj, grey=False): ret = None if obj.name is not None and len(obj.name) > 0: ret = "%s" % effectname(obj) if grey: ret += ui.colored(":", color="grey", attrs=["bold"]) else: ret += ":" if obj.turns is not None and obj.turns > 0: desc_str = obj.description + ",持续%s回合" % obj.turns else: desc_str = obj.description if grey: ret += ui.colored(desc_str, color="grey", attrs=["bold"]) else: ret += desc_str return ret
def effectname(obj, txt=None, grey=False): if txt is None: txt = obj.name styles = ["red", "green", "magenta"] return ui.colored(txt, color=styles[obj.style])
def render(self, entities=None, coordinates=None, show_trace=True): #t1 = time.time() if coordinates is None: coordinates = [] if entities is None: entities = [] entity_info = {} trace_info = [] for p in entities: loc = self.map.point_to_window(p["location"]) entity_info[loc] = p if p["trace"] is not None: trace_info.extend(p["trace"]) grids = self.map.window() plines = [] for j in range(self.map.window_y): plines.append(HOR * (self.gwidth // 2 + 1) + HOR * (self.map.window_x * (self.gwidth + 1) + 1)) real_j = j + self.map.window_start_y if self.map.window_start_x > 0: bg_before, bg_before_color = self.colorvision(self.map.xy[self.map.window_start_x - 1][real_j]) else: bg_before = " " bg_before_color = {} line_contents = [] for idx in range(self.gheight): line_contents.append(ui.fixed((self.gwidth // 2 + 1) * (real_j % 2), bg=bg_before, **bg_before_color) + VER) for i in range(self.map.window_x): contents = [] for idx in range(self.gheight): contents.append("") g = grids[i][j] terran_char, terran_color = self.colorvision(g) real_coor = self.map.point_to_real((i, j)) if show_trace and real_coor in trace_info: contents[0] = ui.colored("(%s, %s)" % (i, j), color="blue", attrs=["bold"]) for coor_info in coordinates: if coor_info["positions"] is None or real_coor not in coor_info["positions"]: continue if coor_info.get("reality", False): coor = real_coor else: coor = (i, j) contents[0] += ui.colored("(%s, %s)" % coor, color=coor_info.get("color", "green"), attrs=["bold"]) #break if (i, j) in entity_info: for idx in range(self.gheight): contents[idx] += entity_info[(i, j)]["contents"][idx] elif g.object is not None: contents[0] += ui.colored(g.title(), attrs=["bold"]) elif real_coor in self.map.transport_locs: if self.map.tpl_id == "MAP_WORLD": showstr = EntityMap.one(self.map.transport_locs[real_coor]).name contents[0] += ui.colored(showstr, attrs=["bold"]) else: showstr = "前往" + EntityMap.one(self.map.transport_locs[real_coor]).name contents[0] += ui.colored(showstr, color="grey", attrs=["bold"]) for idx in range(self.gheight): line_contents[idx] += ui.fixed(self.gwidth, n=contents[idx], bg=terran_char, **terran_color) + VER if self.map.window_start_x + self.map.window_x < self.map.x - 1: bg_before, bg_before_color = self.colorvision(self.map.xy[self.map.window_start_x + self.map.window_x][real_j]) else: bg_before = " " bg_before_color = {} for idx in range(self.gheight): line_contents[idx] += ui.fixed((self.gwidth // 2 + 1) * ((real_j + 1) % 2), bg=bg_before, **bg_before_color) for l in line_contents: plines.append(l) plines.append(HOR * (self.gwidth // 2 + 1) + HOR * (self.map.window_x * (self.gwidth + 1) + 1)) ui.echo(plines)