Last active
April 21, 2022 21:52
-
-
Save DamianDominoDavis/437f700ae5d6ac5a87b173810a73fdab to your computer and use it in GitHub Desktop.
search 2CRS seeds for enchants
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
// search a specific 2CRS seed for an enchantment type, by source | |
float[item] scores; | |
item[int] them; | |
boolean[string] types; | |
int[item] sizes; | |
string[item] quals; | |
effect[item] effs; | |
int[item] durs; | |
string[item] mods; | |
boolean[string] classes = $strings[Seal Clubber,Turtle Tamer,Pastamancer,Sauceror,Disco Bandit,Accordion Thief]; | |
boolean[string] signs = $strings[Mongoose,Wallaby,Vole,Platypus,Opossum,Marmot,Wombat,Blender,Packrat]; | |
string[int] fetch(string cl, string si) { | |
string[int] b = file_to_array(`TCRS_{cl.replace_string(' ','_')}_{si}.txt`); | |
if (b.count()==0) { | |
cli_execute(`try; tcrs fetch {cl},{si};`); | |
b = file_to_array(`TCRS_{cl.replace_string(' ','_')}_{si}.txt`); | |
} | |
if (b.count()==0) | |
abort(`could not fetch {cl}/{si}`); | |
return b; | |
} | |
string pattern = '^\(\\d+\)\\t\([^\\t]+\)\\t\(\\d{1,2}\)\\t\(crappy|decent|good|awesome|EPIC\)?\t\(Effect: \\"\(.+\)\\", Effect Duration: \(\\d+\)\)?\(.*\)$'; | |
/* 0: original string | |
1: item id | |
2: modified item name | |
3: size | |
4: quality | |
5: composite effect string | |
6: effect name | |
7: effect duration | |
8: equipment enchantment | |
*/ | |
boolean has_parts(string[int] parts, boolean[int] which) { | |
foreach w in which | |
if (parts[w] == '' || (w==3 && parts[w]=='0')) | |
return false; | |
return true; | |
} | |
boolean parts_has_effect(string[int] parts) { | |
return parts.has_parts($ints[6,7]); | |
} | |
boolean parts_is_equip(string[int] parts) { | |
return parts.has_parts($ints[8]); | |
} | |
boolean parts_give_adv(string[int] parts) { | |
return parts.has_parts($ints[1,3,4]) && parts[1].to_int().to_item().spleen == 0; | |
} | |
float hmuch(item it, string desc, string mod) { | |
matcher m; | |
if (desc.contains_text('Effect: ')) { | |
m = 'Effect: \"\(.+\)\", Effect Duration: \(\\d+\)'.create_matcher(desc); | |
if (m.find()) | |
return m.group(1).to_effect().numeric_modifier(mod); | |
} | |
if (desc.contains_text(mod)) { | |
m = (mod + ': ([-+]?\d+\.?\d*)').create_matcher(desc); | |
if (m.find()) | |
return m.group(1).substring(mod.length()+2).to_float(); | |
} | |
return 0; | |
} | |
string subtype(item it) { | |
if (it.to_slot() != $slot[none]) | |
return 'equipment: ' + it.to_slot(); | |
if (it.item_type().length() > 1) | |
return it.item_type(); | |
if (it.combat | it.combat_reusable) | |
return 'combat item'; | |
if (it.effect_modifier('Effect') != $effect[none]) | |
return 'potion'; | |
if (it.usable | it.reusable) | |
return 'usable'; | |
if (it.pasteable | it.smithable | it.cookable | it.mixable) | |
return 'ingredient'; | |
return '???'; | |
} | |
void get_them(string cls, string sig, string mod) { | |
them = {}; | |
types = {}; | |
foreach line,s in fetch(cls,sig) { | |
string[int] part = s.group_string(pattern)[0]; | |
item it = part[1].to_item(); | |
string subtype = part[1].to_item().subtype(); | |
int size = part[3].to_int(); | |
string quality = part[4]; | |
effect ef = part[6].to_effect(); | |
int duration = part[7].to_int(); | |
string enchants = part[8].to_lower_case(); | |
mod = mod.to_lower_case(); | |
float much = ef.numeric_modifier(mod) + enchants.group_string(mod + ': ([-+]?\\d+\\.?\\d*)')[0,1].to_float(); | |
if (much > 0) { | |
scores[it] = much; | |
them[them.count()] = it; | |
types[it.subtype()] = true; | |
if (part.parts_give_adv()) { | |
quals[it] = quality; | |
sizes[it] = size; | |
} | |
if (part.parts_has_effect()) { | |
durs[it] = duration; | |
effs[it] = ef; | |
} | |
if (part.parts_is_equip()) | |
mods[it] = enchants; | |
} | |
} | |
sort them by -scores[value]; | |
} | |
void main(string class_sign_modifier) { | |
string[int] mands = class_sign_modifier.split_string('\\s*,\\s*'); | |
if (mands.count()!=3) { | |
print('Usage: Class, Sign, Modifier','red'); | |
print('(example: 2c_hunter Turtle Tamer, Platypus, Familiar Weight)','red'); | |
return; | |
} | |
get_them(mands[0], mands[1], mands[2]); | |
foreach t in types { | |
print(t, 'blue'); | |
foreach _,x in them | |
if (x.subtype() == t) { | |
print( scores[x].to_string('[%+.0f] ') | |
+ (durs contains x? ' ('+ durs[x] +') ':'') | |
+ x | |
+ (quals contains x? ' [' + quals[x] + ' x' + sizes[x] + '] ':'') | |
+ (effs contains x? ' => ' + effs[x] + ' = ' + effs[x].string_modifier('Modifiers') :'') | |
+ (mods contains x? ' => ' + mods[x] :'') | |
); | |
} | |
} | |
} |
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
// search all 2CRS seeds for a specific target effect, by seed | |
import <2c_hunter.ash>; | |
void main(string searchFor) { | |
effect ef = searchFor.to_effect(); | |
if (ef==$effect[none]) | |
abort(`what effect is {searchFor}?`); | |
foreach cl in classes | |
foreach si in signs { | |
foreach line,s in fetch(cl,si) | |
if (s.contains_text('Effect: "'+ef+'"')) { | |
string[int,int] parts = s.group_string('([^\t]+)\t?'); | |
item it = parts[0,1].to_int().to_item(); | |
int duration = s.group_string('Effect Duration: \(\\d+\)')[0][1].to_int(); | |
print(`{cl}/{si}: {it} => ({duration}) {ef}`); | |
} | |
print(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment