Large

Castle Age - Battle Master

By MuadDib Last update Apr 22, 2010 — Installed 17,128 times.

Correct siege calc?

in
Subscribe to Correct siege calc? 2 posts, 2 voices



Artifice Scriptwright
FirefoxMacintosh

I'm working on Castle Age Autoplayer, and made an updated version of the T2K calculation to account for siege completions, i.e. if you have 1 click left for a Last Stand that will kill a hydra, it won't last as long. On the other hand, if the Last Stand is already done and the hydra has 10% left, it will still be a while.

Here's the code:

t2kCalc: function (boss, time, percentHealthLeft, siegeStage, clicksNeededInCurrentStage) {
var timeLeft = parseInt(time[0], 10) + (parseInt(time[1], 10) * 0.0166);
var timeUsed = (boss.duration - timeLeft);
if (!boss.siege || !boss.hp) {
return Math.round((percentHealthLeft * timeUsed / (100 - percentHealthLeft)) * 10) / 10;
}

var T2K = 0;
var damageDone = (100 - percentHealthLeft) / 100 * boss.hp;
var hpLeft = boss.hp - damageDone;
var totalSiegeDamage = 0;
var totalSiegeClicks = 0;
var attackDamPerHour = 0;
var clicksPerHour = 0;
var clicksToNextSiege = 0;
var nextSiegeAttackPlusSiegeDamage = 0;
for (var s in boss.siegeClicks) {
if (boss.siegeClicks.hasOwnProperty(s)) {
//gm.log('s ' + s + ' T2K ' + T2K+ ' hpLeft ' + hpLeft);
if (s < siegeStage - 1 || clicksNeededInCurrentStage === 0) {
totalSiegeDamage += boss.siegeDam[s];
totalSiegeClicks += boss.siegeClicks[s];
}
if (s == siegeStage - 1) {
attackDamPerHour = (damageDone - totalSiegeDamage) / timeUsed;
clicksPerHour = (totalSiegeClicks + boss.siegeClicks[s] - clicksNeededInCurrentStage) / timeUsed;
gm.log('Attack Damage Per Hour: ' + attackDamPerHour + ' Damage Done: ' + damageDone + ' Total Siege Damage: ' + totalSiegeDamage + ' Time Used: ' + timeUsed + ' Clicks Per Hour: ' + clicksPerHour);
}
if (s >= siegeStage - 1) {
clicksToNextSiege = (s == siegeStage - 1) ? clicksNeededInCurrentStage : boss.siegeClicks[s];
nextSiegeAttackPlusSiegeDamage = boss.siegeDam[s] + clicksToNextSiege / clicksPerHour * attackDamPerHour;
if (hpLeft <= nextSiegeAttackPlusSiegeDamage || clicksNeededInCurrentStage === 0) {
T2K += hpLeft / attackDamPerHour;
break;
}
T2K += clicksToNextSiege / clicksPerHour;
hpLeft -= nextSiegeAttackPlusSiegeDamage;
}
}
}

gm.log('T2K based on siege: ' + T2K + ' T2K estimate without calculating siege impacts: ' + percentHealthLeft / (100 - percentHealthLeft) * timeLeft);
return Math.round(T2K * 10) / 10;
},

Hope that came out ok. Some of the less than and greater than signs might have gotten messed up a bit with the HTML post.

 
MysticMetal User
FirefoxWindows

Why didn't you just modify the handleAttack function? It already does most of this (figuring out siege damage, enemy HP, time left to kill, etc.)... I think it's only missing the clicksToNextSiege and the formulas you want (plus it shows some of the variables and conditional formatting you might need).

Your code would also be easier to read if you used the < pre> block so the spaces are maintained.

	like this

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel