code:
;=================================================
;戦闘用のユーザー関数
;各種イベントやクエストから呼ばれる想定
;=================================================

;-------------------------------------------------
;@CC_INIT()
;CC関連の初期化を行う
;-------------------------------------------------
@CC_INIT()
IF DT_EXIST("CC_ACTOR")
    DT_CLEAR "CC_ACTOR"
ENDIF
IF DT_EXIST("CC_SKILL_SLOT")
    DT_CLEAR "CC_SKILL_SLOT"
ENDIF

CALL CREATE_CC_ACTOR_TABLE()
CALL CREATE_CC_SKILL_SLOT_TABLE()
CALL CREATE_CC_SP_TOKEN_NUM_TABLE()

CALL CC_ACTION_MANAGER_("INIT")
VARSET _DIC_CC_TEMP_WEAPON
;武器スキルのクールタイムは開始時に常にリセット
FOR LOCAL, 0, VARSIZE("ACTIVE_SKILL_COOLTIME")
    CVARSET WPN_ACTIVE_SKILL_COOLTIME, LOCAL, 0
NEXT
CC_ROUND_COUNT = 1
CC_FORCE_END = 0

;戦闘で使用するスプライトの初期化
CALL CLOSE_COMBAT_DISPOSE_SPRITE(1)

;戦闘用BGMの再生を停止
;戦闘開始前からBGMが鳴っていた場合はそれを再生する
@CC_STOPBGM()
IF FL_PREVBGM != ""
    CALL  FL_PLAYBGM(FL_PREVBGM)
ELSE
    CALL FL_STOPBGM()
ENDIF

;-------------------------------------------------
; @CC_SET_TEMP_WEAPON()
; 特定のキャラクターに戦闘時のみ一時的に特定の武器を武器を使用させたい場合に使う
; ここにセットされた装備は本来の装備に優先される
; 基本的にはモブキャラ向けを想定しているが、自キャラに一時的に素手を強要したい場合などにも使える
;-------------------------------------------------
@CC_SET_TEMP_WEAPON(CHARA_ID, WEAPON_ID, WEAPON_NAME = "", MATERIAL)
#DIM CHARA_ID
#DIMS WEAPON_NAME
#DIM WEAPON_ID
#DIM MATERIAL

IF WEAPON_NAME == ""
    CALL GET_WEAPON_NAME(WEAPON_ID)
    WEAPON_NAME = %RESULTS%
    WEAPON_NAME '= @"%WPN_材質別接頭文字:MATERIAL%の%WEAPON_NAME%"
ENDIF
_DIC_CC_TEMP_WEAPON:CHARA_ID '= @"[WEAPON_NAME:%WEAPON_NAME%][WEAPON_ID:{WEAPON_ID}][MATERIAL:{MATERIAL}]"

;-------------------------------------------------
;@CC_ADDCHARA
;キャラクターデータを持つキャラクターをキャラ番号指定でメンバーに追加する
;引数:1 "ATTACKER","DEFENDER"のいずれかを指定
;引数:2 キャラ番号
;-------------------------------------------------
@CC_ADDCHARA(SIDE, CHARA_ID)
#DIMS SIDE
#DIM CHARA_ID
#DIM DYNAMIC IDX, CC_MAX_MEMBER_NUM
#DIM DYNAMIC MEM_CNT

IF SIDE == "ATTACKER"
    MEM_CNT = DT_SELECT("CC_ACTOR", @"SIDE = 1",,IDX)
    IF MEM_CNT >= CC_MAX_MEMBER_NUM / 2
        DEBUGPRINTFORML CLOSE_COMBAT:エラー 攻撃側メンバーが上限({CC_MAX_MEMBER_NUM / 2})を超えています
        THROW CLOSE_COMBAT:エラー 攻撃側メンバーが上限を超えています
    ELSE
        CALL CC_SET_CHARADATA(CHARA_ID, 1)
    ENDIF
ELSE
    MEM_CNT = DT_SELECT("CC_ACTOR", @"SIDE = 0",,IDX)
    IF MEM_CNT >= CC_MAX_MEMBER_NUM / 2
        DEBUGPRINTFORML CLOSE_COMBAT:エラー 防御側メンバーが上限({CC_MAX_MEMBER_NUM / 2})を超えています
        THROW CLOSE_COMBAT:エラー 防御側メンバーが上限を超えています
    ELSE
        CALL CC_SET_CHARADATA(CHARA_ID, 0)
    ENDIF
ENDIF

;-------------------------------------------------
;@CC_ADDPARTY()
;クエストのパーティメンバーを戦闘メンバーに追加する
;引数:1 デフォルトは"ATTACKER"(左：攻撃側)。"ATTACKER","DEFENDER"のいずれかを指定
;-------------------------------------------------
;region @CC_ADDPARTY
@CC_ADDPARTY(SIDE = "ATTACKER")
#DIMS SIDE
FOR LOCAL, 0, LIST_COUNT(_LIST_QST_PARTY)
    CALL CC_ADDCHARA(SIDE, TOINT(LIST_GET(_LIST_QST_PARTY, LOCAL)))
NEXT
;#endregion

;-------------------------------------------------
;@CC_ADDMOB
;キャラクターデータを持たないモブをパラメータを直接指定して戦闘メンバーに追加する
;引数:1 "ATTACKER","DEFENDER"のいずれかを指定
;引数:2 表示する名前を指定
;引数:3 現HPを指定
;引数:4 最大HPを指定
;引数:5 戦闘値を指定
;-------------------------------------------------
@CC_ADDMOB(SIDE, CC_NAME, HP, MAXHP, 戦闘, 魔術 = 0, エリート = 0, 脅威選定 = 0)
#DIMS SIDE
#DIMS CC_NAME
#DIM HP
#DIM MAXHP
#DIM 戦闘
#DIM 魔術
#DIM エリート
#DIM 脅威選定
#DIM DYNAMIC IDX, CC_MAX_MEMBER_NUM
#DIM DYNAMIC MEM_CNT

IF SIDE == "ATTACKER"
    MEM_CNT = DT_SELECT("CC_ACTOR", @"SIDE = 1",,IDX)
    IF MEM_CNT >= CC_MAX_MEMBER_NUM / 2
        DEBUGPRINTFORML CLOSE_COMBAT:エラー 攻撃側メンバーが上限({CC_MAX_MEMBER_NUM / 2})を超えています
        THROW CLOSE_COMBAT:エラー 攻撃側メンバーが上限を超えています
    ELSE
        CALL CC_SET_MOBDATA(1, CC_NAME, HP, MAXHP, 戦闘, 魔術, エリート, 脅威選定)
    ENDIF
ELSE
    MEM_CNT = DT_SELECT("CC_ACTOR", @"SIDE = 0",,IDX)
    IF MEM_CNT >= CC_MAX_MEMBER_NUM / 2
        DEBUGPRINTFORML CLOSE_COMBAT:エラー 攻撃側メンバーが上限({CC_MAX_MEMBER_NUM / 2})を超えています
        THROW CLOSE_COMBAT:エラー 攻撃側メンバーが上限を超えています
    ELSE
        CALL CC_SET_MOBDATA(0, CC_NAME, HP, MAXHP, 戦闘, 魔術, エリート, 脅威選定)
    ENDIF
ENDIF

;-------------------------------------------------
;;; @CC_ENEMY_DATA または"ENEMY_DATA"テーブルに定義済みのモブを戦闘メンバーに追加する
;;; - ARG
;;; 引数:0 (必須) "ATTACKER","DEFENDER"のいずれかを指定
;;; 引数:1 (必須) @CC_ENEMY_DATA の ENEMY_DEF_NAME
;;; 引数:2 (任意) 戦闘画面の表示上のモブ名。デフォルトはENEMY_NAME
;;; 引数:3 (任意)能力値を補正する場合指定。テーブル定義の能力値に対してn%加算し補正をかける。百分率指定
;;; 引数:4 (任意)オプション辞書  [KEY:VALUE]の辞書形式で指定。各オプションは以下参照
;;; "CHARA_ID" 指定したキャラとテーブルにないパラメータの同期をとる（ポートレイト、衣装状態など） 。戦闘用パラメータはテーブルの値より参照
;;; "HP"など"CC_ACTOR" に含まれるパラメータを指定することで、パラメータを上書き可能
;;;   -  ENEMY_PASSIVE_SKILL と ENEMY_ACTIVE_SKILL は入れ子対策のため`[ENEMY_PASSIVE_SKILL:<SMITE;1><MANA_SMITE;1>]`形式で与えてください
;;; - RETURN
;;; RESULT:0 データテーブル上のID
;;;-------------------------------------------------
@CC_ADDMOB_FROM_TABLE(SIDES, ENEMY_DEF_NAME, CC_NAME = "", 能力値補正率 = 0, DIC_OPTIONS)
#DIMS ENEMY_DEF_NAME
#DIMS CC_NAME
#DIM  能力値補正率
#DIMS SIDES
#DIM  SIDE
#DIM  PLACEMENT
#DIM  ステータス補正
#DIMS DIC_OPTIONS
#DIM  DYNAMIC ID
#DIM  ACTOR_DID
#DIM  COLUMN_NUM
#DIMS COLUMNS, 1000
#DIMS DIC_SKILL

;戦闘開始時の補正ステータス
#DIM  DYNAMIC 最大HP
#DIM  DYNAMIC 攻撃力
#DIM  DYNAMIC 魔力
#DIM  DYNAMIC 防御力
#DIM  DYNAMIC 軽減値
#DIM  DYNAMIC 行動力
#DIM  DYNAMIC 最大HP補正率
#DIM  DYNAMIC 攻撃力補正率
#DIM  DYNAMIC 魔力補正率
#DIM  DYNAMIC 防御力補正率
#DIM  DYNAMIC 軽減値補正率
#DIM  DYNAMIC 行動力補正率
#DIM  DYNAMIC CHARA_ID
#DIM  DYNAMIC SHOW_PORTRAIT

DT_SELECT "ENEMY_DATA", @"ENEMY_DEF_NAME = '%ENEMY_DEF_NAME%'"
IF RESULT < 1
    DEBUGPRINTFORML @CC_ADDMOB_FROM_TABLE エラー：指定されたエネミー定義"%ENEMY_DEF_NAME%"は存在しません
    RETURN 0
ELSE
    ID = RESULT:1
ENDIF

IF SIDES == "ATTACKER" || SIDES == "DEFENDER"
    SIDE = SIDES == "ATTACKER" ? 1 # 0
ELSE
    SIDE = TOINT(SIDES)
ENDIF
;位置情報　仮仕様で登録順
PLACEMENT = DT_SELECT("CC_ACTOR", @"SIDE = {SIDE}")

IF CC_NAME == ""
    CC_NAME = %DT_CELL_GETS("ENEMY_DATA", ID, "ENEMY_NAME", 1)%
ENDIF

最大HP補正率 = FTIMES(能力値補正率, 75) + 100
攻撃力補正率 = FTIMES(能力値補正率, 100) + 100
魔力補正率 =   FTIMES(能力値補正率, 100) + 100
防御力補正率 = FTIMES(能力値補正率, 50) + 100
軽減値補正率 = FTIMES(能力値補正率, 75) + 100
行動力補正率 = FTIMES(能力値補正率, 50) + 100

最大HP = FTIMES(DT_CELL_GET("ENEMY_DATA", ID, "MAX_HP", 1), 最大HP補正率)
攻撃力 = FTIMES(DT_CELL_GET("ENEMY_DATA", ID, "ATTACK", 1), 攻撃力補正率)
魔力   = FTIMES(DT_CELL_GET("ENEMY_DATA", ID, "MAG", 1), 魔力補正率)
防御力 = FTIMES(DT_CELL_GET("ENEMY_DATA", ID, "DEFENCE", 1), 防御力補正率)
軽減値 = FTIMES(DT_CELL_GET("ENEMY_DATA", ID, "ARMOR", 1), 軽減値補正率)
行動力 = FTIMES(DT_CELL_GET("ENEMY_DATA", ID, "AGILITY", 1), 行動力補正率)

IF DIC_CONTAINSKEY(DIC_OPTIONS, "CHARA_ID")
    CHARA_ID = DIC_GETINT(DIC_OPTIONS, "CHARA_ID")
    SHOW_PORTRAIT = 1
ELSE
    CHARA_ID = -1
ENDIF

{
    DT_ROW_ADD "CC_ACTOR"
        ,"CHARA_ID", CHARA_ID
        ,"CHARA_NAME", CC_NAME
        ,"ENEMY_TYPE", DT_CELL_GET("ENEMY_DATA", ID, "ENEMY_TYPE", 1)
        ,"SIDE", SIDE
        ,"PLACEMENT", PLACEMENT
        ,"MAX_HP", 最大HP
        ,"HP", 最大HP
        ,"STR", 攻撃力
        ,"MAG", 魔力
        ,"FACTION", -1
        ,"ATTACK", 攻撃力
        ,"DEFENCE", 防御力
        ,"ARMOR", 軽減値
        ,"AGILITY", 行動力
        ,"CRITICAL_RATE", DT_CELL_GET("ENEMY_DATA", ID, "CRITICAL_RATE", 1)
        ,"CRITICAL_DAMAGE_RATE", DT_CELL_GET("ENEMY_DATA", ID, "CRITICAL_DAMAGE_RATE", 1)
        ,"HATE_RATE", DT_CELL_GET("ENEMY_DATA", ID, "HATE_RATE", 1)
        ,"TARGETING", DT_CELL_GET("ENEMY_DATA", ID, "TARGETING", 1)
        ,"REGIST_POISON", DT_CELL_GET("ENEMY_DATA", ID, "REGIST_POISON", 1)
        ,"REGIST_STUN", DT_CELL_GET("ENEMY_DATA", ID, "REGIST_STUN", 1)
        ,"REGIST_BURN", DT_CELL_GET("ENEMY_DATA", ID, "REGIST_BURN", 1)
        ,"REGIST_CHARM", DT_CELL_GET("ENEMY_DATA", ID, "REGIST_CHARM", 1)
        ,"REGIST_PANIC", DT_CELL_GET("ENEMY_DATA", ID, "REGIST_PANIC", 1)
        ,"REGIST_BLIND", DT_CELL_GET("ENEMY_DATA", ID, "REGIST_BLIND", 1)
        ,"REGIST_DEATH", DT_CELL_GET("ENEMY_DATA", ID, "REGIST_DEATH", 1)
        ,"SELECTED_SKILL_SLOT", -1
        ,"ENEMY_AI", DT_CELL_GETS("ENEMY_DATA", ID, "ENEMY_AI", 1)
        ,"ENEMY_DEF_NAME", ENEMY_DEF_NAME
        ,"ENEMY_AI_ROUTINE_MODE", DT_CELL_GETS("ENEMY_DATA", ID, "ENEMY_AI_ROUTINE_MODE", 1)
        ,"ENEMY_AI_ROUTINE_SEQUENCE", DT_CELL_GET("ENEMY_DATA", ID, "ENEMY_AI_ROUTINE_SEQUENCE", 1)
        ,"ENEMY_ACTIVE_SKILL", DT_CELL_GETS("ENEMY_DATA", ID, "ENEMY_ACTIVE_SKILL", 1)
        ,"ENEMY_PASSIVE_SKILL", DT_CELL_GETS("ENEMY_DATA", ID, "ENEMY_PASSIVE_SKILL", 1)
        ,"DROP_ITEM_LIST", DT_CELL_GETS("ENEMY_DATA", ID, "DROP_ITEM_LIST", 1)
        ,"EXP", DT_CELL_GET("ENEMY_DATA", ID, "EXP", 1)
        ,"SHOW_PORTRAIT", SHOW_PORTRAIT
        ,"IS_PLAYABLE", 0
}
ACTOR_DID = RESULT
;CALL DEBUG_TIMER_END

;CALL DEBUG_OUTPUT_TABLE("CC_ACTOR")

IF DIC_OPTIONS != ""
    COLUMN_NUM = DIC_KEYSF(DIC_OPTIONS)
    ARRAYCOPY "RESULTS", "COLUMNS"
    FOR LOCAL, 0, COLUMN_NUM
        SIF COLUMNS:LOCAL == "CHARA_ID"
            CONTINUE

        IF GROUPMATCH(COLUMNS:LOCAL, "ENEMY_ACTIVE_SKILL", "ENEMY_PASSIVE_SKILL")
            DIC_SKILL = %DIC_GET(DIC_OPTIONS, COLUMNS:LOCAL)%
            ;DEBUGPRINTFORML DIC_SKILL: %DIC_SKILL%
            DIC_SKILL = %REPLACE(DIC_SKILL, "<", "[")%
            DIC_SKILL = %REPLACE(DIC_SKILL, ";", ":")%
            DIC_SKILL = %REPLACE(DIC_SKILL, ">", "]")%
            ;DEBUGPRINTFORML DIC_SKILL: %DIC_SKILL%
            CALL CC_SETS_ENEMYDATA(ACTOR_DID, COLUMNS:LOCAL, DIC_SKILL)
            CONTINUE
        ENDIF

        SELECTCASE DT_COLUMN_EXIST("CC_ACTOR", COLUMNS:LOCAL)
            CASE 1, 2, 3, 4
                ;DEBUGPRINTFORML BEFORE {DT_CELL_GET("CC_ACTOR", TARGET_DID, COLUMNS:LOCAL, 1)}
                CALL CC_SET_ENEMYDATA(ACTOR_DID, COLUMNS:LOCAL, DIC_GETINT(DIC_OPTIONS, COLUMNS:LOCAL))
                ;DEBUGPRINTFORML AFTER {DT_CELL_GET("CC_ACTOR", TARGET_DID, COLUMNS:LOCAL, 1)}
            CASE 5
                ;DEBUGPRINTFORML BEFORE %DT_CELL_GETS("CC_ACTOR", TARGET_DID, COLUMNS:LOCAL, 1)%
                CALL CC_SETS_ENEMYDATA(ACTOR_DID, COLUMNS:LOCAL, DIC_GET(DIC_OPTIONS, COLUMNS:LOCAL))
                ;DEBUGPRINTFORML AFTER %DT_CELL_GETS("CC_ACTOR", TARGET_DID, COLUMNS:LOCAL, 1)%
            CASEELSE
                DEBUGPRINTFORML 指定された行名%COLUMNS:LOCAL%が存在しません
        ENDSELECT
    NEXT
ENDIF

;トークン管理テーブルにキャラクターを追加
DT_ROW_ADD "CC_SP_TOKEN_NUM", "ID", ACTOR_DID
CALL CC_CREATE_ACTOR_FLAG(ACTOR_DID)

RETURN ACTOR_DID

;-------------------------------------------------
;;; エネミーデータの指定キーに値を設定する
;;; 引数:1 データテーブル上のID(@CC_ENEMY_DATAの返り値を指定するとよい)
;;; 引数:2 キー名
;;; 引数:3 設定値
;;; 文字列用
;;;-------------------------------------------------
@CC_SETS_ENEMYDATA(ENEMY_DID, KEY, VALUES)
#DIM  ENEMY_DID
#DIMS KEY
#DIMS VALUES

DT_CELL_SET "CC_ACTOR", ENEMY_DID, KEY, VALUES, 1
;;; 数値用
@CC_SET_ENEMYDATA(ENEMY_DID, KEY, VALUE)
#DIM  ENEMY_DID
#DIMS KEY
#DIM VALUE

DT_CELL_SET "CC_ACTOR", ENEMY_DID, KEY, VALUE, 1

;-------------------------------------------------
;@CC_ADD_COMBAT_EXP
;MASTERと同じ所属勢力の戦闘参加メンバー全員に引数:1 で指定した戦闘経験値を追加する
;引数:1 獲得経験値
;引数:2 経験値獲得メッセージ表示の有無(表示しない場合0を指定)
;引数:3 自動レベルアップの有無(実施しない場合0を指定)
;-------------------------------------------------
@CC_ADD_COMBAT_EXP(COMBAT_EXP, メッセージ表示 = 1, 自動レベルアップ = 1)
#DIM COMBAT_EXP
#DIM メッセージ表示
#DIM 自動レベルアップ
#DIM DYNAMIC MEMBER_LIST, CC_MAX_MEMBER_NUM + 1

CALL CC_GET_MEMBER_LIST(MEMBER_LIST, CFLAG:MASTER:所属)
FOR LOCAL, 0, FINDELEMENT(MEMBER_LIST, -1)
    CALL PRINT_ADD_EXP(MEMBER_LIST:LOCAL, "戦闘経験値", COMBAT_EXP, メッセージ表示)
    SIF TALENT:(MEMBER_LIST:LOCAL):魔術師 || TALENT:(MEMBER_LIST:LOCAL):神聖術師 || TALENT:(MEMBER_LIST:LOCAL):成長型 == 12
        CALL PRINT_ADD_EXP(MEMBER_LIST:LOCAL, "魔術経験値", COMBAT_EXP, メッセージ表示)
    IF 自動レベルアップ == 1
        CALL TRAIN_AUTO_ABLUP(MEMBER_LIST:LOCAL, メッセージ表示 ? 0 # 1)
    ENDIF
NEXT
SIF メッセージ表示
    PRINTL

;-------------------------------------------------
;@CC_GET_DROP_ITEM
;指定のサイドに属するエネミーにドロップアイテムが設定されている場合、取得判定を行う
;引数:1
;-------------------------------------------------
; #region @CC_GET_LOOT_FROM
@CC_GET_LOOT_FROM(SIDES)
#DIMS SIDES
#DIM  DYNAMIC SIDE
#DIM  DYNAMIC MEM_CNT
#DIM  DYNAMIC IDX, CC_MAX_MEMBER_NUM
#DIM  DYNAMIC LIST_IDX
#DIMS DYNAMIC DROP_ITEM_LIST
#DIMS DYNAMIC ITEM_IDS
#DIMS DYNAMIC DROP_NUMS
#DIMS DYNAMIC DROP_NUMS_RANGE, 2
#DIM  DYNAMIC DROP_NUM
#DIM  DYNAMIC DROP_RATE
#DIM  DYNAMIC SUM_ITEM, ITEM_LENGTH
#DIM  DYNAMIC SUM_MONEY
#DIM  DYNAMIC SUM_EXP
#DIMS DYNAMIC LIST_DROP_EQUIP
#DIM  ITER_I
#DIM  ITER_J

;集計処理
SIDE = SIDES == "ATTACKER" ? 1 # 0
MEM_CNT = DT_SELECT("CC_ACTOR", @"SIDE = {SIDE}",,IDX)
FOR ITER_I, 0, MEM_CNT
    DROP_ITEM_LIST = %DT_CELL_GETS("CC_ACTOR", IDX:ITER_I, "DROP_ITEM_LIST", 1)%
    SIF RESULT < 0
        RETURN 0
    FOR ITER_J, 0, LIST_COUNT(DROP_ITEM_LIST)
        LIST_IDX = ITER_J * 3
        DROP_RATE = TOINT(LIST_GET(DROP_ITEM_LIST, LIST_IDX + 2))
        SIF DROP_RATE < RAND:1000
            CONTINUE
        ITEM_IDS = %LIST_GET(DROP_ITEM_LIST, LIST_IDX)%
        DROP_NUMS = %LIST_GET(DROP_ITEM_LIST, LIST_IDX + 1)%
        SPLIT DROP_NUMS, "-", DROP_NUMS_RANGE
        IF RESULT > 1
            DROP_NUM = RAND(TOINT(DROP_NUMS_RANGE:0), TOINT(DROP_NUMS_RANGE:1) + 1)
        ELSE
            DROP_NUM = TOINT(DROP_NUMS)
        ENDIF
        SELECTCASE ITEM_IDS
            CASE "MONEY"
                SUM_MONEY += DROP_NUM
            CASEELSE
                ;数値の場合ITEM_IDが指定されているとみなす
                IF ISNUMERIC(ITEM_IDS)
                    SUM_ITEM:(TOINT(ITEM_IDS)) += DROP_NUM
                ELSEIF EXISTVAR(ITEM_IDS)
                    SUM_ITEM:(GETVAR(ITEM_IDS)) += DROP_NUM
                ELSE
                    ;文字列の場合EQUIP_DATAテーブルの装備品定義名が指定されているとみなす
                    LIST_DROP_EQUIP = %LIST_ADD(LIST_DROP_EQUIP, @"%ITEM_IDS%,{DROP_NUM}")%
                ENDIF
        ENDSELECT

    NEXT
    SUM_EXP += DT_CELL_GET("CC_ACTOR", IDX:ITER_I, "EXP", 1)
NEXT

;ラベル
PRINTL
CALL PRINT_TITLE("COMBAT REWARD","戦利品")

;資金・アイテム獲得処理
SIF SUM_MONEY != 0
    CALL QST_CHANGE_ITEM(@"MONEY,{SUM_MONEY},", 0)
FOR ITER_I, 0, ITEM_LENGTH
    IF SUM_ITEM:ITER_I != 0
        CALL QST_CHANGE_ITEM(@"{ITER_I},{SUM_ITEM:ITER_I},", 0)
    ENDIF
NEXT
FOR LOCAL, 0, LIST_COUNT(LIST_DROP_EQUIP)
    IF LOCAL != 0 && LOCAL % 2 != 0
        CALL QST_CHANGE_ITEM(@"%LIST_GET(LIST_DROP_EQUIP, LOCAL - 1)%,%LIST_GET(LIST_DROP_EQUIP, LOCAL)%,", 0)
    ENDIF
NEXT
PRINTL
;経験値獲得処理
CALL CC_ADD_COMBAT_EXP(SUM_EXP)

WAIT
; #endregion

;-------------------------------------------------
;@CC_APPLY_CHARA_HP
;MASTERと同じ所属勢力の戦闘参加メンバー全員の体力を戦闘後の値に変更する
;-------------------------------------------------
@CC_APPLY_CHARA_HP()
#DIM DYNAMIC IDX, CC_MAX_MEMBER_NUM
#DIM DYNAMIC CHARA_ID
#DIM DYNAMIC HP
#DIM DYNAMIC HP_LOST
#DIM DYNAMIC MEM_CNT

MEM_CNT = DT_SELECT("CC_ACTOR",,, IDX)
FOR LOCAL, 0, MEM_CNT
    IF DT_CELL_GET("CC_ACTOR", IDX:LOCAL, "FACTION", 1) == CFLAG:MASTER:所属
        CHARA_ID = DT_CELL_GET("CC_ACTOR", IDX:LOCAL, "CHARA_ID", 1)
        HP = DT_CELL_GET("CC_ACTOR", IDX:LOCAL, "HP", 1)
        IF HAS_SKILL(CHARA_ID, "PSV_MARTIAL_ARTS_POWER_THROUGH")
            HP_LOST = DT_CELL_GET("CC_ACTOR", IDX:LOCAL, "MAX_HP", 1) - HP
            IF HP_LOST >= BASE:CHARA_ID:体力
                BASE:CHARA_ID:気力 -= (HP_LOST - BASE:CHARA_ID:体力)
                BASE:CHARA_ID:気力 = MIN(BASE:CHARA_ID:気力, 1)
                BASE:CHARA_ID:体力 = 1
            ELSE
                BASE:CHARA_ID:体力 = MAX(1, HP)
            ENDIF
        ELSE
            BASE:CHARA_ID:体力 = MAX(1, HP)
        ENDIF
    ENDIF
NEXT

;-------------------------------------------------
;@CC_GET_MEMBER_LIST
;第二引数に指定した所属のメンバーを参加メンバーから取得する
;引数:1 参加メンバーIDを格納するための一次元配列
;引数:2 CFLAG:ID:所属
;-------------------------------------------------
@CC_GET_MEMBER_LIST(MEMBER_LIST, 所属)
#DIM REF MEMBER_LIST
#DIM 所属
#DIM DYNAMIC MEMBER_LIST_IDX
#DIM DYNAMIC IDX, CC_MAX_MEMBER_NUM
#DIM DYNAMIC MEM_CNT
VARSET MEMBER_LIST, -1

MEM_CNT = DT_SELECT("CC_ACTOR",,, IDX)
FOR LOCAL, 0, MEM_CNT
    IF DT_CELL_GET("CC_ACTOR", IDX:LOCAL, "FACTION", 1) == 所属
        MEMBER_LIST:MEMBER_LIST_IDX = DT_CELL_GET("CC_ACTOR", IDX:LOCAL, "CHARA_ID", 1)
        MEMBER_LIST_IDX ++
    ENDIF
NEXT

RETURN

;=================================================
;内部処理用
;=================================================
;-------------------------------------------------
; キャラを戦闘メンバーとして登録する
;-------------------------------------------------
; #region @CC_SET_CHARADATA
@CC_SET_CHARADATA(CHARA_ID, SIDE)
#DIM CHARA_ID
#DIM SIDE
#DIM DYNAMIC IDX
#DIM  DYNAMIC ACTOR_DID
#DIM  DYNAMIC EQUIP_DID
#DIM  DYNAMIC SLOT_IDX
#DIM  DYNAMIC SKILL_LV
#DIM  DYNAMIC EFFECT_RATE
#DIMS DYNAMIC SKILL_DEF_NAME
#DIMS DYNAMIC DIC_WPN_SKILL
#DIMS DYNAMIC MEM_SKILL_DEF_LIST, VARSIZE("SKILL_DEF_LIST")
#DIM  DYNAMIC FACTION
#DIM  DYNAMIC IS_PLAYABLE
#DIM  DYNAMIC PLACEMENT
#DIMS DYNAMIC WPN_PASSIVE_SKILLS, VARSIZE("WPN_EQUIP_SLOT_ID_LIST")
;戦闘開始時の補正ステータス
#DIM  DYNAMIC 攻撃力
#DIM  DYNAMIC 魔力
#DIM  DYNAMIC 防御力
#DIM  DYNAMIC 軽減値
#DIM  DYNAMIC 行動力
#DIM  DYNAMIC 攻撃力補正率 = 100
#DIM  DYNAMIC 魔力補正率 = 100
#DIM  DYNAMIC 防御力補正率 = 100
#DIM  DYNAMIC 軽減値補正率 = 100
#DIM  DYNAMIC 行動力補正率 = 100
#DIM  DYNAMIC WEAPON_DID

#DIM  ITER_I
#DIM  ITER_J

CALL C_COND_SET_INFO_TO_MAP(CHARA_ID, "BEFORE_COMBAT")

CALL CC_CALC_CHARA_STATUS(CHARA_ID)
DT_SELECT "CHARA_STATUS",@"CHARA_ID = {CHARA_ID}",, IDX
攻撃力 = DT_CELL_GET("CHARA_STATUS", IDX, "ATTACK", 1)
魔力   = DT_CELL_GET("CHARA_STATUS", IDX, "MAG", 1)
防御力 = DT_CELL_GET("CHARA_STATUS", IDX, "DEFENCE", 1)
軽減値 = DT_CELL_GET("CHARA_STATUS", IDX, "ARMOR", 1)
行動力 = DT_CELL_GET("CHARA_STATUS", IDX, "AGILITY", 1)

;;戦闘開始時のスキルによるパラメータ補正
;少数精鋭による補正
SKILL_LV = HAS_SKILL(CHARA_ID, "FEW_ELITE", スキル_大分類_冒険)
IF SKILL_LV
    攻撃力補正率 += 5 * (QST_MAX_PARTYNUM - MAX(QST_PARTYNUM, 1))
    軽減値補正率 += 5 * (QST_MAX_PARTYNUM - MAX(QST_PARTYNUM, 1))
ENDIF

;食事による補正（１戦闘永続）
IF CFLAG:CHARA_ID:QST食事
    TRYCALLFORMF GET_INFO_INSTANT_BUFF_{CFLAG:CHARA_ID:QST食事}("AGI")
    行動力補正率 += RESULT
ENDIF

;補正率に基づく補正
攻撃力 = FTIMES(攻撃力, 攻撃力補正率)
魔力   = FTIMES(魔力,   魔力補正率)
防御力 = FTIMES(防御力, 防御力補正率)
軽減値 = FTIMES(軽減値, 軽減値補正率)
行動力 = FTIMES(行動力, 行動力補正率)

;DEBUGPRINTFORML %ANAME(CHARA_ID)%の攻撃力{攻撃力},攻撃力補正率{攻撃力補正率}

;位置情報　仮仕様で登録順
PLACEMENT = DT_SELECT("CC_ACTOR", @"SIDE = {SIDE}")

;自陣営の場合は操作可能キャラとして登録
IF CFLAG:CHARA_ID:所属 == 所属_プレイヤー
    IS_PLAYABLE = 1
ELSE
    IS_PLAYABLE = 0
ENDIF

;軽量化のため武器パッシブを事前集約
CALL CC_INTEGRATE_WPN_PASSIVE_SKILL(CHARA_ID, WPN_PASSIVE_SKILLS)
CALL GET_WEAPON_LIST_IDX_BY_CHARA_ID(CHARA_ID)
WEAPON_DID = RESULT:1

{
    DT_ROW_ADD "CC_ACTOR"
        ,"CHARA_ID", CHARA_ID
        ,"CHARA_NAME", ANAME(CHARA_ID)
        ,"SIDE", SIDE
        ,"PLACEMENT", PLACEMENT
        ,"FACTION", CFLAG:CHARA_ID:所属
        ,"MAX_HP", DT_CELL_GET("CHARA_STATUS", IDX, "MAX_HP", 1)
        ,"HP", MAX(1 ,DT_CELL_GET("CHARA_STATUS", IDX, "HP", 1))
        ,"STR", DT_CELL_GET("CHARA_STATUS", IDX, "STR", 1)
        ,"MAG", 魔力
        ,"ATTACK", 攻撃力
        ,"DEFENCE", 防御力
        ,"ARMOR", 軽減値
        ,"AGILITY", 行動力
        ,"CRITICAL_RATE", DT_CELL_GET("CHARA_STATUS", IDX, "CRITICAL_RATE", 1)
        ,"CRITICAL_DAMAGE_RATE", DT_CELL_GET("CHARA_STATUS", IDX, "CRITICAL_DAMAGE_RATE", 1)
        ,"HATE_RATE", DT_CELL_GET("CHARA_STATUS", IDX, "HATE_RATE", 1)
        ,"TARGETING", DT_CELL_GET("CHARA_STATUS", IDX, "TARGETING", 1)
        ,"SELECTED_SKILL_SLOT", -1
        ,"SHOW_PORTRAIT", 1
        ,"IS_PLAYABLE", IS_PLAYABLE
        ,"WPN_PASSIVE_SKILLS", WPN_PASSIVE_SKILLS:(FINDELEMENT(WPN_EQUIP_SLOT_ID_LIST, WPN_EQUIP_SLOT_ID_武器))
        ,"RELIC_1_PASSIVE_SKILLS", WPN_PASSIVE_SKILLS:(FINDELEMENT(WPN_EQUIP_SLOT_ID_LIST, WPN_EQUIP_SLOT_ID_レリック1))
        ,"RELIC_2_PASSIVE_SKILLS", WPN_PASSIVE_SKILLS:(FINDELEMENT(WPN_EQUIP_SLOT_ID_LIST, WPN_EQUIP_SLOT_ID_レリック2))
        ,"REGIST_POISON", DT_CELL_GET("CHARA_STATUS", IDX, "REGIST_POISON", 1)
        ,"REGIST_STUN", DT_CELL_GET("CHARA_STATUS", IDX, "REGIST_STUN", 1)
        ,"REGIST_BURN", DT_CELL_GET("CHARA_STATUS", IDX, "REGIST_BURN", 1)
        ,"REGIST_CHARM", DT_CELL_GET("CHARA_STATUS", IDX, "REGIST_CHARM", 1)
        ,"REGIST_PANIC", DT_CELL_GET("CHARA_STATUS", IDX, "REGIST_PANIC", 1)
        ,"REGIST_BLIND", DT_CELL_GET("CHARA_STATUS", IDX, "REGIST_BLIND", 1)
        ,"REGIST_DEATH", DT_CELL_GET("CHARA_STATUS", IDX, "REGIST_DEATH", 1)
        ,"WEAPON_DID", WEAPON_DID
}
ACTOR_DID = RESULT

;トークン管理テーブルにキャラクターを追加
DT_ROW_ADD "CC_SP_TOKEN_NUM", "ID", ACTOR_DID
;アクターフラグ用の連想配列を作成
CALL CC_CREATE_ACTOR_FLAG(ACTOR_DID)

;素手フラグ
SIF CC_CALC_CHARA_STATUS_IS_BAREHAND
    CALL CC_SET_ACTOR_FLAG(ACTOR_DID, "IS_BAREHAND", 1)

;発情トークン追加
CALL CC_ADD_SP_TOKEN(ACTOR_DID, "ESTRUS", TCVAR:CHARA_ID:媚薬)
CALL CC_SET_SP_TOKEN(ACTOR_DID, "CHEST_EXPOSE", C_COND("露出_胸:露出",,CHARA_ID))
CALL CC_SET_SP_TOKEN(ACTOR_DID, "GENITAL_EXPOSE", C_COND("露出_秘部:露出",,CHARA_ID))

;アクティブスキルスロットにセットされているスキルをスロット用テーブルにセット
FOR LOCAL, 0, LIST_COUNT(_LIST_ACTIVE_SKILL_SLOT:CHARA_ID:0)
    SKILL_DEF_NAME = %LIST_GET(_LIST_ACTIVE_SKILL_SLOT:CHARA_ID:0, LOCAL)%
    SKILL_LV = HAS_SKILL(CHARA_ID, SKILL_DEF_NAME, スキル_大分類_冒険)
    {
        DT_ROW_ADD "CC_SKILL_SLOT"
            ,"CHARA_ID", CHARA_ID
            ,"SKILL_DEF_NAME", SKILL_DEF_NAME
            ,"SKILL_LV", SKILL_LV
            ,"EQUIP_DID", 0
            ,"SKILL_SLOT_IDX", LOCAL
            ,"COOLTIME", ACTIVE_SKILL_COOLTIME:CHARA_ID:LOCAL
    }
NEXT
;装備のアクティブスキルをスロット用テーブルにセット
CALL GET_ALL_WEAPON_LIST_IDX_BY_CHARA_ID(CHARA_ID)
FOR ITER_I, 0, RESULT
    EQUIP_DID = RESULT:(1 + ITER_I)
    DIC_WPN_SKILL '= @"%DT_CELL_GETS("WEAPON_STOCK", EQUIP_DID, "ACTIVE_WEAPON_SKILL", 1)%"
    IF DIC_WPN_SKILL != ""
        CALL DIC_KEYS(DIC_WPN_SKILL)
        ARRAYCOPY "RESULTS", "MEM_SKILL_DEF_LIST"
        FOR ITER_J, 0, RESULT
            {
                DT_ROW_ADD "CC_SKILL_SLOT"
                    ,"CHARA_ID", CHARA_ID
                    ,"SKILL_DEF_NAME", MEM_SKILL_DEF_LIST:ITER_J
                    ,"SKILL_LV", TOINT(DIC_GET(DIC_WPN_SKILL, MEM_SKILL_DEF_LIST:ITER_J))
                    ,"EQUIP_DID", EQUIP_DID
                    ,"SKILL_SLOT_IDX", SLOT_IDX + 3
            }
            SLOT_IDX ++
        NEXT
    ENDIF
NEXT

;スキル処理：初期加護
;"OPENING"タイミングより優先したいので暫定でこの書式にしておく
SKILL_LV = HAS_SKILL(CHARA_ID, "WPN_ADD_BLESSING_AT_START", スキル_大分類_武器)
IF SKILL_LV
    CALL SKILL_GET_EFFECT_RATE(武器スキル_パッシブ, "WPN_ADD_BLESSING_AT_START", SKILL_LV, 1)
    EFFECT_RATE = RESULT
    CALL CC_ADD_SP_TOKEN(ACTOR_DID, "BLESSING", EFFECT_RATE)
ENDIF

;スキル処理：ルーンプリローダーの初期詠唱点
SKILL_LV = HAS_SKILL(CHARA_ID, "WPN_ADD_CAST_AT_START", スキル_大分類_武器)
IF SKILL_LV
    CALL SKILL_GET_EFFECT_RATE(武器スキル_パッシブ, "WPN_ADD_CAST_AT_START", SKILL_LV, 1)
    EFFECT_RATE = RESULT
    CALL CC_ADD_SP_TOKEN(ACTOR_DID, "CAST", EFFECT_RATE)
ENDIF

;スキル処理：残響の初期歌唱点
SKILL_LV = HAS_SKILL(CHARA_ID, "WPN_ADD_SONG_AT_START", スキル_大分類_武器)
IF SKILL_LV
    CALL SKILL_GET_EFFECT_RATE(武器スキル_パッシブ, "WPN_ADD_SONG_AT_START", SKILL_LV, 1)
    EFFECT_RATE = RESULT
    CALL CC_ADD_SP_TOKEN(ACTOR_DID, "SONG", EFFECT_RATE)
ENDIF

;スキル処理：聖印の初期詠唱点
SKILL_LV = HAS_SKILL(CHARA_ID, "WPN_ADD_PRAYER_AT_START", スキル_大分類_武器)
IF SKILL_LV
    CALL SKILL_GET_EFFECT_RATE(武器スキル_パッシブ, "WPN_ADD_PRAYER_AT_START", SKILL_LV, 1)
    EFFECT_RATE = RESULT
    CALL CC_ADD_SP_TOKEN(ACTOR_DID, "PRAYER", EFFECT_RATE)
ENDIF

;食事トークン追加処理
IF CFLAG:CHARA_ID:QST食事
    IF EXISTFUNCTION(@"GET_INFO_INSTANT_BUFF_{CFLAG:CHARA_ID:QST食事}") > 0
        TRYCALLFORMF GET_INFO_INSTANT_BUFF_{CFLAG:CHARA_ID:QST食事}("TURN")
        EFFECT_RATE = RESULT
        DT_CELL_SET "CC_ACTOR", ACTOR_DID, "MEAL_EFFECT_ID", CFLAG:CHARA_ID:QST食事, 1
        CALL CC_ADD_SP_TOKEN(ACTOR_DID, "MEAL_EFFECT", EFFECT_RATE)
        ;食事効果フラグをリセット
        CFLAG:CHARA_ID:QST食事 = 0
    ENDIF
ENDIF
; #endregion

;重複可否等を考慮して武器パッシブを整理
@CC_INTEGRATE_WPN_PASSIVE_SKILL(CHARA_ID, DIC_RESULTS)
#DIM  CHARA_ID
#DIMS REF DIC_RESULTS, 0
#DIM  DYNAMIC WPN_NUM
#DIM  DYNAMIC WPN_IDX, VARSIZE("WPN_EQUIP_SLOT_ID_LIST")
#DIMS DYNAMIC DIC_WPN_SKILL, VARSIZE("WPN_EQUIP_SLOT_ID_LIST")
#DIMS DYNAMIC PASSIVE_WEAPON_SKILLS, 10
#DIM  DYNAMIC WPN_SKILL_NUM
#DIM  DYNAMIC ITER_I
#DIM  DYNAMIC ITER_J
#DIM  DYNAMIC ITER_K
#DIM  DYNAMIC EQUIP_SLOT_ID
#DIM  DYNAMIC ARRAY_INDEX
#DIM  DYNAMIC SKILL_LV
#DIM  DYNAMIC REDUNDANT_SKILL_LV
#DIM  DYNAMIC THRESHOLD_SKILL_LV
#DIMS DYNAMIC SKILL_NAME
#DIMS DYNAMIC REDUNDANT_SKILL_TYPE

WPN_NUM = DT_SELECT("WEAPON_STOCK", @"EQUIP_CHARA_ID = {CHARA_ID}", "EQUIP_SLOT_ID ASC", WPN_IDX)

FOR ITER_I, 0, WPN_NUM
    DIC_WPN_SKILL:ITER_I = %DT_CELL_GETS("WEAPON_STOCK", WPN_IDX:ITER_I, "PASSIVE_WEAPON_SKILL", 1)%
    DEBUGPRINTFORML DIC_WPN_SKILL:{ITER_I} = %DIC_WPN_SKILL:ITER_I%
NEXT

FOR ITER_I, 0, WPN_NUM
    SIF DIC_WPN_SKILL:ITER_I == ""
        CONTINUE

    EQUIP_SLOT_ID = DT_CELL_GET("WEAPON_STOCK", WPN_IDX:ITER_I, "EQUIP_SLOT_ID", 1)
    ARRAY_INDEX = FINDELEMENT(WPN_EQUIP_SLOT_ID_LIST, EQUIP_SLOT_ID)

    WPN_SKILL_NUM = DIC_KEYSF(DIC_WPN_SKILL:ITER_I)
    ARRAYCOPY "RESULTS", "PASSIVE_WEAPON_SKILLS"
    FOR ITER_J, 0, WPN_SKILL_NUM
        SKILL_NAME = %PASSIVE_WEAPON_SKILLS:ITER_J%
        SIF XML_GET(XMLID_WPN_SKILL_PASSIVE, @"//defname[@parentname='%SKILL_NAME%']/redundantSkill", REDUNDANT_SKILL_TYPE, 1) == 0
            CONTINUE
        SKILL_LV = DIC_GETINT(DIC_WPN_SKILL:ITER_I, SKILL_NAME)
        SELECTCASE REDUNDANT_SKILL_TYPE
            CASE "NOT_ALLOWED"
                ;重複不可 -> このレベル以下の重複スキルを探して削除。上回る場合は自身を削除
                THRESHOLD_SKILL_LV = SKILL_LV
                FOR ITER_K, ITER_I + 1, WPN_NUM
                    REDUNDANT_SKILL_LV = DIC_GETINT(DIC_WPN_SKILL:ITER_K, SKILL_NAME)
                    SIF REDUNDANT_SKILL_LV == 0
                        CONTINUE
                    IF THRESHOLD_SKILL_LV >= REDUNDANT_SKILL_LV
                        DIC_WPN_SKILL:ITER_K = %DIC_REMOVE(DIC_WPN_SKILL:ITER_K, SKILL_NAME)%
                    ELSE
                        SIF THRESHOLD_SKILL_LV == SKILL_LV
                            DIC_WPN_SKILL:ITER_I = %DIC_REMOVE(DIC_WPN_SKILL:ITER_I, SKILL_NAME)%
                        THRESHOLD_SKILL_LV = REDUNDANT_SKILL_LV
                    ENDIF
                NEXT
        ENDSELECT
    NEXT
    DIC_RESULTS:ARRAY_INDEX = %DIC_WPN_SKILL:ITER_I%
NEXT

;FOR LOCAL, 0, VARSIZE("WPN_EQUIP_SLOT_ID_LIST")
;    DEBUGPRINTFORML DIC_RESULTS:{LOCAL} = %DIC_RESULTS:LOCAL%
;NEXT

@CC_SET_MOBDATA(SIDE, CC_NAME, HP, MAX_HP, 戦闘, 魔術 , MOB_ELITE , 作戦)
#DIM SIDE
#DIMS CC_NAME
#DIM HP
#DIM MAX_HP
#DIM 戦闘
#DIM 魔術

;追加分
#DIM MOB_ELITE
#DIM 防御力
#DIM 軽減値
#DIM 行動力
#DIM 敵視
#DIM 作戦
#DIM 敵視_高脅威
#DIM 敵視_低脅威
#DIM 敵視_魔術師
#DIM 敵視_低耐久

#DIM ACTOR_DID
#DIM PLACEMENT
IF !MOB_ELITE
    防御力 = 戦闘 / 10
    軽減値 = LIMIT(MAX_HP / 15, 0, 300)
    行動力 = 戦闘 * 125 / 100
    敵視   = 100
ELSE
    防御力 = 戦闘 / 8
    軽減値 = LIMIT(MAX_HP / 15, 0, 500)
    行動力 = 戦闘 * 175 / 100
    敵視   = 150
ENDIF
;位置情報　仮仕様で登録順
PLACEMENT = DT_SELECT("CC_ACTOR", @"SIDE = {SIDE}")

{
    DT_ROW_ADD "CC_ACTOR"
        ,"CHARA_ID", -1
        ,"CHARA_NAME", CC_NAME
        ,"SIDE", SIDE
        ,"PLACEMENT", PLACEMENT
        ,"MAX_HP", MAX_HP
        ,"HP", HP
        ,"STR", 戦闘
        ,"MAG", 魔術
        ,"FACTION", -1
        ,"ATTACK", 戦闘
        ,"DEFENCE", 防御力
        ,"ARMOR", 軽減値
        ,"AGILITY", 行動力
        ,"HATE_RATE", 敵視
        ,"TARGETING", 作戦
        ,"SELECTED_SKILL_SLOT", -1
        ,"ENEMY_ACTIVE_SKILL", ""
}
ACTOR_DID = RESULT

;トークン管理テーブルにキャラクターを追加
DT_ROW_ADD "CC_SP_TOKEN_NUM", "ID", ACTOR_DID
;アクターフラグ用の連想配列を作成
CALL CC_CREATE_ACTOR_FLAG(ACTOR_DID)

; DEBUGPRINTFORML *-----------------------*
; DEBUGPRINTFORML %CC_NAME%
; DEBUGPRINTFORML 敵視_高脅威:{敵視_高脅威}
; DEBUGPRINTFORML 敵視_低脅威:{敵視_低脅威}
; DEBUGPRINTFORML 敵視_魔術師:{敵視_魔術師}
; DEBUGPRINTFORML 敵視_低耐久:{敵視_低耐久}

RETURN
; #endregion

;-------------------------------------------------
; 戦闘前に実行されるスキルによる能力補正
; このファイルで扱うのはいまいち。暫定
;-------------------------------------------------
@CC_CALC_ATK_BUFF(CHARA_ID, _XML_SKILL, 補正前攻撃力)
#DIM CHARA_ID
#DIMS _XML_SKILL
#DIM 補正前攻撃力
#DIM DYNAMIC 加算攻撃力
#DIMS DYNAMIC SKILL_DEF_NAME
#DIM DYNAMIC SKILL_LV

XML_GET _XML_SKILL, "//defname[.//func[text()='ATK_BUFF_BY_MULTIPLIER']]/@parentname", RESULTS, 1
IF RESULT
    SKILL_DEF_NAME = %RESULTS%
    CALL SKILL_GET_LEVEL(CHARA_ID, 1, SKILL_DEF_NAME)
    SKILL_LV = RESULT
    XML_GET _XML_SKILL, @"//rate/li[{SKILL_LV}]", RESULTS, 1
    IF RESULT
        加算攻撃力 = (補正前攻撃力 * TOINT(RESULTS)) / 100
    ENDIF
ENDIF

RETURN 加算攻撃力

@CC_CALC_DEF_BUFF(CHARA_ID, _XML_SKILL, 補正前軽減値)
#DIM CHARA_ID
#DIMS _XML_SKILL
#DIM 補正前軽減値
#DIM DYNAMIC 加算軽減値
#DIMS DYNAMIC SKILL_DEF_NAME
#DIM DYNAMIC SKILL_LV

XML_GET _XML_SKILL, "//defname[.//func[text()='DEF_BUFF_BY_MULTIPLIER']]/@parentname", RESULTS, 1
IF RESULT
    SKILL_DEF_NAME = %RESULTS%
    CALL SKILL_GET_LEVEL(CHARA_ID, 1, SKILL_DEF_NAME)
    SKILL_LV = RESULT
    XML_GET _XML_SKILL, @"//rate/li[{SKILL_LV}]", RESULTS, 1
    IF RESULT
        加算軽減値 = (補正前軽減値 * TOINT(RESULTS)) / 100
    ENDIF
ENDIF

RETURN 加算軽減値

;-------------------------------------------------
;;;各アクターのフラグ
;-------------------------------------------------
@CC_CREATE_ACTOR_FLAG(ACTOR_DID)
#DIM  ACTOR_DID
MAP_RELEASE @"ACTOR_FLAG_{ACTOR_DID}"
MAP_CREATE @"ACTOR_FLAG_{ACTOR_DID}"

@CC_SETS_ACTOR_FLAG(ACTOR_DID, KEYS, VALUES)
#DIM  ACTOR_DID
#DIMS KEYS
#DIMS VALUES
MAP_SET @"ACTOR_FLAG_{ACTOR_DID}", KEYS, VALUES

;;; 数値をフラグ変数にセット
@CC_SET_ACTOR_FLAG(ACTOR_DID, KEYS, VALUE)
#DIM  ACTOR_DID
#DIMS KEYS
#DIM  VALUE
CALL CC_SETS_ACTOR_FLAG(ACTOR_DID, KEYS, TOSTR(VALUE))

;;; 数値をフラグ変数に加算
@CC_ADD_ACTOR_FLAG(ACTOR_DID, KEYS, ADD_VALUE)
#DIM  ACTOR_DID
#DIMS KEYS
#DIM  ADD_VALUE
#DIM  CURRENT_VALUE

CURRENT_VALUE = CC_GET_ACTOR_FLAG(ACTOR_DID, KEYS)
CALL CC_SET_ACTOR_FLAG(ACTOR_DID, KEYS, CURRENT_VALUE + ADD_VALUE)

;;; @CC_SET_ACTOR_FLAGでセットしたフラグ変数を取得する
@CC_GETS_ACTOR_FLAG(ACTOR_DID, KEYS)
#FUNCTIONS
#DIM  ACTOR_DID
#DIMS KEYS
RETURNF MAP_GET(@"ACTOR_FLAG_{ACTOR_DID}", KEYS)

;;; @CC_SET_ACTOR_FLAGでセットしたフラグ変数を数値変換して取得する
@CC_GET_ACTOR_FLAG(ACTOR_DID, KEYS)
#FUNCTION
#DIM  ACTOR_DID
#DIMS KEYS
RETURNF TOINT(CC_GETS_ACTOR_FLAG(ACTOR_DID, KEYS))

;;; @CC_SET_ACTOR_FLAGでセットしたフラグ変数を削除する
@CC_REMOVE_ACTOR_FLAG(ACTOR_DID, KEYS)
#DIM  ACTOR_DID
#DIMS KEYS
MAP_REMOVE @"ACTOR_FLAG_{ACTOR_DID}", KEYS

@CC_RELEASE_ALL_ACTOR_FLAG
#DIM MEM_CNT
#DIM IDX, CC_MAX_MEMBER_NUM

MEM_CNT = DT_SELECT("CC_ACTOR",,, IDX)
FOR LOCAL, 0, MEM_CNT
    MAP_RELEASE @"ACTOR_FLAG_{IDX:LOCAL}"
NEXT
;-------------------------------------------------
;戦闘処理時のスキル実行関数
;-------------------------------------------------
;キャラクターアクティブスキル
; #region @CC_EXEC_ACTIVE_SKILL
@CC_EXEC_ACTIVE_SKILL(EXECUTE_AT, ATTACKER_DID, DEFENDER_DID = 0, SKILL_DEF_NAME = "")
#DIMS EXECUTE_AT
#DIMS SUBCATEGORY
#DIM ATTACKER_DID
#DIM DEFENDER_DID
#DIMS SKILL_DEF_NAME

;キャラ情報
#DIM  DYNAMIC ATK_CHARA_ID
#DIM  DYNAMIC DEF_CHARA_ID
;武器情報
#DIM  DYNAMIC ATK_WPN_DID
#DIM  DYNAMIC DEF_WPN_DID
#DIMS DYNAMIC ATK_WPN_SKILL
#DIMS DYNAMIC DEF_WPN_SKILL
;スキル情報
#DIM DYNAMIC  ATK_SELECT_SLOT = -1
#DIM DYNAMIC  DEF_SELECT_SLOT = -1
#DIMS DYNAMIC _XML_SKILL
#DIM DYNAMIC  ERR_FLG
#DIM DYNAMIC  ATK_SKILL_SLOT_ID
#DIM DYNAMIC  COLLATERAL_TARGET_TYPE
#DIM DYNAMIC  COLLATERAL_TARGET_RANGE
#DIM DYNAMIC  SKILL_LEVEL
VARSET RESULT

ATK_CHARA_ID = DT_CELL_GET("CC_ACTOR", ATTACKER_DID, "CHARA_ID", 1)
IF ATK_CHARA_ID != -1
    ATK_SELECT_SLOT = DT_CELL_GET("CC_ACTOR", ATTACKER_DID, "SELECTED_SKILL_SLOT", 1)
    DT_SELECT "CC_SKILL_SLOT", @"CHARA_ID = {ATK_CHARA_ID} AND SKILL_SLOT_IDX = {ATK_SELECT_SLOT}",,ATK_SKILL_SLOT_ID
    SIF RESULT
        ATK_WPN_SKILL '= @"%DT_CELL_GETS("CC_SKILL_SLOT", ATK_SKILL_SLOT_ID, "SKILL_DEF_NAME", 1)%"
ENDIF
IF DEFENDER_DID
    DEF_CHARA_ID = DT_CELL_GET("CC_ACTOR", DEFENDER_DID, "CHARA_ID", 1)
    IF DEF_CHARA_ID != -1
        DEF_SELECT_SLOT = DT_CELL_GET("CC_ACTOR", DEFENDER_DID, "SELECTED_SKILL_SLOT", 1)
        DT_SELECT "CC_SKILL_SLOT", @"CHARA_ID = {DEF_CHARA_ID} AND SKILL_SLOT_IDX = {DEF_SELECT_SLOT}"
        SIF RESULT
            DEF_WPN_SKILL '= @"%DT_CELL_GETS("CC_SKILL_SLOT", RESULT:1, "SKILL_DEF_NAME", 1)%"
    ENDIF
ENDIF

;XML取得
IF SKILL_DEF_NAME == "" && ATK_CHARA_ID != -1
    SKILL_DEF_NAME = %ATK_WPN_SKILL%
ENDIF
IF STRFIND(SKILL_DEF_NAME, "WPN_") != 0
    XML_GET XMLID_SKILL_BATTLE, @"//defname[@parentname='%SKILL_DEF_NAME%']", _XML_SKILL, 3
ELSE
    XML_GET XMLID_WPN_SKILL_ACTIVE, @"//defname[@parentname='%SKILL_DEF_NAME%']", _XML_SKILL, 3
ENDIF
;スキル処理
SELECTCASE EXECUTE_AT
    CASE "ON_ATTACK", "BEFORE_ATTACK", "AFTER_ATTACK"
        XML_GET _XML_SKILL, @"//func[//executeAt[(text()='%EXECUTE_AT%')]]", RESULTS, 1
        IF RESULT
            TRYCCALLFORM CC_%RESULTS%(ATTACKER_DID, DEFENDER_DID, _XML_SKILL)
                CALL KOJO_XML_COMBAT_BY_TRIGGER_ID(RESULT, "TRIGGER")
                CALL CC_ACTION_MANAGER_("RESOLVE")
                RETURN 1
            CATCH
                DEBUGPRINTFORML CAUTION:@CLOSE_COMBAT_ATTACK
                DEBUGPRINTFORML スキル<%SKILL_DEF_NAME%>が呼ばれましたが、対応するスキル処理関数が見つかりませんでした
                RETURN 0
            ENDCATCH
        ENDIF
    CASE "TARGETING"
        VARI TARGETING
        VARI TARGETING_SIDE
        VARS TARGETING_TOKEN_NAME
        ERR_FLG = 1

        IF XML_GET(_XML_SKILL, "defname/collateralTargetType", RESULTS, 1)
            IF ISNUMERIC(RESULTS)
                COLLATERAL_TARGET_TYPE = TOINT(RESULTS)
            ELSEIF EXISTVAR(@"WPN_COLLATERAL_TARGET_%RESULTS%")
                COLLATERAL_TARGET_TYPE = GETVAR(@"WPN_COLLATERAL_TARGET_%RESULTS%")
            ENDIF

            IF ATK_CHARA_ID == -1
                SKILL_LEVEL = CC_HAS_SKILL(ATTACKER_DID, SKILL_DEF_NAME)
            ELSE
                SKILL_LEVEL = DT_CELL_GET("CC_SKILL_SLOT", ATK_SKILL_SLOT_ID, "SKILL_LV", 1)
            ENDIF
            ;DEBUGPRINTFORML SKILL_LEVEL {SKILL_LEVEL}
            XML_GET _XML_SKILL, @"defname/value[@label='collateralTargetRange']/li[{SKILL_LEVEL}]", RESULTS, 1
            COLLATERAL_TARGET_RANGE = TOINT(RESULTS)
            DEBUGPRINTFORML %SKILL_DEF_NAME% COLLATERAL_TARGET_TYPE = {COLLATERAL_TARGET_TYPE} COLLATERAL_TARGET_RANGE = {COLLATERAL_TARGET_RANGE}
        ENDIF

        XML_GET _XML_SKILL, "//overrideTargeting", RESULTS, 1
        IF RESULT > 0
            IF ISNUMERIC(RESULTS)
                TARGETING = TOINT(RESULTS)
                ERR_FLG = 0
            ELSEIF EXISTVAR(@"WPN_脅威選定_%RESULTS%")
                TARGETING = GETVAR(@"WPN_脅威選定_%RESULTS%")
                ERR_FLG = 0
            ENDIF

            IF TARGETING == WPN_脅威選定_トークン
                XML_GET _XML_SKILL, "//targetingToken", RESULTS, 1
                TARGETING_TOKEN_NAME '= RESULT > 0 ? @"%RESULTS%" # ""
                IF (TARGETING_TOKEN_NAME != "" && !CC_SP_TOKEN_IS_EXIST(TARGETING_TOKEN_NAME)) || TARGETING_TOKEN_NAME == ""
                    ERR_FLG = 1
                ELSE
                    ERR_FLG = 0
                ENDIF
            ENDIF
        ELSE
            RETURN 0,0,0, COLLATERAL_TARGET_TYPE, COLLATERAL_TARGET_RANGE
        ENDIF
        XML_GET _XML_SKILL, "//targetingSide", RESULTS, 1
        IF RESULT
            TARGETING_SIDE = TOINT(RESULTS)
        ENDIF
        RESULTS = %TARGETING_TOKEN_NAME%
        RETURN !ERR_FLG, TARGETING, TARGETING_SIDE, COLLATERAL_TARGET_TYPE, COLLATERAL_TARGET_RANGE
ENDSELECT
RETURN 0

;キャラクターパッシブスキル
; #region @CC_EXEC_PASSIVE_SKILL
@CC_EXEC_PASSIVE_SKILL(EXECUTE_AT, ATTACKER_DID, DEFENDER_DID, SKILL_DEF_NAME = "")
#DIMS EXECUTE_AT
#DIM ATTACKER_DID
#DIM DEFENDER_DID
#DIMS SKILL_DEF_NAME

;キャラ情報
#DIM  DYNAMIC ATK_CHARA_ID
#DIM  DYNAMIC DEF_CHARA_ID
#DIM  DYNAMIC ATK_IS_PLAYABLE
#DIM  DYNAMIC DEF_IS_PLAYABLE
;スキル情報
#DIMS DYNAMIC _XML_SKILL
#DIMS DYNAMIC ATK_SKILL_DEF_LIST, VARSIZE("SKILL_DEF_LIST")
#DIMS DYNAMIC DEF_SKILL_DEF_LIST, VARSIZE("SKILL_DEF_LIST")
#DIMS DYNAMIC _DIC_ATK_SKILL

ATK_CHARA_ID = DT_CELL_GET("CC_ACTOR", ATTACKER_DID, "CHARA_ID", 1)
DEF_CHARA_ID = DT_CELL_GET("CC_ACTOR", DEFENDER_DID, "CHARA_ID", 1)
ATK_IS_PLAYABLE = DT_CELL_GET("CC_ACTOR", ATTACKER_DID, "IS_PLAYABLE", 1)
DEF_IS_PLAYABLE = DT_CELL_GET("CC_ACTOR", DEFENDER_DID, "IS_PLAYABLE", 1)

IF ATK_IS_PLAYABLE
    CALL DIC_KEYS(_DIC_SKILL_LIST:ATK_CHARA_ID:1)
    ARRAYCOPY "RESULTS", "ATK_SKILL_DEF_LIST"
    _DIC_ATK_SKILL '= _DIC_SKILL_LIST:ATK_CHARA_ID:1
ELSE
    CALL DIC_KEYS(DT_CELL_GETS("CC_ACTOR", ATTACKER_DID, "ENEMY_PASSIVE_SKILL", 1))
    ARRAYCOPY "RESULTS", "ATK_SKILL_DEF_LIST"
    _DIC_ATK_SKILL '= DT_CELL_GETS("CC_ACTOR", ATTACKER_DID, "ENEMY_PASSIVE_SKILL", 1)
ENDIF
IF DEF_IS_PLAYABLE
    CALL DIC_KEYS(_DIC_SKILL_LIST:DEF_CHARA_ID:1)
    ARRAYCOPY "RESULTS", "DEF_SKILL_DEF_LIST"
ELSE
    CALL DIC_KEYS(DT_CELL_GETS("CC_ACTOR", DEFENDER_DID, "ENEMY_PASSIVE_SKILL", 1))
    ARRAYCOPY "RESULTS", "DEF_SKILL_DEF_LIST"
ENDIF

VARI XML_RESULT
VARS XML_RESULTS
FOR LOCAL, 0, FINDELEMENT(ATK_SKILL_DEF_LIST, "",,, 1)
    XML_GET XMLID_SKILL_BATTLE, @"//defname[@parentname='%ATK_SKILL_DEF_LIST:LOCAL%']", _XML_SKILL, 3
    SIF !RESULT
        CONTINUE
    ;XML_GET _XML_SKILL, @"//func[contains(text(), 'ATKSKILL')]", RESULTS, 1
    ;アクティブスキルは除く
    XML_GET _XML_SKILL, @"//func[//subcategory[(text()='ACTIVE')]]", XML_RESULTS, 1
    SIF RESULT
        CONTINUE
    XML_GET _XML_SKILL, @"//triggerChance/li[{DIC_GETINT(_DIC_ATK_SKILL, ATK_SKILL_DEF_LIST:LOCAL)}]", XML_RESULTS, 1
    SIF RESULT && !PERCENT(TOINT(XML_RESULTS))
        CONTINUE
    XML_GET _XML_SKILL, "//triggerCondition", XML_RESULTS, 1
    XML_RESULT = RESULT
    SIF XML_RESULT
        DEBUGPRINTFORML triggerCondition %XML_RESULTS% = {TOINT(STRFORM(XML_RESULTS))}
    SIF XML_RESULT && !TOINT(STRFORM(XML_RESULTS))
        CONTINUE
    XML_GET _XML_SKILL, @"//func[//executeAt[(text()='%EXECUTE_AT%')]]", XML_RESULTS, 1
    SIF !RESULT
        CONTINUE
    DEBUGPRINTFORML EXEC CC_%XML_RESULTS%
    TRYCCALLFORM CC_%XML_RESULTS%(ATTACKER_DID, DEFENDER_DID, _XML_SKILL)
        ;パッシブは行数が増えがちなので使用せずEXECとまとめて表示
        ;CALL KOJO_XML_COMBAT_BY_TRIGGER_ID(RESULT, "TRIGGER")
    CATCH
        DEBUGPRINTFORML CAUTION:@CLOSE_COMBAT_ATTACK
        DEBUGPRINTFORML スキル<%ATK_SKILL_DEF_LIST:LOCAL%>が呼ばれましたが、対応するスキル処理関数が見つかりませんでした
    ENDCATCH
NEXT
CALL CC_ACTION_MANAGER_("RESOLVE")
; #endregion

;-------------------------------------------------
;;; HAS_SKILLのキャラ・エネミー対応版
;;; CC_ACTOR生成後(つまりCLOSE_COMBAT中のみ)使用可能
;-------------------------------------------------
@CC_HAS_SKILL(ACTOR_DID, SKILL_DEF_NAME, MAJORGENRE = スキル_大分類_冒険)
#FUNCTION
#DIM  ACTOR_DID
#DIMS SKILL_DEF_NAME
#DIM  MAJORGENRE
#DIM  DYNAMIC CHARA_ID
#DIMS DYNAMIC DIC_ENEMY_SKILLS

CHARA_ID = DT_CELL_GET("CC_ACTOR", ACTOR_DID, "CHARA_ID", 1)
IF CHARA_ID != -1
    RETURNF HAS_SKILL(CHARA_ID, SKILL_DEF_NAME, MAJORGENRE)
ELSE
    DIC_ENEMY_SKILLS = %DT_CELL_GETS("CC_ACTOR", ACTOR_DID, "ENEMY_ACTIVE_SKILL", 1)%
    IF DIC_CONTAINSKEY(DIC_ENEMY_SKILLS, SKILL_DEF_NAME)
        RETURNF TOINT(DIC_GET(DIC_ENEMY_SKILLS, SKILL_DEF_NAME))
    ENDIF
    DIC_ENEMY_SKILLS = %DT_CELL_GETS("CC_ACTOR", ACTOR_DID, "ENEMY_PASSIVE_SKILL", 1)%
    IF DIC_CONTAINSKEY(DIC_ENEMY_SKILLS, SKILL_DEF_NAME)
        RETURNF TOINT(DIC_GET(DIC_ENEMY_SKILLS, SKILL_DEF_NAME))
    ENDIF
ENDIF
RETURNF 0

;-------------------------------------------------
;指定した定義名のスキルを習得済みの場合スキルレベルを返す
;装備スキル(武器、レリック)の場合はその武器のDIDをRESULT:1として返す
;装備スキルに重複したスキルがセットされている場合は、最も高いLVを優先して返す
;-------------------------------------------------
@HAS_SKILL(CHARA_ID, SKILL_DEF_NAME, MAJORGENRE = スキル_大分類_冒険)
; #region
#FUNCTION
#DIM  CHARA_ID
#DIMS SKILL_DEF_NAME
#DIM  MAJORGENRE
#DIM  DYNAMIC DID, 1000
#DIMS DYNAMIC SKILL_DIC
#DIM  DYNAMIC TEMP_SKILL_LV
#DIM  DYNAMIC TEMP_DID
#DIM  DYNAMIC CONFIRMED_SKILL_LV
#DIM  DYNAMIC CONFIRMED_DID

SIF CHARA_ID == -1
    RETURNF 0

IF MAJORGENRE != スキル_大分類_武器
    CALLF DIC_KEYSF(_DIC_SKILL_LIST:CHARA_ID:MAJORGENRE)
    IF FINDELEMENT(RESULTS, SKILL_DEF_NAME) != -1
        RETURNF TOINT(DIC_GET(_DIC_SKILL_LIST:CHARA_ID:MAJORGENRE, SKILL_DEF_NAME))
    ELSE
        RETURNF 0
    ENDIF
ELSE
    DT_SELECT "WEAPON_STOCK", @"EQUIP_CHARA_ID = {CHARA_ID}", "EQUIP_SLOT_ID ASC", DID
    FOR LOCAL, 0, RESULT
        SKILL_DIC = %DT_CELL_GETS("WEAPON_STOCK", DID:LOCAL, "ACTIVE_WEAPON_SKILL", 1)%
        IF DIC_CONTAINSKEY(SKILL_DIC, SKILL_DEF_NAME)
            TEMP_SKILL_LV = TOINT(DIC_GET(SKILL_DIC, SKILL_DEF_NAME))
            TEMP_DID = DID:LOCAL
            IF TEMP_SKILL_LV > CONFIRMED_SKILL_LV
                CONFIRMED_SKILL_LV = TEMP_SKILL_LV
                CONFIRMED_DID = TEMP_DID
            ENDIF
        ENDIF
        SKILL_DIC = %DT_CELL_GETS("WEAPON_STOCK", DID:LOCAL, "PASSIVE_WEAPON_SKILL", 1)%
        IF DIC_CONTAINSKEY(SKILL_DIC, SKILL_DEF_NAME)
            TEMP_SKILL_LV = TOINT(DIC_GET(SKILL_DIC, SKILL_DEF_NAME))
            TEMP_DID = DID:LOCAL
            IF TEMP_SKILL_LV > CONFIRMED_SKILL_LV
                CONFIRMED_SKILL_LV = TEMP_SKILL_LV
                CONFIRMED_DID = TEMP_DID
            ENDIF
        ENDIF
    NEXT
    RESULT:1 = CONFIRMED_DID
    RETURNF CONFIRMED_SKILL_LV
ENDIF
; #endregion

;-------------------------------------------------
;;; 特定の装備が指定したスキルを持つかどうかを判定する
;;; 持つ場合はスキルレベルを返す
;-------------------------------------------------
@WPN_HAS_SKILL(EQUIP_DID, SKILL_DEF_NAME)
; #region
#FUNCTION
#DIM  EQUIP_DID
#DIMS SKILL_DEF_NAME
#DIM  DYNAMIC SKILL_LV
#DIMS DYNAMIC SKILL_DIC

SKILL_DIC = %DT_CELL_GETS("WEAPON_STOCK", EQUIP_DID, "ACTIVE_WEAPON_SKILL", 1)%
IF DIC_CONTAINSKEY(SKILL_DIC, SKILL_DEF_NAME)
    SKILL_LV = TOINT(DIC_GET(SKILL_DIC, SKILL_DEF_NAME))
ENDIF
SKILL_DIC = %DT_CELL_GETS("WEAPON_STOCK", EQUIP_DID, "PASSIVE_WEAPON_SKILL", 1)%
IF DIC_CONTAINSKEY(SKILL_DIC, SKILL_DEF_NAME)
    SKILL_LV = TOINT(DIC_GET(SKILL_DIC, SKILL_DEF_NAME))
ENDIF

RETURNF SKILL_LV
; #endregion

;-------------------------------------------------
;;; 戦闘系スキルのジャンルを取得
;;; - ARGS
;;;     - SKILL_DEF_NAME {string}: スキル定義名
;;; - RETURN
;;;     - RESULT:0 {int}: 0=該当なし 1=キャラクターの戦闘スキル 2=装備スキル
;;;     - RESULT:1 {int}: スキルのジャンル(キャラクターの戦闘スキルはアクティブ、パッシブ混在なので実質装備のみ有効な返り値
;;;       武器スキル_アクティブor武器スキル_パッシブ)
;-------------------------------------------------
@CC_GET_SKILL_GENRE(SKILL_DEF_NAME)
; #region CC_GET_SKILL_GENRE
#FUNCTION
#DIMS DYNAMIC SKILL_DEF_NAME
#DIM  DYNAMIC GENRE
#DIM  DYNAMIC WPN_SKILL_GENRE
#DIMS DYNAMIC _XML_SKILL

;キャラクターの戦闘スキルかを判定
XML_GET XMLID_SKILL_BATTLE, @"//defname[@parentname='%SKILL_DEF_NAME%']", _XML_SKILL, 3
IF RESULT
    RESULT:1 = 1
    RETURNF 1
ENDIF
;装備スキルかを判定
WPN_SKILL_GENRE = WPN_SKILL_GET_GENRE(SKILL_DEF_NAME)
IF WPN_SKILL_GENRE != -1
    RESULT:1 = 2
    RETURNF 2
ENDIF

RETURNF 0

;-------------------------------------------------
;;; 武器スキルのジャンルを取得
;;;-------------------------------------------------
@WPN_SKILL_GET_GENRE(SKILL_DEF_NAME)
; #region
#FUNCTION
#DIMS DYNAMIC SKILL_DEF_NAME
#DIMS DYNAMIC _XML_SKILL
#DIM  DYNAMIC GENRE

GENRE = 武器スキル_アクティブ
XML_GET XMLID_WPN_SKILL:GENRE, @"//defname[@parentname='%SKILL_DEF_NAME%']", _XML_SKILL, 3
IF RESULT
    RETURNF GENRE
ENDIF

GENRE = 武器スキル_パッシブ
XML_GET XMLID_WPN_SKILL:GENRE, @"//defname[@parentname='%SKILL_DEF_NAME%']", _XML_SKILL, 3
IF RESULT
    RETURNF GENRE
ENDIF

RETURNF -1
;#endregion

;-------------------------------------------------
;;; 武器スキルのXMLを取得
;;;-------------------------------------------------
@WPN_SKILL_GET_XML(SKILL_DEF_NAME)
; #region
#DIMS SKILL_DEF_NAME

VARS _XML_SKILL
XML_GET XMLID_WPN_SKILL:武器スキル_アクティブ, @"//defname[@parentname='%SKILL_DEF_NAME%']", _XML_SKILL, 3
IF !RESULT
    XML_GET XMLID_WPN_SKILL:武器スキル_パッシブ, @"//defname[@parentname='%SKILL_DEF_NAME%']", _XML_SKILL, 3
    IF !RESULT
        PRINTFORMW エラー:@WPN_SKILL_GET_EFFECT_RATE スキル<%SKILL_DEF_NAME%>のデータが取得できませんでした
        THROW
    ENDIF
ENDIF

RESULTS = %_XML_SKILL%
RETURN 1

;-------------------------------------------------
;;; 武器スキルのXMLを取得(式中関数版)
;;;-------------------------------------------------
@WPN_SKILL_GET_XMLF(SKILL_DEF_NAME)
; #region
#FUNCTIONS
#DIMS SKILL_DEF_NAME
#DIMS _XML_SKILL

IF XML_GET(XMLID_WPN_SKILL:武器スキル_アクティブ, @"//defname[@parentname='%SKILL_DEF_NAME%']", _XML_SKILL, 3)
    RETURNF _XML_SKILL
ELSEIF XML_GET(XMLID_WPN_SKILL:武器スキル_パッシブ, @"//defname[@parentname='%SKILL_DEF_NAME%']", _XML_SKILL, 3)
    RETURNF _XML_SKILL
ELSE
    THROW エラー:@WPN_SKILL_GET_EFFECT_RATE スキル<%SKILL_DEF_NAME%>のデータが取得できませんでした
ENDIF
;-------------------------------------------------
;;; 武器スキルの効果量を取得
;;;-------------------------------------------------
@WPN_SKILL_GET_EFFECT_RATE(SKILL_DEF_NAME, SKILL_LV)
; #region
#DIMS SKILL_DEF_NAME
#DIM  SKILL_LV

VARS _XML_SKILL
CALL WPN_SKILL_GET_XML(SKILL_DEF_NAME)
_XML_SKILL = %RESULTS%

VARI RATE, 3
XML_GET _XML_SKILL, @"//rate/li[{SKILL_LV}]", RESULTS, 1
IF RESULT
    RATE:0 = TOINT(RESULTS)
ENDIF
XML_GET _XML_SKILL, @"//rate2/li[{SKILL_LV}]", RESULTS, 1
IF RESULT
    RATE:1 = TOINT(RESULTS)
ENDIF
XML_GET _XML_SKILL, @"//rate3/li[{SKILL_LV}]", RESULTS, 1
IF RESULT
    RATE:2 = TOINT(RESULTS)
ENDIF

IF RATE:0 != 0
    RESULT:1 = RATE:1
    RESULT:2 = RATE:2
    RETURN RATE:0
ELSE
    RETURN 0
ENDIF
; #endregion

;-------------------------------------------------
;;; 武器スキルの効果量を取得(式中関数版)
;;;-------------------------------------------------
@WPN_SKILL_GET_EFFECT_RATEF(SKILL_DEF_NAME, SKILL_LV, RATE_ID = 1)
; #region
#FUNCTION
#DIMS SKILL_DEF_NAME
#DIM  SKILL_LV
#DIM  RATE_ID
#DIMS _XML_SKILL

_XML_SKILL = %WPN_SKILL_GET_XMLF(SKILL_DEF_NAME)%

SELECTCASE RATE_ID
    CASE 1
        SIF XML_GET(_XML_SKILL, @"//rate/li[{SKILL_LV}]", RESULTS, 1)
            RETURNF TOINT(RESULTS)
    CASE 2
        SIF XML_GET(_XML_SKILL, @"//rate2/li[{SKILL_LV}]", RESULTS, 1)
            RETURNF TOINT(RESULTS)
    CASE 3
        SIF XML_GET(_XML_SKILL, @"//rate3/li[{SKILL_LV}]", RESULTS, 1)
            RETURNF TOINT(RESULTS)
ENDSELECT

THROW エラー:@WPN_SKILL_GET_EFFECT_RATEF スキル<%SKILL_DEF_NAME%> LV={SKILL_LV} RATE={RATE_ID}のデータが取得できませんでした

; #endregion

;-------------------------------------------------
;;; スキルのクールタイムを取得
;;;-------------------------------------------------
@WPN_SKILL_GET_COOLTIME(SKILL_DEF_NAME, SKILL_LV)
; #region
#DIMS DYNAMIC SKILL_DEF_NAME
#DIM  DYNAMIC SKILL_LV

VARS _XML_SKILL
CALL WPN_SKILL_GET_XML(SKILL_DEF_NAME)
_XML_SKILL = %RESULTS%

XML_GET _XML_SKILL, @"//cooltime/li[{SKILL_LV}]", RESULTS, 1
RETURN TOINT(RESULTS)
; #endregion

;武器パッシブスキル
; #region @CC_EXEC_WPN_PASSIVE_SKILL
@CC_EXEC_WPN_PASSIVE_SKILL(EXECUTE_AT, ATTACKER_DID, DEFENDER_DID)
#DIMS EXECUTE_AT
#DIM ATTACKER_DID
#DIM DEFENDER_DID

;キャラ情報
#DIM  DYNAMIC ATK_CHARA_ID
#DIM  DYNAMIC DEF_CHARA_ID
;武器情報
#DIM  DYNAMIC ATK_EQUIP_DID, 3
#DIM  DYNAMIC ATK_EQUIPNUM
#DIM  DYNAMIC DEF_EQUIP_DID, 3
#DIMS DYNAMIC DIC_WPN_SKILL
#DIM  DYNAMIC WPN_SKILLNUM
#DIMS DYNAMIC WPN_SKILL_DEF_LIST, VARSIZE("SKILL_DEF_LIST")
;スキル情報
#DIMS DYNAMIC _XML_SKILL
#DIMS DYNAMIC SKILL_DEF_NAME

#DIM  DYNAMIC ITER_I
#DIM  DYNAMIC ITER_J

ATK_CHARA_ID = DT_CELL_GET("CC_ACTOR", ATTACKER_DID, "CHARA_ID", 1)
DEF_CHARA_ID = DT_CELL_GET("CC_ACTOR", DEFENDER_DID, "CHARA_ID", 1)
IF ATK_CHARA_ID != -1
    CALL GET_ALL_WEAPON_LIST_IDX_BY_CHARA_ID(ATK_CHARA_ID)
    ATK_EQUIPNUM = RESULT
    FOR LOCAL, 0, ATK_EQUIPNUM
        ATK_EQUIP_DID:LOCAL = RESULT:(1 + LOCAL)
    NEXT
ENDIF

FOR ITER_I, 0, ATK_EQUIPNUM
    SIF !ATK_EQUIP_DID:ITER_I
        CONTINUE
    DIC_WPN_SKILL = %DT_CELL_GETS("WEAPON_STOCK", ATK_EQUIP_DID:ITER_I, "PASSIVE_WEAPON_SKILL", 1)%
    CALL DIC_KEYS(DIC_WPN_SKILL)
    SIF !RESULT
        CONTINUE
    WPN_SKILLNUM = RESULT
    ARRAYCOPY "RESULTS", "WPN_SKILL_DEF_LIST"
    FOR ITER_J, 0, WPN_SKILLNUM
        XML_GET XMLID_WPN_SKILL_PASSIVE, @"//defname[@parentname='%WPN_SKILL_DEF_LIST:ITER_J%']", _XML_SKILL, 3
        SIF !RESULT
            CONTINUE
        XML_GET _XML_SKILL, @"//triggerChance/li[{DIC_GETINT(DIC_WPN_SKILL, WPN_SKILL_DEF_LIST:ITER_J)}]", RESULTS, 1
        SIF RESULT && !PERCENT(TOINT(RESULTS))
            CONTINUE
        XML_GET _XML_SKILL, "//triggerCondition", RESULTS, 1
        ;DEBUGPRINTFORML CONDITION: %RESULTS% = {TOINT(STRFORM(RESULTS))}
        SIF RESULT && !TOINT(STRFORM(RESULTS))
            CONTINUE
        XML_GET _XML_SKILL, @"//func[//executeAt[(text()='%EXECUTE_AT%')]]", RESULTS, 1
        SIF !RESULT
            CONTINUE
        TRYCCALLFORM CC_%RESULTS%(ATTACKER_DID, DEFENDER_DID, _XML_SKILL, ATK_EQUIP_DID:ITER_I)
            ;パッシブは行数が増えがちなので、使用しない。
            ;CALL KOJO_XML_COMBAT_BY_TRIGGER_ID(RESULT, "TRIGGER")
            CALL CC_ACTION_MANAGER_("RESOLVE")
        CATCH
            DEBUGPRINTFORML スキル<%WPN_SKILL_DEF_LIST:ITER_J%>が呼ばれましたが、対応するスキル処理関数が見つかりませんでした
        ENDCATCH
    NEXT
NEXT
; #endregion

;-------------------------------------------------
; コスト付きスキルのコスト支払い処理
;-------------------------------------------------
; #region @CC_COST_ITEM_TOCAST
@CC_COST_ITEM_TOCAST(CHARA_DID, SKILL_DEF_NAME)
#DIM CHARA_DID
#DIMS SKILL_DEF_NAME
#DIMS DYNAMIC DIC_REQITEM_TOCAST
#DIMS DYNAMIC REQ_ITEM_NAME
#DIM  DYNAMIC REQ_ITEM_NUM
#DIM  DYNAMIC COST_ITEM, ITEM_LENGTH

;アイテムの場合プレイヤー所属以外のキャラは要求コストを無視
SIF DT_CELL_GET("CC_ACTOR", CHARA_DID, "FACTION", 1) != CFLAG:MASTER:所属
    RETURN 1

;武器スキルかどうか確認
DIC_REQITEM_TOCAST = %GET_SKILL_DATA(SKILL_DEF_NAME, "reqItemToCast", 1, 武器スキル_アクティブ)%

;習得スキルかどうか確認
SIF DIC_REQITEM_TOCAST == ""
    DIC_REQITEM_TOCAST = %GET_SKILL_DATA(SKILL_DEF_NAME, "reqItemToCast", 0, スキル_ジャンル_戦闘)%

IF DIC_REQITEM_TOCAST != ""
    CALL DIC_KEYS(DIC_REQITEM_TOCAST)
    FOR LOCAL, 0, RESULT
        REQ_ITEM_NAME = %RESULTS:LOCAL%
        REQ_ITEM_NUM = TOINT(DIC_GET(DIC_REQITEM_TOCAST, RESULTS:LOCAL))
        IF HO_ITEM_STOCK:GETVAR(REQ_ITEM_NAME) < REQ_ITEM_NUM
            RETURN 0
        ELSE
            COST_ITEM:GETVAR(REQ_ITEM_NAME) -= REQ_ITEM_NUM
        ENDIF
    NEXT
    CALL CHANGE_ITEM_STOCK_M(COST_ITEM)
ENDIF
RETURN 1
; #endregion

; #region @CC_COST_ITEM_TOCAST
@CC_COST_TOKEN_TOCAST(CHARA_DID, DIC_REQTOKEN_TOCAST)
#DIM  CHARA_DID
#DIMS SKILL_DEF_NAME
#DIM  GENRE
#DIMS DYNAMIC DIC_REQTOKEN_TOCAST
#DIMS DYNAMIC REQ_ITEM_NAME
#DIM  DYNAMIC REQ_ITEM_NUM
#DIM  DYNAMIC NOW_OWN_ITEM
#DIM  ITER_I

IF DIC_REQTOKEN_TOCAST != ""
    CALL DIC_KEYS(DIC_REQTOKEN_TOCAST)
    FOR ITER_I, 0, RESULT
        REQ_ITEM_NAME = %RESULTS:ITER_I%
        REQ_ITEM_NUM = TOINT(DIC_GET(DIC_REQTOKEN_TOCAST, RESULTS:ITER_I))
        NOW_OWN_ITEM = DT_CELL_GET("CC_ACTOR", CHARA_DID, REQ_ITEM_NAME, 1)
        DT_CELL_SET "CC_ACTOR", CHARA_DID, REQ_ITEM_NAME, MAX(NOW_OWN_ITEM - REQ_ITEM_NUM, 0), 1
    NEXT
ENDIF
RETURN 1
; #endregion

; #region @CC_COST_SP_TOKEN_TOCAST
@CC_COST_SP_TOKEN_TOCAST(CHARA_DID, DIC_REQTOKEN_TOCAST)
#DIM  CHARA_DID
#DIMS DIC_REQTOKEN_TOCAST

#DIMS DYNAMIC REQ_TOKEN_NAME
#DIM  DYNAMIC REQ_TOKEN_NUM
#DIM  KEY_NUM
#DIM  ITER_I

IF DIC_REQTOKEN_TOCAST != ""
    CALL DIC_KEYS(DIC_REQTOKEN_TOCAST)
    KEY_NUM = RESULT
    FOR ITER_I, 0, KEY_NUM
        REQ_TOKEN_NAME = %RESULTS:ITER_I%
        REQ_TOKEN_NUM = TOINT(DIC_GET(DIC_REQTOKEN_TOCAST, RESULTS:ITER_I))
        CALL CC_SUB_SP_TOKEN(CHARA_DID, REQ_TOKEN_NAME, REQ_TOKEN_NUM)
    NEXT
ENDIF
RETURN 1
; #endregion

;-------------------------------------------------
;スキル定義XMLからパラメータ参照用テーブルを作成
;-------------------------------------------------
; #region @SKILL_GET_PARAMS_TO_TABLE
@SKILL_GET_PARAMS_TO_TABLE(_XML_SKILL, CHARA_DID, EQUIP_DID = 0)
#DIMS _XML_SKILL
#DIM  CHARA_DID
#DIM  EQUIP_DID
#DIM  DYNAMIC CHARA_ID
#DIM  DYNAMIC IS_PLAYABLE
#DIMS DYNAMIC SKILL_DEF_NAME
#DIMS DYNAMIC CATEGORY
#DIMS DYNAMIC SUBCATEGORY
#DIMS DYNAMIC SKILL_NAME
#DIM  DYNAMIC SKILL_LV
#DIM  DYNAMIC SKILL_COOLTIME
#DIM  DYNAMIC EFFECT_RATE
#DIM  DYNAMIC EFFECT_RATE2
#DIM  DYNAMIC EFFECT_RATE3
#DIM  DYNAMIC WEAPON_DID
#DIMS DYNAMIC DIC_WPN_SKILL
#DIMS DYNAMIC REQITEM_TOCAST
#DIMS DYNAMIC REQTOKEN_TOCAST
#DIMS DYNAMIC ENEMY_SKILL
#DIM  DYNAMIC VALUE_LABEL_COUNT
#DIMS DYNAMIC LABELS, MAX_VALUE_PER_SKILL

CHARA_ID = DT_CELL_GET("CC_ACTOR", CHARA_DID, "CHARA_ID", 1)
IS_PLAYABLE = DT_CELL_GET("CC_ACTOR", CHARA_DID, "IS_PLAYABLE", 1)
IF DT_EXIST("SKILL_PARAMS")
    DT_CLEAR "SKILL_PARAMS"
ENDIF
CALL CREATE_SKILL_PARAMS_TABLE

XML_GET _XML_SKILL, "//defname/@parentname", RESULTS, 1
SIF !RESULT
    RETURN 0
SKILL_DEF_NAME = %RESULTS%
XML_GET _XML_SKILL, "//skillname", RESULTS,1
SKILL_NAME = %RESULTS%
XML_GET _XML_SKILL, "//subcategory", RESULTS,1
SUBCATEGORY = %RESULTS%
;通常アクティブスキル
IF SUBCATEGORY == "DEFAULT"
    ;防御などのデフォルトスキルはレベル1として扱う
    SKILL_LV = 1
ELSEIF !EQUIP_DID
    IF IS_PLAYABLE
        CALL SKILL_GET_LEVEL(CHARA_ID, 1, SKILL_DEF_NAME)
        SKILL_LV = RESULT
    ELSE
        IF SUBCATEGORY == "ACTIVE"
            ENEMY_SKILL = %DT_CELL_GETS("CC_ACTOR", CHARA_DID, "ENEMY_ACTIVE_SKILL", 1)%
            SKILL_LV = TOINT(DIC_GET(ENEMY_SKILL, SKILL_DEF_NAME))
            ; ENDIF
        ELSE
            ENEMY_SKILL = %DT_CELL_GETS("CC_ACTOR", CHARA_DID, "ENEMY_PASSIVE_SKILL", 1)%
            SKILL_LV = TOINT(DIC_GET(ENEMY_SKILL, SKILL_DEF_NAME))
        ENDIF
    ENDIF
    ;武器アクティブスキル
ELSE
    IF IS_PLAYABLE
        IF SUBCATEGORY == "ACTIVE"
            DIC_WPN_SKILL = %DT_CELL_GETS("WEAPON_STOCK", EQUIP_DID, "ACTIVE_WEAPON_SKILL", 1)%
        ELSE
            DIC_WPN_SKILL = %DT_CELL_GETS("WEAPON_STOCK", EQUIP_DID, "PASSIVE_WEAPON_SKILL", 1)%
        ENDIF
        SKILL_LV = TOINT(DIC_GET(DIC_WPN_SKILL, SKILL_DEF_NAME))
    ELSE
        RETURN 0
    ENDIF
ENDIF
;効果量とクールタイム
XML_GET _XML_SKILL, @"//rate/li[{SKILL_LV}]", RESULTS, 1
EFFECT_RATE  = TOINT(RESULTS)
XML_GET _XML_SKILL, @"//rate2/li[{SKILL_LV}]", RESULTS, 1
EFFECT_RATE2 = TOINT(RESULTS)
XML_GET _XML_SKILL, @"//rate3/li[{SKILL_LV}]", RESULTS, 1
EFFECT_RATE3 = TOINT(RESULTS)
XML_GET _XML_SKILL, @"//cooltime/li[{SKILL_LV}]", RESULTS, 1
SKILL_COOLTIME = TOINT(RESULTS)

;ラベル付き効果量
;modifierと分けるため、defname直下のみ取得
VALUE_LABEL_COUNT = XML_GET(_XML_SKILL, @"defname/value/@label", LABELS, 1)
;DEBUGPRINTFORML VALUE_LABEL_COUNT = {VALUE_LABEL_COUNT}
FOR LOCAL, 0, VALUE_LABEL_COUNT
    XML_GET _XML_SKILL, @"defname/value[@label = '%LABELS:LOCAL%']/li[{SKILL_LV}]", RESULTS, 1
    MAP_SET CCS_MAP_SKILL_VALUES, LABELS:LOCAL, RESULTS
NEXT
;DEBUGPRINTFORML CCS_MAP_SKILL_VALUES %SKILL_DEF_NAME%
;DEBUGPRINTFORML %MAP_TOXML(CCS_MAP_SKILL_VALUES)%

;消費コスト_アイテム
RESULTS '= ""
XML_GET _XML_SKILL, @"//reqItemToCast", RESULTS, 1
REQITEM_TOCAST = %RESULTS%
IF REQITEM_TOCAST != ""
    REQITEM_TOCAST = %REPLACE(REQITEM_TOCAST, "\\$RATE", @"{EFFECT_RATE}")%
ENDIF
;消費コスト_トークン
RESULTS '= ""
XML_GET _XML_SKILL, @"//reqTokenToCast", RESULTS, 1
REQTOKEN_TOCAST = %RESULTS%
IF REQTOKEN_TOCAST != ""
    REQTOKEN_TOCAST = %REPLACE(REQTOKEN_TOCAST, "\\$RATE", @"{EFFECT_RATE}")%
ENDIF

{
    DT_ROW_ADD "SKILL_PARAMS"
        ,"SKILL_DEF_NAME", SKILL_DEF_NAME
        ,"SKILL_NAME", SKILL_NAME
        ,"SKILL_LV", SKILL_LV
        ,"EFFECT_RATE", EFFECT_RATE
        ,"EFFECT_RATE2", EFFECT_RATE2
        ,"EFFECT_RATE3", EFFECT_RATE3
        ,"COOLTIME", SKILL_COOLTIME
        ,"REQITEM_TOCAST", REQITEM_TOCAST
        ,"REQTOKEN_TOCAST", REQTOKEN_TOCAST
}
RETURN 1
; #endregion

;-------------------------------------------------
;全員分のパッシブ発動チェック
;-------------------------------------------------
@CC_PASSIVE_CHECK_ALL(EXECUTE_AT)
#DIMS EXECUTE_AT
#DIMS ACTOR_LIST, CC_MAX_MEMBER_NUM + 1
#DIM  DYNAMIC ACTOR_DID
#DIM  DYNAMIC TARGET_DID

CALL CLOSE_COMBAT_SET_ORDER(ACTOR_LIST)
FOR LOCAL, 0, CC_MAX_MEMBER_NUM + 1
    SIF ACTOR_LIST:LOCAL == "-1"
        BREAK

    ACTOR_DID = TOINT(DIC_GET(ACTOR_LIST:LOCAL, "ACTOR_DID"))
    CALL CLOSE_COMBAT_SET_TARGET(ACTOR_DID)
    TARGET_DID = RESULT
    CALL CC_EXEC_PASSIVE_SKILL(EXECUTE_AT, ACTOR_DID, TARGET_DID)
    CALL CC_EXEC_WPN_PASSIVE_SKILL(EXECUTE_AT, ACTOR_DID, TARGET_DID)

    CALL CLOSE_COMBAT_DRAW_WINDOW(ACTOR_DID)

NEXT


code:
;-------------------------------------------------
;;; 戦闘イベント入力処理関連
;;; 入力受付処理
;;; - RETURN: 0=再入力, 1=入力完了
;-------------------------------------------------
@CLOSE_COMBAT_INPUT(OPTIONS)
#DIMS OPTIONS
#DIMS DYNAMIC INPUT_VALUES
#DIM  DYNAMIC CHARA_DID
#DIM DYNAMIC SKILL_SLOT_IDX
#DIM DYNAMIC NOW_SELECTED_SLOT_IDX

WHILE 1
	VARSET RESULTS
	INPUTS , 1
	REDRAW 0
	;CLEARLINE 1
	INPUT_VALUES = %RESULTS:1%
	IF !DIC_CONTAINSKEY(OPTIONS, "TARGET_SELECT")
		;スキルを右クリック
		IF RESULT:1 == 2
			IF DIC_GET(INPUT_VALUES, "INPUT_FROM") == "SKILL_SLOT"
				CHARA_DID = TOINT(DIC_GET(INPUT_VALUES, "CHARA_DID"))
				SKILL_SLOT_IDX = TOINT(DIC_GET(INPUT_VALUES, "SKILL_SLOT_IDX"))
				NOW_SELECTED_SLOT_IDX = DT_CELL_GET("CC_ACTOR", CHARA_DID, "SELECTED_SKILL_SLOT", 1)
				IF SKILL_SLOT_IDX != NOW_SELECTED_SLOT_IDX
					DT_CELL_SET "CC_ACTOR", CHARA_DID, "SELECTED_SKILL_SLOT", SKILL_SLOT_IDX, 1
					CALL FL_PLAYSE("Switch_0.mp3")
				ELSE
					DT_CELL_SET "CC_ACTOR", CHARA_DID, "SELECTED_SKILL_SLOT", -1, 1
					CALL FL_PLAYSE("Switch_1.mp3")
				ENDIF
				RETURN 0
			ENDIF
			;左クリック
		ELSEIF RESULT:1 == 1
			;何もない場所をクリック
			IF INPUT_VALUES == "" || INPUT_VALUES == "_"
				BREAK
				;オートを選択
			ELSEIF DIC_CONTAINSKEY(INPUT_VALUES, "AUTO")
				CC_AUTO_MODE = CC_AUTO_MODE_INPUT + 1
				BREAK
				;オートの種類を選択するオプションを表示
			ELSEIF DIC_GET(INPUT_VALUES, "AUTO_OPTION") == "1"
				CALL OPTION_POPUP("通常攻撃,スキル,")
				SIF RESULT != -1
					CC_AUTO_MODE_INPUT = RESULT
				RETURN 0
				;オートの速度を選択するオプションを表示
			ELSEIF DIC_GET(INPUT_VALUES, "AUTO_OPTION") == "2"
				CALL OPTION_POPUP("通常,1.5倍速,2倍速,")
				IF RESULT == 0
					CC_AUTO_INPUT_WAIT = 200
				ELSEIF RESULT == 1
					CC_AUTO_INPUT_WAIT = 133
				ELSEIF RESULT == 2
					CC_AUTO_INPUT_WAIT = 100
				ENDIF
				RETURN 0
			ENDIF
			IF DIC_CONTAINSKEY(INPUT_VALUES, "FORCE_END")
				CC_FORCE_END = TOINT(DIC_GET(INPUT_VALUES, "FORCE_END"))
				BREAK
			ENDIF
			;防御を選択
			IF DIC_CONTAINSKEY(INPUT_VALUES, "DEFENCE")
				CHARA_DID = TOINT(DIC_GET(INPUT_VALUES, "CHARA_DID"))
				DT_CELL_SET "CC_ACTOR", CHARA_DID, "SELECTED_SKILL_SLOT", -1, 1
				DT_CELL_SET "CC_ACTOR", CHARA_DID, "SUBSTATE", "防御", 1
				BREAK
			ENDIF
		ELSEIF RESULT:1 == 3;中ボタンクリック
			;オートを選択したとみなす
			CC_AUTO_MODE = CC_AUTO_MODE_INPUT + 1
			BREAK
		ELSE
			;ENTER入力を非ボタンクリックとみなす
			BREAK
		ENDIF
	ENDIF
	;;ターゲット選択処理
	;左右クリックどちらでも可
	IF RESULT:1
		IF DIC_CONTAINSKEY(INPUT_VALUES, "TARGET_ACTOR_DID")
			CC_MULTI_TARGET_LIST = %DIC_GET(INPUT_VALUES, "TARGET_ACTOR_DID")%
			BREAK
		ENDIF
	ENDIF
	IF INPUT_VALUES != ""
		CLEARLINE 1
	ENDIF
WEND
RETURN 1

;-------------------------------------------------
;入力情報表示
; ACTOR_DID: プレイヤーキャラ
; ACTOR_NPC_ONLY: 0=通常, 1=観戦モード
;-------------------------------------------------
@CC_COMBAT_INPUT_SHOW(ACTOR_DID, ACTOR_NPC_ONLY = 0)
#DIM DYNAMIC ACTOR_DID
#DIM DYNAMIC ACTOR_NPC_ONLY
#DIM DYNAMIC ACTOR_CHARA_ID
#DIM DYNAMIC SIDE

;観戦モード用
IF ACTOR_NPC_ONLY
	IF CC_AUTO_MODE == 0
		CALL CC_PRINT("")
		CALL CC_PRINT(@"@C:{カラー_注釈}@ -左クリック：行動実行 -右クリック：スキル選択 -中クリック：オート戦闘@/C@")
		CALL CC_PRINT(@"@C:{カラー_白}@@B:[AUTO:1]@[オート]@/B@ : @B:[AUTO_OPTION:2]@[+]表示速度 - %COMBAT_SPEED_NAME()%@/B@@/C@")
	ELSE
		CALL CC_PRINT(@"@C:{カラー_注釈}@ -左クリックでオート解除@/C@")
	ENDIF
	RETURN 0
ENDIF

ACTOR_CHARA_ID = DT_CELL_GET("CC_ACTOR", ACTOR_DID, "CHARA_ID", 1)
;操作不可能キャラの場合
SIF ACTOR_CHARA_ID < 0
	RETURN -1

CALL CC_PRINT(@"◆ %ANAME(ACTOR_CHARA_ID)%の行動ターン ◆")
IF CC_AUTO_MODE == 0 && ACTOR_NPC_ONLY == 0
	VARS TOOLTIP
	CALL CC_PRINT(@"@C:{カラー_注釈}@ -左クリック：行動実行 -中クリック：オート戦闘@/C@")
	CALL CC_PRINT(@"@C:{カラー_注釈}@ -アクティブスキルがセットされている場合、対象スキルを右クリックすることでアクティブにできる@/C@")
	TOOLTIP '= "軽減値の50%相当の[バリア]を自身に生成し行動を終了します"
	CALL CC_PRINT(@"@C:{カラー_白}@@B:[DEFENCE:1][CHARA_DID:{ACTOR_DID}]$%TOOLTIP%@[防御]@/B@@/C@")
	CALL CC_PRINT(@"@C:{カラー_白}@@B:[AUTO:1]@[オート]@/B@ : @B:[AUTO_OPTION:1]@[+]優先行動 - %COMBAT_MODE_NAME()%@/B@ @B:[AUTO_OPTION:2]@[+]表示速度 - %COMBAT_SPEED_NAME()%@/B@@/C@")
	CALL CC_PRINT("")
	IF HAS_SKILL(ACTOR_CHARA_ID, "SURRENDER", スキル_大分類_性技)
		SIDE = DT_CELL_GET("CC_ACTOR", ACTOR_DID, "SIDE", 1)
		CALL CC_PRINT(@"@C:{カラー_白}@@B:[FORCE_END:{SIDE == 1 ? 2 # 1}]@[降伏する]@/B@@/C@")
	ENDIF
ELSE
	CALL CC_PRINT(@"@C:{カラー_注釈}@ -左クリックでオート解除@/C@")
	CALL CC_PRINT("")
	CALL CC_PRINT("")
	CALL CC_PRINT("")
ENDIF
[IF_DEBUG]
CALL CC_PRINT(@"@C:{カラー_選択不可}@(DEBUG)@B:[FORCE_END:1]@[攻撃側勝利]@/B@ @B:[FORCE_END:2]@[防御側勝利]@/B@@/C@")
[ENDIF]

RETURN 0

;-------------------------------------------------
;入力受付処理(オート)
; RETURN 1:入力完了
;-------------------------------------------------
@CLOSE_COMBAT_INPUT_AUTO()

VARSET RESULT
VARSET RESULTS
TINPUTS CC_AUTO_INPUT_WAIT, "TIME_OVER", 0, "", 1
CLEARLINE 1

SIF RESULT:1 == 1	;左クリックでオート解除
	CC_AUTO_MODE = 0

RETURN 1

;-------------------------------------------------
;;; 自動戦闘モード(CC_AUTO_MODE)の表示名を返す式中関数
;-------------------------------------------------
@COMBAT_MODE_NAME()
#FUNCTIONS
SELECTCASE CC_AUTO_MODE_INPUT
	CASE 0
		RETURNF "通常攻撃"
	CASE 1
		RETURNF "スキル"
ENDSELECT
RETURNF "不明"

;-------------------------------------------------
;;; 自動戦闘モードの入力待ち時間(CC_AUTO_INPUT_WAIT)の表示名を返す式中関数
;-------------------------------------------------
@COMBAT_SPEED_NAME()
#FUNCTIONS
SELECTCASE CC_AUTO_INPUT_WAIT
	CASE 100
		RETURNF "2倍速"
	CASE 133
		RETURNF "1.5倍速"
	CASE 200
		RETURNF "通常"
	CASEELSE
		;通常時の値に変換する
		CC_AUTO_INPUT_WAIT = 200
		RETURNF "通常"
ENDSELECT
RETURNF "不明"

repo_name: napo/erafl

license: unknown