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::    cmd_give.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")

  # give an item from inventory to another player in the same room
  def cmd_give(args)
    to_keyword = _("to")
    money_keyword = _("dollars")
    case args
    when /(\d+)\s+#{money_keyword}\s+#{to_keyword}\s+(.+)/,
	/\$(\d+)\s+#{to_keyword}\s+(.+)/
	amount = $1.to_i
	whom = $2
	if amount <= get_stat(:cash)
		ppl = peopleinroom(whom)
		case ppl.size
		when 0
			sendto _("Nobody here by that name.")
		when 1
			to = ppl[0]
			adjust_stat(:cash, -amount)
			to.adjust_stat(:cash, amount)
			sendto _("You give %{name} %{amt} dollars." % {:name => to.name, :amt => amount})
			msg = Msg.new _("^p1 gives you %{amt} dollars." % {:amt => amount})
			msg.p1 = name
			add_event(id, to.id, :show, msg)
			msg = Msg.new _("^p1 gives ^p2 ^o1.")
			msg.p1 = name
			msg.p2 = to.name
			msg.o1 = _("%{amt} dollars" % {:amt => amount})
			add_event(to.id, id, :showrest, msg)
		else
			sendto _("Which one?")
		end
	else
		sendto _("You do not have that much money.")
	end
    when /(.+)\s+#{to_keyword}\s+(.+)/
	what = $1
	whom = $2
	objs = find_inv(what)
	if objs.size > 0
		ppl = peopleinroom(whom)
		case ppl.size
		when 0
			sendto _("Nobody here by that name")
			return
		when 1
			to = ppl[0]
		   	objs.each do |obj|
				add_event(id,to.id,:give,obj.id)
		   	end
		else
			sendto _("Which one?")
			return
		end
	else
       		sendto _("You are not carrying %{item}" % {:item => what})
	end
    else
        sendto _("Give what and to whom?")
    end
  end

end