Project1

标题: 被动技能脚本谁说明一下啊 [打印本页]

作者: 气味123    时间: 2010-8-24 15:11
标题: 被动技能脚本谁说明一下啊
  1. #--------------------------------------------------------------------------
  2. # □ RPG::Skill
  3. #--------------------------------------------------------------------------
  4. module RPG
  5. class Skill
  6.    #--------------------------------------------------------------------------
  7.    # ● 特技类型 (0 : 攻击, 1 : 回复, 2 : 支援, 3 : 被动)
  8.    #--------------------------------------------------------------------------
  9.    def type
  10.      if @occasion == 3
  11.        return 3
  12.      elsif @power == 0 and @atk_f == 0
  13.        return 2
  14.      elsif @power < 0
  15.        return 1
  16.      else
  17.        return 0
  18.      end
  19.    end
  20.    #--------------------------------------------------------------------------
  21.    # ● 被动技判定
  22.    #--------------------------------------------------------------------------
  23.    def innate?
  24.      return (type == 3)
  25.    end
  26.    #--------------------------------------------------------------------------
  27.    # ● 获得被动特技类型
  28.    #     skill : 特技
  29.    #--------------------------------------------------------------------------
  30.    def innate_type
  31.      # 不是被动特技的情况下
  32.      if not innate?
  33.        return -1
  34.      end
  35.      case @scope
  36.      when 0
  37.        # 属性防御类特技
  38.        if @element_set != []
  39.          return 1
  40.        # 状态防御类特技
  41.        elsif @minus_state_set != [] or @plus_state_set != []
  42.          return 2
  43.        # 数值加成类特技
  44.        else
  45.          return 0
  46.        end
  47.      when 1
  48.        return 3
  49.      end
  50.    end
  51.    #--------------------------------------------------------------------------
  52.    # ● 判断增加或减少
  53.    #     index : 判断项目
  54.    #--------------------------------------------------------------------------
  55.    def sign(index)
  56.      unless innate?
  57.        return 0
  58.      end
  59.      if index >= 0
  60.        return (@sp_cost & (2 ** index) == 2 ** index) ? -1 : 1
  61.      else
  62.        case innate_type
  63.        when 0
  64.          return 0
  65.        when 1
  66.          return @minus_state_set.include?(-index) ? -0.5 : 1
  67.        when 2
  68.          return (@sp_cost & 1024 == 1024) ? true : false
  69.        end
  70.      end
  71.    end
  72.    #--------------------------------------------------------------------------
  73.    # ● 最大 HP 上升量
  74.    #--------------------------------------------------------------------------
  75.    def maxhp_plus
  76.      return (innate? and innate_type <= 2) ? @hit * sign(6) : 0
  77.    end
  78.    #--------------------------------------------------------------------------
  79.    # ● 最大 SP 上升量
  80.    #--------------------------------------------------------------------------
  81.    def maxsp_plus
  82.      return (innate? and innate_type <= 2) ? @variance * sign(9) : 0
  83.    end
  84.    #--------------------------------------------------------------------------
  85.    # ● 力量上升量
  86.    #--------------------------------------------------------------------------
  87.    def str_plus
  88.      return (innate? and innate_type <= 2) ? @str_f * sign(2) : 0
  89.    end
  90.    #--------------------------------------------------------------------------
  91.    # ● 灵巧上升量
  92.    #--------------------------------------------------------------------------
  93.    def dex_plus
  94.      return (innate? and innate_type <= 2) ? @dex_f * sign(3): 0
  95.    end
  96.    #--------------------------------------------------------------------------
  97.    # ● 速度上升量
  98.    #--------------------------------------------------------------------------
  99.    def agi_plus
  100.      return (innate? and innate_type <= 2) ? @agi_f * sign(4) : 0
  101.    end
  102.    #--------------------------------------------------------------------------
  103.    # ● 魔力上升量
  104.    #--------------------------------------------------------------------------
  105.    def int_plus
  106.      return (innate? and innate_type <= 2) ? @int_f * sign(5) : 0
  107.    end
  108.    #--------------------------------------------------------------------------
  109.    # ● 攻击力上升量
  110.    #--------------------------------------------------------------------------
  111.    def atk_plus
  112.      return (innate? and innate_type <= 2) ? @atk_f * sign(0) : 0
  113.    end
  114.    #--------------------------------------------------------------------------
  115.    # ● 防御力上升量
  116.    #--------------------------------------------------------------------------
  117.    def pdef_plus
  118.      return (innate? and innate_type <= 2) ? @pdef_f * sign(7) : 0
  119.    end
  120.    #--------------------------------------------------------------------------
  121.    # ● 魔防力上升量
  122.    #--------------------------------------------------------------------------
  123.    def mdef_plus
  124.      return (innate? and innate_type <= 2) ? @mdef_f * sign(8) : 0
  125.    end
  126.    #--------------------------------------------------------------------------
  127.    # ● 回避修正上升量
  128.    #--------------------------------------------------------------------------
  129.    def eva_plus
  130.      return (innate? and innate_type <= 2) ? @eva_f * sign(1) : 0
  131.    end
  132.    #--------------------------------------------------------------------------
  133.    # ● 属性防御上升量
  134.    #     element_id : 属性ID
  135.    #--------------------------------------------------------------------------
  136.    def element_plus(element_id)
  137.      unless innate? and innate_type == 1
  138.        return 0
  139.      else
  140.        if @element_set.include?(element_id)
  141.          return Integer(@power * sign(-element_id))
  142.        else
  143.          return 0
  144.        end
  145.      end
  146.    end
  147.    #--------------------------------------------------------------------------
  148.    # ● 状态防御上升量
  149.    #     state_id : 状态ID
  150.    #--------------------------------------------------------------------------
  151.    def state_plus(state_id)
  152.      unless innate? and innate_type == 2 and not sign(-1)
  153.        return 0
  154.      else
  155.        if @plus_state_set.include?(state_id)
  156.          return @power
  157.        elsif @minus_state_set.include?(state_id)
  158.          return -@power
  159.        else
  160.          return 0
  161.        end
  162.      end
  163.    end
  164.    #--------------------------------------------------------------------------
  165.    # ● 状态防御集合
  166.    #--------------------------------------------------------------------------
  167.    def guard_state_set
  168.      return (innate? and innate_type == 2 and sign(-1)) ? @minus_state_set : []
  169.    end
  170.    #--------------------------------------------------------------------------
  171.    # ● 自动状态集合
  172.    #--------------------------------------------------------------------------
  173.    def auto_states
  174.      return (innate? and innate_type == 2 and sign(-1)) ? @plus_state_set : []
  175.    end
  176. end
  177. end
  178. #==============================================================================
  179. # ■ Game_Actor (分割定义 2)
  180. #------------------------------------------------------------------------------
  181. #  处理角色的类。本类在 Game_Actors 类 ($game_actors)
  182. # 的内部使用、Game_Party 类请参考 ($game_party) 。
  183. #==============================================================================

  184. class Game_Actor
  185. #--------------------------------------------------------------------------
  186. # ● 定义实例变量
  187. #--------------------------------------------------------------------------
  188. attr_reader   :innate_skills            # 被动特技
  189. alias sailcat_setup setup
  190. alias sailcat_learn_skill learn_skill
  191. alias sailcat_forget_skill forget_skill
  192. alias sailcat_base_maxhp base_maxhp
  193. alias sailcat_base_maxsp base_maxsp
  194. alias sailcat_base_str base_str
  195. alias sailcat_base_dex base_dex
  196. alias sailcat_base_agi base_agi
  197. alias sailcat_base_int base_int
  198. alias sailcat_base_atk base_atk
  199. alias sailcat_base_pdef base_pdef
  200. alias sailcat_base_mdef base_mdef
  201. alias sailcat_base_eva base_eva
  202. alias sailcat_element_rate element_rate
  203. alias sailcat_state_guard? state_guard?
  204. alias sailcat_hit hit
  205. #--------------------------------------------------------------------------
  206. # ● 设置
  207. #     actor_id : 角色 ID
  208. #--------------------------------------------------------------------------
  209. def setup(actor_id)
  210.    @innate_skills = []
  211.    sailcat_setup(actor_id)
  212. end
  213. #--------------------------------------------------------------------------
  214. # ● 领悟特技
  215. #     skill_id : 特技 ID
  216. #--------------------------------------------------------------------------
  217. def learn_skill(skill_id)
  218.    sailcat_learn_skill(skill_id)
  219.    unless @innate_skills.include?(skill_id)
  220.      @innate_skills.push(skill_id)
  221.      @innate_skills.sort!
  222.      update_skill_state(nil, $data_skills[skill_id])
  223.    end
  224. end
  225. #--------------------------------------------------------------------------
  226. # ● 遗忘特技
  227. #     skill_id : 特技 ID
  228. #--------------------------------------------------------------------------
  229. def forget_skill(skill_id)
  230.    sailcat_forget_skill(skill_id)
  231.    @innate_skills.delete(skill_id)
  232.    update_skill_state($data_skills[skill_id], nil)
  233. end
  234. #--------------------------------------------------------------------------
  235. # ● 更新被动特技的自动状态
  236. #     old_skill : 去除的特技
  237. #     new_skill : 设定的特技
  238. #--------------------------------------------------------------------------
  239. def update_skill_state(old_skill, new_skill)
  240.    if old_skill != nil and old_skill.auto_states != []
  241.      for state in old_skill.auto_states
  242.        remove_state(state, true)
  243.      end
  244.    end
  245.    if new_skill != nil and new_skill.auto_states != []
  246.      for state in new_skill.auto_states
  247.        add_state(state, true)
  248.      end
  249.    end
  250. end
  251. #--------------------------------------------------------------------------
  252. # ● 获取基本 MaxHP
  253. #--------------------------------------------------------------------------
  254. def base_maxhp
  255.    m = n = sailcat_base_maxhp
  256.    for skill_id in @innate_skills
  257.      skill = $data_skills[skill_id]
  258.      n += m * (skill != nil ? skill.maxhp_plus : 0) / 100
  259.    end
  260.    return n
  261. end
  262. #--------------------------------------------------------------------------
  263. # ● 获取基本 MaxSP
  264. #--------------------------------------------------------------------------
  265. def base_maxsp
  266.    m = n = sailcat_base_maxsp
  267.    for skill_id in @innate_skills
  268.      skill = $data_skills[skill_id]
  269.      n += m * (skill != nil ? skill.maxsp_plus : 0) / 100
  270.    end
  271.    return n
  272. end
  273. #--------------------------------------------------------------------------
  274. # ● 获取基本力量
  275. #--------------------------------------------------------------------------
  276. def base_str
  277.    m = n = sailcat_base_str
  278.    for skill_id in @innate_skills
  279.      skill = $data_skills[skill_id]
  280.      n += m * (skill != nil ? skill.str_plus : 0) / 100
  281.    end
  282.    return [n, 999].min
  283. end
  284. #--------------------------------------------------------------------------
  285. # ● 获取基本灵巧
  286. #--------------------------------------------------------------------------
  287. def base_dex
  288.    m = n = sailcat_base_dex
  289.    for skill_id in @innate_skills
  290.      skill = $data_skills[skill_id]
  291.      n += m * (skill != nil ? skill.dex_plus : 0) / 100
  292.    end
  293.    return [n, 999].min
  294. end
  295. #--------------------------------------------------------------------------
  296. # ● 获取基本速度
  297. #--------------------------------------------------------------------------
  298. def base_agi
  299.    m = n = sailcat_base_agi
  300.    for skill_id in @innate_skills
  301.      skill = $data_skills[skill_id]
  302.      n += m * (skill != nil ? skill.agi_plus : 0) / 100
  303.    end
  304.    return [n, 999].min
  305. end
  306. #--------------------------------------------------------------------------
  307. # ● 获取基本魔力
  308. #--------------------------------------------------------------------------
  309. def base_int
  310.    m = n = sailcat_base_int
  311.    for skill_id in @innate_skills
  312.      skill = $data_skills[skill_id]
  313.      n += m * (skill != nil ? skill.int_plus : 0) / 100
  314.    end
  315.    return [n, 999].min
  316. end
  317. #--------------------------------------------------------------------------
  318. # ● 获取基本攻击力
  319. #--------------------------------------------------------------------------
  320. def base_atk
  321.    m = n = sailcat_base_atk
  322.    for skill_id in @innate_skills
  323.      skill = $data_skills[skill_id]
  324.      n += m * (skill != nil ? skill.atk_plus : 0) / 100
  325.    end
  326.    return [n, 999].min
  327. end
  328. #--------------------------------------------------------------------------
  329. # ● 获取基本物理防御
  330. #--------------------------------------------------------------------------
  331. def base_pdef
  332.    m = n = sailcat_base_pdef
  333.    for skill_id in @innate_skills
  334.      skill = $data_skills[skill_id]
  335.      n += m * (skill != nil ? skill.pdef_plus : 0) / 100
  336.    end
  337.    return [n, 999].min
  338. end
  339. #--------------------------------------------------------------------------
  340. # ● 获取基本魔法防御
  341. #--------------------------------------------------------------------------
  342. def base_mdef
  343.    m = n = sailcat_base_mdef
  344.    for skill_id in @innate_skills
  345.      skill = $data_skills[skill_id]
  346.      n += m * (skill != nil ? skill.mdef_plus : 0) / 100
  347.    end
  348.    return [n, 999].min
  349. end
  350. #--------------------------------------------------------------------------
  351. # ● 获取基本回避修正
  352. #--------------------------------------------------------------------------
  353. def base_eva
  354.    n = sailcat_base_eva
  355.    for skill_id in @innate_skills
  356.      skill = $data_skills[skill_id]
  357.      n += skill != nil ? skill.eva_plus : 0
  358.    end
  359.    return [n, 100].min
  360. end
  361. #--------------------------------------------------------------------------
  362. # ● 获取命中率
  363. #--------------------------------------------------------------------------
  364. def hit
  365.    n = sailcat_hit
  366.    for skill_id in @innate_skills
  367.      skill = $data_skills[skill_id]
  368.      n = (skill != nil and skill.sign(12) == -1) ? 100 : n
  369.    end
  370.    return n
  371. end
  372. #--------------------------------------------------------------------------
  373. # ● 判定防御状态
  374. #     state_id : 状态 ID
  375. #--------------------------------------------------------------------------
  376. def state_guard?(state_id)
  377.    n = sailcat_state_guard?(state_id)
  378.    for skill_id in @innate_skills
  379.      skill = $data_skills[skill_id]
  380.      n |= skill.guard_state_set.include?(state_id) if skill != nil
  381.    end
  382.    return n
  383. end
  384. #--------------------------------------------------------------------------
  385. # ● 取得属性修正值
  386. #     element_id : 属性 ID
  387. #--------------------------------------------------------------------------
  388. def element_rate(element_id)
  389.    result = sailcat_element_rate(element_id)
  390.    for skill_id in @innate_skills
  391.      skill = $data_skills[skill_id]
  392.      if skill != nil
  393.        result -= skill.element_plus(element_id)
  394.        result = [[result, 300].min, -200].max
  395.      end
  396.    end
  397.    return result
  398. end
  399. #--------------------------------------------------------------------------
  400. # ● 取得状态修正值
  401. #     state_id : 状态 ID
  402. #--------------------------------------------------------------------------
  403. def state_rate(state_id)
  404.    table = [0,100,80,60,40,20,0]
  405.    result = table[self.state_ranks[state_id]]
  406.    for skill_id in @innate_skills
  407.      skill = $data_skills[skill_id]
  408.      if skill != nil
  409.        result -= skill.state_plus(state_id)
  410.        result = [[result, 100].min, 0].max
  411.      end
  412.    end
  413.    return result
  414. end
  415. end
  416. class Game_Battler
  417. #--------------------------------------------------------------------------
  418. # ● 状态变化 (+) 的适用
  419. #     plus_state_set  : 状态变化 (+)
  420. #--------------------------------------------------------------------------
  421. def states_plus(plus_state_set)
  422.    # 清除有效标志
  423.    effective = false
  424.    # 循环 (附加状态)
  425.    for i in plus_state_set
  426.      # 无法防御本状态的情况下
  427.      unless self.state_guard?(i)
  428.        # 这个状态如果不是 full 的话就设置有效标志
  429.        effective |= self.state_full?(i) == false
  430.        # 状态为 [不能抵抗] 的情况下
  431.        if $data_states[i].nonresistance
  432.          # 设置状态变化标志
  433.          @state_changed = true
  434.          # 附加状态
  435.          add_state(i)
  436.        # 这个状态不是 full 的情况下
  437.        elsif self.state_full?(i) == false
  438.          # 将状态的有效度变换为概率、与随机数比较
  439.          if rand(100) < self.state_rate(i)
  440.            # 设置状态变化标志
  441.            @state_changed = true
  442.            # 附加状态
  443.            add_state(i)
  444.          end
  445.        end
  446.      end
  447.    end
  448.    # 过程结束
  449.    return effective
  450. end
  451. end
  452. class Game_Enemy
  453. #--------------------------------------------------------------------------
  454. # ● 获取状态修正值
  455. #     state_id : 状态 ID
  456. #--------------------------------------------------------------------------
  457. def state_rate(state_id)
  458.    return [0,100,80,60,40,20,0][self.state_ranks[state_id]]
  459. end
  460. end
复制代码
里怎么设置啊




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1