Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # DSI Card Trading System v1.1
- # -- Last Updated: 2017.03.24
- # -- Author: dsiver144
- # -- Level: Normal
- # -- Requires: n/a
- #==============================================================================
- $imported = {} if $imported.nil?
- $imported["DSI-CardTrading"] = true
- #==============================================================================
- # + Updates
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # 2017.02.27 - Finish first version.
- # 2017.03.24 - Modify for checking the trade
- #==============================================================================
- # + Instructions
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # To install this script, open up your script editor and copy/paste this script
- # to an open slot below ?? Materials/?f?? but above ?? Main. Remember to save.
- # Remember to put this script below: DSI-Bitmap.
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Script Call:
- # trade_card(your_card_id, their_card_id, switch_id)
- # ex: trade_card(28, 29, 7) # Trade your "Earth Throw" with their "Wood Hammer"
- # if the trade is successful then turn on switch 7 else do nothing to the
- # switch.
- # ------------------------------------------------------------------------------
- # latest_trade_result # Use in condition branches for checking latest trade result
- # Return value: True or False
- # ex: latest_trade_result == true
- #==============================================================================
- module DSIVER144
- module CARD_TRADING
- SCROLLABLE_BACKGROUND = "BlueSky"
- SCROLL_X = 1
- SCROLL_Y = 1
- MESSAGES = {}
- MESSAGES[:no_card] = "You don't have the card that I'm looking for!"
- MESSAGES[:has_card] = "Do you want to trade your card with mine?"
- MESSAGES[:cancel_trade] = "Well, if you change your mind later on, you know where to find me!"
- MESSAGES[:success_trade] = "Thanks for the trade!"
- BEGIN_TRADE_SE = ["Flash2",70,100]
- TRADING_SE = ["Sound2",70,100]
- TRADE_COMPLETE_SE = ["Blue Magic (FF6)",70,100]
- ACTOR_SPRITE_X = 25
- ACTOR_SPRITE_Y = 165
- TRADER_SPRITE_X = 520
- TRADER_SPRITE_Y = 165
- OTHER_BUTTONS_TEXT = "\\i[1600]:Confirm - \\i[1602]:Cancel"
- OTHER_BUTTONS_MARGIN = 176
- end # CARD_TRADING
- end # DSIVER144
- class Game_Interpreter
- #--------------------------------------------------------------------------
- # * new method: latest_trade_result
- #--------------------------------------------------------------------------
- def latest_trade_result
- $game_system.recently_trade_stt
- end
- #--------------------------------------------------------------------------
- # * new method: get_event
- #--------------------------------------------------------------------------
- def get_event
- return $game_map.events[@event_id]
- end
- #--------------------------------------------------------------------------
- # * new method: trade_card
- #--------------------------------------------------------------------------
- def trade_card(your_card, their_card, switch_id)
- SceneManager.call(Scene_CardTrading)
- SceneManager.scene.prepare(your_card, their_card, get_event, switch_id)
- Fiber.yield
- end
- end # Game_Interpreter
- class Game_Interpreter2 < Game_Interpreter
- def initialize
- end
- end # Game_Interpreter2
- include DSIVER144::CARD_TRADING
- class Scene_CardTrading < Scene_Base
- #--------------------------------------------------------------------------
- # * new method: trade_card
- #--------------------------------------------------------------------------
- def prepare(*params) # (Player_Card, Their Card, Event)
- @interpreter = Game_Interpreter2.new
- @your_card_id = params[0]
- @their_card_id = params[1]
- if params[2].is_a?(Game_Event)
- @their_name = params[2].character_name
- @their_index = params[2].character_index
- @switch_id = params[3]
- end
- if params[2].is_a?(String)
- @their_name = params[2]
- @their_index = params[3].to_i
- @switch_id = params[4]
- end
- $game_system.recently_trade_stt = false
- #$game_switches[@switch_id] = false
- @has_card = @interpreter.has_card?(@your_card_id)
- end
- #--------------------------------------------------------------------------
- # * new method: start
- #--------------------------------------------------------------------------
- def start
- super
- create_background_image
- create_main_windows
- end
- #-------------------------------------------------------------------------
- # * new method: create_background_image
- #-------------------------------------------------------------------------
- def create_background_image
- @background_image = Plane.new
- if SCROLLABLE_BACKGROUND != false
- begin
- @background_image.bitmap = Cache.parallax(SCROLLABLE_BACKGROUND)
- @has_parallax = true
- rescue
- @background_image.bitmap = SceneManager.background_bitmap
- @background_image.color.set(16, 16, 16, 128)
- end
- else
- @background_image.bitmap = SceneManager.background_bitmap
- @background_image.color.set(16, 16, 16, 128)
- end
- end
- #--------------------------------------------------------------------------
- # * new method: draw_character
- #--------------------------------------------------------------------------
- def draw_character(character_name, character_index, x, y, des_bitmap)
- return unless character_name
- bitmap = Cache.character(character_name)
- sign = character_name[/^[\!\$]./]
- if sign && sign.include?('$')
- cw = bitmap.width / 3
- ch = bitmap.height / 4
- else
- cw = bitmap.width / 12
- ch = bitmap.height / 8
- end
- n = character_index
- src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
- des_bitmap.blt(x - cw / 2, y - ch, bitmap, src_rect)
- end
- #--------------------------------------------------------------------------
- # * new method: create_main_windows
- #--------------------------------------------------------------------------
- def create_main_windows
- @message_window = Window_CardTradeMessage.new(0,0,450,96)
- @message_window.x = 0.5*(Graphics.width - @message_window.width)
- @message_window.y = Graphics.height - @message_window.height - 4
- @command_window = Window_TradeCommand.new(0,0)
- @command_window.x = 0.5*(Graphics.width - @command_window.width)
- @command_window.y = 0.5*(Graphics.height - @command_window.height)
- @command_window.deactivate
- @command_window.openness = 0
- @command_window.set_handler(:ok, method(:process_trade))
- @command_window.set_handler(:cancel, method(:cancel_trade))
- @spr_PlayerCard = Sprite.new
- @spr_PlayerCard.bitmap = Cache.picture("Card#{@your_card_id}")
- @spr_PlayerCard.x = @message_window.x
- @spr_PlayerCard.y = @message_window.y - @spr_PlayerCard.bitmap.height - 27
- @spr_TheirCard = Sprite.new
- @spr_TheirCard.bitmap = Cache.picture("Card#{@their_card_id}")
- @spr_TheirCard.x = @message_window.x + @message_window.width - @spr_TheirCard.bitmap.width
- @spr_TheirCard.y = @spr_PlayerCard.y
- @spr_chars = Sprite.new
- @spr_chars.bitmap = Bitmap.new(Graphics.width,Graphics.height)
- @spr_texts = Sprite.new
- @spr_texts.bitmap = Bitmap.new(Graphics.width,Graphics.height)
- @spr_texts.bitmap.fill_rect(@spr_PlayerCard.x,@spr_PlayerCard.y - 24,@spr_PlayerCard.bitmap.width,20,Color.new(0,0,0,150))
- @spr_texts.bitmap.fill_rect(@spr_TheirCard.x,@spr_TheirCard.y - 24,@spr_TheirCard.bitmap.width,20,Color.new(0,0,0,150))
- @spr_texts.bitmap.draw_text(@spr_PlayerCard.x,@spr_PlayerCard.y - 25,@spr_PlayerCard.bitmap.width,24,"Your Card", 1)
- @spr_texts.bitmap.draw_text(@spr_TheirCard.x,@spr_TheirCard.y - 25,@spr_TheirCard.bitmap.width,24,"Their Card", 1)
- @spr_texts.x = 0
- @spr_texts.y = 0
- @spr_texts.z = 300
- @spr_card_names = Sprite.new
- @spr_card_names.bitmap = Bitmap.new(Graphics.width,Graphics.height)
- yy = @spr_PlayerCard.y + @spr_PlayerCard.height + 1
- player_card_name = $data_skills[@your_card_id].name
- if !@has_card
- @spr_PlayerCard.tone = Tone.new(0,0,0,200)
- @spr_PlayerCard.opacity = 220
- player_card_name = "?????????????????????"
- end
- their_card_name = $data_skills[@their_card_id].name
- @spr_card_names.bitmap.fill_rect(@spr_PlayerCard.x,yy + 2,@spr_PlayerCard.bitmap.width,20,Color.new(0,0,0,150))
- @spr_card_names.bitmap.fill_rect(@spr_TheirCard.x,yy + 2,@spr_PlayerCard.bitmap.width,20,Color.new(0,0,0,150))
- @spr_card_names.bitmap.draw_text(@spr_PlayerCard.x,yy,@spr_PlayerCard.bitmap.width,24,player_card_name, 1)
- @spr_card_names.bitmap.draw_text(@spr_TheirCard.x,yy,@spr_TheirCard.bitmap.width,24,their_card_name, 1)
- name = $game_actors[1].character_name
- index = $game_actors[1].character_index
- their_name = @their_name
- their_index = @their_index
- draw_character(name, index, ACTOR_SPRITE_X, ACTOR_SPRITE_Y, @spr_chars.bitmap)
- draw_character(their_name, their_index, TRADER_SPRITE_X, TRADER_SPRITE_Y, @spr_chars.bitmap)
- @spr_chars.x = 0
- @spr_chars.y = 0
- @spr_chars.z = 260
- if !@has_card
- @message_window.draw_message(MESSAGES[:no_card])
- else
- @message_window.draw_message(MESSAGES[:has_card])
- @command_window.activate
- @command_window.open
- end
- end
- #--------------------------------------------------------------------------
- # * new method: terminate
- #--------------------------------------------------------------------------
- def terminate
- super
- @background_image.bitmap.dispose
- @background_image.dispose
- @spr_chars.bitmap.dispose
- @spr_chars.dispose
- @spr_texts.bitmap.dispose
- @spr_texts.dispose
- @spr_card_names.bitmap.dispose
- @spr_card_names.dispose
- @spr_PlayerCard.bitmap.dispose
- @spr_PlayerCard.dispose
- @spr_TheirCard.bitmap.dispose
- @spr_TheirCard.dispose
- end
- #--------------------------------------------------------------------------
- # * new method: redraw_names
- #--------------------------------------------------------------------------
- def redraw_names
- yy = @spr_PlayerCard.y + @spr_PlayerCard.height + 1
- player_card_name = $data_skills[@their_card_id].name
- their_card_name = $data_skills[@your_card_id].name
- @spr_card_names.bitmap.fill_rect(@spr_PlayerCard.x,yy + 2,@spr_PlayerCard.bitmap.width,20,Color.new(0,0,0,150))
- @spr_card_names.bitmap.fill_rect(@spr_TheirCard.x,yy + 2,@spr_PlayerCard.bitmap.width,20,Color.new(0,0,0,150))
- @spr_card_names.bitmap.draw_text(@spr_PlayerCard.x,yy,@spr_PlayerCard.bitmap.width,24,player_card_name, 1)
- @spr_card_names.bitmap.draw_text(@spr_TheirCard.x,yy,@spr_TheirCard.bitmap.width,24,their_card_name, 1)
- end
- #--------------------------------------------------------------------------
- # * new method: process_trade
- #--------------------------------------------------------------------------
- def process_trade
- des_x1 = @spr_TheirCard.x + 20
- des_x2 = @spr_PlayerCard.x
- @command_window.close
- while @spr_card_names.opacity > 0
- @command_window.update
- @spr_card_names.opacity -= 10
- @spr_texts.opacity -= 10
- Graphics.update
- end
- @spr_card_names.bitmap.clear
- redraw_names
- @message_window.draw_message("TRADING...")
- RPG::SE.new(*BEGIN_TRADE_SE).play
- @spr_PlayerCard.flash(Color.new(255,255,255), 30)
- @spr_TheirCard.flash(Color.new(255,255,255), 30)
- 30.times do
- Graphics.update
- @spr_PlayerCard.update
- @spr_TheirCard.update
- end
- RPG::SE.new(*BEGIN_TRADE_SE).play
- @spr_PlayerCard.flash(Color.new(255,255,255), 60)
- @spr_TheirCard.flash(Color.new(255,255,255), 60)
- 60.times do
- @command_window.update
- Graphics.update
- @spr_PlayerCard.update
- @spr_TheirCard.update
- end
- RPG::SE.new(*TRADING_SE).play
- loop do
- @command_window.update
- Graphics.update
- x1 = des_x1 - @spr_PlayerCard.x
- x2 = des_x2 - @spr_TheirCard.x
- if Math.sqrt(des_x1**2 - @spr_PlayerCard.x**2) > 1
- @spr_PlayerCard.x += x1*0.05
- else
- complete_1 ||= true
- end
- if Math.sqrt((des_x2**2 - @spr_TheirCard.x**2).abs) > 1
- @spr_TheirCard.x += x2*0.05
- else
- complete_2 ||= true
- end
- if complete_1 || complete_2
- break
- end
- end
- RPG::SE.new(*TRADE_COMPLETE_SE).play
- @spr_PlayerCard.flash(Color.new(255,255,255), 60)
- @spr_TheirCard.flash(Color.new(255,255,255), 60)
- 60.times do
- @command_window.update
- Graphics.update
- @spr_PlayerCard.update
- @spr_TheirCard.update
- @spr_card_names.opacity += 10
- @spr_texts.opacity += 10
- end
- @message_window.draw_message(MESSAGES[:success_trade])
- $game_switches[@switch_id] = true
- $game_system.recently_trade_stt = true
- process_gain_lose_card
- @success_trade = true
- end
- #--------------------------------------------------------------------------
- # * new method: process_gain_lose_card
- #--------------------------------------------------------------------------
- def process_gain_lose_card
- @interpreter.add_card_to_coll(@their_card_id)
- @interpreter.remove_card?(@your_card_id)
- end
- #--------------------------------------------------------------------------
- # * new method: cancel_trade
- #--------------------------------------------------------------------------
- def cancel_trade
- @command_window.close
- @command_window.deactivate
- @message_window.draw_message(MESSAGES[:cancel_trade])
- @cancel_trade = true
- end
- #--------------------------------------------------------------------------
- # * new method: update_no_card_input
- #--------------------------------------------------------------------------
- def update_no_card_input
- while true
- Input.update
- Graphics.update
- if Input.trigger?(:B)
- break
- return_scene
- end
- end
- end
- #--------------------------------------------------------------------------
- # * new method: update_parallax
- #--------------------------------------------------------------------------
- def update_parallax
- return unless @has_parallax
- @background_image.ox += SCROLL_X if Graphics.frame_count % 3 == 0
- @background_image.oy += SCROLL_Y if Graphics.frame_count % 3 == 0
- end
- #--------------------------------------------------------------------------
- # * new method: update
- #--------------------------------------------------------------------------
- def update
- super
- update_parallax
- if !@has_card or @cancel_trade or @success_trade
- if Input.trigger?(:B)
- Sound.play_cancel
- return_scene
- end
- end
- end # update
- end # Scene_CardTrading
- class Window_TradeCommand < Window_Command
- #--------------------------------------------------------------------------
- # * new method: trade_card
- #--------------------------------------------------------------------------
- def window_width
- return 150
- end
- #--------------------------------------------------------------------------
- # * new method: trade_card
- #--------------------------------------------------------------------------
- def alignment
- return 1
- end
- #--------------------------------------------------------------------------
- # * new method: trade_card
- #--------------------------------------------------------------------------
- def make_command_list
- add_command("Trade!", :ok)
- add_command("No!", :cancel)
- end
- end # Window_TradeCommand
- class Game_System
- attr_accessor :recently_trade_stt
- alias_method(:dsi_recently_trade_stt_initialize, :initialize)
- #--------------------------------------------------------------------------
- # * alias method: initialize
- #--------------------------------------------------------------------------
- def initialize
- @recently_trade_stt = false
- dsi_recently_trade_stt_initialize # Call original method
- end
- end # Game_System
- class Window_CardTradeMessage < Window_Base
- #--------------------------------------------------------------------------
- # * new method: draw_message
- #--------------------------------------------------------------------------
- def draw_message(message)
- contents.clear
- text_bitmap = Bitmap.new(contents_width,contents_height)
- text_bitmap.turn_on_wordwraping
- text_bitmap.draw_text_ex(0,0,message, false)
- contents.blt(0,0, text_bitmap, text_bitmap.rect)
- draw_text_ex(contents_width - OTHER_BUTTONS_MARGIN,contents_height - 24,OTHER_BUTTONS_TEXT)
- end
- end # Window_CardTradeMessage
- #===============================================================================
- # * END OF FILE
- #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement