code:
;-------------------------------------------------
; FLAG:調教モード =8 居住区関連ステータス描画モード
; いまいち用途が定まってない画面
;-------------------------------------------------
@HO_DRAW_STATUS_WINDOW
;UIコンテナの作成
VARI UIC_ID
CALL UIC_DISPOSE()
CALL UIC_INIT()
UIC_ID = RESULT

CALL HO_STATUS_WINDOW_SET_UIC(UIC_ID)
VARI CHARA_ID
CHARA_ID = MASTER

CALL HO_STATUS_WINDOW_SET_TARGET("LEFT_TOP")
IF RESULT != -1
    CALL HO_STATUS_WINDOW_SET_CONTAINTS(UIC_ID, "LEFT_TOP", RESULT)
ENDIF

CALL HO_STATUS_WINDOW_SET_TARGET("LEFT_BOTTOM")
IF RESULT != -1
    CALL HO_STATUS_WINDOW_SET_CONTAINTS(UIC_ID, "LEFT_BOTTOM", RESULT)
ENDIF

CALL UIC_SHOW(UIC_ID)
CALL HO_DRAW_INFO_WINDOW()
CALL NEWLINE(26)

@HO_STATUS_WINDOW_SET_CONTAINTS(UIC_ID, STR_PLACE = "LEFT_TOP", CHARA_ID)
#DIM  UIC_ID
#DIMS STR_PLACE
#DIM  CHARA_ID
#DIMS CONST PARAM_NAME1  = "快Ｃ", "快Ｖ", "快Ａ", "快Ｂ", "快Ｍ", "快Ｕ"
#DIMS CONST PARAM_NAME2  = "射精", "噴乳"

VARS TEXT
VARS HTML
HTML += @""
CALL UIC_SET_TEXT(UIC_ID, @"UIC_%STR_PLACE%_PORTRAIT", HTML)

VARI PARAMS
VARI BASE_VALUE
VARI MAX_VALUE
VARS PARAM_BAR
VARI BAR_LENGTH

;基礎情報
BAR_LENGTH = 16
TEXT '= @"%ANAME(CHARA_ID)%"
TEXT += @"@B:[STATUS_WINDOW:1][TARGET:%STR_PLACE%]@[変更]@/B@"
HTML '= @"%CONV_TAG2H(TEXT)%"
HTML += "
"
BASE_VALUE = BASE:CHARA_ID:体力
MAX_VALUE = MAXBASE:CHARA_ID:体力
PARAM_BAR =  体力:%FuncTagSetText_CreateColorBarText(BASE_VALUE, MAX_VALUE, BAR_LENGTH, カラー_パ赤, カラー_パ赤, カラー_ダークグレー, 1, "▂")%
HTML += @"%CONV_TAG2H(TAG_PRINT_SHAPE(PARAM_BAR, 40, 1, 0))%"
HTML += "
"
BASE_VALUE = BASE:CHARA_ID:気力
MAX_VALUE = MAXBASE:CHARA_ID:気力
PARAM_BAR =  気力:%FuncTagSetText_CreateColorBarText(BASE_VALUE, MAX_VALUE, BAR_LENGTH, カラー_パ緑, カラー_パ緑, カラー_ダークグレー, 1, "▂")%
HTML += @"%CONV_TAG2H(TAG_PRINT_SHAPE(PARAM_BAR, 40, 1, 0))%"
HTML += "
"
HTML += "
"

;PALAM系情報
TEXT '= ""
;機嫌
TEXT += "機嫌 "
TEXT += @"@C:{GETCOLOR_EMOTION(CHARA_ID)}@%TOSTR_EMOTION(CHARA_ID)%@/C@"
;潤滑
TEXT += " "
TEXT += @"潤滑Lv" + @"%STR_TAG_PARAM2(CHARA_ID, GETNUM(PALAM, "潤滑"))%"
;欲情
TEXT += " "
TEXT += @"欲情Lv" + @"%STR_TAG_PARAM2(CHARA_ID, GETNUM(PALAM, "欲情"))%"
IF TCVAR:(CHARA_ID):媚薬 > 0
    TEXT += " "
    TEXT += @"発情Lv" + @"@C:{カラー_ピンク}@%TOSTR(TCVAR:(CHARA_ID):媚薬, "#0")%@/C@"
ENDIF
IF CHARA_ID == MASTER
    ;絶頂抑制スタンス
    TEXT += " "
    TEXT += @"快楽の受容:@B:[STATUS_WINDOW:1][ORGASM_SURPRESS_STANCE:%STR_PLACE%][CHARA_ID:{CHARA_ID}]@[%ORGASM_SURPRESS_STANCE_STR(CFLAG:(CHARA_ID):絶頂抑制スタンス)%]@/B@"
ENDIF

HTML += CONV_TAG2H(TEXT)
HTML += "
"

;状態異常系
TEXT '= ""
SIF TCVAR:(CHARA_ID):離脱フラグ == 離脱フラグ_睡眠
    TEXT += TAG_PRINT_SHAPE("睡眠", 5, 1, 0)
SIF IS_EQUIP_PLAYER(CHARA_ID, T_N("ペニバン装着"))
    TEXT += TAG_PRINT_SHAPE("ﾍﾟﾆﾊﾞﾝ", 5, 1, 0)
SIF IS_EQUIP_PLAYER(CHARA_ID, T_N("コンドーム"))
    TEXT += TAG_PRINT_SHAPE("ゴム", 5, 1, 0)
SIF TCVAR:(CHARA_ID):利尿剤
    TEXT += TAG_PRINT_SHAPE("利尿", 5, 1, 0)
SIF TCVAR:(CHARA_ID):催眠中 > 0
    TEXT += TAG_PRINT_SHAPE("催眠", 5, 1, 0)

IF CFLAG:(CHARA_ID):避妊薬残ターン
    TEXT += TAG_PRINT_SHAPE("避妊", 5, 1, 0)
ELSE
    SIF IS_OVULATION(CHARA_ID) || CFLAG:(CHARA_ID):排卵誘発剤
        TEXT += TAG_PRINT_SHAPE(@"@C:{カラー_妊娠}@排卵@/C@", 5, 1, 0)
    SIF TALENT:(CHARA_ID):妊娠
        TEXT += TAG_PRINT_SHAPE(@"@C:{カラー_妊娠}@妊娠@/C@", 5, 1, 0)
ENDIF
HTML += CONV_TAG2H(TEXT)
HTML += "
"
TEXT '= ""

IF FLAG:ハウジングモード && !FLAG:クエストモード
    SIF IS_HUNGRY(CHARA_ID)
        TEXT += TAG_PRINT_SHAPE("空腹", 5, 1, 0)
    SIF IS_SWEAT(CHARA_ID)
        TEXT += TAG_PRINT_SHAPE("発汗", 5, 1, 0)
ENDIF

HTML += CONV_TAG2H(TEXT)
HTML += "
"

CALL UIC_SET_TEXT(UIC_ID, @"UIC_%STR_PLACE%_MAIN", HTML)

;快感系パラメータ1
BAR_LENGTH = 8
HTML '= ""
FOR PARAMS, 0, VARSIZE("PARAM_NAME1")
    BASE_VALUE = PALAM:CHARA_ID:(GETNUM(PALAM, PARAM_NAME1:PARAMS))
    IF BASE_VALUE <= 10000
        MAX_VALUE = 10000
    ELSE
        MAX_VALUE = 99999
    ENDIF
    IF BASE_VALUE <= 10000
        PARAM_BAR =  %PARAM_NAME1:PARAMS%:%FuncTagSetText_CreateColorBarText(BASE_VALUE, MAX_VALUE, BAR_LENGTH, カラー_パステルピンク, カラー_ピンク, カラー_ダークグレー, 0, "▂")%
    ELSE
        PARAM_BAR =  %PARAM_NAME1:PARAMS%:%FuncTagSetText_CreateColorBarText(BASE_VALUE, MAX_VALUE, BAR_LENGTH, カラー_黄, 0xFFFFFF, カラー_ピンク, 0, "▂")%
    ENDIF
    HTML += @"%CONV_TAG2H(TAG_PRINT_SHAPE(PARAM_BAR, 16, 1, 0))%"
    IF (PARAMS + 1) % 4 == 0
        HTML += "
"
    ENDIF
NEXT
HTML += "
"

;快感系パラメータ2
FOR PARAMS, 0, VARSIZE("PARAM_NAME2")
    BASE_VALUE = PALAM:CHARA_ID:(GETNUM(PALAM, PARAM_NAME2:PARAMS))
    SELECTCASE PARAM_NAME2:PARAMS
        CASE "射精"
            SIF !HAS_PENIS(CHARA_ID)
                CONTINUE
            PARAM_BAR =  %PARAM_NAME2:PARAMS%:%FuncTagSetText_CreateColorBarText(BASE_VALUE, MAX_VALUE, BAR_LENGTH, カラー_クリーム, カラー_クリーム, カラー_ダークグレー, 0, "▂")%
        CASE "噴乳"
            SIF !TALENT:CHARA_ID:母乳体質
                CONTINUE
            PARAM_BAR =  %PARAM_NAME2:PARAMS%:%FuncTagSetText_CreateColorBarText(BASE_VALUE, MAX_VALUE, BAR_LENGTH, カラー_白, カラー_白, カラー_ダークグレー, 0, "▂")%
        CASEELSE
            PARAM_BAR =  %PARAM_NAME2:PARAMS%:%FuncTagSetText_CreateColorBarText(BASE_VALUE, MAX_VALUE, BAR_LENGTH, カラー_パステルピンク, カラー_ピンク, カラー_ダークグレー, 0, "▂")%
    ENDSELECT
    HTML += @"%CONV_TAG2H(TAG_PRINT_SHAPE(PARAM_BAR, 16, 1, 0))%"
    IF (PARAMS + 1) % 2 == 0
        HTML += "
"
    ENDIF
NEXT

CALL UIC_SET_TEXT(UIC_ID, @"UIC_%STR_PLACE%_PARAMS", HTML)

@HO_STATUS_WINDOW_INPUT(INPUT_VALUES)
#DIMS INPUT_VALUES
#DIMS DYNAMIC VALUES
#DIM  DYNAMIC CHARA_ID

IF DIC_CONTAINSKEY(INPUT_VALUES, "TARGET")
    VALUES = %DIC_GET(INPUT_VALUES, "TARGET")%
    IF VALUES == "LEFT_TOP"
        CALL HO_STATUS_WINDOW_OPTION_POPUP("LEFT_TOP")
    ELSEIF VALUES == "LEFT_BOTTOM"
        CALL HO_STATUS_WINDOW_OPTION_POPUP("LEFT_BOTTOM")
    ENDIF
ELSEIF DIC_CONTAINSKEY(INPUT_VALUES, "ORGASM_SURPRESS_STANCE")
    VALUES = %DIC_GET(INPUT_VALUES, "ORGASM_SURPRESS_STANCE")%
    CHARA_ID = DIC_GETINT(INPUT_VALUES, "CHARA_ID")
    DEBUGPRINTFORML VALUES:%VALUES%
    IF VALUES == "LEFT_TOP"
        CALL HO_STATUS_WINDOW_OPTION_POPUP_ORGASM_SURPRESS_STANCE("LEFT_TOP", CHARA_ID)
    ELSEIF VALUES == "LEFT_BOTTOM"
        CALL HO_STATUS_WINDOW_OPTION_POPUP_ORGASM_SURPRESS_STANCE("LEFT_BOTTOM", CHARA_ID)
    ENDIF
ENDIF

@HO_STATUS_WINDOW_SET_UIC(UIC_ID)
#DIM UIC_ID
VARI WIDTH  = 4100
VARI HEIGHT = 2600
; CALL UIC_ADD(UIC_ID, "UIC_PARENT", "", @"[BORDER:0PX][SIZE:{WIDTH},{HEIGHT}]")
; CALL UIC_SET_LAYOUT(UIC_ID, "UIC_PARENT", "[TARGET:LINE_LEFT][ANCHOR:LEFT_TOP][TARGET_PIVOT:LEFT_TOP][PADDING:25,0]")
CALL UIC_ADD(UIC_ID, "UIC_LEFT", "", @"[BORDER:1PX][SIZE:{WIDTH - 50},{HEIGHT}]")
CALL UIC_SET_LAYOUT(UIC_ID, "UIC_LEFT", "[TARGET:UIC_PARENT][ANCHOR:LEFT_TOP][TARGET_PIVOT:LEFT_TOP][PADDING:25,0]")
CALL UIC_ADD(UIC_ID, "UIC_LEFT", "", @"[BORDER:1PX][SIZE:{WIDTH - 50},{HEIGHT}]")
CALL UIC_SET_LAYOUT(UIC_ID, "UIC_LEFT", "[TARGET:UIC_PARENT][ANCHOR:LEFT_TOP][TARGET_PIVOT:LEFT_TOP][PADDING:25,0]")

CALL UIC_ADD(UIC_ID, "UIC_LEFT_TOP", "", @"[BORDER:0PX][SIZE:{WIDTH - 50},{900}]")
CALL UIC_SET_LAYOUT(UIC_ID, "UIC_LEFT_TOP", "[TARGET:UIC_LEFT][ANCHOR:LEFT_TOP][TARGET_PIVOT:LEFT_TOP][PADDING:0,0]")
CALL UIC_ADD(UIC_ID, "UIC_LEFT_TOP_MAIN", "<button value = '[STATUS_WINDOW_TARGET:LEFT_TOP]'>[変更]</button>", @"[BORDER:0PX][SIZE:{WIDTH - 50 - 900},{900}]")
CALL UIC_SET_LAYOUT(UIC_ID, "UIC_LEFT_TOP_MAIN", "[TARGET:UIC_LEFT_TOP][ANCHOR:RIGHT_TOP][TARGET_PIVOT:RIGHT_TOP][PADDING:50,50]")
CALL UIC_ADD(UIC_ID, "UIC_LEFT_TOP_PARAMS", "", @"[BORDER:1PX][SIZE:{WIDTH - 50},{HEIGHT / 2 - 900}]")
CALL UIC_SET_LAYOUT(UIC_ID, "UIC_LEFT_TOP_PARAMS", "[TARGET:UIC_LEFT_TOP][ANCHOR:LEFT_TOP][TARGET_PIVOT:LEFT_BOTTOM][PADDING:0,0]")
CALL UIC_ADD(UIC_ID, "UIC_LEFT_TOP_PORTRAIT", "", @"[BORDER:1PX][SIZE:{800},{800}]")
CALL UIC_SET_LAYOUT(UIC_ID, "UIC_LEFT_TOP_PORTRAIT", "[TARGET:UIC_LEFT_TOP][ANCHOR:LEFT_TOP][TARGET_PIVOT:LEFT_TOP][PADDING:50,50]")

CALL UIC_ADD(UIC_ID, "UIC_LEFT_BOTTOM", "", @"[BORDER:0PX][SIZE:{WIDTH - 50},{900}]")
CALL UIC_SET_LAYOUT(UIC_ID, "UIC_LEFT_BOTTOM", "[TARGET:UIC_LEFT_TOP_PARAMS][ANCHOR:LEFT_TOP][TARGET_PIVOT:LEFT_BOTTOM][PADDING:0,0]")
CALL UIC_ADD(UIC_ID, "UIC_LEFT_BOTTOM_MAIN", "<button value = '[STATUS_WINDOW_TARGET:LEFT_BOTTOM]'>[変更]</button>", @"[BORDER:0PX][SIZE:{WIDTH - 50 - 900},{900}]")
CALL UIC_SET_LAYOUT(UIC_ID, "UIC_LEFT_BOTTOM_MAIN", "[TARGET:UIC_LEFT_BOTTOM][ANCHOR:RIGHT_TOP][TARGET_PIVOT:RIGHT_TOP][PADDING:50,50]")
CALL UIC_ADD(UIC_ID, "UIC_LEFT_BOTTOM_PARAMS", "", @"[BORDER:1PX][SIZE:{WIDTH - 50},{HEIGHT / 2 - 900}]")
CALL UIC_SET_LAYOUT(UIC_ID, "UIC_LEFT_BOTTOM_PARAMS", "[TARGET:UIC_LEFT_BOTTOM][ANCHOR:LEFT_TOP][TARGET_PIVOT:LEFT_BOTTOM][PADDING:0,0]")
CALL UIC_ADD(UIC_ID, "UIC_LEFT_BOTTOM_PORTRAIT", "", @"[BORDER:1PX][SIZE:{800},{800}]")
CALL UIC_SET_LAYOUT(UIC_ID, "UIC_LEFT_BOTTOM_PORTRAIT", "[TARGET:UIC_LEFT_BOTTOM][ANCHOR:LEFT_TOP][TARGET_PIVOT:LEFT_TOP][PADDING:50,50]")

;;; ステータス表示対象の選択画面
@HO_STATUS_WINDOW_OPTION_POPUP(STR_PLACE = "LEFT_TOP")
#DIMS STR_PLACE
#DIMS CURRENT_TARGET
#DIMS DYNAMIC ATR
#DIMS DYNAMIC BODY
#DIMS DYNAMIC HTML

IF STR_PLACE == "LEFT_TOP"
    CURRENT_TARGET = %HO_STATUS_WINDOW_TARGET_TOP%
ELSEIF STR_PLACE == "LEFT_BOTTOM"
    CURRENT_TARGET = %HO_STATUS_WINDOW_TARGET_BOTTOM%
ENDIF

VARI CHARA_ID
BODY += @""
IF FLAG:クエストモード
    BODY += @"<button value = '[TARGET:MASTER]'>[リーダーに固定]</button>"
ELSE
    BODY += @"<button value = '[TARGET:MASTER]'>[主人公に固定]</button>"
ENDIF
BODY += @"
"
BODY += @""
BODY += @"<button value = '[TARGET:PLAYER]'>[コマンド実行者に固定]</button>"
BODY += @"
"
BODY += @""
BODY += @"<button value = '[TARGET:TARGET]'>[コマンド対象に固定]</button>"
BODY += @"
"
FOR CHARA_ID, 0, CHARANUM
    SIF CHARA_ID == MASTER || !CFLAG:CHARA_ID:調教参加フラグ
        CONTINUE
    BODY += @""
    BODY += @"<button value = '[TARGET:{CHARA_ID}]'>[%ANAME(CHARA_ID)%に固定]</button>"
    BODY += @"
"
NEXT
BODY += @"
"
BODY += @"<button value = '[EXIT:1]'>[閉じる]</button>"
BODY += @"

"
ATR += @"
"

HTML = %ATR + BODY + "
"%
CLEARLINE 2
HTML_PRINT HTML, 1

WHILE 1
    INPUTS ,1
    VARS INPUT_VALUES
    VARI MOUSE_BTN = RESULT:1
    INPUT_VALUES = %RESULTS%

    IF INPUT_VALUES != ""
        CLEARLINE 1
    ELSE
        BREAK
    ENDIF
    ;クリック時処理
    IF MOUSE_BTN == 1
        IF DIC_CONTAINSKEY(INPUT_VALUES, "TARGET")
            CLEARLINE 1
            IF STR_PLACE == "LEFT_TOP"
                HO_STATUS_WINDOW_TARGET_TOP = %DIC_GET(INPUT_VALUES, "TARGET")%
            ELSEIF STR_PLACE == "LEFT_BOTTOM"
                HO_STATUS_WINDOW_TARGET_BOTTOM = %DIC_GET(INPUT_VALUES, "TARGET")%
            ENDIF
            RETURN DIC_GETINT(INPUT_VALUES, "OPTION")
            BREAK
        ENDIF
        IF DIC_CONTAINSKEY(INPUT_VALUES, "EXIT")
            CLEARLINE 1
            BREAK
        ENDIF
        ;右クリック時処理
    ELSEIF MOUSE_BTN == 2
        CLEARLINE 1
        BREAK
    ENDIF
WEND

RETURN -1

@HO_STATUS_WINDOW_SET_TARGET(STR_PLACE = "LEFT_TOP")
#DIMS STR_PLACE
#DIMS DYNAMIC TARGET_OPTION
#DIM  DYNAMIC CHARA_ID
TARGET_OPTION '= STR_PLACE == "LEFT_TOP" ? @"%HO_STATUS_WINDOW_TARGET_TOP%" # @"%HO_STATUS_WINDOW_TARGET_BOTTOM%"
CHARA_ID = -1
SELECTCASE TARGET_OPTION
    CASE "MASTER"
        CHARA_ID = FLAG:クエストモード ? QST_LEADER_ID() # MASTER
    CASE "PLAYER"
        CHARA_ID = MPLY
    CASE "TARGET"
        CHARA_ID = MTAR
    CASE ""
        IF STR_PLACE == "LEFT_TOP"
            CHARA_ID = FLAG:クエストモード ? QST_LEADER_ID() # MASTER
        ELSE
            CHARA_ID = MTAR != -1 ? MTAR # -1
        ENDIF
    CASEELSE
        IF ISNUMERIC(TARGET_OPTION)
            CHARA_ID = TOINT(TARGET_OPTION)
            IF !CFLAG:CHARA_ID:調教参加フラグ
                CHARA_ID = -1
            ENDIF
        ENDIF
ENDSELECT
RETURN CHARA_ID

;;; 快楽の受容スタンスの選択画面
@HO_STATUS_WINDOW_OPTION_POPUP_ORGASM_SURPRESS_STANCE(STR_PLACE = "LEFT_TOP", CHARA_ID)
#DIMS STR_PLACE
#DIM  CHARA_ID
#DIMS CURRENT_TARGET
#DIMS DYNAMIC ATR
#DIMS DYNAMIC BODY
#DIMS DYNAMIC HTML

VARI IDX
BODY += @"◇絶頂の快楽にどう接しますか？"
BODY += @"
"
FOR IDX, 0, VARSIZE("ORGASM_SURPRESS_STANCE_VALUE")
    BODY += @""
    BODY += @"<button value = '[STANCE:{ORGASM_SURPRESS_STANCE_VALUE:IDX}]' title = '%ORGASM_SURPRESS_STANCE_TOOLTIP:IDX%'>[%ORGASM_SURPRESS_STANCE_STR(ORGASM_SURPRESS_STANCE_VALUE:IDX)%]</button>"
    BODY += @"
"
NEXT
BODY += @"
"
BODY += @"<button value = '[EXIT:1]'>[閉じる]</button>"
BODY += @"

"
ATR += @"
"

HTML = %ATR + BODY + "
"%
CLEARLINE 2
HTML_PRINT HTML, 1

WHILE 1
    INPUTS ,1
    VARS INPUT_VALUES
    VARI MOUSE_BTN = RESULT:1
    INPUT_VALUES = %RESULTS%

    IF INPUT_VALUES != ""
        CLEARLINE 1
    ELSE
        BREAK
    ENDIF
    ;クリック時処理
    IF MOUSE_BTN == 1
        IF DIC_CONTAINSKEY(INPUT_VALUES, "STANCE")
            CLEARLINE 1
            CFLAG:CHARA_ID:絶頂抑制スタンス = TOINT(DIC_GET(INPUT_VALUES, "STANCE"))
            BREAK
        ENDIF
        IF DIC_CONTAINSKEY(INPUT_VALUES, "EXIT")
            CLEARLINE 1
            BREAK
        ENDIF
        ;右クリック時処理
    ELSEIF MOUSE_BTN == 2
        CLEARLINE 1
        BREAK
    ENDIF
WEND

RETURN -1


code:
;-------------------------------------------------
;ゲストモブの買い物処理
;@HO_CHARAACT_ACTION_PROGRESS から呼ばれる
;顧客による選好とか需要みたいな要素を導入したいところ。。。
;FORCE_BUYに1を立てると販売判定を実施せずに購入処理にうつる
;-------------------------------------------------
; #region
@HO_GUEST_TRADE_ITEM(CHARA_ID, SHOPPER_ID = -1, FORCE_BUY = 0)
#DIM  CHARA_ID
#DIM  SHOPPER_ID
#DIM  FORCE_BUY
#DIMS DYNAMIC _LIST_ITEM
#DIMS DYNAMIC _LIST_CHARA
#DIM  DYNAMIC BUY_ITEM_ID
#DIMS DYNAMIC BUY_ITEM_NAME
#DIM  DYNAMIC BUY_ITEM_NUM
#DIM  DYNAMIC BUY_ITEM_PRICE
#DIM  DYNAMIC PROFIT
#DIM  DYNAMIC SHOPPER_SEDUCTION_LV

BUY_ITEM_ID = -1

;店番中のキャラがいる
CALL HO_FIND_CHARA("ACTION", "店番中")
_LIST_CHARA = %RESULTS%
IF !LIST_COUNT(_LIST_CHARA)
    ;MASTERが店頭に立っていれば販売可能とみなす
    CALL HO_CHECK_USE_MODULE_USAGE(MASTER, "商店")
    SIF !RESULT
        RETURN 0
    _LIST_CHARA = %LIST_ADD(_LIST_CHARA, TOSTR(MASTER))%
ENDIF

;店番中のキャラの中からランダムで販売担当を選出
IF SHOPPER_ID == -1
    SHOPPER_ID = TOINT(LIST_RAND(_LIST_CHARA))
ENDIF
CALL SKILL_GET_LEVEL(SHOPPER_ID, スキル_大分類_性技, "SEDUCTION")
SHOPPER_SEDUCTION_LV = RESULT

;キャラクターに購入の意思がある
SIF RAND:100 >= CFLAG:CHARA_ID:キャラ購買意欲 && !FORCE_BUY
    RETURN 0
IF RAND:2
    CALL HO_GUEST_BUY_ITEM(CHARA_ID, SHOPPER_ID, FORCE_BUY)
    SIF RESULT
        RETURN RESULT
    CALL HO_GUEST_BUY_EQUIP(CHARA_ID, SHOPPER_ID, FORCE_BUY)
    RETURN RESULT
ELSE
    CALL HO_GUEST_BUY_EQUIP(CHARA_ID, SHOPPER_ID, FORCE_BUY)
    SIF RESULT
        RETURN RESULT
    CALL HO_GUEST_BUY_ITEM(CHARA_ID, SHOPPER_ID, FORCE_BUY)
    RETURN RESULT
ENDIF
; #endregion

;-------------------------------------------------
; アイテムの購入処理
;-------------------------------------------------
; #region
@HO_GUEST_BUY_ITEM(CHARA_ID, SHOPPER_ID = -1, FORCE_BUY = 0)
#DIM  CHARA_ID
#DIM  SHOPPER_ID
#DIM  FORCE_BUY
#DIMS DYNAMIC _LIST_ITEM
#DIMS DYNAMIC _LIST_CHARA
#DIM  DYNAMIC BUY_ITEM_ID
#DIMS DYNAMIC BUY_ITEM_NAME
#DIM  DYNAMIC BUY_ITEM_NUM
#DIM  DYNAMIC BUY_ITEM_PRICE
#DIM  DYNAMIC PROFIT
#DIM  DYNAMIC SHOPPER_SEDUCTION_LV

;購入アイテム候補をリスト化
FOR LOCAL, 0, ITEM_LENGTH
    IF HO_ITEM_TRADE_STOCK:LOCAL > 0
        _LIST_ITEM = %LIST_ADD(_LIST_ITEM, TOSTR(LOCAL))%
    ENDIF
NEXT
SIF !LIST_COUNT(_LIST_ITEM)
    RETURN 0

;;購入アイテムを決定(今はランダムに選出)
;5回抽選を試みる
FOR LOCAL, 0, 5
    BUY_ITEM_ID = TOINT(LIST_RAND(_LIST_ITEM))
    CALL GET_ITEM_INFO(BUY_ITEM_ID, ITEM_PRICE)
    BUY_ITEM_PRICE = RESULT
    IF BUY_ITEM_PRICE < CFLAG:CHARA_ID:キャラ消費金額
        BREAK
    ELSE
        ;単価が高すぎて変えない場合は購入候補から外して再抽選
        _LIST_ITEM = %LIST_REMOVEALL(_LIST_ITEM, TOSTR(BUY_ITEM_ID))%
        SIF !LIST_COUNT(_LIST_ITEM)
            RETURN 0
    ENDIF
NEXT
SIF BUY_ITEM_ID < 0
    RETURN 0

;購入量の決定
BUY_ITEM_NUM = 1
FOR LOCAL, 0, 4
    SIF !RAND:3
        BREAK
    IF BUY_ITEM_PRICE * (BUY_ITEM_NUM + 1) < CFLAG:CHARA_ID:キャラ消費金額
        BUY_ITEM_NUM ++
    ELSE
        BREAK
    ENDIF
NEXT

SIF HO_ITEM_TRADE_STOCK:BUY_ITEM_ID < BUY_ITEM_NUM
    BUY_ITEM_NUM = HO_ITEM_TRADE_STOCK:BUY_ITEM_ID

;販売処理
CALL GET_ITEM_NAME(BUY_ITEM_ID)
BUY_ITEM_NAME = %RESULTS%
;MEMO:将来的に売上計算式は店番のステータスやスキルで補正したい
PROFIT = BUY_ITEM_PRICE * BUY_ITEM_NUM
CFLAG:CHARA_ID:キャラ消費金額 -= PROFIT
HO_ITEM_TRADE_STOCK:BUY_ITEM_ID -= BUY_ITEM_NUM
;購入に成功した場合キャラ購買意欲を減衰させる
CFLAG:CHARA_ID:キャラ購買意欲 = MAX(0, CFLAG:CHARA_ID:キャラ購買意欲 - RAND(10, 30))
;購入イベント後のスキル処理・経験値・評判処理
CALL HO_TRADE_AFTER_PURCHASE_PROCESS(SHOPPER_ID, PROFIT)
PROFIT = RESULT

;ログ出力
IF SHOPPER_ID == MASTER
    CALL FL_PLAYSE("Money_0.mp3")
    CALLF TAG_PRINT(@"%ANAME(SHOPPER_ID)%は%ANAME(CHARA_ID)%に@C:{カラー_注意}@%BUY_ITEM_NAME%@/C@を{BUY_ITEM_NUM}個売却し@C:{カラー_緑}@%TOSTR(PROFIT, "###,###")%@/C@ディナリを得た", 1)
    WAIT
ENDIF
CALL HO_PRINT_LOG(@"%ANAME(SHOPPER_ID)%は@C:{カラー_注意}@%BUY_ITEM_NAME%@/C@を{BUY_ITEM_NUM}個売却し@C:{カラー_緑}@%TOSTR(PROFIT, "###,###")%@/C@ディナリを得た")

RETURN 1
; #endregion

;-------------------------------------------------
; 装備の購入処理
;-------------------------------------------------
; #region
@HO_GUEST_BUY_EQUIP(CHARA_ID, SHOPPER_ID = -1, FORCE_BUY = 0)
#DIM  CHARA_ID
#DIM  SHOPPER_ID
#DIM  FORCE_BUY
#DIMS DYNAMIC _LIST_ITEM
#DIMS DYNAMIC _LIST_CHARA
#DIM  DYNAMIC BUY_ITEM_DID
#DIMS DYNAMIC BUY_ITEM_NAME
#DIM  DYNAMIC BUY_ITEM_NUM
#DIM  DYNAMIC BUY_ITEM_PRICE
#DIM  DYNAMIC PROFIT
#DIM  DYNAMIC SHOPPER_SEDUCTION_LV
#DIM  DYNAMIC EQUIP_IDX, WPN_MAX_WEAPON_STOCK

BUY_ITEM_NUM = DT_SELECT("WEAPON_STOCK","ON_SALE_FLAG = 1",, EQUIP_IDX)
SIF !BUY_ITEM_NUM
    RETURN 0
;購入アイテム候補をリスト化
FOR LOCAL, 0, BUY_ITEM_NUM
    ;購入アイテム候補がリストの上限を超える場合は追加を打ち切る
    SIF LOCAL == _LIST_MAX - 1
        BREAK
    _LIST_ITEM = %LIST_ADD(_LIST_ITEM, TOSTR(EQUIP_IDX:LOCAL))%
NEXT

;;購入アイテムを決定(今はランダムに選出)
;3回抽選を試みる
FOR LOCAL, 0, 3
    BUY_ITEM_DID = TOINT(LIST_RAND(_LIST_ITEM))
    BUY_ITEM_PRICE = DT_CELL_GET("WEAPON_STOCK", BUY_ITEM_DID, "PRICE", 1)
    IF BUY_ITEM_PRICE < CFLAG:CHARA_ID:キャラ消費金額
        BREAK
    ELSE
        ;単価が高すぎて変えない場合は購入候補から外して再抽選
        _LIST_ITEM = %LIST_REMOVEALL(_LIST_ITEM, TOSTR(BUY_ITEM_DID))%
        SIF !LIST_COUNT(_LIST_ITEM)
            RETURN 0
    ENDIF
NEXT
;全て購入候補対象外
SIF BUY_ITEM_DID < 0
    RETURN 0

;販売処理
CALL GET_WEAPON_PRINT_NAME(BUY_ITEM_DID)
BUY_ITEM_NAME = %RESULTS%
;MEMO:将来的に売上計算式は店番のステータスやスキルで補正したい
PROFIT = BUY_ITEM_PRICE
CFLAG:CHARA_ID:キャラ消費金額 -= PROFIT
DT_ROW_REMOVE "WEAPON_STOCK", BUY_ITEM_DID
;購入に成功した場合キャラ購買意欲を減衰させる
CFLAG:CHARA_ID:キャラ購買意欲 = MAX(0, CFLAG:CHARA_ID:キャラ購買意欲 - RAND(10, 30))
;購入イベント後のスキル処理・経験値・評判処理
CALL HO_TRADE_AFTER_PURCHASE_PROCESS(SHOPPER_ID, PROFIT)
PROFIT = RESULT

;ログ出力
IF SHOPPER_ID == MASTER
    CALL FL_PLAYSE("Money_0.mp3")
    CALLF TAG_PRINT(@"%ANAME(SHOPPER_ID)%は%ANAME(CHARA_ID)%に@C:{カラー_注意}@%BUY_ITEM_NAME%@/C@を売却し@C:{カラー_緑}@%TOSTR(PROFIT, "###,###")%@/C@ディナリを得た", 1)
    WAIT
ENDIF
CALL HO_PRINT_LOG(@"%ANAME(SHOPPER_ID)%は@C:{カラー_注意}@%BUY_ITEM_NAME%@/C@を売却し@C:{カラー_緑}@%TOSTR(PROFIT, "###,###")%@/C@ディナリを得た")

RETURN 1
; #endregion

;-------------------------------------------------
; 購入後処理
;-------------------------------------------------
; #region
@HO_TRADE_AFTER_PURCHASE_PROCESS(SHOPPER_ID, PROFIT)
#DIM  SHOPPER_ID
#DIM  PROFIT
#DIM  DYNAMIC CHARA_ID
#DIM  DYNAMIC SKILL_LV
#DIM  DYNAMIC K4_UNIQUE_SKILL_FLAG
#DIM  DYNAMIC BASE_EXP = 3

;オリヴィアのユニークスキル所持判定
;このスキルはオリヴィアが店番に立っていれば誰が販売担当でも恩恵を受ける
CHARA_ID = NAME_TO_CHARA("UC_オリヴィア")
CALL HO_GET_CHARAACT(CHARA_ID)
IF RESULTS == "店番中" && HAS_SKILL(CHARA_ID, "K4_UNIQUE_SKILL_ADDITIONAL_BENEFIT", スキル_大分類_生活)
    K4_UNIQUE_SKILL_FLAG = 1
ELSE
    K4_UNIQUE_SKILL_FLAG = 0
ENDIF

;販売担当者のスキル処理
SKILL_LV = HAS_SKILL(SHOPPER_ID, "SKILL_ADDITIONAL_BENEFIT", スキル_大分類_生活)
IF SKILL_LV
    CALL SKILL_GET_EFFECT_RATE(スキル_ジャンル_生活, "SKILL_ADDITIONAL_BENEFIT",SKILL_LV)
    PROFIT = FTIMES(PROFIT, 100 + RESULT)
ENDIF

;オリヴィアのユニークスキル補正
IF K4_UNIQUE_SKILL_FLAG
    PROFIT = FTIMES(PROFIT, 125)
ENDIF

;資金の増加
MONEY += PROFIT

;社交経験値の獲得
BASE_EXP += INRANGE(PROFIT / 2000, 1, 5)
CALL HO_CHARAACT_ABLUP(SHOPPER_ID, "社交", BASE_EXP)

;領地評判の上昇
領地評判_商業_増減値 += INRANGE(PROFIT / 500, 1, 20)

;オリヴィアのユニークスキル補正
IF K4_UNIQUE_SKILL_FLAG
    領地評判_商業_増減値 = FTIMES(領地評判_商業_増減値, 125)
ENDIF

RETURN PROFIT

; #endregion

;-------------------------------------------------
; ゲスト生成処理
;店番中のキャラが居るなら商店のあるルームに買い物客ゲストの生成を試みる
;-------------------------------------------------
; #region
@HO_CREATE_GUEST_SHOPPER
#DIMS DYNAMIC _LIST_CHARA
#DIM  DYNAMIC ROOM_IDX
#DIM  DYNAMIC CHARA_ID
#DIM  DYNAMIC SHOPPER_ID

;買物目的のモブ生成は8:30～17:30時まで
SIF !INRANGE(HO_TIME, HO_CLOCK(830), HO_CLOCK(1730))
    RETURN 0

CALL HO_FIND_CHARA("ACTION", "店番中")
IF !RESULT
    CALL HO_CHECK_USE_MODULE_USAGE(MASTER, "商店")
    IF RESULT
        _LIST_CHARA = %LIST_ADD(_LIST_CHARA, TOSTR(MASTER))%
    ELSE
        RETURN 0
    ENDIF
ELSE
    _LIST_CHARA = %RESULTS%
ENDIF
SHOPPER_ID = TOINT(LIST_GET(_LIST_CHARA, 0))
IF SHOPPER_ID != MASTER
    CALL HO_GET_CHARAPLACE(SHOPPER_ID)
    ROOM_IDX = RESULT
ELSE
    ROOM_IDX = HO_MASTER現在地
ENDIF

;;ユニークキャラクターのゲスト判定
;オリヴィアのゲスト判定
CHARA_ID = NAME_TO_CHARA("UC_オリヴィア")
;オリヴィアの出現条件を満たしている
IF K4_DFLAG_行商人オリヴィア && CFLAG:CHARA_ID:所属 != 所属_プレイヤー
    ;まだオリヴィアが領内活動に参加していない
    IF HO_GET_CHARAIDXF(CHARA_ID) == -1 && !TCVAR:CHARA_ID:2500 && RAND:100 < 60
        CALL HO_CREATE_UNIQUE_GUEST(CHARA_ID, ROOM_IDX, "買物客")
        CALL HO_PRINT_LOG(@"@C:{カラー_緑}@%ANAME(CHARA_ID)%が買い物にやって来た@/C@")
        CFLAG:CHARA_ID:キャラ消費金額 = RAND(24, 48) * 400
        CFLAG:CHARA_ID:キャラ購買意欲 = RAND(40, 64)
        CFLAG:CHARA_ID:キャラ滞在時間 = RAND(48, 64) * HO_単位時間
        CFLAG:CHARA_ID:ゲストモブ = 1
        ;オリヴィアの来店済みフラグ(TCVARのキャラ自由枠を使用)
        TCVAR:CHARA_ID:2500 = 1
        ;オリヴィアの商店在庫を設定
        CALL CREATE_GUEST_SET_SHOP_STOCK(CHARA_ID)
        RETURN 1
    ENDIF
ENDIF

;モブ生成判定
CALL HO_CREATE_GUEST(ROOM_IDX, "買物客", "買物客", RAND:100 < FLCONFIG:買物ゲストの男性率 ? 0 # 1)
IF RESULT
    CHARA_ID = RESULT
    CALL HO_PRINT_LOG(@"@C:{カラー_緑}@%ANAME(CHARA_ID)%が買い物にやって来た@/C@")
    ;買い物目的のゲストは3-4時間滞在する
    CFLAG:CHARA_ID:キャラ滞在時間 = RAND(36, 42) * HO_単位時間
    IF IS_FEMALE(CHARA_ID)
        CFLAG:CHARA_ID:汎用口上パターン = 1000
    ENDIF
    RETURN 1
ENDIF

RETURN 0
; #endregion

;-------------------------------------------------
; コマンド:購入から呼び出されるゲスト商店
;-------------------------------------------------
@HO_SHOP_MANAGE_SHOP_GUEST_SHOP(DICS_SHOP_STOCK)
#DIMS REF DICS_SHOP_STOCK
FOR LOCAL, 0, MAX_SHOP_STOCKNUM
    DICS_SHOP_STOCK:LOCAL = %DICS_GUEST_SHOP_STOCK:(MTAR:0):LOCAL%
NEXT

repo_name: napo/erafl

license: unknown


code:
;-------------------------------------------------
; 交易画面
;-------------------------------------------------
@HO_TRADE_MENU()
#DIM DYNAMIC LINE_NUM
LINE_NUM = LINECOUNT
HO_TRADE_PAGE_RIGHT = 0
HO_TRADE_PAGE_LEFT = 0

WHILE 1
    LINE_NUM = LINECOUNT
    CALL HO_DRAW_TRADE_WINDOW
    REDRAW 1
    CALL HO_TRADE_WINDOW_INPUT()
    REDRAW 0
    IF RESULT == -1
        CLEARLINE LINECOUNT - LINE_NUM
        RETURN -1
    ENDIF
    CLEARLINE LINECOUNT - LINE_NUM
WEND

@HO_DRAW_TRADE_WINDOW
CALL WndMgr_DestroyWindow(-1)
CALL HO_DRAW_TRADE_WINDOW_PARENT
IF HO_TRADE_CATEGORY == 0
    CALL HO_DRAW_TRADE_WINDOW_LEFT
    CALL HO_DRAW_TRADE_WINDOW_RIGHT
ELSE
    CALL HO_DRAW_TRADE_EQUIP_WINDOW_LEFT
    CALL HO_DRAW_TRADE_EQUIP_WINDOW_RIGHT
ENDIF
CALL WndMgr_DisplayAll()

;-------------------------------------------------
; 親ウィンドウ
;-------------------------------------------------
@HO_DRAW_TRADE_WINDOW_PARENT
#DIM CONST WINDOW_ID = 0
#DIM CONST WND_WIDTH  = 170
#DIM CONST WND_HEIGHT = 44
#DIM DYNAMIC L_CNT
#DIM BTN_ID

BTN_ID = HO_交易ボタンID

CALL WndMgr_CreateWindow(WINDOW_ID, 0, 1, WND_WIDTH, WND_HEIGHT, 2)
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@◇交易品管理◇@/C@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

CALL WndMgr_TextSet(WINDOW_ID, L_CNT, @"@C:{カラー_注釈}@移動量:@/C@")
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"@B:{BTN_ID + 0}@@C:{HO_TRADE_TRANSFER_SWITCH == 0 ? カラー_選択中 # カラー_注釈}@ [1] @/C@@/B@")
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"@B:{BTN_ID + 1}@@C:{HO_TRADE_TRANSFER_SWITCH == 1 ? カラー_選択中 # カラー_注釈}@ [5] @/C@@/B@")
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"@B:{BTN_ID + 2}@@C:{HO_TRADE_TRANSFER_SWITCH == 2 ? カラー_選択中 # カラー_注釈}@ [10] @/C@@/B@")
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"@B:{BTN_ID + 3}@@C:{HO_TRADE_TRANSFER_SWITCH == 3 ? カラー_選択中 # カラー_注釈}@ [100] @/C@@/B@")
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"@B:{BTN_ID + 4}@@C:{HO_TRADE_TRANSFER_SWITCH == 4 ? カラー_選択中 # カラー_注釈}@ [1000] @/C@@/B@")
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"@B:{BTN_ID + 9}@@C:{HO_TRADE_TRANSFER_SWITCH == 9 ? カラー_選択中 # カラー_注釈}@ [ALL] @/C@@/B@")

CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"@C:{カラー_注釈}@　　　カテゴリー:@/C@")
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"@B:[CATEGORY:0]@@C:{HO_TRADE_CATEGORY == 0 ? カラー_選択中 # カラー_注釈}@　[アイテム]@/C@@/B@")
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"@B:[CATEGORY:1]@@C:{HO_TRADE_CATEGORY == 1 ? カラー_選択中 # カラー_注釈}@　[武器]@/C@@/B@")
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"@B:[CATEGORY:2]@@C:{HO_TRADE_CATEGORY == 2 ? カラー_選択中 # カラー_注釈}@　[レリック] @/C@@/B@")

L_CNT ++
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

;フッター出力
;-------------------------------------------------
L_CNT = WND_HEIGHT - 4
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@B:[EXIT:9999]@@C:{カラー_白}@[戻る]@/C@@/B@")

RETURN

;-------------------------------------------------
; アイテム用の在庫・販売管理メニュー
;-------------------------------------------------
; #region
@HO_DRAW_TRADE_WINDOW_LEFT
#DIM CONST WINDOW_ID = 1
#DIM CONST WND_WIDTH  = 82
#DIM CONST WND_HEIGHT = 36
#DIM CONST ヘッダー行数 = 2
#DIM CONST アイテムリスト行数 = 30
#DIMS DYNAMIC DETAIL_LIST, ITEM_LENGTH
#DIM DYNAMIC ITEM_NUM
#DIM DYNAMIC L_CNT
#DIM DYNAMIC BTN_ID
#DIM DYNAMIC PAGE_NUM
#DIMS DYNAMIC STR_FOOTER
#DIM DYNAMIC DETAIL_LINECOUNT

BTN_ID = HO_交易ボタンID + 10000

CALL HO_TRADE_COUNT_PAGE_NUM(HO_ITEM_STOCK, アイテムリスト行数)
PAGE_NUM = RESULT

;ウィンドウ作成
CALL WndMgr_CreateWindow(WINDOW_ID, 2, 6, WND_WIDTH, WND_HEIGHT, 2)
CALL WndMgr_Attribute(WINDOW_ID, "BorderColor", カラー_選択不可)

;ヘッダー
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@◇備蓄◇@/C@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

;明細リスト作成
DETAIL_LINECOUNT = 0
FOR LOCAL, 0, ITEM_LENGTH
    ITEM_NUM = HO_ITEM_STOCK:LOCAL
    CALL GET_ITEM_INFO(LOCAL, ITEM_CANNOT_SELL)
    SIF RESULT
        CONTINUE
    IF ITEM_NUM > 0
        CALL HO_TRADE_PRINT_STOCK_DETAIL(HO_ITEM_STOCK, LOCAL)
        DETAIL_LIST:DETAIL_LINECOUNT '= @"@B:{BTN_ID + LOCAL}@%RESULTS%@/B@"
        DETAIL_LINECOUNT ++
    ENDIF
NEXT

;明細リスト出力
L_CNT = 0
FOR LOCAL, アイテムリスト行数 * HO_TRADE_PAGE_LEFT, アイテムリスト行数 * (HO_TRADE_PAGE_LEFT + 1)
    IF  L_CNT / アイテムリスト行数 <= 0
        CALL WndMgr_TextSet(WINDOW_ID, L_CNT + ヘッダー行数, DETAIL_LIST:LOCAL)
        L_CNT++
    ELSE
        CALL WndMgr_TextAdd(WINDOW_ID, (L_CNT % アイテムリスト行数) + ヘッダー行数, DETAIL_LIST:LOCAL)
        L_CNT ++
    ENDIF
    L_CNT ++
NEXT

;フッター
IF PAGE_NUM > 0
    STR_FOOTER += HO_TRADE_PAGE_LEFT > 0 ? @"@B:{BTN_ID + 9000}@<<@/B@ " # "   "
    STR_FOOTER += @"%TOSTR(HO_TRADE_PAGE_LEFT + 1, "..")% "
    STR_FOOTER += HO_TRADE_PAGE_LEFT != PAGE_NUM ? @"@B:{BTN_ID + 9001}@>>@/B@" # "  "
    CALLF TAG_PRINT_SHAPE(STR_FOOTER, WND_WIDTH - 8, 1, 2)
    CALL WndMgr_TextSet(WINDOW_ID, アイテムリスト行数 + 2, @"@C:{カラー_注釈}@%RESULTS%@/C@")
ENDIF

@HO_DRAW_TRADE_WINDOW_RIGHT
#DIM CONST WINDOW_ID = 2
#DIM CONST WND_WIDTH  = 84
#DIM CONST WND_HEIGHT = 36
#DIM CONST ヘッダー行数 = 2
#DIM CONST アイテムリスト行数 = 30
#DIMS DYNAMIC DETAIL_LIST, ITEM_LENGTH
#DIM DYNAMIC ITEM_NUM
#DIM DYNAMIC L_CNT
#DIM DYNAMIC BTN_ID
#DIM DYNAMIC PAGE_NUM
#DIMS DYNAMIC STR_FOOTER
#DIM DYNAMIC DETAIL_LINECOUNT

BTN_ID = HO_交易ボタンID + 20000

CALL HO_TRADE_COUNT_PAGE_NUM(HO_ITEM_TRADE_STOCK, アイテムリスト行数)
PAGE_NUM = RESULT

;ウィンドウ作成
CALL WndMgr_CreateWindow(WINDOW_ID, 84, 6, WND_WIDTH, WND_HEIGHT, 2)
CALL WndMgr_Attribute(WINDOW_ID, "BorderColor", カラー_選択不可)
;ヘッダー
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@◇販売品◇@/C@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

;明細リスト作成
DETAIL_LINECOUNT = 0
FOR LOCAL, 0, ITEM_LENGTH
    ITEM_NUM = HO_ITEM_TRADE_STOCK:LOCAL
    IF ITEM_NUM > 0
        CALL HO_TRADE_PRINT_STOCK_DETAIL(HO_ITEM_TRADE_STOCK, LOCAL)
        DETAIL_LIST:DETAIL_LINECOUNT '= @"@B:{BTN_ID + LOCAL}@%RESULTS%@/B@"
        DETAIL_LINECOUNT ++
    ENDIF
NEXT

;明細リスト出力
L_CNT = 0
FOR LOCAL, アイテムリスト行数 * HO_TRADE_PAGE_RIGHT, アイテムリスト行数 * (HO_TRADE_PAGE_RIGHT + 1)
    IF  L_CNT / アイテムリスト行数 <= 0
        CALL WndMgr_TextSet(WINDOW_ID, L_CNT + ヘッダー行数, DETAIL_LIST:LOCAL)
        L_CNT++
    ELSE
        CALL WndMgr_TextAdd(WINDOW_ID, (L_CNT % アイテムリスト行数) + ヘッダー行数, DETAIL_LIST:LOCAL)
        L_CNT ++
    ENDIF
    L_CNT ++
NEXT

;フッター
IF PAGE_NUM > 0
    STR_FOOTER += HO_TRADE_PAGE_RIGHT > 0 ? @"@B:{BTN_ID + 9000}@<<@/B@ " # "   "
    STR_FOOTER += @"%TOSTR(HO_TRADE_PAGE_RIGHT + 1, "..")% "
    STR_FOOTER += HO_TRADE_PAGE_RIGHT != PAGE_NUM ? @"@B:{BTN_ID + 9001}@>>@/B@" # "  "
    CALLF TAG_PRINT_SHAPE(STR_FOOTER, WND_WIDTH - 8, 1, 2)
    CALL WndMgr_TextSet(WINDOW_ID, アイテムリスト行数 + 2, @"@C:{カラー_注釈}@%RESULTS%@/C@")
ENDIF

@HO_TRADE_PRINT_STOCK_DETAIL(ITEM_STOCK_ARRAY, ITEM_ID)
#DIM REF ITEM_STOCK_ARRAY
#DIM ITEM_ID
#DIMS DYNAMIC ITEM_NAME
#DIM DYNAMIC ITEM_NUM
#DIMS DYNAMIC STR_ITEM_NUM
#DIMS DYNAMIC STR_PRICE

CALL GET_ITEM_NAME(ITEM_ID)
ITEM_NAME = %RESULTS%
ITEM_NAME = %TAG_PRINT_SHAPE(ITEM_NAME, 16, 1, 0)%
STR_ITEM_NUM = %TAG_PRINT_SHAPE(@"× %TOSTR(ITEM_STOCK_ARRAY:ITEM_ID)%", 10, 1, 0)%
CALL GET_ITEM_INFO(ITEM_ID,ITEM_PRICE)
STR_PRICE = %TAG_PRINT_SHAPE(TOSTR(RESULT,"#,###,###"), 10, 1, 0)%

RESULTS '= @"%TAG_PRINT_SHAPE(@"%ITEM_NAME%%STR_ITEM_NUM%%STR_PRICE%", 38, 1, 0)%"

; #endregion

;-------------------------------------------------
; 武器・レリック用の在庫・販売管理メニュー
;-------------------------------------------------
; #region
@HO_DRAW_TRADE_EQUIP_WINDOW_LEFT
#DIM CONST WINDOW_ID = 1
#DIM CONST WND_WIDTH  = 120
#DIM CONST WND_HEIGHT = 36
#DIM CONST ヘッダー行数 = 4
#DIM CONST アイテムリスト行数 = 14
#DIMS DYNAMIC DETAIL_LIST, ITEM_LENGTH
#DIM DYNAMIC ITEM_NUM
#DIM DYNAMIC L_CNT
#DIM DYNAMIC BTN_ID
#DIM DYNAMIC PAGE_NUM
#DIMS DYNAMIC STR_FOOTER
#DIM DYNAMIC DETAIL_LINECOUNT

;装備関連の変数
#DIM  DYNAMIC EQUIP_IDX, WPN_MAX_WEAPON_STOCK
#DIM  DYNAMIC STATUS_IDX
#DIM  DYNAMIC WEAPON_ID
#DIMS DYNAMIC DIC_WPN_SKILL
#DIMS DYNAMIC SKILL_DEF_NAME
#DIMS DYNAMIC WPN_SKILL_DEF_LIST, VARSIZE("SKILL_DEF_LIST")
#DIMS DYNAMIC SKILL_NAME
#DIM  DYNAMIC SKILL_LV
#DIM  DYNAMIC PRICE
#DIMS DYNAMIC TOOLTIP

#DIM  DYNAMIC EQUIP_TYPE
#DIMS DYNAMIC DT_FILTER
#DIMS DYNAMIC SORT_ORDER = "WEAPON_ID ASC, MATERIAL ASC"

;印字カラム
#DIMS DYNAMIC COLUMN, 9
#DIM  DYNAMIC COLUMN_IDX
#DIM  DYNAMIC COLUMN_LENGTH = 26, 14, 6, 6, 6, 6, 6, 6, 8,
#DIM  DYNAMIC COLUMN_PADDING = 0, 0, 0, 0, 0, 0, 0, 0, 0
;ステータスの表示順序
{
    #DIMS CONST   COLUMN_ORDER =
        "ATTACK"
        , "DEFENCE"
        , "ARMOR"
        , "MAG"
        , "AGILITY"
        , "HATE_RATE"
        , "TARGETING"
}

SIF HO_TRADE_CATEGORY == 2
    EQUIP_TYPE = 1
DT_FILTER '= @"EQUIP_TYPE = {EQUIP_TYPE} AND EQUIP_CHARA_ID < 0 AND (ON_SALE_FLAG = 0 OR ON_SALE_FLAG IS NULL) AND (FAVORITE_FLAG = 0 OR FAVORITE_FLAG IS NULL)"

BTN_ID = HO_交易ボタンID + 10000
CALL HO_TRADE_COUNT_PAGE_NUM(HO_ITEM_STOCK, アイテムリスト行数)
PAGE_NUM = RESULT

;ウィンドウ作成
CALL WndMgr_CreateWindow(WINDOW_ID, 2, 6, WND_WIDTH, WND_HEIGHT, 2)
CALL WndMgr_Attribute(WINDOW_ID, "BorderColor", カラー_選択不可)

;ヘッダー
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@◇備蓄◇@/C@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
LOCALS = %TAG_PRINT_SHAPE(@"@B:[SORT:WEAPON_NAME]@[名称]@/B@", 28, 1)%
LOCALS += TAG_PRINT_SHAPE(@"@B:[SORT:PRICE]@　[値段]@/B@", 12, 1, 1)
LOCALS += TAG_PRINT_SHAPE(@"@B:[SORT:ATTACK]@　[攻]@/B@", 6, 1)
LOCALS += TAG_PRINT_SHAPE(@"@B:[SORT:DEFENCE]@　[防]@/B@", 6, 1)
LOCALS += TAG_PRINT_SHAPE(@"@B:[SORT:ARMOR]@　[軽]@/B@", 6, 1)
LOCALS += TAG_PRINT_SHAPE(@"@B:[SORT:MAG]@　[魔]@/B@", 6, 1)
LOCALS += TAG_PRINT_SHAPE(@"@B:[SORT:AGILITY]@　[行]@/B@", 6, 1)
LOCALS += TAG_PRINT_SHAPE(@"@B:[SORT:HATE_RATE]@　[敵]@/B@", 6, 1)
LOCALS += TAG_PRINT_SHAPE(@"@B:[SORT:HATE_RATE]@　[選]@/B@", 8, 1)
LOCALS += TAG_PRINT_SHAPE(@"　　[スキル]", 22, 1)
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, LOCALS)
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

;明細リスト作成
;-------------------------------------------------
DETAIL_LINECOUNT = 0
;ソート
IF HO_TRADE_CURRENT_SORT_COLUMN != ""
    SELECTCASE HO_TRADE_CURRENT_SORT_ORDER
        CASE 1 ;降順
            SORT_ORDER '= @"%HO_TRADE_CURRENT_SORT_COLUMN% DESC"
        CASE 2 ;昇順
            SORT_ORDER '= @"%HO_TRADE_CURRENT_SORT_COLUMN% ASC"
    ENDSELECT
ELSE
    SORT_ORDER '= "WEAPON_ID ASC, MATERIAL ASC"
ENDIF
ITEM_NUM = DT_SELECT("WEAPON_STOCK", DT_FILTER, SORT_ORDER, EQUIP_IDX)
PAGE_NUM = ITEM_NUM / (アイテムリスト行数 + 1)
FOR LOCAL, 0, ITEM_NUM
    CALL GET_WEAPON_PRINT_NAME(EQUIP_IDX:LOCAL)
    COLUMN:0 = %TAG_PRINT_SHAPE(@"@C:{カラー_白}@@B:[STOCK_EQUIP_DID:{EQUIP_IDX:LOCAL}]@[%RESULTS%]@/B@@/C@", COLUMN_LENGTH:0, 1)%
    CALL GET_EQUIP_PRICE(EQUIP_IDX:LOCAL)
    PRICE = RESULT
    ;ここでPRICEの値を更新するの実装としてはとてもよろしくない
    DT_CELL_SET "WEAPON_STOCK", EQUIP_IDX:LOCAL, "PRICE", PRICE, 1
    COLUMN:1 = %TAG_PRINT_SHAPE(TOSTR(PRICE, "#,##0"), COLUMN_LENGTH:1, 1, 1)%
    FOR STATUS_IDX, 0, WPN_MAX_STATUSNUM
        IF COLUMN_ORDER:STATUS_IDX != "TARGETING"
            COLUMN:(STATUS_IDX + 2) = %TAG_PRINT_SHAPE(@"@C:{カラー_注釈}@{DT_CELL_GET("WEAPON_STOCK", EQUIP_IDX:LOCAL, COLUMN_ORDER:STATUS_IDX, 1)}@/C@", COLUMN_LENGTH:(STATUS_IDX + 2), 1, 1)%
        ELSEIF EQUIP_TYPE == 0
            COLUMN:(STATUS_IDX + 2) = %TAG_PRINT_SHAPE(@"@C:{カラー_注釈}@%WPN_脅威選定文字列:DT_CELL_GET("WEAPON_STOCK", EQUIP_IDX:LOCAL, COLUMN_ORDER:STATUS_IDX, 1)%@/C@", COLUMN_LENGTH:(STATUS_IDX + 2), 1, 1)%
        ENDIF
    NEXT
    DETAIL_LIST:DETAIL_LINECOUNT '= ""
    FOR COLUMN_IDX, 0, VARSIZE("COLUMN")
        DETAIL_LIST:DETAIL_LINECOUNT += COLUMN:COLUMN_IDX
    NEXT
    DETAIL_LIST:DETAIL_LINECOUNT += "    "
    ;武器スキル_パッシブ
    CALL GET_EQUIP_SKILL_LIST_STR(EQUIP_IDX:LOCAL, 武器スキル_パッシブ)
    DETAIL_LIST:DETAIL_LINECOUNT += RESULTS
    ;武器スキル_アクティブ
    CALL GET_EQUIP_SKILL_LIST_STR(EQUIP_IDX:LOCAL, 武器スキル_アクティブ)
    DETAIL_LIST:DETAIL_LINECOUNT += RESULTS
    DETAIL_LINECOUNT ++
NEXT

;明細リスト出力
L_CNT = 0
FOR LOCAL, アイテムリスト行数 * HO_TRADE_PAGE_LEFT, アイテムリスト行数 * (HO_TRADE_PAGE_LEFT + 1)
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT + ヘッダー行数, DETAIL_LIST:LOCAL)
    L_CNT ++
    L_CNT ++
NEXT

;フッター
IF PAGE_NUM > 0
    STR_FOOTER += HO_TRADE_PAGE_LEFT > 0 ? @"@B:{BTN_ID + 9000}@<<@/B@ " # "   "
    STR_FOOTER += @"%TOSTR(HO_TRADE_PAGE_LEFT + 1, "..")% "
    STR_FOOTER += HO_TRADE_PAGE_LEFT != PAGE_NUM ? @"@B:{BTN_ID + 9001}@>>@/B@" # "  "
    CALLF TAG_PRINT_SHAPE(STR_FOOTER, WND_WIDTH - 8, 1, 2)
    CALL WndMgr_TextSet(WINDOW_ID, (アイテムリスト行数 * 2) + 4, @"@C:{カラー_注釈}@%RESULTS%@/C@")
ENDIF

@HO_DRAW_TRADE_EQUIP_WINDOW_RIGHT
#DIM CONST WINDOW_ID = 2
#DIM CONST WND_WIDTH  = 46
#DIM CONST WND_HEIGHT = 36
#DIM CONST ヘッダー行数 = 4
#DIM CONST アイテムリスト行数 = 14
#DIMS DYNAMIC DETAIL_LIST, WPN_MAX_WEAPON_STOCK
#DIM DYNAMIC ITEM_NUM
#DIM DYNAMIC L_CNT
#DIM DYNAMIC BTN_ID
#DIM DYNAMIC PAGE_NUM
#DIMS DYNAMIC STR_FOOTER
#DIM DYNAMIC DETAIL_LINECOUNT

;装備関連の変数
#DIM  DYNAMIC EQUIP_IDX, WPN_MAX_WEAPON_STOCK
#DIM  DYNAMIC STATUS_IDX
#DIM  DYNAMIC WEAPON_ID
#DIMS DYNAMIC DIC_WPN_SKILL
#DIMS DYNAMIC SKILL_DEF_NAME
#DIMS DYNAMIC WPN_SKILL_DEF_LIST, VARSIZE("SKILL_DEF_LIST")
#DIMS DYNAMIC SKILL_NAME
#DIM  DYNAMIC SKILL_LV
#DIMS DYNAMIC TOOLTIP
#DIM  DYNAMIC PRICE

#DIM  DYNAMIC EQUIP_TYPE
#DIMS DYNAMIC DT_FILTER

;印字カラム
#DIMS DYNAMIC COLUMN, 2
#DIM  DYNAMIC COLUMN_IDX
#DIM  DYNAMIC COLUMN_LENGTH = 28, 12
#DIM  DYNAMIC COLUMN_PADDING = 0, 0

;ウィンドウ作成
CALL WndMgr_CreateWindow(WINDOW_ID, 122, 6, WND_WIDTH, WND_HEIGHT, 2)
CALL WndMgr_Attribute(WINDOW_ID, "BorderColor", カラー_選択不可)
;ヘッダー
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@◇販売品◇@/C@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
LOCALS = %TAG_PRINT_SHAPE(@"[名称]", 28, 1)%
LOCALS += TAG_PRINT_SHAPE(@"　[値段]", 12, 1, 1)
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, LOCALS)
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

BTN_ID = HO_交易ボタンID + 20000

SIF HO_TRADE_CATEGORY == 2
    EQUIP_TYPE = 1
DT_FILTER '= @"EQUIP_TYPE = {EQUIP_TYPE} AND EQUIP_CHARA_ID < 0 AND ON_SALE_FLAG = 1"

;明細リスト作成
DETAIL_LINECOUNT = 0
ITEM_NUM = DT_SELECT("WEAPON_STOCK", DT_FILTER,, EQUIP_IDX)
PAGE_NUM = ITEM_NUM / (アイテムリスト行数 + 1)
FOR LOCAL, 0, ITEM_NUM
    CALL GET_WEAPON_PRINT_NAME(EQUIP_IDX:LOCAL)
    COLUMN:0 = %TAG_PRINT_SHAPE(@"@C:{カラー_白}@@B:[SALE_EQUIP_DID:{EQUIP_IDX:LOCAL}]@[%RESULTS%]@/B@@/C@", COLUMN_LENGTH:0, 1)%
    CALL GET_EQUIP_PRICE(EQUIP_IDX:LOCAL)
    PRICE = RESULT
    COLUMN:1 = %TAG_PRINT_SHAPE(TOSTR(PRICE, "#,##0"), COLUMN_LENGTH:1, 1, 1)%
    FOR COLUMN_IDX, 0, VARSIZE("COLUMN")
        DETAIL_LIST:DETAIL_LINECOUNT += COLUMN:COLUMN_IDX
    NEXT
    DETAIL_LINECOUNT ++
NEXT

;明細リスト出力
L_CNT = 0
FOR LOCAL, アイテムリスト行数 * HO_TRADE_PAGE_RIGHT, アイテムリスト行数 * (HO_TRADE_PAGE_RIGHT + 1)
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT + ヘッダー行数, DETAIL_LIST:LOCAL)
    L_CNT ++
    L_CNT ++
NEXT

;フッター
IF PAGE_NUM > 0
    STR_FOOTER += HO_TRADE_PAGE_RIGHT > 0 ? @"@B:{BTN_ID + 9000}@<<@/B@ " # "   "
    STR_FOOTER += @"%TOSTR(HO_TRADE_PAGE_RIGHT + 1, "..")% "
    STR_FOOTER += HO_TRADE_PAGE_RIGHT != PAGE_NUM ? @"@B:{BTN_ID + 9001}@>>@/B@" # "  "
    CALLF TAG_PRINT_SHAPE(STR_FOOTER, WND_WIDTH - 8, 1, 2)
    CALL WndMgr_TextSet(WINDOW_ID, (アイテムリスト行数 * 2) + 4, @"@C:{カラー_注釈}@%RESULTS%@/C@")
ENDIF

; #endregion

;-------------------------------------------------
; 交易メニュー入力受付
;-------------------------------------------------
; #region
@HO_TRADE_WINDOW_INPUT()
#DIMS DYNAMIC INPUT_VALUES
#DIM  DYNAMIC INPUT_VALUE
#DIM  DYNAMIC VALUE
#DIM  DYNAMIC INPUT_WINDOW_ID
#DIMS DYNAMIC SORT_COLUMN

ONEINPUTS
IF ISNUMERIC(RESULTS)
    INPUT_VALUE = TOINT(RESULTS)
    INPUT_WINDOW_ID = (INPUT_VALUE - HO_交易ボタンID) / 10000
    SELECTCASE INPUT_WINDOW_ID
            ;親ウィンドウからの入力処理
        CASE 0
            VALUE = INPUT_VALUE - HO_交易ボタンID
            ;移動量ボタンが押された場合
            IF INRANGE(VALUE, 0, 9)
                HO_TRADE_TRANSFER_SWITCH = VALUE
            ENDIF
            ;備蓄ウィンドウからの入力処理
        CASE 1
            VALUE = INPUT_VALUE - HO_交易ボタンID - 10000
            IF VALUE < ITEM_LENGTH
                CALL HO_TRADE_TRANSFER_STOCK_TO_SALE(VALUE)
            ELSEIF INRANGE(VALUE, 9000, 9001)
                IF VALUE == 9000
                    HO_TRADE_PAGE_LEFT --
                ELSE
                    HO_TRADE_PAGE_LEFT ++
                ENDIF
            ENDIF
            ;販売品ウィンドウからの入力処理
        CASE 2
            VALUE = INPUT_VALUE - HO_交易ボタンID - 20000
            IF  VALUE < ITEM_LENGTH
                CALL HO_TRADE_TRANSFER_SALE_TO_STOCK(VALUE)
            ELSEIF INRANGE(VALUE, 9000, 9001)
                IF VALUE == 9000
                    HO_TRADE_PAGE_RIGHT --
                ELSE
                    HO_TRADE_PAGE_RIGHT ++
                ENDIF
            ENDIF
        CASEELSE
    ENDSELECT
ELSE
    INPUT_VALUES = %RESULTS%
    IF DIC_CONTAINSKEY(INPUT_VALUES, "EXIT")
        RETURN -1
    ELSEIF DIC_CONTAINSKEY(INPUT_VALUES, "CATEGORY")
        HO_TRADE_CATEGORY = TOINT(DIC_GET(INPUT_VALUES, "CATEGORY"))
        HO_TRADE_PAGE_RIGHT = 0
        HO_TRADE_PAGE_LEFT = 0
    ELSEIF DIC_CONTAINSKEY(INPUT_VALUES, "STOCK_EQUIP_DID")
        DT_CELL_SET "WEAPON_STOCK", TOINT(DIC_GET(INPUT_VALUES, "STOCK_EQUIP_DID")), "ON_SALE_FLAG", 1, 1
    ELSEIF DIC_CONTAINSKEY(INPUT_VALUES, "SALE_EQUIP_DID")
        DT_CELL_SET "WEAPON_STOCK", TOINT(DIC_GET(INPUT_VALUES, "SALE_EQUIP_DID")), "ON_SALE_FLAG", 0, 1
    ELSEIF DIC_CONTAINSKEY(RESULTS, "SORT")
        SORT_COLUMN = %DIC_GET(RESULTS, "SORT")%
        IF SORT_COLUMN == HO_TRADE_CURRENT_SORT_COLUMN
            HO_TRADE_CURRENT_SORT_ORDER ++
            IF HO_TRADE_CURRENT_SORT_ORDER > 2
                HO_TRADE_CURRENT_SORT_COLUMN '= ""
                HO_TRADE_CURRENT_SORT_ORDER = 0
            ENDIF
        ELSE
            HO_TRADE_CURRENT_SORT_COLUMN = %SORT_COLUMN%
            HO_TRADE_CURRENT_SORT_ORDER = 1
        ENDIF
    ENDIF
ENDIF
RETURN
; #endregion

@HO_TRADE_TRANSFER_STOCK_TO_SALE(ITEM_ID)
#DIM ITEM_ID
#DIM TRANSFER_AMOUNT

CALL HO_TRADE_SET_TRANSFER_AMOUNT(HO_ITEM_STOCK, ITEM_ID)
TRANSFER_AMOUNT = RESULT
CALL CHANGE_ITEM_STOCK(ITEM_ID, TRANSFER_AMOUNT * -1)
HO_ITEM_TRADE_STOCK:ITEM_ID += TRANSFER_AMOUNT

@HO_TRADE_TRANSFER_SALE_TO_STOCK(ITEM_ID)
#DIM ITEM_ID
#DIM TRANSFER_AMOUNT

CALL HO_TRADE_SET_TRANSFER_AMOUNT(HO_ITEM_TRADE_STOCK, ITEM_ID)
TRANSFER_AMOUNT = RESULT
HO_ITEM_TRADE_STOCK:ITEM_ID -= TRANSFER_AMOUNT
CALL CHANGE_ITEM_STOCK(ITEM_ID, TRANSFER_AMOUNT)

@HO_TRADE_SET_TRANSFER_AMOUNT(ITEM_STOCK_ARRAY_FROM, ITEM_ID)
#DIM REF ITEM_STOCK_ARRAY_FROM
#DIM ITEM_ID
#DIM TRANSFER_AMOUNT

SELECTCASE HO_TRADE_TRANSFER_SWITCH
    CASE 0
        TRANSFER_AMOUNT = 1
    CASE 1
        TRANSFER_AMOUNT = MIN(5, ITEM_STOCK_ARRAY_FROM:ITEM_ID)
    CASE 2
        TRANSFER_AMOUNT = MIN(10, ITEM_STOCK_ARRAY_FROM:ITEM_ID)
    CASE 3
        TRANSFER_AMOUNT = MIN(100, ITEM_STOCK_ARRAY_FROM:ITEM_ID)
    CASE 4
        TRANSFER_AMOUNT = MIN(1000, ITEM_STOCK_ARRAY_FROM:ITEM_ID)
    CASE 9
        TRANSFER_AMOUNT = ITEM_STOCK_ARRAY_FROM:ITEM_ID
ENDSELECT

RETURN TRANSFER_AMOUNT

@HO_TRADE_COUNT_PAGE_NUM(ITEM_STOCK_ARRAY, MAX_ROW_NUM)
#DIM REF ITEM_STOCK_ARRAY
#DIM MAX_ROW_NUM
#DIM PAGE_NUM
#DIM DYNAMIC CNT

MAX_ROW_NUM = MAX(1, MAX_ROW_NUM)

FOR LOCAL, 0, ITEM_LENGTH
    IF ITEM_STOCK_ARRAY:LOCAL > 0
        CNT++
    ENDIF
NEXT
RETURN CNT / (MAX_ROW_NUM + 1)


code:
;-------------------------------------------------
; アイテム加工画面
;-------------------------------------------------
@HO_ITEM_CRAFT_MENU(MODULE_ID)
#DIM MODULE_ID
#DIM CONST WINDOW_ID = 0
#DIM DYNAMIC LINE_NUM

;初期処理
HO_ITEM_CRAFT_PAGE_LEFT = 0
HO_ITEM_CRAFT_SELECT_ITEM_ID = -1
HO_ITEM_CRAFT_SELECT_RUNE_ID = -1
HO_ITEM_CRAFT_SELECT_RUNE_GENRE = 武器スキル_パッシブ
HO_CRAFT_CATEGORY = 0
HO_CRAFT_IS_ACTIVE_SUBWND = 0
HO_ITEM_CRAFT_BASE_PRODUCTION_RATE = 1
HO_ITEM_CRAFT_NUM_PRODUCTION       = 1
HO_ITEM_CRAFT_PRODUCTION_TIME      = 0

LINE_NUM = LINECOUNT

WHILE 1
    LINE_NUM = LINECOUNT
    REDRAW 0
    CALL WndMgr_DestroyWindow(-1)
    CALL HO_DRAW_CRAFT_ITEM_WINDOW_PARENT(MODULE_ID)
    IF HO_CRAFT_IS_ACTIVE_SUBWND && HO_CRAFT_CATEGORY == 0
        CALL WndMgr_Attribute(-1, "Disabled", 1)
        CALL HO_DRAW_CRAFT_ORDER_WINDOW()
    ENDIF
    CALL WndMgr_DisplayAll()
    REDRAW 1
    CALL HO_CRAFT_WINDOW_INPUT(MODULE_ID)
    IF RESULT == -1
        CLEARLINE LINECOUNT - LINE_NUM
        RETURN -1
    ELSEIF RESULT == 1
        CLEARLINE LINECOUNT - LINE_NUM
        RETURN 1
    ENDIF
    CLEARLINE LINECOUNT - LINE_NUM
WEND

@HO_DRAW_CRAFT_ITEM_WINDOW_PARENT(MODULE_ID)
#DIM MODULE_ID
#DIM CONST WINDOW_ID = 0
#DIM CONST WND_WIDTH  = 170
#DIM CONST WND_HEIGHT = 54
#DIM DYNAMIC L_CNT
#DIM DYNAMIC BTN_ID

#DIMS DYNAMIC _LIST_MEMBER
#DIM DYNAMIC MEMBER_NUM
#DIM DYNAMIC CHARA_ID
#DIM DYNAMIC F_COL, 10

#DIMS DYNAMIC ITEM_NAME
#DIM DYNAMIC ITEM_NUM
#DIM DYNAMIC MATERIAL_NEEDS, ITEM_LENGTH
#DIM DYNAMIC WPN_MATERIAL_NEEDS, WPN_材質種類数, ITEM_LENGTH
#DIMS DYNAMIC WEAPON_NAME
#DIM DYNAMIC 材質種類
#DIM DYNAMIC アイテム種類
#DIM DYNAMIC IS_CRAFTABLE

BTN_ID = HO_アイテムクラフトボタンID

CALL WndMgr_CheckExistWindow()
FINDELEMENT RESULT, WINDOW_ID, 1
IF RESULT == -1
    CALL WndMgr_CreateWindow(WINDOW_ID, 0, 1, WND_WIDTH, WND_HEIGHT, 2)
ELSE
    CALL WndMgr_ResetWindow(WINDOW_ID)
ENDIF

;CATEGORYタブの文字色
VARSET F_COL, カラー_白
F_COL:HO_CRAFT_CATEGORY = カラー_選択中

CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@S:1@@C:{カラー_注釈}@◇クラフト◇@/C@@/S@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

;ヘッダー
LOCALS '= @"@C:{F_COL:0}@@B:0@[素材]@/B@@/C@"
SELECTCASE MODULE_ID
    CASE 301
        LOCALS += @"@C:{F_COL:1}@@B:1@　[武器]@/B@@/C@"
        LOCALS += @"@C:{F_COL:3}@@B:3@　[武器の強化]@/B@@/C@"
        LOCALS += @"@C:{F_COL:4}@@B:4@　[武器の付呪]@/B@@/C@"
    CASE 305
        LOCALS += @"@C:{F_COL:2}@@B:2@　[衣類]@/B@@/C@"
ENDSELECT
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, LOCALS)

SELECTCASE HO_CRAFT_CATEGORY
        ;アイテム
    CASE 0
        CALL HO_DRAW_CRAFT_ITEM_WINDOW_LEFT(MODULE_ID)
        CALL HO_DRAW_CRAFT_ITEM_WINDOW_RIGHT(MODULE_ID)
        ;武器
    CASE 1
        CALL HO_DRAW_CRAFT_ITEM_WINDOW_LEFT(MODULE_ID)
        CALL HO_DRAW_CRAFT_ITEM_WINDOW_RIGHT_WEAPON(MODULE_ID)
        ;衣類
    CASE 2
        CALL HO_DRAW_CRAFT_ITEM_WINDOW_LEFT(MODULE_ID)
        CALL HO_DRAW_CRAFT_ITEM_WINDOW_RIGHT_CLOTH(MODULE_ID)
        ;武器の改良
    CASE 3
        CALL HO_DRAW_ITEM_MENU_WINDOW_LEFT(MODULE_ID, "WEAPON_MODIFY")
        IF HO_CRAFT_IS_ACTIVE_SUBWND
            CALL WndMgr_Attribute(-1, "Disabled", 1)
            CALL HO_DRAW_CRAFT_ITEM_WINDOW_RIGHT_WEAPON_MODIFY(MODULE_ID)
        ENDIF
    CASE 4
        CALL HO_DRAW_ITEM_MENU_WINDOW_LEFT(MODULE_ID, "WEAPON_ENCHANT")
        IF HO_CRAFT_IS_ACTIVE_SUBWND
            CALL WndMgr_Attribute(-1, "Disabled", 1)
            IF HO_CRAFT_IS_ACTIVE_SUBWND == 1
                CALL HO_DRAW_CRAFT_ITEM_WINDOW_RIGHT_WEAPON_ENCHANT(MODULE_ID)
            ELSEIF HO_CRAFT_IS_ACTIVE_SUBWND == 2
                CALL HO_DRAW_CRAFT_ITEM_WINDOW_RIGHT_WEAPON_SELECT_RUNE(MODULE_ID)
            ENDIF
        ENDIF
    CASEELSE

ENDSELECT

;フッター出力
;-------------------------------------------------
L_CNT = WND_HEIGHT - 4
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@B:9999999@@C:{カラー_白}@[キャンセル]@/C@@/B@")

RETURN

@HO_DRAW_CRAFT_ITEM_WINDOW_LEFT(MODULE_ID)
#DIM MODULE_ID
#DIM CONST WINDOW_ID = 1
#DIM CONST WND_WIDTH  = 64
#DIM CONST WND_HEIGHT = 48
#DIM DYNAMIC L_CNT
#DIM DYNAMIC F_COL, 10

;CATEGORYタブの文字色
VARSET F_COL, カラー_白
F_COL:HO_CRAFT_CATEGORY = カラー_選択中

;ウィンドウ作成
CALL WndMgr_CreateWindow(WINDOW_ID, 2, 5, WND_WIDTH, WND_HEIGHT, 2)
CALL WndMgr_Attribute(WINDOW_ID, "BorderColor", カラー_選択不可)

CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@作成するアイテムを選択してください@/C@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

;衣類用の衣装部位タブ
IF HO_CRAFT_CATEGORY == 2
    FOR LOCAL, 0, VARSIZE("CLOTH_PART_NAME")
        SIF LOCAL == 衣装部位_武器
            CONTINUE
        LOCALS '= TAG_PRINT_SHAPE(@"@B:{LOCAL + 1000}@%TOHALF(CLOTH_PART_NAME:LOCAL)%@/B@", 8, 1, 2)
        CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"@C:{HO_ITEM_CRAFT_SELECT_CLOTH_PARTS == LOCAL ? カラー_選択中 # カラー_白}@[%LOCALS%]@/C@　")
        SIF (LOCAL + 1) % 5 == 0
            L_CNT ++
    NEXT
    L_CNT ++
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
ENDIF

SELECTCASE HO_CRAFT_CATEGORY
        ;アイテム
    CASE 0
        CALL HO_DRAW_CRAFT_ITEM_WINDOW_PRINT_DETAIL_ITEM(WINDOW_ID, MODULE_ID)
        ;武器
    CASE 1
        CALL HO_DRAW_CRAFT_ITEM_WINDOW_PRINT_DETAIL_WEAPON(WINDOW_ID, MODULE_ID)
        ;衣類
    CASE 2
        CALL HO_DRAW_CRAFT_ITEM_WINDOW_PRINT_DETAIL_CLOTH(WINDOW_ID, MODULE_ID)
        ;武器の改良
    CASE 3
        ; CALL HO_DRAW_CRAFT_ITEM_WINDOW_PRINT_DETAIL_WEAPON_MODIFY(WINDOW_ID, MODULE_ID)
    CASEELSE

ENDSELECT

@HO_DRAW_CRAFT_ITEM_WINDOW_RIGHT(MODULE_ID)
#DIM MODULE_ID
#DIM CONST WINDOW_ID = 2
#DIM CONST WND_WIDTH  = 102
#DIM CONST WND_HEIGHT = 48
#DIM CONST ヘッダー行数 = 2
#DIM CONST BTN_ID = 2000
#DIM DYNAMIC L_CNT

#DIMS DYNAMIC ITEM_NAME
#DIM  DYNAMIC ITEM_ID
#DIMS DYNAMIC MATERIAL_NAME
#DIM DYNAMIC MATERIAL_NEEDS, ITEM_LENGTH
#DIM  DYNAMIC STOCKNUM
#DIM DYNAMIC F_COL
#DIM DYNAMIC IS_CRAFTABLE = 1
#DIM DYNAMIC ERR_FLG

#DIM DYNAMIC 基準生産量
#DIM DYNAMIC 基準生産時間 = 15
#DIMS DYNAMIC 生産物名
#DIM DYNAMIC 生産時間
#DIM DYNAMIC 生産回数
#DIMS DYNAMIC 現在時刻
#DIMS DYNAMIC 完了予定時刻
#DIM  DYNAMIC 能力累算

;ウィンドウ作成
CALL WndMgr_CreateWindow(WINDOW_ID, 66, 5, WND_WIDTH, WND_HEIGHT, 2)
CALL WndMgr_Attribute(WINDOW_ID, "BorderColor", カラー_選択不可)
SIF HO_ITEM_CRAFT_SELECT_ITEM_ID == -1
    RETURN

ITEM_ID = HO_ITEM_CRAFT_SELECT_ITEM_ID
IF ITEM_ID >= 1000000
    ITEM_ID -= 1000000
    IS_CRAFTABLE = 0
ENDIF

基準生産量   = HO_ITEM_CRAFT_BASE_PRODUCTION_RATE
生産回数     = HO_ITEM_CRAFT_NUM_PRODUCTION

;ヘッダー
CALL GET_ITEM_NAME(ITEM_ID)
ITEM_NAME = %RESULTS%
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@S:1@@C:{カラー_注釈}@◇　%ITEM_NAME%　◇@/C@@/S@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

;概要欄
VARSET RESULTS
FOR LOCAL, 0, 10
    TRYCALLFORM GET_ITEM_DESCRIPTION_{ITEM_ID}
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"　%RESULTS:LOCAL%")
NEXT

CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
VARSET RESULTS
FOR LOCAL, 0, 10
    TRYCALLFORM GET_ITEM_SUBDESCRIPTION_{ITEM_ID}
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"　%RESULTS:LOCAL%")
NEXT

;備考欄
L_CNT++
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@S:1@@C:{カラー_注釈}@◇　生産情報　◇@/S@@/C@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

CALL WndMgr_TextSet(WINDOW_ID, L_CNT, @"@C:{カラー_注釈}@・要求素材@/C@")

FOR LOCAL, 0, 5
    IF LOCAL > 0
        CALL GET_ITEM_MATERIAL_NEEDS(ITEM_ID, MATERIAL_NEEDS, LOCAL)
    ENDIF
    IF LOCAL == 0 || (LOCAL > 0 && RESULT > 0) ;通常レシピは確定で表示。代替レシピ(RECIPE_ID > 0)はレシピが有効(RESULT > 0)なら表示
        CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"@B:{BTN_ID + 10 + LOCAL}@@C:{LOCAL == HO_CRAFT_RECIPE_ID ? カラー_選択中 # カラー_白}@　　[レシピ{LOCAL + 1}]@/C@@/B@")
    ENDIF
NEXT
L_CNT ++
L_CNT ++
CALL GET_ITEM_MATERIAL_NEEDS(ITEM_ID, MATERIAL_NEEDS, HO_CRAFT_RECIPE_ID)
FOR LOCAL:0, 0, ITEM_LENGTH
    IF MATERIAL_NEEDS:(LOCAL:0) > 0
        IF LOCAL == ITEM_ディナリ
            STOCKNUM = MONEY
        ELSEIF LOCAL == ITEM_淫堕点
            STOCKNUM = QST_LEWD_POINT
        ELSE
            STOCKNUM = HO_ITEM_STOCK:(LOCAL:0)
        ENDIF
        CALL GET_ITEM_NAME(LOCAL:0)
        MATERIAL_NAME = %RESULTS%
        LOCALS = %TAG_PRINT_SHAPE(@"　　@C:{カラー_白}@%MATERIAL_NAME%@/C@", 24, 1, 0)%
        LOCALS += @"× {(MATERIAL_NEEDS:(LOCAL:0)* 生産回数)}"
        LOCALS += @"@C:{カラー_選択不可}@　(所持:{STOCKNUM})@/C@"
        CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, LOCALS)
        L_CNT ++
        IF STOCKNUM < MATERIAL_NEEDS:(LOCAL:0)
            IS_CRAFTABLE = 0
        ENDIF
    ENDIF
NEXT

;生産対象の情報を取得
CALL GET_ITEM_INFO(ITEM_ID, ITEM_基準生産量 + HO_CRAFT_RECIPE_ID)
基準生産量 = RESULT
;15分以上に時間をかけたいものに生産時間を加算
CALL GET_ITEM_INFO(ITEM_ID, ITEM_追加生産時間)
基準生産時間 += RESULT
;クラフトに参加している他のキャラの能力に応じ生産時間を減算 （100-3*√該当能力累算)％ 能力50が3人いると所要時間36％減
CALL HO_GET_USE_MODULE_INFO(MASTER)
MODULE_ID = RESULT
FOR LOCAL, 0, MTAR_NUM
    SELECTCASE MODULE_ID
        CASE 300 ;作業台
            能力累算 += ABL:(MTAR:LOCAL):器用
        CASE 302 ;キッチン
            能力累算 += ABL:(MTAR:LOCAL):料理
        CASE 303 ;錬金台
            能力累算 += ABL:(MTAR:LOCAL):知識
        CASEELSE
            能力累算 += ABL:(MTAR:LOCAL):器用
    ENDSELECT
NEXT
SIF 能力累算
    基準生産時間 = MAX(10, FTIMES(基準生産時間, 100 - (3 * SQRT(能力累算))))
;まとめ作りボーナスで時間減算 100-(生産回数の２乗÷4)％　10個作ると25％の時短に
SIF 生産回数 > 1
    基準生産時間 = MAX(10, FTIMES(基準生産時間, 100 - (生産回数 * 生産回数 / 4)))
;基準生産時間に端数がある場合は単位時間の倍数になるように
SIF 基準生産時間 % HO_単位時間 > 0
    基準生産時間 = MAX(HO_単位時間, 基準生産時間 / HO_単位時間 * HO_単位時間)

現在時刻 '= @"{HO_TIME / 60}:%TOSTR(HO_TIME % 60, "00")%"
生産時間 = 基準生産時間 * 生産回数
完了予定時刻 '= @"{(HO_TIME + 生産時間) / 60}:%TOSTR((HO_TIME + 生産時間) % 60, "00")%"

;;生産回数と時間
;生産回数設定ボタン
;生産量増減時のエラーチェック
FOR LOCAL:0, 0, ITEM_LENGTH
    IF LOCAL == ITEM_ディナリ
        STOCKNUM = MONEY
    ELSEIF LOCAL == ITEM_淫堕点
        STOCKNUM = QST_LEWD_POINT
    ELSE
        STOCKNUM = HO_ITEM_STOCK:(LOCAL:0)
    ENDIF
    IF (MATERIAL_NEEDS:(LOCAL:0) * (生産回数 + 1)) > STOCKNUM
        ERR_FLG ++
    ENDIF
    IF HO_TIME + 基準生産時間 * (生産回数 + 1) > HO_CLOCK(2700)
        ERR_FLG ++
    ENDIF
NEXT

L_CNT ++
IF 生産回数 > 1
    LOCALS '= @"@B:{BTN_ID + 3}@[-]@/B@ "
ELSE
    LOCALS '= @"@C:{カラー_選択不可}@[-]@/C@ "
ENDIF
IF !ERR_FLG && 生産回数 < 10
    LOCALS += @"@B:{BTN_ID + 2}@[+]@/B@ "
ELSE
    LOCALS += @"@C:{カラー_選択不可}@[+]@/C@ "
ENDIF

;L_CNT = 25
L_CNT = WND_HEIGHT - 7 - 4
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@・生産回数@/C@")
L_CNT ++
CALL WndMgr_TextSet(WINDOW_ID, L_CNT, @"　　@C:{カラー_白}@生産回数:{生産回数}回　@/C@%LOCALS%")
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"　　　　@C:{カラー_白}@⇒　所要時間:{生産時間}分 (%現在時刻% → %完了予定時刻%)@/C@")
L_CNT ++
;生産対象の情報を印字
L_CNT ++
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@・生産物@/C@")
L_CNT ++
LOCALS = %TAG_PRINT_SHAPE(@"　　　　@C:{カラー_注意}@⇒　%ITEM_NAME%@/C@", 36, 1, 0)%
LOCALS += @"× {基準生産量 * 生産回数}"
LOCALS += @"@C:{カラー_選択不可}@　(所持:{HO_ITEM_STOCK:ITEM_ID})@/C@"
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注意}@%LOCALS%@/C@")

;フッター
L_CNT = WND_HEIGHT - 4
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
IF IS_CRAFTABLE
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT, @"@B:{BTN_ID + 1}@@C:{カラー_白}@[クラフトする]@/C@@/B@")
ELSE
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT, @"@C:{カラー_選択不可}@[クラフトする]@/C@")
ENDIF
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT++, @"@B:[CRAFT_ORDER:{ITEM_ID}][RECIPE_NO:{HO_CRAFT_RECIPE_ID}]@　[レシピを指示書に登録]@/B@")

HO_ITEM_CRAFT_BASE_PRODUCTION_RATE = 基準生産量
HO_ITEM_CRAFT_NUM_PRODUCTION       = 生産回数
HO_ITEM_CRAFT_PRODUCTION_TIME      = 生産時間

@HO_DRAW_CRAFT_ITEM_WINDOW_PRINT_DETAIL_ITEM(WINDOW_ID, MODULE_ID)
#DIM WINDOW_ID
#DIM MODULE_ID
#DIM CONST HEADER_NUM = 2
#DIM CONST MAX_ROW = 40
#DIM CONST BTN_ID = 1000000

#DIM  DYNAMIC WND_WIDTH
#DIMS DYNAMIC DETAIL_LIST, ITEM_LENGTH
#DIM  DYNAMIC ITEM_NUM
#DIM  DYNAMIC L_CNT
#DIM  DYNAMIC PAGE_NUM
#DIMS DYNAMIC STR_FOOTER
#DIM  DYNAMIC DETAIL_LINECOUNT
;アイテム関連
#DIMS DYNAMIC ITEM_NAME
#DIM  DYNAMIC MATERIAL_NEEDS, ITEM_LENGTH
#DIM  DYNAMIC ITEM_ID
#DIM  DYNAMIC IS_CRAFTABLE
#DIM  DYNAMIC RECIPE_ID

;明細リスト作成
DETAIL_LINECOUNT = 0
L_CNT = 0
FOR ITEM_ID, 0, ITEM_LENGTH
    CALL CHECK_ITEM_CRAFTABLE((ITEM_ID), MODULE_ID)
    SIF RESULT == -1
        CONTINUE
    IS_CRAFTABLE = -1
    FOR RECIPE_ID, 0, 5
        CALL GET_ITEM_MATERIAL_NEEDS((ITEM_ID), MATERIAL_NEEDS, RECIPE_ID)
        SIF RESULT == -1
            CONTINUE
        FOR LOCAL:1, 0, ITEM_LENGTH
            ;アイテム在庫が要求を満たさない場合、表示はするが作成は不可に
            IF MATERIAL_NEEDS:(LOCAL:1) > 0 && (HO_ITEM_STOCK:(LOCAL:1) < MATERIAL_NEEDS:(LOCAL:1))
                IS_CRAFTABLE = 0
            ELSEIF HO_ITEM_STOCK:(LOCAL:1) >= MATERIAL_NEEDS:(LOCAL:1)
                IS_CRAFTABLE = 1
            ENDIF
        NEXT
    NEXT
    CALL GET_ITEM_NAME(ITEM_ID)
    ITEM_NAME = %RESULTS%
    IF IS_CRAFTABLE == 1
        DETAIL_LIST:DETAIL_LINECOUNT '= @"@B:{BTN_ID + ITEM_ID}@@C:{カラー_白}@[%ITEM_NAME%]@/C@@/B@"
    ELSE
        DETAIL_LIST:DETAIL_LINECOUNT '= @"@B:{BTN_ID + ITEM_ID + 1000000}@@C:{カラー_選択不可}@[%ITEM_NAME%]@/C@@/B@"
    ENDIF
    DETAIL_LIST:DETAIL_LINECOUNT = %TAG_PRINT_SHAPE(DETAIL_LIST:DETAIL_LINECOUNT, 28, 1, 0)%
    DETAIL_LINECOUNT ++
NEXT

PAGE_NUM = DETAIL_LINECOUNT / MAX_ROW

;明細リスト出力
L_CNT = 0
FOR LOCAL, MAX_ROW * HO_ITEM_CRAFT_PAGE_LEFT, MAX_ROW * (HO_ITEM_CRAFT_PAGE_LEFT + 1)
    IF  L_CNT / MAX_ROW <= 0
        CALL WndMgr_TextSet(WINDOW_ID, L_CNT + HEADER_NUM, DETAIL_LIST:LOCAL)
        L_CNT++
    ELSE
        CALL WndMgr_TextAdd(WINDOW_ID, (L_CNT % MAX_ROW) + HEADER_NUM, DETAIL_LIST:LOCAL)
        L_CNT ++
    ENDIF
    L_CNT ++
NEXT

;フッター
CALL WndMgr_GetRectangle(WINDOW_ID)
WND_WIDTH = RESULT:2

IF PAGE_NUM > 0
    STR_FOOTER += HO_ITEM_CRAFT_PAGE_LEFT > 0 ? @"@B:9000@<<@/B@ " # "   "
    STR_FOOTER += @"%TOSTR(HO_ITEM_CRAFT_PAGE_LEFT + 1, "..")% "
    STR_FOOTER += HO_ITEM_CRAFT_PAGE_LEFT != PAGE_NUM ? @"@B:9001@>>@/B@" # "  "
    CALLF TAG_PRINT_SHAPE(STR_FOOTER, WND_WIDTH - 8, 1, 2)
    CALL WndMgr_TextSet(WINDOW_ID, MAX_ROW + 2, @"@C:{カラー_注釈}@%RESULTS%@/C@")
ENDIF

@HO_DRAW_CRAFT_ITEM_WINDOW_PRINT_DETAIL_WEAPON(WINDOW_ID, MODULE_ID)
#DIM WINDOW_ID
#DIM MODULE_ID
#DIM CONST HEADER_NUM = 2
#DIM CONST MAX_ROW = 20
#DIM CONST BTN_ID = 1000000

#DIM  DYNAMIC WND_WIDTH
#DIMS DYNAMIC DETAIL_LIST, ITEM_LENGTH
#DIM  DYNAMIC ITEM_NUM
#DIM  DYNAMIC L_CNT
#DIM  DYNAMIC PAGE_NUM
#DIMS DYNAMIC STR_FOOTER
#DIM  DYNAMIC DETAIL_LINECOUNT
;アイテム関連
#DIMS DYNAMIC ITEM_NAME
#DIM DYNAMIC WPN_MATERIAL_NEEDS, WPN_材質種類数, ITEM_LENGTH
#DIM  DYNAMIC ITEM_ID
#DIM  DYNAMIC IS_CRAFTABLE
#DIM  DYNAMIC 材質種類
#DIM  DYNAMIC 素材アイテム

;明細リスト作成
DETAIL_LINECOUNT = 0
L_CNT = 0
FOR ITEM_ID, 0, WPN_MAX_WEAPONNUM
    CALL CHECK_WEAPON_CRAFTABLE(ITEM_ID, MODULE_ID)
    SIF RESULT == -1
        CONTINUE
    FOR 材質種類, 0, WPN_材質種類数
        CALL GET_WEAPON_MATERIAL_NEEDS(ITEM_ID, 材質種類, WPN_MATERIAL_NEEDS)
        IF RESULT != -1
            IS_CRAFTABLE = -1
            FOR 素材アイテム, 0, ITEM_LENGTH
                ;アイテム在庫が要求を満たさない場合、表示はするが作成は不可に
                IF WPN_MATERIAL_NEEDS:材質種類:素材アイテム > 0 && (HO_ITEM_STOCK:素材アイテム < WPN_MATERIAL_NEEDS:材質種類:素材アイテム)
                    IS_CRAFTABLE = 0
                ENDIF
            NEXT
            CALL GET_WEAPON_NAME(ITEM_ID)
            ITEM_NAME = %RESULTS%
            IF IS_CRAFTABLE
                DETAIL_LIST:DETAIL_LINECOUNT '= @"@B:{BTN_ID + ITEM_ID + (材質種類 * 1000)}@@C:{カラー_白}@[%WPN_材質別接頭文字:材質種類%の%ITEM_NAME%]@/C@@/B@"
            ELSE
                DETAIL_LIST:DETAIL_LINECOUNT '= @"@B:{BTN_ID + ITEM_ID + (材質種類 * 1000) + 1000000}@@C:{カラー_選択不可}@[%WPN_材質別接頭文字:材質種類%の%ITEM_NAME%]@/C@@/B@"
            ENDIF
            DETAIL_LIST:DETAIL_LINECOUNT = %TAG_PRINT_SHAPE(DETAIL_LIST:DETAIL_LINECOUNT, 28, 1, 0)%
            DETAIL_LINECOUNT ++
        ELSE
            CONTINUE
        ENDIF
    NEXT
NEXT

PAGE_NUM = DETAIL_LINECOUNT / MAX_ROW

;明細リスト出力
L_CNT = 0
FOR LOCAL, MAX_ROW * HO_ITEM_CRAFT_PAGE_LEFT, MAX_ROW * (HO_ITEM_CRAFT_PAGE_LEFT + 1)
    IF  L_CNT / MAX_ROW <= 0
        CALL WndMgr_TextSet(WINDOW_ID, L_CNT + HEADER_NUM, DETAIL_LIST:LOCAL)
        L_CNT++
    ELSE
        CALL WndMgr_TextAdd(WINDOW_ID, (L_CNT % MAX_ROW) + HEADER_NUM, DETAIL_LIST:LOCAL)
        L_CNT ++
    ENDIF
    L_CNT ++
NEXT

;フッター
CALL WndMgr_GetRectangle(WINDOW_ID)
WND_WIDTH = RESULT:2

IF PAGE_NUM > 0
    STR_FOOTER += HO_ITEM_CRAFT_PAGE_LEFT > 0 ? @"@B:9000@<<@/B@ " # "   "
    STR_FOOTER += @"%TOSTR(HO_ITEM_CRAFT_PAGE_LEFT + 1, "..")% "
    STR_FOOTER += HO_ITEM_CRAFT_PAGE_LEFT != PAGE_NUM ? @"@B:9001@>>@/B@" # "  "
    CALLF TAG_PRINT_SHAPE(STR_FOOTER, WND_WIDTH - 8, 1, 2)
    CALL WndMgr_TextSet(WINDOW_ID, MAX_ROW + 2, @"@C:{カラー_注釈}@%RESULTS%@/C@")
ENDIF

@HO_DRAW_CRAFT_ITEM_WINDOW_RIGHT_WEAPON(MODULE_ID)
#DIM MODULE_ID
#DIM CONST WINDOW_ID = 2
#DIM CONST WND_WIDTH  = 102
#DIM CONST WND_HEIGHT = 37
#DIM CONST ヘッダー行数 = 2
#DIM CONST BTN_ID = 2000
#DIM DYNAMIC L_CNT

#DIM  DYNAMIC ITEM_ID
#DIMS DYNAMIC ITEM_NAME
#DIMS DYNAMIC MATERIAL_NAME
#DIM DYNAMIC MATERIAL_NEEDS, ITEM_LENGTH
#DIM DYNAMIC F_COL
#DIM DYNAMIC IS_CRAFTABLE = 1
#DIM DYNAMIC ERR_FLG
;生産関連変数
#DIM DYNAMIC 基準生産量
#DIM DYNAMIC 基準生産時間 = 30
#DIMS DYNAMIC 生産物名
#DIM DYNAMIC 生産時間
#DIM DYNAMIC 生産回数 = 1
#DIMS DYNAMIC 現在時刻
#DIMS DYNAMIC 完了予定時刻
;武器関連変数
#DIMS DYNAMIC WEAPON_NAME
#DIM DYNAMIC WEAPON_ID
#DIM DYNAMIC 材質種類
#DIM DYNAMIC WPN_MATERIAL_NEEDS, WPN_材質種類数, ITEM_LENGTH
#DIM DYNAMIC PASSIVE_SKILL_SLOT
#DIM DYNAMIC ACTIVE_SKILL_SLOT

#DIMS CONST  WPN_STATUS_NAME_SHORT = "攻撃", "防御", "軽減", "魔力", "行動", "敵視", "選敵"
#DIM  DYNAMIC COLUMN_LENGTH = 14, 14, 14, 14, 14, 14, 16
#DIM  DYNAMIC STATUS_IDX
;ステータスの表示順序
{
    #DIMS CONST COLUMN_ORDER =
        "ATTACK"
        , "DEFENCE"
        , "ARMOR"
        , "MAG"
        , "AGILITY"
        , "HATE_RATE"
        , "TARGETING"
}

;ウィンドウ作成
CALL WndMgr_CreateWindow(WINDOW_ID, 66, 5, WND_WIDTH, WND_HEIGHT, 2)
CALL WndMgr_Attribute(WINDOW_ID, "BorderColor", カラー_選択不可)
SIF HO_ITEM_CRAFT_SELECT_ITEM_ID == -1
    RETURN

ITEM_ID = HO_ITEM_CRAFT_SELECT_ITEM_ID
IF ITEM_ID >= 1000000
    ITEM_ID -= 1000000
    IS_CRAFTABLE = 0
ENDIF

;1-3桁目 WEAPON_ID
;4-5桁目 材質種類
WEAPON_ID = ITEM_ID % 1000
材質種類   = ITEM_ID / 1000
;武器名
CALL GET_WEAPON_NAME(WEAPON_ID)
WEAPON_NAME '= @"%WPN_材質別接頭文字:材質種類%の%RESULTS%"
;ステータス取得
CALL GET_WEAPON_STATUS(WEAPON_ID, 材質種類)

;ヘッダー
CALL GET_ITEM_NAME(ITEM_ID)
ITEM_NAME = %RESULTS%
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@S:1@@C:{カラー_注釈}@◇　%WEAPON_NAME%　◇@/C@@/S@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@・ステータス@/C@")
LOCALS '= ""
FOR LOCAL, 0, WPN_MAX_STATUSNUM
    STATUS_IDX = FINDELEMENT(WPN_STATUS_NAME_ENG, COLUMN_ORDER:LOCAL)
    IF STATUS_IDX != WPN_脅威選定
        LOCALS += TAG_PRINT_SHAPE(@"@C:{カラー_白}@%WPN_STATUS_NAME_SHORT:LOCAL%:{WPN_STATUS:STATUS_IDX}@/C@", COLUMN_LENGTH:LOCAL, 1)
    ELSE
        LOCALS += TAG_PRINT_SHAPE(@"@C:{カラー_白}@%WPN_STATUS_NAME_SHORT:LOCAL%:%WPN_脅威選定文字列:(WPN_STATUS:STATUS_IDX)%@/C@", COLUMN_LENGTH:LOCAL, 1)
    ENDIF
NEXT
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"　%LOCALS%")

TRYCCALLFORM GET_WEAPON_SKILL_SLOT_{WEAPON_ID}(材質種類)
    PASSIVE_SKILL_SLOT = RESULT:0
    ACTIVE_SKILL_SLOT = RESULT:1
    L_CNT ++
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@・スキルスロット数@/C@")
    LOCALS '= @"@C:{カラー_オレンジ}@　ACTIVE :@/C@%"□"* (ACTIVE_SKILL_SLOT)%"
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, LOCALS)
    LOCALS '=  @"@C:{カラー_黄緑}@　PASSIVE:@/C@%"□"* (PASSIVE_SKILL_SLOT)%"
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, LOCALS)
CATCH
ENDCATCH

;生産情報
L_CNT ++
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@S:1@@C:{カラー_注釈}@◇　生産情報　◇@/S@@/C@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@・要求素材@/C@")
L_CNT ++
CALL GET_WEAPON_MATERIAL_NEEDS(WEAPON_ID, 材質種類, WPN_MATERIAL_NEEDS)
FOR LOCAL:0, 0, ITEM_LENGTH
    IF WPN_MATERIAL_NEEDS:材質種類:(LOCAL:0) > 0
        CALL GET_ITEM_NAME(LOCAL:0)
        MATERIAL_NAME = %RESULTS%
        LOCALS = %TAG_PRINT_SHAPE(@"　　@C:{カラー_白}@%MATERIAL_NAME%@/C@", 24, 1, 0)%
        LOCALS += @"× {WPN_MATERIAL_NEEDS:材質種類:(LOCAL:0)}"
        LOCALS += @"@C:{カラー_選択不可}@　(所持:{HO_ITEM_STOCK:(LOCAL:0)})@/C@"
        CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, LOCALS)
        L_CNT ++
    ENDIF
NEXT

SIF !IS_CRAFTABLE
    RETURN

;生産時間
現在時刻 '= @"{HO_TIME / 60}:%TOSTR(HO_TIME % 60, "00")%"
生産時間 = 基準生産時間 * 生産回数
完了予定時刻 '= @"{(HO_TIME + 生産時間) / 60}:%TOSTR((HO_TIME + 生産時間) % 60, "00")%"
L_CNT = 25
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@・生産回数@/C@")
L_CNT ++
CALL WndMgr_TextSet(WINDOW_ID, L_CNT, @"　　@C:{カラー_白}@生産回数:{生産回数}回　@/C@")
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"　　　　@C:{カラー_白}@⇒　所要時間:{生産時間}分 (%現在時刻% → %完了予定時刻%)@/C@")
L_CNT ++

;フッター
L_CNT = WND_HEIGHT - 4
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@B:{BTN_ID + 1}@@C:{カラー_白}@[クラフトする]@/C@@/B@")

HO_ITEM_CRAFT_WEAPON_NAME          = %WEAPON_NAME%
HO_ITEM_CRAFT_WEAPON_MATERIAL      = 材質種類
HO_ITEM_CRAFT_NUM_PRODUCTION       = 生産回数
HO_ITEM_CRAFT_PRODUCTION_TIME      = 生産時間

;-------------------------------------------------
;衣装
;-------------------------------------------------
@HO_DRAW_CRAFT_ITEM_WINDOW_PRINT_DETAIL_CLOTH(WINDOW_ID, MODULE_ID)
#DIM WINDOW_ID
#DIM MODULE_ID
#DIM CONST HEADER_NUM = 6
#DIM CONST MAX_ROW = 26
#DIM CONST BTN_ID = 1000000

#DIM  DYNAMIC WND_WIDTH
#DIM  DYNAMIC WND_HEIGHT
#DIMS DYNAMIC DETAIL_LIST, ITEM_LENGTH
#DIM  DYNAMIC ITEM_NUM
#DIM  DYNAMIC L_CNT
#DIM  DYNAMIC PAGE_NUM
#DIMS DYNAMIC STR_FOOTER
#DIM  DYNAMIC DETAIL_LINECOUNT
;アイテム関連
#DIMS DYNAMIC ITEM_NAME
#DIM  DYNAMIC MATERIAL_NEEDS, ITEM_LENGTH
#DIM  DYNAMIC ITEM_ID
#DIM  DYNAMIC IS_CRAFTABLE
;衣装関連
#DIM 部位

部位 = HO_ITEM_CRAFT_SELECT_CLOTH_PARTS
;明細リスト作成
DETAIL_LINECOUNT = 0
L_CNT = 0
;衣装の0番は"なし"なので1からスタート
FOR ITEM_ID, 1, ITEM_LENGTH
    CALL GET_CLOTH_MATERIAL_NEEDS(部位, ITEM_ID, MATERIAL_NEEDS)
    IS_CRAFTABLE = 1
    FOR LOCAL:1, 0, ITEM_LENGTH
        ;アイテム在庫が要求を満たさない場合、表示はするが作成は不可に
        IF MATERIAL_NEEDS:(LOCAL:1) > 0 && (HO_ITEM_STOCK:(LOCAL:1) < MATERIAL_NEEDS:(LOCAL:1))
            IS_CRAFTABLE = 0
        ENDIF
    NEXT
    CALL GET_CLOTH_NAME(部位, ITEM_ID)
    IF RESULT
        ITEM_NAME = %RESULTS%
        IF IS_CRAFTABLE
            DETAIL_LIST:DETAIL_LINECOUNT '= @"@B:{BTN_ID + ITEM_ID}@@C:{カラー_白}@[%ITEM_NAME%]@/C@@/B@"
        ELSE
            DETAIL_LIST:DETAIL_LINECOUNT '= @"@B:{BTN_ID + ITEM_ID + 1000000}@@C:{カラー_選択不可}@[%ITEM_NAME%]@/C@@/B@"
        ENDIF
        DETAIL_LIST:DETAIL_LINECOUNT = %TAG_PRINT_SHAPE(DETAIL_LIST:DETAIL_LINECOUNT, 28, 1, 0)%
        DETAIL_LINECOUNT ++
    ENDIF
    ; ELSE
    ;     CONTINUE
    ; ENDIF
NEXT

PAGE_NUM = DETAIL_LINECOUNT / MAX_ROW

;明細リスト出力
L_CNT = 0
FOR LOCAL, MAX_ROW * HO_ITEM_CRAFT_PAGE_LEFT, MAX_ROW * (HO_ITEM_CRAFT_PAGE_LEFT + 1)
    IF  L_CNT / MAX_ROW <= 0
        CALL WndMgr_TextSet(WINDOW_ID, L_CNT + HEADER_NUM, DETAIL_LIST:LOCAL)
        L_CNT++
    ELSE
        CALL WndMgr_TextAdd(WINDOW_ID, (L_CNT % MAX_ROW) + HEADER_NUM, DETAIL_LIST:LOCAL)
        L_CNT ++
    ENDIF
    L_CNT ++
NEXT

;フッター
CALL WndMgr_GetRectangle(WINDOW_ID)
WND_WIDTH  = RESULT:2
WND_HEIGHT = RESULT :3
L_CNT = WND_HEIGHT - 4
IF PAGE_NUM > 0
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
    STR_FOOTER += HO_ITEM_CRAFT_PAGE_LEFT > 0 ? @"@B:9000@<<@/B@ " # "   "
    STR_FOOTER += @"%TOSTR(HO_ITEM_CRAFT_PAGE_LEFT + 1, "..")% "
    STR_FOOTER += HO_ITEM_CRAFT_PAGE_LEFT != PAGE_NUM ? @"@B:9001@>>@/B@" # "  "
    CALLF TAG_PRINT_SHAPE(STR_FOOTER, WND_WIDTH - 8, 1, 2)
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@%RESULTS%@/C@")
ENDIF

@HO_DRAW_CRAFT_ITEM_WINDOW_RIGHT_CLOTH(MODULE_ID)
#DIM MODULE_ID
#DIM CONST WINDOW_ID = 2
#DIM CONST WND_WIDTH  = 102
#DIM CONST WND_HEIGHT = 37
#DIM CONST ヘッダー行数 = 2
#DIM CONST BTN_ID = 2000
#DIM DYNAMIC L_CNT

#DIM  DYNAMIC ITEM_ID
#DIMS DYNAMIC ITEM_NAME
#DIMS DYNAMIC MATERIAL_NAME
#DIM DYNAMIC MATERIAL_NEEDS, ITEM_LENGTH
#DIM DYNAMIC F_COL
#DIM DYNAMIC IS_CRAFTABLE = 1
#DIM DYNAMIC ERR_FLG
;生産関連変数
#DIM DYNAMIC  基準生産量   = 1
#DIM DYNAMIC  基準生産時間 = 30
#DIMS DYNAMIC 生産物名
#DIM DYNAMIC  生産時間
#DIM DYNAMIC  生産回数
#DIMS DYNAMIC 現在時刻
#DIMS DYNAMIC 完了予定時刻
;武器関連変数
#DIMS DYNAMIC WEAPON_NAME
#DIM DYNAMIC WEAPON_ID
#DIM DYNAMIC 材質種類
#DIM DYNAMIC WPN_MATERIAL_NEEDS, WPN_材質種類数, ITEM_LENGTH
;衣装関連
#DIM 部位

部位            = HO_ITEM_CRAFT_SELECT_CLOTH_PARTS
生産回数        = HO_ITEM_CRAFT_NUM_PRODUCTION

;ウィンドウ作成
CALL WndMgr_CreateWindow(WINDOW_ID, 66, 5, WND_WIDTH, WND_HEIGHT, 2)
CALL WndMgr_Attribute(WINDOW_ID, "BorderColor", カラー_選択不可)
SIF HO_ITEM_CRAFT_SELECT_ITEM_ID == -1
    RETURN

ITEM_ID = HO_ITEM_CRAFT_SELECT_ITEM_ID
IF ITEM_ID >= 1000000
    ITEM_ID -= 1000000
    IS_CRAFTABLE = 0
ENDIF

WEAPON_ID = ITEM_ID % 1000
材質種類   = ITEM_ID / 1000

;アイテム名
CALL GET_CLOTH_NAME(部位, ITEM_ID)
ITEM_NAME = %RESULTS%
生産回数   = HO_ITEM_CRAFT_NUM_PRODUCTION

;ヘッダー
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@S:1@@C:{カラー_注釈}@◇　%ITEM_NAME%　◇@/C@@/S@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

;概要欄
; VARSET RESULTS
; FOR LOCAL, 0, 10
;     TRYCALLFORM GET_ITEM_DESCRIPTION_{ITEM_ID}
;     CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"　%RESULTS:LOCAL%")
; NEXT
L_CNT += 4

;備考欄
L_CNT++
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@S:1@@C:{カラー_注釈}@◇　生産情報　◇@/S@@/C@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@・要求素材@/C@")
L_CNT ++
;材料は暫定で固定
CALL GET_CLOTH_MATERIAL_NEEDS(部位, ITEM_ID, MATERIAL_NEEDS)
FOR LOCAL:0, 0, ITEM_LENGTH
    IF MATERIAL_NEEDS:(LOCAL:0) > 0
        CALL GET_ITEM_NAME(LOCAL:0)
        MATERIAL_NAME = %RESULTS%
        LOCALS = %TAG_PRINT_SHAPE(@"　　@C:{カラー_白}@%MATERIAL_NAME%@/C@", 24, 1, 0)%
        LOCALS += @"× {(MATERIAL_NEEDS:(LOCAL:0)* 生産回数)}"
        LOCALS += @"@C:{カラー_選択不可}@　(所持:{HO_ITEM_STOCK:(LOCAL:0)})@/C@"
        CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, LOCALS)
        L_CNT ++
    ENDIF
NEXT

SIF !IS_CRAFTABLE
    RETURN

;生産対象の情報を取得
; CALL GET_ITEM_INFO(ITEM_ID, ITEM_基準生産量)
; 基準生産量 = RESULT
現在時刻 '= @"{HO_TIME / 60}:%TOSTR(HO_TIME % 60, "00")%"
生産時間 = 基準生産時間 * 生産回数
完了予定時刻 '= @"{(HO_TIME + 生産時間) / 60}:%TOSTR((HO_TIME + 生産時間) % 60, "00")%"

;;生産回数と時間
;生産回数設定ボタン
;生産量増減時のエラーチェック
FOR LOCAL:0, 0, ITEM_LENGTH
    IF (MATERIAL_NEEDS:(LOCAL:0) * (生産回数 + 1)) > HO_ITEM_STOCK:(LOCAL:0)
        ERR_FLG ++
    ENDIF
    IF HO_TIME + 基準生産時間 * (生産回数 + 1) > HO_CLOCK(2700)
        ERR_FLG ++
    ENDIF
NEXT

L_CNT ++
IF 生産回数 > 1
    LOCALS '= @"@B:{BTN_ID + 3}@[-]@/B@ "
ELSE
    LOCALS '= @"@C:{カラー_選択不可}@[-]@/C@ "
ENDIF
IF !ERR_FLG && 生産回数 < 10
    LOCALS += @"@B:{BTN_ID + 2}@[+]@/B@ "
ELSE
    LOCALS += @"@C:{カラー_選択不可}@[+]@/C@ "
ENDIF

L_CNT = 25
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@・生産回数@/C@")
L_CNT ++
CALL WndMgr_TextSet(WINDOW_ID, L_CNT, @"　　@C:{カラー_白}@生産回数:{生産回数}回　@/C@%LOCALS%")
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"　　　　@C:{カラー_白}@⇒　所要時間:{生産時間}分 (%現在時刻% → %完了予定時刻%)@/C@")
L_CNT ++
;生産対象の情報を印字
L_CNT ++
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@・生産物@/C@")
L_CNT ++
LOCALS = %TAG_PRINT_SHAPE(@"　　　　@C:{カラー_注意}@⇒　%ITEM_NAME%@/C@", 36, 1, 0)%
LOCALS += @"× {基準生産量 * 生産回数}"
LOCALS += @"@C:{カラー_選択不可}@　(所持:{HAVE_CLOTH:部位:ITEM_ID})@/C@"
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注意}@%LOCALS%@/C@")

;フッター
L_CNT = WND_HEIGHT - 4
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@B:{BTN_ID + 1}@@C:{カラー_白}@[クラフトする]@/C@@/B@")

HO_ITEM_CRAFT_BASE_PRODUCTION_RATE = 基準生産量
HO_ITEM_CRAFT_NUM_PRODUCTION       = 生産回数
HO_ITEM_CRAFT_PRODUCTION_TIME      = 生産時間

@HO_DRAW_CRAFT_ORDER_WINDOW()
#DIM CONST WND_WIDTH  = 140
#DIM CONST WND_HEIGHT = 40
#DIM CONST WND_POS_X = 10
#DIM CONST WND_POS_Y = 4
#DIM  DYNAMIC WINDOW_ID
#DIM  DYNAMIC L_CNT
#DIM  DYNAMIC F_COL

#DIM  DYNAMIC MODULE_LIST_IDX
#DIM  DYNAMIC ITEM_ID
#DIMS DYNAMIC ITEM_NAME
#DIM  DYNAMIC MATERIAL_NEEDS, ITEM_LENGTH
#DIMS DYNAMIC TOOLTIP

#DIM  DYNAMIC RECIPE_NO
#DIM  DYNAMIC TARGET_NUM
#DIM  DYNAMIC IS_ACTIVE
#DIM  DYNAMIC IDX

#DIMS DYNAMIC MODULE_NAME
#DIM  DYNAMIC MODULE_ID

#DIM  DYNAMIC REGISTED_CRAFT_ORDER, MAX_CRAFT_ORDER

CALL WndMgr_VacantId()
WINDOW_ID = RESULT

CALL WndMgr_CreateWindow(WINDOW_ID, WND_POS_X, WND_POS_Y, WND_WIDTH, WND_HEIGHT, 2)

MODULE_LIST_IDX = HO_MASTER_USE_MODULE_LIST_IDX
ITEM_ID = TOINT(DIC_GET(HO_ITEM_CRAFT_DIC_CRAFT_ORDER, "CRAFT_ORDER"))
RECIPE_NO = TOINT(DIC_GET(HO_ITEM_CRAFT_DIC_CRAFT_ORDER, "RECIPE_NO"))
CALL HO_GET_MODULE_LIST(MODULE_LIST_IDX, "MODULE_ID")
MODULE_ID = RESULT
CALL HO_GET_MODULE_DATA(MODULE_ID, "MODULE_NAME")
MODULE_NAME = %RESULTS%
CALL GET_ITEM_NAME(ITEM_ID)
ITEM_NAME = %RESULTS%

;ヘッダー
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"◆以下の作業指示を登録します。登録先を選択してください")
L_CNT ++
LOCALS '= @"%MODULE_NAME%で%ITEM_NAME%を生産(レシピ{RECIPE_NO + 1})"
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT++, LOCALS)
L_CNT ++
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

;明細行
DT_SELECT "CRAFT_ORDER",,, REGISTED_CRAFT_ORDER
FOR LOCAL, 0, RESULT
    ;情報取得
    MODULE_LIST_IDX = DT_CELL_GET("CRAFT_ORDER", REGISTED_CRAFT_ORDER:LOCAL, "MODULE_LIST_IDX", 1)
    ITEM_ID = DT_CELL_GET("CRAFT_ORDER", REGISTED_CRAFT_ORDER:LOCAL, "ITEM_ID", 1)
    RECIPE_NO = DT_CELL_GET("CRAFT_ORDER", REGISTED_CRAFT_ORDER:LOCAL, "RECIPE_NO", 1)
    TARGET_NUM = DT_CELL_GET("CRAFT_ORDER", REGISTED_CRAFT_ORDER:LOCAL, "TARGET_NUM", 1)
    IS_ACTIVE = DT_CELL_GET("CRAFT_ORDER", REGISTED_CRAFT_ORDER:LOCAL, "IS_ACTIVE", 1)
    CALL HO_GET_MODULE_LIST(MODULE_LIST_IDX, "MODULE_ID")
    MODULE_ID = RESULT
    CALL HO_GET_MODULE_DATA(MODULE_ID, "MODULE_NAME")
    MODULE_NAME = %RESULTS%
    CALL GET_ITEM_NAME(ITEM_ID)
    ITEM_NAME = %RESULTS%

    ;ツールチップ生成
    CALL GET_ITEM_MATERIAL_NEEDS(ITEM_ID, MATERIAL_NEEDS, RECIPE_NO)
    CALL HO_GET_MATERIAL_NEEDS_STR(MATERIAL_NEEDS)
    TOOLTIP '= "◆必要コスト<br>"
    TOOLTIP += RESULTS
    ;文字列出力
    LOCALS '= @"[%TOSTR(IDX + 1, "00")%] %MODULE_NAME%で%ITEM_NAME%を生産"
    LOCALS += @"@B:DUMMY$%TOOLTIP%@(レシピ{RECIPE_NO + 1})@/B@"
    LOCALS '= TAG_PRINT_SHAPE(LOCALS, 50, 1, 0)
    IF TARGET_NUM == 0
        LOCALS += @"　可能な限り"
    ELSE
        LOCALS += @"　在庫が{TARGET_NUM}個になるまで"
    ENDIF
    LOCALS += @"@C:{カラー_選択不可}@(現在:{HO_ITEM_STOCK:ITEM_ID}個)@/C@"
    LOCALS '= TAG_PRINT_SHAPE(LOCALS, 100, 1, 0)
    LOCALS += @"　@B:[REPLACE_ORDER:{REGISTED_CRAFT_ORDER:LOCAL}]@[上書]@/B@"
    LOCALS += @"　@B:[DELETE_ORDER:{REGISTED_CRAFT_ORDER:LOCAL}]@[削除]@/B@"
    LOCALS += @"　@B:[SET_TARGET_NUM:{REGISTED_CRAFT_ORDER:LOCAL}]@[生産量設定]@/B@"

    CALL WndMgr_TextAdd(WINDOW_ID, L_CNT++, LOCALS)
    L_CNT++
    IDX ++
NEXT
L_CNT++
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"[%TOSTR(IDX + 1, "00")%]@C:{カラー_白}@@B:[ADD_ORDER:1]@ [追加]@/B@@/C@")

;フッター
L_CNT = WND_HEIGHT - 4
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@B:[EXIT:1]@　[決定]@/B@")

@HO_ADD_CRAFT_ORDER()
#DIM DYNAMIC ITEM_ID
#DIM DYNAMIC RECIPE_NO
#DIM DYNAMIC MODULE_LIST_IDX

DT_SELECT "CRAFT_ORDER"
IF RESULT == MAX_CRAFT_ORDER
    CALL COLOR_PRINTW("登録可能な指示が上限に達しています", カラー_注意)
    RETURN 0
ENDIF

MODULE_LIST_IDX = HO_MASTER_USE_MODULE_LIST_IDX
ITEM_ID = TOINT(DIC_GET(HO_ITEM_CRAFT_DIC_CRAFT_ORDER, "CRAFT_ORDER"))
RECIPE_NO = TOINT(DIC_GET(HO_ITEM_CRAFT_DIC_CRAFT_ORDER, "RECIPE_NO"))
{
    DT_ROW_ADD "CRAFT_ORDER"
        ,"ITEM_ID", ITEM_ID
        ,"MODULE_LIST_IDX", MODULE_LIST_IDX
        ,"RECIPE_NO", RECIPE_NO
        ,"TARGET_NUM", 0
        ,"IS_ACTIVE", 1
}
RETURN RESULT

@HO_REPLACE_CRAFT_ORDER(DATAIDX)
#DIM DATAIDX
#DIM DYNAMIC ITEM_ID
#DIM DYNAMIC RECIPE_NO
#DIM DYNAMIC MODULE_LIST_IDX

CALL COLOR_PRINTL("既に登録済みの指示を上書きします。よろしいですか？", カラー_注意)
CALL ASK_YN()
IF RESULT
    RETURN 0
ENDIF

MODULE_LIST_IDX = HO_MASTER_USE_MODULE_LIST_IDX
ITEM_ID = TOINT(DIC_GET(HO_ITEM_CRAFT_DIC_CRAFT_ORDER, "CRAFT_ORDER"))
RECIPE_NO = TOINT(DIC_GET(HO_ITEM_CRAFT_DIC_CRAFT_ORDER, "RECIPE_NO"))
{
    DT_ROW_SET "CRAFT_ORDER", DATAIDX
        ,"ITEM_ID", ITEM_ID
        ,"MODULE_LIST_IDX", MODULE_LIST_IDX
        ,"RECIPE_NO", RECIPE_NO
        ,"TARGET_NUM", 0
        ,"IS_ACTIVE", 1
}
RETURN RESULT

@HO_DELETE_CRAFT_ORDER(DATAIDX)
#DIM DATAIDX
#DIM DYNAMIC ITEM_ID
#DIM DYNAMIC RECIPE_NO
#DIM DYNAMIC MODULE_LIST_IDX

CALL COLOR_PRINTL("既に登録済みの指示を削除します。よろしいですか？", カラー_注意)
CALL ASK_YN()
IF RESULT
    RETURN 0
ENDIF

DT_ROW_REMOVE "CRAFT_ORDER", DATAIDX
RETURN RESULT

@HO_CRAFT_ORDER_SET_TARGET_NUM(DATAIDX)
#DIM DATAIDX
#DIM DYNAMIC ITEM_ID
#DIM DYNAMIC RECIPE_NO
#DIM DYNAMIC MODULE_LIST_IDX

CALL COLOR_PRINTL("目標生産数を設定してください(0～999,0で可能な限り生産)", カラー_注意)

WHILE 1
    INPUT
    IF !INRANGE(RESULT, 0, 999)
        PRINTFORMW 入力値が不正です
        CLEARLINE 2
    ELSE
        DT_CELL_SET "CRAFT_ORDER", DATAIDX, "TARGET_NUM", RESULT, 1
        RETURN RESULT
    ENDIF
WEND

@HO_REMOVE_CRAFT_ORDER(MODULE_LIST_IDX)
#DIM MODULE_LIST_IDX
#DIM DYNAMIC DID, MAX_CRAFT_ORDER
#DIM DYNAMIC CHARA_ID
#DIM DYNAMIC ITER_I
#DIM DYNAMIC ITER_J

;削除された設備に対応する作業指示を削除
DT_SELECT "CRAFT_ORDER", @"MODULE_LIST_IDX = {MODULE_LIST_IDX}",, DID
FOR ITER_I, 0, RESULT
    ;キャラクター側の作業指示を削除
    FOR CHARA_ID, 0, CHARANUM
        DT_ROW_REMOVE "CRAFT_ORDER", DID:ITER_I
        FOR ITER_J, 0, HO_TIMETABLENUM
            _LIST_HO_CRAFT_ORDER_DID:CHARA_ID:ITER_J = %LIST_REMOVEALL(_LIST_HO_CRAFT_ORDER_DID:CHARA_ID:ITER_J, TOSTR(DID:ITER_I))%
        NEXT
    NEXT
NEXT

RETURN


code:
@HO_DRAW_CRAFT_ITEM_WINDOW_RIGHT_WEAPON_ENCHANT(MODULE_ID)
; #region
#DIM MODULE_ID
#DIM CONST WINDOW_ID = 2
#DIM CONST WND_WIDTH  = 102
#DIM CONST WND_HEIGHT = 37
#DIM CONST ヘッダー行数 = 2
#DIM CONST BTN_ID = 2000
#DIM DYNAMIC L_CNT

#DIM  DYNAMIC ITEM_ID
#DIMS DYNAMIC ITEM_NAME
#DIMS DYNAMIC MATERIAL_NAME
#DIM DYNAMIC MATERIAL_NEEDS, ITEM_LENGTH
#DIM DYNAMIC F_COL
#DIM DYNAMIC IS_CRAFTABLE = 1
#DIM DYNAMIC ERR_FLG

;武器関連変数
#DIMS DYNAMIC WEAPON_PRINT_NAME
#DIMS DYNAMIC WEAPON_NAME
#DIM  DYNAMIC WEAPON_DID
#DIM  DYNAMIC WEAPON_ID
#DIM  DYNAMIC RUNE_DID
#DIMS DYNAMIC DIC_REMOVE_ENCHANT
#DIM  DYNAMIC WEAPON_RANK
#DIM  DYNAMIC MODIFIED_STATUS, WPN_MAX_STATUSNUM
#DIM  DYNAMIC STATUS_IDX
#DIM  DYNAMIC EQUIP_CHARA_ID
;スキル関連
#DIM DYNAMIC  PASSIVE_SKILL_SLOT
#DIM DYNAMIC  ACTIVE_SKILL_SLOT
#DIM  DYNAMIC PASSIVE_SKILL_SLOT_USED
#DIM  DYNAMIC ACTIVE_SKILL_SLOT_USED
#DIMS DYNAMIC SKILL_DEF_NAME
#DIMS DYNAMIC SKILL_NAME
#DIM  DYNAMIC SKILL_LV
#DIM  DYNAMIC WPN_SKILL_GENRE
#DIMS DYNAMIC TOOLTIP
#DIM  DYNAMIC AMOUNT
#DIM  DYNAMIC COST

#DIM  DYNAMIC PARAM_DIFF
#DIMS CONST  WPN_STATUS_NAME_SHORT = "攻撃", "防御", "軽減", "魔力", "行動", "敵視", "選敵"
#DIM  DYNAMIC COLUMN_LENGTH = 14, 14, 14, 14, 14, 14, 16
;ステータスの表示順序
{
    #DIMS CONST COLUMN_ORDER =
        "ATTACK"
        , "DEFENCE"
        , "ARMOR"
        , "MAG"
        , "AGILITY"
        , "HATE_RATE"
        , "TARGETING"
}

;ウィンドウ作成
CALL WndMgr_CreateWindow(WINDOW_ID, 66, 5, WND_WIDTH, WND_HEIGHT, 2)
CALL WndMgr_Attribute(WINDOW_ID, "BorderColor", カラー_選択不可)
SIF HO_ITEM_CRAFT_SELECT_ITEM_ID == -1
    RETURN

WEAPON_DID = HO_ITEM_CRAFT_SELECT_ITEM_ID
RUNE_DID = HO_ITEM_CRAFT_SELECT_RUNE_ID
DIC_REMOVE_ENCHANT = %HO_ITEM_CRAFT_DIC_REMOVE_ENCHANT%

;武器名
CALL GET_WEAPON_STOCK_TABLE(WEAPON_DID, "WEAPON_NAME")
WEAPON_NAME = %RESULTS%
CALL GET_WEAPON_PRINT_NAME(WEAPON_DID)
WEAPON_PRINT_NAME = %RESULTS%
CALL GET_WEAPON_STOCK_TABLE(WEAPON_DID, "EQUIP_CHARA_ID")
EQUIP_CHARA_ID = RESULT
CALL GET_WEAPON_STOCK_TABLE(WEAPON_DID, "WEAPON_RANK")
WEAPON_RANK = RESULT
CALL GET_WEAPON_STOCK_TABLE(WEAPON_DID, "PASSIVE_SKILL_SLOT")
PASSIVE_SKILL_SLOT = RESULT
CALL GET_WEAPON_STOCK_TABLE(WEAPON_DID, "ACTIVE_SKILL_SLOT")
ACTIVE_SKILL_SLOT = RESULT
CALL GET_WEAPON_STOCK_TABLE(WEAPON_DID, "PASSIVE_SKILL_SLOT_USED")
PASSIVE_SKILL_SLOT_USED = RESULT
CALL GET_WEAPON_STOCK_TABLE(WEAPON_DID, "ACTIVE_SKILL_SLOT_USED")
ACTIVE_SKILL_SLOT_USED = RESULT

;改造前の武器ステータス取得
VARSET WPN_STATUS
FOR STATUS_IDX, 0, VARSIZE("WPN_STATUS_NAME_ENG")
    DT_CELL_GET "WEAPON_STOCK", WEAPON_DID, WPN_STATUS_NAME_ENG:STATUS_IDX, 1
    WPN_STATUS:STATUS_IDX = RESULT
NEXT
;改良後ステータス取得
CALL GET_WEAPON_MODIFIED_STATUS(WPN_STATUS, MODIFIED_STATUS)
CALL GET_WEAPON_MODIFY_COST(MATERIAL_NEEDS, WEAPON_RANK)
SIF !RESULT
    IS_CRAFTABLE = 0

;スキルルーンの情報取得
IF RUNE_DID != -1
    CALL RUNE_STOCK_GET_TABLE_DATA(RUNE_DID, "SKILL_DEF_NAME")
    SKILL_DEF_NAME = %RESULTS%
    CALL RUNE_STOCK_GET_TABLE_DATA(RUNE_DID, "SKILL_LV")
    SKILL_LV = RESULT
    CALL RUNE_STOCK_GET_TABLE_DATA(RUNE_DID, "AMOUNT")
    AMOUNT = RESULT
    CALL RUNE_STOCK_GET_TABLE_DATA(RUNE_DID, "WPN_SKILL_GENRE")
    WPN_SKILL_GENRE = RESULT
    CALL SKILL_GET_NAME(WPN_SKILL_GENRE, SKILL_DEF_NAME, 1)
    SKILL_NAME = %RESULTS%
    CALL GET_SKILL_DESC(SKILL_DEF_NAME, WPN_SKILL_GENRE, SKILL_LV, 1)
    TOOLTIP = %RESULTS%
ENDIF

;印字部
;ヘッダー
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@S:1@@C:{カラー_注釈}@◇　%WEAPON_PRINT_NAME%　◇@/C@@/S@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))

;ステータス欄
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@・現在のステータス@/C@")
LOCALS '= ""
FOR LOCAL, 0, WPN_MAX_STATUSNUM
    STATUS_IDX = FINDELEMENT(WPN_STATUS_NAME_ENG, COLUMN_ORDER:LOCAL)
    IF STATUS_IDX != WPN_脅威選定
        LOCALS += TAG_PRINT_SHAPE(@"@C:{カラー_白}@%WPN_STATUS_NAME_SHORT:LOCAL%:{WPN_STATUS:STATUS_IDX}@/C@", COLUMN_LENGTH:LOCAL, 1)
    ELSE
        LOCALS += TAG_PRINT_SHAPE(@"@C:{カラー_白}@%WPN_STATUS_NAME_SHORT:LOCAL%:%WPN_脅威選定文字列:(WPN_STATUS:STATUS_IDX)%@/C@", COLUMN_LENGTH:LOCAL, 1)
    ENDIF
NEXT

CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"　%LOCALS%")
IF EQUIP_CHARA_ID >= 0
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"　装備者:%ANAME(EQUIP_CHARA_ID)%")
ELSE
    L_CNT ++
ENDIF

;付与されているスキル
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@・現在の装備スキル@/C@")
;アクティブスキル
CALL GET_EQUIP_SKILL_LIST_STR(WEAPON_DID, 武器スキル_アクティブ)
IF RESULTS != ""
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_オレンジ}@　ACTIVE :@/C@%RESULTS%")
ENDIF
;パッシブスキル
CALL GET_EQUIP_SKILL_LIST_STR(WEAPON_DID, 武器スキル_パッシブ)
IF RESULTS != ""
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_黄緑}@　PASSIVE:@/C@%RESULTS%")
ENDIF

;スキルスロット
L_CNT ++
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@・空スキルスロット数@/C@")
LOCALS '= @"@C:{カラー_オレンジ}@　ACTIVE :@/C@%"■"* ACTIVE_SKILL_SLOT_USED%%"□"* (ACTIVE_SKILL_SLOT - ACTIVE_SKILL_SLOT_USED)%"
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, LOCALS)
LOCALS '=  @"@C:{カラー_黄緑}@　PASSIVE:@/C@%"■"* PASSIVE_SKILL_SLOT_USED%%"□"* (PASSIVE_SKILL_SLOT - PASSIVE_SKILL_SLOT_USED)%"
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, LOCALS)

;付呪情報欄
L_CNT ++
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@S:1@@C:{カラー_注釈}@◇　付呪情報　◇@/S@@/C@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"　%WEAPON_NAME%@")
L_CNT ++

;アクティブスキル
CALL ENCHANT_GET_EQUIP_SKILL_LIST_STR(WEAPON_DID, 武器スキル_アクティブ)
IF RESULTS != ""
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT, @"@C:{カラー_オレンジ}@　ACTIVE :@/C@%RESULTS%")
    IF ACTIVE_SKILL_SLOT > 0
        IF RUNE_DID != -1 && HO_ITEM_CRAFT_SELECT_RUNE_GENRE == 武器スキル_アクティブ
            CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"@B:[SELECT_RUNE:{武器スキル_アクティブ}]$%TOOLTIP%@@C:{カラー_注意}@⇒<%SKILL_NAME%Lv{SKILL_LV}>@/B@@/C@")
        ELSEIF RUNE_DID == -1
            IF ACTIVE_SKILL_SLOT - ACTIVE_SKILL_SLOT_USED > 0
                CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @" @B:[SELECT_RUNE:{武器スキル_アクティブ}]@[+]@/B@")
            ENDIF
        ENDIF
    ENDIF
    L_CNT ++
ENDIF
;パッシブスキル
CALL ENCHANT_GET_EQUIP_SKILL_LIST_STR(WEAPON_DID, 武器スキル_パッシブ)
IF RESULTS != ""
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT, @"@C:{カラー_黄緑}@　PASSIVE:@/C@%RESULTS%")
    IF PASSIVE_SKILL_SLOT > 0
        IF RUNE_DID != -1 && HO_ITEM_CRAFT_SELECT_RUNE_GENRE == 武器スキル_パッシブ
            CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"@B:[SELECT_RUNE:{武器スキル_パッシブ}]$%TOOLTIP%@@C:{カラー_注意}@⇒<%SKILL_NAME%Lv{SKILL_LV}>@/B@@/C@")
        ELSEIF RUNE_DID == -1
            IF PASSIVE_SKILL_SLOT - PASSIVE_SKILL_SLOT_USED > 0
                CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @" @B:[SELECT_RUNE:{武器スキル_パッシブ}]@[+]@/B@")
            ENDIF
        ENDIF
    ENDIF
    L_CNT ++
ENDIF

VARI REMOVE_ENCHANT_MODE
IF RUNE_DID != -1
    ;付呪
    CALL EQUIP_GET_COST_FOR_ENCHANT(WEAPON_DID, SKILL_DEF_NAME, WPN_SKILL_GENRE, SKILL_LV)
    COST = RESULT
    L_CNT ++
    L_CNT ++
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@・消費ルーン@/C@")
    LOCALS = %TAG_PRINT_SHAPE(@"　　@C:{カラー_注意}@<%SKILL_NAME%Lv{SKILL_LV}>@", 24, 1, 0)%
    IF COST > AMOUNT
        LOCALS += @"× @C:{カラー_オレンジ}@{COST}@/C@"
    ELSE
        LOCALS += @"× @C:{カラー_白}@{COST}@/C@"
    ENDIF
    LOCALS += @"@C:{カラー_選択不可}@　(所持:{AMOUNT})@/C@"
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, LOCALS)
ELSEIF DIC_CONTAINSKEY(DIC_REMOVE_ENCHANT, "REMOVE_ENCHANT")
    ;解呪対象の情報取得
    VARS STR_GENRE
    VARS SKILL_SLOT_USED_SKILL
    SKILL_DEF_NAME = %DIC_GET(DIC_REMOVE_ENCHANT, "REMOVE_ENCHANT")%
    WPN_SKILL_GENRE = WPN_SKILL_GET_GENRE(SKILL_DEF_NAME)
    STR_GENRE '= WPN_SKILL_GENRE == 武器スキル_アクティブ ? "ACTIVE" # "PASSIVE"
    SKILL_SLOT_USED_SKILL = %DT_CELL_GETS("WEAPON_STOCK", WEAPON_DID, @"%STR_GENRE%_SKILL_SLOT_USED_SKILL_NAME", 1)%
    SKILL_LV = DIC_GETINT(SKILL_SLOT_USED_SKILL, SKILL_DEF_NAME)
    SKILL_NAME = %TOHALF(GET_WPN_SKILL_NAME(SKILL_DEF_NAME, WPN_SKILL_GENRE))%
    AMOUNT = RUNE_STOCK_GET_AMOUNT(SKILL_DEF_NAME, SKILL_LV)
    COST = 1
    REMOVE_ENCHANT_MODE = 1
    ;メッセージ表示部
    L_CNT ++
    L_CNT ++
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@・解呪対象スキル・返却ルーン@/C@")
    LOCALS = %TAG_PRINT_SHAPE(@"　　@C:{カラー_注意}@<%SKILL_NAME%Lv{SKILL_LV}>@", 24, 1, 0)%
    LOCALS += @"× @C:{カラー_緑}@{COST}@/C@"
    LOCALS += @"@C:{カラー_選択不可}@　(所持:{AMOUNT})@/C@"
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, LOCALS)
ENDIF

;フッター
L_CNT = WND_HEIGHT - 4
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
IF RUNE_DID != -1 && COST <= AMOUNT
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT, @"@B:[EXEC_ENCHANT_WEAPON:{WEAPON_DID}]@@C:{カラー_白}@[付呪する]@/C@@/B@")
ELSEIF REMOVE_ENCHANT_MODE == 1
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT, @"@B:[EXEC_REMOVE_ENCHANT:{WEAPON_DID}]@@C:{カラー_白}@[解呪する]@/C@@/B@")
ELSE
    CALL WndMgr_TextSet(WINDOW_ID, L_CNT, @"@C:{カラー_選択不可}@[付呪する]@/C@")
ENDIF
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"　@B:[RENAME:1]@@C:{カラー_白}@[リネーム]@/C@@/B@")
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"　@B:[EXIT:1]@@C:{カラー_白}@[キャンセル]@/C@@/B@")
; #endregion

@HO_DRAW_CRAFT_ITEM_WINDOW_RIGHT_WEAPON_SELECT_RUNE(MODULE_ID)
; #region

#DIM MODULE_ID
#DIM CONST WINDOW_ID = 2
#DIM CONST WND_WIDTH  = 102
#DIM CONST WND_HEIGHT = 37
#DIM CONST ヘッダー行数 = 2
#DIM CONST BTN_ID = 2000
#DIM DYNAMIC L_CNT

#DIM  DYNAMIC ITEM_ID
#DIMS DYNAMIC ITEM_NAME
#DIMS DYNAMIC MATERIAL_NAME
#DIM DYNAMIC MATERIAL_NEEDS, ITEM_LENGTH
#DIM DYNAMIC F_COL
#DIM DYNAMIC IS_CRAFTABLE = 1
#DIM DYNAMIC ERR_FLG

;武器関連変数
#DIMS DYNAMIC WEAPON_PRINT_NAME
#DIMS DYNAMIC WEAPON_NAME
#DIM  DYNAMIC WEAPON_DID
#DIM  DYNAMIC WEAPON_ID
#DIM  DYNAMIC WEAPON_RANK
#DIM  DYNAMIC MODIFIED_STATUS, WPN_MAX_STATUSNUM
#DIM  DYNAMIC STATUS_IDX
#DIM  DYNAMIC EQUIP_CHARA_ID
#DIM DYNAMIC PASSIVE_SKILL_SLOT
#DIM DYNAMIC ACTIVE_SKILL_SLOT
#DIM  DYNAMIC PARAM_DIFF

;ウィンドウ作成
CALL WndMgr_CreateWindow(WINDOW_ID, 66, 5, WND_WIDTH, WND_HEIGHT, 2)
CALL WndMgr_Attribute(WINDOW_ID, "BorderColor", カラー_選択不可)
SIF HO_ITEM_CRAFT_SELECT_ITEM_ID == -1
    RETURN
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_注釈}@付呪するルーンを選択してください@/C@")
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
CALL HO_DRAW_ITEM_MENU_WINDOW_PRINT_DETAIL_RUNE(WINDOW_ID, "WEAPON_ENCHANT")
;フッター
L_CNT = WND_HEIGHT - 4
CALL WndMgr_TextSet(WINDOW_ID, L_CNT++, @"@C:{カラー_選択不可}@―@/C@" * ((WND_WIDTH / 2) - 2))
CALL WndMgr_TextAdd(WINDOW_ID, L_CNT, @"　@B:[SELECT_RUNE_EXIT:1]@@C:{カラー_白}@[戻る]@/C@@/B@")
; #endregion

;-------------------------------------------------
;;; 対象ルーンが選択可能か判定
;-------------------------------------------------
@HO_ITEM_CRAFT_CHECK_CAN_SELECT_RUNE()
#DIM  DYNAMIC WEAPON_DID
#DIM  DYNAMIC RUNE_DID
#DIMS DYNAMIC SKILL_DEF_NAME
#DIM  DYNAMIC WPN_SKILL_GENRE

WEAPON_DID = HO_ITEM_CRAFT_SELECT_ITEM_ID
RUNE_DID = HO_ITEM_CRAFT_SELECT_RUNE_ID

;スキルルーンの情報取得
CALL RUNE_STOCK_GET_TABLE_DATA(RUNE_DID, "SKILL_DEF_NAME")
SKILL_DEF_NAME = %RESULTS%
CALL RUNE_STOCK_GET_TABLE_DATA(RUNE_DID, "WPN_SKILL_GENRE")
WPN_SKILL_GENRE = RESULT

CALL EQUIP_CAN_ADD_SKILL(WEAPON_DID, SKILL_DEF_NAME, WPN_SKILL_GENRE)
RETURN RESULT

;-------------------------------------------------
;;; 付呪処理実行
;-------------------------------------------------
@HO_ITEM_CRAFT_EXEC_ENCHANT_WEAPON(WEAPON_DID)
; #region
#DIM WEAPON_DID
;素材関連
#DIM  DYNAMIC MATERIAL_NEEDS, ITEM_LENGTH
;武器関連変数
#DIMS DYNAMIC WEAPON_NAME
#DIM  DYNAMIC WEAPON_ID
#DIM  DYNAMIC WEAPON_RANK
#DIM  DYNAMIC MODIFIED_STATUS, WPN_MAX_STATUSNUM
#DIM  DYNAMIC STATUS_IDX
;スキル関連
#DIM  DYNAMIC RUNE_DID
#DIM DYNAMIC  PASSIVE_SKILL_SLOT
#DIM DYNAMIC  ACTIVE_SKILL_SLOT
#DIMS DYNAMIC SKILL_DEF_NAME
#DIMS DYNAMIC SKILL_NAME
#DIM  DYNAMIC SKILL_LV
#DIM  DYNAMIC WPN_SKILL_GENRE
#DIMS DYNAMIC TOOLTIP
#DIM  DYNAMIC AMOUNT
#DIM  DYNAMIC COST

;改造前の武器ステータス取得
VARSET WPN_STATUS
FOR STATUS_IDX, 0, VARSIZE("WPN_STATUS_NAME_ENG")
    DT_CELL_GET "WEAPON_STOCK", WEAPON_DID, WPN_STATUS_NAME_ENG:STATUS_IDX, 1
    WPN_STATUS:STATUS_IDX = RESULT
NEXT

;武器名
CALL GET_WEAPON_STOCK_TABLE(WEAPON_DID, "WEAPON_NAME")
WEAPON_NAME = %RESULTS%
CALL GET_WEAPON_STOCK_TABLE(WEAPON_DID, "WEAPON_RANK")
WEAPON_RANK = RESULT

;付呪対象ルーンの取得
RUNE_DID = HO_ITEM_CRAFT_SELECT_RUNE_ID

;スキルルーンの情報取得
CALL RUNE_STOCK_GET_TABLE_DATA(RUNE_DID, "SKILL_DEF_NAME")
SKILL_DEF_NAME = %RESULTS%
CALL RUNE_STOCK_GET_TABLE_DATA(RUNE_DID, "SKILL_LV")
SKILL_LV = RESULT
CALL RUNE_STOCK_GET_TABLE_DATA(RUNE_DID, "AMOUNT")
AMOUNT = RESULT
CALL RUNE_STOCK_GET_TABLE_DATA(RUNE_DID, "WPN_SKILL_GENRE")
WPN_SKILL_GENRE = RESULT
CALL SKILL_GET_NAME(WPN_SKILL_GENRE, SKILL_DEF_NAME, 1)
SKILL_NAME = %RESULTS%
CALL GET_SKILL_DESC(SKILL_DEF_NAME, WPN_SKILL_GENRE, SKILL_LV, 1)
TOOLTIP = %RESULTS%

;強化コスト取得
CALL EQUIP_GET_COST_FOR_ENCHANT(WEAPON_DID, SKILL_DEF_NAME, SKILL_LV)
COST = RESULT

;付呪実行
CALL EQUIP_ADD_SKILL(WEAPON_DID, SKILL_DEF_NAME, WPN_SKILL_GENRE, SKILL_LV)

;コスト消費
CALL RUNE_STOCK_UPDATE(SKILL_DEF_NAME, WPN_SKILL_GENRE, SKILL_LV, COST * -1)

CALL FL_PLAYSE("CRAFT_3.mp3")
PRINTFORMW %WEAPON_NAME%にスキル:<%SKILL_NAME%Lv{SKILL_LV}>を付呪した！

HO_ITEM_CRAFT_SELECT_RUNE_ID = -1
; #endregion

;-------------------------------------------------
;;; 解呪処理実行
;-------------------------------------------------
@HO_ITEM_CRAFT_EXEC_REMOVE_ENCHANT(WEAPON_DID)
; #region
#DIM WEAPON_DID
;素材関連
#DIM  DYNAMIC MATERIAL_NEEDS, ITEM_LENGTH
;武器関連変数
#DIMS DYNAMIC WEAPON_NAME
#DIM  DYNAMIC WEAPON_ID
#DIM  DYNAMIC WEAPON_RANK
#DIM  DYNAMIC MODIFIED_STATUS, WPN_MAX_STATUSNUM
#DIM  DYNAMIC STATUS_IDX
;スキル関連
#DIM  DYNAMIC RUNE_DID
#DIM DYNAMIC  PASSIVE_SKILL_SLOT
#DIM DYNAMIC  ACTIVE_SKILL_SLOT
#DIMS DYNAMIC SKILL_DEF_NAME
#DIMS DYNAMIC SKILL_NAME
#DIM  DYNAMIC SKILL_LV
#DIM  DYNAMIC WPN_SKILL_GENRE
#DIMS DYNAMIC TOOLTIP
#DIM  DYNAMIC AMOUNT
#DIM  DYNAMIC COST
#DIMS DYNAMIC DIC_REMOVE_ENCHANT
#DIMS DYNAMIC STR_GENRE
#DIMS DYNAMIC SKILL_SLOT_USED_SKILL

;解呪対象スキル情報
DIC_REMOVE_ENCHANT = %HO_ITEM_CRAFT_DIC_REMOVE_ENCHANT%

;武器名
CALL GET_WEAPON_STOCK_TABLE(WEAPON_DID, "WEAPON_NAME")
WEAPON_NAME = %RESULTS%
CALL GET_WEAPON_STOCK_TABLE(WEAPON_DID, "WEAPON_RANK")
WEAPON_RANK = RESULT

;スキル情報取得
SKILL_DEF_NAME = %DIC_GET(DIC_REMOVE_ENCHANT, "REMOVE_ENCHANT")%
WPN_SKILL_GENRE = WPN_SKILL_GET_GENRE(SKILL_DEF_NAME)
STR_GENRE '= WPN_SKILL_GENRE == 武器スキル_アクティブ ? "ACTIVE" # "PASSIVE"
SKILL_SLOT_USED_SKILL = %DT_CELL_GETS("WEAPON_STOCK", WEAPON_DID, @"%STR_GENRE%_SKILL_SLOT_USED_SKILL_NAME", 1)%
SKILL_LV = DIC_GETINT(SKILL_SLOT_USED_SKILL, SKILL_DEF_NAME)
SKILL_NAME = %TOHALF(GET_WPN_SKILL_NAME(SKILL_DEF_NAME, WPN_SKILL_GENRE))%
CALL GET_SKILL_DESC(SKILL_DEF_NAME, WPN_SKILL_GENRE, SKILL_LV, 1)
TOOLTIP = %RESULTS%

;強化コスト取得
CALL EQUIP_GET_COST_FOR_ENCHANT(WEAPON_DID, SKILL_DEF_NAME, SKILL_LV)
COST = RESULT

;解呪実行
CALL EQUIP_REMOVE_SKILL(WEAPON_DID, SKILL_DEF_NAME, WPN_SKILL_GENRE)

;コスト返却
CALL RUNE_STOCK_UPDATE(SKILL_DEF_NAME, WPN_SKILL_GENRE, SKILL_LV, COST)

CALL FL_PLAYSE("CRAFT_3.mp3")
PRINTFORMW %WEAPON_NAME%からスキル:<%SKILL_NAME%Lv{SKILL_LV}>を解呪した！

HO_ITEM_CRAFT_DIC_REMOVE_ENCHANT '= ""
; #endregion

@ENCHANT_GET_EQUIP_SKILL_LIST_STR(EQUIP_DID, GENRE)
#DIM  EQUIP_DID
#DIM  GENRE
#DIM  DYNAMIC EQUIP_IDX, WPN_MAX_WEAPON_STOCK
#DIM  DYNAMIC WEAPON_ID
#DIMS DYNAMIC DIC_WPN_SKILL
#DIMS DYNAMIC SKILL_DEF_NAME
#DIMS DYNAMIC WPN_SKILL_DEF_LIST, VARSIZE("SKILL_DEF_LIST")
#DIMS DYNAMIC SKILL_NAME
#DIM  DYNAMIC SKILL_LV
#DIMS DYNAMIC TOOLTIP
#DIM  DYNAMIC F_COL
#DIM  DYNAMIC IDX
#DIM  DYNAMIC ITER_I

SKILL_NAME '= ""
VARS STR_GENRE
VARI SKILL_SLOT
VARI SKILL_SLOT_USED
VARS SKILL_SLOT_USED_SKILL_NAME

IF GENRE == 武器スキル_アクティブ
    STR_GENRE '= "ACTIVE"
ELSE
    STR_GENRE '= "PASSIVE"
ENDIF

;DIC_WPN_SKILL = %DT_CELL_GETS("WEAPON_STOCK", EQUIP_DID, @"%STR_GENRE%_WEAPON_SKILL", 1)%
SKILL_SLOT = DT_CELL_GET("WEAPON_STOCK", EQUIP_DID, @"%STR_GENRE%_SKILL_SLOT", 1)
SKILL_SLOT_USED = DT_CELL_GET("WEAPON_STOCK", EQUIP_DID, @"%STR_GENRE%_SKILL_SLOT_USED", 1)
SKILL_SLOT_USED_SKILL_NAME = %DT_CELL_GETS("WEAPON_STOCK", EQUIP_DID, @"%STR_GENRE%_SKILL_SLOT_USED_SKILL_NAME", 1)%

CALL DIC_KEYS(SKILL_SLOT_USED_SKILL_NAME)
ARRAYCOPY "RESULTS", "WPN_SKILL_DEF_LIST"
FOR ITER_I, 0, RESULT
    SKILL_DEF_NAME = %WPN_SKILL_DEF_LIST:ITER_I%
    SKILL_LV = TOINT(DIC_GET(SKILL_SLOT_USED_SKILL_NAME, SKILL_DEF_NAME))
    CALL GET_SKILL_DESC(SKILL_DEF_NAME, GENRE, SKILL_LV, 1)
    TOOLTIP = %RESULTS%
    ;ルーンによって付呪されたスキルである場合
    IF DIC_CONTAINSKEY(SKILL_SLOT_USED_SKILL_NAME, SKILL_DEF_NAME)
        TOOLTIP += "

※このスキルはルーンによって付呪された
"
        SKILL_NAME += @"@B:DUMMY$%TOOLTIP%@<R:%TOHALF(GET_WPN_SKILL_NAME(SKILL_DEF_NAME, GENRE))%Lv{SKILL_LV}>@/B@@B:[REMOVE_ENCHANT:%SKILL_DEF_NAME%][GENRE:{GENRE}]@[-] @/B@"
    ELSE
        SKILL_NAME += @"@B:DUMMY$%TOOLTIP%@<%TOHALF(GET_WPN_SKILL_NAME(SKILL_DEF_NAME, GENRE))%Lv{SKILL_LV}>@/B@@B:[REMOVE_ENCHANT:%SKILL_DEF_NAME%][GENRE:{GENRE}]@[-] @/B@"
    ENDIF
NEXT
IF SKILL_SLOT - SKILL_SLOT_USED > 0
    TOOLTIP '= "ルーン付呪枠"
    SKILL_NAME += @"@B:DUMMY$%TOOLTIP%@<---> @/B@" * (SKILL_SLOT - SKILL_SLOT_USED)
ENDIF
IF GENRE == 武器スキル_アクティブ
    F_COL = カラー_オレンジ
ELSE
    F_COL = カラー_黄緑
ENDIF
RESULTS '= @"@C:{F_COL}@%SKILL_NAME%@/C@"

RETURN


code:
@HO_CRAFT_WINDOW_INPUT(MODULE_ID)
#DIM MODULE_ID
#DIM  DYNAMIC INPUT_VALUE
#DIM  DYNAMIC MATERIAL_NEEDS, ITEM_LENGTH
#DIM  DYNAMIC WEAPON_ID
#DIM  DYNAMIC WPN_MATERIAL_NEEDS, WPN_材質種類数, ITEM_LENGTH
#DIMS DYNAMIC SORT_COLUMN

;入力受付
REDRAW 1
ONEINPUTS
REDRAW 0
CLEARLINE 1
PRINTL

IF ISNUMERIC(RESULTS)
    RESULT = TOINT(RESULTS)
    ;キャンセルボタン
    IF RESULT == 9999999
        RETURN -1
    ELSEIF INRANGE(RESULT, 0, 4)
        HO_ITEM_CRAFT_SELECT_ITEM_ID = -1
        HO_CRAFT_CATEGORY = RESULT
        HO_ITEM_MENU_PAGE_LEFT = 0
        HO_ITEM_CRAFT_PAGE_LEFT = 0
        ;アイテム作成
    ELSEIF HO_CRAFT_CATEGORY == 0 && INRANGE(RESULT, 2000, 2999)
        SELECTCASE RESULT - 2000
            CASE 1
                CALL GET_ITEM_MATERIAL_NEEDS(HO_ITEM_CRAFT_SELECT_ITEM_ID, MATERIAL_NEEDS, HO_CRAFT_RECIPE_ID)
                CALL USE_MATERIAL(MATERIAL_NEEDS, HO_ITEM_CRAFT_NUM_PRODUCTION)
                CALL CHANGE_ITEM_STOCK(HO_ITEM_CRAFT_SELECT_ITEM_ID, HO_ITEM_CRAFT_BASE_PRODUCTION_RATE * HO_ITEM_CRAFT_NUM_PRODUCTION)
                ;地の文・口上表示用
                TFLAG:クラフト_アイテムID = HO_ITEM_CRAFT_SELECT_ITEM_ID
                TFLAG:クラフト_作成量 = HO_ITEM_CRAFT_BASE_PRODUCTION_RATE * HO_ITEM_CRAFT_NUM_PRODUCTION
                RETURN 1
            CASE 2
                HO_ITEM_CRAFT_NUM_PRODUCTION ++
            CASE 3
                HO_ITEM_CRAFT_NUM_PRODUCTION --
                ;使用レシピ切替
            CASE 10 TO 14
                HO_CRAFT_RECIPE_ID = RESULT - 2010
        ENDSELECT
        ;衣装作成
    ELSEIF HO_CRAFT_CATEGORY == 2 && INRANGE(RESULT, 2000, 2999)
        SELECTCASE RESULT - 2000
            CASE 1
                CALL GET_CLOTH_MATERIAL_NEEDS(HO_ITEM_CRAFT_SELECT_CLOTH_PARTS, HO_ITEM_CRAFT_SELECT_ITEM_ID, MATERIAL_NEEDS)
                CALL USE_MATERIAL(MATERIAL_NEEDS, HO_ITEM_CRAFT_NUM_PRODUCTION)
                CALL CHANGE_CLOTH_STOCK(HO_ITEM_CRAFT_SELECT_CLOTH_PARTS, HO_ITEM_CRAFT_SELECT_ITEM_ID, HO_ITEM_CRAFT_NUM_PRODUCTION)
                ;地の文・口上表示用
                TFLAG:クラフト_アイテムID   = HO_ITEM_CRAFT_SELECT_ITEM_ID
                TFLAG:クラフト_衣装部位     = HO_ITEM_CRAFT_SELECT_CLOTH_PARTS
                TFLAG:クラフト_作成量       = HO_ITEM_CRAFT_NUM_PRODUCTION
                RETURN 1
            CASE 2
                HO_ITEM_CRAFT_NUM_PRODUCTION ++
            CASE 3
                HO_ITEM_CRAFT_NUM_PRODUCTION --
        ENDSELECT
        ;武器作成
    ELSEIF  HO_CRAFT_CATEGORY == 1 && INRANGE(RESULT, 2000, 2999)
        WEAPON_ID = HO_ITEM_CRAFT_SELECT_ITEM_ID % 1000
        CALL GET_WEAPON_MATERIAL_NEEDS(WEAPON_ID, HO_ITEM_CRAFT_WEAPON_MATERIAL, WPN_MATERIAL_NEEDS)
        FOR LOCAL, 0, ITEM_LENGTH
            MATERIAL_NEEDS:LOCAL = WPN_MATERIAL_NEEDS:HO_ITEM_CRAFT_WEAPON_MATERIAL:LOCAL
        NEXT
        ;生産に必要なアイテムを消費
        CALL USE_MATERIAL(MATERIAL_NEEDS)
        ;スキルスロット数を取得
        TRYCCALLFORM GET_WEAPON_SKILL_SLOT_{WEAPON_ID}(HO_ITEM_CRAFT_WEAPON_MATERIAL)
            CALL ADD_WEAPON_STOCK_LIST(WEAPON_ID, HO_ITEM_CRAFT_WEAPON_NAME, HO_ITEM_CRAFT_WEAPON_MATERIAL, 0,,,, RESULT:0, RESULT:1)
        CATCH
            CALL ADD_WEAPON_STOCK_LIST(WEAPON_ID, HO_ITEM_CRAFT_WEAPON_NAME, HO_ITEM_CRAFT_WEAPON_MATERIAL, 0)
        ENDCATCH
        ;クラフトコマンド実行時　地の文表示用
        TFLAG:クラフト_作成量  = HO_ITEM_CRAFT_NUM_PRODUCTION
        TFLAG:クラフト_武器IDX = RESULT
        RETURN 1
        ;衣装部位タブ切り替え
    ELSEIF  HO_CRAFT_CATEGORY == 2 && INRANGE(RESULT, 1000, 1999)
        HO_ITEM_CRAFT_SELECT_CLOTH_PARTS = RESULT - 1000
        HO_ITEM_CRAFT_PAGE_LEFT = 0
        RETURN
        ;ページ処理
    ELSEIF INRANGE(RESULT, 9000, 9001)
        IF RESULT == 9000
            IF HO_CRAFT_CATEGORY == 3
                HO_ITEM_MENU_PAGE_LEFT --
            ELSE
                HO_ITEM_CRAFT_PAGE_LEFT --
            ENDIF
        ELSE
            IF HO_CRAFT_CATEGORY == 3
                HO_ITEM_MENU_PAGE_LEFT ++
            ELSE
                HO_ITEM_CRAFT_PAGE_LEFT ++
            ENDIF
        ENDIF
        ;アイテム選択
    ELSEIF INRANGE(RESULT, 1000000, 2999999)
        ;クラフト可能なアイテム ITEM_ID + 1000000, クラフト不可能なアイテム ITEM_ID + 2000000
        HO_ITEM_CRAFT_NUM_PRODUCTION = 1
        HO_CRAFT_RECIPE_ID = 0
        HO_ITEM_CRAFT_SELECT_ITEM_ID = (RESULT - 1000000)
        RETURN
    ENDIF
ELSE
    ;アイテム作成
    IF HO_CRAFT_CATEGORY == 0
        IF !HO_CRAFT_IS_ACTIVE_SUBWND
            IF DIC_CONTAINSKEY(RESULTS, "CRAFT_ORDER")
                HO_CRAFT_IS_ACTIVE_SUBWND = 1
                HO_ITEM_CRAFT_DIC_CRAFT_ORDER = %RESULTS%
            ENDIF
        ELSE
            IF DIC_CONTAINSKEY(RESULTS, "EXIT")
                HO_CRAFT_IS_ACTIVE_SUBWND = 0
            ELSEIF DIC_CONTAINSKEY(RESULTS, "ADD_ORDER")
                CALL HO_ADD_CRAFT_ORDER()
            ELSEIF DIC_CONTAINSKEY(RESULTS, "REPLACE_ORDER")
                CALL HO_REPLACE_CRAFT_ORDER(TOINT(DIC_GET(RESULTS, "REPLACE_ORDER")))
            ELSEIF DIC_CONTAINSKEY(RESULTS, "DELETE_ORDER")
                CALL HO_DELETE_CRAFT_ORDER(TOINT(DIC_GET(RESULTS, "DELETE_ORDER")))
            ELSEIF DIC_CONTAINSKEY(RESULTS, "SET_TARGET_NUM")
                CALL HO_CRAFT_ORDER_SET_TARGET_NUM(TOINT(DIC_GET(RESULTS, "SET_TARGET_NUM")))
            ENDIF
        ENDIF
        ;武器の強化、付呪
    ELSEIF HO_CRAFT_CATEGORY == 3 || HO_CRAFT_CATEGORY == 4
        IF !HO_CRAFT_IS_ACTIVE_SUBWND
            IF DIC_CONTAINSKEY(RESULTS, "WEAPON_DID")
                HO_ITEM_CRAFT_SELECT_ITEM_ID = TOINT(DIC_GET(RESULTS, "WEAPON_DID"))
                HO_CRAFT_IS_ACTIVE_SUBWND = 1
            ELSEIF DIC_CONTAINSKEY(RESULTS, "SORT")
                SORT_COLUMN = %DIC_GET(RESULTS, "SORT")%
                IF SORT_COLUMN == HO_ITEM_MENU_CURRENT_SORT_COLUMN
                    HO_ITEM_MENU_CURRENT_SORT_ORDER ++
                    IF HO_ITEM_MENU_CURRENT_SORT_ORDER > 2
                        HO_ITEM_MENU_CURRENT_SORT_COLUMN '= ""
                        HO_ITEM_MENU_CURRENT_SORT_ORDER = 0
                    ENDIF
                ELSE
                    HO_ITEM_MENU_CURRENT_SORT_COLUMN = %SORT_COLUMN%
                    HO_ITEM_MENU_CURRENT_SORT_ORDER = 1
                ENDIF
            ENDIF
        ELSE
            IF DIC_CONTAINSKEY(RESULTS, "MODIFY_WEAPON")
                CALL HO_ITEM_CRAFT_MODIFY_WEAPON(HO_ITEM_CRAFT_SELECT_ITEM_ID)
            ELSEIF DIC_CONTAINSKEY(RESULTS, "EXEC_ENCHANT_WEAPON")
                CALL HO_ITEM_CRAFT_EXEC_ENCHANT_WEAPON(HO_ITEM_CRAFT_SELECT_ITEM_ID)
            ELSEIF DIC_CONTAINSKEY(RESULTS, "EXEC_REMOVE_ENCHANT")
                CALL HO_ITEM_CRAFT_EXEC_REMOVE_ENCHANT(HO_ITEM_CRAFT_SELECT_ITEM_ID)
            ELSEIF DIC_CONTAINSKEY(RESULTS, "RENAME")
                CALL HO_ITEM_CRAFT_MODIFT_WEAPON_RENAME(HO_ITEM_CRAFT_SELECT_ITEM_ID)
            ELSEIF DIC_CONTAINSKEY(RESULTS, "EXIT")
                HO_CRAFT_IS_ACTIVE_SUBWND = 0
                HO_ITEM_CRAFT_SELECT_RUNE_ID  = -1
                HO_ITEM_CRAFT_DIC_REMOVE_ENCHANT '= ""
            ELSEIF DIC_CONTAINSKEY(RESULTS, "SELECT_RUNE")
                IF HO_ITEM_CRAFT_SELECT_RUNE_ID == -1
                    HO_ITEM_CRAFT_SELECT_RUNE_GENRE = DIC_GETINT(RESULTS, "SELECT_RUNE")
                    HO_CRAFT_IS_ACTIVE_SUBWND = 2
                ELSE
                    HO_ITEM_CRAFT_SELECT_RUNE_ID  = -1
                ENDIF
            ELSEIF DIC_CONTAINSKEY(RESULTS, "SELECT_RUNE_EXIT")
                HO_ITEM_CRAFT_SELECT_RUNE_PAGE_LEFT = 0
                HO_CRAFT_IS_ACTIVE_SUBWND = 1
            ELSEIF DIC_CONTAINSKEY(RESULTS, "RUNE_ID")
                HO_ITEM_CRAFT_SELECT_RUNE_ID = DIC_GETINT(RESULTS, "RUNE_ID")
                CALL HO_ITEM_CRAFT_CHECK_CAN_SELECT_RUNE()
                IF RESULT == -1
                    CALL COLOR_PRINTW("既に同種のスキルが付呪されているため選択できません", カラー_注意)
                    HO_ITEM_CRAFT_SELECT_RUNE_ID = -1
                ELSE
                    HO_CRAFT_IS_ACTIVE_SUBWND = 1
                ENDIF
            ELSEIF DIC_CONTAINSKEY(RESULTS, "REMOVE_ENCHANT")
                HO_ITEM_CRAFT_DIC_REMOVE_ENCHANT = %RESULTS%
            ELSEIF DIC_CONTAINSKEY(RESULTS, "RUNE_PAGE_PREV")
                HO_ITEM_CRAFT_SELECT_RUNE_PAGE_LEFT --
            ELSEIF DIC_CONTAINSKEY(RESULTS, "RUNE_PAGE_NEXT")
                HO_ITEM_CRAFT_SELECT_RUNE_PAGE_LEFT ++
            ENDIF
        ENDIF
    ENDIF
ENDIF