Minor new additions for v20 (#147)

* Moved TMs/ TRs and HMs into their own handlers
* Improved Plugin Error Message
* Added sound effect when picking berries
* Allow player to always see quantity when buying items
* Trainers now require a Mega Ring item in their items (in trainers.txt) to Mega Evolve
This commit is contained in:
Golisopod-User
2021-12-30 00:06:26 +05:30
committed by GitHub
parent fb29f19a28
commit 13cc9790ce
11 changed files with 81 additions and 46 deletions

View File

@@ -356,7 +356,7 @@ module PluginManager
Graphics.update Graphics.update
t = Thread.new do t = Thread.new do
Console.echo_error "Plugin Error:\r\n#{msg}" Console.echo_error "Plugin Error:\r\n#{msg}"
p "Plugin Error: #{msg}" print("Plugin Error:\r\n#{msg}")
Thread.exit Thread.exit
end end
while t.status while t.status

View File

@@ -54,6 +54,7 @@ class Battle
attr_reader :player # Player trainer (or array of trainers) attr_reader :player # Player trainer (or array of trainers)
attr_reader :opponent # Opponent trainer (or array of trainers) attr_reader :opponent # Opponent trainer (or array of trainers)
attr_accessor :items # Items held by opponents attr_accessor :items # Items held by opponents
attr_accessor :ally_items # Items held by allies
attr_accessor :endSpeeches attr_accessor :endSpeeches
attr_accessor :endSpeechesWin attr_accessor :endSpeechesWin
attr_accessor :party1starts # Array of start indexes for each player-side trainer's party attr_accessor :party1starts # Array of start indexes for each player-side trainer's party
@@ -119,6 +120,7 @@ class Battle
@player = player # Array of Player/NPCTrainer objects, or nil @player = player # Array of Player/NPCTrainer objects, or nil
@opponent = opponent # Array of NPCTrainer objects, or nil @opponent = opponent # Array of NPCTrainer objects, or nil
@items = nil @items = nil
@ally_items = nil # Array of items held by ally. This is just used for Mega Evolution for now.
@endSpeeches = [] @endSpeeches = []
@endSpeechesWin = [] @endSpeechesWin = []
@party1 = p1 @party1 = p1
@@ -167,6 +169,8 @@ class Battle
else else
@struggle = Move::Struggle.new(self, nil) @struggle = Move::Struggle.new(self, nil)
end end
@mega_rings = []
GameData::Item.each { |item| @mega_rings.push(item.id) if item.has_flag?("MegaRing") }
end end
#============================================================================= #=============================================================================
@@ -259,8 +263,14 @@ class Battle
end end
def pbGetOwnerItems(idxBattler) def pbGetOwnerItems(idxBattler)
return [] if !@items || !opposes?(idxBattler) if opposes?(idxBattler)
return @items[pbGetOwnerIndexFromBattlerIndex(idxBattler)] return [] if !@items
return @items[pbGetOwnerIndexFromBattlerIndex(idxBattler)]
else
return [] if !@ally_items
return @ally_items[pbGetOwnerIndexFromBattlerIndex(idxBattler)]
end
return []
end end
# Returns whether the battler in position idxBattler is owned by the same # Returns whether the battler in position idxBattler is owned by the same

View File

@@ -62,21 +62,25 @@ class Battle
# Choosing to Mega Evolve a battler # Choosing to Mega Evolve a battler
#============================================================================= #=============================================================================
def pbHasMegaRing?(idxBattler) def pbHasMegaRing?(idxBattler)
return true if !pbOwnedByPlayer?(idxBattler) # Assume AI trainer have a ring if pbOwnedByPlayer?(idxBattler)
Settings::MEGA_RINGS.each { |item| return true if $bag.has?(item) } @mega_rings.each { |item| return true if $bag.has?(item) }
else
trainer_items = pbGetOwnerItems(idxBattler)
return false if !trainer_items
@mega_rings.each { |item| return true if trainer_items.include?(item) }
end
return false return false
end end
def pbGetMegaRingName(idxBattler) def pbGetMegaRingName(idxBattler)
if pbOwnedByPlayer?(idxBattler) if !@mega_rings.empty?
Settings::MEGA_RINGS.each do |item| if pbOwnedByPlayer?(idxBattler)
return GameData::Item.get(item).name if $bag.has?(item) @mega_rings.each { |item| return GameData::Item.get(item).name if $bag.has?(item) }
else
trainer_items = pbGetOwnerItems(idxBattler)
@mega_rings.each { |item| return GameData::Item.get(item).name if trainer_items&.include?(item) }
end end
end end
# NOTE: Add your own Mega objects for particular NPC trainers here.
# if pbGetOwnerFromBattlerIndex(idxBattler).trainer_type == :BUGCATCHER
# return _INTL("Mega Net")
# end
return _INTL("Mega Ring") return _INTL("Mega Ring")
end end

View File

@@ -406,6 +406,7 @@ def pbTrainerBattleCore(*args)
end end
# Calculate who the player trainer(s) and their party are # Calculate who the player trainer(s) and their party are
playerTrainers = [$player] playerTrainers = [$player]
allyItems = []
playerParty = $player.party playerParty = $player.party
playerPartyStarts = [0] playerPartyStarts = [0]
room_for_partner = (foeParty.length > 1) room_for_partner = (foeParty.length > 1)
@@ -417,6 +418,7 @@ def pbTrainerBattleCore(*args)
ally = NPCTrainer.new($PokemonGlobal.partner[1], $PokemonGlobal.partner[0]) ally = NPCTrainer.new($PokemonGlobal.partner[1], $PokemonGlobal.partner[0])
ally.id = $PokemonGlobal.partner[2] ally.id = $PokemonGlobal.partner[2]
ally.party = $PokemonGlobal.partner[3] ally.party = $PokemonGlobal.partner[3]
allyItems[1] = ally.items.clone
playerTrainers.push(ally) playerTrainers.push(ally)
playerParty = [] playerParty = []
$player.party.each { |pkmn| playerParty.push(pkmn) } $player.party.each { |pkmn| playerParty.push(pkmn) }
@@ -431,6 +433,7 @@ def pbTrainerBattleCore(*args)
battle.party1starts = playerPartyStarts battle.party1starts = playerPartyStarts
battle.party2starts = foePartyStarts battle.party2starts = foePartyStarts
battle.items = foeItems battle.items = foeItems
battle.ally_items = allyItems
battle.endSpeeches = foeEndSpeeches battle.endSpeeches = foeEndSpeeches
# Set various other properties in the battle class # Set various other properties in the battle class
pbPrepareBattle(battle) pbPrepareBattle(battle)

View File

@@ -445,9 +445,9 @@ def pbPickBerry(berry, qty = 1)
end end
$bag.add(berry, qty) $bag.add(berry, qty)
if qty > 1 if qty > 1
pbMessage(_INTL("You picked the {1} \\c[1]{2}\\c[0].\\wtnp[30]", qty, berry_name)) pbMessage(_INTL("\\me[Berry get]You picked the {1} \\c[1]{2}\\c[0].\\wtnp[30]", qty, berry_name))
else else
pbMessage(_INTL("You picked the \\c[1]{1}\\c[0].\\wtnp[30]", berry_name)) pbMessage(_INTL("\\me[Berry get]You picked the \\c[1]{1}\\c[0].\\wtnp[30]", berry_name))
end end
pocket = berry.pocket pocket = berry.pocket
pbMessage(_INTL("{1} put the \\c[1]{2}\\c[0] in the <icon=bagPocket{3}>\\c[1]{4}\\c[0] Pocket.\1", pbMessage(_INTL("{1} put the \\c[1]{2}\\c[0] in the <icon=bagPocket{3}>\\c[1]{4}\\c[0] Pocket.\1",

View File

@@ -638,23 +638,7 @@ end
def pbUseItem(bag, item, bagscene = nil) def pbUseItem(bag, item, bagscene = nil)
itm = GameData::Item.get(item) itm = GameData::Item.get(item)
useType = itm.field_use useType = itm.field_use
if itm.is_machine? # TM or TR or HM if useType == 1 # Item is usable on a Pokémon
if $player.pokemon_count == 0
pbMessage(_INTL("There is no Pokémon."))
return 0
end
machine = itm.move
return 0 if !machine
movename = GameData::Move.get(machine).name
pbMessage(_INTL("\\se[PC access]You booted up {1}.\1", itm.name))
if !pbConfirmMessage(_INTL("Do you want to teach {1} to a Pokémon?", movename))
return 0
elsif pbMoveTutorChoose(machine, nil, true, itm.is_TR?)
bag.remove(item) if itm.consumed_after_use?
return 1
end
return 0
elsif useType == 1 # Item is usable on a Pokémon
if $player.pokemon_count == 0 if $player.pokemon_count == 0
pbMessage(_INTL("There is no Pokémon.")) pbMessage(_INTL("There is no Pokémon."))
return 0 return 0
@@ -705,7 +689,7 @@ def pbUseItem(bag, item, bagscene = nil)
bagscene&.pbRefresh bagscene&.pbRefresh
} }
return (ret) ? 1 : 0 return (ret) ? 1 : 0
elsif useType == 2 # Item is usable from Bag elsif useType == 2 || itm.is_machine? # Item is usable from Bag or teaches a move
intret = ItemHandlers.triggerUseFromBag(item) intret = ItemHandlers.triggerUseFromBag(item)
if intret >= 0 if intret >= 0
bag.remove(item) if intret == 1 && itm.consumed_after_use? bag.remove(item) if intret == 1 && itm.consumed_after_use?

View File

@@ -13,7 +13,7 @@ ItemHandlers::UseText.copy(:BICYCLE, :MACHBIKE, :ACROBIKE)
# 1 = used # 1 = used
# 2 = close the Bag to use # 2 = close the Bag to use
# If there is no UseFromBag handler for an item being used from the Bag (not on # If there is no UseFromBag handler for an item being used from the Bag (not on
# a Pokémon and not a TM/HM), calls the UseInField handler for it instead. # a Pokémon), calls the UseInField handler for it instead.
#=============================================================================== #===============================================================================
ItemHandlers::UseFromBag.add(:HONEY, proc { |item| ItemHandlers::UseFromBag.add(:HONEY, proc { |item|
@@ -64,6 +64,23 @@ ItemHandlers::UseFromBag.add(:TOWNMAP, proc { |item|
next ($game_temp.fly_destination) ? 2 : 0 next ($game_temp.fly_destination) ? 2 : 0
}) })
ItemHandlers::UseFromBag.addIf(proc { |item| GameData::Item.get(item).is_machine? },
proc { |item|
if $player.pokemon_count == 0
pbMessage(_INTL("There is no Pokémon."))
next 0
end
item_data = GameData::Item.get(item)
move = item_data.move
next 0 if !move
pbMessage(_INTL("\\se[PC access]You booted up {1}.\1", item_data.name))
next 0 if !pbConfirmMessage(_INTL("Do you want to teach {1} to a Pokémon?",
GameData::Move.get(move).name))
next 1 if pbMoveTutorChoose(move, nil, true, item_data.is_TR?)
next 0
}
)
#=============================================================================== #===============================================================================
# ConfirmUseInField handlers # ConfirmUseInField handlers
# Return values: true/false # Return values: true/false

View File

@@ -186,6 +186,9 @@ class PokemonMart_Scene
@sprites["icon"].item = itemwindow.item @sprites["icon"].item = itemwindow.item
@sprites["itemtextwindow"].text = @sprites["itemtextwindow"].text =
(itemwindow.item) ? @adapter.getDescription(itemwindow.item) : _INTL("Quit shopping.") (itemwindow.item) ? @adapter.getDescription(itemwindow.item) : _INTL("Quit shopping.")
@sprites["qtywindow"].visible = !itemwindow.item.nil?
@sprites["qtywindow"].text = _INTL("In Bag:<r>x{1}", @adapter.getQuantity(itemwindow.item))
@sprites["qtywindow"].y = Graphics.height - 108 - @sprites["qtywindow"].height
itemwindow.refresh itemwindow.refresh
end end
@sprites["moneywindow"].text = _INTL("Money:\r\n<r>{1}", @adapter.getMoneyString) @sprites["moneywindow"].text = _INTL("Money:\r\n<r>{1}", @adapter.getMoneyString)
@@ -232,6 +235,16 @@ class PokemonMart_Scene
@sprites["moneywindow"].height = 96 @sprites["moneywindow"].height = 96
@sprites["moneywindow"].baseColor = Color.new(88, 88, 80) @sprites["moneywindow"].baseColor = Color.new(88, 88, 80)
@sprites["moneywindow"].shadowColor = Color.new(168, 184, 184) @sprites["moneywindow"].shadowColor = Color.new(168, 184, 184)
@sprites["qtywindow"] = Window_AdvancedTextPokemon.new("")
pbPrepareWindow(@sprites["qtywindow"])
@sprites["qtywindow"].setSkin("Graphics/Windowskins/goldskin")
@sprites["qtywindow"].viewport = @viewport
@sprites["qtywindow"].width = 190
@sprites["qtywindow"].height = 64
@sprites["qtywindow"].baseColor = Color.new(88, 88, 80)
@sprites["qtywindow"].shadowColor = Color.new(168, 184, 184)
@sprites["qtywindow"].text = _INTL("In Bag:<r>x{1}", @adapter.getQuantity(@sprites["itemwindow"].item))
@sprites["qtywindow"].y = Graphics.height - 108 - @sprites["qtywindow"].height
pbDeactivateWindows(@sprites) pbDeactivateWindows(@sprites)
@buying = buying @buying = buying
pbRefresh pbRefresh
@@ -328,6 +341,16 @@ class PokemonMart_Scene
@sprites["moneywindow"].visible = false @sprites["moneywindow"].visible = false
end end
def pbShowQuantity
pbRefresh
@sprites["qtywindow"].visible = true
end
def pbHideQuantity
pbRefresh
@sprites["qtywindow"].visible = false
end
def pbDisplay(msg, brief = false) def pbDisplay(msg, brief = false)
cw = @sprites["helpwindow"] cw = @sprites["helpwindow"]
cw.letterbyletter = true cw.letterbyletter = true
@@ -490,11 +513,7 @@ class PokemonMart_Scene
Input.update Input.update
olditem = itemwindow.item olditem = itemwindow.item
self.update self.update
if itemwindow.item != olditem pbRefresh if itemwindow.item != olditem
@sprites["icon"].item = itemwindow.item
@sprites["itemtextwindow"].text =
(itemwindow.item) ? @adapter.getDescription(itemwindow.item) : _INTL("Quit shopping.")
end
if Input.trigger?(Input::BACK) if Input.trigger?(Input::BACK)
pbPlayCloseMenuSE pbPlayCloseMenuSE
return nil return nil

View File

@@ -421,10 +421,8 @@ end
def pbMoveTutorChoose(move, movelist = nil, bymachine = false, oneusemachine = false) def pbMoveTutorChoose(move, movelist = nil, bymachine = false, oneusemachine = false)
ret = false ret = false
move = GameData::Move.get(move).id move = GameData::Move.get(move).id
if movelist != nil && movelist.is_a?(Array) if movelist.is_a?(Array)
movelist.length.times do |i| movelist.map! { |m| GameData::Move.get(m).id }
movelist[i] = GameData::Move.get(movelist[i]).id
end
end end
pbFadeOutIn { pbFadeOutIn {
movename = GameData::Move.get(move).name movename = GameData::Move.get(move).name

View File

@@ -1,4 +1,4 @@
# See the documentation on the wiki to learn how to edit this file. # See the documentation on the wiki to learn how to edit this file.
#------------------------------- #-------------------------------
[REPEL] [REPEL]
Name = Repel Name = Repel
@@ -5623,7 +5623,7 @@ Name = Mega Ring
NamePlural = Mega Rings NamePlural = Mega Rings
Pocket = 8 Pocket = 8
Price = 0 Price = 0
Flags = KeyItem Flags = KeyItem, MegaRing
Description = This ring contains an untold power that somehow enables Pokémon carrying Mega Stones to Mega Evolve. Description = This ring contains an untold power that somehow enables Pokémon carrying Mega Stones to Mega Evolve.
#------------------------------- #-------------------------------
[POKEMONBOXLINK] [POKEMONBOXLINK]
@@ -5648,4 +5648,4 @@ NamePlural = Old Sea Maps
Pocket = 8 Pocket = 8
Price = 0 Price = 0
Flags = KeyItem Flags = KeyItem
Description = A faded sea chart that shows the way to a certain island. Description = A faded sea chart that shows the way to a certain island.

View File

@@ -1,4 +1,4 @@
# See the documentation on the wiki to learn how to edit this file. # See the documentation on the wiki to learn how to edit this file.
#------------------------------- #-------------------------------
[CAMPER,Liam] [CAMPER,Liam]
LoseText = A very good battle, indeed! LoseText = A very good battle, indeed!