Class: FFXI::VanaMoon

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/Vana/moon.rb

Constant Summary collapse

MOON_PHASES =
["Full", "Waning Gibbous", "Last Quarter", "Waning Crescent",
"New Moon", "Waxing Crescent", "First Quarter", "Waxing Gibbous"]

Constants included from Constants

Constants::BASIS_DATE, Constants::DAY, Constants::HOUR, Constants::MINUTE, Constants::MOON_DATE, Constants::MS_BASIS_DATE, Constants::MS_BASIS_VANA, Constants::MS_DAY, Constants::MS_GAME_DAY, Constants::MS_HOUR, Constants::MS_MINUTE, Constants::MS_MOON_DATE, Constants::MS_SECOND

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time = Time.now) ⇒ VanaMoon

Returns a new instance of VanaMoon.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/Vana/moon.rb', line 8

def initialize(time = Time.now)
  localtime = (time.to_f * 1000).to_i
  # Each lunar cycle takes exactly 84 game days
  # (3 days, 8 hours, 38 minutes, 24 seconds)
  @moon_days = ((localtime - MS_MOON_DATE.to_i) / MS_GAME_DAY).floor % 84
  @moon_percent = - ((42 - @moon_days).to_f / 42 * 100).round
  @elapsed_time = (localtime - MS_MOON_DATE.to_i) % MS_GAME_DAY

  case @moon_percent
  when (-100..-94)
    @moon_phase = 0
    @next_phase_target = 3
  when (90..100)
    @moon_phase = 0
    @next_phase_target = 3 + 84
  when (-93..-62)
    @moon_phase = 1
    @next_phase_target = 17
  when (-61..-41)
    @moon_phase = 2
    @next_phase_target = 25
  when (-40..-11)
    @moon_phase = 3
    @next_phase_target = 38
  when (-10..6)
    @moon_phase = 4
    @next_phase_target = 45
  when (7..36)
    @moon_phase = 5
    @next_phase_target = 58
  when (37..56)
    @moon_phase = 6
    @next_phase_target = 66
  when (57..89)
    @moon_phase = 7
    @next_phase_target = 80
  end

  case @moon_phase
  when (0..3)
    @next_optimal_phase = 4
    @optimal_phase_target = 38
    @optimal_phase_target += 84 if (90..100).include? @moon_percent
  when (4..7)
    @next_optimal_phase = 0
    @optimal_phase_target = 80
  end
end

Instance Attribute Details

#elapsed_timeObject (readonly)

Returns the value of attribute elapsed_time.



57
58
59
# File 'lib/Vana/moon.rb', line 57

def elapsed_time
  @elapsed_time
end

#moon_daysObject (readonly)

Returns the value of attribute moon_days.



57
58
59
# File 'lib/Vana/moon.rb', line 57

def moon_days
  @moon_days
end

Instance Method Details

#next_phaseObject



83
84
85
# File 'lib/Vana/moon.rb', line 83

def next_phase
  MOON_PHASES[(@moon_phase + 1) % 8]
end

#optimal_phaseObject



95
96
97
# File 'lib/Vana/moon.rb', line 95

def optimal_phase
  MOON_PHASES[@next_optimal_phase]
end

#percentObject



63
64
65
# File 'lib/Vana/moon.rb', line 63

def percent
  "#{@moon_percent.abs}%"
end

#phaseObject



67
68
69
# File 'lib/Vana/moon.rb', line 67

def phase
  MOON_PHASES[@moon_phase]
end

#to_iObject



59
60
61
# File 'lib/Vana/moon.rb', line 59

def to_i
  @moon_percent
end

#to_nextObject



79
80
81
# File 'lib/Vana/moon.rb', line 79

def to_next
  format_countdown(to_next_array)
end

#to_next_arrayObject



75
76
77
# File 'lib/Vana/moon.rb', line 75

def to_next_array
  countdown_to(@next_phase_target)
end

#to_optimalObject



91
92
93
# File 'lib/Vana/moon.rb', line 91

def to_optimal
  format_countdown(to_optimal_array)
end

#to_optimal_arrayObject



87
88
89
# File 'lib/Vana/moon.rb', line 87

def to_optimal_array
  countdown_to(@optimal_phase_target)
end

#to_sObject



71
72
73
# File 'lib/Vana/moon.rb', line 71

def to_s
  "#{percent} #{phase}"
end