[15432] | 1 | Trigger.prototype.IntroductionMessage = function(data)
|
---|
| 2 | {
|
---|
| 3 | if (this.state != "start")
|
---|
| 4 | return;
|
---|
| 5 |
|
---|
| 6 | var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
---|
| 7 | cmpGUIInterface.PushNotification({
|
---|
[18840] | 8 | "players": [1,2],
|
---|
[15432] | 9 | "message": markForTranslation("Collect the treasures before your enemy does! May the better win!"),
|
---|
| 10 | translateMessage: true
|
---|
| 11 | });
|
---|
| 12 | };
|
---|
| 13 |
|
---|
| 14 | Trigger.prototype.TreasureCollected = function(data)
|
---|
| 15 | {
|
---|
| 16 | var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
---|
| 17 |
|
---|
| 18 | var count = ++this.treasureCount.players[data.player];
|
---|
[18839] | 19 | var goalCount = this.treasureCount.maximum / 2 + 1;
|
---|
[15432] | 20 | var otherPlayer = (data.player == 1 ? 2 : 1);
|
---|
[18840] | 21 |
|
---|
[15432] | 22 | // Check if having more treasures than the enemy is still possible
|
---|
[18840] | 23 | if ( (count == this.treasureCount.maximum / 2) &&
|
---|
[15432] | 24 | (this.treasureCount.players[otherPlayer] == this.treasureCount.maximum / 2) )
|
---|
| 25 | {
|
---|
[17614] | 26 | cmpGUIInterface.PushNotification({
|
---|
| 27 | "players": [1,2],
|
---|
| 28 | "message": markForTranslation("No winner yet, prepare for battle!"),
|
---|
| 29 | "translateMessage": true
|
---|
| 30 | });
|
---|
[18840] | 31 |
|
---|
[15432] | 32 | // keep notifying the player that the victory condition has changed.
|
---|
[18839] | 33 | this.RegisterTrigger("OnInterval", "BattleMessage", {
|
---|
| 34 | "enabled": true,
|
---|
| 35 | "delay": 10000,
|
---|
| 36 | "interval": 12000
|
---|
| 37 | });
|
---|
[15432] | 38 | }
|
---|
| 39 | else if (count >= goalCount) // Check for victory
|
---|
| 40 | {
|
---|
| 41 | cmpGUIInterface.PushNotification({
|
---|
[18840] | 42 | "players": [otherPlayer],
|
---|
[16002] | 43 | "message": markForTranslation("Your enemy's treasury is filled to the brim, you lose!"),
|
---|
[15432] | 44 | "translateMessage": true
|
---|
| 45 | });
|
---|
| 46 | cmpGUIInterface.PushNotification({
|
---|
[18840] | 47 | "players": [data.player],
|
---|
[15432] | 48 | "message": markForTranslation("Your treasury is filled to the brim, you are victorious!"),
|
---|
| 49 | "translateMessage": true
|
---|
| 50 | });
|
---|
| 51 | this.DoAfterDelay(5000, "Victory", data.player);
|
---|
| 52 | }
|
---|
| 53 | else
|
---|
| 54 | {
|
---|
| 55 | // Notify if the other player if a player is close to victory (3 more treasures to collect)
|
---|
| 56 | if (count + 3 == goalCount)
|
---|
| 57 | {
|
---|
| 58 | cmpGUIInterface.PushNotification({
|
---|
[18840] | 59 | "players": [otherPlayer],
|
---|
[15432] | 60 | "message": markForTranslation("Hurry up! Your enemy is close to victory!"),
|
---|
| 61 | "translateMessage": true
|
---|
| 62 | });
|
---|
| 63 | }
|
---|
[18840] | 64 |
|
---|
[15432] | 65 | if (count + 3 >= goalCount)
|
---|
| 66 | {
|
---|
| 67 | var remainingTreasures = ( goalCount - count);
|
---|
| 68 | cmpGUIInterface.PushNotification({
|
---|
| 69 | "players": [data.player],
|
---|
| 70 | "parameters": {"remainingTreasures": remainingTreasures},
|
---|
| 71 | "message": markForTranslation("Treasures remaining to collect for victory: %(remainingTreasures)s!"),
|
---|
| 72 | "translateMessage": true
|
---|
| 73 | });
|
---|
| 74 | }
|
---|
| 75 | else
|
---|
| 76 | {
|
---|
| 77 | cmpGUIInterface.PushNotification({
|
---|
[18840] | 78 | "players": [data.player],
|
---|
[15432] | 79 | "message": markForTranslation("You have collected a treasure!"),
|
---|
| 80 | "translateMessage": true
|
---|
| 81 | });
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 | };
|
---|
| 85 |
|
---|
| 86 | Trigger.prototype.BattleMessage = function()
|
---|
| 87 | {
|
---|
| 88 | var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
---|
| 89 | cmpGUIInterface.PushNotification({
|
---|
[18840] | 90 | "players": [1,2],
|
---|
[15432] | 91 | "message": markForTranslation("Defeat your enemy to win!"),
|
---|
| 92 | "translateMessage": true
|
---|
| 93 | });
|
---|
[18839] | 94 | };
|
---|
[15432] | 95 |
|
---|
| 96 | Trigger.prototype.Victory = function(playerID)
|
---|
| 97 | {
|
---|
[19955] | 98 | TriggerHelper.SetPlayerWon(
|
---|
| 99 | playerID,
|
---|
| 100 | n => markForPluralTranslation(
|
---|
| 101 | "%(lastPlayer)s has won (treasure collected).",
|
---|
| 102 | "%(players)s and %(lastPlayer)s have won (treasure collected).",
|
---|
| 103 | n),
|
---|
| 104 | n => markForPluralTranslation(
|
---|
| 105 | "%(lastPlayer)s has been defeated (treasure collected).",
|
---|
| 106 | "%(players)s and %(lastPlayer)s have been defeated (treasure collected).",
|
---|
| 107 | n));
|
---|
[18839] | 108 | };
|
---|
[15432] | 109 |
|
---|
[18840] | 110 | var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
|
---|
| 111 |
|
---|
[15432] | 112 | // TODO: It would be nice to get the total number of treasure on the map automatically somehow
|
---|
| 113 | cmpTrigger.treasureCount = { "players": { "1":0,"2":0 }, "maximum": 36 };
|
---|
| 114 | cmpTrigger.state = "start";
|
---|
| 115 | cmpTrigger.DoAfterDelay(2000, "IntroductionMessage", {});
|
---|
| 116 | cmpTrigger.RegisterTrigger("OnTreasureCollected", "TreasureCollected", { "enabled": true });
|
---|