赞 | 0 |
VIP | 135 |
好人卡 | 6 |
积分 | 3 |
经验 | 37799 |
最后登录 | 2020-4-30 |
在线时间 | 812 小时 |
Lv2.观梦者 旅之愚者
- 梦石
- 0
- 星屑
- 275
- 在线时间
- 812 小时
- 注册时间
- 2007-7-28
- 帖子
- 2148
|
3楼
楼主 |
发表于 2010-9-12 08:03:52
|
只看该作者
本帖最后由 六祈 于 2011-1-10 21:16 编辑
连一帖发布代码
Skill_Level- #技能等级
- #————————————注意————————————————————————
- #———除了本页脚本外,还需要在存读档中追加dump和load技能数据库——————
- #————————————注意————————————————————————
- module RPG
- class Skill < UsableItem
- #定义技能等级上限的常数
- MAX_LEVEL = 10
- def level
- return @level.nil? ? 0 : @level
- end
-
- def level=(level)
- @level = [level , MAX_LEVEL].min
- end
-
- def learned?
- return level > 0
- end
-
- def level_top?
- return level == MAX_LEVEL
- end
-
- def base_damage
- n = @base_damage
- @base_damage_plus ||= self.read_note("base_damage")
- return @base_damage_plus.nil? ? n : (n + @base_damage_plus * level)
- end
-
- def base_damage_plus
- @base_damage_plus || 0
- end
-
- def atk_f
- n = @atk_f
- @atk_f_plus ||= self.read_note("atk_f")
- return @atk_f_plus.nil? ? n : (n + @atk_f_plus * level)
- end
-
- def atk_f_plus
- @atk_f_plus || 0
- end
-
- def spi_f
- n = @spi_f
- @spi_f_plus ||= self.read_note("spi_f")
- return @spi_f_plus.nil? ? n : (n + @spi_f_plus * level)
- end
-
- def spi_f_plus
- @spi_f_plus || 0
- end
-
- def mp_cost
- n = @mp_cost
- @mp_cost_plus ||= self.read_note("mp_cost")
- return @mp_cost_plus.nil? ? n : (n + @mp_cost_plus * level)
- end
-
- def mp_cost_plus
- @mp_cost_plus || 0
- end
- end
- end
复制代码 Skill_Leaf- #在技能树图中用于表示节点的类
- class Skill_Leaf
- attr_reader :x , :y , :id
-
- def initialize(skill_id)
- @id = skill_id
- @post_skills = []
- @x = 0
- @y = 0
- end
-
- def learned?
- skill.learned?
- end
-
- def set_x(x)
- @x = x
- end
-
- def set_y(y)
- @y = y
- end
-
- def skill
- $data_skills[@id]
- end
-
- def skill_icon
- $data_skills[@id].icon_index
- end
-
- def set_pre_skill(skill_id)
- @pre_skill = $data_skills[skill_id]
- end
-
- def can_learn?
- return ((@pre_skill.nil? or @pre_skill.learned?) and !skill.level_top?)
- end
-
- def post_skills
- @post_skills
- end
-
- def add_post_skill(skill_id)
- @post_skills.push(skill_id) unless @post_skills.include?(skill_id)
- end
- end
复制代码 Skill_Help- #描绘技能属性及升级变化的窗口
- class Window_Skill_Help < Window_Base
- attr_reader :skill_id
- def initialize(skill_id)
- super(0 , 0 , 180 , 176)
- @skill_id = skill_id
- refresh
- end
-
- def refresh
- self.contents.clear
- skill = $data_skills[@skill_id]
- self.contents.draw_text(0 , 0 , 146 , 24 , skill.name , 1)
- self.contents.draw_text(0 , 24 , 72 , 24 , "LV")
- self.contents.draw_text(72 , 24 , 74 , 24 , "%3d" % skill.level + (skill.level_top? ? "" : "→" + "%3d" % (skill.level + 1)))
- self.contents.draw_text(0 , 48 , 72 , 24 , "基础伤害")
- self.contents.draw_text(72 , 48 , 74 , 24 , "%3d" % skill.base_damage +
- (skill.level_top? ? "" : "→" + "%3d" % (skill.base_damage + skill.base_damage_plus)))
- self.contents.draw_text(0 , 72 , 72 , 24 , "MP消耗")
- self.contents.draw_text(72 , 72 , 74 , 24 , "%3d" % skill.mp_cost +
- (skill.level_top? ? "" : "→" + "%3d" % (skill.mp_cost + skill.mp_cost_plus)))
- self.contents.draw_text(0 , 96 , 72 , 24 , "攻击相关")
- self.contents.draw_text(72 , 96 , 74 , 24 , "%3d" % skill.atk_f +
- (skill.level_top? ? "" : "→" + "%3d" % (skill.atk_f + skill.atk_f_plus)))
- self.contents.draw_text(0 , 120 , 72 , 24 , "精神相关")
- self.contents.draw_text(72 , 120 , 74 , 24 , "%3d" % skill.spi_f +
- (skill.level_top? ? "" : "→" + "%3d" % (skill.spi_f + skill.spi_f_plus)))
- end
-
- def skill_id=(id)
- @skill_id = id
- refresh
- end
-
- end
复制代码 Window_Skill_Tree- class Window_Skill_Tree < Window_Base
- #连线粗细
- LINE_WEIGHT = 3
- #同一技能导出多个技能时x值的分散程度
- WIDTH = 240
- #整体y值位移(为了美观)
- Y_MOVE = -20
- attr_reader :x_index , :y_index
- def initialize(tree_id)
- super(0 , 0 , 240 , 360)
- @x_index = 0
- @y_index = 0
- #定义连线颜色
- @color = Color.new(175 , 28 , 200)
- #转换技能树为各个节点
- create_tree_levels(tree_id)
- #计算各节点y坐标
- calculate_y
- #计算各节点x坐标(x过大或负值过大均会修正)
- calculate_x
- #刷新(描绘点和连线)
- refresh
- #更新选择框
- update_cursor
- end
-
- def refresh
- self.contents.clear
- draw_leaves
- draw_branches
- end
-
- def create_tree_levels(tree_id)
- @levels = []
- level = 0
- @skills = {}
- while(temp = $data_skills[tree_id].read_note("level_" + (level + 1).to_s))
- @levels[level] = []
- temp.each do |id|
- @levels[level].push(@skills[id] = Skill_Leaf.new(id))
- end
- level += 1
- end
- connections = $data_skills[tree_id].read_note("connections")
- connections.each do |line|
- @skills[line[0]].add_post_skill(line[1])
- @skills[line[1]].set_pre_skill(line[0])
- end
- @level_max = @levels.size
- end
-
- def calculate_y
- @delta_y = (self.height - 32) / @levels.size / 2
- @levels.each_with_index do |level , i|
- level.each do |skill|
- skill.set_y(@delta_y * (i * 2 + 1) + Y_MOVE)
- end
- end
- end
-
- def calculate_x
- @levels[0].each_index do |index|
- @levels[0][index].set_x((self.width - 32) / @levels[0].size * (index * 2 + 1) / 2)
- end
- for i in 0...@level_max - 1
- @levels[i].each do |pre_skill|
- size = pre_skill.post_skills.size.to_f
- pre_skill.post_skills.each_with_index do |id , index|
- @skills[id].set_x(pre_skill.x + (((index + 1)/ (size + 1) - 0.5)* WIDTH).to_i)
- end
- end
- end
- @levels.each do |level|
- level.sort!{|a , b| a.x <=> b.x}
- end
- temp = @levels.flatten
- middle = self.width / 2 - 16
- max_x = temp.map{|leaf| (leaf.x - middle).abs}.max
- if max_x > middle - 20
- temp.each do |leaf|
- leaf.set_x(middle + (leaf.x - middle) * (middle - 20) / max_x)
- end
- end
- end
-
- def draw_leaves
- @levels.each do |level|
- level.each do |skill|
- draw_icon(skill.skill_icon , skill.x - 12 , skill.y - 12 , skill.learned?)
- end
- end
- end
-
- def draw_branches
- @skills.each_value do |skill|
- next if @levels[@level_max - 1].include?(skill)
- draw_lines(skill)
- end
- end
-
- def draw_lines(pre_skill)
- return if pre_skill.post_skills.size == 0
- post_skills = pre_skill.post_skills
- case post_skills.size
- when 1
- post_skill = @skills[post_skills[0]]
- self.contents.fill_rect(pre_skill.x , pre_skill.y + 12 , LINE_WEIGHT ,
- post_skill.y - pre_skill.y - 24 , color)
- else
- self.contents.fill_rect(pre_skill.x , pre_skill.y + 12 , LINE_WEIGHT ,
- @delta_y - 12 , color)
- x_start = post_skills.map{|id| @skills[id].x}.min
- x_end = post_skills.map{|id| @skills[id].x}.max
- self.contents.fill_rect(x_start , pre_skill.y + @delta_y ,
- x_end - x_start , LINE_WEIGHT , color)
- post_skills.each do |id|
- self.contents.fill_rect(@skills[id].x , pre_skill.y + @delta_y ,
- LINE_WEIGHT , @skills[id].y - pre_skill.y - @delta_y - 12 , color)
- end
- end
- end
- def update
- super
- if Input.trigger?(Input::LEFT)
- Sound.play_cursor unless @levels[@y_index].size == 1
- @x_index -= 1
- @x_index %= @levels[@y_index].size
- update_cursor
- return
- end
- if Input.trigger?(Input::RIGHT)
- Sound.play_cursor unless @levels[@y_index].size == 1
- @x_index += 1
- @x_index %= @levels[@y_index].size
- update_cursor
- return
- end
- if Input.trigger?(Input::UP)
- Sound.play_cursor
- @y_index -= 1
- @y_index %= @level_max
- @x_index = [@x_index , @levels[@y_index].size - 1].min
- update_cursor
- return
- end
- if Input.trigger?(Input::DOWN)
- Sound.play_cursor
- @y_index += 1
- @y_index %= @level_max
- @x_index = [@x_index , @levels[@y_index].size - 1].min
- update_cursor
- return
- end
- end
-
- def update_cursor
- if @x_index < 0 or @y_index < 0 # 当光标位置小于0
- self.cursor_rect.empty # 隐藏光标
- else
- skill = @levels[@y_index][@x_index]
- rect = Rect.new(skill.x - 12 , skill.y - 12 , 24 , 24)
- self.cursor_rect = rect # 更新光标矩形
- end
- end
-
- def skill_leaf
- @levels[@y_index][@x_index]
- end
-
- def color
- @color
- end
-
- end
复制代码 Scene_Skill_Tree- #使用方法:$scene = Scene_Skill_Tree(actor_id)
- class Scene_Skill_Tree < Scene_Base
- def initialize(actor_id)
- @actor = $game_actors[actor_id]
- end
-
- def start
- @trees = @actor.skill_trees
- @tree_window = Window_Command.new(160 , @trees.map{|id| $data_skills[id].name})
- @tree_window.x = 400
- @skill_window = Window_Skill_Tree.new(@trees[0])
- @map_spriteset = Spriteset_Map.new
- @description_window = Window_Base.new(240 , 0 , 120 , 56)
- refresh_description
- @help_window = Window_Skill_Help.new(skill_id)
- @help_window.z = 9999
- @help_window.visible = false
- move_help_window
- end
-
- def update
- if @tree_window.active
- update_tree
- return
- end
- if @skill_window.active
- update_skill
- return
- end
- end
-
- def terminate
- @skill_window.dispose
- @map_spriteset.dispose
- @description_window.dispose
- @help_window.dispose
- @tree_window.dispose
- end
-
- def update_tree
- @tree_window.update
- if Input.trigger?(Input::B)
- Sound.play_cancel
- $scene = Scene_Map.new
- return
- end
- if Input.trigger?(Input::C)
- Sound.play_decision
- @skill_window = Window_Skill_Tree.new(@trees[@tree_window.index])
- @help_window.visible = true
- @help_window.update
- @skill_window.active = true
- @tree_window.active = false
- return
- end
- end
-
- def update_skill
- @skill_window.update
- refresh_help_window
- if Input.trigger?(Input::B)
- Sound.play_cancel
- @help_window.visible = false
- @tree_window.active = true
- return
- end
- if Input.trigger?(Input::C)
- unless (@skill_window.skill_leaf.can_learn? and @actor.skill_point > 0)
- Sound.play_buzzer
- return
- else
- Sound.play_decision
- @skill_window.skill_leaf.skill.level += 1
- @actor.skill_point -= 1
- @actor.learn_skill(skill_id)
- @skill_window.refresh
- refresh_description
- @help_window.refresh
- return
- end
- end
- end
-
- def refresh_description
- @description_window.contents.clear
- @description_window.contents.draw_text(0 , 0 , 88 , 24 , "技能点: " + "%2d" % @actor.skill_point , 2)
- end
-
- def skill_id
- @skill_window.skill_leaf.id
- end
-
- def refresh_help_window
- if skill_id != @help_window.skill_id
- @help_window.skill_id = skill_id
- move_help_window
- end
- end
-
- def move_help_window
- @help_window.x = @skill_window.skill_leaf.x + 48
- @help_window.y = [@skill_window.skill_leaf.y + 24 , 416 - @help_window.height].min
- end
-
- end
复制代码 Game_Actor追加- class Game_Actor
- #每升一级获得技能点常数
- SKILL_POINT_PER_LEVEL = 5
- #获得技能树
- def skill_trees
- @skills.find_all{|skill_id| $data_skills[skill_id].description.index("skill_tree")}
- end
- #常规技能中排除技能树
- def skills
- result = []
- for i in @skills
- next if $data_skills[i].description.index("skill_tree")
- result.push($data_skills[i])
- end
- return result
- end
- #技能点的读写
- def skill_point
- return @skill_point.nil? ? 0 : @skill_point
- end
-
- def skill_point=(p)
- @skill_point = p
- end
- #追加定义,升级获得技能点
- alias :ski_lv_up :level_up
- def level_up
- ski_lv_up
- self.skill_point += SKILL_POINT_PER_LEVEL
- end
-
- end
复制代码 |
|