Ticket #3983: damageVariants.3.diff
File damageVariants.3.diff, 8.7 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/art/actors/structures/iberians/fireship.xml
2 2 <actor version="1"> 3 3 <castshadow/> 4 4 <group> 5 <variant frequency="1" name=" firea">5 <variant frequency="1" name="base"> 6 6 <mesh>structural/iber_fireship.dae</mesh> 7 7 <props> 8 8 <prop actor="props/structures/iberians/fireship_wood.xml" attachpoint="root"/> 9 <prop actor="particle/flame_med.xml" attachpoint="fire1"/> 10 <prop actor="particle/smoke_med.xml" attachpoint="fire1"/> 11 <prop actor="particle/flame.xml" attachpoint="fire2"/> 12 <prop actor="" attachpoint="fire3"/> 9 </props> 10 <textures><texture file="structural/iber_ship.dds" name="baseTex"/></textures> 11 </variant> 12 </group> 13 <group> 14 <variant name="healthy" frequency="1"> 15 <props> 16 <prop actor="particle/flame_jav.xml" attachpoint="fire1"/> 17 <prop actor="particle/smoke_jav.xml" attachpoint="fire1"/> 13 18 <prop actor="particle/flame_jav.xml" attachpoint="fire4"/> 14 19 <prop actor="particle/smoke_jav.xml" attachpoint="fire4"/> 15 <prop actor="particle/flame.xml" attachpoint="fire5"/>16 <prop actor="particle/smoke_catapult.xml" attachpoint="fire5"/>17 20 </props> 18 <textures><texture file="structural/iber_ship.dds" name="baseTex"/></textures>19 21 </variant> 20 <variant frequency="1" name="fireb"> 21 <mesh>structural/iber_fireship.dae</mesh> 22 <variant name="lightDamage"> 22 23 <props> 23 <prop actor="props/structures/iberians/fireship_wood.xml" attachpoint="root"/> 24 <prop actor="particle/flame_jav.xml" attachpoint="fire1"/> 24 <prop actor="particle/flame.xml" attachpoint="fire1"/> 25 25 <prop actor="particle/smoke.xml" attachpoint="fire1"/> 26 <prop actor="particle/flame.xml" attachpoint="fire2"/> 27 <prop actor="particle/flame_med.xml" attachpoint="fire3"/> 28 <prop actor="particle/smoke_med.xml" attachpoint="fire3"/> 26 <prop actor="particle/flame_jav.xml" attachpoint="fire3"/> 27 <prop actor="particle/smoke_jav.xml" attachpoint="fire3"/> 28 <prop actor="particle/flame.xml" attachpoint="fire4"/> 29 <prop actor="particle/smoke_jav.xml" attachpoint="fire4"/> 30 </props> 31 </variant> 32 <variant name="mediumDamage"> 33 <props> 34 <prop actor="particle/flame.xml" attachpoint="fire1"/> 35 <prop actor="particle/smoke.xml" attachpoint="fire1"/> 36 <prop actor="particle/flame_jav.xml" attachpoint="fire2"/> 37 <prop actor="particle/flame.xml" attachpoint="fire3"/> 38 <prop actor="particle/smoke.xml" attachpoint="fire3"/> 39 <prop actor="particle/flame.xml" attachpoint="fire4"/> 40 <prop actor="particle/smoke.xml" attachpoint="fire4"/> 29 41 <prop actor="particle/flame_jav.xml" attachpoint="fire5"/> 30 <prop actor="particle/smoke_jav.xml" attachpoint="fire5"/>31 42 </props> 32 <textures><texture file="structural/iber_ship.dds" name="baseTex"/></textures>33 43 </variant> 44 <variant name="heavyDamage"> 45 <props> 46 <prop actor="particle/flame_large.xml" attachpoint="fire1"/> 47 <prop actor="particle/smoke_med.xml" attachpoint="fire1"/> 48 <prop actor="particle/flame.xml" attachpoint="fire2"/> 49 <prop actor="particle/flame_large.xml" attachpoint="fire3"/> 50 <prop actor="particle/smoke.xml" attachpoint="fire3"/> 51 <prop actor="particle/flame.xml" attachpoint="fire4"/> 52 <prop actor="particle/flame_large.xml" attachpoint="fire4"/> 53 <prop actor="particle/smoke_med.xml" attachpoint="fire5"/> 54 </props> 55 </variant> 56 <variant name="death"> 57 </variant> 34 58 </group> 35 59 <material>player_trans.xml</material> 36 60 </actor> -
binaries/data/mods/public/simulation/components/Health.js
17 17 "</element>" + 18 18 "</optional>" + 19 19 "<optional>" + 20 "<element name='SpawnEntityOnDeath' a:help='Entity template to spawn when this entity dies. Note: this is different than the corpse, which retains the original entity's appearance'>" + 21 "<text/>" + 20 "<element name='DamageVariants'>" + 21 "<oneOrMore>" + 22 "<element a:help='Name of the variant to select when health drops under the defined ratio'>" + 23 "<anyName/>" + 24 "<data type='decimal'>" + 25 "<param name='minInclusive'>0</param>" + 26 "<param name='maxInclusive'>1</param>" + 27 "</data>" + 28 "</element>" + 29 "</oneOrMore>" + 22 30 "</element>" + 23 31 "</optional>" + 24 32 "<element name='RegenRate' a:help='Hitpoint regeneration rate per second.'>" + … … 34 42 "<value a:help='Remain in the world with 0 health'>remain</value>" + 35 43 "</choice>" + 36 44 "</element>" + 45 "<optional>" + 46 "<element name='SpawnEntityOnDeath' a:help='Entity template to spawn when this entity dies. Note: this is different than the corpse, which retains the original entity's appearance'>" + 47 "<text/>" + 48 "</element>" + 49 "</optional>" + 37 50 "<element name='Undeletable' a:help='Prevent players from deleting this entity.'>" + 38 51 "<data type='boolean'/>" + 39 52 "</element>" + … … 51 64 this.regenRate = ApplyValueModificationsToEntity("Health/RegenRate", +this.template.RegenRate, this.entity); 52 65 this.idleRegenRate = ApplyValueModificationsToEntity("Health/IdleRegenRate", +this.template.IdleRegenRate, this.entity); 53 66 this.CheckRegenTimer(); 67 this.UpdateActor(); 54 68 }; 55 69 56 70 //// Interface functions //// … … 92 106 cmpRangeManager.SetEntityFlag(this.entity, "injured", false); 93 107 } 94 108 95 Engine.PostMessage(this.entity, MT_HealthChanged, { "from": old, "to": this.hitpoints });109 this.RegisterHealthChanged(old); 96 110 }; 97 111 98 112 Health.prototype.IsRepairable = function() … … 223 237 } 224 238 225 239 this.hitpoints = 0; 226 227 Engine.PostMessage(this.entity, MT_HealthChanged, { "from": oldHitpoints, "to": this.hitpoints }); 240 this.RegisterHealthChanged(oldHitpoints); 228 241 } 229 242 230 243 } … … 231 244 else 232 245 { 233 246 this.hitpoints -= amount; 234 235 Engine.PostMessage(this.entity, MT_HealthChanged, { "from": oldHitpoints, "to": this.hitpoints }); 247 this.RegisterHealthChanged(oldHitpoints); 236 248 } 237 249 state.change = this.hitpoints - oldHitpoints; 238 250 return state; … … 262 274 cmpRangeManager.SetEntityFlag(this.entity, "injured", false); 263 275 } 264 276 265 Engine.PostMessage(this.entity, MT_HealthChanged, { "from": old, "to": this.hitpoints }); 277 this.RegisterHealthChanged(old); 278 266 279 // We return the old and the actual hp 267 280 return { "old": old, "new": this.hitpoints}; 268 281 }; … … 337 350 return spawnedEntity; 338 351 }; 339 352 353 Health.prototype.UpdateActor = function() 354 { 355 if (!this.template.DamageVariants) 356 return; 357 let ratio = this.GetHitpoints() / this.GetMaxHitpoints(); 358 let newSelection = "alive"; 359 if (ratio > 0) 360 { 361 let minTreshold = 1; 362 for (let key in this.template.DamageVariants) 363 { 364 let treshold = +this.template.DamageVariants[key]; 365 if (treshold < ratio || treshold > minTreshold) 366 continue; 367 newSelection = key; 368 minTreshold = treshold; 369 } 370 } 371 else 372 newSelection = "death"; 373 374 if (this.currentSelection && this.currentSelection == newSelection) 375 return; 376 377 let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); 378 if (cmpVisual) 379 cmpVisual.SetVariant("health", newSelection); 380 }; 381 340 382 Health.prototype.OnValueModification = function(msg) 341 383 { 342 384 if (msg.component != "Health") … … 361 403 this.CheckRegenTimer(); 362 404 }; 363 405 364 Health.prototype. OnHealthChanged = function()406 Health.prototype.RegisterHealthChanged = function(from) 365 407 { 366 408 this.CheckRegenTimer(); 409 this.UpdateActor() 410 Engine.PostMessage(this.entity, MT_HealthChanged, { "from": from, "to": this.hitpoints }); 367 411 }; 368 412 369 413 Engine.RegisterComponentType(IID_Health, "Health", Health); -
binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_fire.xml
29 29 <Health> 30 30 <Max>500</Max> 31 31 <RegenRate>-3</RegenRate> 32 <DamageVariants> 33 <lightdamage>0.85</lightdamage> 34 <mediumdamage>0.65</mediumdamage> 35 <heavydamage>0.35</heavydamage> 36 </DamageVariants> 32 37 </Health> 33 38 <Identity> 34 39 <GenericName>Fire Ship</GenericName>