| 1 | Trigger.prototype.CheckHeroicideDefeat = function(data) |
| 2 | { |
| 3 | if (data.entity == this.heroes[data.from]) |
| 4 | TriggerHelper.DefeatPlayer(data.from); |
| 5 | }; |
| 6 | |
| 7 | Trigger.prototype.InitGame = function(msg) |
| 8 | { |
| 9 | let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); |
| 10 | let heroTemplates = cmpTemplateManager.FindAllTemplates(false).filter(temp => temp.indexOf("_hero_") > -1 && temp.indexOf("campaigns") == -1); |
| 11 | |
| 12 | let numberOfPlayers = TriggerHelper.GetNumberOfPlayers(); |
| 13 | |
| 14 | for (let i = 1; i < numberOfPlayers; ++i) |
| 15 | { |
| 16 | let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); |
| 17 | let playerEntities = cmpRangeManager.GetEntitiesByPlayer(i); |
| 18 | let spawnPoints = playerEntities.filter(p => TriggerHelper.EntityHasClass(p, "CivilCentre")); |
| 19 | |
| 20 | if (!spawnPoints.length) |
| 21 | spawnPoints = playerEntities.filter(p => TriggerHelper.EntityHasClass(p, "Ship")); |
| 22 | |
| 23 | spawnPoints = spawnPoints.length ? spawnPoints : playerEntities; |
| 24 | |
| 25 | let cmpPlayer = QueryPlayerIDInterface(i); |
| 26 | let civHeros = heroTemplates.filter(hero => hero.indexOf(cmpPlayer.GetCiv()) > -1); |
| 27 | |
| 28 | let heroTemplate = civHeros[Math.floor(Math.random() * civHeros.length)]; |
| 29 | this.heroes[i] = TriggerHelper.SpawnUnits(spawnPoints[0], heroTemplate, 1, i); |
| 30 | if (TriggerHelper.EntityHasClass(spawnPoints[0], "Ship")) |
| 31 | { |
| 32 | let cmpUnitAI = Engine.QueryInterface(this.heroes[i][0], IID_UnitAI); |
| 33 | cmpUnitAI.Garrison(spawnPoints[0]); |
| 34 | } |
| 35 | } |
| 36 | }; |
| 37 | |
| 38 | let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); |
| 39 | cmpTrigger.heroes = {}; |
| 40 | cmpTrigger.DoAfterDelay(0, "InitGame", {}); |
| 41 | |
| 42 | cmpTrigger.RegisterTrigger("OnOwnershipChanged", "CheckHeroicideDefeat", { "enabled": true }); |