#!/usr/bin/env bash
# should be run from inside "magic" dir of MAOSS
# fd . -x ffmpeg -i {} -filter:a volumedetect -f null /dev/null 2>&1 | rg 'mean_volume|max_volume'
# make patch dir
patch_dir="../../../04 MAO Spell Sounds - Replacement Patch/Sound/Fx/magic"
temp_dir="../../../99_temp_dir/Sound/Fx/magic"
if [ ! -d "${patch_dir}" ]; then mkdir -pv "${patch_dir}"; fi
if [ ! -d "${temp_dir}" ]; then mkdir -pv "${temp_dir}"; fi
# fire
mv -v "fireA.wav" "${temp_dir}/firesA.wav"
mv -v "fireH.wav" "${temp_dir}/firesHit.wav"
# mv -v "fireT.wav" "${temp_dir}/fireT.wav"
mv -v "fireC.wav" "${temp_dir}/firesCast.wav"
# frost
mv -v "frstA.wav" "${temp_dir}/frostA.wav"
mv -v "frstC.wav" "${temp_dir}/frostCast.wav"
mv -v "frstH.wav" "${temp_dir}/frostHit.wav"
mv -v "frstT.wav" "${temp_dir}/frostT.wav"
# shock
mv -v "shokA.wav" "${temp_dir}/shokingA.wav"
mv -v "shokC.wav" "${temp_dir}/shokingCast.wav"
mv -v "shokH.wav" "${temp_dir}/shokingHit.wav"
mv -v "shokT.wav" "${temp_dir}/shokingT.wav"
# poison
mv -v "poisA.wav" "${temp_dir}/poisonA.wav"
mv -v "poisC.wav" "${temp_dir}/poisonCast.wav"
mv -v "poisH.wav" "${temp_dir}/poisonHit.wav"
mv -v "poisT.wav" "${temp_dir}/poisonT.wav"
# schools
mv -v "altrA.wav" "${temp_dir}/alterA.wav"
mv -v "altrC.wav" "${temp_dir}/alterCast.wav"
mv -v "altrFAIL.wav" "${temp_dir}/alterFail.wav"
mv -v "altrH.wav" "${temp_dir}/alterHit.wav"
mv -v "altrT.wav" "${temp_dir}/alterT.wav"
mv -v "conjA.wav" "${temp_dir}/conjurA.wav"
mv -v "conjC.wav" "${temp_dir}/conjurCast.wav"
mv -v "conjFAIL.wav" "${temp_dir}/conjurFail.wav"
mv -v "conjH.wav" "${temp_dir}/conjurHit.wav"
mv -v "conjT.wav" "${temp_dir}/conjurT.wav"
mv -v "destA.wav" "${temp_dir}/destructA.wav"
mv -v "destC.wav" "${temp_dir}/destructCast.wav"
mv -v "destFAIL.wav" "${temp_dir}/destructFail.wav"
mv -v "destH.wav" "${temp_dir}/destructHit.wav"
mv -v "destT.wav" "${temp_dir}/destructT.wav"
mv -v "illuA.wav" "${temp_dir}/illusA.wav"
mv -v "illuC.wav" "${temp_dir}/illusCast.wav"
mv -v "illuFAIL.wav" "${temp_dir}/illusFail.wav"
mv -v "illuH.wav" "${temp_dir}/illusHit.wav"
mv -v "illuT.wav" "${temp_dir}/illusT.wav"
mv -v "mystA.wav" "${temp_dir}/mysticA.wav"
mv -v "mystC.wav" "${temp_dir}/mysticCast.wav"
mv -v "mystFAIL.wav" "${temp_dir}/mysticFail.wav"
mv -v "mystH.wav" "${temp_dir}/mysticHit.wav"
mv -v "mystT.wav" "${temp_dir}/mysticT.wav"
mv -v "restA.wav" "${temp_dir}/restorA.wav"
mv -v "restC.wav" "${temp_dir}/restorCast.wav"
mv -v "restFAIL.wav" "${temp_dir}/restorFail.wav"
mv -v "restH.wav" "${temp_dir}/restorHit.wav"
mv -v "restT.wav" "${temp_dir}/restorT.wav"
# these files do not require renaming, but need volume increase
mv -v "enchantFAIL.wav" "${temp_dir}/enchantFAIL.wav" 
mv -v "enchant.wav" "${temp_dir}/enchant.wav"
mv -v "fireT.wav" "${temp_dir}/fireT.wav"
# increase volume
fd . "${temp_dir}" -x ffmpeg -i "{}" -filter:a "volume=5dB" "${patch_dir}/{/}"
# copy original readme
mv -v "../../../readme.txt" "../../../04 MAO Spell Sounds - Replacement Patch"
