=begin ★ks_通常攻撃スキル 最終更新日 2011/01/26 2011/01/26 通常攻撃スキルが実行時に使用できない場合に通常攻撃をする挙動を修正。 □===制作・著作===□ MaidensnowOnline 暴兎 (http://maidensnow.blog100.fc2.com/) 使用プロジェクトを公開する場合、readme等に当HP名とそのアドレスを記述してください。 使用報告はしてくれると喜びます。 □===配置場所===□ エリアスのみで構成されているので、 可能な限り"▼ メイン"の上、近くに配置してください。 □===他の必須スクリプト===□ ★ks汎用判定 battler(位置不問) □===説明・使用方法===□ 武器・アクター(エネミー)に応じて、 アクター及びエネミーの"通常攻撃"を自動的に特定のスキルで行います。 候補のスキルの内、全てのスキルが使用できない場合は通常攻撃になります。 両方に設定した場合の優先度は、武器→アクターの順になります。 例)通常攻撃を"スキルID231・スキルID155のうち現在使用できる状態のもの"にする。 <通常攻撃 231 155> 例2)"使えればスキルID15、使えなければアクターの設定は無視して通常攻撃"の武器。 <通常攻撃 15 -1>(-1は通常攻撃) そのうちスキルにあわせて、別の武器として使える武器(例・銃剣)を 設定する機能も移植します。 □===エリアスしている主なメソッド===□ Game_Actor skill_learn? □===利用できる新規メソッド===□ 特になし =end #------------------------------------------------------------------------------ # ■ KS_Extend #------------------------------------------------------------------------------ module KS_Extend WEAPON_SHIFT_IGNORE = [] BASIC_ATTACK_SKILL = /<通常攻撃\s*((?:-|)\d+(?:\s*|\s*(?:-|)\d+)*)>/i SUB_ATTACK_SKILL = /<選択攻撃\s*((?:-|)\d+(?:\s*|\s*(?:-|)\d+)*)>/i SHIFT_WEAPON = /<シフト武器\s+(\d+)\s+(\d+(,\d+)*)>/i FREE_HAND = /<武器無視\s*(\d+)>/i end #------------------------------------------------------------------------------ # ■ Kernel #------------------------------------------------------------------------------ module Kernel alias create_ks_param_cache_for_basic_attackm create_ks_param_cache def create_ks_param_cache# Kernel alias @__basic_attack_skill = [] create_ks_param_cache_for_basic_attackm end alias judge_note_line_for_basic_attack judge_note_line def judge_note_line(line)# Kernel judge_note_line_for_basic_attack(line) if line =~ KS_Extend::BASIC_ATTACK_SKILL $1.scan(/(?:-|)\d+/).each { |num| if num.to_i == -1 @__basic_attack_skill << nil else skill = $data_skills[num.to_i] @__basic_attack_skill << skill end } #pp @id, @name, :basic_attack_skill, @__basic_attack_skill elsif line =~ KS_Extend::SUB_ATTACK_SKILL @__sub_attack_skill = [] if @__sub_attack_skill == nil $1.scan(/(?:-|)\d+/).each { |num| if num.to_i == -1 @__sub_attack_skill << nil else skill = $data_skills[num.to_i] @__sub_attack_skill << skill end } #pp @id, @name, :sub_attack_skill, @__sub_attack_skill elsif line =~ KS_Extend::SHIFT_WEAPON set = [$1.to_i,[]] $2.scan(/\d+/).each { |num| set[1] << num.to_i } @__shift_weapons[set[1]] = set[0] #pp @id,@name,line,:shift_weapons,@__shift_weapons elsif line =~ KS_Extend::FREE_HAND @__free_hand = $1.to_i end end end #------------------------------------------------------------------------------ # ■ KS_Extend_Data #------------------------------------------------------------------------------ module KS_Extend_Data def basic_attack_skill ; create_ks_param_cache unless @__ks_cache_done return @__basic_attack_skill ; end def sub_attack_skill ; create_ks_param_cache unless @__ks_cache_done @__sub_attack_skill = @__basic_attack_skill.compact unless @__sub_attack_skill return @__sub_attack_skill ; end end module KGC module ReproduceFunctions WEAPON_ELEMENT_ID_LIST = [] unless defined?(WEAPON_ELEMENT_ID_LIST) end end #------------------------------------------------------------------------------ # ■ RPG::BaseItem #------------------------------------------------------------------------------ class RPG::BaseItem def free_hand_attack? ; create_ks_param_cache unless @__ks_cache_done return @__free_hand ; end alias create_ks_param_cache_for_basic_attack create_ks_param_cache def create_ks_param_cache @__shift_weapons = {} create_ks_param_cache_for_basic_attack end def shift_weapons ; create_ks_param_cache unless @__ks_cache_done result = {} return result unless @__shift_weapons for key in @__shift_weapons.keys result[key] = $data_weapons[@__shift_weapons[key]] end return result end end #------------------------------------------------------------------------------ # ■ Game_BattleAction #------------------------------------------------------------------------------ class Game_BattleAction #-------------------------------------------------------------------------- # ● 通常攻撃を設定 #-------------------------------------------------------------------------- alias set_attack_for_basic_attack set_attack def set_attack set_attack_for_basic_attack bat = battler.basic_attack_skill if bat set_skill(bat.id) end @flags[:basic_attack] = true end #-------------------------------------------------------------------------- # ● 行動準備 #-------------------------------------------------------------------------- alias prepare_for_basic_attack prepare def prepare prepare_for_basic_attack if !valid? && !attack? && @flags[:basic_attack] set_attack end end end #------------------------------------------------------------------------------ # ■ Game_Battler #------------------------------------------------------------------------------ class Game_Battler BAT_ARY = [] unless defined?(BAT_ARY) for i in BAT_ARY.size...1 BAT_ARY << [] end def restre_hand(last_hand = [@off_hand_exec, @free_hand_exec]) @off_hand_exec = last_hand[0] start_free_hand_attack(last_hand[1]) end def start_free_hand_attack(free_hand_rank = 0) # 0 完全素手 1 性能無視・修正適用 @free_hand_exec = free_hand_rank end def end_free_hand_attack @free_hand_exec = false end def start_free_hand_attack?(obj) if obj.is_a?(RPG::UsableItem) && obj.free_hand_attack? start_free_hand_attack(obj.free_hand_attack?) return end start_weapon_shift?(obj) end def start_weapon_shift?(obj) key = @off_hand_exec ? 0 : 1 cheta = 10 key += obj.serial_id * cheta cheta **= 4 key += :sws.to_i * cheta cheta **= 5 key += hand_symbol(true) * cheta unless self.equips_cache[:weapon_shift].has_key?(key) self.equips_cache[:weapon_shift][key] = judge_weapon_shift?(obj) end if self.equips_cache[:weapon_shift][key] start_free_hand_attack(self.equips_cache[:weapon_shift][key]) return true end end_free_hand_attack return false end def judge_weapon_shift?(obj) if obj tar_set = Vocab::TmpAry[0].clear tar_set += obj.element_set tar_set -= KS_Extend::WEAPON_SHIFT_IGNORE else tar_set = Array::MALEE_ARY end return false if tar_set.empty? weapon_eles = KGC::ReproduceFunctions::WEAPON_ELEMENT_ID_LIST wep = true_weapon(true) if wep tar_set2 = tar_set - wep.element_set for key in wep.shift_weapons.keys weapon = wep.shift_weapons[key] next if (tar_set & key).empty? && (!weapon || (tar_set2 & weapon.element_set & weapon_eles).empty?) return key end if !(tar_set & wep.element_set & weapon_eles).empty? return false end end if self.luncher && !(tar_set & @luncher.element_set & weapon_eles).empty? return :luncher end return false end end #------------------------------------------------------------------------------ # ■ Game_Actor #------------------------------------------------------------------------------ class Game_Actor alias skill_learn_for_basic_attack_skill skill_learn? def skill_learn?(skill)# Game_Actor alias return skill_learn_for_basic_attack_skill(skill) || basic_attack_skill_list.include?(skill) end def basic_attack_skill key = (action.flags[:shortcut_reverse] ? 1 : 2) cheta = 10 key += :basic_attack_skill.to_i * cheta cheta **= 6 key += hand_symbol * cheta unless @paramater_cache[key] @paramater_cache[key] = [] @paramater_cache[key] += true_weapon.basic_attack_skill if true_weapon @paramater_cache[key] += actor.basic_attack_skill.compact end skills = BAT_ARY[0].clear + @paramater_cache[key] for skill in skills return skill if !skill || skill_can_use?(skill) end return nil end def basic_attack_skill_list skills = BAT_ARY[0].clear skills += true_weapon.basic_attack_skill if true_weapon skills += actor.basic_attack_skill return skills end def sub_attack_skill_list skills = BAT_ARY[0].clear skills += true_weapon.sub_attack_skill if true_weapon skills += actor.sub_attack_skill return skills end end #------------------------------------------------------------------------------ # ■ Game_Enemy #------------------------------------------------------------------------------ class Game_Enemy def basic_attack_skill for skill in enemy.basic_attack_skill return skill if !skill || skill_can_use?(skill) end return nil end def basic_attack_skill_list skills = BAT_ARY[0].clear skills += enemy.basic_attack_skill return skills end def sub_attack_skill_list skills = BAT_ARY[0].clear skills += enemy.sub_attack_skill return skills end end