oakdex-pokemon 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -0
- data/lib/oakdex/pokemon.rb +7 -10
- data/lib/oakdex/pokemon/growth_events.rb +3 -0
- data/lib/oakdex/pokemon/growth_events/add_hp.rb +24 -0
- data/lib/oakdex/pokemon/growth_events/remove_status_condition.rb +17 -0
- data/lib/oakdex/pokemon/growth_events/revive.rb +12 -0
- data/lib/oakdex/pokemon/use_item_service.rb +116 -0
- data/lib/oakdex/pokemon/version.rb +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d21644d03a3d35efce1f5dec4bcba277d5d87395
|
4
|
+
data.tar.gz: aa47c97fd2fc60ea0bf4c94e6d49bfb9beaea7b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a86f5126133eeda5e15bf68ef74aa555b3022c48984c9e35014668cad92ebfb8bdf9a8f87fe63de9184215848800fc106e23415e449acfdcee92ed363517a0d
|
7
|
+
data.tar.gz: 4d15acde748b58cde382e363567037ac53ab8ee653ed3cc9a7c823cc19b920fbe362c10b0eab7d835b4160f238da3f61b9068272060007fcd043b7511f8b4224
|
data/README.md
CHANGED
@@ -135,6 +135,37 @@ while exeggcute.growth_event? do
|
|
135
135
|
end
|
136
136
|
end
|
137
137
|
exeggcute.name # => Exeggutor
|
138
|
+
|
139
|
+
|
140
|
+
# Item Usage
|
141
|
+
charmander = Oakdex::Pokemon.create('Charmander', level: 15, hp: 32)
|
142
|
+
charmander.usable_item?('Potion') # => true
|
143
|
+
charmander.use_item('Potion')
|
144
|
+
# Charmander gets HP
|
145
|
+
while charmander.growth_event? do
|
146
|
+
e = charmander.growth_event
|
147
|
+
if e.read_only?
|
148
|
+
puts e.message
|
149
|
+
e.execute # => gains ~8HP
|
150
|
+
end
|
151
|
+
end
|
152
|
+
charmander.hp # => 40
|
153
|
+
charmander.usable_item?('Potion') # => false
|
154
|
+
|
155
|
+
|
156
|
+
charmander = Oakdex::Pokemon.create('Charmander', level: 15, primary_status_condition: 'poison')
|
157
|
+
charmander.usable_item?('Antidote') # => true
|
158
|
+
charmander.use_item('Antidote')
|
159
|
+
# Charmander heals status condition
|
160
|
+
while charmander.growth_event? do
|
161
|
+
e = charmander.growth_event
|
162
|
+
if e.read_only?
|
163
|
+
puts e.message
|
164
|
+
e.execute # => heals poison
|
165
|
+
end
|
166
|
+
end
|
167
|
+
charmander.primary_status_condition # => nil
|
168
|
+
charmander.usable_item?('Antidote') # => false
|
138
169
|
```
|
139
170
|
|
140
171
|
|
data/lib/oakdex/pokemon.rb
CHANGED
@@ -6,6 +6,7 @@ require 'oakdex/pokemon/move'
|
|
6
6
|
require 'oakdex/pokemon/factory'
|
7
7
|
require 'oakdex/pokemon/experience_gain_calculator'
|
8
8
|
require 'oakdex/pokemon/evolution_matcher'
|
9
|
+
require 'oakdex/pokemon/use_item_service'
|
9
10
|
require 'oakdex/pokemon/growth_events'
|
10
11
|
|
11
12
|
module Oakdex
|
@@ -165,14 +166,14 @@ module Oakdex
|
|
165
166
|
evolution: available_evolution) if available_evolution
|
166
167
|
end
|
167
168
|
|
168
|
-
def usable_item?(item_id)
|
169
|
-
|
169
|
+
def usable_item?(item_id, options = {})
|
170
|
+
service = UseItemService.new(self, item_id, options)
|
171
|
+
service.usable?
|
170
172
|
end
|
171
173
|
|
172
|
-
def use_item(item_id)
|
173
|
-
|
174
|
-
|
175
|
-
evolution: evolution_by_item(item_id))
|
174
|
+
def use_item(item_id, options = {})
|
175
|
+
service = UseItemService.new(self, item_id, options)
|
176
|
+
service.use
|
176
177
|
end
|
177
178
|
|
178
179
|
def increment_level
|
@@ -223,10 +224,6 @@ module Oakdex
|
|
223
224
|
|
224
225
|
private
|
225
226
|
|
226
|
-
def evolution_by_item(item_id)
|
227
|
-
EvolutionMatcher.new(self, 'item', item_id: item_id).evolution
|
228
|
-
end
|
229
|
-
|
230
227
|
def initial_stat(stat)
|
231
228
|
Stat.initial_stat(stat,
|
232
229
|
level: level,
|
@@ -15,3 +15,6 @@ require 'oakdex/pokemon/growth_events/did_not_learn_move'
|
|
15
15
|
require 'oakdex/pokemon/growth_events/did_evolution'
|
16
16
|
require 'oakdex/pokemon/growth_events/skipped_evolution'
|
17
17
|
require 'oakdex/pokemon/growth_events/evolution'
|
18
|
+
require 'oakdex/pokemon/growth_events/add_hp'
|
19
|
+
require 'oakdex/pokemon/growth_events/revive'
|
20
|
+
require 'oakdex/pokemon/growth_events/remove_status_condition'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
class Oakdex::Pokemon
|
4
|
+
module GrowthEvents
|
5
|
+
# When pokemon received HP
|
6
|
+
class AddHp < Base
|
7
|
+
def message
|
8
|
+
"#{@pokemon.name} heals by #{real_hp}HP."
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute
|
12
|
+
@pokemon.change_hp_by(@options[:hp])
|
13
|
+
remove_event
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def real_hp
|
19
|
+
max_add = @pokemon.hp - @pokemon.current_hp
|
20
|
+
[max_add, @options[:hp]].min
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
class Oakdex::Pokemon
|
4
|
+
module GrowthEvents
|
5
|
+
# When pokemon gets status condition healed
|
6
|
+
class RemoveStatusCondition < Base
|
7
|
+
def message
|
8
|
+
"#{@pokemon.name} heals #{@pokemon.primary_status_condition}."
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute
|
12
|
+
@pokemon.primary_status_condition = nil
|
13
|
+
remove_event
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module Oakdex
|
2
|
+
class Pokemon
|
3
|
+
# Represents Item usage
|
4
|
+
class UseItemService
|
5
|
+
def initialize(pokemon, item_id, options = {})
|
6
|
+
@pokemon = pokemon
|
7
|
+
@item = Oakdex::Pokedex::Item.find!(item_id)
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def usable?
|
12
|
+
!evolution.nil? || effect_usable?
|
13
|
+
end
|
14
|
+
|
15
|
+
def use
|
16
|
+
return unless usable?
|
17
|
+
unless evolution.nil?
|
18
|
+
@pokemon.add_growth_event(GrowthEvents::Evolution,
|
19
|
+
evolution: evolution)
|
20
|
+
end
|
21
|
+
execute_effects
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def in_battle?
|
28
|
+
@options[:in_battle]
|
29
|
+
end
|
30
|
+
|
31
|
+
def effect_usable?
|
32
|
+
@item.effects.any? do |effect|
|
33
|
+
condition_applies?(effect) && target_applies?(effect) &&
|
34
|
+
pokemon_changes_apply?(effect)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def condition_applies?(effect)
|
39
|
+
condition = effect['condition']
|
40
|
+
condition == 'Always' ||
|
41
|
+
(in_battle? && condition == 'During Battle') ||
|
42
|
+
(!in_battle? && condition == 'Outside of Battle')
|
43
|
+
end
|
44
|
+
|
45
|
+
def target_applies?(effect)
|
46
|
+
target = effect['target']
|
47
|
+
['Single Pokemon', 'Single Pokemon > Single Move',
|
48
|
+
'Single Pokemon > All Moves', 'Team'].include?(target)
|
49
|
+
end
|
50
|
+
|
51
|
+
def pokemon_changes_apply?(effect)
|
52
|
+
pokemon_changes = effect['pokemon_changes'] || []
|
53
|
+
return true if pokemon_changes.empty?
|
54
|
+
pokemon_changes.any? do |change|
|
55
|
+
pokemon_change_applies?(change)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def pokemon_change_applies?(change)
|
60
|
+
!pokemon_field_max?(change) &&
|
61
|
+
(!@pokemon.fainted? || (@pokemon.fainted? && change['revive']))
|
62
|
+
end
|
63
|
+
|
64
|
+
def pokemon_field_max?(change)
|
65
|
+
case change['field']
|
66
|
+
when 'current_hp' then @pokemon.current_hp >= @pokemon.hp
|
67
|
+
when 'status_condition' then !change['conditions']
|
68
|
+
.include?(@pokemon.primary_status_condition)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def execute_effects
|
73
|
+
@item.effects.each do |effect|
|
74
|
+
execute_pokemon_changes(effect)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def execute_pokemon_changes(effect)
|
79
|
+
(effect['pokemon_changes'] || []).each do |change|
|
80
|
+
execute_pokemon_change(change) if pokemon_change_applies?(change)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def execute_pokemon_change(change)
|
85
|
+
case change['field']
|
86
|
+
when 'current_hp' then execute_current_hp_change(change)
|
87
|
+
when 'status_condition' then execute_remove_status_condition(change)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def execute_remove_status_condition(_change)
|
92
|
+
@pokemon.add_growth_event(GrowthEvents::RemoveStatusCondition)
|
93
|
+
end
|
94
|
+
|
95
|
+
def execute_current_hp_change(change)
|
96
|
+
change_by = change['change_by']
|
97
|
+
if change['change_by_percent']
|
98
|
+
change_by = percent_calculation(:hp, change['change_by_percent'])
|
99
|
+
end
|
100
|
+
if change['revive']
|
101
|
+
@pokemon.add_growth_event(GrowthEvents::Revive, hp: change_by)
|
102
|
+
else
|
103
|
+
@pokemon.add_growth_event(GrowthEvents::AddHp, hp: change_by)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def percent_calculation(field, percent)
|
108
|
+
(@pokemon.public_send(field).to_f * (percent.to_f / 100)).to_i
|
109
|
+
end
|
110
|
+
|
111
|
+
def evolution
|
112
|
+
EvolutionMatcher.new(@pokemon, 'item', item_id: @item.name).evolution
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oakdex-pokemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jalyna Schroeder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oakdex-pokedex
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.4.
|
19
|
+
version: 0.4.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.4.
|
26
|
+
version: 0.4.3
|
27
27
|
description: Pokémon Instance Representer, based on oakdex-pokedex
|
28
28
|
email: jalyna.schroeder@gmail.com
|
29
29
|
executables: []
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/oakdex/pokemon/experience_gain_calculator.rb
|
38
38
|
- lib/oakdex/pokemon/factory.rb
|
39
39
|
- lib/oakdex/pokemon/growth_events.rb
|
40
|
+
- lib/oakdex/pokemon/growth_events/add_hp.rb
|
40
41
|
- lib/oakdex/pokemon/growth_events/base.rb
|
41
42
|
- lib/oakdex/pokemon/growth_events/did_evolution.rb
|
42
43
|
- lib/oakdex/pokemon/growth_events/did_not_learn_move.rb
|
@@ -45,9 +46,12 @@ files:
|
|
45
46
|
- lib/oakdex/pokemon/growth_events/gained_exp.rb
|
46
47
|
- lib/oakdex/pokemon/growth_events/learn_move.rb
|
47
48
|
- lib/oakdex/pokemon/growth_events/level_up.rb
|
49
|
+
- lib/oakdex/pokemon/growth_events/remove_status_condition.rb
|
50
|
+
- lib/oakdex/pokemon/growth_events/revive.rb
|
48
51
|
- lib/oakdex/pokemon/growth_events/skipped_evolution.rb
|
49
52
|
- lib/oakdex/pokemon/move.rb
|
50
53
|
- lib/oakdex/pokemon/stat.rb
|
54
|
+
- lib/oakdex/pokemon/use_item_service.rb
|
51
55
|
- lib/oakdex/pokemon/version.rb
|
52
56
|
homepage: http://github.com/jalyna/oakdex-pokemon
|
53
57
|
licenses:
|