Class: Mgmg::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/mgmg/recipe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recipe, para = :power, name: nil, **kw) ⇒ Recipe



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/mgmg/recipe.rb', line 3

def initialize(recipe, para=:power, name: nil, **kw)
	@recipe = recipe
	@recipe.each(&:freeze) if @recipe.kind_of?(Enumerable)
	@recipe.freeze
	@para = para
	if name.nil?
		if recipe.kind_of?(String)
			@name = recipe
		else
			@name = recipe.join(' ')
		end
	else
		@name = name
	end
	@option = Option.new(**kw).set_default(@recipe)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



20
21
22
# File 'lib/mgmg/recipe.rb', line 20

def name
  @name
end

#paraObject

Returns the value of attribute para.



20
21
22
# File 'lib/mgmg/recipe.rb', line 20

def para
  @para
end

#recipeObject (readonly)

Returns the value of attribute recipe.



19
20
21
# File 'lib/mgmg/recipe.rb', line 19

def recipe
  @recipe
end

Instance Method Details

#build(smith = -1,, armor = smith, comp = armor.tap{armor=smith}, **kw) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/mgmg/recipe.rb', line 77

def build(smith=-1, armor=smith, comp=armor.tap{armor=smith}, **kw)
	opt = temp_opt(**kw)
	smith, armor, comp = opt.smith_min, opt.armor_min, opt.comp_min if smith.nil?
	case @recipe
	when String
		recipe.build(smith, comp, opt:)
	when Enumerable
		recipe.build(smith, armor, comp, opt:)
	else
		raise BrokenRecipeError
	end
end

#buster_optimize(smith = nil, comp = smith, **kw) ⇒ Object



184
185
186
187
188
189
190
191
# File 'lib/mgmg/recipe.rb', line 184

def buster_optimize(smith=nil, comp=smith, **kw)
	opt = temp_opt(**kw)
	if @recipe.kind_of?(String)
		@recipe.buster_optimize(smith, comp, opt:)
	else
		raise InvalidRecipeError, "Mgmg::Recipe#buster_optimize is available only for String recipes."
	end
end

#find_max(max_exp, para: @para, **kw) ⇒ Object



113
114
115
116
# File 'lib/mgmg/recipe.rb', line 113

def find_max(max_exp, para: @para, **kw)
	opt = temp_opt(**kw)
	@recipe.find_max(para, max_exp, opt:)
end

#initialize_copy(other) ⇒ Object



21
22
23
24
# File 'lib/mgmg/recipe.rb', line 21

def initialize_copy(other)
	@recipe = other.recipe.dup
	@option = other.option.dup
end

#ir(**kw) ⇒ Object



147
148
149
# File 'lib/mgmg/recipe.rb', line 147

def ir(**kw)
	temp_opt(**kw).irep
end

#max_weight(include_outsourcing = false) ⇒ Object



59
60
61
# File 'lib/mgmg/recipe.rb', line 59

def max_weight(include_outsourcing=false)
	@recipe.max_weight(opt: @option)
end

#min_compObject



74
75
76
# File 'lib/mgmg/recipe.rb', line 74

def min_comp
	@recipe.min_comp
end

#min_level(w = @option.target_weight, include_outsourcing = false) ⇒ Object



62
63
64
# File 'lib/mgmg/recipe.rb', line 62

def min_level(w=@option.target_weight, include_outsourcing=false)
	@recipe.min_level(w, include_outsourcing, opt: @option)
end

#min_levels(w = 1) ⇒ Object



65
66
67
# File 'lib/mgmg/recipe.rb', line 65

def min_levels(w=1)
	@recipe.min_levels(w, opt: @option)
end

#min_levels_max(w = 1) ⇒ Object



68
69
70
# File 'lib/mgmg/recipe.rb', line 68

def min_levels_max(w=1)
	@recipe.min_levels_max(w, opt: @option)
end

#min_smithObject



71
72
73
# File 'lib/mgmg/recipe.rb', line 71

def min_smith
	@recipe.min_smith
end

#min_weightObject



56
57
58
# File 'lib/mgmg/recipe.rb', line 56

def min_weight
	@recipe.min_weight(opt: @option)
end

#option(**kw) ⇒ Object



41
42
43
44
# File 'lib/mgmg/recipe.rb', line 41

def option(**kw)
	@option = temp_opt(**kw)
	@option
end

#option=(new_option) ⇒ Object



45
46
47
# File 'lib/mgmg/recipe.rb', line 45

def option=(new_option)
	@option = new_option.set_default(@recipe)
end

#para_call(smith = -1,, armor = smith, comp = armor.tap{armor=smith}, para: @para, **kw) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/mgmg/recipe.rb', line 135

def para_call(smith=-1, armor=smith, comp=armor.tap{armor=smith}, para: @para, **kw)
	opt = temp_opt(**kw)
	smith, armor, comp = correct_level(smith, armor, comp, opt)
	case @recipe
	when String
		opt.irep.para_call(para, smith, comp)
	when Enumerable
		opt.irep.para_call(para, smith, armor, comp)
	else
		raise InvalidRecipeError
	end
end

#phydef_optimize(smith = nil, comp = smith, **kw) ⇒ Object



176
177
178
179
180
181
182
183
# File 'lib/mgmg/recipe.rb', line 176

def phydef_optimize(smith=nil, comp=smith, **kw)
	opt = temp_opt(**kw)
	if @recipe.kind_of?(String)
		@recipe.phydef_optimize(smith, comp, opt:)
	else
		raise InvalidRecipeError, "Mgmg::Recipe#phydef_optimize is available only for String recipes."
	end
end

#poly(para = @para, **kw) ⇒ Object



168
169
170
171
172
173
174
175
# File 'lib/mgmg/recipe.rb', line 168

def poly(para=@para, **kw)
	opt = temp_opt(**kw)
	if @recipe.kind_of?(String)
		@recipe.poly(para, opt:)
	else
		raise InvalidRecipeError, "Mgmg::Recipe#poly is available only for String recipes."
	end
end

#replace(new_recipe, para: @para, **kw) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/mgmg/recipe.rb', line 48

def replace(new_recipe, para: @para, **kw)
	@recipe = new_recipe
	@recipe.each(&:freeze) if @recipe.kind_of?(Enumerable)
	@recipe.freeze
	@para = para
	@option = Option.new(**kw).set_default(@recipe)
	self
end

#search(target, para: @para, **kw) ⇒ Object



109
110
111
112
# File 'lib/mgmg/recipe.rb', line 109

def search(target, para: @para, **kw)
	opt = temp_opt(**kw)
	@recipe.search(para, target, opt:)
end

#show(smith = -1,, armor = smith, comp = armor.tap{armor=smith}, para: @para, search: nil, find_max: nil, **kw) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/mgmg/recipe.rb', line 89

def show(smith=-1, armor=smith, comp=armor.tap{armor=smith}, para: @para, search: nil, find_max: nil, **kw)
	opt = temp_opt(**kw)
	if search
		sc = @recipe.search(para, search, opt:)
		@recipe.show(*sc, para:, name: @name, opt:)
	elsif find_max
		sc = @recipe.search(para, find_max, opt:)
		@recipe.show(*sc, para:, name: @name, opt:)
	else
		smith, armor, comp = opt.smith_min, opt.armor_min, opt.comp_min if smith.nil?
		case @recipe
		when String
			@recipe.show(smith, comp, para:, name: @name, opt:)
		when Enumerable
			@recipe.show(smith, armor, comp, para:, name: @name, opt:)
		else
			raise BrokenRecipeError
		end
	end
end