Please test it and make sure it works and while doing so test it in 3 cases (attack, raiding, and war attack).
Currently defense is not calculated right while raiding and Gree's answer is always vague about it, "we are looking into it" hope u straighten out this.