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