Last active
May 28, 2022 20:08
-
-
Save AntumDeluge/654ba150eb0c4f716b9b39719c010be8 to your computer and use it in GitHub Desktop.
Calculates drop rarity score for items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dark elf knight;9 | |
Dhohr Nuggetcutter;1 | |
babybear;11 | |
assassin;151 | |
dark elf general;8 | |
littlewizard;44 | |
djinn;29 | |
barbarian chaman;4 | |
elf bodyguard;8 | |
bat;89 | |
giant;48 | |
archer elf;37 | |
ram;1 | |
chaos bishop;2 | |
madaram axeman;3 | |
rat;256 | |
elder skeleton;6 | |
ebony pegasus;21 | |
bloody zombie;10 | |
devil monk;4 | |
lion;44 | |
superogre;7 | |
vampire lord;1 (0 + 1 ItemGuardCreature) | |
duergar wizard;16 | |
child dark elf;13 | |
amazoness coastguard mistress;3 | |
golden unicorn;33 | |
winged blurble;6 | |
tiny skelly;10 | |
amazoness giant;1 | |
caverat;84 | |
mountain orc warrior;6 | |
ratwoman;20 | |
vampire bride;1 | |
master assassin;60 | |
zombie;51 | |
arachne;1 | |
albino elf archer;23 | |
troll;40 | |
madaram windwalker;3 | |
bone dragon;9 | |
imperial archer leader;12 | |
militia elf;30 | |
fallen angel;4 | |
fallen warrior;7 | |
oni warrior;23 | |
spider;57 | |
penguin;36 | |
soldier kobold;47 | |
ice giant;2 | |
darkmonk;25 | |
veteran goblin;2 | |
mithrilbourgh wizard;13 | |
googon;10 | |
dwarf golem;11 | |
pegasus;1 | |
dark elf captain;19 | |
black dragon;5 (???) | |
skeleton;137 | |
giant killer bat;228 | |
madaram queen ;1 | |
infantry gnome;7 | |
sapphire mermaid;83 | |
archmage elf;18 | |
elf;107 | |
cannibal woman;7 | |
violet avenger;7 | |
imperial experiment;3 | |
oni archer;18 | |
elder gargoyle;6 | |
young beholder;5 | |
ninja;57 | |
ogre soldier;12 | |
cave troll;22 | |
tiny scarab;8 | |
white horse;2 | |
elephant;55 | |
minotaur king;1 (0 + 1 ItemGuardCreature) | |
deer;88 | |
neo kraken;69 | |
amazoness commander;13 | |
imperial general giant;9 | |
chaos knight;2 | |
samurai;20 | |
fox;43 | |
archer kobold;21 | |
piglet;2 | |
dark aruthon;8 | |
ent;40 | |
brain ahouga;8 | |
minotaur;9 (8 + 1 ItemGuardCreature) | |
madaram archer;3 | |
golden death;1 | |
green slime;22 | |
brown slime;8 | |
imperial general;13 | |
crab;88 | |
elder sheepman;12 | |
duergar elite;6 | |
ivory pegasus;22 | |
fallen high priest;8 | |
rysin dragon;27 | |
kobold;32 | |
red dragon;32 | |
oni priest;19 | |
boar;46 | |
commander elf;16 | |
chaos lord;11 | |
mimic;27 | |
ice golem;4 | |
necrosophia;2 | |
dark archangel;1 | |
baby pegasus;37 | |
kraken;2 | |
barbarian wolf;8 | |
imperial demon servant;13 | |
oni king;1 | |
bull;1 | |
dark elf master;2 | |
giant spider;47 | |
poison shroom;7 | |
littlewitch;27 | |
blordrough soldier;53 | |
risecia swordsman;6 | |
archangel;2 | |
ruby mermaid;102 | |
mountain orc chief;4 | |
high lich;1 | |
big bad wolf;1 | |
dwarf;54 | |
musth elephant;4 | |
shark;8 | |
beholder;5 | |
amazoness bodyguard;13 | |
mithrilbourgh general;3 | |
madaram peasant;4 | |
leader dwarf;19 | |
water demon;112 | |
bull elephant;12 | |
armored sheepman;16 | |
orc warrior;50 | |
elf sacerdotist;15 | |
soldier elf;75 | |
cow;7 | |
fire elemental;21 | |
angel;3 | |
mithrilbourgh soldier;56 | |
kalavan wisewoman;5 | |
xenocium;2 | |
giantrat;47 | |
royal mummy;10 | |
glacier centaur;26 | |
mountain orc;8 | |
Chief Falatheen of the Risecia;2 | |
giant gnomess;4 | |
pigeon;9 | |
fallen priest;12 | |
ice elemental;12 | |
turtle;11 | |
madaram queen;2 | |
cannibal warrior;2 | |
mithrilbourgh colonel;11 | |
chick;13 | |
mountain orc hunter;11 | |
orc spearman;10 | |
blordrough storm trooper;57 | |
black duergar;9 | |
giant dwarf;2 | |
solar centaur;16 | |
chicken;36 | |
chaos queen;1 | |
elite frogman;5 | |
mountain hero dwarf;28 | |
chaos soldier;259 | |
golden orc;1 | |
veteran kobold;40 | |
goblin;18 | |
incorporeal armor;5 | |
legendary ice elemental;1 | |
amazoness archer commander;13 | |
gnome;43 | |
chaos warrior;162 | |
centaur king;33 | |
elder duergar;5 | |
black bear;118 | |
mithrilbourgh sergeant;13 | |
elder dwarf;40 | |
mountain elder dwarf;36 | |
earth elemental;16 | |
chaos red dragonrider;4 | |
woolly mammoth;104 | |
kasarkutominubat;1 | |
imperial high priest;9 | |
naga;26 | |
black death;4 | |
imperial leader;13 | |
mummy;32 | |
madaram stalker;3 | |
imperial chief;11 | |
oni queen;3 | |
vampirette;7 | |
razorrat;67 | |
elder cannibal;3 | |
mountain dwarf guardian;37 | |
tiger;50 | |
amazoness imperator;1 | |
horse;7 | |
glow monster;14 | |
king cobra;3 | |
death knight;18 | |
madaram healer;7 | |
madaram pawn;8 | |
emperor dalmung;1 | |
blordrough general;32 | |
ogre;19 | |
orc chief;25 | |
duergar;3 | |
leader kobold;16 | |
water elemental;15 | |
amazoness hunter;33 | |
dark elf archer;32 | |
armed naga;12 | |
mermaid;8 | |
warrior skeleton;66 | |
balrog;3 | |
albino elf king;6 | |
madaram buster blader;1 | |
imperial defender;40 | |
devil queen;6 | |
wolf;91 | |
duergar king;2 (1 + 1 ItemGuardCreature) | |
blordrough elite;53 | |
littlefairy;19 | |
dodo;32 | |
giant gnome;4 | |
gashadokuro;1 | |
amazoness elite coastguard;7 | |
unicorn;2 | |
elder beholder;7 | |
thing;5 (4 + 1 ItemGuardCreature) | |
hero dwarf;26 | |
black slime;24 | |
venom gargoyle;6 | |
dark gargoyle;9 | |
lich;1 | |
mouse;9 | |
killer bat;45 | |
imperial scientist;17 (16 + 1 ItemGuardCreature) | |
amazoness archer;36 | |
beaver;25 | |
dark elf wizard;12 | |
green phantom;4 | |
master giant;9 | |
dark mutant;10 | |
blordrough captain;50 | |
chaos commander;57 | |
lamia;67 | |
imperial elite guardian;18 | |
high naga;17 | |
dead lich;1 | |
cavalryman gnome;7 | |
kalavan housewife;16 | |
black unicorn;13 | |
chaos king;1 | |
crocodile;32 | |
old ent;2 | |
madaram rook;2 | |
imperial demon lord;9 | |
wizard frogman;17 | |
gargoyle;13 | |
cat woman;19 | |
madaram trooper;3 | |
madaram knight;2 | |
orc;22 | |
barbarian;3 | |
bandit;103 | |
water scarab;2 | |
elder giant;28 | |
leprechaun;23 | |
monk;18 | |
chaos sorcerer;30 | |
rotten zombie;21 | |
chaos overlord;4 | |
madaram cavalry;3 | |
demon skeleton;28 (27 + 1 ItemGuardCreature) | |
risecia thug;7 | |
shadows assassin;86 | |
killer bee;10 (???) | |
ratman;84 | |
baby angel;12 | |
mother hen;6 | |
risecia archer;11 | |
mountain dwarf;39 | |
imperial mutant;7 | |
madaram king;1 | |
grass snake;15 | |
flying golden dragon;23 | |
madaram soldier;2 | |
apprentice assassin;8 | |
duergar axeman;2 | |
blue dragon;33 | |
imperial veteran;6 | |
imperial priest;15 | |
dark elf admiral;5 | |
imperial commander;21 | |
amethyst mermaid;91 | |
mithrilbourgh knight;15 | |
goat;2 | |
wooden golem;11 | |
clurichaun;23 | |
dark elf ranger;5 | |
green dragon;30 (29 + 1 ItemGuardCreature) | |
ghost hound;2 | |
nymph;8 | |
bronze pegasus;28 | |
elder ogre;8 | |
chaos dragonrider;14 | |
barbarian elite;6 | |
blordrough quartermaster;49 | |
imperial knight;12 | |
amazoness coastguard;33 | |
dark elf matronmother;4 | |
zombie rat;17 | |
ghost;48 | |
dark elf viceroy;2 | |
robot aruthon;6 | |
entwife;8 | |
black giant;3 | |
demon;22 | |
dark elf;21 | |
dwarf guardian;38 | |
mithrilbourgh elite archer;20 | |
elf wizard;15 | |
archrat;27 | |
snarfkin;21 | |
dark elf sacerdotist;12 | |
grobble monster;2 | |
twilight slime;1 (0 + 1 ItemGuardCreature) | |
stone golem;26 | |
giant bat;203 | |
madaram bishop;2 | |
imperial archer;35 | |
albino elf swordsman;43 | |
mithrilbourgh lieutenant;9 | |
panda;4 | |
cobra;17 | |
monkey;34 | |
werewolf;17 | |
barbarian king;3 | |
blordrough corporal;53 | |
orc hunter;13 | |
mountain leader dwarf;18 | |
mage elf;20 | |
red roohako;4 | |
white unicorn;33 | |
madaram hero;2 | |
dark angel;2 | |
barbarian priest;5 | |
elite sheepman;12 | |
albino elf queen;8 | |
giant kobold;4 | |
poisonous spider;38 | |
bear;98 | |
hunter;72 | |
amazoness vigilance;2 | |
barbarian leader;7 | |
invisible man;7 | |
chaos pawn;8 | |
frogman;16 | |
emerald mermaid;108 | |
kalavan citizen;7 | |
dark elf elite archer;15 | |
centaur;1 | |
winged blue imp;21 | |
kalavan peasant;10 | |
Lord Durin;1 | |
death;26 | |
soldier goblin;1 | |
snake;83 | |
mage gnome;23 | |
mithrilbourgh archer;5 | |
imp;56 | |
air elemental;15 | |
red troll;16 | |
chaos green dragonrider;6 | |
sheepman;13 | |
polar bear;4 | |
disciple assassin;18 (17 + 1 ItemGuardCreature) | |
caiman;33 | |
cyclops;23 | |
cannibal;8 | |
venomrat;51 | |
imperial elite archer;26 | |
duergar hero;10 | |
blordrough infantry;45 | |
chaos rook;2 | |
albino elf magician;22 | |
blue mohiko;7 | |
headless monster;14 | |
twin headed dragon;28 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
## The MIT License (MIT) | |
# | |
# Copyright © 2022 Jordan Irwin (AntumDeluge) | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy of | |
# this software and associated documentation files (the "Software"), to deal in | |
# the Software without restriction, including without limitation the rights to | |
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | |
# of the Software, and to permit persons to whom the Software is furnished to do | |
# so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in | |
# all copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
## SOFTWARE. | |
# Instructions: | |
# | |
# This script calculates a rarity score for items dropped by creatures. Higher | |
# values mean more rare. It must be run from the Stendhal source code root | |
# directory. A file `buildtools/creature_spawn_points.txt` must exist with its | |
# contents in the format of `creature name;spawn points count`. The contents | |
# can be generated with the `games.stendhal.tools.GenerateMonsterUsage` tool. | |
# | |
# 1) Execute `ant compile_stendhaltools` | |
# 2) Execute `java -cp ./:./libs/*:./build/lib/:./build/build_stendhaltools games.stendhal.tools.GenerateMonsterUsage` | |
# 3) Copy the output to `buildtools/creature_spawn_points.txt` | |
# 4) Run the script: `python stendhal_item_drop_score.py <creature1> [<creature2> ...]` | |
import os, sys, codecs | |
import xml.etree.ElementTree as ET | |
dir_script = os.path.dirname(__file__) | |
if len(sys.argv) < 2: | |
print("ERROR: must provide at least one item name") | |
sys.exit(1) | |
items = sys.argv[1:] | |
scores = {} | |
spawn_points = {} | |
sp_file = os.path.join(dir_script, "creature_spawn_points.txt") | |
if not os.path.isfile(sp_file): | |
print("ERROR: cannot find spawn points file: {}".format(sp_file)) | |
sys.exit(1) | |
sp_buffer = codecs.open(sp_file, "r", "utf-8") | |
if not sp_buffer: | |
print("ERROR: could not open spawn points file for reading: {}".format(sp_file)) | |
sys.exit(1) | |
sp_lines = sp_buffer.readlines() | |
sp_buffer.close() | |
for li in sp_lines: | |
if ";" in li: | |
sp = li.split(";") | |
cname = sp[0].strip() | |
sp_count = sp[1].strip() | |
if " " in sp_count: | |
sp_count = sp_count.split(" ")[0].strip() | |
if sp_count.isdigit(): | |
spawn_points[cname] = int(sp_count) | |
dir_conf = "data/conf/creatures/" | |
if not os.path.isdir(dir_conf): | |
print("ERROR: creature configuration dir not found: {}".format(dir_conf)) | |
sys.exit(1) | |
# check that config files exist | |
if len([xml for xml in os.listdir(dir_conf) if os.path.isfile(os.path.join(dir_conf, xml)) and os.path.join(dir_conf, xml).endswith(".xml")]) == 0: | |
print("WARNING: no configuration files found in directory: {}".format(dir_conf)) | |
sys.exit(0) | |
scores = {} | |
def calScore(sp_count, drop_rate, sp_time): | |
return (sp_count * drop_rate * (1 / sp_time)) * 1000 | |
def turnsToMin(turns): | |
return turns * 0.3 / 60 | |
for i in items: | |
print("\nExamining drops for: {}".format(i)) | |
# value if no score found | |
scores[i] = "n/a" | |
for ROOT, DIRS, FILES in os.walk(dir_conf): | |
for file in FILES: | |
if file.endswith(".xml"): | |
file = os.path.join(ROOT, file) | |
tree = ET.parse(file) | |
root = tree.getroot() | |
# keep track of creatures in case there are duplicates, such as deer | |
checked_creatures = [] | |
for creature in root: | |
cname = creature.attrib["name"] | |
if cname not in spawn_points or cname in checked_creatures: | |
continue | |
checked_creatures.append(cname) | |
drops_elem = creature.find("{stendhal}drops") | |
if drops_elem != None: | |
drops = drops_elem.findall("{stendhal}item") | |
for item_elem in drops: | |
if "value" in item_elem.attrib and "probability" in item_elem.attrib: | |
drop_name = item_elem.attrib["value"] | |
drop_prob = item_elem.attrib["probability"] | |
if drop_name == i and drop_prob.replace(".", "", 1).isdigit(): | |
drop_prob = float(drop_prob) / 100 | |
respawn = creature.find("{stendhal}respawn") | |
if respawn != None and "value" in respawn.attrib: | |
respawn = respawn.attrib["value"] | |
if respawn.isdigit(): | |
respawn = int(respawn) | |
creature_score = calScore(spawn_points[cname], drop_prob, turnsToMin(respawn)) | |
msg = " {}: {}".format(cname, creature_score) | |
if creature_score == 0: | |
msg = "{} (WARNING: score of 0 may be inaccurate)".format(msg) | |
print(msg) | |
aggr_score = 0 | |
if i in scores and scores[i] != "n/a": | |
aggr_score = scores[i] | |
scores[i] = aggr_score + creature_score | |
total = 0 | |
if i in scores: | |
total = scores[i] | |
print(" Total: {}".format(total)) | |
print() | |
if len(scores) == 0: | |
print("WARNING: no scores found") | |
sys.exit(0) | |
for iname in scores: | |
print("{}: {}".format(iname, scores[iname])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment