VX 스크립트

상점
2011.01.23 15:10

상점에서 아이템 분류

조회 수 3510 추천 수 1 댓글 5
Atachment
첨부 '1'

#******************************************************************************
#
#    * ショップアイテム分類
#
#  --------------------------------------------------------------------------
#    バージョン :  1.0.5
#    対      応 :  RPGツクールVX : RGSS2
#    制  作  者 :  CACAO
#    配  布  元 :  http://cacaosoft.web.fc2.com/
#  --------------------------------------------------------------------------
#   == 概要 ==
#
#    : 表示するアイテムを種類別に分けます。
#
#  --------------------------------------------------------------------------
#   == 注意事項 ==
#
#    ※ このスクリプトの実行には、Cacao Base Script が必要です。
#    ※ 再定義を多く行っております。なるべく上部に導入してください。
#
#  --------------------------------------------------------------------------
#   == 画像規格 ==
#
#    ★ ショップアイコン
#     144 x 24 の画像(ShopIcon)を "Graphics/System" にご用意ください。
#     ※ 詳細はサイトの説明をご覧ください。
#
#
#******************************************************************************


#/////////////////////////////////////////////////////////////////////////////#
#                                                                             #
#                  このスクリプトには設定項目はありません。                   #
#                                                                             #
#/////////////////////////////////////////////////////////////////////////////#


module CAO::KSHOP
  # アイテムのアイコン画像
  FILE_ITME_ICON = "ShopIcon"
 
  # アイテムの表示切替時の効果音
  SE_PAGE = ["Audio/SE/Book", 90, 150]
 
  # 売却時の数字のアラインメント
  NUM_ALIGN = 2
 
  # テキストの設定
  TEXT_SELL = "買取価格:"
  TEXT_HAVE = "所持数:"
 
  #--------------------------------------------------------------------------
  # ● 売却価格の取得
  #--------------------------------------------------------------------------
  def self.get_sell_price(price)
    return price / 2
  end
  #--------------------------------------------------------------------------
  # ● KGC[装備拡張]の有無
  #--------------------------------------------------------------------------
  def self.in_kgc_equip_ext?
    return Hash === $imported && $imported["EquipExtension"]
  end
  #--------------------------------------------------------------------------
  # ● アイテム+装備品の総数
  #--------------------------------------------------------------------------
  def self.item_max
    if in_kgc_equip_ext?
      return KGC::EquipExtension::EQUIP_TYPE.uniq.size + 2
    else
      return 6  # アイテム, 武器, 盾, 頭, 身体, 装飾
    end
  end
  #--------------------------------------------------------------------------
  # ● アイテムの表示順の取得
  #--------------------------------------------------------------------------
  def self.item_index(item)
    case item
    when RPG::Item
      index = 0
    when RPG::Weapon
      index = 1
    when RPG::Armor
      if in_kgc_equip_ext?
        index = 2 + KGC::EquipExtension::EQUIP_TYPE.index(item.kind)
      else
        index = 2 + item.kind
      end
    end
    return index
  end
end

class Window_ShopIcon < Window_Base
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_accessor :index                    #
  #--------------------------------------------------------------------------
  # 〇 オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    super(0, 56, 384, 56)
    @item_max = CAO::KSHOP.item_max
    @index = 0
    @img_icon = Cache.system(CAO::KSHOP::FILE_ITME_ICON)
    refresh
  end
  #--------------------------------------------------------------------------
  # 〇 リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    cw = self.contents.width / @item_max
    for i in 0...@item_max
      x = cw * i + (cw - 24) / 2
      rect = Rect.new(24 * i, 0, 24, 24)
      self.contents.blt(x, 0, @img_icon, rect, (@index == i ? 255 : 128))
    end
  end
  #--------------------------------------------------------------------------
  # 〇 フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    if Input.trigger?(Input::LEFT)
      @index = (@index - 1 + @item_max) % @item_max
    end
    if Input.trigger?(Input::RIGHT)
      @index = (@index + 1) % @item_max
    end
  end
end

class Window_ShopBuy < Window_Selectable
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_accessor :item_index               #
  #--------------------------------------------------------------------------
  # 〇 オブジェクト初期化
  #--------------------------------------------------------------------------
  alias _cao_initialize_kshop initialize
  def initialize(x, y)
    @item_index = 0
    _cao_initialize_kshop(x, y)
  end
  #--------------------------------------------------------------------------
  # 〇 アイテムの取得
  #--------------------------------------------------------------------------
  def item
    return @data[@item_index][self.index]
  end
  #--------------------------------------------------------------------------
  # 〇 リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    @data = Array.new(CAO::KSHOP.item_max) { [] }
    for goods_item in @shop_goods
      case goods_item[0]
      when 0
        item = $data_items[goods_item[1]]
      when 1
        item = $data_weapons[goods_item[1]]
      when 2
        item = $data_armors[goods_item[1]]
      end
      if item != nil
        @data[CAO::KSHOP.item_index(item)].push(item)
      end
    end
    @item_max = @data[@item_index].size
    create_contents
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  # 〇 項目の描画
  #     index : 項目番号
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[@item_index][index]
    number = $game_party.item_number(item)
    enabled = (item.price <= $game_party.gold and number < 99)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    draw_item_name(item, rect.x, rect.y, enabled)
    rect.width -= 4
    self.contents.draw_text(rect, item.price, 2)
  end
  #--------------------------------------------------------------------------
  # 〇 ヘルプテキスト更新
  #--------------------------------------------------------------------------
  def update_help
    item = self.item
    @help_window.set_text(item == nil ? "" : item.description)
  end
end

class Window_ShopSell < Window_Item
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_accessor :item_index               #
  #--------------------------------------------------------------------------
  # 〇 オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height)
    super(x, y, width, height)
    @column_max = 1
    @item_index = 0
  end
  #--------------------------------------------------------------------------
  # 〇 リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    @data = []
    for item in $game_party.items
      next unless include?(item)
      @data.push(item)
      if item.is_a?(RPG::Item) and item.id == $game_party.last_item_id
        self.index = @data.size - 1
      end
    end
    @data.push(nil) if include?(nil)
    @item_max = @data.size
    create_contents
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  # 〇 項目の描画
  #     index : 項目番号
  #--------------------------------------------------------------------------
  def draw_item(index)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    item = @data[index]
    if item != nil
      number = $game_party.item_number(item)
      enabled = enable?(item)
      draw_item_name(item, rect.x, rect.y, enabled)
      self.contents.font.color = system_color
      self.contents.draw_text(244, rect.y, 95, WLH, CAO::KSHOP::TEXT_SELL)
      self.contents.draw_text(413, rect.y, 75, WLH, CAO::KSHOP::TEXT_HAVE)
      self.contents.font.color = normal_color
      price = CAO::KSHOP.get_sell_price(item.price)
      align = CAO::KSHOP::NUM_ALIGN
      self.contents.draw_text(339, rect.y, 70, WLH, price, align)
      self.contents.draw_text(488, rect.y, 20, WLH, number, align)
    end
  end
  #--------------------------------------------------------------------------
  # ●
  #--------------------------------------------------------------------------
  def include?(item)
    return false if item == nil
    return @item_index == CAO::KSHOP.item_index(item)
  end
  #--------------------------------------------------------------------------
  # 〇 アイテム名の描画
  #     item    : アイテム (スキル、武器、防具でも可)
  #     x       : 描画先 X 座標
  #     y       : 描画先 Y 座標
  #     enabled : 有効フラグ。false のとき半透明で描画
  #--------------------------------------------------------------------------
  def draw_item_name(item, x, y, enabled = true)
    if item != nil
      draw_icon(item.icon_index, x, y, enabled)
      self.contents.font.color = normal_color
      self.contents.font.color.alpha = enabled ? 255 : 128
      self.contents.draw_text(x + 24, y, 240, WLH, item.name)
    end
  end
end

class Window_ShopNumber < Window_Base
  #--------------------------------------------------------------------------
  # 〇 オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(x, y)
    super(x, y, 304, 304)
    @item = nil
    @max = 1
    @price = 0
    @index = 1
    @number = 1
    @digits_max = 2
  end
  #--------------------------------------------------------------------------
  # 〇 アイテム、最大個数、価格の設定
  #--------------------------------------------------------------------------
  def set(item, max, price)
    @item = item
    @max = max
    @price = price
    @number = 1
    @index = 1
    refresh
    update_cursor
  end
  #--------------------------------------------------------------------------
  # 〇 リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    y = 96
    self.contents.clear
    draw_item_name(@item, 0, y)
    self.contents.font.color = normal_color
    self.contents.draw_text(212, y, 20, WLH, "×")
    s = sprintf("%0*d", @digits_max, @number)
    for i in 0...@digits_max
      self.contents.draw_text(240 + i * 14, y, 14, WLH, s[i,1], 1)
    end
    draw_currency_value(@price * @number, 4, y + WLH * 2, 264)
  end
  #--------------------------------------------------------------------------
  # 〇 フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    if self.active
      if Input.repeat?(Input::UP) or Input.repeat?(Input::DOWN)
        Sound.play_cursor
        place = 10 ** (@digits_max - 1 - @index)
        n = @number / place % 10
        @number -= n * place
        n = (n + 1) % 10 if Input.repeat?(Input::UP)
        n = (n + 9) % 10 if Input.repeat?(Input::DOWN)
        @number += n * place
        @number = [@number, @max].min
        refresh
      end
      last_index = @index
      if Input.repeat?(Input::RIGHT)
        if @index < @digits_max - 1 or Input.trigger?(Input::RIGHT)
          @index = (@index + 1) % @digits_max
        end
      end
      if Input.repeat?(Input::LEFT)
        if @index > 0 or Input.trigger?(Input::LEFT)
          @index = (@index + @digits_max - 1) % @digits_max
        end
      end
      if @index != last_index
        Sound.play_cursor
      end
      update_cursor
    end
  end
  #--------------------------------------------------------------------------
  # ● カーソルの更新
  #--------------------------------------------------------------------------
  def update_cursor
    self.cursor_rect.set(240 + @index * 14, 96, 14, WLH)
  end
end

class Scene_Shop < Scene_Base
  #--------------------------------------------------------------------------
  # ● 開始処理
  #--------------------------------------------------------------------------
  def start
    super
    create_menu_background
    create_command_window
    @help_window = Window_Help.new
    @gold_window = Window_Gold.new(384, 56)
    @dummy_window = Window_Base.new(0, 112, 544, 304)
    @buy_window = Window_ShopBuy.new(0, 112)
    @buy_window.active = false
    @buy_window.visible = false
    @buy_window.help_window = @help_window
    @sell_window = Window_ShopSell.new(0, 112, 544, 304)
    @sell_window.active = false
    @sell_window.visible = false
    @sell_window.help_window = @help_window
    @number_window = Window_ShopNumber.new(0, 112)
    @number_window.active = false
    @number_window.visible = false
    @status_window = Window_ShopStatus.new(304, 112)
    @status_window.visible = false
  end
  #--------------------------------------------------------------------------
  # 〇 開始処理
  #--------------------------------------------------------------------------
  alias _cao_start_kshop start
  def start
    _cao_start_kshop
    @icon_window = Window_ShopIcon.new
    @icon_window.active = false
    @icon_window.visible = false
  end
  #--------------------------------------------------------------------------
  # 〇 終了処理
  #--------------------------------------------------------------------------
  alias _cao_terminate_kshop terminate
  def terminate
    _cao_terminate_kshop
    @icon_window.dispose
  end
  #--------------------------------------------------------------------------
  # 〇 フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    update_menu_background
    @help_window.update
    @command_window.update
    @gold_window.update
    @dummy_window.update
    @buy_window.update
    @sell_window.update
    @number_window.update
    @status_window.update
    if @command_window.active
      update_command_selection
    elsif @buy_window.active
      update_buy_selection
      update_item_kind
    elsif @sell_window.active
      update_sell_selection
      update_item_kind
    elsif @number_window.active
      update_number_input
    end
  end
  #--------------------------------------------------------------------------
  # 〇 コマンドウィンドウの作成
  #--------------------------------------------------------------------------
  def create_command_window
    s1 = Vocab::ShopBuy
    s2 = Vocab::ShopSell
    s3 = Vocab::ShopCancel
    @command_window = CAO::Window_Command.new(0, 56, 384, 56, [s1,s2,s3], 1, 3)
    if $game_temp.shop_purchase_only
      @command_window.draw_item(1, false)
    end
  end
  #--------------------------------------------------------------------------
  # 〇 コマンド選択の更新
  #--------------------------------------------------------------------------
  def update_command_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      $scene = Scene_Map.new
    elsif Input.trigger?(Input::C)
      case @command_window.index
      when 0
        Sound.play_decision
        @command_window.active = false
        @command_window.visible = false
        @icon_window.active = true
        @icon_window.visible = true
        @icon_window.refresh
        @dummy_window.visible = false
        @buy_window.active = true
        @buy_window.visible = true
        @buy_window.refresh
        @status_window.visible = true
      when 1
        if $game_temp.shop_purchase_only
          Sound.play_buzzer
        else
          Sound.play_decision
          @command_window.active = false
          @command_window.visible = false
          @icon_window.active = true
          @icon_window.visible = true
          @icon_window.refresh
          @dummy_window.visible = false
          @sell_window.active = true
          @sell_window.visible = true
          @sell_window.refresh
        end
      when 2
        Sound.play_decision
        $scene = Scene_Map.new
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 表示アイテム選択の更新
  #--------------------------------------------------------------------------
  def update_item_kind
    last_index = @icon_window.index
    @icon_window.update
    if @icon_window.index != last_index
      Audio.se_play(*CAO::KSHOP::SE_PAGE)
      @icon_window.refresh
      @buy_window.index = 0
      @sell_window.index = 0
      @buy_window.item_index = @icon_window.index
      @sell_window.item_index = @icon_window.index
      if @buy_window.active
        @buy_window.refresh
      elsif @sell_window.active
        @sell_window.refresh
      end
    end
  end
  #--------------------------------------------------------------------------
  # 〇 購入アイテム選択の更新
  #--------------------------------------------------------------------------
  def update_buy_selection
    @status_window.item = @buy_window.item
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @command_window.active = true
      @command_window.visible = true
      @icon_window.active = false
      @icon_window.visible = false
      @dummy_window.visible = true
      @buy_window.active = false
      @buy_window.visible = false
      @status_window.visible = false
      @status_window.item = nil
      @help_window.set_text("")
    elsif Input.trigger?(Input::C)
      @item = @buy_window.item
      number = $game_party.item_number(@item)
      if @item == nil or @item.price > $game_party.gold or number == 99
        Sound.play_buzzer
      else
        Sound.play_decision
        max = @item.price == 0 ? 99 : $game_party.gold / @item.price
        max = [max, 99 - number].min
        @buy_window.active = false
        @buy_window.visible = false
        @number_window.set(@item, max, @item.price)
        @number_window.active = true
        @number_window.visible = true
      end
    end
  end
  #--------------------------------------------------------------------------
  # 〇 売却アイテム選択の更新
  #--------------------------------------------------------------------------
  def update_sell_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @command_window.active = true
      @command_window.visible = true
      @icon_window.active = false
      @icon_window.visible = false
      @dummy_window.visible = true
      @sell_window.active = false
      @sell_window.visible = false
      @status_window.item = nil
      @help_window.set_text("")
    elsif Input.trigger?(Input::C)
      @item = @sell_window.item
      @status_window.item = @item
      if @item == nil or @item.price == 0
        Sound.play_buzzer
      else
        Sound.play_decision
        max = $game_party.item_number(@item)
        @sell_window.active = false
        @sell_window.visible = false
        @number_window.set(@item, max, CAO::KSHOP.get_sell_price(@item.price))
        @number_window.active = true
        @number_window.visible = true
        @status_window.visible = true
      end
    end
  end
end

카카오 엔진 스크립트 중 상점에서 아이템분류를 해주는 스크립트입니다.

중복이라면 댓글로 남겨주시면 자삭하겠습니다.

* 필요한 것

쇼뿌아이콘

저장 위치 : Graphics / system
파일 이름 : ShopIcon
이 즈 : 144 x 24

24 x 24 이미지 다음 순서 정렬합니다.
아이템, 무기, 방패, 머리, , 장식

KGC 님의 장비 확장 스크립트 사용하려면
그곳에서 설정한 정렬 오른쪽으로 추가하십시오.
144px 맞추기 필요 없습니다.

ShopIcon.png

ShopIcon.png로 GraphicsSystem에 넣어주세요

Comment '5'

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 스크립트 자료 게시물 작성시 주의사항 3 습작 2012.12.24 5398
557 기타 요리 시스템을 도입하는 스크립트입니다. 9 file 스페나로츠 2011.08.18 3141
556 기타 화면 확대 스크립트 12 file 에돌이 2011.07.22 3059
555 기타 해상도 변경 스크립트 11 카리스 2011.07.19 2723
554 스킬 강화주문서, SW_EchantScroll by 시옷전사(SiotWarrior) 21 file 시옷전사 2011.07.13 2605
553 온라인 RPGVX 3D스크립트 11 file 고자몬 2011.07.10 5049
552 스킬 스킬북으로 스킬 레벨업!, 'SW_BookSkill' by SiotWarrior(재수정) 21 file 시옷전사 2011.05.15 2817
551 키입력 한글입력기(펌) 수정 10 전설의달빛조각사 2011.04.03 2674
550 스킬 훔치기 스킬을 만드는 스크립트! 5 우켈킁 2011.03.31 2390
549 기타 KGC counter 스크립트. 반격기 추가스크립트입니다. 4 우켈킁 2011.03.31 1812
548 전투 VX SRPG 스크립트를 살짝 손대봤습니다. 13 아이미르 2011.03.31 3428
547 스킬 스킬 필요조건에 살짝 손대봤습니다. -- 수정 18 아이미르 2011.03.23 2499
546 전투 [덮어씌우기]Window_ActorCommand_EX 4 맛난호빵 2011.03.12 2341
545 이름입력 아이템, 장비, 스킬 이름 색깔 바꾸기 14 까까까 2011.03.04 3732
544 타이틀/게임오버 [NO.0 간단 스크립트] 타이틀에 제작자 정보 올려보기 14 file NO.0 2011.01.30 3362
» 상점 상점에서 아이템 분류 5 file 파이어 2011.01.23 3510
542 기타 IEX - Script Library 1.0 by IceDragon 8 Alkaid 2011.01.11 2619
541 타이틀/게임오버 KGC_TitleDirection 알기쉽게 설명추가 5 파이어 2011.01.03 2662
540 메시지 소설풍(노벨풍) 문자 스크립트 31 file 맛난호빵 2011.01.03 5551
539 상태/속성 MOG - Menu Status V 2.0 16 아방스 2011.01.01 3316
538 메시지 캐릭터 대화상자 - Character's Textbox ver 1.0 6 아방스 2010.12.17 6455
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ... 32 Next
/ 32