Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- #
- # Pacman Advanced Creatived (PAC) Engine - Skills Shop Scene
- # 5/6/2011
- # Type: Scene
- # Installation: Simple values, event commands, tags.
- # Level: Difficult
- #
- #===============================================================================
- #
- # Description:
- # These seem quite popular, so I decided to make one. It's a fairly simple
- # skills shop(pe), functioning through script calls and tags. Trust me, it's
- # the simplest way to do it. Players will be able to purchase skills for their
- # actors and use them in battle and menus.
- #
- #===============================================================================
- #
- # Insctuctions:
- # INSTALLATION
- # Paste above main, below materials in the script editor. Remember to save.
- # Follow configuration, tags and call instructions as below.
- # CONFIGURATION
- # DEFAULT_BUY_SKIIL_COST is, of course, the default cost for all skills.
- # SKILL_LEARNED_ICON is the number of the icon that will display if the current
- # skill is already taught to them.
- # TAGS
- # <buy cost: x>
- # Sets the cost for the skill in whose notebox this is placed.
- # <buy class: x>
- # <buy class: x, x, x>
- # The classes that are allowed to buy the skill. If nothing is used, all will
- # be able to purchase it.
- # <buy actor: x>
- # <buy actor: x, x, x>
- # The actors able to purchase the skill. If nothing is used, all will be able
- # to buy it.
- # <buy level requirement: x>
- # The level required to purchase the skill.
- # SCRIPT CALLS
- # In an event, use the script command and enter the following syntax:
- # skills = [Skill IDs]
- # $scene = Scene_SkillShop.new(skills)
- # For example, use:
- # skills = [1, 2, 5, 6..10, 15...22, 60, 62]
- # $scene = Scene_SkillShop.new(skills)
- # To enter the skill shop with the chosen skill IDs. Note, .. means that all
- # numbers between the two, inclusive of the last one will be used, ... means
- # that all numbers between the two, exclusive of the last will be used.
- #
- #===============================================================================
- #
- # EDITING BEGINS AT LINE 65. DO NOT TOUCH LINES 55-63.
- #
- #===============================================================================
- $imported = {} if $imported == nil
- $imported["PAC_SkillShop"] = true
- module PAC
- module MENU
- #===============================================================================
- #
- # BEGIN EDIING
- #
- #===============================================================================
- # This is the default cost for skills.
- DEFAULT_BUY_SKILL_COST = 500
- # This icon will appear next to the actor's name if skill already learned.
- SKILL_LEARNED_ICON = 141
- #===============================================================================
- #
- # This script no longer requires editing. Do not edit anything in this script
- # unless you are a compenent scripter. Should you edit without any scripting
- # education, it may result in me tutting at you for getting it wrong.
- #
- #===============================================================================
- end
- end
- #==============================================================================
- # RPG::Skill
- #==============================================================================
- class RPG::Skill < RPG::UsableItem
- #--------------------------------------------------------------------------
- # * Buy Skill Cost
- #--------------------------------------------------------------------------
- def buy_skill_cost
- return @buy_skill_cost if @buy_skill_cost != nil
- @buy_skill_cost = PAC::MENU::DEFAULT_BUY_SKILL_COST
- self.note.split(/[\r\n]+/).each { |line|
- case line
- when /<(?:BUY_COST|BUY COST):[ ](\d+)>/i
- @buy_skill_cost = $1.to_i
- end
- }
- return @buy_skill_cost
- end
- #--------------------------------------------------------------------------
- # * Buy For Class Skill
- #--------------------------------------------------------------------------
- def buy_for_class_skill
- return @buy_for_class_skill if @buy_for_class_skill != nil
- @buy_for_class_skill = []
- self.note.split(/[\r\n]+/).each { |line|
- case line
- when /<(?:BUY_CLASS|BUY CLASS):[ ](\d+(?:\s*,\s*\d+)*)>/i
- $1.scan(/\d+/).each { |num|
- @buy_for_class_skill.push(num.to_i) if num.to_i > 0 }
- end
- }
- if @buy_for_class_skill == [] and self.buy_for_actor_skill == []
- for class_id in $data_classes
- @buy_for_class_skill.push(class_id.id)
- end
- end
- return @buy_for_class_skill
- end
- #--------------------------------------------------------------------------
- # * Buy For Actor Skill
- #--------------------------------------------------------------------------
- def buy_for_actor_skill
- return @buy_for_actor_skill if @buy_for_actor_skill != nil
- @buy_for_actor_skill = []
- self.note.split(/[\r\n]+/).each { |line|
- case line
- when /<(?:BUY_ACTOR|BUY ACTOR):[ ](\d+(?:\s*,\s*\d+)*)>/i
- $1.scan(/\d+/).each { |num|
- @buy_for_actor_skill.push(num.to_i) if num.to_i > 0 }
- end
- }
- return @buy_for_actor_skill
- end
- #--------------------------------------------------------------------------
- # * Buy Skill Level Requirement
- #--------------------------------------------------------------------------
- def buy_skill_level_requirement
- return @buy_skill_level_requirement if @buy_skill_level_requirement != nil
- @buy_skill_level_requirement = 0
- self.note.split(/[\r\n]+/).each { |line|
- case line
- when /<(?:BUY LEVEL REQUIREMENT|BUY LEVEL REQUIREMENT):[ ](\d+)>/i
- @buy_skill_level_requirement = $1.to_i
- end
- }
- return @buy_skill_level_requirement
- end
- end
- #==============================================================================
- # ** Window_SkillBuy
- #==============================================================================
- class Window_SkillBuy < Window_Selectable
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(gold_window, skill_list)
- @skill_list = skill_list
- window_y = gold_window.y + gold_window.height
- super(0, window_y, Graphics.width - 240, Graphics.height - window_y)
- refresh
- self.index = 0
- end
- #--------------------------------------------------------------------------
- # * Get Skill
- #--------------------------------------------------------------------------
- def skill
- return @data[self.index]
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- @data = []
- for skill in @skill_list
- @data.push(skill) if include?(skill)
- end
- @item_max = @data.size
- create_contents
- for i in 0...@item_max
- draw_item(i)
- end
- end
- #--------------------------------------------------------------------------
- # * Whether or not to include in skill list
- #--------------------------------------------------------------------------
- def include?(skill)
- return false if skill.nil?
- return true
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- rect = item_rect(index)
- self.contents.clear_rect(rect)
- skill = @data[index]
- if skill != nil
- rect.width -= 4
- enabled = can_buy_skill?(skill)
- draw_item_name(skill, rect.x, rect.y, enabled)
- self.contents.draw_text(rect, skill.buy_skill_cost, 2)
- end
- end
- #--------------------------------------------------------------------------
- # * Whether or not player can buy the skill
- #--------------------------------------------------------------------------
- def can_buy_skill?(skill)
- return false if skill.nil?
- return false if skill.buy_skill_cost > $game_party.gold
- return true
- end
- #--------------------------------------------------------------------------
- # * Update Help Text
- #--------------------------------------------------------------------------
- def update_help
- @help_window.set_text(skill == nil ? "" : skill.description)
- end
- end
- #==============================================================================
- # ** Window_SkillShopStatus
- #==============================================================================
- class Window_SkillShopStatus < Window_Selectable
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(buy_window)
- @buy_window = buy_window
- super(@buy_window.width, @buy_window.y, 240, @buy_window.height)
- self.active = false
- self.index = -1
- refresh
- end
- #--------------------------------------------------------------------------
- # * Get Actor
- #--------------------------------------------------------------------------
- def actor
- return @data[self.index]
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- @skill = @buy_window.skill
- @data = $game_party.members
- @item_max = @data.size
- create_contents
- for i in 0...@item_max
- draw_item(i)
- end
- end
- #--------------------------------------------------------------------------
- # * Get rectangle for displaying items
- #--------------------------------------------------------------------------
- def item_rect(index)
- rect = Rect.new(0, 0, 0, 0)
- rect.width = (contents.width + @spacing) / @column_max - @spacing
- rect.height = (contents.height / [@item_max, 1].max)
- rect.x = index % @column_max * (rect.width + @spacing)
- rect.y = index / @column_max * rect.height
- return rect
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- rect = item_rect(index)
- self.contents.clear_rect(rect)
- actor = @data[index]
- if actor != nil
- rect.width -= 4
- enabled = can_learn_skill?(actor, @skill)
- self.contents.font.color.alpha = enabled ? 255 : 128
- face_width = [92, rect.height-4].min
- draw_actor_face(actor, rect.x+2, rect.y+2, face_width)
- if actor.skill_learn?(@skill)
- draw_icon(PAC::MENU::SKILL_LEARNED_ICON, rect.x+4+face_width, rect.y+2)
- face_width += 24
- end
- self.contents.draw_text(rect.x+4+face_width, rect.y+2, 108, 24, actor.name)
- return if WLH*2 + rect.y+2 > rect.height + rect.y
- level = sprintf("%s %d", Vocab.level, actor.level)
- rect.y += WLH
- if actor.skill_learn?(@skill)
- draw_icon(@skill.icon_index, rect.x+4+face_width-24, rect.y+2)
- end
- self.contents.draw_text(rect.x+4+face_width, rect.y+2, 108, 24, level)
- end
- end
- #--------------------------------------------------------------------------
- # * Can the actor learn the skill?
- #--------------------------------------------------------------------------
- def can_learn_skill?(actor, skill)
- return false if skill.nil?
- return false if actor.skill_learn?(skill)
- return false if skill.buy_skill_level_requirement > actor.level
- return true if skill.buy_for_actor_skill.include?(actor.id)
- return true if skill.buy_for_class_skill.include?(actor.class.id)
- return false
- end
- end
- #==============================================================================
- # ** Scene_SkillShop
- #==============================================================================
- class Scene_SkillShop < Scene_Base
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(skill_list = [])
- id_list = []
- for skill_id in skill_list
- case skill_id
- when Integer
- id_list.push(skill_id)
- when Range
- id_list |= skill_id.to_a
- end
- end
- @skill_list = []
- for skill_id in id_list
- @skill_list.push($data_skills[skill_id])
- end
- end
- #--------------------------------------------------------------------------
- # * Start processing
- #--------------------------------------------------------------------------
- def start
- super
- create_menu_background
- @help_window = Window_Help.new
- @gold_window = Window_Gold.new(Graphics.width - 160, @help_window.height)
- create_command_window
- @buy_window = Window_SkillBuy.new(@gold_window, @skill_list)
- @buy_window.y = @gold_window.y + @gold_window.height
- @buy_window.help_window = @help_window
- @buy_window.active = false
- @status_window = Window_SkillShopStatus.new(@buy_window)
- end
- #--------------------------------------------------------------------------
- # * Termination Processing
- #--------------------------------------------------------------------------
- def terminate
- super
- dispose_menu_background
- @command_window.dispose
- @help_window.dispose
- @gold_window.dispose
- @buy_window.dispose
- @status_window.dispose
- end
- #--------------------------------------------------------------------------
- # * Create Command Window
- #--------------------------------------------------------------------------
- def create_command_window
- s1 = Vocab::ShopBuy
- s2 = Vocab::ShopCancel
- @command_window = Window_Command.new(Graphics.width - 160, [s1, s2], 2)
- @command_window.y = @gold_window.y
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- super
- update_menu_background
- @help_window.update
- @gold_window.update
- if @command_window.active
- update_command_selection
- elsif @buy_window.active
- update_buy_selection
- elsif @status_window.active
- update_status_selection
- end
- end
- #--------------------------------------------------------------------------
- # * Update Command Selection
- #--------------------------------------------------------------------------
- def update_command_selection
- @command_window.update
- if Input.trigger?(Input::B)
- Sound.play_cancel
- $scene = Scene_Map.new
- elsif Input.trigger?(Input::C)
- case @command_window.index
- when 0 # buy
- Sound.play_decision
- @command_window.active = false
- @buy_window.active = true
- when 1 # quit
- Sound.play_decision
- $scene = Scene_Map.new
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Update Buy Item Selection
- #--------------------------------------------------------------------------
- def update_buy_selection
- @buy_window.update
- if @last_buy_index != @buy_window.index
- @last_buy_index = @buy_window.index
- @status_window.refresh
- end
- if Input.trigger?(Input::B)
- Sound.play_cancel
- @command_window.active = true
- @buy_window.active = false
- @last_buy_index = -1
- elsif Input.trigger?(Input::C)
- if @buy_window.can_buy_skill?(@buy_window.skill)
- Sound.play_decision
- @status_window.index = 0
- @status_window.active = true
- @buy_window.active = false
- else
- Sound.play_buzzer
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Update Status Selection
- #--------------------------------------------------------------------------
- def update_status_selection
- @status_window.update
- if Input.trigger?(Input::B)
- Sound.play_cancel
- @status_window.index = -1
- @status_window.active = false
- @buy_window.active = true
- elsif Input.trigger?(Input::C)
- if @status_window.can_learn_skill?(@status_window.actor, @buy_window.skill)
- Sound.play_shop
- @status_window.actor.learn_skill(@buy_window.skill.id)
- $game_party.lose_gold(@buy_window.skill.buy_skill_cost)
- @gold_window.refresh
- @buy_window.refresh
- @status_window.refresh
- else
- Sound.play_buzzer
- end
- end
- end
- end
- #===============================================================================
- #
- # END OF SCRIPT
- #
- #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement