#!/usr/bin/perl
# This needs to be stackless for destroy to work.
#use Mooix::Verb;
run sub {
	my $this=shift;
	%_=@_;
	my $avatar=$_{avatar};
	
	my $massspread = $this->startmass - $this->endmass;
	my $delta = $massspread / $this->max;
        my $current = $this->mass / $delta;
	
	if ($current < 1) {
		# If no direct object was specified, then the user just
		# said "eat" or "drink" or something, and since this one is
		# used up, let the parser try another.
		if (! $_{direct_object}) {
			exit Mooix::Verb::SKIP;
		}
		fail "It's all used up.";
	}
	if (! $_{notake}) {
		# take the consumable
	        if ($this->location != $avatar) {
			$this->take_verb(%_);
		}
		if ($this->location != $avatar) {
			fail "You must be holding that."
		}
	}

	$current--;
	$this->mass($current * $delta + $this->endmass);
	$this->used(1);
	
	# Run consume method if it exists.
	if ($this->implements("consume")) {
		$this->consume(@_);
	}
	$this->msg('consume', %_);
	if ($current < 1) {
		# The object is totally consumed.
		$this->msg('consumed', %_);
		if ($this->endmass && ($this->endvolume || ! $this->changevolume)) {
			$this->mass($this->endmass);
			$this->volume($this->endvolume) if $this->endvolume;
			$this->adjective("empty");
			# Run finished method if it exists
			if ($this->implements("finished")) {
				$this->finished(@_);
			}
		}
		else {
			$this->destroy(quiet => 1);
		}
	}
}
