lib/demiurge/agent.rb
# Actually wander to an adjacent position, chosen randomly
Actually wander to an adjacent position, chosen randomly
Actually wander to an adjacent position chosen randomly
def apply
      agent = @engine.item_by_name(@name)
      agent.state["wander_counter"] += 1
      wander_every = agent.state["wander_every"] || 3
      return if agent.state["wander_counter"] < wander_every
      next_coords = agent.location.adjacent_positions(agent.position)
      if next_coords.empty?
        @engine.admin_warning("Oh no! Wandering agent #{@name.inspect} is stuck and can't get out!",
                             "zone" => agent.zone_name, "location" => agent.location_name, "agent" => @name)
        return
      end
      chosen = next_coords.sample
      pos = "#{agent.location_name}##{chosen.join(",")}"
      agent.move_to_position(pos, { "method" => "wander" })
      agent.state["wander_counter"] = 0
    end
def apply agent = @engine . item_by_name ( @name ) agent . state [ "wander_counter" ] += 1 wander_every = agent . state [ "wander_every" ] || 3 return if agent . state [ "wander_counter" ] < wander_every next_coords = agent . location . adjacent_positions ( agent . position ) if next_coords . empty? @engine . admin_warning ( "Oh no! Wandering agent #{@name.inspect} is stuck and can't get out!" , "zone" => agent . zone_name , "location" => agent . location_name , "agent" => @name ) return end chosen = next_coords . sample pos = "#{agent.location_name}##{chosen.join(",")}" agent . move_to_position ( pos , { "method" => "wander" } ) agent . state [ "wander_counter" ] = 0 end
Actually wander to an adjacent position, chosen randomly
Actually wander to an adjacent position chosen randomly