This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
/
player.js
3502 lines (2780 loc) · 90 KB
/
player.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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//#include inc_admin.js, inc_groups.js, inc_organizations.js, inc_making.js
//#include inc_stores.js, inc_skills.js, inc_stats.js
//#include inc_metabolics.js, inc_items.js
//#include inc_buddies.js, inc_quests.js, inc_buffs.js
//#include inc_tests.js, inc_houses.js, inc_acl_keys.js, inc_achievements.js
//#include inc_familiar.js, inc_demo.js, inc_party.js, inc_instances.js
//#include inc_auctions.js, inc_announcements.js, inc_skill_packages.js
//#include inc_activity.js, inc_prompts.js, inc_trophies.js
//#include inc_trading.js, inc_teleportation.js, inc_jobs.js
//#include inc_daily_history.js, inc_profile.js, inc_rewards.js
//#include inc_avatar.js, inc_mail.js, inc_conversations.js
//#include ../items/include/events.js ../items/include/rook.js
//#include inc_special_locations.js, inc_games.js, inc_eleven_secrets.js
//#include inc_requests.js, inc_counters.js, inc_imagination.js, inc_furniture.js
//#include inc_world_events.js, inc_mountaineering.js, inc_physics.js
//#include inc_butler.js, inc_newxp.js, inc_towers.js, inc_feats.js
//#include inc_visiting.js, inc_emotes.js
log.info("player.js EXECUTED");
var is_player = 1;
function init(){
//
// core stuff
//
if (!this.date_last_login) this.date_last_login = 0;
if (!this.is_dead) this.is_dead = 0;
//
// various bits
//
this.stats_init();
this.skills_init();
this.making_init();
this.buffs_init();
this.metabolics_init(); // must come after stats & buffs
this.achievements_init();
this.quests_init();
this.familiar_init();
this.instances_init();
this.auctions_init();
this.prompts_init();
this.trading_init();
this.jobs_init();
this.daily_history_init();
this.rewards_init();
this.mail_init();
this.buddies_init();
this.groups_init();
this.organizations_init();
this.conversations_init();
this.teleportation_init();
this.counters_init();
this.imagination_init();
this.furniture_init();
// Hardcoded values matching the client
this.h = 112;
this.w = 59;
//
// clean up old things
//
if (this.abilities){
this.abilities.apiDelete();
delete this.abilities;
}
delete this.talents;
delete this.level;
delete this.cash;
delete this.announce;
delete this.schoolState;
delete this.toSP;
delete this.toLoc;
delete this.dist;
delete this.character_class;
delete this.garliced;
delete this.mooned;
delete this.bag_size;
delete this.last_pet;
//delete this.home;
if (this.starting_instance) this.starting_instance.apiDelete();
delete this.starting_instance;
if (!this.is_god && this.location_history) delete this.location_history;
}
//
// Called by the GS when the player logs in
//
function onLogin(){
log.info('----------------- onLogin: '+this.tsid);
this.init();
this.familiar_clean_queue();
this.quests_restart_queue();
// Clear Zilloween data if necessary
if (!isZilloween()) {
this.clearZilloweenData();
}
//
// tell reverse contacts that we've come online
//
var tsids = this.buddies_get_reverse_tsids();
var args = {
tsid: this.tsid,
label: this.label,
level: this.stats_get_level(),
location: {
tsid: this.location.getProp('tsid'),
label: this.location.is_hidden() ? 'A secret place' : this.location.getProp('label')
}
};
var online = apiCallMethodForOnlinePlayers('buddies_send_buddy_online', tsids, args);
this.date_last_login = time();
// Do any region-specific log-in stuff
this.location.region_login(this);
if (!this.last_location) { this.last_location = this.location; }
this.tp_queue = [];
this.imagination_convert();
//this.imagination_convert_currants();
}
//
// This is called when a player is moved to another GS and they have re-connected to it
//
function onRelogin(){
log.info('----------------- onReLogin: '+this.tsid);
this.init();
}
//
// Called by 'login_end' in main.js (the client has finished logging in and loading the game)
//
function onLoggedin(){
this.buffs_login();
this.houses_login();
//
// learn new recipes created since we learned the skill
//
this.skills_learn_missing_recipes();
this.achievements_login();
this.quests_login();
this.party_login();
this.instances_login();
this.trading_rollback();
this.rewards_return();
this.conversations_login();
this.date_last_loggedin = time();
//
// Resume any overlays
//
if (this.last_overlay_script){
delete this.last_overlay_script;
this.run_overlay_script(this.last_overlay_script);
this.apiSendMsg({ type: 'annc_flush' }); // HACKS!
}
this.checkNewGameDay();
this.apiCancelTimer('onPeriodicEnergyLoss');
this.apiSetTimer('onPeriodicEnergyLoss', 90000);
// Periodically check for play time achievements:
this.apiSetTimer('onPlayTimeCheck', 120000);
this.is_afk = false;
// move any expired courier items into the mailbox.
this.mail_login();
// Did someone recognize our death while we were logged out?
if (this.death_recognized) {
this.recognizeDeath(this.death_recognized.type, this.death_recognized.recognizer);
delete this.death_recognized;
}
// fix broken quoin upgrades:
var coin_modifier = 0;
if (this.buffs_has('crazy_coin_collector')) coin_modifier = 50;
this.stats_set_quoins_max_today(this.imagination_get_quoin_limit() + coin_modifier);
// Mail 2011 Glitchmas Gift between 2011-12-24 @4pm and end of Glitchmas (2012-01-03 @10am)
/*if (config.is_dev || ((getTime()/1000 > 1324771200) && isGlitchmas())){
this.mail_send_special_item('glitchmas_cracker', 1, "Good news! The Glitchmas Yeti awoke from hibernation and sent us a box of these. We’re not sure what they are — though from the description on the packaging it seems to be some kind of explosive …<split butt_txt=\"Wot?\" />Yeah, we thought we should do the safe thing and get them out of the office as soon as possible. So we passed them on to you!<split butt_txt=\"Hmm. Thanks.\" />You might want to find a friend to pull it with, though. Who knows? Maybe there’s something inside. We’re too scared to look. Happy Glitchmas! — Tiny Speck");
}*/
if (this.skills_get_count() >= 11) this.achievements_grant('first_eleven_skills');
// Recover feat rewards
if (this.feats_has_unclaimed_rewards()){
this.familiar_send_alert({
'callback' : 'feats_familiar_turnin_do',
'feat_id' : this.feats_has_unclaimed_rewards()
});
}
}
//
// Called by the GS when the player disconnects or is timed out
// There is *always* an onLogin before this, but not necessarily an onLoggedIn
//
function onLogout(){
log.info("ON LOGOUT ",this.label);
this.buffs_logout();
this.houses_logout();
this.party_logout();
this.instances_logout();
this.groups_logout();
this.organizations_logout();
this.trading_cancel_auto();
this.quests_pause_queue();
this.quests_on_logout();
//
// tell reverse contacts that we've gone offline
//
var tsids = this.buddies_get_reverse_tsids();
var online = apiCallMethodForOnlinePlayers('buddies_send_buddy_offline', tsids, {tsid: this.tsid, label: this.label});
//
// tell old location we've gone offline (this is to handle when client reloads mid-move, after player has been removed from old location already
//
if (this['!local_move_data'] && this['!local_move_data'].old_loc) {
this['!local_move_data'].old_loc.apiSendMsg({
type: 'pc_logout',
pc: this.make_hash()
});
}
//
// Record time played and test for *real* logout
//
if (this.date_last_loggedin && (this.date_last_loggedin > this.date_last_logout || !this.date_last_logout)){
var time_played = time() - this.date_last_loggedin;
log.info(this.label + ' was logged in for ' + time_played + ' seconds.');
var d = new Date();
var day = d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate();
// Only accurate as of 2011-04-13 1:30pm-ish
this.achievements_increment('time_played', day, time_played);
this.counters_increment('time_played', day, time_played);
if (!this.time_played) this.time_played = 0;
this.time_played += time_played;
apiLogAction('LOGOUT', 'pc='+this.tsid);
}
if (this['!current_overlay_script']){
this.last_overlay_script = this['!current_overlay_script'];
delete this['!current_overlay_script'];
}
if (this['!mining']){
var rock = apiFindObject(this['!mining']);
if (rock){
rock.cancelMining(this);
}
}
if (this['!clearing']){
var tree = apiFindObject(this['!clearing']);
if (tree){
tree.cancelClearing(this);
}
}
if (this['!pulling']) {
var cracker = apiFindObject(this['!pulling']);
if (cracker){
cracker.cancelPulling(this);
}
}
// Stop following and remove followers
this.stopFollowing();
this.removeFollowers();
// Do any region-specific logout stuff
this.location.region_logout(this);
this.is_afk = false;
this.date_last_logout = time();
// Cancel all courier items
this.mail_logout();
this.lastActiveCallback('logout');
// cancel all action request replies
this.cancelActionRequestReplies();
for (var i in this.tp_queue){
var item = this.tp_queue[i];
if (item) this.teleportToLocation(item.tsid, item.x, item.y, item.args);
}
if (this.location.isInstance()){
if (this.location.instance_id.substr(0, 19) == 'underground_puzzle_' || this.location.instance_id.substr(0, 19) == 'ticket_to_paradise_'){
var exit = this.instances_get_exit(this.location.instance_id);
this.teleportToLocationDelayed(exit.tsid, exit.x, exit.y);
this.prompts_add_simple("It looks like you ran into some trouble. You've been moved to a safe place.");
}
}
}
// set a flag when we do a street move, so time-critical things like chasing JuJus/Deimaginators don't
// "catch" us while we're waiting for a slow street move to complete
function didStartStreetMove(){
this.did_start_move = true;
/* Update data for hairball achievement */
if (this.buffs_has('hairball_dash')) {
this.buffs_hairball_leave_street();
}
return true;
}
function didEndStreetMove(){
delete this.did_start_move;
return true;
}
function isMovingStreets(){
return this.did_start_move ? true : false;
}
// This is called when a player is moving to another GS and they're about to disconnect from the one they're on
function onGSLogout(){
log.info("ON GS LOGOUT ",this.label);
}
function onClean(){
// this is called on all dev players when you type '/clean' into
// the chat box
this.quests_reset();
this.init();
}
function init_prop(group, key, value, lo, hi){
if (!this[group]){
this[group] = {};
}
if (!this[group][key]){
this[group][key] = this.apiNewProperty(key, value);
}
this[group][key].apiSetLimits(lo, hi);
}
function testTimer(){
log.info("TEST TIMER time="+getTime());
this.apiSetTimer("testTimer",60000);
}
// If the player is on a ladder, returns the ladder. Else returns null.
function isOnLadder() {
var geo = this.location.geometry.layers;
for (var layer in geo) {
//log.info("Checking for ladders in layer "+layer);
var lds = geo[layer].ladders;
for(var lid in lds){
var ld= lds[lid];
if (this.x===ld.x){
if(this.y<ld.y && this.y>(ld.y-ld.h)){
return ld;
}
}
}
}
return null;
}
function isFlying(){
// log.info("dx="+this.dx);
if (this.dy<0) return false;
var pls = this.location.geometry.platforms;
for(var plid in pls){
var pl= pls[plid];
if (this.y===pl.y){
if(this.x>pl.x && this.x<pl.x+pl.w){
return false;
}
}
}
if (this.isOnLadder()) { return false; }
return true;
}
function isInAir(){
if (this.isOnLadder()) { return false; }
var dest = this.location.apiGetPointOnTheClosestPlatformLineBelow(this.x, this.y);
if (Math.abs(this.y - dest.y) < 10) return false;
return true;
}
function sendActivity(msg, from, no_growl, no_activity){
if (no_growl && no_activity) return;
if (from === undefined) from = this;
// Auto-prepend?
var auto_prepend = false;
if (from){
var new_msg = msg.replace(new RegExp('^'+utils.regexp_escape(from.label)+' '), '');
if (new_msg != msg){
msg = new_msg;
auto_prepend = true;
}
}
this.sendMsgOnline({
type: 'activity',
txt: msg,
pc: from ? from.make_hash() : {},
auto_prepend: auto_prepend,
no_growl: no_growl ? true : false,
growl_only: no_activity ? true : false,
});
//log.info('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'+msg);
}
// This function is not necessary anymore, and should/could be refactored out
function sendOnlineActivity(msg){
this.sendActivity(msg);
}
function sendLocationActivity(msg, from, exclusions){
if (from === undefined) from = this;
// Auto-prepend?
var auto_prepend = false;
if (from){
var new_msg = msg.replace(new RegExp('^'+utils.regexp_escape(from.label)+' '), '');
if (new_msg != msg){
msg = new_msg;
auto_prepend = true;
}
}
if (!exclusions) {
exclusions = [];
}
exclusions.push(this.tsid);
//this.sendActivity("Sending location activity while excluding "+exclusions);
this.location.apiSendMsgX({
type: 'activity',
txt: msg,
pc: from ? from.make_hash() : {},
auto_prepend: auto_prepend
}, exclusions);
}
function teleportToLocationVariableDelay(tsid, x, y, time, args){
if (!apiIsPlayerOnline(this.tsid)){
return this.teleportToLocation(tsid, x, y, args);
}
this['!teleport_delayed'] = {
'tsid': tsid,
'x': x,
'y': y,
'args': args
};
this.apiSetTimer('handleDelayedTeleport', time);
}
function teleportToLocationDelayed(tsid, x, y, args){
if (!apiIsPlayerOnline(this.tsid)){
return this.teleportToLocation(tsid, x, y, args);
}
this['!teleport_delayed'] = {
'tsid': tsid,
'x': x,
'y': y,
'args': args
};
this.apiSetTimer('handleDelayedTeleport', 500);
}
function handleDelayedTeleport(){
if (this['!teleport_delayed'] && this['!teleport_delayed'].tsid){
var t = this['!teleport_delayed'];
var ret = this.teleportToLocation(t.tsid, t.x, t.y, t.args);
if (ret['ok']){
delete this['!teleport_delayed'];
}
else{
if (!this['!teleport_delayed'].attempts) this['!teleport_delayed'].attempts = 0;
this['!teleport_delayed'].attempts++;
if (this['!teleport_delayed'].attempts < 10){
this.apiSetTimer('handleDelayedTeleport', 500);
}
else{
delete this['!teleport_delayed'];
}
}
}
}
function teleportToLocation(tsid, x, y, args){
if (!args) args = {};
log.info('Teleporting '+this+' to '+tsid+'.');
if (this.apiPlayerHasLockForCurrentLocation()){
log.info('Tried to teleport '+this+' but the player had a location lock.');
return {
'ok' : 0,
'error' : "player has location lock"
};
}
apiLogAction('TELEPORT', 'pc='+this.tsid, 'location='+tsid, 'x='+x, 'y='+y);
var target = apiFindObject(tsid);
if (!target){
log.error(this+" can't find teleport target: "+tsid);
return {
'ok' : 0,
'error' : "can't find location"
};
}
/*if (this.isLoggingIn){
log.info(this+' is logging in.');
return {
'ok' : 0,
'error' : "Player is logging in."
};
}*/
if (this.isLoggingIn || this['!teleporting'] || this["!local_move_data"]){
if (!this.tp_queue) this.tp_queue = [];
if (this.tp_queue.length > 50){
return {
'ok' : 0,
'error': "Already moving, and teleport queue is too large"
};
}
if (this.tp_queue.length && this.tp_queue[this.tp_queue.length-1].tsid != tsid) this.tp_queue.push({tsid: tsid, x: x, y: y, args: args});
log.info('Tried to teleport '+this+' but they are already moving.');
return {
'ok' : 1,
'was_online' : 1,
'is_queued': 1
};
}
//
// actions we need to take before they can teleport
//
this.trading_cancel_auto();
delete this['!is_firefly_whistlin'];
//
// Get the target x,y
//
var geo = target.get_geo_bounds();
x = (x == 'c') ? Math.round((geo.r - geo.l) / 2) + geo.l : intval(x);
y = (y == 'c') ? Math.round((geo.b - geo.t) / 2) + geo.t : intval(y);
//
// Create an instance?
//
if (tsid != this.location.tsid && target.instances_instance_me() && !args.ignore_instance_me){
var instance_id = target.instances_instance_me();
var max_members = target.instances_get_max_members();
var instance = target.instances_next_instance(instance_id, max_members);
if (!instance){
var instance_options = target.instances_get_instance_options();
var location_options = {};
instance = this.instances_create(instance_id, target.tsid, instance_options, location_options);
target.instances_add_instance(instance_id, instance);
}
else if (!this.instances_has(instance_id)){
this.instances_add(instance_id, instance);
}
//pc.instances_enter(instance_id, connect.x, connect.y);
this.instances.previously[instance_id] = this.get_simple_location();
target = apiFindObject(instance.get_entrance());
}
//
// if they're offline, we just move em
//
if (!apiIsPlayerOnline(this.tsid)){
this.apiMoveOfflinePlayerToAnotherLocation(target,x,y);
//target.apiMoveIn(this, x, y);
return {
'ok' : 1,
'was_online' : 0
};
}
//
// if they're online, the client confirms
//
// Stop following another player
this.stopFollowing();
if (target.getProp('hubid') != this.location.getProp('hubid')){
this.announce_sound('TELEPORT_AWAY_HUB');
}else{
this.announce_sound('TELEPORT_AWAY');
}
//
// moving within the same location?
// (we don't need to send geometry)
//
if (tsid == this.location.tsid && !args.force_location_reload){
this.apiSetXY(x, y);
var rsp = {
type: 'teleport_move_start',
in_location: true,
pc: this.make_hash_with_location()
};
this.apiSendMsg(rsp);
return {
'ok' : 1,
'was_online' : 1
};
}
//
// changing game servers?
//
this['!teleporting'] = true;
log.info("teleportToLocation ",target.tsid,"x=",x,"y=",y);
try{
var d = this.apiCheckIfNeedToMoveToAnotherGSAndGetMoveData(target.tsid, x, y);
if (d){
var target_info = target.get_info();
log.info("teleportToLocation d=",d);
this.apiSendMsg({
type: 'teleport_move_start',
token: d.token,
hostport: d.hostAndPort,
destination: { // the value here is a hash that looks just like the ones sent as connect objects on doors and signposts
street_tsid: target_info.tsid,
label: target_info.name,
swf_file_versioned: target_info.swf_file_versioned,
img_file_versioned: target_info.img_file_versioned,
hub_id: target_info.hub_id
},
loading_info: target.getLoadingInfo(this)
});
this.location.apiMoveOut(this, target);
return {
'ok' : 1,
'was_online' : 1
};
}
}catch(e){
this['!teleporting'] = false;
return {
'ok' : 0,
'error' : "An exception was thrown trying to teleport "+this+"."
};
}
//
// teleporting within the same GS
//
var rsp = {
type: 'teleport_move_start',
location: target.prep_geometry(this),
loading_info: target.getLoadingInfo(this)
};
if (args.change_type){
rsp.change_type = args.change_type;
}
if (args.loading_img){
rsp.loading_info = {
loading_img : args.loading_img,
is_basic : true,
};
}
this.apiSendMsg(rsp);
this["!teleport_move_data"] = {
old_loc: this.location
};
//
// call the player's java code to make all of the start move arrangements
// this call will remove player from its current location, execute various onExit callbacks
// set pc location, x and y to new values, and place the pc into the list of non-active player of the target location
// if pc logout after this step, then after next loging he will be placed into target location
this.apiStartLocationMoveX(target, x, y);
return {
'ok' : 1,
'was_online' : 1
};
}
function teleport_to_player(target){
var loc = target.get_simple_location();
this.teleportToLocation(loc.tsid, loc.x, loc.y);
}
//
// called every minute by the GS, starting when it receives login_start from the client and ending on logout
//
function onTimePlaying(){
// called every 1 minute you spend logged in
//log.info('player "'+this.label+'" has been playing for 1 minute');
this.checkNewGameDay();
if(!this['!in_house_deco_mode'] && !this.location.isParadiseLocation() && ((!this['!meditating'] || this['!meditating'] != 'transcendental'))) {
if (!this.location.is_newxp){
var mood_loss_percentage_multiplier = 1.0;
if (this.buffs_has('rookswort')){
mood_loss_percentage_multiplier = 0.5;
}
var max_mood = Math.min(this.metabolics_get_max_mood(), 2000);
var mood_loss = Math.max(max_mood * (0.0025 * mood_loss_percentage_multiplier), 1);
var mood_percentage = this.metabolics_get_percentage('mood');
if (mood_percentage > 80){
mood_loss = Math.max(max_mood * (0.015 * mood_loss_percentage_multiplier), 4);
if (this.imagination_has_upgrade('periodic_mood_loss_reduced_3')){
mood_loss = Math.max(max_mood * (0.0075 * mood_loss_percentage_multiplier), 4);
}else if (this.imagination_has_upgrade('periodic_mood_loss_reduced_2')){
mood_loss = Math.max(max_mood * (0.010 * mood_loss_percentage_multiplier), 4);
}else if (this.imagination_has_upgrade('periodic_mood_loss_reduced_1')){
mood_loss = Math.max(max_mood * (0.0125 * mood_loss_percentage_multiplier), 4);
}
} else if (mood_percentage >= 50){
mood_loss = Math.max(max_mood * (0.005 * mood_loss_percentage_multiplier), 2);
}
if (!this.has_done_intro){
if (this.metabolics_get_percentage('mood') <= 50) mood_loss = 0;
}
if (mood_loss) this.metabolics_lose_mood(mood_loss, 1);
}
}
this.apiSendMsg({
'type': 'time_passes'
});
if (this.metabolics_get_percentage('energy') <= 10 && !this.buffs_has('walking_dead') && !this.is_dead){
if (this.deaths_today){
this.sendActivity('You are extremely low on energy! Find something to eat.');
} else{
this.sendActivity('You are about to croak! Find something to eat.');
}
}
// Do a callback every 10 minutes
if (!this['!onTimePlayingCounter']) this['!onTimePlayingCounter'] = 0;
if (this['!onTimePlayingCounter'] % 10 == 0){
this.lastActiveCallback('on_playing');
}
this['!onTimePlayingCounter']++;
}
function checkNewGameDay(){
var today = current_day_key();
if (!this.last_online_gameday || this.last_online_gameday.length < 8) this.last_online_gameday = today;
if (today > this.last_online_gameday){
// Croaked?
if (this.is_dead){
this.apiSetTimer('checkNewGameDay', 1000);
return this.resurrect();
}
else if (this.end_esquibeth ||
this.location.isInstance('waterfall_01') ||
this.location.isInstance('waterfall_02') ||
this.location.isInstance('waterfall_03') ||
this.location.isInstance('waterfall_04_wider')) {
this.apiSetTimer('checkNewGameDay', 30*1000);
return;
}
else if (this.location.isInstance('rainbow_run')){
this.apiSetTimer('checkNewGameDay', 30*1000);
}
this.doNewDay();
this.last_online_gameday = today;
}
}
function getTimePlayed(){
return this.counters_get_group_sum('time_played');
}
function doNewDay(){
//
// A new day!!! Reset some things
//
// Re-fill energy
var energy = 0;
var mood = 0;
if (this.has_done_intro){
energy = this.metabolics_set_energy(this.metabolics.energy.top);
mood = this.metabolics_set_mood(this.metabolics.mood.top);
}
apiLogAction('NEW_DAY', 'pc='+this.tsid, 'energy='+energy, 'mood='+mood);
var maxDonationXP = Math.round(this.stats_calc_level_from_xp(this.stats_get_xp()).xp_for_this * 0.1);
var previous_time_played = this.getTimePlayed();
var session_time_played = time() - this.date_last_login;
if (this.isOnline() && (previous_time_played + session_time_played) >= 3600 && this.has_done_intro){
var yesterday_key = this.last_online_gameday;
var rsp = {
"type" : "new_day",
"sound" : "NEWDAY",
"energy_gained" : energy,
"stats_yesterday" : {
energy: intval(this.daily_history_get(yesterday_key, 'energy_consumed')) * -1,
imagination: intval(this.daily_history_get(yesterday_key, 'imagination'))
},
"stats_today" : {
energy: energy,
mood: mood
}
};
var hi_variants_tracker = apiFindObject(config.hi_variants_tracker);
rsp.hi_emote_leaderboard = hi_variants_tracker.get_all_counts();
hi_variants_tracker.calculate_pcs_daily_evasion_record_achieves(this);
var levels = intval(this.daily_history_get(yesterday_key, 'level_up'));
if (levels) rsp.new_level = this.stats_get_level();
var quests = this.daily_history_get(yesterday_key, 'quests_completed');
if (num_keys(quests)){
rsp.complete_quests = [];
for (var i in quests){
var q = this.getQuestInstance(quests[i]);
if (q){
rsp.complete_quests.push({name: q.getTitle(this), tsid: q.class_tsid});
}
}
}
var collections = this.daily_history_get(yesterday_key, 'collections');
if (num_keys(collections)){
rsp.complete_collections = [];
for (var i in collections){
var c = this.achievements_get(collections[i]);
if (c){
rsp.complete_collections.push({name: c.name, tsid: this.achievement_get_trophy(collections[i]).class_tsid});
}
}
}
var skills = this.daily_history_get(yesterday_key, 'skills_learned');
if (num_keys(skills)){
rsp.new_skills = [];
for (var i in skills){
rsp.new_skills.push({name: this.skills_get_name(skills[i]), tsid: skills[i]});
}
}
var achievements = this.daily_history_get(yesterday_key, 'achievements');
if (num_keys(achievements)){
rsp.new_badges = [];
for (var i in achievements){
var a = this.achievements_get(achievements[i]);
if (a){
rsp.new_badges.push({
name: a.name,
tsid: achievements[i],
icon_urls: {
swf: a.url_swf,
180: a.url_img_180,
60: a.url_img_60,
40: a.url_img_40
}
});
}
}
}
this.apiSendMsg(rsp);
this.daily_history_archive(yesterday_key);
this.daily_history_reset();
}
// Quoins
if (this.stats.quoins_today.value >= 100){
this.achievements_increment('coin_count', 'days_maxed');
}
else{
this.achievements_set('coin_count', 'days_maxed', 0);
}
this.stats_set_quoins_today(0);
// fix broken quoin upgrades:
this.stats_set_quoins_max_today(this.imagination_get_quoin_limit());
if (this.buffs_has('crazy_coin_collector')){
this.buffs_remove('crazy_coin_collector');