Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Visibility.js
Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | Visibility.prototype.GetRetainInFog = function() | ||||
return this.retainInFog; | return this.retainInFog; | ||||
}; | }; | ||||
Visibility.prototype.GetAlwaysVisible = function() | Visibility.prototype.GetAlwaysVisible = function() | ||||
{ | { | ||||
return this.alwaysVisible; | return this.alwaysVisible; | ||||
}; | }; | ||||
Visibility.prototype.RevealForPlayer = function(player, time) | |||||
wraitii: This should totally be in Vision :p | |||||
{ | |||||
// This is only called for attackers that aren't visible, | |||||
// so this is probably efficient enough. | |||||
let cmpPos = Engine.QueryInterface(this.entity, IID_Position); | |||||
if (!cmpPos || !cmpPos.IsInWorld()) | |||||
return; | |||||
let beacon = Engine.AddEntity("los_beacons/los_reveal_10"); | |||||
let cmpBeaconPos = Engine.QueryInterface(beacon, IID_Position); | |||||
let pos = cmpPos.GetPosition2D(); | |||||
cmpBeaconPos.JumpTo(pos.x, pos.y); | |||||
let cmpBeaconOwner = Engine.QueryInterface(beacon, IID_Ownership); | |||||
cmpBeaconOwner.SetOwner(player); | |||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | |||||
cmpTimer.SetTimeout(this.entity, IID_Visibility, "DestroyBeacon", time, { "beacon": beacon }); | |||||
}; | |||||
Visibility.prototype.DestroyBeacon = function(data) | |||||
{ | |||||
if (data.beacon) | |||||
Engine.DestroyEntity(data.beacon); | |||||
}; | |||||
// TODO: this should be in Vision, but that requires moving Vision to JS. | |||||
Visibility.prototype.OnAttacked = function(msg) | |||||
{ | |||||
if (!msg.attacker) | |||||
return; | |||||
let cmpAttackerVisibility = Engine.QueryInterface(msg.attacker, IID_Visibility); | |||||
if (!cmpAttackerVisibility) | |||||
return; | |||||
let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); | |||||
if (!cmpOwnership) | |||||
return; | |||||
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | |||||
if (cmpRangeManager.GetLosVisibility(msg.attacker, cmpOwnership.GetOwner()) === "visible") | |||||
return; | |||||
cmpAttackerVisibility.RevealForPlayer(cmpOwnership.GetOwner(), 3000); | |||||
}; | |||||
Engine.RegisterComponentType(IID_Visibility, "Visibility", Visibility); | Engine.RegisterComponentType(IID_Visibility, "Visibility", Visibility); |
Wildfire Games · Phabricator
This should totally be in Vision :p