# File cash.rb # Author: Craig Smith # # General Cash 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' # Special Cash object to represent money class Cash < GameObject include GetText bindtextdomain("core") attr_accessor :cname, :cdesc # 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) money = _("money") cash = _("cash") self.name = cash self.cost = 1 # Cash should be at least 1 dollar self.aliases = [ money ] self.cname = _("a dollar") # Short name self.cdesc = _("a dollar") # Descriptive name end # Routine to check current cost attribute and set cname and cdesc def set_desc case cost when 0 log.warn "Cash object with a cost value of 0. Should not exist. Deleting" self.unused = true self.location = nil get_object(location).delete_contents id return when 1 self.cname = _("a dollar") self.cdesc = _("A dollar is on the ground.") when 2..5 self.cname = _("a few dollars") self.cdesc = _("A few dollars is on the ground.") when 6..20 self.cname = _("a stack of cash") self.cdesc = _("A small pile of money is on the ground.") when 21..50 self.cname = _("a roll of cash") self.cdesc = _("A nice roll of cash is on the ground.") else self.cname = _("a large stack of cash") self.cdesc = _("A large pile of money is on the ground.") end end def shortname set_desc cname end # Uses the cost attribute to represent how much money this is def describe(e) ch = get_object(e.from) set_desc msg = mxptag("GroundObj '#{name}' '#{cname}'") + "[color Yellow]" msg << "(#{id}) " if ch.get_stat(:debugmode) == true msg << cdesc msg << "[/color]" + mxptag("/GroundObj") add_event(id, e.from, :show, msg) end # Getting cash is different because the object goes away and you get stats[:cash] def get(e) if has_attribute? :buried add_event(id,e.from,:show, _("You do not see that here.")) return end plyr = get_object(e.from) place = get_object(location) from_cont = false from_cont = true if place.kind_of? Container if not place.kind_of? Room and not place.kind_of? Container place = get_object(plyr.location) end # remove it place.delete_contents(id) self.unused = true self.location = nil # add it plyr.adjust_stat(:cash, cost) set_desc if from_cont add_event(id,e.from,:show, _("You get %{amt} dollars from %{place}." % {:amt => cost, :place => place.shortname})) add_event(e.from,e.from,:roomsay, _("%{person} gets %{obj} from %{place}" % {:person => plyr.name, :obj => cname, :place => place.shortname})) else add_event(id,e.from,:show, _("You get %{amt} dollars." % {:amt => cost})) add_event(e.from,e.from,:roomsay, _("%{person} picks up %{obj}" % {:person => plyr.name, :obj => cname})) end end end