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

	if ($this->wielded) {
		if ($this->location == $avatar) {
			fail "You're already wielding that.";
		}
		else {
			fail "Someone else is wielding that.";
		}
	}

	# Auto-take.
	if ($this->location != $avatar) {
		$this->take_verb(avatar => $avatar);
		if ($this->location != $avatar) {
			fail "You're not holding that.";
		}
	}

	if ($avatar->wield(object => $this) &&
	    $this->wielded(1) && $this->immobile(1)) {
		$this->msg("wield", %_);
	}
	else {
		# back out any changes made
		$avatar->unwield(object => $this);
		$this->wielded(0) if $this->wielded;
		$this->immobile(0) if $this->immobile;
		fail "You cannot wield that.";
	}
}
