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 키입력 마우스 시스템 Simple Mouse System (수정) 42 Incubus 2008.05.24 5693
556 HUD HUD HP / MP 게이지바 스크립트 29 file 아방스 2009.07.02 5677
555 타이틀/게임오버 타이틀 업그레이드 byMOG 16 *ps인간 2009.01.26 5658
554 전투 KGC]전투형태 오버드라이브(턴알) 13 찌나 2008.03.08 5656
553 ((대박!)) 게임상의 모든 글자에 효과 주기.. 33 미카엘 2008.08.20 5582
552 메시지 소설풍(노벨풍) 문자 스크립트 31 file 맛난호빵 2011.01.03 5551
551 타이틀/게임오버 맵 타이틀 스크립트 48 아방스 2009.06.17 5547
550 전투 카운트배틀 시스템(스크립트 한글살짝번역) 10 file 카르와푸딩의아틀리에 2009.06.17 5520
549 온라인 VX Phoenix 온라인 스크립트 Ver 1.5 36 아방스 2009.07.02 5509
548 퀘스트 [패치]오메가 퀘스트 시스템 확장판 v.1.1 72 file 레오 2010.09.25 5474
547 전투 RPG Tankentai SBS 3.3 Kaduki Eng 2 아방스 2009.02.05 5467
546 파티 최대 파티 늘리는 스크립트 59 file 아방스 2008.03.09 5431
545 스킬 스킬 사용시 컷인 연출 (번역) 26 file 훈덕 2009.02.05 5387
544 장비 [스크립트]무기에 옵션을 부가하자 18 아방이 2008.01.29 5380
543 메시지 여러항목 선택지 ... Scene처리.. 23 file 허걱 2009.02.14 5277
542 HUD 맵이름 띄우는 스크립트 입니다. 33 시에란 2008.08.16 5271
541 Side View CBS 사이드뷰배틀 블리치버젼 13 RPGbooster 2008.10.11 5232
540 상점 보관함 스크립트 43 file 허걱 2009.02.02 5161
539 VX 주석액알 PR코더즈의ABS보다 않좋다고생각할수있지만 더좋음 34 배군 2008.08.17 5145
538 Tankentai SBS 2.8 업데이트 [사이드뷰 배틀시스템 ] 42 file RPGbooster 2008.10.08 5140
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