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
t = Thread.new do
Console.echo_error "Plugin Error:\r\n#{msg}"
p "Plugin Error: #{msg}"
print("Plugin Error:\r\n#{msg}")
Thread.exit
end
while t.status

View File

@@ -54,6 +54,7 @@ class Battle
attr_reader :player # Player trainer (or array of trainers)
attr_reader :opponent # Opponent trainer (or array of trainers)
attr_accessor :items # Items held by opponents
attr_accessor :ally_items # Items held by allies
attr_accessor :endSpeeches
attr_accessor :endSpeechesWin
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
@opponent = opponent # Array of NPCTrainer objects, or nil
@items = nil
@ally_items = nil # Array of items held by ally. This is just used for Mega Evolution for now.
@endSpeeches = []
@endSpeechesWin = []
@party1 = p1
@@ -167,6 +169,8 @@ class Battle
else
@struggle = Move::Struggle.new(self, nil)
end
@mega_rings = []
GameData::Item.each { |item| @mega_rings.push(item.id) if item.has_flag?("MegaRing") }
end
#=============================================================================
@@ -259,8 +263,14 @@ class Battle
end
def pbGetOwnerItems(idxBattler)
return [] if !@items || !opposes?(idxBattler)
return @items[pbGetOwnerIndexFromBattlerIndex(idxBattler)]
if opposes?(idxBattler)
return [] if !@items
return @items[pbGetOwnerIndexFromBattlerIndex(idxBattler)]
else
return [] if !@ally_items
return @ally_items[pbGetOwnerIndexFromBattlerIndex(idxBattler)]
end
return []
end
# 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
#=============================================================================
def pbHasMegaRing?(idxBattler)
return true if !pbOwnedByPlayer?(idxBattler) # Assume AI trainer have a ring
Settings::MEGA_RINGS.each { |item| return true if $bag.has?(item) }
if pbOwnedByPlayer?(idxBattler)
@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
end
def pbGetMegaRingName(idxBattler)
if pbOwnedByPlayer?(idxBattler)
Settings::MEGA_RINGS.each do |item|
return GameData::Item.get(item).name if $bag.has?(item)
if !@mega_rings.empty?
if pbOwnedByPlayer?(idxBattler)
@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
# 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")
end

View File

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

View File

@@ -445,9 +445,9 @@ def pbPickBerry(berry, qty = 1)
end
$bag.add(berry, qty)
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
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
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",

View File

@@ -638,23 +638,7 @@ end
def pbUseItem(bag, item, bagscene = nil)
itm = GameData::Item.get(item)
useType = itm.field_use
if itm.is_machine? # TM or TR or HM
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 useType == 1 # Item is usable on a Pokémon
if $player.pokemon_count == 0
pbMessage(_INTL("There is no Pokémon."))
return 0
@@ -705,7 +689,7 @@ def pbUseItem(bag, item, bagscene = nil)
bagscene&.pbRefresh
}
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)
if intret >= 0
bag.remove(item) if intret == 1 && itm.consumed_after_use?

View File

@@ -13,7 +13,7 @@ ItemHandlers::UseText.copy(:BICYCLE, :MACHBIKE, :ACROBIKE)
# 1 = used
# 2 = close the Bag to use
# 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|
@@ -64,6 +64,23 @@ ItemHandlers::UseFromBag.add(:TOWNMAP, proc { |item|
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
# Return values: true/false

View File

@@ -186,6 +186,9 @@ class PokemonMart_Scene
@sprites["icon"].item = itemwindow.item
@sprites["itemtextwindow"].text =
(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
end
@sprites["moneywindow"].text = _INTL("Money:\r\n<r>{1}", @adapter.getMoneyString)
@@ -232,6 +235,16 @@ class PokemonMart_Scene
@sprites["moneywindow"].height = 96
@sprites["moneywindow"].baseColor = Color.new(88, 88, 80)
@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)
@buying = buying
pbRefresh
@@ -328,6 +341,16 @@ class PokemonMart_Scene
@sprites["moneywindow"].visible = false
end
def pbShowQuantity
pbRefresh
@sprites["qtywindow"].visible = true
end
def pbHideQuantity
pbRefresh
@sprites["qtywindow"].visible = false
end
def pbDisplay(msg, brief = false)
cw = @sprites["helpwindow"]
cw.letterbyletter = true
@@ -490,11 +513,7 @@ class PokemonMart_Scene
Input.update
olditem = itemwindow.item
self.update
if itemwindow.item != olditem
@sprites["icon"].item = itemwindow.item
@sprites["itemtextwindow"].text =
(itemwindow.item) ? @adapter.getDescription(itemwindow.item) : _INTL("Quit shopping.")
end
pbRefresh if itemwindow.item != olditem
if Input.trigger?(Input::BACK)
pbPlayCloseMenuSE
return nil

View File

@@ -421,10 +421,8 @@ end
def pbMoveTutorChoose(move, movelist = nil, bymachine = false, oneusemachine = false)
ret = false
move = GameData::Move.get(move).id
if movelist != nil && movelist.is_a?(Array)
movelist.length.times do |i|
movelist[i] = GameData::Move.get(movelist[i]).id
end
if movelist.is_a?(Array)
movelist.map! { |m| GameData::Move.get(m).id }
end
pbFadeOutIn {
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]
Name = Repel
@@ -5623,7 +5623,7 @@ Name = Mega Ring
NamePlural = Mega Rings
Pocket = 8
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.
#-------------------------------
[POKEMONBOXLINK]

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]
LoseText = A very good battle, indeed!