object petbrain; method className() { return $petbrain; } method superClass() { } method receiveDescripton(d) { if (!arrayp(*$owner)) *$owner = list(); if (arrayp(d)) action(d[0], d, *$body); } method init(b) { *$body = b; *$owner = list(); addConnection(b, me); } method isOwner(x) { return listFind(*$owner, x) >= 0; } method parent() { return parent(*$body); } method ownerPresent() { int i; array a; a = contents(parent()); for (i=0; i < length(a); ++i) if (isOwner(a[i])) return 1; } method canTake() { if (!length(*$owner)) *$owner = list(player); return !isOwner(me,player); } method canDrop() { } method canTakeFrom() { return 1; } method canPutIn() { return 1; } method canPut() { return listFind(*$owner, player) == -1; } method actSpeak(actor, speech) { string s,t; int i; array a; if (actor == *$body) return; if (!random(3)) return; if (!isOwner(me, actor)) return; i = index(speech, ","); if (i < 0) return; s = extract(speech, 0, i); t = extract(speech, i+1); if (t[0] == ' ') t = extract(t,1); i = index(s, " "); if (i >= 0) a = sort(tokenize(kernel, s)); else a = list(string2prop(s)); if (!id(*$body, a)) return; if (!strncasecmp(t, "come ", 5) && distance(caller)) { command(*$body, list(dir(caller))); } else if (!strncasecmp(t, "give me ",8)) { command(*$body, "give " + extract(t,8) + " to " + title(actor)); } else command(*$body, t); } method actMove(actor, what, where) { if (distance(caller)) return; if (actor != what && !isOwner(me, actor) && where == parent()) { command(*$body, list($get, what)); } } method actArrive(actor, d) { if (distance(caller)) { if (isOwner(me, actor)) { if (!ownerPresent() || !random(3)) command(*$body, list(dir(caller))); } } else { if (random(2) && listFind(*$owner, actor)>=0) command(*$body, list($hug, actor)); } } method actLeave(actor, dir) { if (distance(caller)) return; if ((listFind(*$owner,actor)>=0 && random(10)) || (!length(*$owner) && !random(3))) command(*$body, list(dir)); } method actAttack(attacker, target, dam, type, mode, weapon) { actEmote(me, attacker, $unfriendly, $attack, target); } method actEmote(who, style, atmos, target1, target2) { int w,t; w = listFind(*$owner, who) + 1; t = target1 && listFind(*$owner, target1)+1; if (style == $unfriendly) { if (w && target1 == *$body) { listRemove(*$owner, who); command(*$body, "say You're mean! I don't like you no more."); } else if (t && w) { if (w > t) { t = target1; target1 = who; who = t; } listRemove(*$owner, target1); command(*$body, "say I guess if you don't like each other, I'll stick with " + def(who) + "."); } else if (!distance(caller) && w && random(2)) command(*$body, list($slash, target1)); else if (!distance(caller) && t && random(2)) { command(*$body, list($slash, who)); } else if (target1 == *$body) command(*$body, list($slash, who)); } else if (style == $friendly) { if (t && w) { } else if (w && target1 != *$body) { queueAdd(*$owner, target1); command(*$body, "say Gosh, if " + def(who) + " likes you, I guess I do too."); } else if (t && who != *$body) /* You are nice to my friend. I'll be nice to you. */ command(*$body, list($hug, who)); else if (!w && target1 == *$body) /* I don't like you and you're being nice to me. I'm a bitch */ command(*$body, list($slap, who)); } } method actDo(actor, action, arg1, arg2) { if (action == $offer) { if (distance(caller) || !isOwner(me, actor)) return; if (arg2 != *$body) return; command(*$body, list($get, arg1, $from, actor)); } }