Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Health.js
Show First 20 Lines • Show All 278 Lines • ▼ Show 20 Lines | |||||
Health.prototype.HandleDeath = function() | Health.prototype.HandleDeath = function() | ||||
{ | { | ||||
let cmpDeathDamage = Engine.QueryInterface(this.entity, IID_DeathDamage); | let cmpDeathDamage = Engine.QueryInterface(this.entity, IID_DeathDamage); | ||||
if (cmpDeathDamage) | if (cmpDeathDamage) | ||||
cmpDeathDamage.CauseDeathDamage(); | cmpDeathDamage.CauseDeathDamage(); | ||||
PlaySound("death", this.entity); | PlaySound("death", this.entity); | ||||
if (this.template.SpawnEntityOnDeath) | if (this.template.SpawnEntityOnDeath) | ||||
this.CreateDeathSpawnedEntity(); | this.CreateEntitiesOnLocation([this.template.SpawnEntityOnDeath]); | ||||
const cmpRepairable = Engine.QueryInterface(this.entity, IID_Repairable); | |||||
if (cmpRepairable && cmpRepairable.template.Rebuildable === 'true') | |||||
this.CreateEntitiesOnLocation(["foundation|" + Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager).GetCurrentTemplateName(this.entity)]); | |||||
switch (this.template.DeathType) | switch (this.template.DeathType) | ||||
{ | { | ||||
case "corpse": | case "corpse": | ||||
this.CreateCorpse(); | this.CreateCorpse(); | ||||
break; | break; | ||||
case "remain": | case "remain": | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | Health.prototype.CreateCorpse = function() | ||||
if (resource) | if (resource) | ||||
Engine.PostMessage(this.entity, MT_EntityRenamed, { | Engine.PostMessage(this.entity, MT_EntityRenamed, { | ||||
"entity": this.entity, | "entity": this.entity, | ||||
"newentity": entCorpse | "newentity": entCorpse | ||||
}); | }); | ||||
}; | }; | ||||
Health.prototype.CreateDeathSpawnedEntity = function() | /** | ||||
* Create entities on the position and at the rotation of this.entity. | |||||
* @param {array} templates - The templates to spawn | |||||
* @returns {array} spawnedEntities - Containing the array of the created entity id's. | |||||
*/ | |||||
Health.prototype.CreateEntitiesOnLocation = function(templates) | |||||
{ | { | ||||
// If the unit died while not in the world, don't spawn a death entity for it | // If the unit died while not in the world, don't spawn a death entity for it | ||||
// since there's nowhere for it to be placed | // since there's nowhere for it to be placed | ||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | ||||
if (!cmpPosition.IsInWorld()) | if (!cmpPosition.IsInWorld()) | ||||
return INVALID_ENTITY; | return INVALID_ENTITY; | ||||
// Create SpawnEntityOnDeath entity | const spawnedEntities = []; | ||||
let spawnedEntity = Engine.AddLocalEntity(this.template.SpawnEntityOnDeath); | for (const template of templates) | ||||
{ | |||||
const spawnedEntity = template.includes('decay') ? Engine.AddLocalEntity(template) : Engine.AddEntity(template); | |||||
Stan: Careful with that, won't do what you want I think. A local entity is not synchronized between… | |||||
/** | |||||
* Initialize some info of the rebuildable foundation. | |||||
* Engine spawned foundations aren't payed for, this handles that. | |||||
*/ | |||||
if (template.includes('foundation')) | |||||
{ | |||||
const cmpFoundation = Engine.QueryInterface(spawnedEntity, IID_Foundation); | |||||
cmpFoundation.SetRebuildableFromEnt(this.entity); // use the still alive entity to fill in some information to be able to rebuild it. | |||||
} | |||||
// Move to same position | // Move to same position | ||||
let cmpSpawnedPosition = Engine.QueryInterface(spawnedEntity, IID_Position); | let cmpSpawnedPosition = Engine.QueryInterface(spawnedEntity, IID_Position); | ||||
let pos = cmpPosition.GetPosition(); | let pos = cmpPosition.GetPosition(); | ||||
cmpSpawnedPosition.JumpTo(pos.x, pos.z); | cmpSpawnedPosition.JumpTo(pos.x, pos.z); | ||||
let rot = cmpPosition.GetRotation(); | let rot = cmpPosition.GetRotation(); | ||||
cmpSpawnedPosition.SetYRotation(rot.y); | cmpSpawnedPosition.SetYRotation(rot.y); | ||||
cmpSpawnedPosition.SetXZRotation(rot.x, rot.z); | cmpSpawnedPosition.SetXZRotation(rot.x, rot.z); | ||||
let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | ||||
let cmpSpawnedOwnership = Engine.QueryInterface(spawnedEntity, IID_Ownership); | let cmpSpawnedOwnership = Engine.QueryInterface(spawnedEntity, IID_Ownership); | ||||
if (cmpOwnership && cmpSpawnedOwnership) | if (cmpOwnership && cmpSpawnedOwnership) | ||||
cmpSpawnedOwnership.SetOwner(cmpOwnership.GetOwner()); | cmpSpawnedOwnership.SetOwner(cmpOwnership.GetOwner()); | ||||
return spawnedEntity; | spawnedEntities.push(spawnedEntity); | ||||
} | |||||
return spawnedEntities; | |||||
}; | }; | ||||
Health.prototype.UpdateActor = function() | Health.prototype.UpdateActor = function() | ||||
{ | { | ||||
if (!this.template.DamageVariants) | if (!this.template.DamageVariants) | ||||
return; | return; | ||||
let ratio = this.hitpoints / this.GetMaxHitpoints(); | let ratio = this.hitpoints / this.GetMaxHitpoints(); | ||||
let newDamageVariant = "alive"; | let newDamageVariant = "alive"; | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Careful with that, won't do what you want I think. A local entity is not synchronized between players.