Class: Demiurge::ActionItemInternal::EveryXTicksIntention Private

Inherits:
Intention
  • Object
show all
Defined in:
lib/demiurge/action_item.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

Instance Method Summary collapse

Methods inherited from Intention

#apply_notification, #cancel, #cancelled?, #try_apply

Constructor Details

#initialize(engine, name) ⇒ EveryXTicksIntention

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of EveryXTicksIntention

Since:

  • 0.0.1



605
606
607
608
# File 'lib/demiurge/action_item.rb', line 605

def initialize(engine, name)
  @name = name
  super(engine)
end

Instance Method Details

#allowed?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.0.1



610
611
612
# File 'lib/demiurge/action_item.rb', line 610

def allowed?
  true
end

#applyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.0.1



632
633
634
635
636
637
638
639
640
641
642
# 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_notificationObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Shouldn't normally happen, but just in case...

Since:

  • 0.0.1



620
621
622
623
624
625
626
627
628
629
630
# 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

#offerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Since:

  • 0.0.1



616
617
# File 'lib/demiurge/action_item.rb', line 616

def offer
end