Advertisement
diamondandplatinum3

Skit System ~ RGSS3

Mar 24th, 2013
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 47.40 KB | None | 0 0
  1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. #             Skit System
  3. #             Version: 1.3
  4. #             Author: DiamondandPlatinum3
  5. #             Date: March 25, 2013    (Created)
  6. #                   June 23, 2014 (Updated)
  7. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. #  Description:
  9. #
  10. #    This script recreates a 'Tales' Skit System for use in RPG Maker VXA.
  11. #    With this script skits can be accessed anywhere if conditions are met.
  12. #    Skits are made in event themselves with a separate event per skit, thus
  13. #    allowing non-scripters to make a Skit Event in a comfortable environment (events).
  14. #
  15. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  16. #------------------------------------------------------------------------------
  17. #  Instructions:
  18. #
  19. #  ~  A video has been made to explain how to use this script.
  20. #     It can be seen here:    http://www.youtube.com/watch?v=uZhW5nAdods
  21. #
  22. #
  23. #
  24. #  ~  Edit the option in the Editable Region to suit your preferences.
  25. #
  26. #
  27. #           --------------------Skit Event--------------------
  28. #  ~  The first thing you need to do is to create an event with two pages.
  29. #     one with no page conditions and the second with a Self-Switch "A" condition.
  30. #     Page one needs an AUTORUN trigger associated with it.
  31. #     This Skit Event will NOT be added to the Skit list
  32. #     until you have entered the map where this event is located.
  33. #    
  34. #    
  35. #   ~ With that now done use the Script Call Command and Enter:
  36. #         start_skit("Skit Name")
  37. #     This lets the script know that you intend for this Event to be a Skit_Event.
  38. #     Replace "Skit Name" with whatever you want your skit to be called.
  39. #       ScreenShot can be found here:   http://goo.gl/5idbb
  40. #
  41. #
  42. #  ~  Now below that you insert conditional branches that you require to be true
  43. #     before the skit can be viewed
  44. #       ScreenShot can be found here:   http://goo.gl/1YLmQ
  45. #      
  46. #
  47. #  ~  This step is not necessary, but if you wish to have a 'logical or' condition
  48. #     for your skit, you can insert the following script call:
  49. #           skit_conditional_or
  50. #     after your initial conditional Statements are complete
  51. #       ScreenShot can be found here:   http://goo.gl/Hwypk
  52. #
  53. #
  54. #
  55. #  ~  Once you have finished setting up your Skit Conditions and are ready to
  56. #     start the eventing Phase, you must enter this script call:
  57. #           start_skit_conversation
  58. #     And you can now enter a complete event for your skit, including 'Show_Text',
  59. #     'Show_Picture', the whole lot.
  60. #       ScreenShot can be found here:   http://goo.gl/sz2Zi
  61. #
  62. #
  63. #  ~  Once the Entire Eventing portion of the Skit is Completed, you have the
  64. #     option of setting up unavailability conditions. These are NOT necessary to
  65. #     include, but if you want conditions where a Skit will no longer be available
  66. #     (Seriously, once a Skit is no longer available, you can't make it available again)
  67. #     you can use this script call:
  68. #           start_unavailable_skit_conditions
  69. #     And Enter Conditional Branches, same as above. You can also use the
  70. #     'Logical_Or' script call if you want to set multiple conditions as well.
  71. #       ScreenShot can be found here:   http://goo.gl/qjVpV
  72. #
  73. #
  74. #  ~  And you're done!
  75. #     You do not need to include a self-switch command as the script automatically
  76. #     activates Self-Switch "A" for you.
  77. #     The event is also temporarily erased from the map 'Erase Event Command'.
  78. #     Be sure that this Skit Event has a second page with Self-Switch "A" so that
  79. #     the skit is not called in a second time.
  80. #
  81. #
  82. #
  83. #
  84. #         --------------------Setting Up Images--------------------
  85. #  ~  You set up the specifics in the Editable Region, though the following
  86. #     screenshots can help you visualise the procedure.
  87. #               http://goo.gl/Cxv6i
  88. #               http://goo.gl/LlkZQ
  89. #
  90. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  91. ($diamondandplatinum3_scripts ||= {})[:SkitSystem] = true
  92. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  93. module DiamondandPlatinum3
  94.   module SkitSystem
  95.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  96.     #                                                        -=
  97.     #                 Editable Region        ////            ==
  98.     #                                                        =-
  99.     #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  100.     #==========================================================
  101.     #                     Skit Images
  102.     #==========================================================
  103.     Skit_Background_Image            = "Skit_Background_Image"   # Skit Background Image
  104.    
  105.     Skit_Animation_Button_Directory  = "Skit Button Animation"   # Folder Name of Animated Button Images
  106.     Number_of_Images                 = 3                         # Number of Relevant Images contained in said folder?
  107.     Animation_Wait_Timer             = 15                        # Wait Timer (in frames) before proceeding to the next animated image
  108.     Skit_Animation_Button_Specs      = [ 20, 10, 100, 75, 75 ]   # [ X Position, Y Position, Z Position, Image Width, Image Height ]
  109.     #==========================================================
  110.     #                     Skit Mechanics
  111.     #==========================================================
  112.     Font_Size                        = 18                        # Size of Font which displays the name of Skit
  113.     Font_Colour                      = [ 255, 255, 0 ]           # [R,G,B] Values for the Text Colour
  114.     Font_Style                       = "(Default)"               # If Using Custom Font Style, put the Style Name here. Else leave as "(Default)"
  115.    
  116.     Skit_Notifications_Max_Opacity   = 150                       # Opacity of the Skit Notifications (Images and Text)
  117.     Skit_Notifications_Fadein_Speed  = 1                         # Fade in Speed for Skit Notifications
  118.     Skit_Notifications_Fadeout_Speed = 3                         # Fadeout Speed of Skit Notification
  119.    
  120.     Skit_Key                         = :Y                        # Which Key will activate Skits? (See Table Below)
  121.                               #------------------------------------
  122.                               # Symbol | Representing Key(s)      |
  123.                               #------------------------------------
  124.                               # :DOWN  | Down Arrow Key           |
  125.                               # :LEFT  | Left Arrow Key           |
  126.                               # :RIGHT | Right Arrow Key          |
  127.                               # :UP    | Up Arrow Key             |
  128.                               # :A     | Shift Key                |
  129.                               # :B     | X & Escape Keys          | - - -> Not Recommended
  130.                               # :C     | Z, Return & Space Keys   | - ->/
  131.                               # :X     | A Key                    | - - >\
  132.                               # :Y     | S Key                    | - - ->\
  133.                               # :Z     | D Key                    | - - - -> Gotta Wonder how Enterbrain thought this was a good idea?
  134.                               # :L     | Q Key                    | - - ->/
  135.                               # :R     | W Key                    | - - >/
  136.                               # :SHIFT | Shift Key                |
  137.                               # :CTRL  | CTRL Key                 |
  138.                               # :ALT   | ALT Key                  |
  139.                               # :F5    | F5 Key                   |
  140.                               # :F6    | F6 Key                   |
  141.                               # :F7    | F7 Key                   |
  142.                               # :F8    | F8 Key                   |
  143.                               # :F9    | F9 Key                   |
  144.                               #------------------------------------
  145.     #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  146.     #                                           \/
  147.     #               End of Editable Region      /\
  148.     #                                           \/
  149.     #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  150.     #---------------------------------------------------------
  151.     # No touchie past here unless you know what you are
  152.     # doing. Failure to heed this warning could cause your
  153.     # computer to yell and scream at you.
  154.     #
  155.     # Edit at your own risk.
  156.     #--------------------------------------------------------
  157.    
  158.    
  159.    
  160.    
  161.    
  162.    
  163.    
  164.    
  165.    
  166.    
  167.     #--------------------------------------------------------------------------
  168.     # * Word Wrapping
  169.     #--------------------------------------------------------------------------
  170.     def self.word_wrapping(bitmap, text, pos = 0)
  171.       bitmap.font.bold            = true
  172.       bitmap.font.shadow          = true
  173.       bitmap.font.size            = Font_Size
  174.      
  175.       # Current Text Position
  176.       current_text_position = 0    
  177.      
  178.       for i in 0..(text.length - 1)
  179.         if text[i] == "\n"
  180.           current_text_position = 0
  181.           next
  182.         end
  183.        
  184.         # Current Position += character width
  185.         current_text_position += bitmap.text_size(text[i]).width
  186.        
  187.         # If Current Position > Window Width
  188.         if (pos + current_text_position) >= (Graphics.width - 32)
  189.           # Then Format the Sentence to fit Line
  190.           current_element = i
  191.           while(text[current_element] != " ")
  192.             break if current_element == 0
  193.             current_element -= 1
  194.           end
  195.          
  196.           temp_text = ""
  197.           for j in 0..(text.length - 1)
  198.             temp_text += text[j]
  199.             temp_text += "\n" if j == current_element
  200.           end
  201.           text = temp_text
  202.           i = current_element
  203.           current_text_position = 0
  204.         end
  205.       end
  206.       return text
  207.     end
  208.     #--------------------------------------------------------------------------
  209.     # * Draw Skit Text
  210.     #--------------------------------------------------------------------------
  211.     def self.draw_skit_text(bitmap, text)
  212.       x = y = h = 0
  213.       for i in 0..(text.length - 1)
  214.         if text[i] == "\n"
  215.           x  = 0
  216.           y += h
  217.           next
  218.         end
  219.         w = bitmap.text_size(text[i]).width
  220.         h = bitmap.text_size(text[i]).height
  221.         bitmap.draw_text(x, y, w * 2, h, text[i], 1)
  222.         x += w
  223.       end
  224.     end
  225.     #--------------------------------------------------------------------------
  226.     # * Get Bitmap Dimensions Based on Text
  227.     #--------------------------------------------------------------------------
  228.     def self.getbitmapdimensionsbasedontext(bitmap, text)
  229.       rwidth  = 0
  230.       height = 0
  231.       x = w = h = 0
  232.       hei = 0
  233.       for i in 0..(text.length - 1)
  234.         if text[i] == "\n"
  235.           rwidth = x if x > rwidth
  236.           height += hei
  237.           x = hei = 0
  238.           next
  239.         end
  240.         w = bitmap.text_size(text[i]).width
  241.         h = bitmap.text_size(text[i]).height
  242.         x += w
  243.         hei = h if h > hei
  244.       end
  245.       rwidth = x if x > rwidth
  246.       height += hei
  247.       return Rect.new(0, 0, rwidth, height)
  248.     end
  249.     #--------------------------------------------------------------------------
  250.     # * Condition Met?
  251.     #--------------------------------------------------------------------------
  252.     def self.condition_met?(info_array)
  253.       case info_array[0]
  254.       when :switch
  255.         return $game_switches[info_array[1]] == info_array[2]
  256.       when :variable
  257.         value = info_array[2] ? info_array[3] : $game_variables[info_array[3]]
  258.         return $game_variables[info_array[1]] == value    if info_array[4] == 0 # ==
  259.         return $game_variables[info_array[1]] >= value    if info_array[4] == 1 # >=
  260.         return $game_variables[info_array[1]] <= value    if info_array[4] == 2 # <=
  261.         return $game_variables[info_array[1]] >  value    if info_array[4] == 3 # >
  262.         return $game_variables[info_array[1]] <  value    if info_array[4] == 4 # <
  263.         return $game_variables[info_array[1]] != value                          # !=
  264.       when :timer
  265.         return false unless $game_timer.working?
  266.         return $game_timer.sec >= info_array[1] if info_array[2]
  267.         return $game_timer.sec <= info_array[1]
  268.       when :actor
  269.         return false unless $game_actors[info_array[1]]
  270.         return $game_party.members.include?($game_actors[info_array[1]])                  if info_array[2] == 0 # In Party
  271.         return $game_actors[info_array[1]].name == info_array[3]                          if info_array[2] == 1 # Name
  272.         return $game_actors[info_array[1]].class_id == info_array[3]                      if info_array[2] == 2 # Class
  273.         return $game_actors[info_array[1]].skill_learn?($data_skills[info_array[3]])      if info_array[2] == 3 # Skill
  274.         return $game_actors[info_array[1]].weapons.include?($data_weapons[info_array[3]]) if info_array[2] == 4 # Weapon
  275.         return $game_actors[info_array[1]].armors.include?($data_armors[info_array[3]])   if info_array[2] == 5 # Armour
  276.         return $game_actors[info_array[1]].state?(info_array[3])                                                # State
  277.       when :character
  278.         character = $game_map.interpreter.dp3_skitsystem_get_event_character(info_array[3], info_array[1])
  279.         return false unless character
  280.         return character.direction == info_array[2]
  281.       when :gold
  282.         return $game_party.gold >= info_array[1] if info_array[2] == 0 # >=
  283.         return $game_party.gold <= info_array[1] if info_array[2] == 1 # <=
  284.         return $game_party.gold <  info_array[1] if info_array[2] == 2 # <
  285.       when :item
  286.         return $game_party.has_item?($data_items[info_array[1]])
  287.       when :weapon
  288.         return $game_party.has_item?($data_weapons[info_array[1]], info_array[2])
  289.       when :armour
  290.         return $game_party.has_item?($data_armors[info_array[1]], info_array[2])
  291.       when :button
  292.         return Input.press?(info_array[1])
  293.       when :script
  294.         return $game_map.interpreter.dp3_skitsystem_get_script_call(info_array[1])
  295.       when :vehicle
  296.         return $game_player.vehicle == $game_map.vehicles[info_array[1]]
  297.       else
  298.         return false
  299.       end
  300.     end
  301.     #--------------------------------------------------------------------------
  302.     # * Unique Skit Name?
  303.     #--------------------------------------------------------------------------
  304.     def self.unique_skit_name?(name)
  305.       $game_system.dp3_skit_system_event_unseen_skit_hash.each_key do |key|
  306.         skit = $game_system.dp3_skit_system_event_unseen_skit_hash[key]
  307.         return false if name == skit.name
  308.       end
  309.       $game_system.dp3_skit_system_event_seen_skit_hash.each_key do |key|
  310.         skit = $game_system.dp3_skit_system_event_seen_skit_hash[key]
  311.         return false if name == skit.name
  312.       end
  313.       $game_system.dp3_skit_system_event_unavailable_hash.each_key do |key|
  314.         skit = $game_system.dp3_skit_system_event_unavailable_hash[key]
  315.         return false if name == skit.name
  316.       end
  317.       return true
  318.     end
  319.     #--------------------------------------------------------------------------
  320.     # * Unique Skit ID?
  321.     #--------------------------------------------------------------------------
  322.     def self.unique_skit_id?(id)
  323.       $game_system.dp3_skit_system_event_unseen_skit_hash.each_key do |key|
  324.         skit = $game_system.dp3_skit_system_event_unseen_skit_hash[key]
  325.         return false if id == skit.id
  326.       end
  327.       $game_system.dp3_skit_system_event_seen_skit_hash.each_key do |key|
  328.         skit = $game_system.dp3_skit_system_event_seen_skit_hash[key]
  329.         return false if id == skit.id
  330.       end
  331.       $game_system.dp3_skit_system_event_unavailable_hash.each_key do |key|
  332.         skit = $game_system.dp3_skit_system_event_unavailable_hash[key]
  333.         return false if id == skit.id
  334.       end
  335.       return true
  336.     end
  337.     #--------------------------------------------------------------------------
  338.     # * Get Available Skits
  339.     #--------------------------------------------------------------------------
  340.     def self.get_available_skits()
  341.       skits = []
  342.       $game_system.dp3_skit_system_event_unseen_skit_hash.each_key do |key|
  343.         skit = $game_system.dp3_skit_system_event_unseen_skit_hash[key]
  344.         skits[skits.size] = skit if skit.skit_available?()
  345.       end
  346.       return skits
  347.     end
  348.     #--------------------------------------------------------------------------
  349.     # * Get Unavailable Skits
  350.     #--------------------------------------------------------------------------
  351.     def self.get_unavailable_skits()
  352.       skits = []
  353.       $game_system.dp3_skit_system_event_unseen_skit_hash.each_key do |key|
  354.         skit = $game_system.dp3_skit_system_event_unseen_skit_hash[key]
  355.         skits[skits.size] = skit if skit.skit_unavailable?()
  356.       end
  357.       return skits
  358.     end
  359.   end
  360. end
  361.  
  362.  
  363.  
  364. #==============================================================================
  365. # ** Skit_Event
  366. #------------------------------------------------------------------------------
  367. #  A class which holds the relative information for the various user made Skits
  368. #  including conditions for availability and unavailability and conversation.
  369. #  Holds one Skit per class instance
  370. #==============================================================================
  371.  
  372. class DP3_Skit_Event
  373.   #--------------------------------------------------------------------------
  374.   # * Public Instance Variables
  375.   #--------------------------------------------------------------------------
  376.   attr_reader :name                     # Skit Name
  377.   attr_reader :id                       # Skit ID (Used for Hash Identity)
  378.   attr_reader :conditions               # Conditions to View Skit
  379.   attr_reader :unavailable_conditions   # Conditions to stop Skit Availability
  380.   attr_reader :event_commands           # Event Commands
  381.   #--------------------------------------------------------------------------
  382.   # * Object Initialization
  383.   #--------------------------------------------------------------------------
  384.   def initialize()
  385.     @name = "Skit"
  386.     @id = 1
  387.     @conditions = {}
  388.     @unavailable_conditions = {}
  389.     @event_commands = {}
  390.   end
  391.   #--------------------------------------------------------------------------
  392.   # * Name=
  393.   #--------------------------------------------------------------------------
  394.   def name=(string)
  395.     @name = string if string.is_a?(String)
  396.   end
  397.   #--------------------------------------------------------------------------
  398.   # * ID=
  399.   #--------------------------------------------------------------------------
  400.   def id=(integer)
  401.     @id = integer if integer.is_a?(Integer)
  402.   end
  403.   #--------------------------------------------------------------------------
  404.   # * Conditions=
  405.   #--------------------------------------------------------------------------
  406.   def conditions=(conditions_array)
  407.     return if conditions_array.empty?
  408.     @conditions = conditions_array
  409.   end
  410.   #--------------------------------------------------------------------------
  411.   # * Unavailable_Conditions=
  412.   #--------------------------------------------------------------------------
  413.   def unavailable_conditions=(conditions_array)
  414.     return if conditions_array.empty?
  415.     @unavailable_conditions = conditions_array
  416.   end
  417.   #--------------------------------------------------------------------------
  418.   # * Event_Commands=
  419.   #--------------------------------------------------------------------------
  420.   def event_commands=(commands_hash)
  421.     return if commands_hash.empty?
  422.     @event_commands = commands_hash
  423.   end
  424.   #--------------------------------------------------------------------------
  425.   # * Skit Available?
  426.   #--------------------------------------------------------------------------
  427.   def skit_available?()
  428.     @conditions.each_key do |key|
  429.       available = false
  430.       @conditions[key].each do |info_array|
  431.         available = DiamondandPlatinum3::SkitSystem::condition_met?(info_array)
  432.         break unless available
  433.       end
  434.       return true if available
  435.     end
  436.     return false
  437.   end
  438.   #--------------------------------------------------------------------------
  439.   # * Skit Unavailable?
  440.   #--------------------------------------------------------------------------
  441.   def skit_unavailable?()
  442.     @unavailable_conditions.each_key do |key|
  443.       unavailable = false
  444.       @unavailable_conditions[key].each do |info_array|
  445.         unavailable = DiamondandPlatinum3::SkitSystem::condition_met?(info_array)
  446.         break unless unavailable
  447.       end
  448.       return true if unavailable
  449.     end
  450.     return false
  451.   end
  452. end
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462. #==============================================================================
  463. # ** Game_Temp
  464. #------------------------------------------------------------------------------
  465. #  This class handles temporary data that is not included with save data.
  466. # The instance of this class is referenced by $game_temp.
  467. #==============================================================================
  468.  
  469. class Game_Temp
  470.   #--------------------------------------------------------------------------
  471.   # * Public Instance Variables
  472.   #--------------------------------------------------------------------------
  473.   attr_accessor :dp3_skit_instance                # Instance of a Skit Class
  474.   #--------------------------------------------------------------------------
  475.   # * Object Initialization
  476.   #--------------------------------------------------------------------------
  477.   alias dp3_skitsystem_gametemp_initialize_wi36                    initialize
  478.   #--------------------------------------------------------------------------
  479.   def initialize
  480.     @dp3_skit_instance = nil
  481.     dp3_skitsystem_gametemp_initialize_wi36() # Call Original Method
  482.   end
  483. end
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493. #==============================================================================
  494. # ** Game_System
  495. #------------------------------------------------------------------------------
  496. #  This class handles system data. It saves the disable state of saving and
  497. # menus. Instances of this class are referenced by $game_system.
  498. #==============================================================================
  499.  
  500. class Game_System
  501.   #--------------------------------------------------------------------------
  502.   # * Public Instance Variables
  503.   #--------------------------------------------------------------------------
  504.   attr_accessor :dp3_skit_system_event_unseen_skit_hash  # Skits That Can Be Seen, but have not yet met conditions
  505.   attr_accessor :dp3_skit_system_event_seen_skit_hash    # Skits that have been Viewed
  506.   attr_accessor :dp3_skit_system_event_unavailable_hash  # Skits that were not viewed and have reached the missable skit condition
  507.   #--------------------------------------------------------------------------
  508.   # * Alias Listings
  509.   #--------------------------------------------------------------------------
  510.   alias dp3_skitsystem_gamesystem_initialize_wi36                  initialize
  511.   #--------------------------------------------------------------------------
  512.   # * Object Initialization
  513.   #--------------------------------------------------------------------------
  514.   def initialize()
  515.     @dp3_skit_system_event_unseen_skit_hash = {}
  516.     @dp3_skit_system_event_seen_skit_hash   = {}
  517.     @dp3_skit_system_event_unavailable_hash = {}
  518.    
  519.     dp3_skitsystem_gamesystem_initialize_wi36() # Call Original Method
  520.   end
  521. end
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531. #==============================================================================
  532. # ** Game_Map
  533. #------------------------------------------------------------------------------
  534. #  This class handles maps. It includes scrolling and passage determination
  535. # functions. The instance of this class is referenced by $game_map.
  536. #==============================================================================
  537.  
  538. class Game_Map
  539.   #--------------------------------------------------------------------------
  540.   # * Setup New Skit Event
  541.   #--------------------------------------------------------------------------
  542.   def dp3_skitsystem_setupnewskit
  543.     event_page         = RPG::Event::Page.new()   # New Event Page
  544.     event_page.trigger = 3                        # Autorun Trigger
  545.    
  546.     # Add in EventCommands from OriginalSkitEvent
  547.     $game_temp.dp3_skit_instance.event_commands.each_key do |key|
  548.       slot                             = event_page.list.size
  549.       event_page.list[slot]            = RPG::EventCommand.new()
  550.       event_page.list[slot].parameters = $game_temp.dp3_skit_instance.event_commands[key][0]
  551.       event_page.list[slot].indent     = $game_temp.dp3_skit_instance.event_commands[key][1]
  552.       event_page.list[slot].code       = $game_temp.dp3_skit_instance.event_commands[key][2]
  553.     end
  554.    
  555.     # At the End of the EventCommandList, Add in an Erase_Event_Command
  556.     slot                             = event_page.list.size
  557.     event_page.list[slot]            = RPG::EventCommand.new()
  558.     event_page.list[slot].parameters = []
  559.     event_page.list[slot].indent     = 0
  560.     event_page.list[slot].code       = 214
  561.  
  562.    
  563.     # Make the Skit Event
  564.     event           = RPG::Event.new(0, 0)    # X,Y Coords
  565.     event.name      = "Skit Event"            # Name
  566.     event.id        = self.events.size + 1    # ID is completely last event on Map
  567.     event.pages[0]  = event_page              # Pass in Page made above
  568.    
  569.     # Make Game_Event
  570.     game_event = Game_Event.new(self.map_id, event)
  571.  
  572.     # Finally Add Event in the Hash
  573.     self.events[event.id] = game_event  
  574.   end
  575. end
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585. #==============================================================================
  586. # ** Game_Interpreter
  587. #------------------------------------------------------------------------------
  588. #  An interpreter for executing event commands. This class is used within the
  589. # Game_Map, Game_Troop, and Game_Event classes.
  590. #==============================================================================
  591.  
  592. class Game_Interpreter
  593.   #--------------------------------------------------------------------------
  594.   # * New Method: Get Event Character
  595.   #--------------------------------------------------------------------------
  596.   def dp3_skitsystem_get_event_character(map_id, event_id)
  597.     curr_map_id = @map_id
  598.     @map_id     = map_id
  599.     event       = get_character(event_id)
  600.     @map_id     = curr_map_id
  601.     return event
  602.   end
  603.   #--------------------------------------------------------------------------
  604.   # * New Method: Get Event Character
  605.   #--------------------------------------------------------------------------
  606.   def dp3_skitsystem_get_script_call(string)
  607.     return eval(string)
  608.   end
  609.   #--------------------------------------------------------------------------
  610.   # * Get Conditional Branch Params
  611.   #--------------------------------------------------------------------------
  612.   def dp3_skitsystem_getconditionbranchparams()
  613.     array = []
  614.     case @params[0]
  615.       when 0;  array = [:switch,     @params[1], @params[2] == 0]
  616.       when 1;  array = [:variable,   @params[1], @params[2] == 0,  @params[3], @params[4]]
  617.       when 3;  array = [:timer,      @params[1], @params[2] == 0]
  618.       when 4;  array = [:actor,      @params[1], @params[2],       @params[3]]
  619.       when 6;  array = [:character,  @params[1], @params[2],       @map_id]
  620.       when 7;  array = [:gold,       @params[1], @params[2]]
  621.       when 8;  array = [:item,       @params[1]]
  622.       when 9;  array = [:weapon,     @params[1], @params[2]]
  623.       when 10; array = [:armour,     @params[1], @params[2]]
  624.       when 11; array = [:button,     @params[1]]
  625.       when 12; array = [:script,     @params[1]]
  626.       when 13; array = [:vehicle,    @params[1]]
  627.     end
  628.     return array
  629.   end
  630.   #--------------------------------------------------------------------------
  631.   # * New Method: Get Skit Conditions
  632.   #--------------------------------------------------------------------------
  633.   def dp3_skitsystem_getskitconditions()
  634.     skit_conditions_hash = {}
  635.     condition_key = 1
  636.    
  637.     # While not EOF
  638.     while(@list[@index])
  639.       # Add Skit Conditions
  640.       if @list[@index].code == 111
  641.         @params = @list[@index].parameters
  642.         skit_conditions_hash[condition_key] = [] if skit_conditions_hash[condition_key].nil?
  643.         i = skit_conditions_hash[condition_key].size
  644.         skit_conditions_hash[condition_key][i] = dp3_skitsystem_getconditionbranchparams()
  645.       end
  646.      
  647.       # Check to See if Conditional Else Branching or Entering Conversation Phase
  648.       if @list[@index].code == 355 || @list[@index].code == 655
  649.         if @list[@index].parameters[0].include?("skit_conditional_or")
  650.           skit_conditional_or()
  651.           condition_key += 1
  652.         elsif @list[@index].parameters[0].include?("start_skit_conversation")
  653.           start_skit_conversation()
  654.           @index += 1
  655.           break
  656.         end
  657.       end
  658.       @index += 1
  659.     end
  660.     return skit_conditions_hash
  661.   end
  662.   #--------------------------------------------------------------------------
  663.   # * New Method: Get Skit Conversation Commands
  664.   #--------------------------------------------------------------------------
  665.   def dp3_skitsystem_getskitconversationcommands()
  666.     event_lines = {}
  667.     event_key = 1
  668.    
  669.     # While not EOF
  670.     while(@list[@index])
  671.       # Check Script Calls For Next Phase
  672.       if @list[@index].code == 355 || @list[@index].code == 655
  673.         if @list[@index].parameters[0].include?("start_unavailable_skit_conditions")
  674.           start_unavailable_skit_conditions()
  675.           @index += 1
  676.           break
  677.         end
  678.       end
  679.       # Add Event Command to List
  680.       event_lines[event_key]    = []
  681.       event_lines[event_key][0] = @list[@index].parameters
  682.       event_lines[event_key][1] = @list[@index].indent
  683.       event_lines[event_key][2] = @list[@index].code
  684.       event_key += 1
  685.       @index += 1
  686.     end
  687.     return event_lines
  688.   end
  689.   #--------------------------------------------------------------------------
  690.   # * New Method: Get Skit Unavailable Conditions
  691.   #--------------------------------------------------------------------------
  692.   def dp3_skitsystem_getskitunavailableconditions()
  693.     skit_conditions_hash = {}
  694.     return skit_conditions_hash unless @list[@index] # Not EOF
  695.     command_key = 1
  696.    
  697.     # While not EOF
  698.     while(@list[@index])
  699.       # Check if Conditional Else Branching is being Made
  700.       if @list[@index].code == 355 || @list[@index].code == 655
  701.         if @list[@index].parameters[0].include?("skit_conditional_or")
  702.           skit_conditional_or()
  703.           command_key += 1
  704.         end
  705.       end
  706.      
  707.       # Add Skit Conditions
  708.       if @list[@index].code == 111
  709.         @params = @list[@index].parameters
  710.         skit_conditions_hash[command_key] = [] if skit_conditions_hash[command_key].nil?
  711.         i = skit_conditions_hash[command_key].size
  712.         skit_conditions_hash[command_key][i] = dp3_skitsystem_getconditionbranchparams()
  713.       end
  714.       @index += 1
  715.     end
  716.     return skit_conditions_hash
  717.   end
  718.   #--------------------------------------------------------------------------
  719.   # * New Method: Start Skit
  720.   #--------------------------------------------------------------------------
  721.   def start_skit(skit_name)
  722.     # Set up Skit Name & ID
  723.     skit_name = skit_name.is_a?(String) ? skit_name.gsub(/[\n\r]+/, "") : "Skit"
  724.     skit_id   = 1
  725.    
  726.     # Move Past this Script Call
  727.     @index += 1
  728.    
  729.     # We're looking for a Conditional Branch to use for the skit
  730.     while(@list[@index].code != 111)    # Conditional Branch
  731.       return unless @list[@index]       # Exit if EOF is Reached
  732.       execute_command()
  733.       @index += 1
  734.     end
  735.    
  736.     # Skit Available Conditions
  737.     skit_conditions_hash = dp3_skitsystem_getskitconditions()
  738.    
  739.     # Return Error if EOF is Reached
  740.     return -1 unless @list[@index]
  741.    
  742.     # Skit Conversation
  743.     event_commands = dp3_skitsystem_getskitconversationcommands()
  744.    
  745.     # Skit Unavailable Conditions
  746.     skit_unavailable_conditions_hash = dp3_skitsystem_getskitunavailableconditions()
  747.    
  748.     # Unique Skit Name?
  749.     temp_name   = skit_name
  750.     temp_number = 1
  751.     while(!DiamondandPlatinum3::SkitSystem::unique_skit_name?(temp_name))
  752.       temp_number += 1
  753.       temp_name = skit_name + "_" +
  754.                   (temp_number < 1000 ? "0" : "") +
  755.                   (temp_number < 100  ? "0" : "") +
  756.                   (temp_number < 10   ? "0" : "") +
  757.                   temp_number.to_s
  758.     end
  759.     skit_name = temp_name
  760.    
  761.     # Unique Skit ID?
  762.     skit_id += 1 while(!DiamondandPlatinum3::SkitSystem::unique_skit_id?(skit_id))
  763.    
  764.     # Add Skit
  765.     skit                        = DP3_Skit_Event.new()
  766.     skit.name                   = skit_name
  767.     skit.id                     = skit_id
  768.     skit.conditions             = skit_conditions_hash
  769.     skit.unavailable_conditions = skit_unavailable_conditions_hash
  770.     skit.event_commands         = event_commands
  771.    
  772.     $game_system.dp3_skit_system_event_unseen_skit_hash[skit_id] = skit
  773.    
  774.    
  775.     # Call Self_Switch "A" && Erase Event on Skit PlaceHolder Event
  776.     @params[0] = "A"
  777.     @params[1] = 0
  778.     command_123()
  779.     command_214()    
  780.   end
  781.   #--------------------------------------------------------------------------
  782.   # * New Method: Start Skit Conversation
  783.   #--------------------------------------------------------------------------
  784.   def start_skit_conversation()
  785.     # Only Exists just in case User Calls Method by Mistake in an unrelated Event.
  786.     # Skit EventCommands use this method call to detect which phase it should
  787.     # enter, the method itself is not actually necessary.
  788.   end
  789.   #--------------------------------------------------------------------------
  790.   # * New Method: Start Unavailable Skit Conditions
  791.   #--------------------------------------------------------------------------
  792.   def start_unavailable_skit_conditions()
  793.   end
  794.   #--------------------------------------------------------------------------
  795.   # * New Method: Skit Condition 'OR'
  796.   #--------------------------------------------------------------------------
  797.   def skit_conditional_or()
  798.   end
  799. end
  800.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809. #==============================================================================
  810. # ** Scene_Map
  811. #------------------------------------------------------------------------------
  812. #  This class performs the map screen processing.
  813. #==============================================================================
  814.  
  815. class Scene_Map < Scene_Base
  816.   #--------------------------------------------------------------------------
  817.   # * Alias Listings
  818.   #--------------------------------------------------------------------------
  819.   alias dp3_skitsystem_scenemap_start_wi36                          start
  820.   alias dp3_skitsystem_scenemap_terminate_wi36                      terminate
  821.   alias dp3_skitsystem_scenemap_update_wi36                         update
  822.   #--------------------------------------------------------------------------
  823.   # * Aliased Method: Start
  824.   #--------------------------------------------------------------------------
  825.   def start
  826.     @dp3_skit_system = DP3_Skit_System.new()
  827.     dp3_skitsystem_scenemap_start_wi36()      # Call Original Method
  828.   end
  829.   #--------------------------------------------------------------------------
  830.   # * Aliased Method: Dispose
  831.   #--------------------------------------------------------------------------
  832.   def terminate()
  833.     @dp3_skit_system.dispose()
  834.     dp3_skitsystem_scenemap_terminate_wi36()  # Call Original Method
  835.   end
  836.   #--------------------------------------------------------------------------
  837.   # * Aliased Method: Frame Update
  838.   #--------------------------------------------------------------------------
  839.   def update
  840.     @dp3_skit_system.update()
  841.     dp3_skitsystem_scenemap_update_wi36()     # Call Original Method
  842.   end
  843. end
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853. #==============================================================================
  854. # ** DP3_Skit_Sytem
  855. #------------------------------------------------------------------------------
  856. #  This class manages the Skit System Display on the Map.
  857. #==============================================================================
  858.  
  859. class DP3_Skit_System
  860.   include DiamondandPlatinum3::SkitSystem
  861.   #--------------------------------------------------------------------------
  862.   # * Skit Instance (Getter|Setter)
  863.   #--------------------------------------------------------------------------
  864.   def skit_instance;       return $game_temp.dp3_skit_instance;  end
  865.   def skit_instance=(obj); $game_temp.dp3_skit_instance = obj;   end
  866.   #--------------------------------------------------------------------------
  867.   # * New Method: Object Initialization
  868.   #--------------------------------------------------------------------------
  869.   def initialize()
  870.     initialise_instance_variables()
  871.     create_button_animation_sprites()
  872.     create_background_sprite()
  873.   end
  874.   #--------------------------------------------------------------------------
  875.   # * New Method: Dispose
  876.   #--------------------------------------------------------------------------
  877.   def dispose()
  878.     dispose_button_animation_sprites()
  879.     dispose_background_sprites()
  880.     self.skit_instance = nil
  881.   end
  882.   #--------------------------------------------------------------------------
  883.   # * New Method: Update
  884.   #--------------------------------------------------------------------------
  885.   def update()    
  886.    
  887.     # If No Skit Instance is available or Game Is Busy, Fadeout Images
  888.     if $game_message.busy?
  889.       fadeout_skit_images()
  890.       return
  891.     elsif self.skit_instance.nil?
  892.       fadeout_skit_images()
  893.     end
  894.    
  895.  
  896.     remove_unavailable_skits()    # Find any unavailable Skits and remove them
  897.    
  898.     if !self.skit_instance.nil?                 # If Game_Temp is holding a Skit For Us
  899.       if skit_instance.skit_available?()
  900.         update_skit_images()                        # Update Button Animation
  901.         fadein_skit_images()                        # Show Skit Images
  902.         play_skit() if Input.trigger?(Skit_Key)     # And if SkitButton is Triggered, Play Skit
  903.       else
  904.         self.skit_instance = nil
  905.       end
  906.     else
  907.       check_for_available_skit()    # Look for any Available Skit
  908.     end
  909.   end
  910.   #--------------------------------------------------------------------------
  911.   # * New Method: Initialise Skit System Instance Variables
  912.   #--------------------------------------------------------------------------
  913.   def initialise_instance_variables()
  914.     @skitanimatedbuttonspriteshash  = {}
  915.     @skitbackgroundspritearray      = []
  916.   end
  917.   #--------------------------------------------------------------------------
  918.   # * New Method: Create Skit Button Animation Sprites
  919.   #--------------------------------------------------------------------------
  920.   def create_button_animation_sprites()
  921.     path = Skit_Animation_Button_Directory + "/"
  922.     for i in 1..Number_of_Images
  923.       sprite          = Sprite.new()
  924.       sprite.bitmap   = Cache.picture(path + i.to_s)
  925.       sprite.x        = Skit_Animation_Button_Specs[0]
  926.       sprite.y        = Skit_Animation_Button_Specs[1]
  927.       sprite.z        = Skit_Animation_Button_Specs[2]
  928.       sprite.zoom_x   = Skit_Animation_Button_Specs[3].to_f / sprite.bitmap.width
  929.       sprite.zoom_y   = Skit_Animation_Button_Specs[4].to_f / sprite.bitmap.height
  930.       sprite.opacity  = 0
  931.       sprite.visible  = false
  932.       @skitanimatedbuttonspriteshash[i] = sprite
  933.     end
  934.     @skitanimatedbuttonspriteshash[:current_frame]     = 1
  935.     @skitanimatedbuttonspriteshash[:current_frametime] = 1000
  936.   end
  937.   #--------------------------------------------------------------------------
  938.   # * New Method: Create Skit Background Sprite
  939.   #--------------------------------------------------------------------------
  940.   def create_background_sprite()
  941.     sprite          = Sprite.new()
  942.     sprite.bitmap   = Cache.picture(Skit_Background_Image)
  943.     sprite.opacity  = 0
  944.     @skitbackgroundspritearray[0] = sprite      #[1] Becomes Another Sprite Defined Later
  945.   end
  946.   #--------------------------------------------------------------------------
  947.   # * New Method: Create Skit Notification
  948.   #--------------------------------------------------------------------------
  949.   def create_skit_notification()
  950.     anim_pos                    = *Skit_Animation_Button_Specs      
  951.     bitmap                      = @skitbackgroundspritearray[0].bitmap
  952.     text                        = self.skit_instance.name
  953.     text                        = DiamondandPlatinum3::SkitSystem::word_wrapping(bitmap, text, anim_pos[0] + anim_pos[3] + 5)
  954.     rect                        = DiamondandPlatinum3::SkitSystem::getbitmapdimensionsbasedontext(bitmap, text)
  955.    
  956.     # Setup Skit Background Sprite
  957.     sprite                      = @skitbackgroundspritearray[0]
  958.     sprite.x                    = anim_pos[0]
  959.     sprite.y                    = anim_pos[1] + ((anim_pos[4] * 0.5) - ((rect.height + 10) * 0.5))
  960.     sprite.y                    = sprite.y < 1 ? 1 : sprite.y
  961.     sprite.z                    = anim_pos[2] - 1
  962.     sprite.zoom_x               = (anim_pos[3] + (rect.width + 50)).to_f / sprite.bitmap.width
  963.     sprite.zoom_y               = (rect.height + 10).to_f / sprite.bitmap.height
  964.    
  965.     # Setup Skit Text
  966.     sprite                      = Sprite.new()
  967.     sprite.bitmap               = Bitmap.new(Graphics.width, rect.height)
  968.     sprite.bitmap.font.size     = Font_Size
  969.     sprite.bitmap.font.bold     = true
  970.     sprite.bitmap.font.shadow   = true
  971.     sprite.bitmap.font.color    = Color.new(*Font_Colour)
  972.     sprite.bitmap.font.name     = Font_Style  if Font_Style && Font_Style.upcase != "(DEFAULT)"
  973.     sprite.x                    = anim_pos[0] + anim_pos[3] + 5
  974.     sprite.y                    = @skitbackgroundspritearray[0].y + 5
  975.     sprite.y                    = sprite.y < 1 ? 1 : sprite.y
  976.     sprite.z                    = anim_pos[2] + 1
  977.     sprite.opacity              = 0
  978.    
  979.     # Dispose Old Notification if it Exists
  980.     if @skitbackgroundspritearray[1]
  981.       @skitbackgroundspritearray[1].bitmap.dispose()
  982.       @skitbackgroundspritearray[1].dispose()
  983.     end
  984.    
  985.     # Assign New Notification
  986.     @skitbackgroundspritearray[1] = sprite
  987.     DiamondandPlatinum3::SkitSystem::draw_skit_text(sprite.bitmap, text)
  988.   end
  989.   #--------------------------------------------------------------------------
  990.   # * New Method: Dispose Animation Sprites
  991.   #--------------------------------------------------------------------------
  992.   def dispose_button_animation_sprites()
  993.     for i in 1..Number_of_Images
  994.       @skitanimatedbuttonspriteshash[i].bitmap.dispose()
  995.       @skitanimatedbuttonspriteshash[i].dispose()
  996.     end
  997.   end
  998.   #--------------------------------------------------------------------------
  999.   # * New Method: Dispose Background Sprites
  1000.   #--------------------------------------------------------------------------
  1001.   def dispose_background_sprites()
  1002.     if @skitbackgroundspritearray[1]
  1003.       @skitbackgroundspritearray[1].bitmap.dispose()
  1004.       @skitbackgroundspritearray[1].dispose()
  1005.     end
  1006.     @skitbackgroundspritearray[0].bitmap.dispose()
  1007.     @skitbackgroundspritearray[0].dispose()
  1008.   end
  1009.   #--------------------------------------------------------------------------
  1010.   # * New Method: Update GameTemp Skit
  1011.   #--------------------------------------------------------------------------
  1012.   def update_gametemp_skit()
  1013.     # Get Random Available Skit
  1014.     skits = DiamondandPlatinum3::SkitSystem::get_available_skits()
  1015.     self.skit_instance = skits[rand(skits.size)] unless skits.empty?
  1016.   end
  1017.   #--------------------------------------------------------------------------
  1018.   # * New Method: Update GameTemp Skit
  1019.   #--------------------------------------------------------------------------
  1020.   def remove_unavailable_skits()
  1021.     skits = DiamondandPlatinum3::SkitSystem::get_unavailable_skits()
  1022.     skits.each do |skit|
  1023.       self.skit_instance = nil if !skit_instance.nil? && skit_instance.id == skit.id
  1024.       $game_system.dp3_skit_system_event_unavailable_hash[skit.id] = skit
  1025.       $game_system.dp3_skit_system_event_unseen_skit_hash.delete(skit.id)
  1026.     end
  1027.   end
  1028.   #--------------------------------------------------------------------------
  1029.   # * New Method: Update Skit Images
  1030.   #--------------------------------------------------------------------------
  1031.   def update_skit_images()
  1032.     @skitanimatedbuttonspriteshash[:current_frametime] += 1
  1033.     if @skitanimatedbuttonspriteshash[:current_frametime] >= Animation_Wait_Timer
  1034.       @skitanimatedbuttonspriteshash[:current_frametime] = 0
  1035.      
  1036.       frame = @skitanimatedbuttonspriteshash[:current_frame]
  1037.       @skitanimatedbuttonspriteshash[frame].visible = false
  1038.      
  1039.       @skitanimatedbuttonspriteshash[:current_frame] += 1
  1040.       if @skitanimatedbuttonspriteshash[:current_frame] > Number_of_Images
  1041.         @skitanimatedbuttonspriteshash[:current_frame] = 1
  1042.       end
  1043.      
  1044.       frame = @skitanimatedbuttonspriteshash[:current_frame]
  1045.       @skitanimatedbuttonspriteshash[frame].visible = true
  1046.     end
  1047.   end
  1048.   #--------------------------------------------------------------------------
  1049.   # * New Method: Show Skit Images
  1050.   #--------------------------------------------------------------------------
  1051.   def fadein_skit_images()
  1052.     return if @skitbackgroundspritearray[0].opacity > Skit_Notifications_Max_Opacity
  1053.    
  1054.     for i in 1..Number_of_Images
  1055.       @skitanimatedbuttonspriteshash[i].opacity += Skit_Notifications_Fadein_Speed
  1056.     end
  1057.     @skitbackgroundspritearray[0].opacity += Skit_Notifications_Fadein_Speed
  1058.     @skitbackgroundspritearray[1].opacity += Skit_Notifications_Fadein_Speed if @skitbackgroundspritearray[1]
  1059.   end
  1060.   #--------------------------------------------------------------------------
  1061.   # * New Method: Fadeout Skit Images
  1062.   #--------------------------------------------------------------------------
  1063.   def fadeout_skit_images()
  1064.     return if @skitbackgroundspritearray[0].opacity == 0
  1065.    
  1066.     for i in 1..Number_of_Images
  1067.       @skitanimatedbuttonspriteshash[i].opacity -= Skit_Notifications_Fadeout_Speed
  1068.     end
  1069.     @skitbackgroundspritearray[0].opacity -= Skit_Notifications_Fadeout_Speed
  1070.     @skitbackgroundspritearray[1].opacity -= Skit_Notifications_Fadeout_Speed if @skitbackgroundspritearray[1]
  1071.   end
  1072.   #--------------------------------------------------------------------------
  1073.   # * New Method: Check For Available Skit
  1074.   #--------------------------------------------------------------------------
  1075.   def check_for_available_skit()    
  1076.     # Find Available Skits if there are none currently available
  1077.     if self.skit_instance.nil?
  1078.       update_gametemp_skit()
  1079.      
  1080.       # If Game_Temp now has a Skit for us, draw it's name and rearrange the
  1081.       # Skit Background Sprite to accomodate for its size/length
  1082.       if !self.skit_instance.nil?
  1083.         create_skit_notification()
  1084.       end
  1085.     end
  1086.   end
  1087.   #--------------------------------------------------------------------------
  1088.   # * New Method: Play Skit
  1089.   #--------------------------------------------------------------------------
  1090.   def play_skit()
  1091.     # Copy Skit Event into Game_Event
  1092.     $game_map.dp3_skitsystem_setupnewskit()
  1093.    
  1094.     # Add Skit to the 'Seen Skits' Hash & Remove from 'Unseen Skits' Hash
  1095.     $game_system.dp3_skit_system_event_seen_skit_hash[self.skit_instance.id] = skit_instance
  1096.     $game_system.dp3_skit_system_event_unseen_skit_hash.delete(self.skit_instance.id)
  1097.     self.skit_instance = nil
  1098.   end
  1099. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement