예제 #1
0
 def loadvalues(self, filename):
     '''load values from file'''
     if os.path.isfile(filename):
         self.gf = open(filename, "rb")
         #Gold
         self.gf.seek(self.gf_gold_addr)
         self.gf_gold = struct.unpack('I', self.gf.read(4))[0]
         #Resources
         self.gf.seek(self.gf_iron_addr)
         self.gf_iron = struct.unpack('H', self.gf.read(2))[0]
         self.gf.seek(self.gf_stone_addr)
         self.gf_stone = struct.unpack('H', self.gf.read(2))[0]
         self.gf.seek(self.gf_wood_addr)
         self.gf_wood = struct.unpack('H', self.gf.read(2))[0]
         #Weapons
         self.gf.seek(self.gf_armor_addr)
         self.gf_armor = struct.unpack('H', self.gf.read(2))[0]
         self.gf.seek(self.gf_bows_addr)
         self.gf_bows = struct.unpack('H', self.gf.read(2))[0]
         self.gf.seek(self.gf_xbows_addr)
         self.gf_xbows = struct.unpack('H', self.gf.read(2))[0]
         self.gf.seek(self.gf_swords_addr)
         self.gf_swords = struct.unpack('H', self.gf.read(2))[0]
         self.gf.close()
     else:
         be.cprint("red", "ERROR: Cannot open game file!")
         sys.exit(1)
예제 #2
0
 def savevalues(self, filename):
     '''save values from file'''
     if os.path.isfile(filename):
         self.gf = open(filename, 'rb+')
         #Gold
         self.gf.seek(self.gf_gold_addr)
         self.gf.write(struct.pack('I', self.gf_gold))
         #Resources
         self.gf.seek(self.gf_iron_addr)
         self.gf.write(struct.pack('H', self.gf_iron))
         self.gf.seek(self.gf_stone_addr)
         self.gf.write(struct.pack('H', self.gf_stone))
         self.gf.seek(self.gf_wood_addr)
         self.gf.write(struct.pack('H', self.gf_wood))
         #Weapons
         self.gf.seek(self.gf_armor_addr)
         self.gf.write(struct.pack('H', self.gf_armor))
         self.gf.seek(self.gf_bows_addr)
         self.gf.write(struct.pack('H', self.gf_bows))
         self.gf.seek(self.gf_xbows_addr)
         self.gf.write(struct.pack('H', self.gf_xbows))
         self.gf.seek(self.gf_swords_addr)
         self.gf.write(struct.pack('H', self.gf_swords))
         self.gf.close()
     else:
         be.cprint("red", "ERROR: Cannot open game file!")
         sys.exit(1)
예제 #3
0
파일: rdp.py 프로젝트: nigel-heaney/Python
def usage():
    be.cprint("white", "Wallix RDP launcher\n")
    be.cprint("White", "-------------------\n\n")
    be.reset_colour
    print " -h | --help                      Show this help"
    print " -l | --list <search1> <search2>  List entries in the DB which match search criteria"
    print " <server name>                    Connect to this server"
예제 #4
0
 def usage(self):
     be.cprint("green", "\nLords of the Realm II - Game File Editor\n")
     be.cprint("grey", "----------------------------------------\n\n")
     be.reset_colour()
     print " -h | --help             Show this help"
     print " -l | --list <file>          Display current values of game file"
     print " -e | --edit <file>          Edit current values of game file"
     print " -s | --set <file>           Update game file with defaults"
예제 #5
0
 def usage(self):
     '''Usage screen'''
     be.cprint("green",
               "\nLords of the Realm II - County Game File Editor\n")
     be.cprint("grey",
               "-----------------------------------------------\n\n")
     be.reset_colour()
     print " -h | --help                 Show this help"
     print " -f | --file <file>          Display current values of game file"
예제 #6
0
 def listfile(self, filename):
     #validate file exists
     self.loadvalues(filename)
     be.cprint("green", "My Lord, the treasury reports the following:\n\n")
     be.reset_colour()
     print "     Gold: ",
     be.set_colour("yellow")
     print "{0:,}".format(self.gf_gold)
     be.reset_colour()
     print "     Iron: ",
     be.set_colour("brown")
     print "{0:,}".format(self.gf_iron)
     be.reset_colour()
     print "    Stone: ",
     be.set_colour("grey")
     print "{0:,}".format(self.gf_stone)
     be.reset_colour()
     print "     Wood: ",
     be.set_colour("green")
     print "{0:,}".format(self.gf_wood)
     be.reset_colour()
     print "    Armor: ",
     be.set_colour("red")
     print "{0:,}".format(self.gf_armor)
     be.reset_colour()
     print "     Bows: ",
     be.set_colour("red")
     print "{0:,}".format(self.gf_bows)
     be.reset_colour()
     print "Crossbows: ",
     be.set_colour("red")
     print "{0:,}".format(self.gf_xbows)
     be.reset_colour()
     print "   Swords: ",
     be.set_colour("red")
     print "{0:,}".format(self.gf_swords)
     be.reset_colour()
예제 #7
0
파일: rdp.py 프로젝트: nigel-heaney/Python
def main():
    db = loaddb()
    opts, args = getopt.getopt(sys.argv[1:], "hl", ["help", "list"])
    if debug: print "Options:", opts
    if debug: print "Args:", args
    for o, a in opts:
        if debug: print "O:", o
        if o in ("-h", "--help"):
            usage()
            print "help"
            sys.exit()
        elif o in ("-l", "--list"):
            if len(args) < 2: args.append('')
            if len(args) < 3: args.append('')
            searchdb(db, args[0].lower(), args[1].lower())
            sys.exit()
    #connect to argument as arg2 if specified
    if debug: print "num args:", len(args)
    if len(args) < 1:
        be.cprint("red", "Error: must specify server to connect to.\n\n")
        usage()
        sys.exit()
    if len(args) < 2: args.append('')
    launch(db, args[0].lower(), args[1])
예제 #8
0
파일: rdp.py 프로젝트: nigel-heaney/Python
def searchdb(db, findstr, findstr2=''):
    '''search db for matching entries and display them'''
    be.cprint(
        "white",
        "{0:^15s} | {1:^10s} | {2:^8s} | {3:^10s} | {5:^30s} | {6:^14s}|\n".
        format("Server", "Customer", "Env", "Type", "User",
               "Connection String", "NAT", "Description"))
    be.cprint(
        "white",
        "{0:<15s}-|-{1:<10s}-|-{2:<8s}-|-{3:<10s}-|-{5:<30s}-|-{6:<14s}|\n".
        format("-" * 15, "-" * 10, "-" * 8, "-" * 10, "-", "-" * 30, "-" * 14,
               "-" * 30))
    for i in db:
        #convert record to long string and look for str matches
        recstr = ""
        for r in i.split('|'):
            recstr += r.lower() + "|"
        found = False
        if re.search(findstr, recstr):
            found = True
            #look for second if exists
            if not recstr == '':
                if not re.search(findstr2, recstr): found = False
        if found:
            server, cust, custenv, stype, user, connstr, wabserver, wssnat, desc = i.split(
                '|')
            connstr = re.sub("^.*_U_@", "", connstr)
            c = "grey"
            if custenv == "TEST": c = "green"
            if custenv == "PROD": c = "cyan"
            if custenv == "DR": c = "red"
            be.cprint(
                c,
                "{0:<15s} | {1:<10s} | {2:<8s} | {3:<10s} | {5:<30s} | {6:<14s}|\n"
                .format(server.rstrip(), cust.rstrip(), custenv.rstrip(),
                        stype.rstrip(), user.rstrip(),
                        connstr.rstrip()[:30], wssnat.rstrip(),
                        desc.rstrip()[:30]))
            #be.cprint(c, "{0:<15s} | {1:<10s} | {2:<8s} | {3:<10s} | {4:<10s} | {5:<30s} | {6:<14s} | {7:<30s}|\n".format(server.rstrip(), cust.rstrip(),custenv.rstrip(),stype.rstrip(),user.rstrip(),connstr.rstrip()[:30],wssnat.rstrip(),desc.rstrip()[:30]))
            be.reset_colour()
예제 #9
0
    def editfile(self, filename):
        self.loadvalues(filename)
        be.cprint("green", "My Lord, Please supply your desired values:\n\n")
        be.reset_colour()
        #Gold
        print "{0:11}{1:10}({2:,})".format("     Gold: ", " ", self.gf_gold),
        print "\r     Gold: ".format(self.gf_gold),
        be.set_colour("yellow")
        self.gf_gold = int(raw_input())
        be.reset_colour()

        #Resources
        print "{0:11}{1:10}({2:,}/65535)".format("     Iron: ", " ",
                                                 self.gf_iron),
        print "\r     Iron: ".format(self.gf_iron),
        be.set_colour("brown")
        self.gf_iron = int(raw_input(''))
        be.reset_colour()

        print "{0:11}{1:10}({2:,}/65535)".format("    Stone: ", " ",
                                                 self.gf_stone),
        print "\r    Stone: ".format(self.gf_stone),
        be.set_colour("grey")
        self.gf_stone = int(raw_input(""))
        be.reset_colour()

        print "{0:11}{1:10}({2:,}/65535)".format("     Wood: ", " ",
                                                 self.gf_wood),
        print "\r     Wood: ".format(self.gf_wood),
        be.set_colour("green")
        self.gf_wood = int(raw_input(''))
        be.reset_colour()

        #Weapons
        print "{0:11}{1:10}({2:,}/65535)".format("    Armor: ", " ",
                                                 self.gf_armor),
        print "\r    Armor: ".format(self.gf_armor),
        be.set_colour("red")
        self.gf_armor = int(raw_input(''))
        be.reset_colour()

        print "{0:11}{1:10}({2:,}/65535)".format("     Bows: ", " ",
                                                 self.gf_bows),
        print "\r     Bows: ".format(self.gf_bows),
        be.set_colour("red")
        self.gf_bows = int(raw_input(''))
        be.reset_colour()

        print "{0:11}{1:10}({2:,}/65535)".format("Crossbows: ", " ",
                                                 self.gf_xbows),
        print "\rCrossbows: ".format(self.gf_xbows),
        be.set_colour("red")
        self.gf_xbows = int(raw_input(''))
        be.reset_colour()

        print "{0:11}{1:10}({2:,}/65535)".format("   Swords: ", " ",
                                                 self.gf_bows),
        print "\r   Swords: ".format(self.gf_swords),
        be.set_colour("red")
        self.gf_swords = int(raw_input(''))
        be.reset_colour()

        self.savevalues(filename)
예제 #10
0
opts, args = getopt.getopt(sys.argv[1:], "hles",
                           ["help", "list", "edit", "set"])
if debug: print "Options:", opts
if debug: print "Args:", args
for o, a in opts:
    if debug: print "O:", o
    if o in ("-h", "--help"):
        gamefile.usage()
        sys.exit()
    elif o in ("-l", "--list"):
        if len(args) > 0:
            #list
            gamefile.listfile(args[0])
            sys.exit()
    elif o in ("-e", "--edit"):
        if len(args) > 0:
            #edit
            gamefile.editfile(args[0])
            sys.exit()
    elif o in ("-s", "--set"):
        if len(args) > 0:
            #Set good default values into game file
            gamefile.savevalues(args[0])
            be.cprint("green", "T'is done my lord...\n")
            be.reset_colour()
            sys.exit()
    else:
        #assume garbage so exit
        be.cprint("red", "ERROR: Unknown, please read the help page")
        be.reset_colour()
예제 #11
0
    def listCounties(self):
        '''Iterate through counties and allow to edit or just view the details of each county'''
        count = 1
        while True:
            be.cprint(
                "green",
                "\nMy Lord, county {0}/{1} reports the following:\n\n".format(
                    count, self.counties))
            be.reset_colour()
            self.loadCounty(count - 1)
            print "Ruler: ",
            be.cprint(self.colors[self.county_color],
                      "{0:}\n".format(self.rulers[self.county_ruler]))
            be.reset_colour()
            print "Tax: ",
            be.cprint("blue", "{0:}\n".format(self.county_tax))
            be.reset_colour()
            print "Happiness: ",
            be.cprint("red", "{0:}\n".format(self.county_happiness))
            be.reset_colour()
            print "Health: ",
            be.cprint("red", "{0:}\n".format(self.health[self.county_health]))
            be.reset_colour()
            print "Population: ",
            be.cprint("white", "{0:}\n".format(self.county_population))
            be.reset_colour()
            print "Grain: ",
            be.cprint("yellow", "{0:}\n".format(self.county_grain))
            be.reset_colour()
            print "Cattle: ",
            be.cprint("white", "{0:}\n".format(self.county_cattle))
            be.reset_colour()

            be.cprint("grey", "(P)revious - (E)dit - (Q)uit - (N)ext: ")
            temp = raw_input("")
            if temp.lower() == 'p':
                count -= 1
                if count < 1: count = 1
            if temp.lower() == 'n':
                count += 1
                if count > self.counties: count = self.counties
            if temp.lower() == 'q':
                be.cprint("green", "\nBye!\n")
                sys.exit(0)
            if temp.lower() == 'e':
                self.editCounty(count)
예제 #12
0
    def editCounty(self, cnum):
        ''' Edit main stats of a county - population, health, grain, cattle
        '''
        be.cprint(
            "green",
            "My Lord, What do you desire for county {0}/{1}:\n\n".format(
                cnum, self.counties))
        be.reset_colour()
        while True:
            print "Ruler 0=None, 1=You, 2=Bishop, 3=Baron, 4=Countess,5=Knight: ",
            be.set_colour("blue")
            temp = int(raw_input())
            be.reset_colour()
            if temp > -1 and temp < 6:
                self.county_ruler = temp
                break

        while True:
            print "Color (0=None, 1=Red, 2=Yellow, 3=Grey, 4=Pink, 5=Blue, 6=Black): ",
            be.set_colour("blue")
            temp = int(raw_input())
            be.reset_colour()
            if temp > -1 and temp < 7:
                self.county_color = temp
                break

        while True:
            print "Happiness 0-100: ",
            be.set_colour("blue")
            temp = int(raw_input())
            be.reset_colour()
            if temp > -1 and temp < 101:
                self.county_happiness = temp
                break
        while True:
            print "Health (1=Plagued, 2=Weak, 3=Normal, 4=Perfect): ",
            be.set_colour("green")
            temp = int(raw_input())
            be.reset_colour()
            if temp > -1 and temp < 6:
                self.county_health = temp
                break
        while True:
            print "Population 0-65535: ",
            be.set_colour("blue")
            temp = int(raw_input())
            be.reset_colour()
            if temp > -1 and temp < 65535:
                self.county_population = temp
                break
        while True:
            print "Grain (0-65535): ",
            be.set_colour("yellow")
            temp = int(raw_input())
            be.reset_colour()
            if temp > -1 and temp < 65535:
                self.county_grain = temp
                break
        while True:
            print "Cattle (0-65535): ",
            be.set_colour("white")
            temp = int(raw_input())
            be.reset_colour()
            if temp > -1 and temp < 65535:
                self.county_cattle = temp
                break

        self.saveCounty(cnum - 1)
예제 #13
0
                break

        self.saveCounty(cnum - 1)

    def countCounties(self):
        '''Count the number of counties in gamefile.'''
        count = 0
        temp = 0
        self.gf.seek(self.countyloc)
        return struct.unpack('B', self.gf.read(1))[0]


#Main
gamefile = lotr2edit()
opts, args = getopt.getopt(sys.argv[1:], "hf", ["help", "file"])
for o, a in opts:
    if debug: print "O:", o
    if o in ("-h", "--help"):
        gamefile.usage()
        sys.exit()
    elif o in ("-f", "--file"):
        if len(args) > 0:
            if os.path.isfile(args[0]):
                gamefile.gf = open(args[0], "r+b")
            gamefile.counties = gamefile.countCounties()
            gamefile.listCounties()
            sys.exit()
    else:
        be.cprint("red", "ERROR: Unknown, please read the help page")
        be.reset_colour()