generic weapon forge #307
Aliases: generic weapon forge, forge
7 verbs · 33 properties · 0 children
Verbs
| Verb | Spec | Flags | Definer | Lines |
|---|---|---|---|---|
forge | this none this | rxd | #307 | 22 |
make_candidate | this none this | rxd | #307 | 10 |
is_legal | this none this | rxd | #307 | 11 |
pick_part | this none this | rxd | #307 | 22 |
forge_name | this none this | rxd | #307 | 51 |
name_priority | this none this | rxd | #307 | 8 |
make_models | this none this | rxd | #307 | 15 |
Properties
| Property | Definer | Flags | Owner | Value |
|---|---|---|---|---|
parts | #307 | rc | #361 | {} |
generic_legendary | #307 | rc | #361 | #-1 |
models | #307 | rc | #361 | {} |
handed | #5 | rc | #361 | <clear> |
wield_msg | #5 | rc | #361 | <clear> |
unwield_msg | #5 | rc | #361 | <clear> |
size | #5 | rc | #361 | <clear> |
look_place_msg | #5 | rc | #361 | <clear> |
value | #5 | rc | #361 | <clear> |
get_msg | #5 | rc | #361 | <clear> |
drop_msg | #5 | rc | #361 | <clear> |
get_fail_msg | #5 | rc | #361 | <clear> |
junk_ok | #5 | rc | #361 | <clear> |
floats | #5 | rc | #361 | <clear> |
long_name_msg | #5 | rc | #361 | <clear> |
article | #5 | rc | #361 | <clear> |
setup_list | #5 | rc | #361 | <clear> |
health | #5 | rc | #361 | <clear> |
health_max | #5 | rc | #361 | <clear> |
min_skill | #5 | rc | #361 | <clear> |
skill | #5 | rc | #361 | <clear> |
recipe_for | #5 | rc | #361 | <clear> |
carried_msg | #5 | rc | #361 | <clear> |
aliases | #1 | rc | #361 | {"generic weapon forge", "forge"} |
description | #1 | rc | #361 | <clear> |
object_size | #1 | r | #29 | {5398, 1298434595} |
hidden_verbs | #1 | rc | #361 | <clear> |
phelp_msg | #1 | rc | #361 | <clear> |
weight | #1 | rwc | #361 | -1 |
owner_verbs | #1 | rc | #361 | <clear> |
plural_name | #1 | rc | #361 | <clear> |
client_image | #1 | rc | #361 | <clear> |
listening | #1 | rc | #361 | <clear> |
Ancestry
Ancestors (nearest first): #5 generic thing → #1 root
Children: none
Call graph
Source
forge
Referenced by
none
Source
1":forge(INT quality) => Forge a weapon of given quality."; 2{quality} = args; 3weapons = {}; 4for i in [1..4] 5parts = {}; 6while (!this:is_legal(parts)) 7parts = this:make_candidate(quality); 8endwhile 9q = 0; 10for x in (parts) 11q = q + x.quality; 12endfor 13weapons = {@weapons, {q, parts}}; 14suspend(0); 15endfor 16weapons = $lu:sort_alist(weapons, 1); 17parts = weapons[$][2]; 18player:tell($ansi.bold_on, this:forge_name(parts), $ansi.reset, " (quality ", weapons[$][1], ")"); 19for x in (parts) 20player:tell($su:nn(x), " ", x:tree_tag()); 21endfor 22return parts;
make_candidate
Referenced by
- #307:forge line 7:
this:make_candidate - #307:make_models line 6:
this:make_candidate
Source
1":(INT quality) => Generate a weapon of the given quality and return the parts list. Might not be a legal weapon."; 2{quality} = args; 3parts = {}; 4qleft = quality; 5for ptype in ($lu:randomly_permute(this.parts)) 6part = this:pick_part(ptype, qleft); 7qleft = qleft - part.quality; 8parts = {@parts, part}; 9endfor 10return parts;
is_legal
Referenced by
- #307:forge line 6:
this:is_legal - #307:make_models line 5:
this:is_legal
Source
1":is_legal(LIST parts) => Is this a legal weapon?"; 2{parts} = args; 3if (!parts) 4return 0; 5endif 6for x in (parts) 7if (!x:compatible_with(parts)) 8return 0; 9endif 10endfor 11return 1;
pick_part
Referenced by
- #307:make_candidate line 6:
this:pick_part
Source
1":pick_part(OBJ parent, INT quality[, INT weapon_quality]) => Pick a random part of the given parent of no more than the given quality."; 2{parent, quality, ?weapon_quality = $maxint} = args; 3poss = {}; 4bucket = $ou:leaves(parent); 5weakest = bucket[1]; 6for x in (bucket) 7if (weapon_quality >= x.min_quality) 8if (x.quality <= quality) 9if ((!x.rarity) || (random(100) > x.rarity)) 10poss = {@poss, x}; 11endif 12endif 13if (x.quality < weakest.quality) 14weakest = x; 15endif 16endif 17endfor 18if (poss) 19return poss[random($)]; 20else 21return weakest; 22endif
forge_name
Referenced by
- #307:forge line 18:
this:forge_name
Source
1{parts} = args; 2n1 = {}; 3n2 = {}; 4magic = 0; 5q = 0; 6for x in (parts) 7if (x.subname_msg) 8{x1, x2} = $su:explode(x.subname_msg, "_"); 9if (x1 != "*") 10n1 = {@n1, {x1, this:name_priority(x1)}}; 11endif 12if (x2 != "*") 13n2 = {@n2, {x2, this:name_priority(x2)}}; 14endif 15endif 16magic = magic + tonum(x); 17q = q + x.quality; 18endfor 19name = ""; 20for x in ($ou:leaves(this.generic_legendary)) 21found = 1; 22for y in (x.required_parts[1..$]) 23if (!(y in parts)) 24found = 0; 25endif 26endfor 27if (found) 28name = $ansi.yellow + $ansi.bold_on; 29{x1, x2} = $su:explode(x.subname_msg, "_"); 30if (x1 != "*") 31n1 = {{x1, 2}}; 32endif 33if (x2 != "*") 34n2 = {{x2, 2}}; 35endif 36endif 37endfor 38n1 = $lu:sort_alist(n1, 2); 39n1 = n1[$][1]; 40n2 = $lu:sort_alist(n2, 2); 41n2 = n2[$][1]; 42name = (name + (n1 + " ")) + n2; 43name = $su:lowercase(name); 44num_let = $rng:gil(2, magic); 45code = ""; 46for i in [1..num_let] 47code = code + "CXJZREVMBDGTNPL"[$rng:gil(15, magic + i)]; 48endfor 49code = code + tostr(q / 10); 50name = (code + " ") + name; 51return name;
name_priority
Referenced by
- #307:forge_name line 10:
this:name_priority - #307:forge_name line 13:
this:name_priority
Source
1name = args[1]; 2if (index($su.alphabet, name[1], 1)) 3return 0; 4elseif (index($su.alphabet, name[2], 1)) 5return 1; 6else 7return 2; 8endif
make_models
Referenced by
none
Source
1this.models = {}; 2for i in [10..100] 3quality = i * 10; 4parts = {}; 5while (!this:is_legal(parts)) 6parts = this:make_candidate(quality); 7yield; 8endwhile 9quality = 0; 10for x in (parts) 11quality = quality + x.quality; 12endfor 13this.models = {@this.models, {quality, parts}}; 14yield; 15endfor