Project1

标题: “字符串”技能树 [打印本页]

作者: 恐惧剑刃    时间: 2013-10-18 22:02
标题: “字符串”技能树
本帖最后由 恋′挂机 于 2013-10-18 22:06 编辑

源自:http://rpg.blue/thread-336098-1-1.html



看似很复杂,其实很简单。



脚本参考,当然要自行做一些整合

选择窗口
  1. # --------------------
  2.   # 重要!!!!!!!!
  3.   # --------------------
  4.   attr_accessor :skill_case
  5.   attr_accessor :shuzhi_hash
复制代码
初始化
  1. # --------------------
  2.     # 重要!!!!!!!!
  3.     # --------------------
  4.    
  5.     # 判断选择状态用的哈希表
  6.     @skill_case = {}
  7.    
  8.     # 树枝的哈希表
  9.     @shuzhi_hash = {}
复制代码
添加
  1. # ------------------
  2.     # 描绘图标与树枝
  3.     # ------------------
  4.    
  5.     # 循环准备
  6.     xunhuan_time = 0
  7.    
  8.     jineng_time = 0
  9.    
  10.     # 简化
  11.     #@shuzhi_array.size - 1
  12.     #@shuzhi_array[jianqu1].split(/◎/)[0].to_i
  13.       
  14.     jianqu1 = @shuzhi_array.size - 1
  15.     jxmh = @shuzhi_array[jianqu1].split(/◎/)[0].to_i
  16.    
  17.     # 矩形
  18.     rect = Rect.new(0, 0, 24, 24)

  19.       
  20.     # 循环
  21.     for i in @shuzhi_array
  22.       # 坐标
  23.       x = (xunhuan_time % jxmh) * 32 + 4
  24.       y = (xunhuan_time / jxmh) * 32 + 4
  25.       # 不等与"☆"描绘
  26.       if i != "☆"
  27.         case i
  28.         # 技能图标
  29.         when "★"
  30.           # 图标透明度
  31.           unless @actor.skills.include?(@skill[jineng_time].id)
  32.             opacity_icon = 160
  33.           else
  34.             opacity_icon = 255
  35.           end
  36.           self.contents.blt(x, y, @icon[jineng_time], rect, opacity_icon)
  37.           # 以XY坐标为主键技能为值
  38.           @skill_case[x.to_s+"◎"+y.to_s] = @skill[jineng_time]
  39.           jineng_time += 1
  40.         # 树枝
  41.         when "→"
  42.           self.contents.blt(x, y, @shuzhi_picture[0], rect)
  43.           # 以XY坐标为主键方向字符为值
  44.           @shuzhi_hash[x.to_s+"◎"+y.to_s] = "→"
  45.         when "←"
  46.           self.contents.blt(x, y, @shuzhi_picture[1], rect)
  47.           # 以XY坐标为主键方向字符为值
  48.           @shuzhi_hash[x.to_s+"◎"+y.to_s] = "←"
  49.         when "↑"
  50.           self.contents.blt(x, y, @shuzhi_picture[2], rect)
  51.           # 以XY坐标为主键方向字符为值
  52.           @shuzhi_hash[x.to_s+"◎"+y.to_s] = "↑"
  53.         when "↓"
  54.           self.contents.blt(x, y, @shuzhi_picture[3], rect)
  55.           # 以XY坐标为主键方向字符为值
  56.           @shuzhi_hash[x.to_s+"◎"+y.to_s] = "↓"
  57.         when "↖"
  58.           self.contents.blt(x, y, @shuzhi_picture[4], rect)
  59.           # 以XY坐标为主键方向字符为值
  60.           @shuzhi_hash[x.to_s+"◎"+y.to_s] = "↖"
  61.         when "↗"
  62.           self.contents.blt(x, y, @shuzhi_picture[5], rect)
  63.           # 以XY坐标为主键方向字符为值
  64.           @shuzhi_hash[x.to_s+"◎"+y.to_s] = "↗"
  65.         when "↘"
  66.           self.contents.blt(x, y, @shuzhi_picture[6], rect)
  67.           # 以XY坐标为主键方向字符为值
  68.           @shuzhi_hash[x.to_s+"◎"+y.to_s] = "↘"
  69.         when "↙"
  70.           self.contents.blt(x, y, @shuzhi_picture[7], rect)
  71.           # 以XY坐标为主键方向字符为值
  72.           @shuzhi_hash[x.to_s+"◎"+y.to_s] = "↙"
  73.         end
  74.       end
  75.       # 项目判断
  76.       xunhuan_time += 1
  77.     end
复制代码
帮助刷新
  1. # 刷新帮助
  2.   def update_help
  3.    
  4.    
  5.     # 为了刷新,就只好牺牲内存了
  6.    
  7.     # 判断
  8.     #if self.index != @old_index
  9.       # 隐藏帮助
  10.       @help_window.visible = false
  11.       # 简化写法
  12.       jianqu1 = @shuzhi_array.size - 1
  13.       jxmh = @shuzhi_array[jianqu1].split(/◎/)[0].to_i
  14.       # 帮助坐标
  15.       x = (self.index % jxmh) * 32
  16.       y = (self.index / jxmh) * 32
  17.       # 循环
  18.       for i in @skill_case.keys
  19.         # 判断
  20.         if i == (x+4).to_s+"◎"+(y+4).to_s
  21.           @help_window.set_text(
  22.           x + 50, y, @skill_case[(x+4).to_s+"◎"+(y+4).to_s], @actor)
  23.         end
  24.       end
  25.     #  @old_index = self.index
  26.     #end
  27.    
  28.   end
复制代码
  1.   # 刷新选择窗口
  2.   def update_select_window
  3.     # B键的按下
  4.     if Input.trigger?(Input::B)
  5.       $scene = Scene_Map.new
  6.     end
  7.     # C键的按下
  8.     if Input.trigger?(Input::C)
  9.       
  10.       # 获取坐标,以坐标为媒介(主键)获取相关信息
  11.       
  12.       # 坐标
  13.       jianqu1 = SHEZHI::ACTOR_ARRAY[@actor.id].size - 1
  14.       jxmh = SHEZHI::ACTOR_ARRAY[@actor.id][jianqu1].split(/◎/)[0].to_i
  15.       
  16.       x = (@select_window.index % jxmh) * 32 + 4
  17.       y = (@select_window.index / jxmh) * 32 + 4
  18.       
  19.       # 判断是否选中技能
  20.       if @select_window.skill_case[x.to_s+"◎"+y.to_s] != nil
  21.         # 简化,方便之后使用skill值
  22.         skill = @select_window.skill_case[x.to_s+"◎"+y.to_s]
  23.         # 判断技能是否已经领悟
  24.         unless @actor.skills.include?(skill)

  25.           # ------------------
  26.           # 判断技能树关系
  27.           # (判断基础技能是否学习)
  28.           # ------------------
  29.           # 连接线:→←↑↓↖↗↘↙
  30.           # ------------------
  31.          
  32.           # 判断准备
  33.           base_skill_array = []
  34.          
  35.           # 左边:
  36.           x_copy = x - 32
  37.           y_copy = y
  38.          
  39.           if @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s] != nil
  40.             # 简化
  41.             shuzhi = @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s]
  42.             # 分歧
  43.             if shuzhi == "→"

  44.               # 获得基础技能坐标
  45.               x_copy = x - 64
  46.               y_copy = y
  47.               # 简化,通过基础技能坐标获取基础技能
  48.               base = @select_window.skill_case[x_copy.to_s+"◎"+y_copy.to_s]
  49.               base_skill_array << base
  50.               
  51.             end
  52.           end
  53.          
  54.           # 右边:
  55.           x_copy = x + 32
  56.           y_copy = y
  57.           if @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s] != nil
  58.             # 简化
  59.             shuzhi = @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s]
  60.             # 分歧
  61.             if shuzhi == "←"

  62.               # 获得基础技能坐标
  63.               x_copy = x + 64
  64.               y_copy = y
  65.               # 简化,通过基础技能坐标获取基础技能
  66.               base = @select_window.skill_case[x_copy.to_s+"◎"+y_copy.to_s]
  67.               base_skill_array << base
  68.               
  69.             end
  70.           end
  71.          
  72.           # 上边:
  73.           x_copy = x
  74.           y_copy = y - 32
  75.           if @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s] != nil
  76.             # 简化
  77.             shuzhi = @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s]
  78.             # 分歧
  79.             if shuzhi == "↓"

  80.               # 获得基础技能坐标
  81.               x_copy = x
  82.               y_copy = y - 64
  83.               # 简化,通过基础技能坐标获取基础技能
  84.               base = @select_window.skill_case[x_copy.to_s+"◎"+y_copy.to_s]
  85.               base_skill_array << base

  86.             end
  87.           end
  88.          
  89.           # 下边:
  90.           x_copy = x
  91.           y_copy = y + 32
  92.           if @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s] != nil
  93.             # 简化
  94.             shuzhi = @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s]
  95.             # 分歧
  96.             if shuzhi == "↑"

  97.               # 获得基础技能坐标
  98.               x_copy = x
  99.               y_copy = y + 64
  100.               # 简化,通过基础技能坐标获取基础技能
  101.               base = @select_window.skill_case[x_copy.to_s+"◎"+y_copy.to_s]
  102.               base_skill_array << base

  103.             end
  104.           end
  105.          
  106.           # 左上方:
  107.           x_copy = x - 32
  108.           y_copy = y - 32
  109.           if @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s] != nil
  110.             # 简化
  111.             shuzhi = @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s]
  112.             # 分歧
  113.             if shuzhi == "↘"

  114.               # 获得基础技能坐标
  115.               x_copy = x - 64
  116.               y_copy = y - 64
  117.               # 简化,通过基础技能坐标获取基础技能
  118.               base = @select_window.skill_case[x_copy.to_s+"◎"+y_copy.to_s]
  119.               base_skill_array << base

  120.             end
  121.           end
  122.          
  123.           # 右上方:
  124.           x_copy = x + 32
  125.           y_copy = y - 32
  126.           if @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s] != nil
  127.             # 简化
  128.             shuzhi = @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s]
  129.             # 分歧
  130.             if shuzhi == "↙"

  131.               # 获得基础技能坐标
  132.               x_copy = x + 64
  133.               y_copy = y - 64
  134.               # 简化,通过基础技能坐标获取基础技能
  135.               base = @select_window.skill_case[x_copy.to_s+"◎"+y_copy.to_s]
  136.               base_skill_array << base

  137.             end
  138.           end
  139.          
  140.           # 右下方:
  141.           x_copy = x + 32
  142.           y_copy = y + 32
  143.           if @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s] != nil
  144.             # 简化
  145.             shuzhi = @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s]
  146.             # 分歧
  147.             if shuzhi == "↖"

  148.               # 获得基础技能坐标
  149.               x_copy = x + 64
  150.               y_copy = y + 64
  151.               # 简化,通过基础技能坐标获取基础技能
  152.               base = @select_window.skill_case[x_copy.to_s+"◎"+y_copy.to_s]
  153.               base_skill_array << base

  154.             end
  155.           end
  156.          
  157.           # 左下方:
  158.           x_copy = x - 32
  159.           y_copy = y + 32
  160.           if @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s] != nil
  161.             # 简化
  162.             shuzhi = @select_window.shuzhi_hash[x_copy.to_s+"◎"+y_copy.to_s]
  163.             # 分歧
  164.             if shuzhi == "↗"

  165.               # 获得基础技能坐标
  166.               x_copy = x - 64
  167.               y_copy = y + 64
  168.               # 简化,通过基础技能坐标获取基础技能
  169.               base = @select_window.skill_case[x_copy.to_s+"◎"+y_copy.to_s]
  170.               base_skill_array << base

  171.             end
  172.           end
  173.          
  174.           # 处理干净
  175.           @yes_or_no = nil
  176.          
  177.           # 正式判断
  178.           if base_skill_array != []
  179.             for i in base_skill_array
  180.               # 任意一项基础技能已经领悟,把true就赋予@yes_or_no
  181.               if @actor.skills.include?(i.id)
  182.                 @yes_or_no = true
  183.               end
  184.             end
  185.             if @yes_or_no
  186.               # 领悟技能
  187.               @actor.learn_skill(skill.id)
  188.               # 选择窗口刷新
  189.               @select_window.refresh
  190.               # 刷新帮助窗口
  191.               @select_window.update_help
  192.             end
  193.           else
  194.             # 领悟技能
  195.             @actor.learn_skill(skill.id)
  196.             # 选择窗口刷新
  197.             @select_window.refresh
  198.             # 刷新帮助窗口
  199.             @select_window.update_help
  200.           end

  201.         end#include?
  202.       end#select
  203.       
  204.     end#if input c
  205.   end#def
复制代码







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