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 5399
357 타이틀/게임오버 륀느님 요청] 전투 전멸후 Game over없이 특정위치로 이동 10 Last H 2009.02.24 2834
356 장비 루시퍼님이올리신 rei의 보이는 장비 아주 조금 해석본 2 file 비류 2010.01.08 2184
355 기타 로딩중 스크립트 24 file NO.0 2009.07.11 4462
354 맵/타일 레이 월드맵 스크립트 14 file 카르와푸딩의아틀리에 2009.07.04 4813
353 레오 저장 스크립트 9 Man... 2008.10.28 2529
352 레벨업시 자세한 능력치화면 31 file RPGbooster 2008.10.08 4181
351 레벨업 할경우 hp/mp 등을 채워주는 스크립트 49 아방스 2008.09.09 4473
350 기타 레벨업 이펙트... 20 비극ㆍ 2010.04.19 3768
349 기타 레벨업 시 증가분의 HP/MP 회복 10 시트르산 2010.09.12 2427
348 메뉴 레벨업 시 자세한 정보 나오는 스크립트 23 아방스 2009.01.20 3895
347 아이템 레벨,능력치,아이템소지갯수,소지금의 한계돌파스크립트 21 file 이탁 2009.01.28 4547
346 타이틀/게임오버 랜덤 타이틀화면 8 file RPGbooster 2008.10.08 2832
345 기타 라이트 이펙트 스크립트 12 file 아방스 2009.02.07 3262
344 기타 땅파기 18 file 비극ㆍ 2010.04.19 3013
343 퀘스트 디아블로 스타일 퀘스트 시스템(번역) 38 file 훈덕 2009.02.03 6049
342 기타 디스크 체인져 VX!! (업데이트..) 30 file Tofuman 2008.12.02 3168
341 디러그 시스템?? 1 Man... 2008.10.28 1247
340 아이템 드롭 아이템 확장 6 신규회원 2012.02.24 2977
339 영상 동영상 재생 스크립트.-Game_Film II-(테스트) 7 할렘 2009.02.22 3741
338 액터 동료가 따라다니게 하는 스크립트 (Woratana's Caterpillar System) 5 MinaAubert 2012.09.13 3012
Board Pagination Prev 1 ... 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ... 32 Next
/ 32