Implemented usage of GameData::Item

This commit is contained in:
Maruno17
2020-11-08 22:45:59 +00:00
parent ff70791104
commit 1955d3698e
82 changed files with 1986 additions and 2195 deletions

View File

@@ -18,31 +18,17 @@ class PBPokemon
attr_accessor :ev
def initialize(species,item,nature,move1,move2,move3,move4,ev)
@species=species
@item=item ? item : 0
@nature=nature
@move1=move1 ? move1 : 0
@move2=move2 ? move2 : 0
@move3=move3 ? move3 : 0
@move4=move4 ? move4 : 0
@ev=ev
@species = species
itm = GameData::Item.try_get(item)
@item = itm ? itm.id : nil
@nature = nature
@move1 = move1 ? move1 : 0
@move2 = move2 ? move2 : 0
@move3 = move3 ? move3 : 0
@move4 = move4 ? move4 : 0
@ev = ev
end
=begin
def _dump(depth)
return [@species,@item,@nature,@move1,@move2,
@move3,@move4,@ev].pack("vvCvvvvC")
end
def self._load(str)
data=str.unpack("vvCvvvvC")
return self.new(
data[0],data[1],data[2],data[3],
data[4],data[5],data[6],data[7]
)
end
=end
def self.fromInspected(str)
insp=str.gsub(/^\s+/,"").gsub(/\s+$/,"")
pieces=insp.split(/\s*;\s*/)
@@ -50,10 +36,7 @@ class PBPokemon
if (PBSpecies.const_defined?(pieces[0]) rescue false)
species=PBSpecies.const_get(pieces[0])
end
item=0
if (PBItems.const_defined?(pieces[1]) rescue false)
item=PBItems.const_get(pieces[1])
end
item = (GameData::Item.exists?(pieces[1])) ? GameData::Item.get(pieces[1]).id : nil
nature=PBNatures.const_get(pieces[2])
ev=pieces[3].split(/\s*,\s*/)
evvalue=0
@@ -87,33 +70,11 @@ class PBPokemon
evvalue|=0x08 if pokemon.ev[3]>60
evvalue|=0x10 if pokemon.ev[4]>60
evvalue|=0x20 if pokemon.ev[5]>60
return self.new(pokemon.species,pokemon.item,pokemon.nature,
return self.new(pokemon.species,pokemon.item_id,pokemon.nature,
pokemon.moves[0].id,pokemon.moves[1].id,pokemon.moves[2].id,
pokemon.moves[3].id,evvalue)
end
def inspect
c1=getConstantName(PBSpecies,@species)
c2=(@item==0) ? "" : getConstantName(PBItems,@item)
c3=getConstantName(PBNatures,@nature)
evlist=""
for i in 0...@ev
if ((@ev&(1<<i))!=0)
evlist+="," if evlist.length>0
evlist+=["HP","ATK","DEF","SPD","SA","SD"][i]
end
end
c4=(@move1==0) ? "" : getConstantName(PBMoves,@move1)
c5=(@move2==0) ? "" : getConstantName(PBMoves,@move2)
c6=(@move3==0) ? "" : getConstantName(PBMoves,@move3)
c7=(@move4==0) ? "" : getConstantName(PBMoves,@move4)
return "#{c1};#{c2};#{c3};#{evlist};#{c4},#{c5},#{c6},#{c7}"
end
def tocompact
return "#{species},#{item},#{nature},#{move1},#{move2},#{move3},#{move4},#{ev}"
end
def self.constFromStr(mod,str)
maxconst=0
for constant in mod.constants
@@ -134,7 +95,7 @@ class PBPokemon
def self.fromstring(str)
s=str.split(/\s*,\s*/)
species=self.constFromStr(PBSpecies,s[1])
item=self.constFromStr(PBItems,s[2])
item=s[2].to_sym
nature=self.constFromStr(PBNatures,s[3])
move1=self.constFromStr(PBMoves,s[4])
move2=(s.length>=12) ? self.constFromStr(PBMoves,s[5]) : 0
@@ -151,6 +112,43 @@ class PBPokemon
return self.new(species,item,nature,move1,move2,move3,move4,ev)
end
=begin
def _dump(depth)
return [@species,@item,@nature,@move1,@move2,
@move3,@move4,@ev].pack("vvCvvvvC")
end
def self._load(str)
data=str.unpack("vvCvvvvC")
return self.new(
data[0],data[1],data[2],data[3],
data[4],data[5],data[6],data[7]
)
end
=end
def inspect
c1=getConstantName(PBSpecies,@species)
c2=(@item) ? GameData::Item.get(@item).name : ""
c3=getConstantName(PBNatures,@nature)
evlist=""
for i in 0...@ev
if ((@ev&(1<<i))!=0)
evlist+="," if evlist.length>0
evlist+=["HP","ATK","DEF","SPD","SA","SD"][i]
end
end
c4=(@move1==0) ? "" : getConstantName(PBMoves,@move1)
c5=(@move2==0) ? "" : getConstantName(PBMoves,@move2)
c6=(@move3==0) ? "" : getConstantName(PBMoves,@move3)
c7=(@move4==0) ? "" : getConstantName(PBMoves,@move4)
return "#{c1};#{c2};#{c3};#{evlist};#{c4},#{c5},#{c6},#{c7}"
end
def tocompact
return "#{species},#{item},#{nature},#{move1},#{move2},#{move3},#{move4},#{ev}"
end
def convertMove(move)
if isConst?(move,PBMoves,:RETURN) && hasConst?(PBMoves,:FRUSTRATION)
move=getConst(PBMoves,:FRUSTRATION)
@@ -939,8 +937,8 @@ def pbOrganizedBattleEx(opponent,challengedata,endspeech,endspeechwin)
# Remember original data, to be restored after battle
challengedata = PokemonChallengeRules.new if !challengedata
oldlevels = challengedata.adjustLevels($Trainer.party,opponent.party)
olditems = $Trainer.party.transform { |p| p.item }
olditems2 = opponent.party.transform { |p| p.item }
olditems = $Trainer.party.transform { |p| p.item_id }
olditems2 = opponent.party.transform { |p| p.item_id }
# Create the battle scene (the visual side of it)
scene = pbNewBattleScene
# Create the battle class (the mechanics side of it)

View File

@@ -333,15 +333,12 @@ class BannedItemRestriction
end
def isSpecies?(species,specieslist)
for s in specieslist
return true if isConst?(species,PBItems,s)
end
return false
return specieslist.any? { |s| species == s }
end
def isValid?(pokemon)
count=0
if pokemon.item!=0 && isSpecies?(pokemon.item,@specieslist)
if pokemon.item && isSpecies?(pokemon.item,@specieslist)
count+=1
end
return count==0

View File

@@ -72,13 +72,8 @@ def pbGetLegalMoves2(species,maxlevel)
tmData=pbLoadSpeciesTMData
if !$tmMoves
$tmMoves=[]
itemData=pbLoadItemsData
for i in 0...itemData.length
next if !itemData[i]
atk=itemData[i][8]
next if !atk || atk==0
next if !tmData[atk]
$tmMoves.push(atk)
GameData::Item.each do |i|
$tmMoves.push(i.move) if i.move && tmData[i.move]
end
end
for atk in $tmMoves
@@ -326,7 +321,7 @@ def pbRandomPokemonFromRule(rule,trainer)
end
break
end
item=0
item = nil
$legalMoves=[] if level!=$legalMovesLevel
$legalMoves[species]=pbGetLegalMoves2(species,level) if !$legalMoves[species]
itemlist=[
@@ -343,13 +338,12 @@ def pbRandomPokemonFromRule(rule,trainer)
# Most used: Leftovers, Life Orb, Choice Band, Choice Scarf, Focus Sash
loop do
if rand(40)==0
item=getID(PBItems,:LEFTOVERS)
item = :LEFTOVERS
break
end
itemsym=itemlist[rand(itemlist.length)]
item=getID(PBItems,itemsym)
next if item==0
case itemsym
item = itemlist[rand(itemlist.length)]
next if !item
case item
when :LIGHTBALL
next if !isConst?(species,PBSpecies,:PIKACHU)
when :SHEDSHELL
@@ -384,27 +378,24 @@ def pbRandomPokemonFromRule(rule,trainer)
next if !isConst?(species,PBSpecies,:CUBONE) &&
!isConst?(species,PBSpecies,:MAROWAK)
end
if itemsym==:LIECHIBERRY && (ev&0x02)==0
if item == :LIECHIBERRY && (ev&0x02)==0
next if rand(2)==0
ev|=0x02
end
if itemsym==:SALACBERRY && (ev&0x08)==0
if item == :SALACBERRY && (ev&0x08)==0
next if rand(2)==0
ev|=0x08
end
if itemsym==:PETAYABERRY && (ev&0x10)==0
if item == :PETAYABERRY && (ev&0x10)==0
next if rand(2)==0
ev|=0x10
end
break
end
if level<10
item=(getConst(PBItems,:ORANBERRY) || item) if rand(40)==0 ||
isConst?(item,PBItems,:SITRUSBERRY)
end
if level>20
item=(getConst(PBItems,:SITRUSBERRY) || item) if rand(40)==0 ||
isConst?(item,PBItems,:ORANBERRY)
if level < 10 && GameData::Item.exists?(:ORANBERRY)
item = :ORANBERRY if rand(40) == 0 || item == :SITRUSBERRY
elsif level > 20 && GameData::Item.exists?(:SITRUSBERRY)
item = :SITRUSBERRY if rand(40) == 0 || item == :ORANBERRY
end
moves=$legalMoves[species]
sketch=false
@@ -483,9 +474,7 @@ def pbRandomPokemonFromRule(rule,trainer)
ev|=0x10 if rand(10)<8 # Emphasize Special Attack
ev&=~0x02 if rand(10)<8 # Deemphasize Attack
end
if !hasNormal && isConst?(item,PBItems,:SILKSCARF)
item=getID(PBItems,:LEFTOVERS)
end
item = :LEFTOVERS if !hasNormal && item == :SILKSCARF
moves=newmoves
break
end
@@ -493,33 +482,31 @@ def pbRandomPokemonFromRule(rule,trainer)
for i in 0...4
moves[i]=0 if !moves[i]
end
if isConst?(item,PBItems,:LIGHTCLAY) &&
if item == :LIGHTCLAY &&
!moves.include?((getConst(PBMoves,:LIGHTSCREEN) || -1)) &&
!moves.include?((getConst(PBMoves,:REFLECT) || -1))
item=getID(PBItems,:LEFTOVERS)
item = :LEFTOVERS
end
if isConst?(item,PBItems,:BLACKSLUDGE)
if item == :BLACKSLUDGE
type1 = pbGetSpeciesData(species,0,SpeciesData::TYPE1)
type2 = pbGetSpeciesData(species,0,SpeciesData::TYPE2) || type1
if !isConst?(type1,PBTypes,:POISON) && !isConst?(type2,PBTypes,:POISON)
item=getID(PBItems,:LEFTOVERS)
item = :LEFTOVERS
end
end
if isConst?(item,PBItems,:HEATROCK) &&
!moves.include?((getConst(PBMoves,:SUNNYDAY) || -1))
item=getID(PBItems,:LEFTOVERS)
if item == :HEATROCK && !moves.include?((getConst(PBMoves,:SUNNYDAY) || -1))
item = :LEFTOVERS
end
if isConst?(item,PBItems,:DAMPROCK) &&
!moves.include?((getConst(PBMoves,:RAINDANCE) || -1))
item=getID(PBItems,:LEFTOVERS)
if item == :DAMPROCK && !moves.include?((getConst(PBMoves,:RAINDANCE) || -1))
item = :LEFTOVERS
end
if moves.include?((getConst(PBMoves,:REST) || -1))
item=getID(PBItems,:LUMBERRY) if rand(3)==0
item=getID(PBItems,:CHESTOBERRY) if rand(4)==0
item = :LUMBERRY if rand(3)==0
item = :CHESTOBERRY if rand(4)==0
end
pk=PBPokemon.new(species,item,nature,moves[0],moves[1],moves[2],moves[3],ev)
pkmn=pk.createPokemon(level,31,trainer)
i+=1
pk = PBPokemon.new(species, item, nature, moves[0], moves[1], moves[2], moves[3], ev)
pkmn = pk.createPokemon(level, 31, trainer)
i += 1
break if rule.ruleset.isPokemonValid?(pkmn)
end
return pkmn
@@ -874,7 +861,7 @@ def pbDecideWinnerScore(party0,party1,rating)
end
basestatsum=baseStatTotal(party0[i].species)
score+=basestatsum/10
score+=10 if party0[i].item!=0 # Not in Battle Dome ranking
score+=10 if party0[i].item # Not in Battle Dome ranking
end
score+=rating+rand(32)
return score
@@ -913,7 +900,7 @@ def pbRuledBattle(team1,team2,rule)
p.level=level
p.calcStats
end
items1[i]=p.item
items1[i]=p.item_id
trainer1.party.push(p)
end
team2.each_with_index do |p,i|
@@ -922,7 +909,7 @@ def pbRuledBattle(team1,team2,rule)
p.level=level
p.calcStats
end
items2[i]=p.item
items2[i]=p.item_id
trainer2.party.push(p)
end
scene=PokeBattle_DebugSceneNoLogging.new