cmd_eat.rb

znmud-0.0.1/cmd/zombie/cmd_eat.rb · 1011 B

From the archive znmud-minimal-0.0.1.tar.gz

Download the archive   « Back to the archive contents

#
# file::    cmd_eat.rb

# 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.
#


module Cmd

  bindtextdomain("cmd")

  # The eat command
  def cmd_eat(args)
	case args
	when nil, ""
		sendto _("Eat what?")
	else
		# Search ground for corpses if zombie
		if has_attribute? :zombie or self.is_a? Zombie
			loc = get_object(location)
			objs = loc.find_objects(args)
			corpses = []
			objs.each { |o| corpses << o if o.is_a? Corpse }
			case corpses.size
			when 0
				sendto _("%{obj} is not a corpse." % {:obj => args})
			else # When more than one just eat the first corpse
				add_event(id, corpses[0].id, :eat)
			end
		else
			objs = find_inv(args)
			if objs.size > 0
				objs.each do |o|
					add_event(o.id, id, :eat)
				end
			else
				sendto _("You are not carrying %{args}" % {:args => args})
			end
		end
	end
  end

end

Site Stats

Snippets: 1791
Codebases: 571