예제 #1
0
def cancel(quest, func):
    from data.getgui import gui
    gui.hook.onQuestCancel.fire(quest)
    gd = functions.get_gamedata()
    gd["quests"]["active"].remove(quest["id"])
    functions.save_gamedata(gd)
    func()
예제 #2
0
def register(data, override=False):
    from data.getgui import gui
    quests = get_quests()
    id = random.random() * 1000000
    id = hashlib.md5(str(id).encode('utf-8')).hexdigest()
    data["id"] = id
    if not "title" in data:
        data["title"] = "Quest"
    if not "description" in data:
        data["description"] = ""
    if not "sdescription" in data:
        data["sdescription"] = data["title"] + "\n" + data["description"]
    if not "tools" in data:
        data["tools"] = {}
    if not "rewards" in data:
        data["rewards"] = {}
    if not "requirements" in data:
        data["requirements"] = {}
    quests[id] = data
    gd = functions.get_gamedata()
    save = True
    if "quests" in gd:
        if "bind" in gd["quests"]:
            if gui.last_event[0] + "+" + gui.last_event[1] + "+" + data[
                    "title"] in gd["quests"]["bind"] and not override:
                save = False
    if save:
        gd["quests"] = quests
        if not "bind" in gd["quests"]:
            gd["quests"]["bind"] = {}
            gd["quests"]["active"] = []
        gd["quests"]["bind"][gui.last_event[0] + "+" + gui.last_event[1] +
                             "+" + data["title"]] = id
        functions.save_gamedata(gd)
        gui.hook.onQuestRegister.fire(data)
예제 #3
0
def acceptquest(func, quest):
    from data.getgui import gui
    gui.hook.onQuestAccept.fire(quest)
    event_functions.add_items(quest["tools"])
    gd = functions.get_gamedata()
    gd["quests"]["active"].append(quest["id"])
    functions.save_gamedata(gd)
    func()
예제 #4
0
def get(quest, func):
    from data.getgui import gui
    gui.hook.onQuestFinish.fire(quest)
    gd = functions.get_gamedata()
    gd["quests"]["active"].remove(quest["id"])
    functions.save_gamedata(gd)
    event_functions.add_items(quest["rewards"])
    for item, amount in quest["requirements"].items():
        event_functions.remove_items(item, amount)
    func()
예제 #5
0
def exit(event, id, func, gui):
    cons = get_cons()
    con = cons[id]
    if con["removeonexit"]:
        del cons[id]
        gd = functions.get_gamedata()
        gd["containers"] = cons
        functions.save_gamedata(gd)
    if not event == "none":
        exec("event." + func + "()")
    else:
        place_functions.hub(gui, False, True)
예제 #6
0
def travel(gui, place, vehicle, key=-1):
    gd = functions.get_gamedata()
    vehicle["key"] = key
    gd["travel"] = {
        "steps": vehicle["steps"],
        "destination": place,
        "vehicle": vehicle
    }
    if not key == -1:
        del gd["places"][gd["place"]]["garage"]["storage"][key]
    functions.save_gamedata(gd)
    leave(gui)
예제 #7
0
def leave(gui):
    gd = functions.get_gamedata()
    gui.hook.onPlaceLeave.fire(gd["place"])
    try:
        place = get_place(gd["place"])
        del gd["place"]
        functions.save_gamedata(gd)
        if place["options"]["events"]["exit"][0] != "None":
            gui.game(place["options"]["events"]["exit"][1],
                     place["options"]["events"]["exit"][0],
                     ["place-exit", name])
        else:
            gui.new_text()
    except:
        gui.new_text()
예제 #8
0
def register(data, override=False):
    from data.getgui import gui
    factions = get_factions()
    if not "value" in data:
        data["value"] = 0
    if not "value2" in data:
        data["value2"] = 0
    cancel = False
    if data["name"] in factions:
        if not override:
            cancel = True
    if not cancel:
        factions[data["name"]] = data
        gd = functions.get_gamedata()
        gd["factions"] = factions
        functions.save_gamedata(gd)
        gui.hook.onFactionRegister.fire(data)
예제 #9
0
def move(event, id, func, direction, item, amount, gui):
    conf = get_cons()[id]
    con = conf["inv"]
    inv = functions.get_inventory()
    if direction == 1:
        gui.hook.onContainerMoveToCon.fire(id, conf, inv, item, amount, event,
                                           func)
    if direction == -1:
        gui.hook.onContainerMoveToInv.fire(id, conf, inv, item, amount, event,
                                           func)
    mistake = False
    if direction == 1:
        if not event_functions.check_item(item) >= amount:
            mistake = True
    else:
        if not con[item] >= amount:
            mistake = True
    if not mistake:
        try:
            exec("print(\"" + str(con[item]) + "\")")
        except KeyError:
            con[item] = 0
        try:
            exec("print(\"" + str(inv[item]) + "\")")
        except KeyError:
            inv[item] = 0
        if direction == 1:
            famount = 0
            for item, amo in con.items():
                famount += amo
            if (conf["size"] - famount - amount) < 0:
                amount += (conf["size"] - famount - amount)
        #	print("Checked. famount:"+str(famount));
        con[item] += amount * direction
        inv[item] += amount * direction * -1
        gd = functions.get_gamedata()
        gd["inventory"] = inv
        gd["containers"][id]["inv"] = con
        functions.save_gamedata(gd)
        if direction == 1:
            inve(event, id, func, gui)
        else:
            open(event, id, func, gui)
예제 #10
0
def svalue(name, value, mode=False):
    if mode:
        valuestring = "value2"
    else:
        valuestring = "value"
    value2 = value
    value *= 1.5
    facs = get_factions()
    fac = facs[name]
    divide = fac[valuestring]
    if divide == 0:
        divide = 1
    value = value * (divide / 2)
    divide = divide / 8
    value = value / divide
    fac[valuestring] += value
    gd = functions.get_gamedata()
    facs[name] = fac
    gd["factions"] = facs
    from data.getgui import gui
    gui.hook.onFactionValue.fire(fac, value2, value, mode)
    functions.save_gamedata(gd)
예제 #11
0
def savetogps(gui, place, remkey=-1):
    gd = functions.get_gamedata()
    try:
        gpsmax = gd["gpsmax"]
    except:
        gpsmax = 3
        gd["gpsmax"] = 3
    gps = get_gps()
    if len(get_gps()) < gpsmax:
        gps.append(gd["place"])
        gd["gps"] = gps
        functions.save_gamedata(gd)
        print("success")
    else:
        if not remkey == -1:
            print("replaced")
            gps[remkey] = gd["place"]
            gd["gps"] = gps
            functions.save_gamedata(gd)
        else:
            print("full")
            enterveh(gui, place, True, -2)
    hub(gui)
예제 #12
0
def enterplace(gui, name, takeveh=False, endjourney=False, force=False):
    gui.hook.onPlaceEnter.fire(name)
    gd = functions.get_gamedata()
    place = get_place(name)
    check = True
    try:
        exec("print(\"" + str(gd["travel"]) + "\")")
    except KeyError:
        check = False
    stop = False
    if check:
        if gd["travel"]["destination"] == name and not endjourney and not force:
            stop = True
    if not stop:
        gd["place"] = name
        gd["place_hub_timer"] = 0
        if endjourney:
            veh = gd["travel"]["vehicle"]
            del gd["travel"]
        elif takeveh:
            veh = gd["travel"]["vehicle"]
        garageworks = True
        try:
            if veh["name"] == "selfdestruct":
                takeveh = False
        except UnboundLocalError:
            print("")
        if takeveh:
            garageworks = False
            if len(gd["places"][name]["garage"]
                   ["storage"]) >= gd["places"][name]["garage"]["size"]:
                functions.save_gamedata(gd)
                garageerror(gui, veh)
            else:
                gd["places"][name]["garage"]["storage"].append(veh)
                garageworks = True
        if garageworks:
            if place["system"]["first"] and place["options"]["events"][
                    "enterf"][0] != "None":
                gd["places"][name]["system"]["first"] = False
                functions.save_gamedata(gd)
                gui.game(place["options"]["events"]["enterf"][1],
                         place["options"]["events"]["enterf"][0],
                         ["place-enterf", name])
            else:
                functions.save_gamedata(gd)
                if place["options"]["events"]["entern"][0] != "None":
                    gui.game(place["options"]["events"]["entern"][1],
                             place["options"]["events"]["entern"][0],
                             ["place-entern", name])
                else:
                    hub(gui, False, True)
    else:
        gui.new_text()
예제 #13
0
파일: gui.py 프로젝트: IedSoftworks/FDoA
    def new_text(self, used_text="X"):
        self.hook.onEventEnd.fire(*self.last_event)
        check = True
        gd = functions.get_gamedata()
        #	print(gd);
        try:
            exec("print(\"" + gd["place"] + "\")")
        except:
            check = False
        check2 = True
        gd = functions.get_gamedata()
        #	print(gd);
        try:
            exec("print(\"" + str(gd["travel"]) + "\")")
        except:
            check2 = False
        if check:
            place_functions.hub(self)
        else:
            if not hasattr(self, "alreadyruns"):
                self.alreadyruns = True
            alreadyruns = False
            if self.alreadyruns:
                alreadyruns = True
                try:
                    self.hub_time += 1
                    if self.hub_time == 3:
                        self.hub_time = 0
                        self.game("hub", "system")
                except AttributeError:
                    setattr(self, "hub_time", 0)
                    pass
                self.alreadyruns = False
        #	print("HUB: "+str(self.hub_time))
            try:
                if check2 and not gd["travel"]["vehicle"]["events"] == "all":
                    place_functions.hub(self, True)
                elif check2:
                    if alreadyruns:
                        gd["travel"]["steps"] -= 1
                        functions.save_gamedata(gd)
                        if gd["travel"]["steps"] <= 0:
                            place_functions.hub(self, True)
            except KeyError:
                print("")
            else:
                alreadyused = functions.json_file_decode(
                    "user\\used_texts.json")[self.activemod]
                if used_text != "X":
                    boo_i = False
                    for i in alreadyused:
                        if alreadyused[i] == used_text:
                            boo_i = True
                    if boo_i:
                        game_folder1 = str(inspect.stack()[1][1])
                        game_folder1 = game_folder1.split("\\")
                        game_folder1 = game_folder1[len(game_folder1) - 2]
                        req = len(alreadyused[game_folder1])
                        alreadyused[game_folder1][req] = used_text + ".py"
                        functions.json_file_encode("user\\used_texts.json",
                                                   alreadyused)

                folders = [f.path for f in os.scandir("events") if f.is_dir()]
                folder = [x[7:] for x in folders]
                random1 = {}
                file_count = 0
                for f in folder:
                    if f != "__init__":
                        if f != "__pycache__":
                            for file in os.scandir("events\\" + f):
                                file = str(file)[11:-2]
                                file_module = file[:-3]

                                if file_module != "__init__":
                                    if file != "__pycache__":
                                        if f != "system":
                                            random1[str(file_count)] = {
                                                "folder": f,
                                                "file": file_module
                                            }
                                            file_count += 1
                print(random1)
                hg = random.random() * len(random1)
                self.game(random1[str(int(hg))]["file"],
                          random1[str(int(hg))]["folder"])
예제 #14
0
def hub(gui, travel=False, returned=False):
    gui.alreadyruns = True
    gui.clear_screen()
    back = gui.hintergrund()
    back.pack()
    gd = functions.get_gamedata()
    if travel:
        print(gd["travel"]["steps"])
        if gd["travel"]["steps"] <= 0:
            print("Destination Reached.")
            enterplace(gui, gd["travel"]["destination"], True, True)
        else:
            gd["travel"]["steps"] -= 1
            functions.save_gamedata(gd)
            print("Travel")
            event(gui, gd["travel"]["vehicle"]["events"])
    else:
        try:
            place = get_place(gd["place"])
        except KeyError:
            gui.game("hub", "system")
        try:
            exec("print(\"" + str(gd["place_hub_timer"]) + "\")")
        except:
            #	print(sys.exc_info());
            gd["place_hub_timer"] = 0
        print(gd["place_hub_timer"])
        if not returned:
            if not gd["place_hub_timer"] == 0:
                if not gd["place_hub_timer"] >= (place["options"]["hubtimer"] +
                                                 1):
                    gd["place_hub_timer"] += 1
                    functions.save_gamedata(gd)
                    print("Random")
                    event(gui, place["options"]["events"]["random"])
                else:
                    print(
                        str(place["options"]["hubtimer"] + 1) + "/" +
                        str(gd["place_hub_timer"]))
                    gd["place_hub_timer"] = 0
                    functions.save_gamedata(gd)
            gd["place_hub_timer"] += 1
        functions.save_gamedata(gd)
        Text = Canvas(back, bg="Gold2", highlightthickness=0)
        Text.place(x=functions.pro_size(10, 0), y=functions.pro_size(10, 1))
        Label(Text,
              text="Willkommen " + place["word"] + " " + gd["place"],
              font=gui_content.ch_fontsize(32),
              bg="Gold2").grid(row=1, columnspan=3, sticky=W)
        Button(Text,
               text="Garage",
               command=partial(garage, gui),
               font=gui_content.ch_fontsize("16"),
               width=functions.pro_size(1, 0)).grid(row=2, padx=5, pady=5)
        if not place["storage"]["disable"]:
            Button(Text,
                   text="Lager",
                   command=partial(storage, gui),
                   font=gui_content.ch_fontsize("16"),
                   width=functions.pro_size(1, 0)).grid(row=2,
                                                        column=1,
                                                        padx=5,
                                                        pady=5)
        else:
            Button(Text,
                   text="Lager",
                   state=DISABLED,
                   command=partial(storage, gui),
                   font=gui_content.ch_fontsize("16"),
                   width=functions.pro_size(1, 0)).grid(row=2,
                                                        column=1,
                                                        padx=5,
                                                        pady=5)
        if not gd["place"] in get_gps():
            Button(Text,
                   text="Ort Speichern",
                   command=partial(savetogps, gui, place),
                   font=gui_content.ch_fontsize("16"),
                   width=functions.pro_size(1, 0)).grid(row=2,
                                                        column=2,
                                                        padx=5,
                                                        pady=5)
        else:
            Button(Text,
                   text="Ort Gespeichert.",
                   command=partial(print, ""),
                   font=gui_content.ch_fontsize("16"),
                   width=functions.pro_size(1, 0),
                   bg="green").grid(row=2, column=2, padx=5, pady=5)
        if len(place["options"]["events"]["clickable"]) > 0:
            Label(Text,
                  text="Aktionen:",
                  font=gui_content.ch_fontsize(20),
                  bg="Gold2").grid(row=3, sticky=W, columnspan=3)
            key = 0
            for value in place["options"]["events"]["clickable"]:
                row = math.floor(key / 6) + 4
                column = (key % 6)
                if key < 61:
                    Button(Text,
                           text=value[2],
                           command=partial(clickable, gui, value),
                           font=gui_content.ch_fontsize("16"),
                           width=functions.pro_size(1, 0),
                           height=functions.pro_size(.05,
                                                     1)).grid(row=row,
                                                              column=column,
                                                              padx=5,
                                                              pady=5)
                elif key == 61:
                    Label(Text,
                          text="Maximum von 60 Aktionen überschritten.",
                          font=gui_content.ch_fontsize(20),
                          bg="Gold2",
                          fg="red").grid(row=14, sticky=W, columnspan=6)
                key += 1
        Label(Text,
              text=place["description"],
              font=gui_content.ch_fontsize(20),
              bg="Gold2").grid(row=15, sticky=W, columnspan=3)
        Button(Text,
               text=gd["place"] + " verlassen",
               command=partial(leave, gui),
               bg="red",
               font=gui_content.ch_fontsize("16"),
               width=functions.pro_size(1, 0)).grid(row=16, padx=5, pady=5)
        if len(place["options"]["events"]["random"]) > 0:
            Button(Text,
                   text="Weitergehen",
                   command=partial(event, gui,
                                   place["options"]["events"]["random"]),
                   bg="green",
                   font=gui_content.ch_fontsize("16"),
                   width=functions.pro_size(1, 0)).grid(row=16,
                                                        column=1,
                                                        padx=5,
                                                        pady=5)
        else:
            Button(Text,
                   text="Weitergehen",
                   state=DISABLED,
                   command=partial(event, gui),
                   bg="green",
                   font=gui_content.ch_fontsize("16"),
                   width=functions.pro_size(1, 0)).grid(row=16,
                                                        column=1,
                                                        padx=5,
                                                        pady=5)