Cleanup of GetBonusAttack function and use it inside petra

simulation part reviewed by fatherbushido
Differential Revision: https://code.wildfiregames.com/D138
This was SVN commit r19210.
This commit is contained in:
mimo
2017-02-09 20:20:59 +00:00
parent 689d5ed562
commit ecde67c19a
3 changed files with 31 additions and 14 deletions
@@ -138,7 +138,7 @@ m.allowCapture = function(gameState, ent, target)
let capturableTargets = gameState.ai.HQ.capturableTargets;
if (!capturableTargets.has(target.id()))
{
capture = ent.captureStrength();
capture = ent.captureStrength() * m.getAttackBonus(ent, target, "Capture");
capturableTargets.set(target.id(), { "strength": capture, "ents": new Set([ent.id()]) });
}
else
@@ -146,7 +146,7 @@ m.allowCapture = function(gameState, ent, target)
let capturable = capturableTargets.get(target.id());
if (!capturable.ents.has(ent.id()))
{
capturable.strength += ent.captureStrength();
capturable.strength += ent.captureStrength() * m.getAttackBonus(ent, target, "Capture");
capturable.ents.add(ent.id());
}
capture = capturable.strength;
@@ -158,6 +158,25 @@ m.allowCapture = function(gameState, ent, target)
return capture > antiCapture + sumCapturePoints/80;
};
/** copy of GetAttackBonus from Attack.js */
m.getAttackBonus = function(ent, target, type)
{
let attackBonus = 1;
if (!ent.get("Attack/" + type) || !ent.get("Attack/" + type + "/Bonuses"))
return attackBonus;
let bonuses = ent.get("Attack/" + type + "/Bonuses");
for (let key in bonuses)
{
let bonus = bonuses[key];
if (bonus.Civ && bonus.Civ !== target.civ())
continue;
if (bonus.Classes && bonus.Classes.split(/\s+/).some(cls => !target.hasClass(cls)))
continue;
attackBonus *= bonus.Multiplier;
}
return attackBonus;
};
/** Makes the worker deposit the currently carried resources at the closest accessible dropsite */
m.returnResources = function(gameState, ent)
{
@@ -2106,11 +2106,14 @@ m.HQ.prototype.updateCaptureStrength = function(gameState)
if (!target || !target.isCapturable())
continue;
if (!this.capturableTargets.has(targetId))
this.capturableTargets.set(targetId, { "strength": ent.captureStrength(), "ents": new Set([ent.id()]) });
this.capturableTargets.set(targetId, {
"strength": ent.captureStrength() * m.getAttackBonus(ent, target, "Capture"),
"ents": new Set([ent.id()])
});
else
{
let capturableTarget = this.capturableTargets.get(target.id());
capturableTarget.strength += ent.captureStrength();
capturableTarget.strength += ent.captureStrength() * m.getAttackBonus(ent, target, "Capture");
capturableTarget.ents.add(ent.id());
}
}
@@ -422,16 +422,11 @@ Attack.prototype.GetAttackBonus = function(type, target)
for (let key in template.Bonuses)
{
let bonus = template.Bonuses[key];
let hasClasses = true;
if (bonus.Classes){
let classes = bonus.Classes.split(/\s+/);
for (let key in classes)
hasClasses = hasClasses && cmpIdentity.HasClass(classes[key]);
}
if (hasClasses && (!bonus.Civ || bonus.Civ === cmpIdentity.GetCiv()))
attackBonus *= bonus.Multiplier;
if (bonus.Civ && bonus.Civ !== cmpIdentity.GetCiv())
continue;
if (bonus.Classes && bonus.Classes.split(/\s+/).some(cls => !cmpIdentity.HasClass(cls)))
continue;
attackBonus *= bonus.Multiplier;
}
}