#!/bin/bash
source $HOME/.gamerc

if [[ $# -lt 3 ]]; then
    echo "Usage: $0 <DIRECTORY_NAME> <MERGE_WORLD_ID_LISTS: TARGET_WID SOURCE_WID_LISTS>" >&2
    exit 1
fi

DIRECTORY_NAME="$1"
SET_ID=$(( $2 / 100 ))
#echo "SET_ID: ${SET_ID}"
WORLD_ID_LISTS_STR=""

for world_id in "${@:2}"; do
    check_set_id=$(( world_id / 100 ))
    if [ "${check_set_id}" -ne "${SET_ID}" ]; then
        exec echo "${world_id} is not equal to SET_ID ${SET_ID}"
    fi

    if [ "${world_id}" -ge 4000 ]; then
        exec echo "Unknown WORLD_ID ${world_id}"
    fi
    WORLD_ID_LISTS_STR="${WORLD_ID_LISTS_STR}${world_id}_"
done
WORLD_ID_LISTS_STR=${WORLD_ID_LISTS_STR%_}

echo ${WORLD_ID_LISTS_STR}
