Changeset View
Standalone View
binaries/data/mods/public/simulation/components/Attack.js
Show First 20 Lines • Show All 465 Lines • ▼ Show 20 Lines | 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; | ||||
return splash; | return splash; | ||||
}; | }; | ||||
Attack.prototype.GetRange = function(type) | Attack.prototype.GetRange = function(type) | ||||
Stan: { on new line. | |||||
{ | { | ||||
let max = +this.template[type].MaxRange; | let max = +this.template[type].MaxRange; | ||||
Done Inline ActionsYou forgot that change :) Stan: You forgot that change :) | |||||
Done Inline Actionslet bonus creates local variable which is changed and forgot after every loop iteration. You are not changing nothing in template.Bonuses which you are returning later Silier: let bonus creates local variable which is changed and forgot after every loop iteration. You… | |||||
Done Inline Actions
Not necessarily. var a = [{"a": 4, "b": 7}, {"a": 5, "b": 8} for (let obj of a) obj.b += 10; warn(uneval(a)); Objects are passed by reference. This would have been correct if you were not iterating the keys. If you print out bonus in the loop, you would only see the key names in the first object. Not the object the key corresponds to. lyv: > let bonus creates local variable which is changed and forgot after every loop iteration.
Not… | |||||
Done Inline ActionsChange is from another diff of mine :) Stan: Change is from another diff of mine :)
It allows bonus modifications from tech. | |||||
Done Inline ActionsAh, I see. lyv: Ah, I see. | |||||
Done Inline ActionsActually I was wrong, this is not from my patch, but it is indeed the reason why my patch and this one are not compatible. Since the multiplier do not get applied correctly here, the tooltip is always wrong. if (template.Bonuses) { for (let bonusKey in template.Bonuses) { let bonus = template.Bonuses[bonusKey]; bonus.Multiplier = ApplyValueModificationsToEntity("Attack/" + type + "/Bonuses/" + bonusKey + "/Multiplier", +bonus.Multiplier, this.entity); } } Stan: Actually I was wrong, this is not from my patch, but it is indeed the reason why my patch and… | |||||
max = ApplyValueModificationsToEntity("Attack/" + type + "/MaxRange", max, this.entity); | max = ApplyValueModificationsToEntity("Attack/" + type + "/MaxRange", max, this.entity); | ||||
let min = +(this.template[type].MinRange || 0); | let min = +(this.template[type].MinRange || 0); | ||||
min = ApplyValueModificationsToEntity("Attack/" + type + "/MinRange", min, this.entity); | min = ApplyValueModificationsToEntity("Attack/" + type + "/MinRange", min, this.entity); | ||||
let elevationBonus = +(this.template[type].ElevationBonus || 0); | let elevationBonus = +(this.template[type].ElevationBonus || 0); | ||||
elevationBonus = ApplyValueModificationsToEntity("Attack/" + type + "/ElevationBonus", elevationBonus, this.entity); | elevationBonus = ApplyValueModificationsToEntity("Attack/" + type + "/ElevationBonus", elevationBonus, this.entity); | ||||
return { "max": max, "min": min, "elevationBonus": elevationBonus }; | return { "max": max, "min": min, "elevationBonus": elevationBonus }; | ||||
}; | }; | ||||
Attack.prototype.GetBonusTemplate = function(type) | Attack.prototype.GetBonusTemplate = function(type) | ||||
{ | { | ||||
let template = this.template[type]; | let template = this.template[type]; | ||||
if (!template) | if (!template) | ||||
template = this.template[type.split(".")[0]].Splash; | template = this.template[type.split(".")[0]].Splash; | ||||
elexisUnsubmitted Done Inline Actions(offtopic, but above line sounds like a hack) elexis: (offtopic, but above line sounds like a hack) | |||||
StanUnsubmitted Done Inline ActionsWell with the caching now it's duplicated. Enjoy. Stan: Well with the caching now it's duplicated. Enjoy. | |||||
return template.Bonuses || null; | if (!template.Bonuses) | ||||
return null; | |||||
// The value of template.Bonuses is readonly so clone it. | |||||
let bonuses = clone(template.Bonuses); | |||||
for (let bonusKey in bonuses) | |||||
{ | |||||
let bonus = bonuses[bonusKey]; | |||||
bonus.Multiplier = ApplyValueModificationsToEntity("Attack/" + type + "/Bonuses/" + bonusKey + "/Multiplier", +bonus.Multiplier, this.entity); | |||||
} | |||||
elexisUnsubmitted Done Inline ActionsThe clone call could be avoided by constructing the output object in place (would also look a bit cleaner). elexis: The `clone` call could be avoided by constructing the output object in place (would also look a… | |||||
return bonuses; | |||||
}; | }; | ||||
/** | /** | ||||
* Attack the target entity. This should only be called after a successful range check, | * Attack the target entity. This should only be called after a successful range check, | ||||
* and should only be called after GetTimers().repeat msec has passed since the last | * and should only be called after GetTimers().repeat msec has passed since the last | ||||
* call to PerformAttack. | * call to PerformAttack. | ||||
*/ | */ | ||||
Attack.prototype.PerformAttack = function(type, target) | Attack.prototype.PerformAttack = function(type, target) | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | if (type == "Ranged") | ||||
actorName = this.template[type].Projectile.ActorName || ""; | actorName = this.template[type].Projectile.ActorName || ""; | ||||
impactActorName = this.template[type].Projectile.ImpactActorName || ""; | impactActorName = this.template[type].Projectile.ImpactActorName || ""; | ||||
impactAnimationLifetime = this.template[type].Projectile.ImpactAnimationLifetime || 0; | impactAnimationLifetime = this.template[type].Projectile.ImpactAnimationLifetime || 0; | ||||
// TODO: Use unit rotation to implement x/z offsets. | // TODO: Use unit rotation to implement x/z offsets. | ||||
let deltaLaunchPoint = new Vector3D(0, this.template[type].Projectile.LaunchPoint["@y"], 0.0); | let deltaLaunchPoint = new Vector3D(0, this.template[type].Projectile.LaunchPoint["@y"], 0.0); | ||||
let launchPoint = Vector3D.add(selfPosition, deltaLaunchPoint); | let launchPoint = Vector3D.add(selfPosition, deltaLaunchPoint); | ||||
let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | ||||
if (cmpVisual) | if (cmpVisual) | ||||
{ | { | ||||
// if the projectile definition is missing from the template | // if the projectile definition is missing from the template | ||||
// then fallback to the projectile name and launchpoint in the visual actor | // then fallback to the projectile name and launchpoint in the visual actor | ||||
if (!actorName) | if (!actorName) | ||||
actorName = cmpVisual.GetProjectileActor(); | actorName = cmpVisual.GetProjectileActor(); | ||||
▲ Show 20 Lines • Show All 139 Lines • Show Last 20 Lines |
{ on new line.