-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.rb
88 lines (73 loc) · 1.28 KB
/
event.rb
1
2
3
4
5
6
7
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class Event
ATTITUDE = [:hard, :normal, :ignore]
TYPES = %i(exam work fun love morework danger)
def initialize(args)
@params = args
raise 'need params' unless @params
t = @params[:type]
@is_choice = false
@how_hard = rand(100)
extend Object.const_get("EventCore::#{t.capitalize}")
end
def params
{
money: money,
age: age,
health: health,
eq: eq,
charm: charm,
how_hard: how_hard,
type: type
}
end
def choice(method)
if !@is_choice and ATTITUDE.include?(method)
send(method)
@is_choice = true
@choice = method
end
end
def human_result
"#{type} is #{@how_hard} hard choice #{@choice} is#{ ' not' unless success?} successs, get #{result}"
end
def health
@params[:health]
end
def charm
@params[:charm]
end
def money
@params[:money]
end
def age
@params[:age]
end
def how_hard
@how_hard
end
def type
@params[:type]
end
def eq
@params[:eq]
end
def money
@params[:money]
end
private
def iq
@params[:iq]
end
def rp
@params[:rp]
end
def rand_rp
rand(1..rp)
end
def success?
@actual_value + rand_rp >= how_hard
end
def calculate_happy
(@how_hard * @happy_rate).round
end
end