コード例 #1
0
def run():
    npcs = {}

    npc_pages = api.query_category("Monsters")
    for name, page in npc_pages.items():
        if name.startswith("Category:"):
            continue

        try:
            code = mw.parse(page, skip_style_tags=True)

            for (vid, version) in util.each_version("Infobox Monster", code):
                doc = util.get_doc_for_id_string(name + str(vid), version,
                                                 npcs)
                if doc == None:
                    continue
                util.copy("name", doc, version, lambda x: x)
                for key in ["hitpoints", "combat"]:
                    try:
                        util.copy(key, doc, version, lambda x: int(x))
                    except ValueError:
                        print("NPC {} has an non integer {}".format(name, key))

        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            print("NPC {} failed:".format(name))
            traceback.print_exc()

    for npcId in copy.copy(npcs):
        npc = npcs[npcId]
        if not 'combat' in npc:
            del npcs[npcId]

    util.write_json("npcs.json", "npcs.min.json", npcs)
コード例 #2
0
def run():
    npcs = {}

    npc_pages = api.query_category("Monsters")
    for name, page in npc_pages.items():
        if name.startswith("Category:"):
            continue

        try:
            code = mw.parse(page, skip_style_tags=True)

            for (vid, version) in util.each_version("Infobox Monster", code):
                if "removal" in version and not str(
                        version["removal"]).strip().lower() in ["", "no"]:
                    continue

                doc = util.get_doc_for_id_string(name + str(vid), version,
                                                 npcs)
                if doc == None:
                    continue
                util.copy("name", doc, version)
                if not "name" in doc:
                    doc["name"] = name

                scaling = util.has_template("Chambers of Xeric",
                                            code) or util.has_template(
                                                "Theatre of Blood", code)
                if not scaling:
                    for key in ["hitpoints"]:
                        try:
                            util.copy(key, doc, version, lambda x: int(x))
                        except ValueError:
                            print("NPC {} has an non integer {}".format(
                                name, key))

        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            print("NPC {} failed:".format(name))
            traceback.print_exc()

    util.write_json("npcs.json", "npcs.min.json", npcs)
コード例 #3
0
def run():
	limits = getLimits()
	stats = {}

	item_pages = api.query_category("Items")
	for name, page in item_pages.items():
		if name.startswith("Category:"):
			continue

		try:
			code = mw.parse(page, skip_style_tags=True)

			equips = {}
			for (vid, version) in util.each_version("Infobox Bonuses", code):
				doc = {}
				equips[vid] = doc

				slotID = str(version["slot"]).strip().lower()
				doc["slot"] = slotIDs[slotID]
				if slotID == "2h":
					doc["is2h"] = True

				for key in [
					"astab", "aslash", "acrush", "amagic", "arange", "dstab", "dslash", "dcrush", "dmagic", "drange", "str",
					"rstr", "mdmg", "prayer", ("speed", "aspeed")
				]:
					try:
						util.copy(key, doc, version, lambda x: int(x))
					except ValueError:
						print("Item {} has an non integer {}".format(name, key))

			for (vid, version) in util.each_version("Infobox Item", code):
				if "removal" in version and str(version["removal"]).strip():
					continue

				doc = util.get_doc_for_id_string(name + str(vid), version, stats)
				if doc == None:
					continue

				util.copy("name", doc, version)
				if not "name" in doc:
					doc["name"] = name

				util.copy("quest", doc, version, lambda x: x.lower() != "no")

				equipable = "equipable" in version and "yes" in str(version["equipable"]).strip().lower()

				if "weight" in version:
					strval = str(version["weight"]).strip()
					if strval.endswith("kg"):
						strval = strval[:-2].strip()
					if strval != "":
						red = WEIGHT_REDUCTION_EXTRACTOR.match(strval)
						if red:
							strval = red.group(2)
						floatval = float(strval)
						if floatval != 0:
							doc["weight"] = floatval

				equipVid = vid if vid in equips else -1 if -1 in equips else None
				if equipVid != None:
					if equipable or not "broken" in version["name"].lower():
						if not equipable:
							print("Item {} has Infobox Bonuses but not equipable".format(name))
						doc["equipable"] = True
						doc["equipment"] = equips[equipVid]
				elif equipable:
					print("Item {} has equipable but not Infobox Bonuses".format(name))
					doc["equipable"] = True
					doc["equipment"] = {}

				itemName = name
				if "gemwname" in version:
					itemName = str(version["gemwname"]).strip()
				elif "name" in version:
					itemName = str(version["name"]).strip()
				if itemName in limits:
					doc['ge_limit'] = limits[itemName]

		except (KeyboardInterrupt, SystemExit):
			raise
		except:
			print("Item {} failed:".format(name))
			traceback.print_exc()

	util.write_json("stats.json", "stats.ids.min.json", stats)