Ticket #1910: 1910-death-damage-1.patch

File 1910-death-damage-1.patch, 6.6 KB (added by Mate-86, 8 years ago)
  • binaries/data

  • binaries/data/mods/public/simulation/components/Attack.js

    Property changes on: binaries/data
    ___________________________________________________________________
    Modified: svn:ignore
    ## -1,3 +1,4 ##
    -*.xmb
     *.db
     *.jbf
    +*.xmb
    +cache
     
    9494            "<Crush>0.0</Crush>" +
    9595            "<MaxRange>4.0</MaxRange>" +
    9696        "</Slaughter>" +
     97        "<Death>" +
     98            "<Shape>Circular</Shape>" +
     99            "<Range>20</Range>" +
     100            "<FriendlyFire>false</FriendlyFire>" +
     101            "<Hack>0.0</Hack>" +
     102            "<Pierce>10.0</Pierce>" +
     103            "<Crush>50.0</Crush>" +
     104        "</Death>" +
    97105    "</a:example>" +
    98106    "<optional>" +
    99107        "<element name='Melee'>" +
     
    177185                Attack.prototype.restrictedClassesSchema +
    178186            "</interleave>" +
    179187        "</element>" +
     188    "</optional>" +
     189    "<optional>" +
     190        "<element name='Death' a:help='When a unit dies it inflicts damage on nearby units.'>" +
     191            "<interleave>" +
     192                "<element name='Shape' a:help='Shape of the splash damage, can be circular or linear'><text/></element>" +
     193                "<element name='Range' a:help='Size of the area affected by the splash'><ref name='nonNegativeDecimal'/></element>" +
     194                "<element name='FriendlyFire' a:help='Whether the splash damage can hurt non enemy units'><data type='boolean'/></element>" +
     195                "<element name='Hack' a:help='Hack damage strength'><ref name='nonNegativeDecimal'/></element>" +
     196                "<element name='Pierce' a:help='Pierce damage strength'><ref name='nonNegativeDecimal'/></element>" +
     197                "<element name='Crush' a:help='Crush damage strength'><ref name='nonNegativeDecimal'/></element>" +
     198                Attack.prototype.bonusesSchema +
     199                Attack.prototype.preferredClassesSchema +
     200                Attack.prototype.restrictedClassesSchema +
     201            "</interleave>" +
     202        "</element>" +
    180203    "</optional>";
    181204
    182205Attack.prototype.Init = function()
     
    545568        };
    546569        if (this.template.Ranged.Splash)
    547570        {
    548             data.friendlyFire = this.template.Ranged.Splash.FriendlyFire;
     571            data.friendlyFire = this.template.Ranged.Splash.FriendlyFire != "false";
    549572            data.radius = +this.template.Ranged.Splash.Range;
    550573            data.shape = this.template.Ranged.Splash.Shape;
    551574            data.isSplash = true;
     
    605628        cmpUnitAI.UpdateRangeQueries();
    606629};
    607630
     631Attack.prototype.CauseDeathDamage = function()
     632{
     633    if (!this.template.Death)
     634        return;
     635
     636    let cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
     637    if (!cmpPosition.IsInWorld())
     638        return;
     639
     640    let pos = cmpPosition.GetPosition();
     641    let cmpDamage = Engine.QueryInterface(SYSTEM_ENTITY, IID_Damage);
     642    let owner = Engine.QueryInterface(this.entity, IID_Ownership).GetOwner();
     643    let playersToDamage = cmpDamage.GetPlayersToDamage(this.template.Death.FriendlyFire, owner);
     644
     645    cmpDamage.CauseSplashDamage({
     646        "attacker": this.entity,
     647        "origin": Vector2D.from3D(pos),
     648        "radius": this.template.Death.Range,
     649        "shape": this.template.Death.Shape,
     650        "strengths": this.GetAttackStrengths("Death"),
     651        "direction": 0, //does directed death damage make sense?
     652        "playersToDamage": playersToDamage,
     653        "type": this.template.Type,
     654        "attackerOwner": owner
     655    });
     656
     657};
     658
    608659Engine.RegisterComponentType(IID_Attack, "Attack", Attack);
  • binaries/data/mods/public/simulation/components/Damage.js

     
    6262};
    6363
    6464/**
     65 * Get the list of players affected by the damage.
     66 * @param {boolean} friendlyFire - a flag indicating if allied entities are also damaged.
     67 * @param {number}  attackerOwner - the player id of the attacker.
     68 */
     69Damage.prototype.GetPlayersToDamage = function(friendlyFire, attackerOwner)
     70{
     71    var playersToDamage = [];
     72    if (!friendlyFire)
     73        playersToDamage = QueryPlayerIDInterface(attackerOwner).GetEnemies();
     74    else
     75    {
     76        let numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers();
     77        for (let i = 0; i < numPlayers; ++i)
     78            playersToDamage.push(i);
     79    }
     80    return playersToDamage;
     81}
     82
     83/**
    6584 * Handles hit logic after the projectile travel time has passed.
    6685 * @param {Object}   data - the data sent by the caller.
    6786 * @param {number}   data.attacker - the entity id of the attacker.
     
    87106    // Do this first in case the direct hit kills the target
    88107    if (data.isSplash)
    89108    {
    90         let playersToDamage = !data.friendlyFire ? QueryPlayerIDInterface(data.attackerOwner).GetEnemies() : null;
     109        let playersToDamage = this.GetPlayersToDamage(data.friendlyFire, data.attackerOwner);
    91110
    92111        this.CauseSplashDamage({
    93112            "attacker": data.attacker,
     
    148167 * @param {string}   data.type - the type of damage.
    149168 * @param {number}   data.attackerOwner - the player id of the attacker.
    150169 * @param {Vector3D} data.direction - the unit vector defining the direction.
    151  * @param {number[]} [data.playersToDamage] - the array of player id's to damage.
     170 * @param {number[]} data.playersToDamage - the array of player id's to damage.
    152171 */
    153172Damage.prototype.CauseSplashDamage = function(data)
    154173{
  • binaries/data/mods/public/simulation/components/Health.js

     
    244244
    245245            this.hitpoints = 0;
    246246            this.RegisterHealthChanged(oldHitpoints);
     247
     248            let cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);
     249            if (cmpAttack)
     250                cmpAttack.CauseDeathDamage();
     251
    247252        }
    248253
    249254    }
  • binaries/data/mods/public/simulation/templates/template_unit_infantry_ranged_slinger.xml

     
    1616      <RepeatTime>1000</RepeatTime>
    1717      <Spread>1.4</Spread>
    1818    </Ranged>
     19    <Death>
     20      <Shape>Circular</Shape>
     21      <Range>15</Range>
     22      <FriendlyFire>true</FriendlyFire>
     23      <Hack>50.0</Hack>
     24      <Pierce>60.0</Pierce>
     25      <Crush>70.0</Crush>
     26    </Death>
    1927  </Attack>
    2028  <Cost>
    2129    <Resources>