Example #1
0
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")
Example #2
0
def create_role(args):
    #xing = ui.read("请输入你的姓氏:",
    #               handler=lambda x: x if len(x.strip()) > 0 else None)
    #ui.echo()
    #ming = ui.read("请输入你的名字:",
    #               handler=lambda x: x if len(x.strip()) > 0 else None)
    #ui.echo()
    #sex = ui.menu(sex_menu, title="请选择你的性别:")
    lead = Person.one("PERSON_PLAYER")
    while True:
        #lead = person.create_player(xing, ming, sex)
        lead.random()
        ui.echo()
        ui.echo(ui.colored("你的初始特质如下", attrs=["bold"]))
        ui.echo()
        ui.echo(person_info(lead))
        ui.echo()
        ui.echo(ui.colored("属性介绍", attrs=["bold"]))
        ui.echo()
        ui.echo(attr_info())
        ui.echo()
        if ui.sure(msg.ACCEPT):
            break
    ui.echo()
    runtime.MODULE.scripts.start()
Example #3
0
def start(loadfile=None):

    print("引擎初始化中……\n")
    console.init()
    print("游戏数据载入中……\n")
    entity.init()
    print("世界构建中……\n")
    context.init()

    m = Map.one("MAP_SUZHOUCHENG")
    player = Person.one("PERSON_PLAYER")

    team_player = Team()
    team_player.include(player)
    team_player.leader = player
    team_player.scenario = m

    context.map = m
    context.PLAYER = player
    context.teams[team_player.id] = team_player

    m.locate(team_player, (18, 27))

    m.window_center(m.location(team_player))

    if loadfile is not None:
        print("存档文件加载中……\n")
        saveload.load(loadfile)
    engine.init()
    engine.start()
Example #4
0
 def input(self, person_loc):
     if person_loc is not None:
         ptpl, loclist = person_loc
         person = Person.one(ptpl)
         if person.team is None:
             person.team = Team()
             person.team.include(person)
         ent = person.team
         for loc in loclist:
             old_ent = self.map.loc_entity.get(loc, None)
             if old_ent is not None:
                 old_ent.include(person)
             else:
                 self.map.loc_entity[loc] = ent
                 self.map.entity_loc[ent.id] = loc
     self.close()
Example #5
0
sys.path.append(os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/../../"))

from proj import data

from proj.runtime import context

from proj import console

from proj import engine
from proj.engine import script

from proj.entity import Person
from proj.entity import Map

console.init()


if __name__ == "__main__":
    player = Person.one("PERSON_PLAYER")
    map = Map.one("MAP_SUZHOUCHENG")
    time_1 = time.time()
    script.run(data.scripts.SCRIPT_WANPENGFEI_1, timeflow=1, 
               subject=Person.one("PERSON_PLAYER"), 
               object=Person.one("PERSON_WAN_PENGFEI"))
    #script.run2(data.scripts.SCRIPT_WANPENGFEI_TEST, timeflow=1,
    #            subject=player,
    #            object=Person.one("PERSON_WAN_PENGFEI"))
    time_2 = time.time()
    print(time_2 - time_1)
    engine.start()
Example #6
0
 def showperson(self, person):
     person = Person.one("PERSON_" + tag[8:].upper())
     self.persons = [person]
     self.launch()
Example #7
0
from proj.entity import Team
from proj.entity import Status

from proj.builtin.actions import BattleStartAction

from proj import console
from proj.console import ui

from proj import engine

from proj.runtime import context

console.init()

if __name__ == "__main__":
    p_lx = Person.one("PERSON_PLAYER")
    p_wpf = Person.one("PERSON_WAN_PENGFEI")

    # 百兵堂
    p_sty = Person.one("PERSON_SONG_TIANYONG")
    p_xh = Person.one("PERSON_XIE_HUI")
    p_jl = Person.one("PERSON_JU_LIU")

    # 长生坛
    p_zsj = Person.one("PERSON_ZHAO_SHENJI")

    # 东厂
    p_tw = Person.one("PERSON_TIAN_WEI")

    # 华山派
    p_yl = Person.one("PERSON_YANG_LEI")
Example #8
0
 def showpath(self, tag):
     person = Person.one("PERSON_%s" % tag[6:].upper())
     if person.team.id not in self.scenario.entity_loc:
         return
     context.guide_dest = person.team
     self.launch()
Example #9
0
    ui.echo()
    ui.echo("【当前状态】")
    for sts in p.status:
        if sts.name is not None:
            ui.echo(sts.name)
    ui.echo()
    ui.echo("【主运心法】")
    ui.echo()
    ui.echo("【习得武学】")
    ui.echo()
    for sk in p.skills:
        ui.echo("  %s:%s" % (sk.belongs.name, sk.name))


if __name__ == "__main__":
    pa = Person.one("PERSON_ZHAO_SHENJI")
    pb = Person.one("PERSON_TIAN_WEI")
    #profile(pb)

    ui.echo()
    ui.echo(" " + ui.colored(" Ω ", attrs=["underline"]) + " " + "   " +
            ui.colored("  ^  ", attrs=["underline"]))
    ui.echo(" " + "├_┤" + " " + "   " + "║" + "║║║" + "║")
    ui.echo("q" + ui.colored("¯V¯", attrs=["underline"]) + "p" + "   " + "q" +
            ui.colored("¯Y¯", attrs=["underline"]) + "p")
    ui.echo(" U U " + "   " + " U U ")

    ui.echo()
    ui.echo(" " + ui.colored("-Π-", attrs=["underline"]) + " " + "   " + " " +
            ui.colored("\\V/", attrs=["underline"]) + " ")
    ui.echo(" " + "├_┤" + " " + "   " + "/" + "├_┤" + "\\")
Example #10
0
                        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))


if __name__ == "__main__":
    superskill(Superskill.one("SUPERSKILL_HUANGLUKUZHUJIAN"),
               Person.one("PERSON_GENG_ZHUQIAO"))
Example #11
0
def backmenu():
    bm = BACK_MENU.pop()
    bm[0].render(*bm[1])
    return bm[0].done()


def popmenu():
    BACK_MENU.pop()


def cleanmenu():
    BACK_MENU = []


class MenuGroup(Interactive):
    pass


if __name__ == "__main__":
    from proj.entity import Person

    p1 = Person.one("PERSON_SONG_TIANYONG")
    p2 = Person.one("PERSON_XIE_HUI")
    p3 = Person.one("PERSON_ZHAO_SHENJI")
    pmenu = [
        menuitem(p1.name, value=p1),
        menuitem(p2.name, value=p2),
        menuitem(p3.name, value=p3)
    ]
    ret = menu(pmenu, multiple=True, multiple_range=[2, 2])
Example #12
0
        MSG(style=MSG.ControlTest).control = self
        print("LaunchedC")

    @Control.listener
    def hook(self):
        print("HookC")
        self.close()
        print("CloseC")


console.init()
engine.init()


if __name__ == "__main__":
    p_player = Person.one("PERSON_PLAYER")
    p_sty = Person.one("PERSON_SONG_TIANYONG")
    p_dtj = Person.one("PERSON_DING_TIEJIANG_SUZHOU")
    m_world = Map.one("MAP_SUZHOUCHENG")
    m_world.locate(p_player.team, (12, 37))
    p_player.team.include(p_sty)
    p_player.team.scenario = m_world
    context.PLAYER = p_player
    
    control = TradeControl(subject=p_player, object=p_dtj)
    #control = TestControlA() 
    #control = SkillControl(subject=p_player)
    #control = EquipmentControl(subject=p_player)
    #control = PipeControl()
    #control.pipe(SkillSelectControl(subject=p_player, type=0), keys=["skill"])\
    #       .pipe(ItemSelectControl(subject=p_player, object=p_player, quantity=1), keys=["item"])
Example #13
0
    # ea * pa.hp_rate / (ea * pa.hp_rate + eb * pb.hp_rate), eb * pb.hp_rate / (ea * pa.hp_rate + eb * pb.hp_rate)
    # ""

    #p = Person()
    #print("灵动\t沉静\t刚猛\t柔易\t颖悟\t朴拙\t命中\t闪避\t反击\t破绽\t破绽伤害\t回复\t医治加成\t攻击加成\t防御加成\tHP加成\t移动力\t时序速度\t经验获得\n")
    #for i in range(-50, 51, 5):
    #    p.gangrou = 0
    #    p.dongjing = i
    #    p.zhipu = 0
    #    print("%s%%\t%s%%\t%s%%\t%s%%\t%s%%\t%s%%\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % \
    #          (50 + p.dongjing, 50 - p.dongjing, 50 + p.gangrou, 50 - p.gangrou, 50 + p.zhipu, 50 - p.zhipu,
    #           p.hit_rate, p.dodge_rate, p.counter_rate, p.critical_rate, p.critical_damage,
    #           p.hp_recover_rate, p.rescue_rate, p.attack_rate, p.defense_rate, p.hp_rate, p.motion, p.speed, p.study_rate))
    entity.init()
    context.init()

    p1 = Person.one("PERSON_ZHANG_YINSONG")
    p2 = Person.one("PERSON_JUE_CHENG")
    #rel1 = context.relationship("person", p1, p2)
    #rel2 = context.relationship("person", p2, p1)
    #print(rel1, rel2)
    print(p1.dodge_rate, p2.dodge_rate)
    print(p1.attack, p2.defense)
    p1.abc = HyperAttr(5,
                       delta=0.5,
                       factor=1.2,
                       type=int,
                       fval=lambda self: self.base + self.delta)
    print(p1.abc())
    print(getattr(p1.__class__, "dodge_rate"))
Example #14
0
# -- coding: utf-8 --

import os
import sys

sys.path.append(
    os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/../../"))

from proj.entity import Map
from proj.entity import Person

if __name__ == "__main__":
    map = Map.one("MAP_TEST_ASTAR")
    person = Person.one("PERSON_PLAYER")
    for steps in [-1, 1, 2, 3, 4]:
        #startpt = (4, 2)
        startpt = (0, 2)
        endpt = (6, 2)
        last = None
        map.pathblocked = set()
        print("Steps: %s, StartPos: %s, Destination: %s" %
              (steps, startpt, endpt))
        while startpt != endpt:
            rst = map.connect_dynamic(startpt,
                                      endpt,
                                      person,
                                      last=last,
                                      steps=steps)
            print(rst)
            startpt = rst[0]
            last = rst[1]
Example #15
0
def load_strdict():
    for p in dir(data.person):
        if not p.startswith("PERSON"):
            continue
        pen = Person.one(p)
        strdict["%s_NAME" % pen.tpl_id] = pen.name