Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/entityExtend.js
Show All 31 Lines | for (let str in attackStrength) | ||||
strength += val * 0.085 / 3; | strength += val * 0.085 / 3; | ||||
break; | break; | ||||
case "Hack": | case "Hack": | ||||
strength += val * 0.075 / 3; | strength += val * 0.075 / 3; | ||||
break; | break; | ||||
case "Pierce": | case "Pierce": | ||||
strength += val * 0.065 / 3; | strength += val * 0.065 / 3; | ||||
break; | break; | ||||
case "Capture": | |||||
// TODO implement this | |||||
break; | |||||
default: | default: | ||||
API3.warn("Petra: " + str + " unknown attackStrength in getMaxStrength"); | API3.warn("Petra: " + str + " unknown attackStrength in getMaxStrength"); | ||||
} | } | ||||
} | } | ||||
let attackRange = ent.attackRange(type); | let attackRange = ent.attackRange(type); | ||||
if (attackRange) | if (attackRange) | ||||
strength += attackRange.max * 0.0125; | strength += attackRange.max * 0.0125; | ||||
Show All 26 Lines | case "Crush": | ||||
strength += val * 0.085 / 3; | strength += val * 0.085 / 3; | ||||
break; | break; | ||||
case "Hack": | case "Hack": | ||||
strength += val * 0.075 / 3; | strength += val * 0.075 / 3; | ||||
break; | break; | ||||
case "Pierce": | case "Pierce": | ||||
strength += val * 0.065 / 3; | strength += val * 0.065 / 3; | ||||
break; | break; | ||||
case "Capture": | |||||
// TODO implement this | |||||
break; | |||||
default: | default: | ||||
API3.warn("Petra: " + str + " unknown armourStrength in getMaxStrength"); | API3.warn("Petra: " + str + " unknown armourStrength in getMaxStrength"); | ||||
} | } | ||||
} | } | ||||
return strength * ent.maxHitpoints() / 100.0; | return strength * ent.maxHitpoints() / 100.0; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | m.getSeaAccess = function(gameState, ent) | ||||
return sea; | return sea; | ||||
}; | }; | ||||
m.setSeaAccess = function(gameState, ent) | m.setSeaAccess = function(gameState, ent) | ||||
{ | { | ||||
m.getSeaAccess(gameState, ent); | m.getSeaAccess(gameState, ent); | ||||
}; | }; | ||||
/** Decide if we should try to capture (returns true) or destroy (return false) */ | /** | ||||
m.allowCapture = function(gameState, ent, target) | * Decide if we should try to capture, melee or ranged attack. | ||||
*/ | |||||
m.getPrefAttackTypes = function(gameState, ent, target) | |||||
{ | { | ||||
if (!target.isCapturable() || !ent.canCapture(target)) | if (!target.isCapturable() || !ent.canCapture(target)) | ||||
return false; | return ["!Capture"]; | ||||
if (target.isInvulnerable()) | if (target.isInvulnerable()) | ||||
return true; | return ["Capture"]; | ||||
// always try to recapture cp from an allied, except if it's decaying | // always try to recapture cp from an allied, except if it's decaying | ||||
if (gameState.isPlayerAlly(target.owner())) | if (gameState.isPlayerAlly(target.owner())) | ||||
return !target.decaying(); | return target.decaying() ? ["!Capture"] : ["Capture"]; | ||||
let antiCapture = target.defaultRegenRate(); | let antiCapture = target.defaultRegenRate(); | ||||
Freagarach: This sounds interesting: the target is allied, but we still try to damage it? | |||||
Done Inline ActionsNothing changed in that regard though. bb: Nothing changed in that regard though. | |||||
if (target.isGarrisonHolder() && target.garrisoned()) | if (target.isGarrisonHolder() && target.garrisoned()) | ||||
antiCapture += target.garrisonRegenRate() * target.garrisoned().length; | antiCapture += target.garrisonRegenRate() * target.garrisoned().length; | ||||
if (target.decaying()) | if (target.decaying()) | ||||
antiCapture -= target.territoryDecayRate(); | antiCapture -= target.territoryDecayRate(); | ||||
let capture; | let capture; | ||||
let capturableTargets = gameState.ai.HQ.capturableTargets; | let capturableTargets = gameState.ai.HQ.capturableTargets; | ||||
if (!capturableTargets.has(target.id())) | if (!capturableTargets.has(target.id())) | ||||
{ | { | ||||
capture = ent.captureStrength() * m.getAttackBonus(ent, target, "Capture"); | capture = ent.attackStrengths("Capture").Capture * m.getAttackBonus(ent, target, "Capture"); | ||||
capturableTargets.set(target.id(), { "strength": capture, "ents": new Set([ent.id()]) }); | capturableTargets.set(target.id(), { "strength": capture, "ents": new Set([ent.id()]) }); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
let capturable = capturableTargets.get(target.id()); | let capturable = capturableTargets.get(target.id()); | ||||
if (!capturable.ents.has(ent.id())) | if (!capturable.ents.has(ent.id())) | ||||
{ | { | ||||
capturable.strength += ent.captureStrength() * m.getAttackBonus(ent, target, "Capture"); | capturable.strength += ent.attackStrengths("Capture").Capture * m.getAttackBonus(ent, target, "Capture"); | ||||
capturable.ents.add(ent.id()); | capturable.ents.add(ent.id()); | ||||
} | } | ||||
capture = capturable.strength; | capture = capturable.strength; | ||||
} | } | ||||
capture *= 1 / (0.1 + 0.9*target.healthLevel()); | capture *= 1 / (0.1 + 0.9*target.healthLevel()); | ||||
let sumCapturePoints = target.capturePoints().reduce((a, b) => a + b); | let sumCapturePoints = target.capturePoints().reduce((a, b) => a + b); | ||||
if (target.hasDefensiveFire() && target.isGarrisonHolder() && target.garrisoned()) | if (target.hasDefensiveFire() && target.isGarrisonHolder() && target.garrisoned()) | ||||
return capture > antiCapture + sumCapturePoints/50; | return capture > antiCapture + sumCapturePoints/50 ? ["Capture"] : ["!Capture"]; | ||||
return capture > antiCapture + sumCapturePoints/80; | return capture > antiCapture + sumCapturePoints/80 ? ["Capture"] : ["!Capture"]; | ||||
}; | }; | ||||
m.getAttackBonus = function(ent, target, type) | m.getAttackBonus = function(ent, target, type) | ||||
{ | { | ||||
let attackBonus = 1; | let attackBonus = 1; | ||||
if (!ent.get("Attack/" + type) || !ent.get("Attack/" + type + "/Bonuses")) | if (!ent.get("Attack/" + type) || !ent.get("Attack/" + type + "/Bonuses")) | ||||
return attackBonus; | return attackBonus; | ||||
let bonuses = ent.get("Attack/" + type + "/Bonuses"); | let bonuses = ent.get("Attack/" + type + "/Bonuses"); | ||||
▲ Show 20 Lines • Show All 238 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
This sounds interesting: the target is allied, but we still try to damage it?