Class: Goby::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/goby/item/item.rb

Overview

Can be used by an Entity in order to trigger anything specified. Placed into the Entity’s inventory.

Direct Known Subclasses

Food, Helmet, Legs, Shield, Torso, Weapon

Constant Summary collapse

DEFAULT_USE_TEXT =

Default text when the Item doesn’t do anything.

"Nothing happens.\n\n"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: "Item", price: 0, consumable: true, disposable: true) ⇒ Item

Returns a new instance of Item.

Parameters:

  • name (String) (defaults to: "Item")

    the name.

  • price (Integer) (defaults to: 0)

    the cost in a shop.

  • consumable (Boolean) (defaults to: true)

    upon use, the item is lost when true.

  • disposable (Boolean) (defaults to: true)

    allowed to sell or drop item when true.



14
15
16
17
18
19
# File 'lib/goby/item/item.rb', line 14

def initialize(name: "Item", price: 0, consumable: true, disposable: true)
  @name = name
  @price = price
  @consumable = consumable
  @disposable = disposable
end

Instance Attribute Details

#consumableObject

Returns the value of attribute consumable.



39
40
41
# File 'lib/goby/item/item.rb', line 39

def consumable
  @consumable
end

#disposableObject

Returns the value of attribute disposable.



39
40
41
# File 'lib/goby/item/item.rb', line 39

def disposable
  @disposable
end

#nameObject

Returns the value of attribute name.



39
40
41
# File 'lib/goby/item/item.rb', line 39

def name
  @name
end

#priceObject

Returns the value of attribute price.



39
40
41
# File 'lib/goby/item/item.rb', line 39

def price
  @price
end

Instance Method Details

#==(rhs) ⇒ Object

Parameters:

  • rhs (Item)

    the item on the right.



30
31
32
# File 'lib/goby/item/item.rb', line 30

def ==(rhs)
  return @name.casecmp(rhs.name).zero?
end

#to_sString

Returns the name of the Item.

Returns:

  • (String)

    the name of the Item.



35
36
37
# File 'lib/goby/item/item.rb', line 35

def to_s
  @name
end

#use(user, entity) ⇒ Object

The function that executes when one uses the item.

Parameters:

  • user (Entity)

    the one using the item.

  • entity (Entity)

    the one on whom the item is used.



25
26
27
# File 'lib/goby/item/item.rb', line 25

def use(user, entity)
  print DEFAULT_USE_TEXT
end