107 lines (90 with data), 2.2 kB
/*
* this present returns an array of found items..
*
* should allow "battle axe 2" etc *sigh*
*
* * "all battle axes"
* * "two battle axes"
* * "third battle axe"
*/
inherit "RO/Servers";
/* hack - should use a back converter */
array numbers = [
"one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten"
];
array number_places = [
"first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "nineth", "tenth"
];
array
Present(string what, (array | object) cont)
{
int i, count = 1, num_items = 1;
array arr, exp, retarr = [ ];
object obj;
if (!what) return retarr;
exp = explode(what, " ");
if (objectp(cont)) arr = contents(cont);
else arr = cont;
if (count = MISC_LIB->str_to_int(exp[sizeof(exp)-1]))
what = implode(exp[..sizeof(exp)-2], " ");
else if ((i = index(number_places, exp[0])) != -1) {
count = i+1;
what = implode(exp[1..], " ");
}
else if ((i = index(numbers, exp[0])) != -1) {
num_items = i+1;
what = PLURAL->singular(implode(exp[1..], " "));
}
else if (exp[0] == "all") {
num_items = sizeof(arr);
what = PLURAL->singular(implode(exp[1..], " "));
}
else count = 1;
for (i = 0; i < sizeof(arr); i++) {
if (arr[i] && (arr[i]->id(what))) {
if (count <= 1) {
num_items--;
retarr = retarr + [ arr[i] ];
if (!num_items) return retarr;
}
count--;
}
}
/* nasty non-generic money hack - sigh */
if (!sizeof(retarr) && cont->query_living()) {
obj = make_some_money(what, cont);
if (obj && environment(cont)) {
move_object(obj, environment(cont));
retarr = [ obj ];
}
}
return retarr;
}
#define MAX_COINS 1000000
make_some_money(str, me)
{
object mon;
int amt;
if (!str) return;
if (index(str, "coin") != -1)
{
amt = atoi(str);
}
else
{
if (str == "1 coin" || str == "coin" ) amt = 1;
else if (str == "money" || str == "coins")
amt = me->query_money();
}
if (amt < 0) amt = 0;
if (amt > MAX_COINS) amt = MAX_COINS;
if (me)
{
if (amt > me->query_money()) return;
me->add_money(-amt);
}
mon = MONEYER->make(amt, me);
return mon;
}