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

  # Replicates changes to a parent object to all clones
  def cmd_replicate(args)
	case args
	when /#(\d+)/
		pid = $1.to_i
		parent = get_object(pid)
		if parent
			if parent.is_a? Account or (parent.is_a? Character and not parent.is_a? Mobile)
				sendto _("Invalid Object type")
				return
			end
			if not parent.isclone
				count =0
				objs = world.find_objects(parent.name)
				objs.each do |o|
					if o.parentid == parent.id
						# Replicate some data
						o.name = parent.name.dup
						o.desc = parent.desc.dup
						o.aliases = parent.aliases.dup
						o.weight = parent.weight
						o.cost = parent.cost

						# These may have been altered from use
						o.attributes = o.attributes.concat(parent.attributes).uniq
						o.val.merge!(parent.val)
						o.modifier.merge!(parent.modifier)
						count += 1
						if parent.is_a? Mobile
							o.skills = parent.skills.dup
							# Only replicate some stats
							o.set_stat(:exp, parent.get_stat(:exp))
							o.set_stat(:intel, parent.get_stat(:intel))
							o.set_stat(:strength, parent.get_stat(:strength))
							o.set_stat(:endurance, parent.get_stat(:endurance))
							o.set_stat(:maxhp, parent.get_stat(:maxhp))
							o.set_stat(:maxmp, parent.get_stat(:maxmp))
							o.set_stat(:level, parent.get_stat(:level))
							o.set_stat(:cash, parent.get_stat(:cash))
						end
						if parent.is_a? Merchant
							o.forsale = parent.forsale.dup
							o.buytype = parent.buytype.dup
							o.buyattribute = parent.buyattribute.dup
							o.buydtype = parent.buydtype.dup
							o.markup = parent.markup
						end
					end
				end
				sendto _("Replicated to %{count} objects." % {:count => count})
			else
				sendto _("You must specify the original parent Oid.")
			end
		else
			sendto _("Invalid Oid.")
		end
	else
		sendto _("Usage: @replicate #oid - Replicates parent object changes to all clones")
	end
  end

end