Module: Petli::Pet::Happy

Extended by:
Tatty::DB::Attributes
Included in:
Petli::Pet
Defined in:
lib/petli/pet/happy.rb

Constant Summary collapse

MOOD_SCALE =
%i(angry annoyed normal happy great)

Instance Method Summary collapse

Methods included from Tatty::DB::Attributes

db_attr

Instance Method Details

#loseObject



29
30
31
# File 'lib/petli/pet/happy.rb', line 29

def lose
  # todo I dont really want it to become more unhappy if they lose
end

#play(game: :dice) ⇒ Object



20
21
22
23
# File 'lib/petli/pet/happy.rb', line 20

def play(game: :dice)
  self.last_play = Time.now
  react(:stand)
end

#update_happinessObject



11
12
13
14
15
16
17
18
# File 'lib/petli/pet/happy.rb', line 11

def update_happiness
  for_hours_since(last_play) do |i|
    self.last_play = Time.now
    next if rand <= 0.3
    self.happiness = [[1, self.happiness-1].max, self.health <= 3 ? 5 : 10].min
  end
  self.mood = MOOD_SCALE[((self.happiness.to_f/10.0)*(MOOD_SCALE.count - 1)).floor]
end

#winObject



25
26
27
# File 'lib/petli/pet/happy.rb', line 25

def win
  self.happiness = [10, self.happiness+1].min
end