示例#1
0
def talk(*args):
    inputlist, i = parse.checkArgs(args, "Talk to who about what?", "about",
                                   "to", "talk")
    valid = True

    if inputlist:
        charid = parse.removeDuplicates(
            find.idFromName(inputlist[:i], "people"))

        while len(charid) > 1:
            charid = ask.which(charid, "people")

        if len(charid) == 0:
            print("That person is not here.")
            valid = False
        elif valid:
            dialogid = parse.removeDuplicates(
                find.idFromName(inputlist[i + 1:], "topic", charid, False))

            while len(dialogid) > 1:
                dialogid = ask.which(dialogid, "topic", charid)

            if len(dialogid) == 0:
                print(
                    find.nameFromID(charid, "people")[0] +
                    " doesn't seem to know anything about that.")
                valid = False
            elif valid:
                print(get.dlg(dialogid[0]))
                action.talk(charid[0], dialogid[0])
示例#2
0
def which(idlist,listType="",charid=[]):
    """When a query returned more than one result and you need to ask which one to use. Returns a list with a single item.
        
        idlist    List: List of IDs.
        listType  String: Type of IDs. Valid values: item/people/location/topic
        charid    List: charid of character whose inventory/topic to search if listType is item or topic."""
    
    if g.debug:
        print("[DBG] ask.which:",idlist,listType,charid)
    
    valid = False
    
    names = find.nameFromID(idlist,listType)
    
    while not valid:
        if g.debug:
            print("[DBG] ask.which NAMES",names)
        
        if len(names) > 1 and len(set(names)) == 1:    # Two things listed, they have the same name -> same type, use the first one.
            if g.debug:
                print("[DBG] ask.which FOUND ONLY ONE UNIQUE IN:",names)
            
            plinput = idlist[:1]
            valid = True
        
        elif len(charid) == 0 and not valid:
            print("Did you mean "+parse.naturalList(names, "or")+"? (empty to cancel)")
            plinput = find.idFromName(parse.sanitize(str(input("> "))),listType)
            
            if g.debug:
                print("[DBG] ask.which PLINPUT:",plinput)
            
            if len(plinput) == 1 or len(plinput) == 0:
                valid = True
            else:
                names = find.nameFromID(plinput,listType)
        
        elif len(charid) > 0 and not valid:
                print("Did you mean "+parse.naturalList(names, "or")+"? (empty to cancel)")
                plinput = find.idFromName(parse.sanitize(str(input("> "))),listType,charid)

                if g.debug:
                    print("[DBG] ask.which PLINPUT:",plinput)
                
                if len(plinput) == 1 or len(plinput) == 0:
                    valid = True
                else:
                    names = find.nameFromID(plinput,listType)
        else:
            sysmsg.show("argerror")
    
    if g.debug:
        print("[DBG] ask.which RETURNS:",plinput)
    
    return plinput
示例#3
0
def take(*args):
    inputlist = parse.checkArgs(args, "Take what?", "", "take")

    if inputlist:
        charid = "player"
        itemid = parse.removeDuplicates(find.idFromName(inputlist, "item"))

        while len(itemid) > 1:
            itemid = ask.which(itemid, "item")

        if len(itemid) != 0 and itemid[0] == "altar":
            print("\"That is way too heavy to carry, let alone move.\"")

        elif itemid:
            slot = find.invSlotByItemID(None)

            if g.debug:
                print("[DBG] take TO SLOT:", slot)

            if slot != 0:
                db.cur.execute(
                    "update item set locid = \"INV\" where itemid = \"" +
                    itemid[0] + "\";")
                db.cur.execute("update inventory set item" + str(slot) +
                               " = \"" + itemid[0] + "\" where charid = \"" +
                               charid + "\";")
                print(find.nameFromID(itemid, "item")[0] + " taken.")
                action.take(itemid[0])
            else:
                print("Your inventory is full.")
        else:
            print(parse.liToStr(inputlist) + " is not here.")
示例#4
0
def shoot(*args):
    if "revolver" in find.listInvItemIDs() and "bullets" in find.listInvItemIDs():
        
        objectid = parse.checkArgs(args,"Shoot what?","","shoot")
    
        if objectid:   
            person = find.idFromName(objectid,"people")
                
            while len(person) > 1:
                print(person)
                person = ask.which(person,"people")
            
            if len(person) != 0 and person[0] in g.immortals:
                print("You shot "+find.nameFromID(person, "people")[0]+".")
                action.shoot(person[0])
            elif person:
                if g.debug:
                    print("[DBG] shoot KILL",person)
                
                db.cur.execute("update people set hp = 0 where charid = \""+person[0]+"\";")
                name = find.nameFromID(person, "people")
                print("You shot",name[0], "dead!")
                death.death(person)
                action.shoot(person[0])
                
            else:
                print("Stop shooting like a maniac.")
            
    elif "revolver" and not "bullets" in find.listInvItemIDs():
        print("You don't have any bullets.")
    elif "bullets" and not "revolver" in find.listInvItemIDs():
        print("You don't have your revolver.")
    else:
        print("You cannot shoot without a loaded revolver.")
示例#5
0
def give(*args):
    inputlist, i = parse.checkArgs(args, "Give what to who?", "to")
    valid = True

    if inputlist:
        itemid = parse.removeDuplicates(
            find.idFromName(inputlist[:i], "item", ["player"]))

        while len(itemid) > 1:
            itemid = ask.which(itemid, "item", ["player"])

        if len(itemid) == 0:
            print("You do not have that item.")
            valid = False
        elif valid:
            charid = parse.removeDuplicates(
                find.idFromName(inputlist[i + 1:], "people"))

            while len(charid) > 1:
                charid = ask.which(charid, "people")

            if len(charid) == 0:
                print("That person is not here.")
                valid = False
            elif valid:
                rightPerson = g.criticalItemPeople[g.criticalItem.index(
                    itemid[0])]

                if g.debug:
                    print("[DBG] give CRITICAL ITEM", itemid, charid,
                          rightPerson)

                if itemid[0] in g.criticalItem and charid[0] == rightPerson:
                    item.transfer(itemid, charid)
                    action.give(itemid[0], charid[0])
                elif itemid[0] == "necklace" and charid[0] == "spgorka":
                    item.transfer(itemid, charid)
                    action.give(itemid[0], charid[0])
                else:
                    print(get.text("dontgive"))
示例#6
0
def attack(*args):
    objectid = parse.checkArgs(args,"Who do you want to attack?","","attack")
    
    if objectid:
        person = find.idFromName(objectid,"people")
            
        while len(person) > 1:
            print(person)
            person = ask.which(person,"people")
        
        if person:
            db.cur.execute("update people set hp = hp-10 where charid = \""+person[0]+"\";")
            name = find.nameFromID(person,"people")
            print("You gave",name[0], "a black eye.")
            
        else:
            print("Stop waving your hands around pointlessly!")
示例#7
0
def greet(*args):
    inputlist = parse.checkArgs(args, "Greet who?", "", "greet")

    if inputlist:
        charid = find.idFromName(inputlist, "people")

        while len(charid) > 1:
            charid = ask.which(charid, "people")

        if charid:
            if len(charid) > 1:
                greet(ask.which(charid), "people")
            else:
                action.greet(charid[0])
                get.topics(charid)
        else:
            print("That person is not here.")
示例#8
0
def call(*args):
    if find.plLoc() in g.callLocs:
        inputlist = parse.checkArgs(args,"Call who?","","call")
    
        if inputlist:
            charid = parse.removeDuplicates(find.idFromName(inputlist,"people",[],False))
            
            while len(charid) > 1:
                charid = ask.which(charid,"people")
            
            if g.debug:
                print("[DBG] call CHARID:",charid)
            
            if charid:
                if charid[0] in g.callPeople:
                    print("Calling "+find.nameFromID(charid,"people")[0]+".")
                    action.call(charid[0])
                else:
                    print("You can't call "+find.nameFromID(charid,"people")[0]+".")
            else:
                print("You can't call that person.")
    else:
        print("There is no phone here.")
示例#9
0
def drop(*args):
    inputlist = parse.checkArgs(args, "Drop what?", "", "drop")

    if inputlist:
        charid = "player"
        itemid = parse.removeDuplicates(
            find.idFromName(inputlist, "item", ["player"]))

        while len(itemid) > 1:
            itemid = ask.which(itemid, "item", ["player"])

        if itemid:
            if len(itemid) != 0:
                slot = find.invSlotByItemID(itemid)
                loc = find.plLoc()
                db.cur.execute("update inventory set item" + str(slot) +
                               " = NULL where charid = \"" + charid + "\";")
                db.cur.execute("update item set locid = \"" + loc +
                               "\" where itemid = \"" + itemid[0] + "\";")
                print(find.nameFromID(itemid, "item")[0] + " dropped.")
            else:
                print("You do not have " + " ".join(inputlist) + ".")
        else:
            print("You do not have " + parse.liToStr(inputlist) + ".")
示例#10
0
def use(*args):
    two = True
    valid = True
    
    if len(args) == 0:
        inputlist = parse.checkArgs(args,"Use what?","","use")
    else:
        inputlist = args[0]
    
    if g.debug:
        print("[DBG] use INPUTLIST:",inputlist)
        
    try:
        i = inputlist.index("on")
        two = True
    except ValueError:
        try:
            i = inputlist.index("with")
            two = True
        except ValueError:
            two = False
    
    if g.debug and two:
        print("[DBG] use INDEX:",i)
    
    if not two:
        item1 = parse.removeDuplicates(find.idFromName(inputlist,"item",["player"]))
        
        while len(item1) > 1:
            item1 = ask.which(item1,"item",["player"])

        if len(item1) == 0:
            print("You have no such item.")
        else:
            action.use(item1[0])
    else:
        item1 = parse.removeDuplicates(find.idFromName(inputlist[:i],"item",["player"]))
        
        while len(item1) > 1:
            item1 = ask.which(item1,"item",["player"])
            
        if len(item1) == 0:
            print("You do not have that item.")
            valid = False
        
        if g.debug:
            print("[DBG] use ITEM1:",item1,valid)
        
        if valid:
            
            item2 = parse.removeDuplicates(find.idFromName(inputlist[i+1:],"item"))
            
            if not item2:
                item2 = parse.removeDuplicates(find.idFromName(inputlist[i+1:],"item",["player"]))
            
            if g.debug:
                print("[DBG] use ITEM2:",item2)
            
            while len(item2) > 1:
                item2 = ask.which(item2,"item")
            
            if len(item2) == 0:
                print("That item is not here.")
                valid = False
            elif valid:
                action.use(item1[0],item2[0])
示例#11
0
def travel(*args):
    inputlist = parse.checkArgs(args, "Travel where?", "", "to")

    if inputlist:
        charid = "player"
        toid = find.idFromName(inputlist, "location", [], True)

        while len(toid) > 1:
            toid = ask.which(toid, "location")

        if toid:
            if get.visCheck(toid[0]):
                if toid[0] in g.worldTravel and find.plLoc() in g.worldTravel:
                    if item.valTrans(
                            200, ["player"], [], " to travel to " +
                            find.nameFromID(toid, "location")[0]):
                        print("You pay the standard fare of 200.")
                        db.cur.execute(
                            "update people set val = val - 200 where charid = \"player\";"
                        )
                        print("Traveling to " +
                              find.nameFromID(toid, "location")[0] + ".")

                        if toid[0] == "buairpor" and g.firstBulgaria == "1" and g.Chapters == "1":
                            print(
                                "\n             ----    Chapter II: Tracking Zlatin Panayotov    ----"
                            )
                            db.cur.execute(
                                "update save set val = 0 where var = \"firstBulgaria\";"
                            )
                            g.update()

                        elif toid[0] == "taport" or toid[
                                0] == "taairpor" and g.firstTanz == "1" and g.Chapters == "1":
                            print(
                                "\n                 ----    Chapter III: Retrieving Beast    ----"
                            )
                            db.cur.execute(
                                "update save set val = 0 where var = \"firstTanz\";"
                            )
                            g.update()

                        elif toid[
                                0] == "inairpor" and g.backToIndia == "1" and g.Chapters == "1":
                            print(
                                "\n                   ----    Chapter IV: The Fjǫrsteinn    ----"
                            )
                            db.cur.execute(
                                "update save set val = 0 where var = \"backToIndia\";"
                            )
                            g.update()

                        elif toid[
                                0] == "grport" and g.grFisherCrater == "0" and g.Chapters == "1":
                            print(
                                "\n                 ----    Chapter V: The Fabled Guðhjǫrr    ----\n"
                            )
                            # Variable update handled in action.

                        elif toid[
                                0] == "peport" and g.firstPeru == "1" and g.Chapters == "1":
                            print(
                                "\n                  ----    Chapter VIII: The Guðhjǫrr    ----"
                            )
                            db.cur.execute(
                                "update save set val = 0 where var = \"firstPeru\";"
                            )
                            g.update()

                        action.travel(find.plLoc(), toid[0])
                        db.cur.execute("update people set locid = \"" +
                                       toid[0] + "\" where charid = \"" +
                                       charid + "\";")
                        cmd.look()

                elif toid[0] == "netoti" or toid[0] == "inbussta":  # Bus fare.
                    if item.valTrans(20, ["player"], ["inbusdri"],
                                     " to take the bus"):
                        print("You pay the bus fare of 20 money.")
                        db.cur.execute(
                            "update people set val = val - 20 where charid = \"player\";"
                        )
                        action.travel(find.plLoc(), toid[0])
                        db.cur.execute("update people set locid = \"" +
                                       toid[0] + "\" where charid = \"" +
                                       charid + "\";")
                        cmd.look()

                elif toid[0] == "pecave2" or toid[
                        0] == "pecave":  # INTO THE PIT WITH YOU!
                    if "flalight" in find.listInvItemIDs(
                    ):  # Flashlight check AKA. FU PL
                        dundundun = True
                    else:
                        dundundun = False

                    if g.debug:
                        print("[DBG] travel FLASHLIGHT CHECK:", dundundun,
                              toid[0])

                    if dundundun:  # Why would you pick it up?
                        action.setVis("pecave2", 0)
                        action.setVis("pecave", 1)
                        print("Traveling to the " +
                              find.nameFromID(["pecave"], "location")[0] + ".")
                        action.travel(find.plLoc(), "pecave")
                        db.cur.execute(
                            "update people set locid = \"pecave\" where charid = \""
                            + charid + "\";")
                        cmd.look()
                    else:
                        action.setVis("pecave", 0)
                        action.setVis("pecave2", 1)
                        print("Traveling to the " +
                              find.nameFromID(["pecave2"], "location")[0] +
                              ".")
                        action.travel(find.plLoc(), "pecave2")
                        db.cur.execute(
                            "update people set locid = \"pecave2\" where charid = \""
                            + charid + "\";")
                        cmd.look()
                else:
                    print("Traveling to " +
                          find.nameFromID(toid, "location")[0] + ".")
                    action.travel(find.plLoc(), toid[0])
                    db.cur.execute("update people set locid = \"" + toid[0] +
                                   "\" where charid = \"" + charid + "\";")
                    cmd.look()
            else:
                print("You can't travel there.")
        else:
            print("You can't travel there.")
示例#12
0
def examine(*args):
    place = False

    if len(args) == 0:
        place = True
    elif len(args) != 0 and args[0][0] == "here" or args[0][0] == "area":
        place = True
    else:
        inputlist = args[0]

    if not place:
        invitem = find.idFromName(inputlist, "item", ["player"])
        if g.debug:
            print("[DBG] examine ITEM INV:", invitem)

        #if not invitem:
        locitem = find.idFromName(inputlist, "item")
        if g.debug:
            print("[DBG] examine ITEM LOCAL:", locitem)

        person = find.idFromName(inputlist, "people")
        if g.debug:
            print("[DBG] examine PERSON:", person)

        while len(invitem) > 1:
            invitem = ask.which(invitem, "item", ["player"])
            if g.debug:
                print("[DBG] examine ITEM INV LOOP:", invitem)

        while len(locitem) > 1:
            locitem = ask.which(locitem, "item")
            if g.debug:
                print("[DBG] examine ITEM LOCAL LOOP:", locitem)

        while len(person) > 1:
            person = ask.which(person, "people")
            if g.debug:
                print("[DBG] examine PERSON LOOP:", person)

        if g.debug:
            print("[DBG] examine FOUND:", locitem, invitem, person)

        if invitem:
            db.cur.execute(
                "select dsc from itemtype, item where item.itemid = \"" +
                invitem[0] + "\" and item.typeid = itemtype.typeid;")
            result = parse.tupleListToList(db.cur.fetchall())
            if result:
                print(result[0])

        elif locitem:
            db.cur.execute(
                "select dsc from itemtype, item where item.itemid = \"" +
                locitem[0] + "\" and item.typeid = itemtype.typeid;")
            result = parse.tupleListToList(db.cur.fetchall())
            if result:
                print(result[0])

        elif person:
            db.cur.execute("select dsc from people where people.charid = \"" +
                           person[0] + "\";")
            result = parse.tupleListToList(db.cur.fetchall())
            if result:
                print(result[0])
            get.topics(person)
        else:
            print("You cannot examine that.")
    elif place:
        action.examine(find.plLoc())
    else:
        print("ERROR")
示例#13
0
def rent(*args):
    if find.plLoc() in g.rentlocs:
        inputlist = parse.checkArgs(args, "Rent what?", "", "rent")

        if g.debug:
            print("[DBG] rent INPUTLIST:", inputlist)

        if inputlist:
            count = 0
            seller = [g.rentppl[g.rentlocs.index(find.plLoc())]]

            if g.debug:
                print("[DBG] rent ARGS:", seller, find.plLoc())

            if find.plLoc() == "grinn1":
                if inputlist[0] == "room":
                    if action.checkTopic("kolrule") and item.valTrans(
                            100, ["player"], ["grinnkee"], " to rent a room"
                    ):  # Player has spoken to Kolbiorn and has enough money.
                        db.cur.execute(
                            "update people set val = val - 100 where charid = \"player\";"
                        )
                        db.cur.execute(
                            "update people set val = val + 100 where charid = \""
                            + seller[0] + "\";")

                        action.rent("", seller[0], True)
                        count += 1
                else:
                    if count < 1:  # Not an elegant solution but it works. (When found many items.)
                        print("There is no", parse.liToStr(inputlist),
                              "to rent here.")
                    count += 1

            elif seller[0] == "grportma":
                if action.getVis("grbay"):  # Player knows about ship.
                    itemid = parse.removeDuplicates(
                        find.idFromName(inputlist, "item", seller, False))

                    if g.debug:
                        print("[DBG] rent SELLER HAS:", itemid)

                    while len(itemid) > 1:
                        itemid = ask.which(itemid, "item", seller)

                    if g.debug:
                        print("[DBG] rent BUYING:", itemid)

                    if len(itemid) == 1:
                        fromSlot = find.invSlotByItemID(itemid, seller)

                        if fromSlot != 0:  # Found item in inventory.
                            val = find.listValueByID(itemid, "item")[0]
                            string = " to rent " + find.nameFromID(
                                itemid, "item")[0]

                            if item.valTrans(
                                    val, ["player"], seller,
                                    string):  # Player has enough money.
                                item.transfer(itemid, ["player"], seller,
                                              "rent", val)
                                action.rent(itemid[0], seller[0])
                                count += 1
                else:
                    if count < 1:  # Not an elegant solution but it works. (When found many items.)
                        print(
                            "\"What would I need that for?\" you think to yourself."
                        )
                    count += 1

                    if g.debug:
                        print("[DBG] rent BAY VIS:", action.getVis("grbay"))
        else:
            if count < 1:  # Not an elegant solution but it works. (When found many items.)
                print("There is no", parse.liToStr(inputlist), "to rent here.")
            count += 1
    else:
        print("There's nothing to rent here.")
示例#14
0
def checkArgs(args,ask,require="",delete="",cmd=""):
    """Check whether player input arguments for a command. If not, ask for input and return a word list."""
    
    if g.debug:
        print("[DBG] checkArgs:",args,ask,require,delete,cmd)
    
    valid = False
    i = None
    
    if len(args) > 0 and len(delete) > 0:
        if args[0][0] == delete:
            del args[0][0]          # Delete the first word like "to" in "talk to" or "travel to".
    
    if len(args) > 0 and len(require) == 0:
        plinput = args[0]
        valid = True
        
    elif len(args) > 0 and len(require) > 0:
        plinput = args[0]
        
        if require in plinput:
            i = plinput.index(require)
            valid = True
        else:
            print("You need to use the word \""+require+"\" in your input.")
            valid = False
           
            if cmd == "talk":
                person = removeDuplicates(find.idFromName(plinput,"people"))
                
                if len(person) == 1:
                    get.topics(person)
        
    while not valid:                        # Player didn't input anything!
        print(ask+" (empty to cancel)")     # I.e. "Take what?"
        plinput = sanitize(str(input("> ")))
        
        if g.debug:
            print("[DBG] checkArgs PLINPUT:",plinput)
        
        if len(plinput) > 0 and len(delete) > 0:
            if plinput[0] == delete:
                del plinput[0]          # Delete the first word like "to" in "talk to" or "travel to".
        
        if len(plinput) > 0:                # Player finally input some arguments.
            if len(require) == 0:
                valid = True
            else:
                if require in plinput:
                    i = plinput.index(require)
                    valid = True
                else:
                    print("You need to use the word \""+require+"\" in your input.")
                    valid = False
        else:
            valid = True
    
    if g.debug:
        print("[DBG] checkArgs RETURNS:",plinput)
    
    if len(require) == 0:
        return plinput
    else:
        return plinput, i