forked from plainblack/Lacuna-Web-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathessentia.js
332 lines (318 loc) · 18.3 KB
/
essentia.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
YAHOO.namespace("lacuna");
if (typeof YAHOO.lacuna.Essentia == "undefined" || !YAHOO.lacuna.Essentia) {
(function(){
var Lang = YAHOO.lang,
Util = YAHOO.util,
Dom = Util.Dom,
Event = Util.Event,
Sel = Util.Selector,
Lacuna = YAHOO.lacuna,
Game = Lacuna.Game,
Lib = Lacuna.Library;
var Essentia = function() {
this.createEvent("onRpc");
this.id = "essentia";
var container = document.createElement("div");
container.id = this.id;
Dom.addClass(container, Lib.Styles.HIDDEN);
container.innerHTML = this._getHtml();
document.body.insertBefore(container, document.body.firstChild);
Dom.addClass(container, "nofooter");
this.Dialog = new YAHOO.widget.Panel(this.id, {
constraintoviewport:true,
fixedcenter:true,
visible:false,
draggable:true,
effect:Game.GetContainerEffect(),
underlay:false,
modal:true,
close:true,
width:"500px",
zIndex:9999
});
this.Dialog.renderEvent.subscribe(function(){
this.timeFood = Dom.get("essentialDetailsTimeFood");
this.timeOre = Dom.get("essentialDetailsTimeOre");
this.timeWater = Dom.get("essentialDetailsTimeWater");
this.timeEnergy = Dom.get("essentialDetailsTimeEnergy");
this.timeHappiness = Dom.get("essentialDetailsTimeHappiness");
this.timeStorage = Dom.get("essentialDetailsTimeStorage");
this.timeBuilding = Dom.get("essentialDetailsTimeBuilding");
this.elCode = Dom.get("essentiaRedeemCode");
this.elEssentiaAmount = Dom.get("essentiaAmount");
this.tabView = new YAHOO.widget.TabView('essentiaTabs');
Event.on(["essentiaBoostFood","essentiaBoostOre","essentiaBoostWater","essentiaBoostEnergy","essentiaBoostHappiness","essentiaBoostStorage","essentiaBoostBuilding"], "click", this.boost, this, true);
Event.on('essentiaRedeemButton', 'click', this.redeemClick, this, true);
Event.on('essentiaInvite', 'click', Lacuna.Invite.show, this, true);
Event.on("essentiaPurchaseButton", "click", function(e){
Event.stopEvent(e);
window.open("/pay?session_id=" + Game.GetSession(), "essentiaPayment", "status=0,toolbar=0,location=0,menubar=0,resizable=1,scrollbars=1,height=550,width=600,directories=0");
});
Game.onTick.subscribe(function(){
this.elEssentiaAmount.innerHTML = Game.EmpireData.essentia;
}, this, true);
Dom.removeClass(this.id, Lib.Styles.HIDDEN);
}, this, true);
this.Dialog.hideEvent.subscribe(function(){
if (this._interval) {
window.clearInterval(this._interval);
delete this._interval;
this.timers = {};
}
}, this, true);
this.timers = {};
this.Dialog.render();
Game.OverlayManager.register(this.Dialog);
};
Essentia.prototype = {
_getHtml : function() {
return [
' <div class="hd">Essentia</div>',
' <div class="bd">',
' <div class="essentiaAmount">Current Essentia: <span id="essentiaAmount"></span></div>',
' <div id="essentiaTabs" class="yui-navset">',
' <ul class="yui-nav">',
' <li><a href="#essentiaTabBoost"><em>Boosts</em></a></li>',
' <li><a href="#essentiaGetMore"><em>Get More Essentia</em></a></li>',
' <li><a href="#essentiaGiveEssentia"><em>Give Essentia</em></a></li>',
' </ul>',
' <div class="yui-content">',
' <div id="essentiaTabBoost">',
' <table>',
' <tr><td colspan="4"> </td><th>Expires</th></tr>',
' <tr>',
' <td class="essentiaDetailsImg"><img class="smallFood" title="Food" src="',Lib.AssetUrl,'ui/s/food.png" /></td>',
' <td class="essentiaDetailsText">+25% food per hour</td>',
' <td class="essentiaDetailsCost">5 <img src="',Lib.AssetUrl,'ui/s/essentia.png" class="smallEssentia" /></td>',
' <td class="essentiaDetailsBoost"><button id="essentiaBoostFood" type="button">Boost</button></td>',
' <td class="essentiaDetailsTime" id="essentialDetailsTimeFood"></td>',
' </tr>',
' <tr>',
' <td class="essentiaDetailsImg"><img class="smallOre" title="Ore" src="',Lib.AssetUrl,'ui/s/ore.png" /></td>',
' <td class="essentiaDetailsText">+25% ore per hour</td>',
' <td class="essentiaDetailsCost">5 <img src="',Lib.AssetUrl,'ui/s/essentia.png" class="smallEssentia" /></td>',
' <td class="essentiaDetailsBoost"><button id="essentiaBoostOre" type="button">Boost</button></td>',
' <td class="essentiaDetailsTime" id="essentialDetailsTimeOre"></td>',
' </tr>',
' <tr>',
' <td class="essentiaDetailsImg"><img class="smallWater" title="Water" src="',Lib.AssetUrl,'ui/s/water.png" /></td>',
' <td class="essentiaDetailsText">+25% water per hour</td>',
' <td class="essentiaDetailsCost">5 <img src="',Lib.AssetUrl,'ui/s/essentia.png" class="smallEssentia" /></td>',
' <td class="essentiaDetailsBoost"><button id="essentiaBoostWater" type="button">Boost</button></td>',
' <td class="essentiaDetailsTime" id="essentialDetailsTimeWater"></td>',
' </tr>',
' <tr>',
' <td class="essentiaDetailsImg"><img class="smallEnergy" title="Energy" src="',Lib.AssetUrl,'ui/s/energy.png" /></td>',
' <td class="essentiaDetailsText">+25% energy per hour</td>',
' <td class="essentiaDetailsCost">5 <img src="',Lib.AssetUrl,'ui/s/essentia.png" class="smallEssentia" /></td>',
' <td class="essentiaDetailsBoost"><button id="essentiaBoostEnergy" type="button">Boost</button></td>',
' <td class="essentiaDetailsTime" id="essentialDetailsTimeEnergy"></td>',
' </tr>',
' <tr>',
' <td class="essentiaDetailsImg"><img class="smallHappiness" title="Happiness" src="',Lib.AssetUrl,'ui/s/happiness.png" /></td>',
' <td class="essentiaDetailsText">+25% happiness per hour</td>',
' <td class="essentiaDetailsCost">5 <img src="',Lib.AssetUrl,'ui/s/essentia.png" class="smallEssentia" /></td>',
' <td class="essentiaDetailsBoost"><button id="essentiaBoostHappiness" type="button">Boost</button></td>',
' <td class="essentiaDetailsTime" id="essentialDetailsTimeHappiness"></td>',
' </tr>',
' <tr>',
' <td class="essentiaDetailsImg"><img class="smallStorage" title="Storage" src="',Lib.AssetUrl,'ui/s/storage.png" /></td>',
' <td class="essentiaDetailsText">+25% storage capacity</td>',
' <td class="essentiaDetailsCost">5 <img src="',Lib.AssetUrl,'ui/s/essentia.png" class="smallEssentia" /></td>',
' <td class="essentiaDetailsBoost"><button id="essentiaBoostStorage" type="button">Boost</button></td>',
' <td class="essentiaDetailsTime" id="essentialDetailsTimeStorage"></td>',
' </tr>',
' <tr>',
' <td class="essentiaDetailsImg"><img class="smallBuilding" title="Building" src="',Lib.AssetUrl,'ui/s/build.png" /></td>',
' <td class="essentiaDetailsText">+25% build speed</td>',
' <td class="essentiaDetailsCost">5 <img src="',Lib.AssetUrl,'ui/s/essentia.png" class="smallEssentia" /></td>',
' <td class="essentiaDetailsBoost"><button id="essentiaBoostBuilding" type="button">Boost</button></td>',
' <td class="essentiaDetailsTime" id="essentialDetailsTimeBuilding"></td>',
' </tr>',
' </table>',
' </div>',
' <div id="essentiaGetMore">',
' <b>Purchase Essentia for yourself.</b><br />',
' <button id="essentiaPurchaseButton" type="button">Purchase Essentia</button>',
' <hr />',
' <div>',
' <label><b>Redeem Essentia Code:</b><br /><input id="essentiaRedeemCode" /></label>',
' <button id="essentiaRedeemButton" type="button">Redeem</button>',
' </div>',
' <hr />',
' <div>',
' <table>',
' <tr><td><b>Invite your friends.</b></td></tr>',
' <tr><td>Invite your friends to the game and you get free essentia. For every university level past 4 that they achieve, you\'ll get 5 essentia.</td></tr>',
' <tr><td>That\'s up to 130 essentia per friend!</td></tr>',
' <tr><td><button id="essentiaInvite" type="button">Invite Friends</button></td></tr>',
' </table>',
' </div>',
' </div>',
' <div id="essentiaGetMore">',
' <p><b>Give the gift of Essentia.</b><br />Simply choose the amount you want, and pay for at it at PayPal with a credit card, or with your PayPal account. You\'ll then receive an email with an essentia code that can be redeemed in the game.</p>',
' <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">',
' <input type="hidden" name="cmd" value="_s-xclick">',
' <input type="hidden" name="hosted_button_id" value="X66S44RDHKKS8">',
' <p style="margin: 10px 0;"><input type="hidden" name="on0" value="Buy an Essentia Code">Buy an Essentia Code: <select name="os0">',
' <option value="30 Essentia">30 Essentia $2.99</option>',
' <option value="100 Essentia">100 Essentia $5.99</option>',
' <option value="200 Essentia">200 Essentia $9.99</option>',
' <option value="600 Essentia">600 Essentia $24.99</option>',
' <option value="1300 Essentia">1300 Essentia $49.99</option>',
' </select></p>',
' <input type="hidden" name="currency_code" value="USD">',
' <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">',
' <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">',
' </form>',
' </div>',
' </div>',
' </div>',
' </div>'
].join('');
},
show : function() {
//this is called out of scope so make sure to pass the correct scope in
Lacuna.Essentia.tabView.selectTab(0);
Lacuna.Essentia.elCode.value = '';
Game.Services.Empire.view_boosts({session_id:Game.GetSession("")},{
success : function(o){
YAHOO.log(o, "info", "Essentia.show.success");
var Self = this;
this._interval = window.setInterval(function(){
Self.tick();
}, 1000);
this.populate(o.result);
},
scope:Lacuna.Essentia
});
Game.OverlayManager.hideAll();
Lacuna.Essentia.elEssentiaAmount.innerHTML = Game.EmpireData.essentia;
Lacuna.Essentia.Dialog.show();
},
hide : function() {
this.Dialog.hide();
},
paymentFinished : function(amount) {
},
redeemClick : function (e) {
Event.stopEvent(e);
var code = this.elCode.value;
var currentEssentia = Game.EmpireData.essentia;
Lacuna.Pulser.Show();
Game.Services.Empire.redeem_essentia_code({
session_id:Game.GetSession(""),
essentia_code: code
},{
success : function(o){
YAHOO.log(o, "info", "EssentiaRedeem.show.success");
Lacuna.Pulser.Hide();
var addedEssentia = o.result.status.empire.essentia - currentEssentia;
alert('Redeemed code for '+addedEssentia+' essentia.');
this.elCode.value = '';
this.fireEvent('onRpc', o.result);
},
scope:this
});
},
boost : function(e) {
var target = Event.getTarget(e);
var func;
switch(target.id) {
case "essentiaBoostFood":
func = Game.Services.Empire.boost_food;
break;
case "essentiaBoostOre":
func = Game.Services.Empire.boost_ore;
break;
case "essentiaBoostWater":
func = Game.Services.Empire.boost_water;
break;
case "essentiaBoostEnergy":
func = Game.Services.Empire.boost_energy;
break;
case "essentiaBoostHappiness":
func = Game.Services.Empire.boost_happiness;
break;
case "essentiaBoostStorage":
func = Game.Services.Empire.boost_storage;
break;
case "essentiaBoostBuilding":
func = Game.Services.Empire.boost_building;
break;
}
if(func) {
func({session_id:Game.GetSession("")},{
success : function(o){
YAHOO.log(o, "info", "Essentia.boost.success");
this.update(o.result);
this.fireEvent("onRpc", o.result);
},
scope:this
});
}
},
update : function(results) {
if(results.food_boost) {
this.updateTime(this.timeFood, results.food_boost);
}
else if(results.ore_boost) {
this.updateTime(this.timeOre, results.ore_boost);
}
else if(results.water_boost) {
this.updateTime(this.timeWater, results.water_boost);
}
else if(results.energy_boost) {
this.updateTime(this.timeEnergy, results.energy_boost);
}
else if(results.happiness_boost) {
this.updateTime(this.timeHappiness, results.happiness_boost);
}
else if(results.storage_boost) {
this.updateTime(this.timeStorage, results.storage_boost);
}
else if(results.building_boost) {
this.updateTime(this.timeBuilding, results.building_boost);
}
},
populate : function(results) {
var boosts = results.boosts;
this.updateTime(this.timeFood, boosts.food);
this.updateTime(this.timeOre, boosts.ore);
this.updateTime(this.timeWater, boosts.water);
this.updateTime(this.timeEnergy, boosts.energy);
this.updateTime(this.timeHappiness, boosts.happiness);
this.updateTime(this.timeStorage, boosts.storage);
this.updateTime(this.timeBuilding, boosts.building);
},
updateTime : function(el, sDate) {
var timers = this.timers;
timers[el.id] = function() {
if(sDate) {
var tTime = Lib.getTime(Lib.parseServerDate(sDate)),
cTime = Lib.getTime(Game.ServerData.time),
diffTime = tTime - cTime;
if(diffTime > 0) {
el.innerHTML = Lib.formatMillisecondTime(diffTime);
return;
}
}
delete timers[el.id];
el.innerHTML = " ";
};
timers[el.id]();
},
tick : function() {
for (var key in this.timers){
if (this.timers.hasOwnProperty(key)) {
this.timers[key]();
}
}
}
};
Lang.augmentProto(Essentia, Util.EventProvider);
Lacuna.Essentia = new Essentia();
})();
YAHOO.register("essentia", YAHOO.lacuna.Essentia, {version: "1", build: "0"});
}
// vim: noet:ts=4:sw=4