source: ps/trunk/binaries/data/mods/public/maps/scenarios/treasure_islands.js

Last change on this file was 21870, checked in by elexis, 6 years ago

Use https in hyperlinks for sites that support it, refs #5257.

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
1Trigger.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({
8 "players": [1,2],
9 "message": markForTranslation("Collect the treasures before your enemy does! May the better win!"),
10 translateMessage: true
11 });
12};
13
14Trigger.prototype.TreasureCollected = function(data)
15{
16 var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
17
18 var count = ++this.treasureCount.players[data.player];
19 var goalCount = this.treasureCount.maximum / 2 + 1;
20 var otherPlayer = (data.player == 1 ? 2 : 1);
21
22 // Check if having more treasures than the enemy is still possible
23 if ( (count == this.treasureCount.maximum / 2) &&
24 (this.treasureCount.players[otherPlayer] == this.treasureCount.maximum / 2) )
25 {
26 cmpGUIInterface.PushNotification({
27 "players": [1,2],
28 "message": markForTranslation("No winner yet, prepare for battle!"),
29 "translateMessage": true
30 });
31
32 // keep notifying the player that the victory condition has changed.
33 this.RegisterTrigger("OnInterval", "BattleMessage", {
34 "enabled": true,
35 "delay": 10000,
36 "interval": 12000
37 });
38 }
39 else if (count >= goalCount) // Check for victory
40 {
41 cmpGUIInterface.PushNotification({
42 "players": [otherPlayer],
43 "message": markForTranslation("Your enemy's treasury is filled to the brim, you lose!"),
44 "translateMessage": true
45 });
46 cmpGUIInterface.PushNotification({
47 "players": [data.player],
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({
59 "players": [otherPlayer],
60 "message": markForTranslation("Hurry up! Your enemy is close to victory!"),
61 "translateMessage": true
62 });
63 }
64
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({
78 "players": [data.player],
79 "message": markForTranslation("You have collected a treasure!"),
80 "translateMessage": true
81 });
82 }
83 }
84};
85
86Trigger.prototype.BattleMessage = function()
87{
88 var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
89 cmpGUIInterface.PushNotification({
90 "players": [1,2],
91 "message": markForTranslation("Defeat your enemy to win!"),
92 "translateMessage": true
93 });
94};
95
96Trigger.prototype.Victory = function(playerID)
97{
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));
108};
109
110var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
111
112// TODO: It would be nice to get the total number of treasure on the map automatically somehow
113cmpTrigger.treasureCount = { "players": { "1":0,"2":0 }, "maximum": 36 };
114cmpTrigger.state = "start";
115cmpTrigger.DoAfterDelay(2000, "IntroductionMessage", {});
116cmpTrigger.RegisterTrigger("OnTreasureCollected", "TreasureCollected", { "enabled": true });
Note: See TracBrowser for help on using the repository browser.