#!/usr/bin/perl
#use Mooix::Thing;
run sub {
	my $this=shift;
	%_=@_;
	my $avatar=$_{avatar};
	
	# Separate contents into what is worn and what is held.
	my @holding, @wearing;
	my @contents=grep { ! $_->hidden } $this->contents->list;
	foreach (@contents) {
		if ($_->worn) {
			push @wearing, $_;
		}
		else {
			push @holding, $_;
			# The contents of some containers are visible
			# to just plain look.
			my @visi = $_->visiblecontents;
			if (@visi) {
				push @holding, @visi;
			}
		}
	}
	
	$_{contents}=$avatar->prettylist(grep { $_ != $avatar} @holding);
	# The reason I do it this way is so if the avatar has a description
	# that says they are wearing something, this doesn't contradict it
	# with a "wearing nothing".
	if (@wearing) {
		$_{contents} .= " and wearing ".$avatar->prettylist(@wearing);
	}
	$this->msg('look', %_);
	# If the object is injured, display an appropriate message.
	my $hp = $this->hitpoints;
	my $max = $this->maxhitpoints;
	if ($hp < $max) {
		$this->hp_regen;
		$hp = $this->hitpoints;
		# Still injured?
		if ($hp < $max) {
			my $injured;

			my $min=$this->minhitpoints;
			if ($hp <= $min) {
				$injured = "dead";
			}
			elsif ($hp <= ($min / 2) - 1) {
				$injured = "unconscious and near death";
			}
			elsif ($hp <= 0) {
				$injured = "unconscious";
			}
			elsif (($max - $hp) >= ($max / 1.5)) {
				$injured = "quite badly hurt";
			}
			elsif (($max - $hp) >= ($max / 2)) {
				$injured = "badly hurt";
			}
			elsif (($max - $hp) >= ($max / 3)) {
				$injured = "hurt";
			}
			elsif (($max - $hp) >= ($max / 4)) {
				$injured = "beat up";
			}
			elsif (($max - $hp) >= ($max / 5)) {
				$injured = "bruised";
			}
			else {
				$injured = "scratched";
			}
			
			$this->msg('injured', %_, injured => $injured);
		}
	}
	$this->msg('sleeping', %_) if $this->sleeping && $hp > 0;
}
