khanhdu

CSCA Dungeon Tools

May 31st, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 35.51 KB | None | 0 0
  1. =begin
  2. CSCA Dungeon Tools
  3. version: 1.4b
  4. Created by: Casper Gaming (http://www.caspergaming.com/)
  5.  
  6. Compatibility:
  7. Made for RPGVXAce
  8. IMPORTANT: ALL CSCA Scripts should be compatible with each other unless
  9. otherwise noted.
  10. REQUIRES CSCA Core Script
  11. ================================================================================
  12. UPDATE HISTORY:
  13.  
  14. Version 1.1
  15. -Fixed boomerang misspelling
  16. -Aliased a few more things
  17. -Bomb is now seperate from other tools, as in you can use other tools while a
  18. bomb is planted. However, you're still limited to 1 arrow/hookshot/boomerang
  19. at one time.
  20. -Tool events are now designated by comments rather than entering a predefined
  21. event id in the module.
  22.  
  23. Version 1.2
  24. -Fixed bug that occured if a map didn't have dungeon tool events set up.
  25. -Fixed bug that caused a crash if any event on the map had no event pages with
  26. met conditions.
  27.  
  28. Version 1.3
  29. -Added ability to hold a button down to turn in the direction pressed instead
  30. of moving. This is able to be done at all times.
  31. -Fixed reset bug
  32. -Added ability to require the player has items to use some tools. For example,
  33. the player might need an arrow in their inventory to use the arrow tool.
  34. -Increased compatibility by aliasing more stuff.
  35.  
  36. Version 1.3b
  37. - Changed some stuff for compatibility with CSCA Menu Organizer.
  38.  
  39. Version 1.4
  40. - Damage floor now doesn't damage the player when hookshotting over it.
  41. - Added a new region, similar to region 1 but only functions if a switch is ON.
  42.  
  43. Version 1.4b
  44. - Region ID 1 will no longer allow tools to go through events. Use the other
  45. regions for this effect. (Toggleable).
  46. ================================================================================
  47.  
  48. FFEATURES:
  49. This script allows you to enable/disable use of pre-made "dungeon tools" easily
  50. with switches. The pre-made tools include: Reset, Arrow, Bomb, Hookshot, Boomarang.
  51. Each tool behaves slightly differently, and it is recommended to download
  52. the demo to get a better understanding of how each tool works.
  53.  
  54. RESET: Resets the map to how it was when you entered. This option will NOT turn
  55. switches/variables back to their original value, but it will turn self
  56. switches to false unless RESET_EXEMPT is put in the event page of an event. It
  57. also transfers the player to where they were originally after the previous
  58. transfer.
  59.  
  60. ARROW: Shoots an arrow in the direction you're facing. When it hits an event, if
  61. the event has ARROW_ACTIVATE in a comment event command, it will activate the
  62. next self switch. If no self switch is on, it will turn A on. If A is on, B will
  63. be turned on, etc.
  64.  
  65. BOMB: Sets a bomb down where the player is standing. When the player steps a
  66. specified amount of times, the bomb blows up, activating the next self switche of
  67. events underneath it, as well as directly above/below, and to the right/left.
  68. The self switches are only turned on if BOMB_ACTIVATE is in their event page in
  69. a comment command.
  70.  
  71. HOOKSHOT: Shoots a hookshot in the direction of the player. If it connects with
  72. an event that has HOOKSHOT_ENABLED in a comment event command, it will move the
  73. player to that event, even if there are impassable tiles in between. If no
  74. event is hit, or the event does not have the comment command, the hookshot
  75. returns to the player.
  76.  
  77. BOOMARANG: Shoots a boomarang, which can collect one item at a time(requires
  78. some eventing, shown in demo). If the boomarang flies over an event with the
  79. comment command BOOMARANG_ACTIVATE, it will turn on that event's next self switch.
  80.  
  81. SETUP
  82. This script requires setup further down. It is important that you do not allow
  83. the player to reset the map before they have transferred once(by using the Transfer
  84. event command), as this script assumes a transfer has already happened.
  85.  
  86. SETTING UP YOUR EVENTS:
  87. Each map where you plan to use these tools MUST have an event with the comment
  88. BOMB_TOOL inside, as well as an event with the comment DUNGEON_TOOL inside. The
  89. BOMB_TOOL event will act as the bomb, and the DUNGEON_TOOL will act as all other
  90. tools. Case Matters. Make sure you set the through/priority/stepping animation
  91. settings in the event page how you want them, as this script does not
  92. automatically do that. If you get a undefined method error, chances are you have
  93. set your events up incorrectly.
  94.  
  95. On maps that do not have these events(any map that you do not want to use these
  96. tools on), it is very important to turn the ON_OFF switch OFF. Remember to turn
  97. it back ON for maps where these tools will be used, though!
  98.  
  99. IMPORTANT! If you do not understand how to do some things, please download the
  100. demo to see each item properly used.
  101.  
  102. CREDIT:
  103. Free to use in noncommercial games if credit is given to:
  104. Casper Gaming (http://www.caspergaming.com/)
  105.  
  106. To use in a commercial game, please purchase a license here:
  107. http://www.caspergaming.com/licenses.html
  108.  
  109. TERMS:
  110. http://www.caspergaming.com/terms_of_use.html
  111. =end
  112. module CSCA_DUNGEON_TOOLS # Don't touch this.
  113.  
  114.   ON_OFF = 1 # Switch ID. Turns this whole script on/off.
  115.  
  116.   # Trigger name        Key on keyboard
  117.   # :A             =    Shift
  118.   # :B             =    X
  119.   # :C             =    Z
  120.   # :X             =    A
  121.   # :Y             =    S
  122.   # :Z             =    D
  123.   # :L             =    Q
  124.   # :R             =    W
  125.   TRIGGER = :R # Which button do you want to bring up the tool select menu?
  126.   USETOOL = :X # Which button do you want to use a tool?
  127.  
  128.   STILL_TRIGGER = :L # Which button do you want the player to hold to turn
  129.                      # without moving?
  130.   ENABLE_STILL = true # Allow the player to hold a button to turn without moving?
  131.  
  132.   # Dungeon Tools. If you don't want to use one, simply leave it's switch OFF.
  133.   ARROW = 2 # Switch ID. Turn ON to allow selection of the arrow.
  134.   BOMB = 3 # Switch ID. Turn ON to allow selection of the bomb.
  135.   HOOKSHOT = 4 # Switch ID. Turn ON to allow selection of the hookshot.
  136.   BOOMERANG = 5 # Switch ID. Turn ON to allow selection of the boomarang.
  137.   RESET = 6 # Switch ID. Turn ON to allow selection of the reset option.
  138.  
  139.   # Names. This is all text shown in game in the selection window.
  140.   ARROW_NAME = "Cung Tên" # Name of the Arrow tool.
  141.   BOMB_NAME = "Lựu Đạn" # Name of the Bomb tool.
  142.   HOOKSHOT_NAME = "Bắn Móc" # Name of the Hookshot tool.
  143.   BOOMERANG_NAME = "Boomerang" # Name of the Boomarang tool.
  144.   RESET_NAME = "Làm Mới" # Name of the Reset tool.
  145.   HEADER = "Công Cụ" # Name of the selection window.
  146.  
  147.   # Icons. These icons will be shown next to the similarly named tools.
  148.   ARROW_ICON = 529 # Icon displayed next to the Arrow text.
  149.   BOMB_ICON = 528 # Icon displayed next to the Bomb text.
  150.   HOOKSHOT_ICON = 530 # Icon displayed next to the Hookshot text.
  151.   BOOMERANG_ICON = 154 # Icon displayed next to the Boomarang text.
  152.   RESET_ICON = 280 # Icon displayed next to the Reset text.
  153.  
  154.   CSCADGT = 1 # Variable ID. By setting this in-game you can force use of some
  155.               # tools. 1 sets to arrow, 2 to bomb, 3 to hookshot, 4 to boomarang.
  156.               # If set to 5, the map will automatically reset and set this to 0,
  157.               # so setting this variable's value to 5 requires some caution.
  158.                
  159.   REGION_ID1 = 1 # Region ID. Arrow/hookshot/boomarang can always move when in
  160.                  # this region, no matter if the map tile is passable or not.
  161.                  # However, the arrow/hookshot will not be able to activate
  162.                  # events while in this region ID either.
  163.   REGION_ID2 = 2 # Region ID. Arrow/hookshot/boomarang can always move when in
  164.                  # this region IF it is facing down.
  165.   REGION_ID3 = 3 # Region ID. Arrow/hookshot/boomarang can always move when in
  166.                  # this region IF it is facing left.
  167.   REGION_ID4 = 4 # Region ID. Arrow/hookshot/boomarang can always move when in
  168.                  # this region IF it is facing right.
  169.   REGION_ID5 = 5 # Region ID. Arrow/hookshot/boomarang can always move when in
  170.                  # this region IF it is facing up.
  171.   REGION_ID6 = 6 # Region ID. Arrow/hookshot/boomarang can always move when in
  172.                  # this region IF it is facing up OR left
  173.   REGION_ID7 = 7 # Region ID. Arrow/hookshot/boomarang can always move when in
  174.                  # this region IF it is facing up OR right
  175.   REGION_ID8 = 8 # Region ID. Arrow/hookshot/boomarang can always move when in
  176.                  # this region IF it is facing down OR left
  177.   REGION_ID9 = 9 # Region ID. Arrow/hookshot/boomarang can always move when in
  178.                  # this region IF it is facing down OR right
  179.   REGION_ID10 = 10 # Region ID. Arrow/hookshot/boomarang can always move when in
  180.                    # this region IF it is facing up OR down.
  181.   REGION_ID11 = 11 # Region ID. Arrow/hookshot/boomarang can always move when in
  182.                    # this region IF it is facing left OR right
  183.   REGION_ID12 = 12 # Region ID. Arrow/hookshot/boomarang can always move when in
  184.                    # this region IF it is facing left OR right OR up
  185.   REGION_ID13 = 13 # Region ID. Arrow/hookshot/boomarang can always move when in
  186.                    # this region IF it is facing left OR right OR down
  187.   REGION_ID14 = 14 # Region ID. Arrow/hookshot/boomarang can always move when in
  188.                    # this region IF it is facing up OR down OR left
  189.   REGION_ID15 = 15 # Region ID. Arrow/hookshot/boomarang can always move when in
  190.                    # this region IF it is facing up OR down OR right
  191.                    
  192.                    
  193.   REGION_ID16 = 16 # Region ID. Arrow/hookshot/boomarang can always move when in
  194.                    # this region IF REGION_SWITCH is ON. Useful for multi-level
  195.                    # areas.
  196.                    
  197.   REGION_SWITCH = 7 # Turns region ID 16 on.
  198.  
  199.   R1_EVENTS = false # Allow region ID 1 to move through events?
  200.                
  201.   FILENAME = "CSCA_DT" # Filename of the character sheet containing your bomb,
  202.                        # arrow, hookshot, and boomarang graphics. This should
  203.                        # be placed in Graphics/Characters.
  204.                        
  205.   # File indexes. Character graphic files are laid out like so:
  206.   # [0,1,2,3]
  207.   # [4,5,6,7]
  208.   # Where each number corresponds to the spot on the character sheet.
  209.   ARROW_INDEX = 1 # Index of the arrow graphic in the previously specified file.
  210.   BOMB_INDEX = 0 # Index of the bomb graphic in the previously specified file.
  211.   HOOKSHOT_INDEX = 3 # Index of the hookshot graphic in the previously specified
  212.                      # file.
  213.   BOOMERANG_INDEX = 2 # Index of the boomarang graphic in the previously
  214.                       # specified file.
  215.                      
  216.   ARROW_DIST = 8 # Amount of spaces you want the arrow to travel.
  217.   BOOMERANG_DIST = 7 # Amount of spaces the boomarang will travel before returning
  218.                      # to you.
  219.   HOOKSHOT_DIST = 6 # Amount of spaces the hookshot will travel before returning
  220.                     # to you.
  221.   STEP_AMOUNT = 6 # Amount of steps required for bomb to explode.
  222.  
  223.   BOMB_ANIMATION_ID = 111 # Bomb explosion animation id.
  224.   BOMB_ANIMATION_TIME = 36 # Bomb explosion animation length in frames. To get
  225.                            # this, multiply the highest number in the animation's
  226.                            # frame list by 4.
  227.  
  228.   # All sound files are located in your Audio/SE/ folder.
  229.   ARROW_SHOOT_SOUND = "Bow1" # Plays when arrow shoots, if enabled.
  230.   ARROW_HIT_SOUND1 = "Damage1" # Plays when arrow hits event, if enabled.
  231.   ARROW_HIT_SOUND2 = "Shot2" # Plays when arrow hits non-event, if enabled.
  232.   BOMB_PLACEMENT_SOUND = "Cursor1" # Sound file to play when bomb is planted.
  233.   HOOKSHOT_USE_SOUND = "Saint3" # Sound file to play when hookshot is used.
  234.   BOOMERANG_USE_SOUND = "Darkness2" # Sound file to play when boomarang thrown.
  235.  
  236.   # Choose whether or not each sound file plays.
  237.   ARROW_SOUND1 = true # Play ARROW_SHOOT_SOUND ?
  238.   ARROW_SOUND2 = true # Play sound when arrow collides with event ?
  239.   ARROW_SOUND3 = true # Play sound when arrow collides with non-event ?
  240.   BOMB_SOUND1 = true # Play BOMB_PLACEMENT_SOUND ?
  241.   HOOKSHOT_SOUND1 = true # Play hookshot use sound ?
  242.   BOOMERANG_SOUND1 = true # Play boomarang throw sound ?
  243.  
  244.  
  245.   # Setting this to true will require the player to have the items specified
  246.   # below in thier inventory or else the tool will not be used. This will also
  247.   # subtract one of that item upon use of that tool.
  248.   REQUIRE_ITEMS_B = false # Require an item to use bombs?
  249.   REQUIRE_ITEMS_A = false # Require an item to use arrows?
  250.  
  251.   # The following item ID's are the items that determine whether a tool is usable.
  252.   # For example, if the palyer know how to use bombs, but has no bombs in their
  253.   # inventory, the bomb tool will be unusable. Only works if REQUIRE_ITEMS is true.
  254.   BOMB_ITEM_ID = 1 # Item ID. This item will be used when the Bomb Tool is used.
  255.   ARROW_ITEM_ID = 2 # Item ID. This item will be used when the Arrow Tool is used.
  256.  
  257.   # Text displayed when a tool is used, but the player doesn't have the required
  258.   # item specified above in their inventory. This feature only happens if
  259.   # REQUIRE_ITEMS is set to true.
  260.   NO_ITEM_TEXT = "Bạn Không Có %ss!"
  261.  
  262. end # END SETUP. Don't touch this or anything below.
  263. $imported = {} if $imported.nil?
  264. $imported["CSCA-DungeonTools"] = true
  265. msgbox('Missing Script: CSCA Core Script! CSCA Dungeon Tools requires this
  266. script to work properly.') if !$imported["CSCA-Core"]
  267. class Game_CharacterBase
  268.   include CSCA_DUNGEON_TOOLS
  269.  
  270.   def csca_change_graphic(character, type)
  271.     case type
  272.     when 1
  273.       character.set_graphic(FILENAME, ARROW_INDEX)
  274.     when 2
  275.       character.set_graphic(FILENAME, BOMB_INDEX)
  276.     when 3
  277.       character.set_graphic(FILENAME, HOOKSHOT_INDEX)
  278.     when 4
  279.       character.set_graphic(FILENAME, BOOMERANG_INDEX)
  280.     else
  281.       character.set_graphic("", 0)
  282.     end
  283.   end
  284.  
  285.   def csca_change_move_speed(speed)
  286.     @move_speed = speed
  287.   end
  288.  
  289.   def csca_change_through(t_f)
  290.     @through = t_f
  291.   end
  292.  
  293. end
  294. class Scene_Map < Scene_Base
  295.   include CSCA_DUNGEON_TOOLS
  296.  
  297.   alias csca_update update_scene
  298.   def update_scene
  299.     csca_update
  300.     csca_update_dt unless $game_map.interpreter.running?
  301.     csca_call_dts unless scene_changing? || $game_map.interpreter.running?
  302.   end
  303.  
  304.   def csca_call_dts
  305.     if Input.press?(TRIGGER) && $game_switches[ON_OFF] && csca_check_tools
  306.       Sound.play_ok
  307.       SceneManager.call(CSCA_Scene_DungeonToolSelect)
  308.     end
  309.   end
  310.  
  311.   def csca_check_tools
  312.     return $game_switches[ARROW] || $game_switches[BOMB] ||
  313.     $game_switches[HOOKSHOT] || $game_switches[BOOMERANG] ||
  314.     $game_switches[RESET]
  315.   end
  316.  
  317.   def csca_update_dt
  318.     if Input.press?(USETOOL) && $game_switches[ON_OFF]
  319.       use_arrow if $game_variables[CSCADGT] == 1
  320.       use_bomb if $game_variables[CSCADGT] == 2
  321.       use_hookshot if $game_variables[CSCADGT] == 3
  322.       use_boomarang if $game_variables[CSCADGT] == 4
  323.     end
  324.   end
  325.  
  326.   def use_arrow
  327.     $game_map.use_arrow unless $game_map.using_tool?
  328.   end
  329.  
  330.   def use_bomb
  331.     $game_map.use_bomb unless $game_map.using_bomb? || $game_map.anime_playing?
  332.   end
  333.  
  334.   def use_hookshot
  335.     $game_map.use_hookshot unless $game_map.using_tool?
  336.   end
  337.  
  338.   def use_boomarang
  339.     $game_map.use_boomarang unless $game_map.using_tool?
  340.   end
  341.  
  342. end
  343. class Game_Map
  344.   include CSCA_DUNGEON_TOOLS
  345.  
  346.   alias csca_map_update update
  347.   def update(main)
  348.     csca_map_update(main)
  349.     csca_reset if $game_variables[CSCADGT] == 5
  350.     csca_update if using_tool? || using_bomb?
  351.     csca_arrow_finish if done_moving? && @tooltype == :arrow
  352.     csca_boomarang_finish if done_moving? && @tooltype == :boomarang
  353.     csca_hookshot_finish if done_moving? && @tooltype == :hookshot
  354.   end
  355.  
  356.   def csca_update
  357.     csca_check_through if @tooltype == :arrow || @tooltype == :boomarang || @tooltype == :hookshot
  358.     csca_check_steps if using_bomb?
  359.     csca_check_pickup if @tooltype == :boomarang && !pickup?
  360.   end
  361.  
  362.   def csca_check_through
  363.     csca_get_event
  364.     d = @csca_event.direction
  365.     x = @csca_event.x
  366.     y = @csca_event.y
  367.     case d
  368.     when 2; y += 1
  369.     when 4; x -= 1
  370.     when 6; x += 1
  371.     when 8; y -= 1
  372.     end
  373.     block_event = events_xy_nt(x, y)
  374.     if ((region_id(@csca_event.x, @csca_event.y) == REGION_ID1) && (block_event == [] || R1_EVENTS))  ||
  375.     (d == 2 && region_id(@csca_event.x, @csca_event.y) == REGION_ID2) ||
  376.     (d == 4 && region_id(@csca_event.x, @csca_event.y) == REGION_ID3) ||
  377.     (d == 6 && region_id(@csca_event.x, @csca_event.y) == REGION_ID4) ||
  378.     (d == 8 && region_id(@csca_event.x, @csca_event.y) == REGION_ID5) ||
  379.     ((d == 8 || d == 4) && region_id(@csca_event.x, @csca_event.y) == REGION_ID6) ||
  380.     ((d == 8 || d == 6) && region_id(@csca_event.x, @csca_event.y) == REGION_ID7) ||
  381.     ((d == 2 || d == 4) && region_id(@csca_event.x, @csca_event.y) == REGION_ID8) ||
  382.     ((d == 2 || d == 6) && region_id(@csca_event.x, @csca_event.y) == REGION_ID9) ||
  383.     ((d == 2 || d == 8) && region_id(@csca_event.x, @csca_event.y) == REGION_ID10) ||
  384.     ((d == 4 || d == 6) && region_id(@csca_event.x, @csca_event.y) == REGION_ID11) ||
  385.     ((d == 4 || d == 6 || d == 8) && region_id(@csca_event.x, @csca_event.y) == REGION_ID12) ||
  386.     ((d == 4 || d == 6 || d == 2) && region_id(@csca_event.x, @csca_event.y) == REGION_ID13) ||
  387.     ((d == 2 || d == 8 || d == 4) && region_id(@csca_event.x, @csca_event.y) == REGION_ID14) ||
  388.     ((d == 2 || d == 8 || d == 6) && region_id(@csca_event.x, @csca_event.y) == REGION_ID15) ||
  389.     ($game_switches[REGION_SWITCH] && region_id(@csca_event.x, @csca_event.y) == REGION_ID16) ||
  390.     @hookshot_reverse_dir == true
  391.       @csca_event.csca_change_through(true)
  392.     else
  393.       @csca_event.csca_change_through(false)
  394.     end
  395.   end
  396.  
  397.   def csca_check_steps
  398.     @bombsteps2 = $game_party.steps
  399.     @bombsteps1 = @bombsteps
  400.     @bombsteps2 -= @bombsteps1
  401.     if @bombsteps2 >= STEP_AMOUNT
  402.       bomb_explode(@csca_bomb_event)
  403.     end
  404.   end
  405.  
  406.   def csca_check_pickup
  407.     x = @csca_event.x
  408.     y = @csca_event.y
  409.     d = @csca_event.direction
  410.     case d
  411.     when 2; y -= 1
  412.     when 4; x += 1
  413.     when 6; x -= 1
  414.     when 8; y += 1
  415.     end
  416.     @csca_event_id = event_id_xy(x, y)
  417.     if @csca_event_id != 0
  418.       csca_get_collision_event(@csca_event_id)
  419.       csca_check_comment(@csca_collision_event, 2)
  420.     end
  421.   end
  422.  
  423.   def bomb_explode(event)
  424.     @waitforanimation = true
  425.     @bombplanted = false
  426.     event.animation_id = BOMB_ANIMATION_ID
  427.     do_bomb_effect(event)
  428.     csca_clear_ok?(event)
  429.   end
  430.  
  431.   def do_bomb_effect(bomb)
  432.     x = bomb.x
  433.     y = bomb.y
  434.     @csca_bomb_event_id5 = event_id_xy(x, y)
  435.     x += 1
  436.     @csca_bomb_event_id1 = event_id_xy(x, y)
  437.     x -= 2
  438.     @csca_bomb_event_id2 = event_id_xy(x, y)
  439.     x = bomb.x
  440.     y += 1
  441.     @csca_bomb_event_id3 = event_id_xy(x, y)
  442.     y -= 2
  443.     @csca_bomb_event_id4 = event_id_xy(x, y)
  444.     if @csca_bomb_event_id1 != 0
  445.       get_bomb_explode_event(@csca_bomb_event_id1)
  446.       csca_check_comment(@csca_bomb_explode_event, 5, 1)
  447.     end
  448.     if @csca_bomb_event_id2 != 0
  449.       get_bomb_explode_event(@csca_bomb_event_id2)
  450.       csca_check_comment(@csca_bomb_explode_event, 5, 2)
  451.     end
  452.     if @csca_bomb_event_id3 != 0
  453.       get_bomb_explode_event(@csca_bomb_event_id3)
  454.       csca_check_comment(@csca_bomb_explode_event, 5, 3)
  455.     end
  456.     if @csca_bomb_event_id4 != 0
  457.       get_bomb_explode_event(@csca_bomb_event_id4)
  458.       csca_check_comment(@csca_bomb_explode_event, 5, 4)
  459.     end
  460.     if @csca_bomb_event_id5 != 0
  461.       get_bomb_explode_event(@csca_bomb_event_id5)
  462.       csca_check_comment(@csca_bomb_explode_event, 5, 5)
  463.     end
  464.   end
  465.  
  466.   def get_arrow_success_coords(event)
  467.     x = event.x
  468.     y = event.y
  469.     d = event.direction
  470.     case d
  471.     when 2; y += ARROW_DIST
  472.     when 4; x -= ARROW_DIST
  473.     when 6; x += ARROW_DIST
  474.     when 8; y -= ARROW_DIST
  475.     end
  476.     @csca_success_x = x
  477.     @csca_success_y = y
  478.   end
  479.  
  480.   def csca_finish_move_route
  481.     @csca_dt_done_moving = true
  482.   end
  483.  
  484.   def csca_arrow_finish
  485.     csca_get_event
  486.     if @csca_event.x == @csca_success_x && @csca_event.y == @csca_success_y
  487.       csca_clear_event
  488.     else
  489.       csca_check_collision(@csca_event)
  490.     end
  491.   end
  492.  
  493.   def csca_boomarang_finish
  494.     $game_party.leader.hp -= 1
  495.     csca_clear_event
  496.   end
  497.  
  498.   def csca_hookshot_finish
  499.     csca_clear_event
  500.   end
  501.  
  502.   def csca_hookshot_check
  503.     csca_check_collision(@csca_event)
  504.   end
  505.  
  506.   def use_arrow
  507.     if $game_party.has_item?($data_items[ARROW_ITEM_ID]) || !REQUIRE_ITEMS_A
  508.       @tooltype = :arrow
  509.       csca_get_event
  510.       csca_event_setup(@csca_event)
  511.       @csca_event.csca_change_graphic(@csca_event, 1)
  512.       @csca_event.csca_change_move_speed(6)
  513.       Audio.se_play("Audio/SE/" + ARROW_SHOOT_SOUND, 80, 100) if ARROW_SOUND1
  514.       get_arrow_success_coords(@csca_event)
  515.       arrow_move_route(@csca_event, ARROW_DIST)
  516.       $game_party.lose_item($data_items[ARROW_ITEM_ID], 1) if REQUIRE_ITEMS_A
  517.     else
  518.       $game_message.add(sprintf(NO_ITEM_TEXT, ARROW_NAME))
  519.     end
  520.   end
  521.  
  522.   def use_bomb
  523.     if $game_party.has_item?($data_items[BOMB_ITEM_ID]) || !REQUIRE_ITEMS_B
  524.       @tooltype = :bomb
  525.       csca_get_bomb_event
  526.       @csca_bomb_event.moveto($game_player.x, $game_player.y)
  527.       @csca_bomb_event.csca_change_graphic(@csca_bomb_event, 2)
  528.       Audio.se_play("Audio/SE/" + BOMB_PLACEMENT_SOUND, 80, 100) if BOMB_SOUND1
  529.       @bombplanted = true
  530.       @bombsteps = $game_party.steps
  531.       $game_party.lose_item($data_items[BOMB_ITEM_ID], 1) if REQUIRE_ITEMS_B
  532.     else
  533.       $game_message.add(sprintf(NO_ITEM_TEXT, BOMB_NAME))
  534.     end
  535.   end
  536.  
  537.   def use_hookshot
  538.     @tooltype = :hookshot
  539.     csca_get_event
  540.     csca_event_setup(@csca_event)
  541.     @csca_event.csca_change_graphic(@csca_event, 3)
  542.     @csca_event.csca_change_move_speed(5)
  543.     Audio.se_play("Audio/SE/" + HOOKSHOT_USE_SOUND, 80, 100) if HOOKSHOT_SOUND1
  544.     hookshot_move_route(@csca_event, HOOKSHOT_DIST)
  545.   end
  546.  
  547.   def use_boomarang
  548.     @tooltype = :boomarang
  549.     csca_get_event
  550.     csca_event_setup(@csca_event)
  551.     @csca_event.csca_change_graphic(@csca_event, 4)
  552.     @csca_event.csca_change_move_speed(5)
  553.     Audio.se_play("Audio/SE/" + BOOMERANG_USE_SOUND, 80, 100) if BOOMERANG_SOUND1
  554.     boomarang_move_route(@csca_event, BOOMERANG_DIST)
  555.   end
  556.  
  557.   def csca_get_event
  558.     events.each do |i, event|
  559.       if event.list != nil
  560.         for i in 0...event.list.size
  561.           if event.list[i].code == 108 && event.list[i].parameters == ["DUNGEON_TOOL"]
  562.             @csca_event = event
  563.           end
  564.         end
  565.       end
  566.     end
  567.   end
  568.  
  569.   def csca_get_bomb_event
  570.     events.each do |i, event|
  571.       if event.list != nil
  572.         for i in 0...event.list.size
  573.           if event.list[i].code == 108 && event.list[i].parameters == ["BOMB_TOOL"]
  574.             @csca_bomb_event = event
  575.           end
  576.         end
  577.       end
  578.     end
  579.   end
  580.  
  581.   def csca_event_setup(event)
  582.     @usingtool = true
  583.     event.moveto($game_player.x, $game_player.y)
  584.     event.set_direction($game_player.direction)
  585.     event.csca_change_through(false)
  586.   end
  587.  
  588.   def using_tool?
  589.     @usingtool
  590.   end
  591.  
  592.   def using_bomb?
  593.     @bombplanted
  594.   end
  595.  
  596.   def anime_playing?
  597.     @waitforanimation
  598.   end
  599.  
  600.   def tooltype?
  601.     @tooltype
  602.   end
  603.  
  604.   def done_moving?
  605.     @csca_dt_done_moving
  606.   end
  607.  
  608.   def pickup?
  609.     @pickedup
  610.   end
  611.  
  612.   def moving_back?
  613.     @movingback
  614.   end
  615.  
  616.   def csca_clear_event
  617.     @usingtool = @csca_dt_done_moving = @pickedup = @movingback = @hookshot_reverse_dir = false
  618.     csca_get_event
  619.     if @csca_event != nil
  620.       @csca_event.moveto(0,0)
  621.       @csca_event.csca_change_graphic(@csca_event, 5)
  622.     end
  623.   end
  624.  
  625.   def csca_clear_bomb_event
  626.     @bombplanted = @waitforanimation = false
  627.     csca_get_bomb_event
  628.     if @csca_bomb_event != nil
  629.       @csca_bomb_event.moveto(1,0)
  630.       @csca_bomb_event.csca_change_graphic(@csca_bomb_event, 5)
  631.     end
  632.   end
  633.  
  634.   def arrow_move_route(event, dist)
  635.     mr = RPG::MoveRoute.new
  636.     mr.repeat = false
  637.     mr.wait = true
  638.     mr.skippable = true
  639.     mc = RPG::MoveCommand.new
  640.     mc.code = 12
  641.     mc.parameters = []
  642.     mc2 = RPG::MoveCommand.new
  643.     mc2.code = 45
  644.     mc2.parameters = ["$game_map.csca_finish_move_route"]
  645.     for i in 0...dist
  646.       mr.list[i] = mc
  647.     end
  648.     mr.list[dist] = mc2
  649.     event.force_move_route(mr)
  650.   end
  651.  
  652.   def boomarang_move_route(event, dist)
  653.     mr = RPG::MoveRoute.new
  654.     mr.repeat = false
  655.     mr.wait = true
  656.     mr.skippable = true
  657.     mc = RPG::MoveCommand.new
  658.     mc.code = 12
  659.     mc.parameters = []
  660.     mc2 = RPG::MoveCommand.new
  661.     mc2.code = 45
  662.     if moving_back?
  663.       mc2.parameters = ["$game_map.csca_finish_move_route"]
  664.     else
  665.       mc2.parameters = ["$game_map.csca_move_back"]
  666.     end
  667.     mc3 = RPG::MoveCommand.new
  668.     mc3.code = 22
  669.     mc3.parameters = []
  670.     for i in 0...dist
  671.       mr.list[i] = mc
  672.     end
  673.     mr.list[dist] = mc3
  674.     mr.list[dist + 1] = mc2
  675.     event.force_move_route(mr)
  676.   end
  677.  
  678.   def hookshot_move_route(event, dist)
  679.     mr = RPG::MoveRoute.new
  680.     mr.repeat = false
  681.     mr.wait = true
  682.     mr.skippable = true
  683.     mc = RPG::MoveCommand.new
  684.     mc.code = 12
  685.     mc.parameters = []
  686.     mc2 = RPG::MoveCommand.new
  687.     mc2.code = 45
  688.     mc2.parameters = ["$game_map.csca_hookshot_check"]
  689.     for i in 0...dist
  690.       mr.list[i] = mc
  691.     end
  692.     mr.list[dist] = mc2
  693.     event.force_move_route(mr)
  694.   end
  695.  
  696.   def hookshot_move_back(event)
  697.     @hookshot_reverse_dir = true
  698.     x1 = $game_player.x
  699.     y1 = $game_player.y
  700.     x2 = event.x
  701.     y2 = event.y
  702.     event.direction == 2 ? distance = (y1 - y2).abs :
  703.     event.direction == 8 ? distance = (y1 - y2).abs : distance = (x1 - x2).abs
  704.     if x1 == x2 && y1 == y2
  705.       csca_clear_event
  706.       return
  707.     end
  708.     mr = RPG::MoveRoute.new
  709.     mr.repeat = false
  710.     mr.wait = true
  711.     mr.skippable = true
  712.     mc = RPG::MoveCommand.new
  713.     mc.code = 13
  714.     mc.parameters = []
  715.     mc2 = RPG::MoveCommand.new
  716.     mc2.code = 45
  717.     mc2.parameters = ["$game_map.csca_finish_move_route"]
  718.     for i in 0...distance
  719.       mr.list[i] = mc
  720.     end
  721.     mr.list[distance] = mc2
  722.     event.force_move_route(mr)
  723.   end
  724.  
  725.   def csca_hookshot_success(event)
  726.     x1 = event.x
  727.     y1 = event.y
  728.     x2 = @csca_event.x
  729.     y2 = @csca_event.y
  730.     event.direction == 2 ? distance = (y1 - y2).abs :
  731.     event.direction == 8 ? distance = (y1 - y2).abs : distance = (x1 - x2).abs
  732.     mr = RPG::MoveRoute.new
  733.     mr.repeat = false
  734.     mr.wait = true
  735.     mr.skippable = true
  736.     mc = RPG::MoveCommand.new
  737.     mc.code = 12
  738.     mc.parameters = []
  739.     mc2 = RPG::MoveCommand.new
  740.     mc2.code = 45
  741.     mc2.parameters = ["$game_map.csca_finish_move_route"]
  742.     mc3 = RPG::MoveCommand.new
  743.     mc3.code = 37
  744.     mc3.parameters = []
  745.     mc4 = RPG::MoveCommand.new
  746.     mc4.code = 38
  747.     mc4.parameters = []
  748.     mc5 = RPG::MoveCommand.new
  749.     mc5.code = 32
  750.     mc5.parameters = []
  751.     mc6 = RPG::MoveCommand.new
  752.     mc6.code = 31
  753.     mc6.parameters = []
  754.     mc7 = RPG::MoveCommand.new
  755.     mc7.code = 45
  756.     mc7.parameters = ["$game_player.csca_move_route_over"]
  757.     mr.list[0] = mc3
  758.     mr.list[1] = mc5
  759.     for i in 2..distance + 1
  760.       mr.list[i] = mc
  761.     end
  762.     mr.list[distance + 2] = mc4
  763.     mr.list[distance + 3] = mc6
  764.     mr.list[distance + 4] = mc2
  765.     mr.list[distance + 5] = mc7
  766.     event.force_move_route(mr)
  767.   end
  768.  
  769.   def csca_move_back
  770.     @movingback = true
  771.     csca_get_event
  772.     x1 = $game_player.x
  773.     y1 = $game_player.y
  774.     x2 = @csca_event.x
  775.     y2 = @csca_event.y
  776.     @csca_event.direction == 2 ? distance = (y1 - y2).abs :
  777.     @csca_event.direction == 8 ? distance = (y1 - y2).abs : distance = (x1 - x2).abs
  778.     boomarang_move_route(@csca_event, distance)
  779.   end
  780.  
  781.   def csca_clear_ok?(event)
  782.     mr = RPG::MoveRoute.new
  783.     mr.repeat = false
  784.     mr.wait = true
  785.     mr.skippable = true
  786.     mc = RPG::MoveCommand.new
  787.     mc.code = 15
  788.     mc.parameters = [BOMB_ANIMATION_TIME]
  789.     mc2 = RPG::MoveCommand.new
  790.     mc2.code = 45
  791.     mc2.parameters = ["$game_map.csca_clear_bomb_event"]
  792.     mr.list[0] = mc
  793.     mr.list[1] = mc2
  794.     event.force_move_route(mr)
  795.   end
  796.  
  797.   def turn_on_next_ss(event)
  798.     csca_map_id = map_id
  799.     csca_event_id = event
  800.     switches = ["A","B","C","D"]
  801.     for i in switches
  802.       key = [csca_map_id, csca_event_id, i]
  803.       if !$game_self_switches[key]
  804.         $game_self_switches[key] = true
  805.         return
  806.       end
  807.     end
  808.   end
  809.  
  810.   def csca_check_collision(event)
  811.     x = event.x
  812.     y = event.y
  813.     d = event.direction
  814.     case d
  815.     when 2; y += 1
  816.     when 4; x -= 1
  817.     when 6; x += 1
  818.     when 8; y -= 1
  819.     end
  820.     @csca_event_id = event_id_xy(x, y)
  821.     if @csca_event_id != 0
  822.       csca_get_collision_event(@csca_event_id)
  823.       csca_check_comment(@csca_collision_event, 1) if @tooltype == :arrow
  824.       if region_id(@csca_event.x, @csca_event.y) == REGION_ID1 && @tooltype == :hookshot
  825.         hookshot_move_back(@csca_event)
  826.       else
  827.         csca_check_comment(@csca_collision_event, 3) if @tooltype == :hookshot
  828.       end
  829.     else
  830.       Audio.se_play("Audio/SE/" + ARROW_HIT_SOUND2, 80, 100) if ARROW_SOUND3 && @tooltype == :arrow
  831.       hookshot_move_back(@csca_event) if @tooltype == :hookshot
  832.     end
  833.     csca_clear_event if @tooltype == :arrow
  834.   end
  835.  
  836.   def csca_get_collision_event(id)
  837.     events.each do |i, event|
  838.       @csca_collision_event = event if event.id == id
  839.     end
  840.   end
  841.  
  842.   def csca_check_comment(event, tool, bombvar = 0)
  843.     unless event == nil
  844.     for i in 0...event.list.size
  845.       case tool
  846.       when 1
  847.         if event.list[i].code == 108 && event.list[i].parameters == ["ARROW_ACTIVATE"]
  848.           Audio.se_play("Audio/SE/" + ARROW_HIT_SOUND1, 80, 100) if ARROW_SOUND2
  849.           turn_on_next_ss(@csca_event_id)
  850.         else
  851.           Audio.se_play("Audio/SE/" + ARROW_HIT_SOUND2, 80, 100) if ARROW_SOUND3
  852.         end
  853.       when 2
  854.         if event.list[i].code == 108 && event.list[i].parameters == ["BOOMERANG_ACTIVATE"] && !pickup?
  855.           turn_on_next_ss(@csca_event_id)
  856.           @pickedup = true
  857.         end
  858.       when 3
  859.         if event.list[i].code == 108 && event.list[i].parameters == ["HOOKSHOT_ENABLED"]
  860.           csca_hookshot_success($game_player)
  861.           return
  862.         else
  863.           hookshot_move_back(@csca_event)
  864.         end
  865.       when 4
  866.         if event.list[i].code == 108 && event.list[i].parameters == ["RESET_EXEMPT"]
  867.           return false
  868.         else
  869.           return true
  870.         end
  871.       when 5
  872.         if event.list[i].code == 108 && event.list[i].parameters == ["BOMB_ACTIVATE"]
  873.           turn_on_next_ss(@csca_bomb_event_id1) if bombvar == 1
  874.           turn_on_next_ss(@csca_bomb_event_id2) if bombvar == 2
  875.           turn_on_next_ss(@csca_bomb_event_id3) if bombvar == 3
  876.           turn_on_next_ss(@csca_bomb_event_id4) if bombvar == 4
  877.           turn_on_next_ss(@csca_bomb_event_id5) if bombvar == 5
  878.         end
  879.       end
  880.     end
  881.     end # unless event == nil
  882.   end
  883.  
  884.   def csca_reset
  885.     $game_variables[CSCADGT] = 0
  886.     map_id = $game_player.csca_transfer_map_id
  887.     event_amount = events.size
  888.     for i in 1..event_amount
  889.       event_id = i
  890.       get_exempt_event(event_id)
  891.       if $game_map.csca_check_comment(@csca_exempt_event, 4)
  892.         switches = ["A","B","C","D"]
  893.         for i in switches
  894.           key = [map_id, event_id, i]
  895.           $game_self_switches[key] = false
  896.         end
  897.       end
  898.     end
  899.     x = $game_player.csca_transfer_x
  900.     y = $game_player.csca_transfer_y
  901.     d = $game_player.direction
  902.     if x != nil && y != nil && d != nil
  903.       $game_player.reserve_transfer(map_id, x, y, d)
  904.       $game_temp.fade_type = 0
  905.     end
  906.   end
  907.  
  908.   def get_exempt_event(id)
  909.     events.each do |i, event|
  910.       @csca_exempt_event = event if event.id == id
  911.     end
  912.   end
  913.  
  914.   def get_bomb_explode_event(id)
  915.     events.each do |i, event|
  916.       @csca_bomb_explode_event = event if event.id == id
  917.     end
  918.   end
  919.  
  920. end
  921. class Game_Player < Game_Character
  922.  
  923.   alias csca_save_transfer reserve_transfer
  924.   def reserve_transfer(map_id, x, y, d = 2)
  925.     csca_save_transfer(map_id, x, y, d)
  926.     @csca_saved_map_id = map_id
  927.     @csca_saved_x = x
  928.     @csca_saved_y = y
  929.     $game_map.csca_clear_event
  930.     $game_map.csca_clear_bomb_event
  931.   end
  932.  
  933.   def csca_transfer_map_id
  934.     @csca_saved_map_id
  935.   end
  936.  
  937.   def csca_transfer_x
  938.     @csca_saved_x
  939.   end
  940.  
  941.   def csca_transfer_y
  942.     @csca_saved_y
  943.   end
  944.  
  945.   def csca_move_route_over
  946.     @move_route_forcing = false
  947.   end
  948.  
  949.   alias csca_movable? movable?
  950.   def movable?
  951.     return false if $game_map.using_tool? && ($game_map.tooltype? == :hookshot || $game_map.tooltype? == :boomarang)
  952.     csca_movable?
  953.   end
  954.  
  955.   alias csca_dt_damage_floor? on_damage_floor?
  956.   def on_damage_floor?
  957.     !($game_map.tooltype? == :hookshot && $game_map.using_tool?) && csca_dt_damage_floor?
  958.   end
  959.  
  960.   def move_by_input
  961.     return if !movable? || $game_map.interpreter.running?
  962.     if Input.press?(CSCA_DUNGEON_TOOLS::STILL_TRIGGER) && CSCA_DUNGEON_TOOLS::ENABLE_STILL
  963.       set_direction(Input.dir4) if Input.dir4 > 0
  964.     else
  965.       move_straight(Input.dir4) if Input.dir4 > 0
  966.     end
  967.   end
  968.  
  969. end
  970. class CSCA_Scene_DungeonToolSelect < Scene_MenuBase
  971.   include CSCA_DUNGEON_TOOLS
  972.  
  973.   def start
  974.     super
  975.     create_command_window
  976.     create_head_window
  977.   end
  978.  
  979.   def update
  980.     super
  981.     update_cancel
  982.   end
  983.  
  984.   def update_cancel
  985.     if Input.press?(:B)
  986.       Sound.play_cancel
  987.       return_scene
  988.     end
  989.   end
  990.  
  991.   def create_command_window
  992.     @command_window = CSCA_Window_DungeonToolSelect.new(200, 150)
  993.     if $game_switches[ARROW]
  994.       @command_window.set_handler(:arrow, method(:select_arrow))
  995.     end
  996.     if $game_switches[BOMB]
  997.       @command_window.set_handler(:bomb, method(:select_bomb))
  998.     end
  999.     if $game_switches[HOOKSHOT]
  1000.       @command_window.set_handler(:hookshot, method(:select_hookshot))
  1001.     end
  1002.     if $game_switches[BOOMERANG]
  1003.       @command_window.set_handler(:boomarang, method(:select_boomarang))
  1004.     end
  1005.     if $game_switches[RESET]
  1006.       @command_window.set_handler(:reset, method(:select_reset))
  1007.     end
  1008.   end
  1009.  
  1010.   def create_head_window
  1011.     @head_window = CSCA_Window_Header.new(200, 100, 160, HEADER)
  1012.   end
  1013.  
  1014.   def select_arrow
  1015.     $game_variables[CSCADGT] = 1
  1016.     return_scene
  1017.   end
  1018.  
  1019.   def select_bomb
  1020.     $game_variables[CSCADGT] = 2
  1021.     return_scene
  1022.   end
  1023.  
  1024.   def select_hookshot
  1025.     $game_variables[CSCADGT] = 3
  1026.     return_scene
  1027.   end
  1028.  
  1029.   def select_boomarang
  1030.     $game_variables[CSCADGT] = 4
  1031.     return_scene
  1032.   end
  1033.  
  1034.   def select_reset
  1035.     $game_variables[CSCADGT] = 5
  1036.     return_scene
  1037.   end
  1038.  
  1039. end
  1040. class CSCA_Window_DungeonToolSelect < Window_Command
  1041.   include CSCA_DUNGEON_TOOLS
  1042.  
  1043.   def initialize(x, y)
  1044.     super(x, y)
  1045.     make_command_icons
  1046.   end
  1047.  
  1048.   def make_command_list
  1049.     add_command(ARROW_NAME, :arrow) if $game_switches[ARROW]
  1050.     add_command(BOMB_NAME, :bomb) if $game_switches[BOMB]
  1051.     add_command(HOOKSHOT_NAME, :hookshot) if $game_switches[HOOKSHOT]
  1052.     add_command(BOOMERANG_NAME, :boomarang) if $game_switches[BOOMERANG]
  1053.     add_command(RESET_NAME, :reset) if $game_switches[RESET]
  1054.   end
  1055.  
  1056.   def make_command_icons
  1057.     y = 0
  1058.     if $game_switches[ARROW]
  1059.       draw_icon(ARROW_ICON, 110, y)
  1060.       y += line_height
  1061.     end
  1062.     if $game_switches[BOMB]
  1063.       draw_icon(BOMB_ICON, 110, y)
  1064.       y += line_height
  1065.     end
  1066.     if $game_switches[HOOKSHOT]
  1067.       draw_icon(HOOKSHOT_ICON, 110, y)
  1068.       y += line_height
  1069.     end
  1070.     if $game_switches[BOOMERANG]
  1071.       draw_icon(BOOMERANG_ICON, 110, y)
  1072.       y += line_height
  1073.     end
  1074.     if $game_switches[RESET]
  1075.       draw_icon(RESET_ICON, 110, y)
  1076.     end
  1077.   end
  1078. end
Advertisement
Add Comment
Please, Sign In to add comment