- 1,224
- Posts
- 10
- Years
- Omnipresence
- Seen Aug 8, 2023
I'm trying to implement some of the older abilities that don't work for the Gen 6 project, and I'm having a bit of trouble implementing Stall. I'm not entirely sure about how pbPriority's ordering actually works, and I can't seem to get it. Hopefully you guys can help me out. Changes highlighted in red.
It seems to sometimes work, but not always, so I've obviously done something wrong.
Code:
def pbPriority(ignorequickclaw=false)
if @usepriority
# use stored priority if round isn't over yet
return @priority
end
speeds=[]
quickclaw=[]
priorities=[]
temp=[]
stall=[]
slowitem=[]
@priority.clear
maxpri=0
minpri=0
# Calculate each Pokémon's speed
for i in 0...4
speeds[i]=@battlers[i].pbSpeed
quickclaw[i]=@battlers[i].hasWorkingItem(:QUICKCLAW)
quickclaw[i]=false if @choices[i][0]!=1
quickclaw[i]=false if ignorequickclaw
[COLOR="red"]#Check for Stall or Lagging Tail or Full Incense
stall[i]=(@battlers[i].hasWorkingAbility(:STALL))?true:false
slowitem[i]=(@battlers[i].hasWorkingItem(:LAGGINGTAIL) || @battlers[i].hasWorkingItem(:FULLINCENSE))?true:false[/COLOR]
end
# Find the maximum and minimum priority
for i in 0...4
# For this function, switching and using items
# is the same as using a move with a priority of 0
pri=0
if @choices[i][0]==1 # Is a move
pri=@choices[i][2].priority
pri+=1 if @battlers[i].hasWorkingAbility(:PRANKSTER) &&
@choices[i][2].basedamage==0 # Is status move
pri+=1 if @battlers[i].hasWorkingAbility(:GALEWINGS) &&
isConst?(@choices[i][2].type,PBTypes,:FLYING)
end
priorities[i]=pri
if i==0
maxpri=pri
minpri=pri
else
maxpri=pri if maxpri<pri
minpri=pri if minpri>pri
end
end
# Find and order all moves with the same priority
curpri=maxpri
loop do
temp.clear
for j in 0...4
if priorities[j]==curpri
temp[temp.length]=j
end
end
# Sort by speed
if temp.length==1
@priority[@priority.length]=@battlers[temp[0]]
else
n=temp.length
usequickclaw=(pbRandom(16)<3)
for m in 0..n-2
for i in 1..n-1
if quickclaw[temp[i]] && usequickclaw
cmp=(quickclaw[temp[i-1]]) ? 0 : -1 #Rank higher if without Quick Claw, or equal if with it
elsif quickclaw[temp[i-1]] && usequickclaw
cmp=1 # Rank lower
[COLOR="Red"]elsif stall[temp[i]] #Check for stall
cmp=(stall[temp[i-1]]) ? 0 : 1
elsif slowitem[temp[i]] #Check for slowing items
cmp=(slowitem[temp[i-1]]) ? 0 : 1[/COLOR]
else #check regular pokemon
cmp=(speeds[temp[i]]>speeds[temp[i-1]]) ? -1 : (speeds[temp[i]]==speeds[temp[i]])? 0 : 1 #Rank higher to higher-speed battler
end
if cmp<0
# put higher-speed Pokémon first
swaptmp=temp[i]
temp[i]=temp[i-1]
temp[i-1]=swaptmp
elsif cmp==0
# swap at random if speeds are equal
if pbRandom(2)==0
swaptmp=temp[i]
temp[i]=temp[i-1]
temp[i-1]=swaptmp
end
end
end
end
#Now add the temp array to priority
for i in temp
@priority[@priority.length]=@battlers[i]
end
end
curpri-=1
break unless curpri>=minpri
end
=begin
prioind=[
@priority[0].index,
@priority[1].index,
@priority[2] ? @priority[2].index : -1,
@priority[3] ? @priority[3].index : -1
]
print("#{speeds.inspect} #{prioind.inspect}")
=end
@usepriority=true
return @priority
end
It seems to sometimes work, but not always, so I've obviously done something wrong.
Last edited: