let GetBtlChara_ENo = function (_ENo) {
    if (_ENo <= -1) return NPlayer[(-_ENo - 1)];
    if (_ENo > -1) return NEnemy[_ENo];
}
let SetBtlChara_ENo = function (_ENo, charaData) {
    if (_ENo <= -1) return NPlayer[(-_ENo - 1)] = charaData;
    if (_ENo > -1) return NEnemy[_ENo] = charaData;
}
let GetEnemyData_ENo = function (chekNo) {
    if (chekNo >= 0) {
        return $dataEnemies[NEnemy[chekNo]._enemyId];
    } else {
        return $dataEnemies[NPlayer[(chekNo * -1) - 1]._enemyId];
    }
}
let GetEnemyName_ENo = function (_ENo) {
    try {
        let _CkName = "";
        if (_ENo <= -1) _CkName = NPlayer[(-_ENo - 1)]._name;
        if (_ENo > -1) _CkName = NEnemy[_ENo]._name;
        return _CkName;
    } catch (e) {
        return "";
    }
}
let GetNState_ENo = function (ckENo) {
    try {
        let _CkState = [];
        if (ckENo <= -1) _CkState = NPlayer[(-ckENo - 1)]._NState;
        if (ckENo > -1) _CkState = NEnemy[ckENo]._NState;
        return _CkState;
    } catch (e) {
        return [];
    }
}
let GetStateTypeSumValue = function (ckNState, typeID) {
    let _rtnVar = 0;
    for (let i = 0; i <= ckNState.length - 1; i++) {
        let _ckTraits = $dataStates[ckNState[i]._No].traits; 
        for (let j = 0; j <= _ckTraits.length - 1; j++) {
            _ckTrait = _ckTraits[j];
            let _StVar = Math.round((_ckTrait.value - 1) * 100); 
            if (_ckTrait.dataId == typeID) {
                _rtnVar += _StVar;
            }
        }
    }
    return _rtnVar;
}
let GetStateTypeSumValue_ENo = function (ckENo, typeID) {
    try {
        let _CkState = GetNState_ENo(ckENo);
        return GetStateTypeSumValue(_CkState, typeID);
    } catch (e) {
    }
    return 0;
}
let CheckStateInType = function (ckNState, typeID) {
    if (ckNState == undefined) return false;
    for (let i = 0; i <= ckNState.length - 1; i++) {
        for (let j = 0; j <= $dataStates[ckNState[i]._No].traits.length - 1; j++) {
            if ($dataStates[ckNState[i]._No].traits[j].code == 11) {
                if ($dataStates[ckNState[i]._No].traits[j].dataId == typeID) return true;
            }
        }
    }
    return false;
}
let CheckNStateInState = function (ckNState, stateId) {
    for (let i = 0; i <= ckNState.length - 1; i++) {
        if (ckNState[i]._No == stateId) {
            return true;
        }
    }
    return false;
}
let CheckNStateInState_ENo = function (ckENo, stateId) {
    return CheckNStateInState(GetNState_ENo(ckENo), stateId);
}
let GetNStateTurn = function (ckNState, stateId) {
    for (let i = 0; i <= ckNState.length - 1; i++) {
        if (ckNState[i]._No == stateId) return ckNState[i]._Turn;
    }
    return 0;
}
let GetNStateTurn_ENo = function (ckENo, stateId) {
    try {
        return GetNStateTurn(GetNState_ENo(ckENo), stateId);
    } catch (e) {
    }
}
let ENo_StateCk_Type = function (_ENo, _TypeId) {
    try {
        let _CkState = GetNState_ENo(_ENo);
        return CheckStateInType(_CkState, _TypeId);
    } catch (e) {
    }
    return false;
}
let DelStateType_ENo = function (_ENo, _TypeId) {
    try {
        let _CkState = GetNState_ENo(_ENo);
        DelStateType(_CkState, _TypeId);
    } catch (e) {
    }
}
let DelStateType = function (ckNState, typeID) {
    if (ckNState == undefined) return;
    for (let i = 0; i <= ckNState.length - 1; i++) {
        for (let j = 0; j <= $dataStates[ckNState[i]._No].traits.length - 1; j++) {
            if ($dataStates[ckNState[i]._No].traits[j].code == 11) {
                if ($dataStates[ckNState[i]._No].traits[j].dataId == typeID) {
                    ckNState.splice(i , 1); i--;
                    break;
                }
            }
        }
    }
}
