food.rb
znmud-0.0.1/lib/core/food.rb · 1.9 KB
From the archive znmud-minimal-0.0.1.tar.gz
Download the archive « Back to the archive contents
# File food.rb
# Author: Craig Smith
#
# General Food object
# 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.
#
require 'gettext'
# Supported Attribute
# :poison => true if food is poisoned
# :no_rot => true if food does not rot
# Supported Values
# :hunger => amount of hunger to fulfill
#
class Food < GameObject
include GetText
bindtextdomain("core")
property :rot_ticks
# Create a new Object
# [+name+] Every object needs a name
# [+owner+] The owner id of this object
# [+location+] The object id containing this object or nil.
# [+return+] A handle to the new Object
def initialize(name, owner, location=nil)
super(name,owner,location)
self.rot_ticks = 1440 # Two hours in a Conatiner is the best
end
def reset
self.rot_ticks = 1440 # Two hours in a Conatiner is the best
end
# Event :rot
# [+e+] Event info
# [+return+] Undefined
def rot(e)
return if not location
return if location == 0
return if has_attribute? :no_rot
mod = 3
loc = get_object(location)
# Do not rot if a mobile is carrying it
return if loc.kind_of? Mobile
# Rotting slows down if carrying
mod = 2 if loc.kind_of? Character
# If you store rotting food in a container it takes longer to rot
mod = 1 if loc.is_a? Container
self.rot_ticks -= mod
if rot_ticks < 1
case loc
when Character
loc.sendto _("%{item} spoils and rots in your hands." % {:item => shortname})
when Room
loc.say _("%{item} spoils and rots on the ground." % {:item => shortname})
when World
self.unused = true
return
else
# The user doesn't see it rot.
end
contents.each do |c|
loc.add_contents(c)
get_object(c).location = loc.id
delete_contents(c)
end
loc.delete_contents(id)
self.unused = true
self.location = nil
end
end
end