PDA

View Full Version : Lich/Ruby capabilities?



Saurven
02-03-2012, 05:30 PM
So is it possible to do something like
wand = GameObj.loot.find{$container.content.find{/crystal wand|golden wand|metal wand/}}
to search through all your containers for those wands, or do ya hafta make $container and $wand arrays individually?

Jymamon
02-04-2012, 03:37 AM
Someone probably has something more clever, but this'll do:

;e wands = Array.new;GameObj.containers.each{|k,v| v.each{|i| wands.push(i) if i.noun=~/(?:crystal|golden|metal) wand/ } }; wands.each{|w| echo "- ##{w.id} -> #{w.to_s}" }

Gibreficul
02-04-2012, 02:07 PM
I didn't have any wands on me, so I added my "sorc gear" to the list of things to find...


wands ||= []
GameObj.inv.each{|item|
item.contents.find_all{|wand| wand.noun =~ /runestone|wand|chalk|book/}.each{|foundwand|
wands.push(foundwand)
}
}
wands.each{|item|;echo item.name}

Returns...

>;wnd
--- Lich: wnd active.
[wnd: some waxy translucent chalk]
[wnd: leather book]
[wnd: silver-bound peacock blue bankbook]
[wnd: some waxy translucent chalk]
[wnd: some fine crystalline chalk]
[wnd: some fine crystalline chalk]
[wnd: some fine crystalline chalk]
[wnd: some fine crystalline chalk]
[wnd: white marble runestone]
[wnd: marbled granite runestone]
[wnd: marbled granite runestone]
[wnd: white marble runestone]
[wnd: white marble runestone]
[wnd: white marble runestone]
[wnd: white marble runestone]
[wnd: marbled granite runestone]
--- Lich: wnd has exited.

Since I'm matching a regexp, bankbook matched book...

TO avoid that...


wands ||= []
GameObj.inv.each{|item|
item.contents.find_all{|wand| ["runestone", "wand", "chalk", "book"].include?(wand.noun)}.each{|foundwand|
wands.push(foundwand)
}
}
wands.each{|item|;echo item.name}

Saurven
02-04-2012, 02:34 PM
You rock, as always.

Jymamon
02-04-2012, 08:38 PM
Since I'm matching a regexp, bankbook matched book...

wand.noun =~ /\b(?:runestone|wand|chalk|book)\b/
will fix it and let you keep the regexp as well if you prefer such things. (I generally do.)

Saurven
02-04-2012, 09:12 PM
Outstanding. Thank you!

DaCapn
02-04-2012, 09:54 PM
I didn't look over the whole conversation carefully, but I didn't notice anyone mentioning the `type` method which can be used on a game object. You might find this useful in these sort of situations. The types are defined in the gameobj-data.xml file (you could add your own and remove the file from the update list as well).

Here's an example:

GameObj.right_hand.contents.find_all { |obj| obj.type =~ /wand/ }.each { |obj| fput "_drag ##{obj.id} ##{GameObj[Lich.lootsack].id}" }

Here's a more generalized version that I use:



$library_deflist['move_objs'] = ['utility','Moves objects of a type from container in right hand to new container; (type,num,container)']
def move_objs(type,num,container)
fput "open ##{GameObj.right_hand.id}"
if num =~ /all/
GameObj.right_hand.contents.find_all { |obj| obj.type =~ /#{type}/i }.each { |obj|
fput "_drag ##{obj.id} ##{GameObj[container].id}"
}
else num.times { fput "_drag ##{GameObj.right_hand.contents.find{ |obj| obj.type =~ /#{type}/i }.id} ##{GameObj[container].id}" }
end
end