Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- #
- # Shanghai Simple Script - Skill Shop
- # Last Date Updated: 2010.06.06
- # Level: Normal
- #
- # This script lets actors buy skills from a shop and use them in battle.
- #===============================================================================
- # Instructions
- # -----------------------------------------------------------------------------
- # To install this script, open up your script editor and copy/paste this script
- # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
- #
- # <buy cost: x>
- # Sets the price for how much the skill sells for.
- #
- # <buy class: x>
- # <buy class: x, x, x>
- # The classes that are allowed to buy this skill. If nothing is used, then all
- # all classes are allowed to buy it.
- #
- # <buy actor: x>
- # <buy actor: x, x, x>
- # The actors that are allowed to buy this skill. No changes if nothing is used.
- #
- # <buy level requirement: x>
- # The required level in order to buy this skill.
- #
- # To launch the skill shop, type something like the following in a script call
- # event on the map.
- #
- # skills = [1, 2, 3, 4, 33..40, 41..80]
- # $scene = Scene_SkillShop.new(skills)
- #
- # And you will automatically be taken to the skill shop screen.
- #===============================================================================
- $imported = {} if $imported == nil
- $imported["SkillShop"] = true
- module SSS
- # This is the default cost for skills.
- DEFAULT_BUY_SKILL_COST = 1000
- # This icon will appear next to the actor's name if already learned the skill.
- SKILL_LEARNED_ICON = 141
- 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 = SSS::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(SSS::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 FILE
- #
- #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement