def handler_battle_skill_scope(ac): map = ac.battle.map if ac.type == SkillType.Counter: ui.echo() ui.echo("%s发动反击!" % ac.subject.name) ui.echo() ui.read("(回车继续)") if ac.battle.current != ac.subject or not ac.battle.controllable(): ui.echo() ui.echo("%s使出" % ac.subject.name + ui.rank(ac.skill.belongs, txt="【%s】" % ac.skill.belongs.name) + \ "中的一式" + ui.rank(ac.skill, txt="【%s】" % ac.skill.name)) ui.echo() if ac.type != SkillType.Counter and ac.battle.current != ac.subject: ui.read("(回车继续)") ui.map(map, entities=battle_person_handler(ac.snapshot), coordinates=[{ "positions": ac.scope, "color": "yellow" }], show_trace=False) #ui.echo() #ui.echo("%s使出" % ac.subject.name + ui.rank(ac.skill.belongs, txt="【%s】" % ac.skill.belongs.name) + \ # "中的一式" + ui.rank(ac.skill, txt="【%s】" % ac.skill.name)) ui.echo() ui.read("(回车继续)")
def skill_menu(person): smenu = [] for sk in person.skills: sk_str = "%s:%s" % (ui.rank(sk.belongs), ui.rank(sk)) comments = [ui.skill(sk)] for effe in sk.effects: comments.append(ui.effect(effe)) smenu.append(ui.menuitem(sk_str, comments=comments, value=sk)) return smenu
def equipment(p): ret = [] ret.append(" 主手:" + \ (ui.rank(p.equipment[0]) if p.equipment[0] is not None else "无") + \ ("(双手持握)" if p.equipment[0] is not None and p.equipment[0].double_hand else "")) ret.append(" 副手:" + \ (ui.rank(p.equipment[1]) if p.equipment[1] is not None else "无") + \ ("(双手持握)" if p.equipment[0] is not None and p.equipment[0].double_hand else "")) ret.append(" 身体:" + ( ui.rank(p.equipment[2]) if p.equipment[2] is not None else "无")) ret.append(" 饰品:" + ( ui.rank(p.equipment[4]) if p.equipment[4] is not None else "无")) return ret
def item_menu(ctrl): smenu = [] for itm, person, valid in ctrl.items: suffix_list = [] if len(ctrl.persons) > 1: suffix_list.append("持有人:%s" % ui.colored(person.name, attrs=["bold"])) if "Equip" in itm.tags: suffix_list.append("数量:1,耐久度:%s/%s" % (itm.durability_current, itm.durability)) else: suffix_list.append("数量:%s" % person.quantities[itm.tpl_id]) if ctrl.showmoney and itm.tpl_id != "ITEM_MONEY": if ctrl.moneystyle == 0: money_num = itm.money else: money_num = int(itm.money * 0.4) suffix_list.append("价值:%s" % ui.byellow(money_num)) if itm in person.equipment: suffix_list.append(ui.colored("装备中", color="green")) suffix = "(%s)" % ",".join(suffix_list) if not valid: mitem = ui.menuitem(itm.name + ui.bgrey(suffix), value=(itm, person), validator=lambda x: False) else: comments = ui.item(itm) mitem = ui.menuitem(ui.rank(itm) + suffix, comments=comments, value=(itm, person), goto=ctrl.select) smenu.append(mitem) return smenu
def handler_battle_finish(ac): ui.echo() result = "胜利" if ac.result else "失败" ui.warn("战斗%s!" % result) ui.echo() for p, exp in ac.explist: ui.echo("%s获得了%s点经验。" % (p.name, exp)) ui.echo() for p, node in ac.nodelist: ui.echo("%s已经习得了技能%s:%s。" % (p.name, ui.rank(node.belongs), ui.rank(node))) ui.echo() for p, item, quantity in ac.itemlist: ui.echo("%s获得了%s×%s。" % (p.name, ui.rank(item), quantity)) ui.echo() ui.read("(回车继续)")
def handler_item_inlay_select_control(ctrl): imenu = [] for idx, inlay in enumerate(ctrl.item.inlays): enabled = "filled" not in inlay if enabled: name_str = inlay["name"] comments = [ "接受材料:%s" % "、".join([ui.tag(acp) for acp in inlay["accept"]]) ] validator = lambda x: True else: name_str = inlay["name"] comments = ["已强化:%s" % ui.rank(inlay["filled"])] comments.extend([ ui.effect(effe, grey=True) for effe in inlay["filled"].effects if effe.name is not None ]) validator = lambda x: False imenu.append( ui.menuitem(name_str, value=idx, comments=comments, validator=validator, goto=ctrl.select)) ret = ui.menu(imenu, title="请选择你要强化的部位:", goback=True, backmethod=ctrl.close) return ret
def handler_person_item_transfer(ctx): if not ui.blankline(): ui.echo() ui.echo( "%s把%s×%s交给了%s" % (ctx.subject.name, ui.rank(ctx.item), ctx.quantity, ctx.object.name)) ui.read()
def item_menu(persons, obj, tags=None, showmoney=False, moneystyle=0, show_comments=True, filter=None): smenu = [] for person in persons: for itm in person.items: show_state = 0 if filter is not None: show_state = filter(person, obj, itm, tags) if show_state == 2: continue suffix_list = [] if len(persons) > 1: suffix_list.append("持有人:%s" % ui.colored(person.name, attrs=["bold"])) if "Equip" in itm.tags: suffix_list.append("数量:1,耐久度:%s/%s" % (itm.durability_current, itm.durability)) else: suffix_list.append("数量:%s" % person.quantities[itm.tpl_id]) if showmoney and itm.tpl_id != "ITEM_MONEY": suffix_list.append("价值:%s" % ui.colored( itm.money if moneystyle == 0 else int(itm.money * 0.4), color="yellow", attrs=["bold"])) if itm in person.equipment: suffix_list.append(ui.colored("装备中", color="green")) suffix = "(%s)" % ",".join(suffix_list) if show_state == 1: mitem = ui.menuitem( ui.rank(itm) + ui.colored(suffix, color="grey", attrs=["bold"]), value=(itm, person), validator=lambda x: False) elif show_comments: comments = ui.item(itm) mitem = ui.menuitem(ui.rank(itm) + suffix, comments=comments, value=(itm, person)) else: mitem = ui.menuitem(ui.rank(itm) + suffix, value=(itm, person)) smenu.append(mitem) return smenu
def handler_person_item_acquire(ctx): if not ui.blankline(): ui.echo() if ctx.item is not None: ui.echo("%s获得了%s×%s" % (ctx.subject.name, ui.rank(ctx.item), ctx.quantity)) else: ui.echo("%s一无所获" % ctx.subject.name) ui.read()
def skill_menu(ctrl): smenu = [] skills = ctrl.skills for sk, errormsg in skills: comments = [ui.skill(sk)] for effe in sk.effects: comments.append(ui.effect(effe)) if errormsg is None: sk_str = "%s:%s" % (ui.rank(sk.belongs), ui.rank(sk)) smenu.append( ui.menuitem(sk_str, comments=comments, value=sk, goto=ctrl.select)) else: sk_str = "%s:%s(%s)" % (sk.belongs.name, sk.name, errormsg) smenu.append(ui.menuitem(sk_str, validator=lambda x: False)) return smenu
def handler_superskill_select_control(ctrl): skmenu = [] for sk in ctrl.superskills: comments = [Item.one("ITEM_%s" % sk.tpl_id[11:]).description] skmenu.append( ui.menuitem(ui.rank(sk), value=sk, comments=comments, goto=ctrl.select)) skmenu.append(ui.menuitem("离开", value='', goto=ctrl.select)) ui.menu(skmenu, title=ctrl.title)
def skill_equipped(p): ret = [] if p.studying is not None: ret.append("【当前修炼】%s:%s(进度:%s/%s)" % (ui.rank( p.studying.belongs), ui.rank(p.studying), p.exp, p.studying.exp)) else: ret.append(ui.colored("【当前修炼】无", color="grey", attrs=["bold"])) ret.append("") if p.running is not None: ret.append("【运行心法】%s" % ui.rank(p.running)) isk_str = ui.inner_skill(p.running, p) for isk in isk_str: ret.append(" %s" % isk) else: ret.append(ui.colored("【运行心法】无", color="grey", attrs=["bold"])) ret.append("") str_list = [ "一", "二", "三", "四", "五", "六", "七", "八", "九", ] asc_idx = 0 for sk in p.skills_equipped: if sk is None: ret.append( ui.colored("【技能%s】无" % str_list[asc_idx], color="grey", attrs=["bold"])) else: comments = [ui.skill(sk)] for effe in sk.effects: comments.append(ui.effect(effe)) ret.append("【技能%s】%s:%s" % (str_list[asc_idx], ui.rank(sk.belongs), ui.rank(sk))) for c in comments: ret.append(" %s" % c) asc_idx += 1 ret.append("") if p.skill_counter is not None: ret.append( "【辅助技能】%s:%s" % (ui.rank(p.skill_counter.belongs), ui.rank(p.skill_counter))) comments = [ui.skill(p.skill_counter)] for effe in p.skill_counter.effects: comments.append(ui.effect(effe)) for c in comments: ret.append(" %s" % c) else: ret.append(ui.colored("【辅助技能】无", color="grey", attrs=["bold"])) return ret
def skills(p): ret = [] ret.append("【运行心法】") ret.append("") if p.running is None: ret.append(" 无") else: ret.append(" " + ui.rank(p.running)) #for isk_str in ui.inner_skill(p.running, p): # ret.append(" %s" % isk_str) isk_str = ui.inner_skill(p.running, p)[0] ret.append(" %s" % isk_str) ret.append("") ret.append("【使用武学】") ret.append("") #str_list = ["一", "二", "三", "四", "五", "六", "七", "八", "九", ] for idx, sk in enumerate(p.skills): ret.append(" " + "%s:%s" % (ui.rank(sk.belongs), ui.rank(sk))) ret.append(" " + ui.skill(sk)) for effe in sk.effects: ret.append(" " + ui.effect(effe)) return ret
def handler_battle_item_scope(ac): map = ac.battle.map if ac.battle.current != ac.subject or not ac.battle.controllable(): ui.echo() ui.map(map, entities=battle_person_handler(ac.snapshot), coordinates=[{ "positions": ac.scope, "color": "yellow" }], show_trace=False) ui.echo() fstr = "%s使用了物品" % ac.subject.name ui.echo(fstr + ui.colored(ui.rank(ac.item, txt="【%s】" % ac.item.name))) ui.echo() ui.read("(回车继续)")
def recipe_menu(ctrl): str_list = [ "一", "二", "三", "四", "五", "六", "七", "八", "九", ] rmenu = [] for idx, ownerrecipe in enumerate(ctrl.recipes): owner, recipe = ownerrecipe enabled = recipe.check(ctrl.persons) if len(recipe.materials) == 0: comments = ["无"] else: comments = [",".join(["任意%s" % ui.tag(k) if isinstance(k, str) else ui.rank(k, grey=not enabled) + ui.colored("×%s" % v, color=None if enabled else "grey", attrs=None if enabled else ["bold"]) \ for k, v in recipe.materials])] showword = ("方案%s" % str_list[idx]) if ctrl.sub else recipe.name suffix = [] if enabled: if not ctrl.sub: suffix.append("持有人:%s" % owner.name) if owner not in ctrl.persons: suffix.append( "费用:%s" % ui.byellow(str(25 + recipe.tmpdict.get("money", 0)))) if len(suffix) > 0: showword += "(%s)" % ",".join(suffix) mitem = ui.menuitem(showword, value=(owner, recipe), comments=comments, goto=ctrl.select) else: mitem = ui.menuitem(showword + "(材料不足)", comments=comments, validator=lambda x: False) rmenu.append(mitem) return rmenu
def handler_person_equip_inlay_choose(ctx): imenu = [] for idx, inlay in enumerate(ctx.item.inlays): enabled = "filled" not in inlay if enabled: name_str = inlay["name"] comments = [ "接受材料:%s" % "、".join([ui.tag(acp) for acp in inlay["accept"]]) ] validator = lambda x: True else: name_str = inlay["name"] comments = ["已强化:%s" % ui.rank(inlay["filled"])] comments.extend([ ui.effect(effe, grey=True) for effe in inlay["filled"].effects ]) validator = lambda x: False imenu.append( ui.menuitem( name_str, value=idx, comments=comments, validator=validator, goto=lambda x: PersonItemChooseOrder( subject=ctx.subject, object=ctx.object, quantity=1, persons=ctx.subject.team.members, order=PersonEquipStrengthenOrder, orderarg={ "equip": ctx.item, "position": x }, filter=lambda a, b, itm: len(itm.tags & ctx.item.inlays[x][ "accept"]) != 0))) ret = ui.menu(imenu, title="请选择你要强化的部位:", goback=True) return ret
def recipe_menu(subject, persons, recipes, filter=None, sub=False): str_list = [ "一", "二", "三", "四", "五", "六", "七", "八", "九", ] rmenu = [] for idx, recipe in enumerate(recipes): if filter is not None and not filter(subject, recipe): continue enabled = recipe.check(persons) if len(recipe.materials) == 0: comments = ["无"] else: comments = [",".join(["任意%s" % ui.tag(k) if isinstance(k, str) else ui.rank(k, grey=not enabled) + ui.colored("×%s" % v, color=None if enabled else "grey", attrs=None if enabled else ["bold"]) \ for k, v in recipe.materials])] showword = ("方案%s" % str_list[idx]) if sub else recipe.name if enabled: if subject not in persons: showword += "(费用:%s)" % ui.colored( str(25 + recipe.tmpdict.get("money", 0)), color="yellow", attrs=["bold"]) rmenu.append(ui.menuitem(showword, value=recipe, comments=comments)) else: rmenu.append(ui.menuitem(showword + "(材料不足)", value=recipe, comments=comments, \ validator=lambda x: False)) return rmenu
def handler_person_skill_learn(ctx): ui.echo("%s已经习得了技能%s:%s,请给%s安排新的修炼内容。" % (ctx.subject.name, ui.rank(ctx.node.belongs), ui.rank(ctx.node))) ui.read()
def handler_person_equip_repair(ctx): ui.echo("%s耐久度已恢复!" % ui.rank(ctx.item)) ui.echo()
def handler_person_item_lost(ctx): if not ui.blankline(): ui.echo() ui.echo("%s失去了%s×%s" % (ctx.subject.name, ui.rank(ctx.item), ctx.quantity)) ui.read()
def handler_person_item_equip(ctx): if not ui.blankline(): ui.echo() ui.echo("%s装备了【%s】" % (ctx.subject.name, ui.rank(ctx.item))) ui.read()
def superskill(superskill, subject=None): layers, connections = to_layers(superskill) ui.echo() ui.echo("当前武学:%s" % ui.rank(superskill)) ui.echo() dires = set() for i in range(len(layers)): layer = layers[i] last = layers[i - 1] connection = connections[i - 1] #maxgap = max(3, len(last) + len(dires) + 2) maxgap = max(3, len(connection) + len(dires) + 2) epts = set() spts = [] for j in range(len(last)): bst = (GAP + WIDTH + 2) * j + WIDTH // 2 + 1 spts.append(bst) for bst in dires: spts.append(bst) dires.clear() if i != 0: for j_raw in range(-1, maxgap): tmpstr = [] tmpepts = set() if j_raw >= 0 and j_raw < len(connection): j = sorted(connection.keys())[j_raw] tmppts = set() bst = spts[j] tmppts.add(bst) for cy in connection[j]: ly, nd = cy if ly >= i + 1: nd = len(connection) if nd not in connections[i]: connections[i][nd] = [] connections[i][nd].append(cy) #ben = (GAP + WIDTH + 2) * nd + WIDTH // 2 + 1 - len(last) + 2 * j #ben = (GAP + WIDTH + 2) * nd + WIDTH // 2 + 1 - (2 * j // 2 if j % 2 == 0 else -2 * (j // 2 + 1)) if nd == j: ben = (GAP + WIDTH + 2) * nd + WIDTH // 2 + 1 elif j > nd: ben = (GAP + WIDTH + 2) * nd + WIDTH // 2 + 1 + 2 * ( (j - nd) // 2 + 1) else: ben = (GAP + WIDTH + 2) * nd + WIDTH // 2 + 1 - 2 * ( (nd - j) // 2 + 1) epts.add(ben) tmppts.add(ben) tmpepts.add(ben) if ly >= i + 1: dires.add(ben) horst, horen = min(tmppts), max(tmppts) tmpstr = [" "] * horst + [HOR] * (horen - horst + 1) for tmppt in tmppts: if tmppt == horst and tmppt == horen: tmpstr[tmppt] = VER elif tmppt == bst: if tmppt in tmpepts: if tmppt == horst: tmpstr[tmppt] = BTR elif tmppt == horen: tmpstr[tmppt] = BTL else: tmpstr[tmppt] = BTC else: if tmppt == horst: tmpstr[tmppt] = LB elif tmppt == horen: tmpstr[tmppt] = RB else: tmpstr[tmppt] = BTT else: if tmppt == horst: tmpstr[tmppt] = LT elif tmppt == horen: tmpstr[tmppt] = RT else: tmpstr[tmppt] = BTB # 分支后竖线 for ept in sorted(epts): if ept >= len(tmpstr): tmpstr += [" "] * (ept - ui.strwidth("".join(tmpstr))) + \ [VER if j_raw != maxgap - 1 or ept in dires else DLT] elif tmpstr[ept] == " ": tmpstr[ ept] = VER if j_raw != maxgap - 1 or ept in dires else DLT # 分支前竖线 for k in sorted(connection.keys()): if j_raw > k: continue vpt = spts[k] if vpt >= len(tmpstr): tmpstr += [" "] * (vpt - len(tmpstr)) + [VER] elif tmpstr[vpt] == " ": tmpstr[vpt] = VER ui.echo("".join(tmpstr)) tmpstr = [LT] + [HOR] * WIDTH + [ RT ] + ([" "] * GAP + [LT] + [HOR] * WIDTH + [RT]) * (len(layer) - 1) for ept in dires: if ept >= len(tmpstr): tmpstr += [" "] * (ept - len(tmpstr)) + [VER] elif tmpstr[ept] == " ": tmpstr[ept] = [VER] ui.echo("".join(tmpstr)) for j in range(HEIGHT): strlist = [] for lyt in layer: if j == 0: ctstr = "【%s】" % (lyt + 1) + superskill.nodes[lyt].name #elif j == 1: # ctstr = ui.nodecond(superskill.nodes[lyt]) elif j == HEIGHT - 1 and subject is not None: learn_st = superskill.learn_status(subject, lyt) if learn_st == 0: ctstr = ui.colored("(已习得)", color="yellow") elif learn_st == -1: ctstr = ui.colored("(条件不足)", color="red") elif subject.studying != superskill.nodes[lyt]: ctstr = ui.colored("(可学习)", color="green") else: ctstr = "经验:%s/%s" % (subject.exp, superskill.nodes[lyt].exp) else: ctstr = "" strlist.append(VER + grid(ctstr) + VER) strlist = (" " * GAP).join(strlist) tmpstr = [] strlen = ui.strwidth(strlist) for ept in dires: if ept >= strlen: tmpstr += [" "] * (ept - strlen) + [VER] elif tmpstr[ept] == " ": tmpstr[ept - strlen] = [VER] ui.echo(strlist + "".join(tmpstr)) strlist = (" " * GAP).join([LB + HOR * WIDTH + RB] * len(layer)) tmpstr = [] strlen = ui.strwidth(strlist) for ept in dires: if ept >= strlen: tmpstr += [" "] * (ept - strlen) + [VER] elif tmpstr[ept] == " ": tmpstr[ept - strlen] = [VER] ui.echo(strlist + "".join(tmpstr))