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 5408
297 폰 시스템 29 RPGbooster 2008.10.11 3454
296 직업 [직업 변경] TBK_JobChanger_Demo_v1.2 10 아방스 2009.02.05 3468
295 기타 범용 게이지 묘화 - KGC 14 file 카르와푸딩의아틀리에 2009.08.19 3476
294 파티 전투중 파티 변경 스크립트 21 아방스 2008.03.09 3477
293 온라인 VX Phoenix 온라인 스크립트 1.3버전 12 아방스 2009.06.18 3486
292 메뉴 Final Fantasy VII Menu System 8 비극ㆍ 2010.04.19 3506
291 메시지 MessageSound v2.0 글자에 소리 다다닥 스크립트 21 할렘 2009.02.02 3510
» 상점 상점에서 아이템 분류 5 file 파이어 2011.01.23 3510
289 새로운 종류의 세이브 스크립트!! 8 Man... 2008.10.28 3517
288 기타 Staff Roll 13 file 허걱 2009.01.31 3523
287 이동 및 탈것 A* 알고리즘을 이용한 길찾기 스크립트 3 file 허걱 2009.04.20 3531
286 기타 경험치, HP, MP 백분율계산 (실시간) 8 file 허걱 2009.08.01 3540
285 메뉴 지난 메뉴 스크립트에 이은 스테이터스 스크립트! 5 file 독사 2008.06.29 3545
284 기타 KGC패시브 스크립트 30 카르와푸딩의아틀리에 2009.10.07 3551
283 전투 XAS Hero Edition VX Manual 번역 1 케이언 2012.01.02 3558
282 기타 데이터베이스 자체 제한 해체 스크립트 [Database Limit Breaker] 13 file 할렘 2009.02.07 3562
281 기타 말풍선 그림 바꾸기 6 file 허걱 2009.08.15 3565
280 타이틀/게임오버 타이틀전 공지사항 19 file AYARSBMA 2010.01.23 3583
279 스킬장착 시스템 17 file RPGbooster 2008.10.11 3585
278 메시지 Display Flipped Picture 스크립트 11 Love♡ 2009.11.09 3585
Board Pagination Prev 1 ... 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ... 32 Next
/ 32