#!/usr/bin/perl
#use Mooix::Thing;
run sub {
	my $this=shift;
	%_=@_;
	my $avatar=$_{avatar};
	my $target=$_{indirect_object};

	# If no target is specified, or sometimes at random (should be
	# dependant on the avatar's dexterity and the object's size and
	# target's size and distance..), pick some object to be the target.
	if ($target == $avatar) {
		fail "Throw it at yourself?";
	}
	if (! $target || rand > 0.5) {
		my @objs=grep { ! $_->hidden && $_ != $avatar && $_ != $this }
			$avatar->location->contents->list;
		$target=$objs[rand($#objs)];
	}
	if (! $target) {
		$target=$avatar->location;
	}

	if ($this->location != $avatar) {
		fail "You are not holding that.";
	}
	$this->msg('throw', %_);
	$this->throw(target => $target) if $this->background;
}
