class Demiurge::ActionItemInternal::EveryXTicksIntention

This is a simple Intention that performs a particular action every so many ticks. It expects its state to be set up via the DSL Builder classes.

@since 0.0.1

Public Class Methods

new(engine, name) click to toggle source
Calls superclass method
# File lib/demiurge/action_item.rb, line 605
def initialize(engine, name)
  @name = name
  super(engine)
end

Public Instance Methods

allowed?() click to toggle source
# File lib/demiurge/action_item.rb, line 610
def allowed?
  true
end
apply() click to toggle source
# File lib/demiurge/action_item.rb, line 632
def apply
  item = @engine.item_by_name(@name)
  everies = item.state["everies"]
  everies.each do |every|
    every["counter"] += 1
    if every["counter"] >= every["every"]
      item.run_action(every["action"])
      every["counter"] = 0
    end
  end
end
cancel_notification() click to toggle source

Shouldn't normally happen, but just in case…

# File lib/demiurge/action_item.rb, line 620
def cancel_notification
  # "Silent" notifications are things like an agent's action queue
  # being empty so it cancels its intention.  These are normal
  # operation and nobody is likely to need notification every
  # tick that they didn't ask to do anything so they didn't.
  return if @cancelled_info && @cancelled_info["silent"]
  item = @engine.item_by_name(@name)
  @engine.send_notification({ reason: @cancelled_reason, by: @cancelled_by, id: @intention_id, intention_type: self.class.to_s },
                            type: Demiurge::Notifications::IntentionCancelled, zone: item.zone_name, location: item.location_name, actor: item.name,
                            include_context: true)
end
offer() click to toggle source

For now, empty. Later we'll want it to honor the offer setting of the underlying action.

# File lib/demiurge/action_item.rb, line 616
def offer
end