Class: Adventure::NPC
- Inherits:
-
Object
- Object
- Adventure::NPC
- Defined in:
- lib/adventure/npc.rb
Overview
Represents an ingame Non-Playable Character (NPC).
Defined Under Namespace
Modules: FriendshipLevel
Instance Attribute Summary collapse
-
#dialogue ⇒ Array<Hash>
The NPC's list of conversation options.
-
#friendship ⇒ Object
readonly
Returns the value of attribute friendship.
-
#gender ⇒ Object
readonly
Returns the value of attribute gender.
-
#inventory ⇒ Object
readonly
Returns the value of attribute inventory.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#purse ⇒ Object
readonly
Returns the value of attribute purse.
-
#species ⇒ Object
readonly
Returns the value of attribute species.
Instance Method Summary collapse
-
#charm ⇒ Integer
Bump the NPC's friendship level by
1, to a maximum of5. -
#initialize(name, species, gender, **opts) ⇒ NPC
constructor
Create a new instance of NPC.
-
#offend ⇒ Integer
Nerf the NPC's friendship level by
1, to a minimum of1. -
#to_i ⇒ Integer
Return an Integer as the NPC's friendship level towards the Player.
-
#to_s ⇒ String
Return a String with the NPC's name, gender, and species.
Constructor Details
#initialize(name, species, gender, **opts) ⇒ NPC
Create a new instance of NPC.
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/adventure/npc.rb', line 52 def initialize(name, species, gender, **opts) # Mandatory parameters. @name = name.strip @species = species.strip.capitalize @gender = gender.strip.capitalize # Optional parameters. @friendship = opts.key?(:friendship) ? opts[:friendship].to_i : FriendshipLevel::NEUTRAL @purse = opts.key?(:purse) ? opts[:purse] : nil @purse = Purse.new unless @purse.is_a? Purse @inventory = opts.key?(:inventory) ? opts[:inventory] : nil @inventory = Inventory.new unless @inventory.is_a? Inventory @dialogue = opts.key?(:dialogue) ? opts[:dialogue].to_a : [] end |
Instance Attribute Details
#dialogue ⇒ Array<Hash>
Returns The NPC's list of conversation options. Each Hash must contain exactly two entries: a question and a reply.
26 27 28 |
# File 'lib/adventure/npc.rb', line 26 def dialogue @dialogue end |
#friendship ⇒ Object (readonly)
Returns the value of attribute friendship.
17 18 19 |
# File 'lib/adventure/npc.rb', line 17 def friendship @friendship end |
#gender ⇒ Object (readonly)
Returns the value of attribute gender.
14 15 16 |
# File 'lib/adventure/npc.rb', line 14 def gender @gender end |
#inventory ⇒ Object (readonly)
Returns the value of attribute inventory.
23 24 25 |
# File 'lib/adventure/npc.rb', line 23 def inventory @inventory end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/adventure/npc.rb', line 8 def name @name end |
#purse ⇒ Object (readonly)
Returns the value of attribute purse.
20 21 22 |
# File 'lib/adventure/npc.rb', line 20 def purse @purse end |
#species ⇒ Object (readonly)
Returns the value of attribute species.
11 12 13 |
# File 'lib/adventure/npc.rb', line 11 def species @species end |
Instance Method Details
#charm ⇒ Integer
Bump the NPC's friendship level by 1, to a maximum of 5.
83 84 85 86 |
# File 'lib/adventure/npc.rb', line 83 def charm @friendship += 1 unless @friendship >= 5 @friendship end |
#offend ⇒ Integer
Nerf the NPC's friendship level by 1, to a minimum of 1.
91 92 93 94 |
# File 'lib/adventure/npc.rb', line 91 def offend @friendship -= 1 unless @friendship <= 1 @friendship end |
#to_i ⇒ Integer
Return an Integer as the NPC's friendship level towards the Player.
76 77 78 |
# File 'lib/adventure/npc.rb', line 76 def to_i @friendship end |
#to_s ⇒ String
Return a String with the NPC's name, gender, and species.
69 70 71 |
# File 'lib/adventure/npc.rb', line 69 def to_s "#{@name}, #{@gender.downcase} #{@species.downcase}" end |