#!/usr/bin/perl
#use Mooix::Root;
#use Mooix::Thing;
run sub {
	my $this=shift;
	my $damage=shift;
	
	my $fall=0;
	if ($this->flying) {
		$this->hp_regen;
		my $hitpoints=$this->hitpoints;
		if ($hitpoints - $damage <= 0) {
			$damage++; # a bit more for the fall
			$fall=1;
		}
	}
	
	$this->super($damage);
	
	if ($fall && $this->flying) {
		# undo fly method
		$this->defense($this->_origdefense);
		$this->flying(0);
		$this->msg("fall");
		$Mooix::Root->system->init->unregister(object => $this,
			from => 'startup');
	}
	elsif ($this->hitpoints > 0) {
		$this->panic if $this->background;
	}
}
