Line data Source code
1 : function TriggerPoint() {} 2 : 3 0 : TriggerPoint.prototype.Schema = 4 : "<optional>" + 5 : "<element name='Reference'>" + 6 : "<text/>" + 7 : "</element>" + 8 : "</optional>"; 9 : 10 0 : TriggerPoint.prototype.Init = function() 11 : { 12 0 : if (this.template && this.template.Reference) 13 : { 14 0 : var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); 15 0 : cmpTrigger.RegisterTriggerPoint(this.template.Reference, this.entity); 16 : } 17 0 : this.currentCollections = {}; 18 0 : this.triggers = {}; 19 : }; 20 : 21 0 : TriggerPoint.prototype.OnDestroy = function() 22 : { 23 0 : if (this.template && this.template.EntityReference) 24 : { 25 0 : var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); 26 0 : cmpTrigger.RemoveRegisteredTriggerPoint(this.template.Reference, this.entity); 27 : } 28 : }; 29 : 30 : /** 31 : * @param name Name of the trigger. 32 : * @param data The data is an object containing information for the range query 33 : * Some of the data has sendible defaults (mentionned next to the object) 34 : * data.players = [1,2,3,...] * list of player ids 35 : * data.minRange = 0 * Minimum range for the query 36 : * data.maxRange = -1 * Maximum range for the query (-1 = no maximum) 37 : * data.requiredComponent = 0 * Required component id the entities will have 38 : * data.enabled = false * If the query is enabled by default 39 : */ 40 0 : TriggerPoint.prototype.RegisterRangeTrigger = function(name, data) 41 : { 42 0 : var players = data.players || Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetAllPlayers(); 43 0 : var minRange = data.minRange || 0; 44 0 : var maxRange = data.maxRange || -1; 45 0 : var cid = data.requiredComponent || 0; 46 : 47 0 : var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 48 0 : var tag = cmpRangeManager.CreateActiveQuery(this.entity, minRange, maxRange, players, cid, cmpRangeManager.GetEntityFlagMask("normal"), true); 49 : 50 0 : this.currentCollections[tag] = []; 51 0 : this.triggers[tag] = name; 52 0 : return tag; 53 : }; 54 : 55 0 : TriggerPoint.prototype.OnRangeUpdate = function(msg) 56 : { 57 0 : var collection = this.currentCollections[msg.tag]; 58 0 : if (!collection) 59 0 : return; 60 : 61 0 : for (var ent of msg.removed) 62 : { 63 0 : var index = collection.indexOf(ent); 64 0 : if (index > -1) 65 0 : collection.splice(index, 1); 66 : } 67 : 68 0 : for (var entity of msg.added) 69 0 : collection.push(entity); 70 : 71 0 : var r = { "currentCollection": collection.slice() }; 72 0 : r.added = msg.added; 73 0 : r.removed = msg.removed; 74 0 : var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); 75 0 : cmpTrigger.CallTrigger("OnRange", this.triggers[msg.tag], r); 76 : }; 77 : 78 : 79 0 : Engine.RegisterComponentType(IID_TriggerPoint, "TriggerPoint", TriggerPoint);