Code:
# * KSwap XP
# Scripter : Kyonides Arkanthes
# 2022-01-04
# Swap the Skills of your Enemies!
# Heroes can swap the foes' ATK parameters.
# Monsters can also swap the heroes' Weapons at will!
# There is also a Nullify Swaps skill as well!
# Check the KSwap module and edit the CONSTANTS accordingly.
# You can prevent the party from casting the "Skill Swap" skill by turning on
# a specific game switch.
# * Aliased Methods * #
# Game_Battler#skill_effect(user, skill)
# Game_Actor#skill_can_use?(skill_id)
# Game_Enemy#atk and actions
# Scene_Battle#start_phase5
module KSwap
# If Switch is ON, then the player can't cast them
BOSS_BATTLE_SWITCH_ID = 1
# [ Weapon Swap ID, Skill Swap ID, Nullify Swaps ID ]
SKILL_IDS = [81, 82, 83]
# Add Skill IDs that will be forbidden during Boss Battles
FORBIDDEN_SKILL_IDS = [81, 82]
# * END OF SETTINGS SECTION * #
extend self
def clear_all
@weapons = nil
@skills = nil
end
def weapon_skill_id() SKILL_IDS[0] end
def skill_id() SKILL_IDS[1] end
def nullify_skill_id() SKILL_IDS[2] end
attr_accessor :weapons, :skills
end
class Array
def simple_shuffle
ary = []
size.times do |n|
elem = self[n]
case rand(6)
when 0,2,4 then ary.unshift(elem)
when 1,3,5 then ary.push(elem)
end
end
ary.compact
end
end
class Game_Battler
alias :kyon_swap_skill_fx :skill_effect
def skill_effect(user, skill)
case skill.id
when KSwap.weapon_skill_id
return false unless rand(100) < user.hit
team.auto_swap_weapons
return true
when KSwap.skill_id
return false unless rand(100) < user.hit
team.auto_swap_skills
return true
when KSwap.nullify_skill_id
return false unless rand(100) < user.hit
team.nullify_swap
end
kyon_swap_skill_fx(user, skill)
end
end
class Game_Actor
attr_writer :skills, :weapon_id
alias :kyon_swap_gm_actor_skill_use? :skill_can_use?
def skill_can_use?(skid)
switch = KSwap::BOSS_BATTLE_SWITCH_ID
skill_ids = KSwap::FORBIDDEN_SKILL_IDS
return false if $game_switches[switch] and skill_ids.include?(skid)
kyon_swap_gm_actor_skill_use?(skid)
end
def team() $game_party end
end
class Game_Enemy
alias :kyon_swap_gm_nmy_actions :actions
alias :kyon_swap_gm_nmy_base_atk :base_atk
def alter_actions() $data_enemies[@alter_id].actions end
def alter_atk() $data_enemies[@atk_id].atk end
def base_atk
@atk_id ? alter_atk : kyon_swap_gm_nmy_base_atk
end
def actions
@alter_id ? alter_actions : kyon_swap_gm_nmy_actions
end
def team() $game_troop end
attr_writer :atk_id, :alter_id
end
class Game_Party
def auto_swap_weapons
KSwap.weapons ||= @actors.map{|a| a.weapon_id }
lotto = KSwap.weapons.simple_shuffle
@actors.each{|a| a.weapon_id = lotto.shift }
end
def auto_swap_skills
KSwap.skills ||= @actors.map{|a| a.skills }
lotto = KSwap.skills.simple_shuffle
@actors.each{|a| a.skills = lotto.shift }
end
def nullify_swap
list = KSwap.weapons
@actors.each{|a| a.weapon_id = list.shift } if list
list = KSwap.skills
@actors.each{|a| a.skills = list.shift } if list
KSwap.clear_all
end
end
class Game_Troop
def ids() @enemies.map{|e| e.id } end
def auto_swap_weapons
lotto = ids.simple_shuffle
@enemies.each{|a| a.atk_id = lotto.shift }
end
def auto_swap_skills
lotto = ids.simple_shuffle
@enemies.each{|e| e.alter_id = lotto.shift }
end
def nullify_swap
@enemies.each do |e|
e.atk_id = nil
e.alter_id = nil
end
end
end
class Scene_Battle
alias :kyon_swap_scn_bttl_start_ph5 :start_phase5
def start_phase5
$game_party.nullify_swap
kyon_swap_scn_bttl_start_ph5
end
end