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::    spawn.rb
# Author:   Craig Smith

# 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.
#

$:.unshift "lib" if !$:.include? "lib"

require 'storage/properties'

# A Spawn object is used to spawn a new game object or mobile in a given
# Room.
class Spawn < Root
  logger 'DEBUG'

  property :targetid, :max, :frequency, :inv, :wear, :wield, :location, :max_in_room
  attr_accessor :tickcnt
  # [+targetid+] TargetID of what to spawn
  # [+owner+]    The displayed name of the Container.
  # [+return+]  A handle to the new Container.
  def initialize(targetid, owner)
    super(nil, owner)
    self.targetid = targetid
    self.max = 1	# Max that can exists in the game
    self.max_in_room = 1 # Max that can exist in a room at a time
    self.frequency=12	# Game ticks until spawn
    @tickcnt=0		# Current tick count
    self.inv = []	# List of items in inventory
    self.wear = []      # List of items worn
    self.wield = []	# List of items weilded
    self.location = nil # Where is this spawn point
  end

  # Loads the target object
  # [+return+] Returns the loaded object
  def load
  	@tickcnt = 0 if not @tickcnt
  	@tickcnt += 1
	if @tickcnt < frequency
		return nil
	else
		@tickcnt = 0
	end
	live = world.find_active_objects(targetid)
	return nil if not live
	return nil if live.size >= max
	o  = world.load_object(targetid)
	if o
		inv.each do |i|
			obj = world.load_object(i)
			obj.location = o.id
			o.add_contents obj.id
		end
		wear.each do |a|
			obj = world.load_object(a)
			obj.location = o.id
			o.wear obj.id
		end
		wield.each do |w|
			obj = world.load_object(w)
			obj.location = o.id
			o.wield obj.id
		end
	else
		log.error "Could not spawn object id #{targetid}"
	end
	o
  end

end