Class: PoorPokemon::Pokemon

Inherits:
Object
  • Object
show all
Defined in:
lib/poor-pokemon/pokemon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arr, flag = false) ⇒ Pokemon

Returns a new instance of Pokemon.



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
# File 'lib/poor-pokemon/pokemon.rb', line 5

def initialize(arr, flag=false)
  #flag is for enemy to have perfect stats
  @name, @type1, @type2, @hp, @att, @def, @spAtt, @spDef, @spd = arr

  #Determines proper stats
  #https://www.dragonflycave.com/mechanics/stats
  #Individual stats (0-15)
  atkIV = flag ? 15: rand(15)
  @att += atkIV
  @att = @att*2+68
  

  defIV = flag ? 15:rand(15)
  @def += defIV
  @def = @def*2+68

  spdIV = flag ? 15:rand(15)
  @spd += spdIV
  @spd = @spd*2+68

  spIV = flag ? 15:rand(15)
  @spAtt += spIV
  @spAtt = @spAtt*2+68
  @spDef += spIV
  @spDef = @spDef*2+68

  #how HP and IV are connected
  if atkIV%2==1
    @hp +=  8
  end
  
  if defIV%2==1
    @hp +=  4
  end
  
  if spdIV%2==1
    @hp +=  2
  end
  
  if spIV%2==1
    @hp +=  1
  end
  @hp = @hp*2+110

  @moves = []
end

Instance Attribute Details

#attObject

Returns the value of attribute att.



2
3
4
# File 'lib/poor-pokemon/pokemon.rb', line 2

def att
  @att
end

#defObject

Returns the value of attribute def.



2
3
4
# File 'lib/poor-pokemon/pokemon.rb', line 2

def def
  @def
end

#hpObject

Returns the value of attribute hp.



2
3
4
# File 'lib/poor-pokemon/pokemon.rb', line 2

def hp
  @hp
end

#movesObject

Returns the value of attribute moves.



2
3
4
# File 'lib/poor-pokemon/pokemon.rb', line 2

def moves
  @moves
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/poor-pokemon/pokemon.rb', line 2

def name
  @name
end

#spAttObject

Returns the value of attribute spAtt.



2
3
4
# File 'lib/poor-pokemon/pokemon.rb', line 2

def spAtt
  @spAtt
end

#spdObject

Returns the value of attribute spd.



2
3
4
# File 'lib/poor-pokemon/pokemon.rb', line 2

def spd
  @spd
end

#spDefObject

Returns the value of attribute spDef.



2
3
4
# File 'lib/poor-pokemon/pokemon.rb', line 2

def spDef
  @spDef
end

#type1Object

Returns the value of attribute type1.



2
3
4
# File 'lib/poor-pokemon/pokemon.rb', line 2

def type1
  @type1
end

#type2Object

Returns the value of attribute type2.



2
3
4
# File 'lib/poor-pokemon/pokemon.rb', line 2

def type2
  @type2
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/poor-pokemon/pokemon.rb', line 52

def alive?
  @hp > 0
end

#attacks(oppPokemon, move) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/poor-pokemon/pokemon.rb', line 56

def attacks(oppPokemon, move)
  #dmg calculations
  attackStat = ["normal", "fighting", "flying", "poison", "ground", "rock", "bug", "ghost"].include?(move.type) ? @att : @spAtt
  attackPower = move.dmg
  defenseStat = ["normal", "fighting", "flying", "poison", "ground", "rock", "bug", "ghost"].include?(move.type) ? oppPokemon.def : oppPokemon.spDef
  randNum = rand(255-217)+217
  stab = move.type == @type1 || move.type == @type2 ? 1.5 : 1
  weakResist = calcWeakResist(oppPokemon,move)

  #dmg equation
  damageTotal = (((((42 * attackStat.to_f * (attackPower.to_f/defenseStat.to_f))/50)+2)*stab.to_f*weakResist.to_f)*randNum.to_f/255).floor

  #applying dmg
  move.pp -= 1
  oppPokemon.hp -= damageTotal
  if oppPokemon.hp < 0
    oppPokemon.hp = 0 #just in case HP checked
  end
  [damageTotal,weakResist]
end

#calcWeakResist(oppPokemon, move, typeInput = nil) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/poor-pokemon/pokemon.rb', line 77

def calcWeakResist(oppPokemon,move, typeInput=nil)
  #returns multiplier for attack effectiveness
  #0.25, 0.5, 1, 2, or 4
  # http://unrealitymag.com/wp-content/uploads/2014/11/rby-rules.jpg
  type = (typeInput || oppPokemon.type1).downcase
  output = 1; #number returned as modifier
  case move.type.downcase
  when 'normal'
    if ['ghost'].include?(type)
      output *= 0
    end
  when 'bug'
    if ['fire','flying',"rock"].include?(type)
      output*=0.5
    elsif ['grass','poison',"psychic"].include?(type)
      output*=2
    end
  when 'dragon'
    #No effectiveness
  when 'ice'
    if ['ice','water'].include?(type)
      output*=0.5
    elsif ['dragon','flying','grass','ground'].include?(type)
      output*=2
    end
  when 'fighting'
    if ['flying','psychic'].include?(type)
      output*=0.5
    elsif ['ice','normal','rock'].include?(type)
      output*=2
    elsif ['ghost'].include?(type)
      output*=0
    end
  when 'fire'
    if ['rock','water'].include?(type)
      output*=0.5
    elsif ['bug','grass','ice'].include?(type)
      output*=2
    end
  when 'flying'
    if ['electric','rock'].include?(type)
      output*=0.5
    elsif ['bug','fighting',"grass"].include?(type)
      output*=2
    end
  when 'grass'
    if ['bug','fire','flying','grass','poison'].include?(type)
      output*=0.5
    elsif ['ground','rock','water'].include?(type)
      output*=2
    end
  when 'ghost'
    if ['normal','psychic'].include?(type)
      output*=0
    end
  when 'ground'
    if ['grass'].include?(type)
      output*=0.5
    elsif ['electric','fire','poison','rock'].include?(type)
      output*=2
    elsif ['flying'].include?(type)
      output*=0
    end
  when 'electric'
    if ['electric','grass'].include?(type)
      output*=0.5
    elsif ['flying','water'].include?(type)
      output*=2
    elsif ['ground'].include?(type)
      output*=0
    end
  when 'poison'
    if ['ground','poison','rock'].include?(type)
      output*=0.5
    elsif ['bug','grass'].include?(type)
      output*=2
    end
  when 'psychic'
    if ['psychic'].include?(type)
      output*=0.5
    elsif ['fighting','poison'].include?(type)
      output*=2
    end
  when 'rock'
    if ['fighting','rock'].include?(type)
    elsif ['bug','fire','flying','ice'].include?(type)
    end
  when 'water'
    if ['grass','ice'].include?(type)
      output*=0.5
    elsif ['fire','ground','rock'].include?(type)
      output*=2
    end
  else
    puts "SOMETHING WENT WRONG WITH TYPE DMG"
    puts "MoveType: #{move.type.downcase} Type: #{type.downcase}"
  end

  if(typeInput.nil? && oppPokemon.type2 !="")
    output *= calcWeakResist(oppPokemon,move, oppPokemon.type2)
  end
  output
end

#canAttack?Boolean

Returns:

  • (Boolean)


181
182
183
184
# File 'lib/poor-pokemon/pokemon.rb', line 181

def canAttack?
  #returns true if pokemon has enough PP to attack
  @moves.any?{|move| move.usable?}
end

#usableMovesObject



186
187
188
189
# File 'lib/poor-pokemon/pokemon.rb', line 186

def usableMoves
  #returns array of usable moves
  @moves.select{|move| move.usable?}
end