1 | function DelayedDamage() {}
|
---|
2 |
|
---|
3 | DelayedDamage.prototype.Schema =
|
---|
4 | "<a:component type='system'/><empty/>";
|
---|
5 |
|
---|
6 | DelayedDamage.prototype.Init = function()
|
---|
7 | {
|
---|
8 | };
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * When missiles miss their target, other units in MISSILE_HIT_RADIUS range are considered.
|
---|
12 | * Large missiles should probably implement splash damage anyways,
|
---|
13 | * so keep this value low for performance.
|
---|
14 | */
|
---|
15 | DelayedDamage.prototype.MISSILE_HIT_RADIUS = 2;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Handles hit logic (after a delay has passed).
|
---|
19 | * @param {Object} data - The data sent by the caller.
|
---|
20 | * @param {string} data.type - The type of damage.
|
---|
21 | * @param {Object} data.attackData - Data of the form { 'effectType': { ...opaque effect data... }, 'Bonuses': {...} }.
|
---|
22 | * @param {number} data.target - The entity id of the target.
|
---|
23 | * @param {number} data.attacker - The entity id of the attacker.
|
---|
24 | * @param {number} data.attackerOwner - The player id of the owner of the attacker.
|
---|
25 | * @param {Vector3D} data.position - The expected position of the target.
|
---|
26 | * @param {number} data.projectileId - The id of the projectile.
|
---|
27 | * @param {Vector3D} data.direction - The unit vector defining the direction.
|
---|
28 | * @param {string} data.attackImpactSound - The name of the sound emited on impact.
|
---|
29 | * @param {boolean} data.friendlyFire - A flag indicating whether allied entities can also be damaged.
|
---|
30 | * ***When splash damage***
|
---|
31 | * @param {boolean} data.splash.friendlyFire - A flag indicating if allied entities are also damaged.
|
---|
32 | * @param {number} data.splash.radius - The radius of the splash damage.
|
---|
33 | * @param {string} data.splash.shape - The shape of the splash range.
|
---|
34 | * @param {Object} data.splash.attackData - same as attackData, for splash.
|
---|
35 | */
|
---|
36 | DelayedDamage.prototype.Hit = function(data, lateness)
|
---|
37 | {
|
---|
38 | if (!data.position)
|
---|
39 | return;
|
---|
40 |
|
---|
41 | if (data.attackImpactSound)
|
---|
42 | Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager).PlaySoundGroupAtPosition(data.attackImpactSound, data.position);
|
---|
43 |
|
---|
44 | if (data.splash)
|
---|
45 | Attacking.CauseDamageOverArea({
|
---|
46 | "type": data.type,
|
---|
47 | "attackData": data.splash.attackData,
|
---|
48 | "attacker": data.attacker,
|
---|
49 | "attackerOwner": data.attackerOwner,
|
---|
50 | "origin": Vector2D.from3D(data.position),
|
---|
51 | "radius": data.splash.radius,
|
---|
52 | "shape": data.splash.shape,
|
---|
53 | "direction": data.direction,
|
---|
54 | "friendlyFire": data.splash.friendlyFire
|
---|
55 | });
|
---|
56 |
|
---|
57 | // Since we can't damage mirages, replace a miraged target by the real target.
|
---|
58 | let target = data.target;
|
---|
59 | let cmpMirage = Engine.QueryInterface(data.target, IID_Mirage);
|
---|
60 | if (cmpMirage)
|
---|
61 | target = cmpMirage.GetParent();
|
---|
62 |
|
---|
63 | if (!data.projectileId)
|
---|
64 | {
|
---|
65 | Attacking.HandleAttackEffects(target, data);
|
---|
66 | return;
|
---|
67 | }
|
---|
68 |
|
---|
69 | let cmpProjectileManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ProjectileManager);
|
---|
70 |
|
---|
71 | // Deal direct damage if we hit the main target
|
---|
72 | // and we could handle the attack.
|
---|
73 | if (PositionHelper.TestCollision(target, data.position, lateness) &&
|
---|
74 | Attacking.HandleAttackEffects(target, data))
|
---|
75 | {
|
---|
76 | cmpProjectileManager.RemoveProjectile(data.projectileId);
|
---|
77 | return;
|
---|
78 | }
|
---|
79 |
|
---|
80 | // If we didn't hit the main target look for nearby units.
|
---|
81 | let ents = PositionHelper.EntitiesNearPoint(Vector2D.from3D(data.position), this.MISSILE_HIT_RADIUS,
|
---|
82 | Attacking.GetPlayersToDamage(data.attackerOwner, data.friendlyFire));
|
---|
83 |
|
---|
84 | for (let ent of ents)
|
---|
85 | {
|
---|
86 | if (!PositionHelper.TestCollision(ent, data.position, lateness) ||
|
---|
87 | !Attacking.HandleAttackEffects(ent, data))
|
---|
88 | continue;
|
---|
89 |
|
---|
90 | cmpProjectileManager.RemoveProjectile(data.projectileId);
|
---|
91 | break;
|
---|
92 | }
|
---|
93 | };
|
---|
94 |
|
---|
95 | Engine.RegisterSystemComponentType(IID_DelayedDamage, "DelayedDamage", DelayedDamage);
|
---|