Class: Goby::Chest

Inherits:
Event
  • Object
show all
Defined in:
lib/goby/event/chest.rb

Overview

A chest containing gold and/or items.

Constant Summary

Constants inherited from Event

Event::DEFAULT_RUN_TEXT

Instance Attribute Summary collapse

Attributes inherited from Event

#command, #mode, #visible

Instance Method Summary collapse

Methods inherited from Event

#==

Constructor Details

#initialize(mode: 0, visible: true, gold: 0, treasures: []) ⇒ Chest

Returns a new instance of Chest.

Parameters:

  • mode (Integer) (defaults to: 0)

    convenient way for a chest to have multiple actions.

  • visible (Boolean) (defaults to: true)

    whether the chest can be seen/activated.

  • gold (Integer) (defaults to: 0)

    the amount of gold in this chest.

  • treasures ([Item]) (defaults to: [])

    the items found in this chest.



12
13
14
15
16
17
# File 'lib/goby/event/chest.rb', line 12

def initialize(mode: 0, visible: true, gold: 0, treasures: [])
  super(mode: mode, visible: visible)
  @command = "open"
  @gold = gold
  @treasures = treasures
end

Instance Attribute Details

#goldObject (readonly)

Returns the value of attribute gold.



29
30
31
# File 'lib/goby/event/chest.rb', line 29

def gold
  @gold
end

#treasuresObject (readonly)

Returns the value of attribute treasures.



29
30
31
# File 'lib/goby/event/chest.rb', line 29

def treasures
  @treasures
end

Instance Method Details

#run(player) ⇒ Object

The function that runs when the player opens the chest.

Parameters:

  • player (Player)

    the one opening the chest.



22
23
24
25
26
27
# File 'lib/goby/event/chest.rb', line 22

def run(player)
  type("You open the treasure chest...\n\n")
  sleep(1) unless ENV['TEST']
  player.add_loot(@gold, @treasures)
  @visible = false
end