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

	# This verb can be called two ways, and what $this is varies. So
	# it's easiest to use the direct object as the object that is being
	# put, rather than $this.
	my $object=$_{direct_object};

	# Let's see if the avatar can even heft the object. If not, they
	# shouldn't be moveing it around.
	if ($object->_mass + $avatar->_mass > $avatar->maxweight) {
		fail "It's too heavy to move.";
	}

	my ($where, @preposition);
	if ($_{indirect_object}) {
		# "put object in object"
		$where = $_{indirect_object};
		
		# Adding this to the parameters of the move call below
		# gets it to check the preposition to see if it's valid.
		@preposition = (preposition => $_{io_preposition});

		# Check to see if the new location is the same, and the
		# preposition is the same as one of the objects existing
		# prepositions. If so, it's a no-op.
		if ($object->location == $where && 
		    grep { $_ eq $_{io_preposition} } $object->preposition ) {
			fail "It's already there.";
		}
	}
	else {
		# "put down object"
		if ($this->location != $avatar) {
			fail "You are not holding that.";
		}
		$where = $avatar->location;
	}

	if ($object->physics->move(object => $object, to => $where, @preposition)) {
		if ($_{indirect_object}) {
			my $prep = (length $_{io_preposition} ? $_{io_preposition} : ($object->preposition)[0]);
			$this->msg('put', %_, where => $where, prep => $prep." ");
		}
		else {
			$this->msg('put', %_, prep => $_{do_preposition})
		}
	}
	else {
		fail "You can't put that there.";
	}
}
