Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Attack.js
Show First 20 Lines • Show All 434 Lines • ▼ Show 20 Lines | Attack.prototype.GetAttackStrengths = function(type) | ||||
let ret = {}; | let ret = {}; | ||||
for (let damageType of DamageTypes.GetTypes()) | for (let damageType of DamageTypes.GetTypes()) | ||||
ret[damageType] = applyMods(damageType); | ret[damageType] = applyMods(damageType); | ||||
return ret; | return ret; | ||||
}; | }; | ||||
Attack.prototype.GetSpread = function(type) | |||||
{ | |||||
if (type != "Ranged" || !this.template[type]) | |||||
return 0; | |||||
return ApplyValueModificationsToEntity("Attack/" + type + "/Spread", +this.template[type].Spread, this.entity); | |||||
} | |||||
Attack.prototype.GetSplashDamage = function(type) | Attack.prototype.GetSplashDamage = function(type) | ||||
{ | { | ||||
if (!this.template[type].Splash) | if (!this.template[type].Splash) | ||||
return false; | return false; | ||||
let splash = this.GetAttackStrengths(type + ".Splash"); | let splash = this.GetAttackStrengths(type + ".Splash"); | ||||
splash.friendlyFire = this.template[type].Splash.FriendlyFire != "false"; | splash.friendlyFire = this.template[type].Splash.FriendlyFire != "false"; | ||||
splash.shape = this.template[type].Splash.Shape; | splash.shape = this.template[type].Splash.Shape; | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | if (type == "Ranged") | ||||
let previousTargetPosition = Engine.QueryInterface(target, IID_Position).GetPreviousPosition(); | let previousTargetPosition = Engine.QueryInterface(target, IID_Position).GetPreviousPosition(); | ||||
let targetVelocity = Vector3D.sub(targetPosition, previousTargetPosition).div(turnLength); | let targetVelocity = Vector3D.sub(targetPosition, previousTargetPosition).div(turnLength); | ||||
let timeToTarget = this.PredictTimeToTarget(selfPosition, horizSpeed, targetPosition, targetVelocity); | let timeToTarget = this.PredictTimeToTarget(selfPosition, horizSpeed, targetPosition, targetVelocity); | ||||
let predictedPosition = (timeToTarget !== false) ? Vector3D.mult(targetVelocity, timeToTarget).add(targetPosition) : targetPosition; | let predictedPosition = (timeToTarget !== false) ? Vector3D.mult(targetVelocity, timeToTarget).add(targetPosition) : targetPosition; | ||||
// Add inaccuracy based on spread. | // Add inaccuracy based on spread. | ||||
let distanceModifiedSpread = ApplyValueModificationsToEntity("Attack/Ranged/Spread", +this.template.Ranged.Spread, this.entity) * | let distanceModifiedSpread = this.GetSpread(type) * predictedPosition.horizDistanceTo(selfPosition) / 100; | ||||
predictedPosition.horizDistanceTo(selfPosition) / 100; | |||||
let randNorm = randomNormal2D(); | let randNorm = randomNormal2D(); | ||||
let offsetX = randNorm[0] * distanceModifiedSpread; | let offsetX = randNorm[0] * distanceModifiedSpread; | ||||
let offsetZ = randNorm[1] * distanceModifiedSpread; | let offsetZ = randNorm[1] * distanceModifiedSpread; | ||||
let realTargetPosition = new Vector3D(predictedPosition.x + offsetX, targetPosition.y, predictedPosition.z + offsetZ); | let realTargetPosition = new Vector3D(predictedPosition.x + offsetX, targetPosition.y, predictedPosition.z + offsetZ); | ||||
// Recalculate when the missile will hit the target position. | // Recalculate when the missile will hit the target position. | ||||
▲ Show 20 Lines • Show All 168 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator