Code:
# * KWeaponDamage XP * #
# Scripter : Kyonides Arkanthes
# v1.1.0 - 2023-05-19
# This scriptlet allows you to either consume some SP while attacking
# your enemy physically or hit an ally, partially healing him or her
# in the process.
# It also features the vampiric weapons that drain part of your hero's HP
# in order to hit the enemy (way) harder than usual.
# * Script Calls * #
# - First Step: Find an Actor - 2 Methods
# actor = $game_actors[ActorID]
# actor = $game_party.actors[Index]
# - Make a Weapon Consume SP for Extra Damage
# actor.weapon_sp_use(WeaponID, SP, Percent)
# - Weapon No Longer Consumes SP
# actor.weapon_no_sp(WeaponID)
# - Clear All Weapons that Consume SP
# actor.clear_weapon_sp
# - Add a Weapon Blessing
# actor.bless_weapon(WeaponID, Percent)
# - Remove a Weapon Blessing
# actor.unbless_weapon(WeaponID)
# - Clear All Blessed Weapons
# actor.clear_weapon_blessing
# - Add a Vampiric Weapon
# actor.vampire_weapon(WeaponID, HP's, Extra DMG %)
# - Remove a Vampiric Weapon
# actor.no_vampire_weapon(WeaponID)
# - Clear All Vampiric Weapons
# actor.clear_vampire_weapons
class Game_Battler
DMG_MISSED = "Miss"
alias :kyon_weapon_dmg_gm_btlr_attack_fx :attack_effect
def attack_effect(attacker)
result = kyon_weapon_dmg_gm_btlr_attack_fx(attacker)
calculate_new_weapon_damage(attacker)
result
end
def calculate_new_weapon_damage(attacker)
return if @damage == DMG_MISSED
if attacker.weapon_sp_use?
total_sp = attacker.get_weapon_sp_cost
return if @sp < total_sp
attacker.sp -= total_sp
new_damage = @damage * attacker.weapon_sp_percent / 100
@damage += new_damage if @hp > 0
self.hp -= new_damage
return
elsif attacker.weapon_blessing?
@damage = -@damage - @damage * attacker.weapon_blessing / 100
dead_no_damage
self.hp -= @damage
return
elsif attacker.vampire_weapon?
attacker.vampire_weapon_hp_cost
dead_no_damage
self.hp -= @damage * attacker.vampire_weapon_dmg / 100
end
end
def dead_no_damage
@damage = 0 if self.maxhp == @hp
end
end
module GameBattlerTest
def actor?
@actor_id != nil
end
def enemy?
@enemy_id != nil
end
end
class Game_Actor
include GameBattlerTest
alias :kyon_weapon_dmg_gm_act_setup :setup
def setup(actor_id)
kyon_weapon_dmg_gm_act_setup(actor_id)
@weapon_use_sp = {}
@weapon_blessings = {}
@vampire_weapons = {}
@vampire_weapons.default = { :hp => 0, :dmg => 0 }
end
def weapon_sp_use(weapon_id, cost, percent)
@weapon_use_sp[weapon_id] = { :sp => cost, :percent => percent }
end
def weapon_no_sp(weapon_id)
@weapon_use_sp.delete(weapon_id)
end
def weapon_sp_cost
@weapon_use_sp[@weapon_id][:sp]
end
def weapon_sp_percent
@weapon_use_sp[@weapon_id][:percent]
end
def get_weapon_sp_cost
self.weapon_sp_cost * self.maxsp / 100
end
def clear_weapon_sp
@weapon_use_sp.clear
end
def weapon_sp_use?
@weapon_use_sp.has_key?(@weapon_id)
end
def bless_weapon(weapon_id, percent)
@weapon_blessings[weapon_id] = percent
end
def unbless_weapon(weapon_id)
@weapon_blessings.delete(weapon_id)
end
def weapon_blessing
@weapon_blessings[@weapon_id]
end
def clear_weapon_blessing
@weapon_blessings.clear
end
def weapon_blessing?
@weapon_blessings.has_key?(@weapon_id)
end
def vampire_weapon(weapon_id, hp_cost, dmg_percent)
@vampire_weapons[weapon_id] = { :hp => hp_cost, :dmg => dmg_percent }
end
def no_vampire_weapon(weapon_id)
@vampire_weapons.delete(weapon_id)
end
def clear_vampire_weapons
@vampire_weapons.clear
end
def vampire_weapon_hp_cost
self.hp -= @vampire_weapons[@weapon_id][:hp]
end
def vampire_weapon_dmg
@vampire_weapons[@weapon_id][:dmg]
end
def vampire_weapon?
@vampire_weapons.has_key?(@weapon_id)
end
attr_reader :weapon_use_sp, :weapon_blessings, :vampire_weapons
end
class Game_Enemy
include GameBattlerTest
def weapon_sp_use?() nil end
def weapon_blessing?() nil end
end
class Scene_Battle
alias :kyon_weapon_dmg_scn_btl_up_ph3_bsc_comm :update_phase3_basic_command
alias :kyon_weapon_dmg_scn_btl_mk_bsc_action_res :make_basic_action_result
def update_phase3_basic_command
if Input.trigger?(Input::C) and @actor_command_window.index == 0
$game_system.se_play($data_system.decision_se)
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 0
blessed = @active_battler.weapon_blessing?
blessed ? start_actor_select : start_enemy_select
return
end
kyon_weapon_dmg_scn_btl_up_ph3_bsc_comm
end
def make_altered_weapon_attack_result
return unless @active_battler.weapon_blessing?
@animation1_id = @active_battler.animation1_id
@animation2_id = @active_battler.animation2_id
if @active_battler.restriction == 3
target = $game_party.random_target_actor
elsif @active_battler.restriction == 2
target = $game_troop.random_target_enemy
else
index = @active_battler.current_action.target_index
target = $game_party.smooth_target_actor(index)
end
return unless target
target.attack_effect(@active_battler)
@target_battlers = [target]
true
end
def make_basic_action_result
if @active_battler.current_action.basic == 0
if @active_battler.actor?
result = make_altered_weapon_attack_result
return if result
end
end
kyon_weapon_dmg_scn_btl_mk_bsc_action_res
end
end