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_split.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")

  # Splits money amount amongst group members
  def cmd_split(args)
	case args
	when "", nil
		sendto _("How much do you want to split amongst your group?")
	when /(\d+)/
		money = $1.to_i
		ppl = []
		# If we are not the leader use the leaders group list
		if @group_leader and not @group_leader == id
			group = get_object(@group_leader).group_members
			ppl << @group_leader
		else
			group = @group_members
		end
		# Only people in room from the group get paid
		group.each { |pid| ppl << pid if get_object(pid).location == location }
		# Include ourselves in the math
		ppl << id if not ppl.include? id
		if ppl.size > 1
			if get_stat(:cash) >= money
				if money >= ppl.size
					# Round down
					money -= (money % ppl.size)
					amt = money / ppl.size
					ppl.each do |gid|
					   if not gid == id
						groupie = get_object(gid)
						adjust_stat(:cash, -amt)
						groupie.adjust_stat(:cash, amt)
						msg = _("%{name} splits %{total} dollars and you get %{amt} dollars." % {:name => name, :total => money, :amt => amt})
						add_event(id, groupie.id, :show, msg)
					   end
					end
					msg = _("You split %{total} dollars %{size} ways, giving out %{amt} each." % {:total => money, :size => ppl.size, :amt => amt})
					add_event(id, id, :show, msg)
				else
					sendto _("You do not have enough to split %{size} ways." % {:size => ppl.size})
				end
			else
				sendto _("You do not have enough money.")
			end
		else
			sendto _("You have nobody in your group to split it with.")
		end
	else
		sendto _("Usage: split <amount>")
	end
  end

end