Submit Your Article Guild Wars 2 Forum RPG Maker VX.com
 
RPG Maker
 

 Username:
 Password:
   Not a member? Register!



Home > RGSS Script Reference > Scene_Skill

Scene_Skill


Inherits from: None

Description: This class contains the windows and handles user input from the skill selection screen within the main menu. Note that skill selection in battle is handled by the Scene_Battle class.

Code


class Scene_Skill
# ------------------------------------
  def initialize(actor_index = 0, equip_index = 0)
    @actor_index = actor_index
  end
# ------------------------------------  
  def main
    @actor = $game_party.actors[@actor_index]
    @help_window = Window_Help.new
    @status_window = Window_SkillStatus.new(@actor)
    @skill_window = Window_Skill.new(@actor)
    @skill_window.help_window = @help_window
    @target_window = Window_Target.new
    @target_window.visible = false
    @target_window.active = false
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @help_window.dispose
    @status_window.dispose
    @skill_window.dispose
    @target_window.dispose
  end
# ------------------------------------ 
  def update
    @help_window.update
    @status_window.update
    @skill_window.update
    @target_window.update
    if @skill_window.active
      update_skill
      return
    end
    if @target_window.active
      update_target
      return
    end
  end
# ------------------------------------
  def update_skill
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Menu.new(1)
      return
    end
    if Input.trigger?(Input::C)
      @skill = @skill_window.skill
      if @skill == nil or not @actor.skill_can_use?(@skill.id)
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      $game_system.se_play($data_system.decision_se)
      if @skill.scope >= 3
        @skill_window.active = false
        @target_window.x = (@skill_window.index + 1) % 2 * 304
        @target_window.visible = true
        @target_window.active = true
        if @skill.scope == 4 || @skill.scope == 6
          @target_window.index = -1
        else
          @target_window.index = 0
        end
      else
        if @skill.common_event_id > 0
          $game_temp.common_event_id = @skill.common_event_id
          $game_system.se_play(@skill.menu_se)
          @actor.sp -= @skill.sp_cost
          @status_window.refresh
          @skill_window.refresh
          @target_window.refresh
          $scene = Scene_Map.new
          return
        end
      end
      return
    end
    if Input.trigger?(Input::R)
      $game_system.se_play($data_system.cursor_se)
      @actor_index += 1
      @actor_index %= $game_party.actors.size
      $scene = Scene_Skill.new(@actor_index)
      return
    end
    if Input.trigger?(Input::L)
      $game_system.se_play($data_system.cursor_se)
      @actor_index += $game_party.actors.size - 1
      @actor_index %= $game_party.actors.size
      $scene = Scene_Skill.new(@actor_index)
      return
    end
  end
# ------------------------------------
  def update_target
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @skill_window.active = true
      @target_window.visible = false
      @target_window.active = false
      return
    end
    if Input.trigger?(Input::C)
      unless @actor.skill_can_use?(@skill.id)
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      if @target_window.index == -1
        used = false
        for i in $game_party.actors
          used |= i.skill_effect(@actor, @skill)
        end
      end
      if @target_window.index >= 0
        target = $game_party.actors[@target_window.index]
        used = target.skill_effect(@actor, @skill)
      end
      if used
        $game_system.se_play(@skill.menu_se)
        @actor.sp -= @skill.sp_cost
        @status_window.refresh
        @skill_window.refresh
        @target_window.refresh
        if @skill.common_event_id > 0
          $game_temp.common_event_id = @skill.common_event_id
          $scene = Scene_Map.new
          return
        end
      end
      unless used
        $game_system.se_play($data_system.buzzer_se)
      end
      return
    end
  end
end

Properties


Actor_Index: The relative position within the party of the actor that is using a skill.

Actor: The absolute ID of the actor that is using a skill.

Help_Window: A Window_Help object that shows the skill description of the currently selected skill.

Status_Window: A Window_SkillStatus object. This shows the name, HP, SP, and status of the actor using a skill.

Skill_Window: A Window_Skill object. This is the main window where the actor's skills are displayed.

Target_Window: A Window_Target object that is made visible when a recovery skill is used so that the player can select the target of the skill.

Skill: The skill that has been selected.

Methods


Initialize

Arguments: None
Local Variables: None

How it Works: This method sets the relative party position of the actor using a skill to the value passed to this method.

Main

Arguments: None
Local Variables: None

How it Works: This is the main method that initializes the object, processes the update, and disposes of the object. First, the absolute ID of the actor using the skill is set using the actor index acquired during initialization. Next, the skill, help, skill status, and target windows are set up. The main loop updates the graphics, checks for input, and updates the window in response to user input. Once the value of $Scene has changed (when the user leaves the skill menu), the final part of the method disposes of the windows.

Update

Arguments: None
Local Variables: None

How it Works: This method updates the contents of the help window, status window, skill window, and target window, then decides which window should be checked for user input, based on which window is active. If the skill window is active, then Update_Skill is called to respond to user input from the skill window. If the target window is active, then Update_Target is called to respond to user input from the target window.

Update_Skill

Arguments: None
Local Variables: None

How it Works: This method responds to the user's input in the skill window. If the user's input is "B" (cancel key), then the cancel sound effect is played and control is transferred back to the main menu. If the user's input is "C" (decision key), then the value of @skill is set to the currently selected skill in the skill window. The method then checks to see if the selected skill can be used by the actor and that the skill is not nil. If one of these isn't the case, then the buzzer sound effect is played and no further processing is done. If the actor can use the skill at this time, then the decision sound effect is played and the skill's "scope" is checked. If the scope is 3 or greater (usable on allies or self), then control is transferred to the target window. The @target_window.x = (@item_window.index + 1) % 2 * 304 statement determines where the target window will appear. If the index of the selected item is odd, then that means selected skill is on the right side of the window, so the target window should appear on the left side (at X = 0). Otherwise, the selected skill is on the left side of the window and the target window should appear on the right side (at X = 304). If the "scope" of the skill being used is 4 (all allies) or 6 (all allies HP 0), then the selection index of the target window is set to -1 (a special index meaning "select all targets"). If only one target is called for, the index is set to 0 (the party leader). If the scope wasn't such that the target window would be activated, then the method checks if a common event is associated with the skill. If one is, then $game_temp.common_event_id is loaded with the common event's ID (so that it will be being executing as soon as the party returns to the map) and the SP cost of the skill used is deducted from the actor's current SP total.

Update_Target

Arguments: None
Local Variables:
Target: The relative party position of the target selected in the target window.
Used: This flag is set if the skill is actually used when a target is selected from the target window. It may not be used if it's an HP recovery skill and the target's HP is full, for instance.

How it Works: This method responds to user input on the target window. If the user input is "B" (cancel key), then the cancel sound effect is played and control is transferred back to the main window. If the user input is "C" (decision key), then the method calls the Game_Actor#Skill_Can_Use? method to check and see if the actor can use the skill. If the actor can't use the skill, then the buzzer sound effect plays and the method returns. If the target index is -1 (entire party), then the loop contained within applies the skill effect to each party member. The local variable used is necessary to keep track of whether the skill actually gets used or not. The skill may not be used if the skill being used is an HP recovery skill, but all legal targets are already at their maximum HP values, for instance. Otherwise, the skill effect is applied to the specific target and the return value of the Game_Battler#Skill_Effect method is stored in used. In the next section, the used flag comes into play. If the flag is set, then the menu sound effect is played, then the SP cost of the skill is subtracted from the user's total SP and the status, skill, and target windows. If there's a common event associated with the skill, then the ID of the common event is loaded into $game_temp.common_event_id and control is transferred back to the map for processing. If the used flag is not set, then the buzzer sound plays, since the target(s) of the skill were illegal. 
Syntax
@
@@
$
alias
[array index]
attr_accessor
attr_reader
attr_writer
class
def
do
ensure
for
if
[iterator]
key => value
new
next
nil
redo
require
return
rescue
self
super
undef
unless
until
while
yield

Classes
Arrow_Actor
Arrow_Base
Arrow_Enemy
Game_Actor
Game_Actors
Game_BattleAct
Game_Battler
Game_Character
Game_Common
Game_Enemy
Game_Event
Game_Map
Game_Party
Game_Picture
Game_Player
Game_Screen
Game_SlfSwitch
Game_Switches
Game_System
Game_Troop
Game_Variables
Interpreter
Scene_Debug
Scene_End
Scene_Equip
Scene_File
Scene_Gameover
Scene_Item
Scene_Load
Scene_Map
Scene_Menu
Scene_Name
Scene_Save
Scene_Shop
Scene_Skill
Scene_Status
Scene_Title
Sprite_Battler
Sprite_Character
Sprite_Picture
Sprite_Timer
Spriteset_Battle
Spriteset_Map
Window_Base
Window_Battleresult
Window_Battlestatus
Window_Command
Window_DebugLeft
Window_DebugRight
Window_EquipItem
Window_EquipLeft
Window_EquipRight
Window_Gold
Window_Help
Window_InputNumb
Window_Item
Window_MenuStatus
Window_Message
Window_NameEdit
Window_NameInput
Window_PartyCom
Window_PlayTime
Window_SaveFile
Window_Selectable
Window_ShopBuy
Window_ShopCom
Window_ShopNum
Window_ShopSell
Window_ShopStatus
Window_Skill
Window_SkillStatus
Window_Status
Window_Steps
Window_Target

Other
Class Hierarchy
Global Variables


RPG RPG Revolution
RPG RPG Revolution is your #1 stop for game development and console RPG games, as well as those created by people like you. Link to us to support us, so we may grow to be better website community for you.

RPG RPG Revolution is an Privacy Policy and Legal