znmud-0.0.1/benchmark/
znmud-0.0.1/cmd/
znmud-0.0.1/cmd/emotes/
znmud-0.0.1/cmd/objects/
znmud-0.0.1/cmd/tiny/
znmud-0.0.1/doc/
znmud-0.0.1/farts/
znmud-0.0.1/lib/
znmud-0.0.1/lib/combat/
znmud-0.0.1/lib/core/bodytypes/
znmud-0.0.1/lib/engine/
znmud-0.0.1/lib/farts/
znmud-0.0.1/logs/
#
# file::    corpse.rb
# Author:   Craig Smith

# This source code copyright (C) 2009 Craig Smith
# All rights reserved.
#
# Released under the terms of the TeensyMUD Public License
# See LICENSE file for additional information.
#

$:.unshift "lib" if !$:.include? "lib"

require 'gettext'
require 'core/gameobject'
require 'storage/properties'

# This object doesn't do much but is a special object none the less
class Corpse < Container
  include GetText
  bindtextdomain("core")
  logger 'DEBUG'

  property :rot_ticks, :eaten

  MAX_EATEN = 5
  DEFAULT_ROT_TICKS = 25

  def initialize(name, owner, location)
    super(name, owner, location)
    add_attribute(:fixed)
    self.rot_ticks = DEFAULT_ROT_TICKS		# Tick count until decay
    self.eaten = 0		# Has corpse been eaten
    put_object(self)
  end

  # Trigger to describe a corpse
  # [+e+] Event info
  # [+return+] Undefined
  def describe(e)
	ch = get_object(e.from)
	o = get_object(owner)
	desc = ""
	desc = _("partially eaten ") if eaten > 0
	msg = "[COLOR Yellow]"
	msg << "(#{id}) " if ch.get_stat(:debugmode) == true
	msg << _("The %{desc}corpse of %{name} is here[/COLOR]" % {:desc => desc, :name => o.name})
	add_event(id, e.from, :show, msg)
  end

  # Resets the object back to it's original state
  def reset
	self.rot_ticks = DEFAULT_ROT_TICKS
	self.eaten = 0
	self.contents.clear
  end

  # Event :eat
  # [+e+] Event info
  # [+return+] Undefined
  def eat(e)
	ch = get_object(e.from)
	o = get_object(owner)
	room = get_object(location)
	self.eaten += 1
	ch.stats[:hunger] -= 50
	ch.stats[:hunger] = 0 if ch.stats[:hunger] < 0
	if eaten >= MAX_EATEN
		msg = Msg.new _("^p1 devours the corpse of %{name}" % {:name => o.name})
		msg.p1 = ch.name
		room.say(msg)
		contents.each do |c|
			room.add_contents(c)
			delete_contents(c)
		end
		room.delete_contents(id)
		self.unused = true
		self.location = nil
	else
		msg = Msg.new _("^p1 begins eating the corpse of %{name}" % {:name => o.name})
		msg.p1 = ch.name
		room.say(msg)
	end
  end

  # Event :rot
  # [+e+] Event info
  # [+return+] Undefined
  def rot(e)
	return if not location
	return if location == 0
	room = get_object(location)
	return if not room.is_a? Room  # Don't rot if something is odd
	self.rot_ticks -= 1
	if self.rot_ticks < 1
		o = get_object(owner)
		room.say(_("A horde of hungry maggots devour the corpse of %{name}" % {:name => o.name}))
		contents.each do |c|
			room.add_contents(c)
			delete_contents(c)
			get_object(c).location = location
		end
		room.delete_contents(id)
		self.unused = true
		self.location = nil
	end
  end
end