-
Notifications
You must be signed in to change notification settings - Fork 0
/
old_scripts.js
4856 lines (4488 loc) · 193 KB
/
old_scripts.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
// Don't touch anything here if you don't know what you do.
var noPlayer = '*';
var mafia = new function() {
// Remember to update this if you are updating mafia
// Otherwise mafia game won't get reloaded
this.version = "2011-05-12.1";
var defaultTheme = {
name: "default",
sides: [
{ "side": "mafia", "translation": "Mafia"
},
{ "side": "mafia1", "translation": "French Canadian Mafia"
},
{ "side": "mafia2", "translation": "Italian Mafia"
},
{ "side": "village", "translation": "Good people"
},
{ "side": "werewolf", "translation": "WereWolf"
},
{ "side": "godfather", "translation": "Godfather"
}
],
roles: [{
"role": "villager",
"translation": "Villager",
"side": "village",
"help": "You dont have any special commands during the night! Vote to remove people in the day!",
"actions": {}
}, {
"role": "inspector",
"translation": "Inspector",
"side": "village",
"help": "Type /Inspect [name] to find his/her identity!",
"actions": { "night": {"inspect": {"target": "AnyButSelf", "common": "Self", "priority": 30} } }
}, {
"role": "bodyguard",
"translation": "Bodyguard",
"side": "village",
"help": "Type /Protect [name] to protect someone!",
"actions": { "night": {"protect": {"target": "AnyButSelf", "common": "Role", "priority": 5, "broadcast": "role"} },
"startup": "role-reveal"}
}, {
"role": "mafia",
"translation": "Mafia",
"side": "mafia",
"help": "Type /Kill [name] to kill someone!",
"actions": { "night": {"kill": {"target": "AnyButTeam", "common": "Team", "priority": 11, "broadcast": "team"} },
"startup": "team-reveal"}
}, {
"role": "werewolf",
"translation": "WereWolf",
"side": "werewolf",
"help": "Type /Kill [name] to kill someone!",
"actions": { "night": {"kill": {"target": "AnyButSelf", "common": "Self", "priority": 10} },
"distract": {"mode": "ChangeTarget", "hookermsg": "You tried to distract the Werewolf (what an idea, srsly), you were ravishly devoured, yum !", "msg": "The ~Distracter~ came to you last night! You devoured her instead !"},
"avoidHax": ["kill"] }
}, {
"role": "hooker",
"translation": "Pretty Lady",
"side": "village",
"help": "Type /Distract [name] to distract someone! Vote to remove people in the day!",
"actions": { "night": {"distract": {"target": "AnyButSelf", "common": "Self", "priority": 1} } }
}, {
"role": "mayor",
"translation": "Mayor",
"side": "village",
"help": "You dont have any special commands during the night! Vote to remove people in the day! (your vote counts as 2)",
"actions": { "vote": 2 }
}, {
"role": "spy",
"translation": "Spy",
"side": "village",
"help": "You can find out who is going to get killed next!(no command for this ability) Vote to remove people in the day!",
"actions": { "hax": {"kill": { "revealTeam": 0.33, "revealPlayer": 0.1} } }
}, {
"role": "godfather",
"translation": "Godfather",
"side": "godfather",
"help": "Type /Kill [name] to kill someone! You can kill 2 targets, Type /kill [name2] again to select your second target!",
"actions": { "night": {"kill": {"target": "AnyButSelf", "common": "Self", "priority": 20, "limit": 2} },
"distract": {"mode": "ChangeTarget", "hookermsg": "You tried to seduce the Godfather, you just were killed!", "msg": "The ~Distracter~ came to you last night! You killed her instead!"},
"avoidHax": ["kill"] }
}, {
"role": "vigilante",
"translation": "Vigilante",
"side": "village",
"help": "Type /Kill [name] to kill someone!(dont kill the good people!)",
"actions": { "night": {"kill": {"target": "AnyButSelf", "common": "Self", "priority": 19} } }
}, {
"role": "mafia1",
"translation": "French Canadian Mafia",
"side": "mafia1",
"help": "Type /Kill [name] to kill someone!",
"actions": { "night": {"kill": {"target": "AnyButTeam", "common": "Team", "priority": 12, "broadcast": "team"} },
"startup": "team-reveal"}
}, {
"role": "mafia2",
"translation": "Italian Mafia",
"side": "mafia2",
"help": "Type /Kill [name] to kill someone!",
"actions": { "night": {"kill": {"target": "AnyButTeam", "common": "Team", "priority": 11, "broadcast": "team"} },
"startup": "team-reveal"}
}, {
"role": "conspirator1",
"translation": "French Canadian Conspirator",
"side": "mafia1",
"help": "You dont have any special commands during the night! You are sided French Canadian Mafia. Vote to remove people in the day!",
"actions": { "inspect": {"revealAs": "villager"},
"startup": "team-reveal"}
}, {
"role": "conspirator2",
"translation": "Italian Conspirator",
"side": "mafia2",
"help": "You dont have any special commands during the night! You are sided Italian Mafia. Vote to remove people in the day!",
"actions": { "inspect": {"revealAs": "villager"},
"startup": "team-reveal"}
}, {
"role": "mafiaboss1",
"translation": "Don French Canadian Mafia",
"side": "mafia1",
"help": "Type /Kill [name] to kill someone! You can't be distracted!",
"actions": { "night": {"kill": {"target": "AnyButTeam", "common": "Team", "priority": 12, "broadcast": "team"} },
"distract": {"mode": "ignore"},
"startup": "team-reveal"}
}, {
"role": "mafiaboss2",
"translation": "Don Italian Mafia",
"side": "mafia2",
"help": "Type /Kill [name] to kill someone! You can't be distracted!",
"actions": { "night": {"kill": {"target": "AnyButTeam", "common": "Team", "priority": 11, "broadcast": "team"} },
"distract": {"mode": "ignore"},
"startup": "team-reveal"}
}, {
"role": "samurai",
"translation": "Samurai",
"side": "village",
"help": "Type /Kill [name] during the day phase to kill someone! You will be revealed when you kill, so make wise choices! You are allied with the Good people.",
"actions": { "standby": {"kill": {"target": "AnyButSelf", "msg": "You can kill now using /kill [name] :",
"killmsg": "~Self~ pulls out a sword and strikes it through ~Target~'s chest!"} } }
}, {
"role": "miller",
"translation": "Miller",
"side": "village",
"help": "You dont have any special commands during the night! Vote to remove people in the day! Oh, and insp sees you as Mafia",
"actions": { "inspect": {"revealAs": "mafia"} },
}],
roles1: ["bodyguard", "mafia", "inspector", "werewolf", "hooker", "villager", "mafia",
"villager", "miller", "villager", "mayor"],
roles2: ["bodyguard", "mafia1", "mafia1", "inspector", "hooker", "villager", "mafia2",
"mafia2", "villager", "villager", "villager", "mayor", "villager", "spy", "villager",
"villager", "villager", "mafiaboss1", "villager", "vigilante", "villager", "godfather",
"mafiaboss2", "samurai", "villager", "villager", "werewolf", "mafia1",
"mafia2", "bodyguard"],
villageCantLoseRoles: ["mayor", "vigilante", "samurai"]
};
/* Theme is a small helper to organize themes
* inside the mafia game */
function Theme() {}
Theme.prototype.toString = function() { return "[theme Theme]"; }
Theme.prototype.addSide = function(obj) {
this.sideTranslations[obj.side] = obj.translation;
}
Theme.prototype.addRole = function(obj) {
this.roles[obj.role] = obj;
if ("hax" in obj.actions) {
for(var i in obj.actions.hax) {
var action = i;
if (!(action in this.haxRoles)) {
this.haxRoles[action] = [];
}
this.haxRoles[action].push(obj.role);
}
}
if ("night" in obj.actions) {
for (var i in obj.actions.night) {
var priority = obj.actions.night[i].priority;
var action = i;
var role = obj.role;
this.nightPriority.push({'priority': priority, 'action': action, 'role': role});
}
this.nightPriority.sort(function(a,b) { return a.priority - b.priority });
}
if ("standby" in obj.actions) {
for (var i in obj.actions.standby) {
this.standbyRoles.push(obj.role);
}
}
}
/* Theme Loading and Storing */
Theme.prototype.side = function(side) {
return this.sideTranslations[side];
}
Theme.prototype.getHaxRolesFor = function(command) {
if (command in this.haxRoles) {
return this.haxRoles[command];
}
return [];
}
this.loadTheme = function(plain_theme) {
var theme = new Theme();
theme.sideTranslations = {};
theme.roles = {};
theme.nightPriority = [];
theme.standbyRoles = [];
theme.haxRoles = {};
// Init from the theme
for (var i in plain_theme.sides) {
theme.addSide(plain_theme.sides[i]);
}
for (var i in plain_theme.roles) {
theme.addRole(plain_theme.roles[i]);
}
theme.roles1 = plain_theme.roles1;
theme.roles2 = plain_theme.roles2;
theme.villageCantLoseRoles = plain_theme.villageCantLoseRoles;
theme.name = plain_theme.name;
this.themes[theme.name.toLowerCase()] = theme;
}
this.loadWebTheme = function(url) {
if (typeof sys != 'object') return;
sys.webCall(url, 'SESSION.global().mafia.addWebTheme(resp)');
}
this.addWebTheme = function(resp) {
try {
plain_theme = JSON.parse(resp);
mafia.loadTheme(plain_theme);
} catch (err) {
sys.sendAll("+MafiaBot: Couldn't download Internet theme.", mafiachan);
return;
}
}
this.themes = {};
this.loadTheme(defaultTheme);
this.isInGame = function(player) {
if (mafia.state == "entry") {
return this.signups.indexOf(player) != -1;
}
return player in this.players;
};
this.hasCommand = function(name, command, state) {
var player = this.players[name];
return (state in player.role.actions && command in player.role.actions[state]);
};
this.correctCase = function(string) {
var lstring = string.toLowerCase();
for (var x in this.players) {
if (x.toLowerCase() == lstring)
return this.players[x].name;
}
return noPlayer;
};
this.clearVariables = function() {
/* hash : playername => playerstruct */
this.players = {};
this.signups = [];
this.state = "blank";
this.ticks = 0;
this.votes = {};
this.voteCount = 0;
this.ips = [];
this.resetTargets();
};
this.lastAdvertise = 0;
this.resetTargets = function() {
this.teamTargets = {};
this.roleTargets = {};
for (var p in this.players) {
this.players[p].targets = {};
this.players[p].dayKill = undefined;
this.players[p].guarded = undefined;
}
};
this.clearVariables();
/* callback for /start */
this.startGame = function(src, commandData) {
if (mafia.state != "blank") {
sys.sendMessage(src, "±Game: A game is going on. Wait until it's finished to start another one", mafiachan);
sys.sendMessage(src, "±Game: You can join the game by typing /join !", mafiachan);
return;
}
mafia.theme = mafia.themes["default"];
if (commandData != noPlayer) {
var themeName = commandData.toLowerCase();
if (themeName in mafia.themes) {
mafia.theme = mafia.themes[themeName];
} else {
sys.sendMessage(src, "±Game: No such theme!", mafiachan);
return;
}
}
sys.sendAll("", mafiachan);
sys.sendAll("*** ************************************************************************************", mafiachan);
sys.sendAll("±Game: " + sys.name(src) + " started a game with theme "+mafia.theme.name+"!", mafiachan);
sys.sendAll("±Game: Type /Join to enter the game!", mafiachan);
sys.sendAll("*** ************************************************************************************", mafiachan);
sys.sendAll("", mafiachan);
if (sys.playersOfChannel(mafiachan).length < 20) {
var time = parseInt(sys.time());
if (false && time > mafia.lastAdvertise + 60*15) {
mafia.lastAdvertise = time;
sys.sendAll("", 0);
sys.sendAll("*** ************************************************************************************", 0);
sys.sendAll("±Game: " + sys.name(src) + " started a mafia game!", 0);
sys.sendAll("±Game: Go in the #Mafia Channel and type /Join to enter the game!", 0);
sys.sendAll("*** ************************************************************************************", 0);
sys.sendAll("", 0);
}
}
mafia.clearVariables();
mafia.state = "entry";
mafia.ticks = 60;
};
/* callback for /end */
this.endGame = function(src) {
if (mafia.state == "blank") {
sys.sendMessage(src, "±Game: No game is going on.",mafiachan);
return;
}
sys.sendAll("*** ************************************************************************************", mafiachan);
sys.sendAll("±Game: " + sys.name(src) + " has stopped the game!", mafiachan);
sys.sendAll("*** ************************************************************************************", mafiachan);
sys.sendAll("", mafiachan);
mafia.clearVariables();
};
/* called every second */
this.tickDown = function() {
if (this.ticks <= 0) {
return;
}
this.ticks = this.ticks - 1;
if (this.ticks == 0)
this.callHandler(this.state);
else {
if (this.ticks == 30 && this.state == "entry") {
sys.sendAll("", mafiachan);
sys.sendAll("±Game: Hurry up, you only have "+this.ticks+" seconds more to join!", mafiachan);
sys.sendAll("", mafiachan);
}
}
};
this.sendPlayer = function(player, message) {
var id = sys.id(player);
if (id == undefined)
return;
sys.sendMessage(id, message, mafiachan);
};
this.getPlayersForTeam = function(side) {
var team = [];
for (var p in this.players) {
var player = this.players[p];
if (player.role.side == side) {
team.push(player.name);
}
}
return team;
};
this.getPlayersForTeamS = function(side) {
return mafia.getPlayersForTeam(side).join(", ");
};
this.getPlayersForRole = function(role) {
var team = []
for (var p in this.players) {
var player = this.players[p];
if (player.role.role == role) {
team.push(player.name);
}
}
return team;
};
this.getPlayersForRoleS = function(role) {
return mafia.getPlayersForRole(role).join(", ");
};
this.getCurrentRoles = function() {
var list = []
for (var p in this.players) {
list.push(this.players[p].role.translation);
}
/* Sorting to not give out the order of the roles per player */
return list.sort().join(", ");
};
this.getCurrentPlayers = function() {
var list = [];
for (var p in this.players) {
list.push(this.players[p].name);
}
return list.sort().join(", ");
}
this.player = function(role) {
for (var p in this.players) {
if (mafia.players[p].role.role == role) //Checks sequentially all roles to see if this is the good one
return x;
}
return noPlayer;
};
this.removePlayer = function(player) {
//sys.sendAll("removing player " + player.name, mafiachan);
for (var action in player.role.actions.night) {
var targetMode = player.role.actions.night[action].target;
var team = this.getPlayersForTeam(player.role.side);
var role = this.getPlayersForRole(player.role.role);
if ((targetMode == 'AnyButSelf' || targetMode == 'Any')
|| (targetMode == 'AnyButTeam' && team.length == 1)
|| (targetMode == 'AnyButRole' && role.length == 1)) {
this.removeTarget(player, action);
}
}
delete this.players[player.name];
};
this.kill = function(player) {
sys.sendAll("±Kill: " + player.name + " (" + player.role.translation + ") died!", mafiachan);
this.removePlayer(player);
};
this.removeTargets = function(player) {
for (var action in player.role.actions.night) {
this.removeTarget(player, action);
}
};
this.removeTarget = function(player, action) {
var targetMode = player.role.actions.night[action].common;
if (targetMode == 'Self') {
player.targets[action] = [];
} else if (targetMode == 'Team') {
if (!(player.role.side in this.teamTargets)) {
this.teamTargets[player.role.side] = {};
}
this.teamTargets[player.role.side][action] = [];
} else if (targetMode == 'Role') {
if (!(player.role.role in this.roleTargets)) {
this.roleTargets[player.role.role] = {};
}
this.roleTargets[player.role.role][action] = [];
}
};
this.removeTarget2 = function(player, target) {
// TODO: implement
};
this.getTargetsFor = function(player, action) {
var commonTarget = player.role.actions.night[action].common;
if (commonTarget == 'Self') {
if (!(action in player.targets)) {
player.targets[action] = [];
}
return player.targets[action];
} else if (commonTarget == 'Team') {
if (!(player.role.side in this.teamTargets)) {
this.teamTargets[player.role.side] = {};
}
if (!(action in this.teamTargets[player.role.side])) {
this.teamTargets[player.role.side][action]= [];
}
return this.teamTargets[player.role.side][action];
} else if (commonTarget == 'Role') {
if (!(player.role.role in this.roleTargets)) {
this.roleTargets[player.role.role] = {};
}
if (!(action in this.roleTargets[player.role.role])) {
this.roleTargets[player.role.role][action]= [];
}
return this.roleTargets[player.role.role][action];
}
};
this.setTarget = function(player, target, action) {
var commonTarget = player.role.actions.night[action].common;
var limit = 1;
if (player.role.actions.night[action].limit !== undefined) {
limit = player.role.actions.night[action].limit;
}
var list;
if (commonTarget == 'Self') {
if (!(action in player.targets)) {
player.targets[action] = [];
}
list = player.targets[action];
} else if (commonTarget == 'Team') {
if (!(player.role.side in this.teamTargets)) {
this.teamTargets[player.role.side] = {};
}
if (!(action in this.teamTargets[player.role.side])) {
this.teamTargets[player.role.side][action]= [];
}
list = this.teamTargets[player.role.side][action];
} else if (commonTarget == 'Role') {
if (!(player.role.role in this.roleTargets)) {
this.roleTargets[player.role.role] = {};
}
if (!(action in this.roleTargets[player.role.role])) {
this.roleTargets[player.role.role][action]= [];
}
list = this.roleTargets[player.role.role][action];
}
if (list.indexOf(target.name) == -1) {
list.push(target.name);
if (list.length > limit) {
list.splice(0, 1);
}
}
if (this.ticks > 0 && limit > 1)
this.sendPlayer(player.name, "±Game: Your target(s) are " + list.join(', ') + "!");
};
this.testWin = function() {
outer:
for (var p in mafia.players) {
var winSide = mafia.players[p].role.side;
if (winSide != 'village') {
for (var i in mafia.villageCantLoseRoles) {
if (mafia.player(mafia.villageCantLoseRoles[i]) != noPlayer)
// baddies shouldn't win if vigi, mayor or samurai is alive
continue outer;
}
}
var players = [];
var goodPeople = [];
for (var x in mafia.players) {
if (mafia.players[x].role.side == winSide) {
players.push(x);
} else if (winSide == 'village') {
// if winSide = villy all people must be good people
continue outer;
} else if (mafia.players[x].role.side == 'village') {
goodPeople.push(x);
} else {
// some other baddie team alive
return false;
}
}
if (players.length >= goodPeople.length) {
sys.sendAll("±Game: The " + mafia.theme.side(winSide) + " (" + players.join(', ') + ") wins!", mafiachan);
if (goodPeople.length > 0) {
sys.sendAll("±Game: The " + mafia.theme.side('village') + " (" + goodPeople.join(', ') + ") lose!", mafiachan);
}
sys.sendAll("*** ************************************************************************************", mafiachan);
mafia.clearVariables();
return true;
}
}
return false;
};
this.handlers = {
entry: function () {
sys.sendAll("*** ************************************************************************************", mafiachan);
sys.sendAll("Times Up! :", mafiachan);
if (mafia.signups.length < 5) {
sys.sendAll("Well, Not Enough Players! :", mafiachan);
sys.sendAll("You need at least 5 players to join (Current; " + mafia.signups.length + ").", mafiachan);
sys.sendAll("*** ************************************************************************************", mafiachan);
mafia.clearVariables();
return;
}
/* Creating the roles list */
if (mafia.signups.length <= mafia.theme.roles1.length) {
var srcArray = mafia.theme.roles1.slice(0, mafia.signups.length);
} else {
var srcArray = mafia.theme.roles2.slice(0, mafia.signups.length);
}
srcArray = shuffle(srcArray);
for (var i = 0; i < srcArray.length; ++i) {
mafia.players[mafia.signups[i]] = {'name': mafia.signups[i], 'role': mafia.theme.roles[srcArray[i]], 'targets': {}};
}
sys.sendAll("The Roles have been Decided! :", mafiachan);
for (var p in mafia.players) {
var player = mafia.players[p];
var role = player.role;
mafia.sendPlayer(player.name, "±Game: You are a " + role.translation + "!");
mafia.sendPlayer(player.name, "±Game: " + role.help);
if (role.actions.startup == "team-reveal") {
mafia.sendPlayer(player.name, "±Game: Your team is " + mafia.getPlayersForTeamS(role.side) + ".");
}
if (role.actions.startup == "role-reveal") {
mafia.sendPlayer(player.name, "±Game: People with your role are " + mafia.getPlayersForRoleS(role.role) + ".");
}
if (typeof role.actions.startup == "object" && role.actions.startup.revealRole) {
mafia.sendPlayer(player.name, "±Game: The " + mafia.theme.roles[role.actions.startup.revealRole].translation + " is " + mafia.getPlayersForRoleS(player.role.actions.startup.revealRole) + "!");
}
}
sys.sendAll("Current Roles: " + mafia.getCurrentRoles() + ".", mafiachan);
sys.sendAll("Current Players: " + mafia.getCurrentPlayers() + ".", mafiachan);
sys.sendAll("Time: Night", mafiachan);
sys.sendAll("Make your moves, you only have 30 seconds! :", mafiachan);
sys.sendAll("*** ************************************************************************************", mafiachan);
mafia.ticks = 30;
mafia.state = "night";
mafia.resetTargets();
}
,
night : function() {
sys.sendAll("*** ************************************************************************************", mafiachan);
sys.sendAll("Times Up! :", mafiachan);
var nightkill = false;
var getTeam = function(role, commonTarget) {
var team = [];
if (commonTarget == 'Role') {
team = mafia.getPlayersForRole(role.role);
} else if (commonTarget == 'Team') {
team = mafia.getPlayersForTeam(role.side);
}
return team;
}
for (var i in mafia.theme.nightPriority) {
var o = mafia.theme.nightPriority[i];
var names = mafia.getPlayersForRole(o.role);
for (var j = 0; j < names.length; ++j) {
if (!mafia.isInGame(names[j])) continue;
var player = mafia.players[names[j]];
//sys.sendAll(player.name + " is " + o.role + ", action is " +o.action , mafiachan);
var targets = mafia.getTargetsFor(player, o.action);
//sys.sendAll("targets are " + targets, mafiachan);
if (o.action == "distract") {
if (targets.length == 0) continue;
var target = targets[0];
if (!mafia.isInGame(target)) continue;
target = mafia.players[target];
var distractMode = target.role.actions.distract;
if (distractMode === undefined) {
mafia.sendPlayer(target.name, "±Game: The " + player.role.translation +" came to you last night! You were too busy being distracted!");
mafia.removeTargets(target);
/* warn role / teammates */
if ("night" in target.role.actions) {
for (var action in target.role.actions.night) {
var team = getTeam(target.role, target.role.actions.night[action].common);
for (var x in team) {
if (team[x] != target.name) {
mafia.sendPlayer(team[x], "±Game: Your teammate was too busy with the " + player.role.translation + " during the night, you decided not to " + action + " anyone during the night!");
}
}
}
}
} else if (distractMode.mode == "ChangeTarget") {
mafia.sendPlayer(player.name, "±Game: " + distractMode.hookermsg);
mafia.sendPlayer(target.name, "±Game: " + distractMode.msg.replace("~Distracter~", player.role.translation));
mafia.kill(player);
nightkill = true;
mafia.removeTargets(target);
} else if (distractMode.mode == "ignore") {
mafia.sendPlayer(target.name, "±Game: " + distractMode.msg);
}
}
else if (o.action == "protect") {
if (targets.length == 0) continue;
var target = targets[0];
if (!mafia.isInGame(target)) continue;
target = mafia.players[target];
target.guarded = true;
}
else if (o.action == "inspect") {
if (targets.length == 0) continue;
var target = targets[0];
if (!mafia.isInGame(target)) continue;
target = mafia.players[target];
var inspectMode = target.role.actions.inspect;
if (inspectMode === undefined) {
mafia.sendPlayer(player.name, "±Info: " + target.name + " is the " + target.role.translation + "!!");
} else if (inspectMode.revealAs !== undefined) {
mafia.sendPlayer(player.name, "±Info: " + target.name + " is the " + mafia.theme.roles[inspectMode.revealAs].translation + "!!");
}
}
else if (o.action == "kill") {
for (var t in targets) {
var target = targets[t];
if (!mafia.isInGame(target)) continue;
target = mafia.players[target];
if (target.guarded) {
mafia.sendPlayer(player.name, "±Game: Your target (" + target.name + ") was protected!");
} else {
mafia.sendPlayer(target.name, "±Game: You were killed during the night!");
mafia.kill(target);
nightkill = true;
}
}
}
}
}
if (!nightkill) {
sys.sendAll("No one died! :", mafiachan);
}
if (mafia.testWin()) {
return;
}
mafia.ticks = 30;
if (mafia.players.length >= 15) {
mafia.ticks = 40;
} else if (mafia.players.length <= 4) {
mafia.ticks = 15;
}
sys.sendAll("*** ************************************************************************************", mafiachan);
sys.sendAll("Current Roles: " + mafia.getCurrentRoles() + ".", mafiachan);
sys.sendAll("Current Players: " + mafia.getCurrentPlayers() + ".", mafiachan);
sys.sendAll("Time: Day", mafiachan);
sys.sendAll("You have " + mafia.ticks + " seconds to debate who are the bad guys! :", mafiachan);
for (var role in mafia.theme.standbyRoles) {
var names = mafia.getPlayersForRole(mafia.theme.standbyRoles[role]);
for (var j = 0; j < names.length; ++j) {
for (var k in mafia.players[names[j]].role.actions.standby) {
mafia.sendPlayer(names[j], mafia.players[names[j]].role.actions.standby[k].msg);
}
}
}
sys.sendAll("*** ************************************************************************************", mafiachan);
mafia.state = "standby";
}
,
standby : function() {
mafia.ticks = 30;
sys.sendAll("*** ************************************************************************************", mafiachan);
sys.sendAll("Current Roles: " + mafia.getCurrentRoles() + ".", mafiachan);
sys.sendAll("Current Players: " + mafia.getCurrentPlayers() + ".", mafiachan);
sys.sendAll("Time: Day", mafiachan);
sys.sendAll("It's time to vote someone off, type /Vote [name], you only have " + mafia.ticks + " seconds! :", mafiachan);
sys.sendAll("*** ************************************************************************************", mafiachan);
mafia.state = "day";
mafia.votes = {};
mafia.voteCount = 0;
}
,
day : function() {
sys.sendAll("*** ************************************************************************************", mafiachan);
sys.sendAll("Times Up! :", mafiachan);
var voted = {};
for (var pname in mafia.votes) {
var player = mafia.players[pname];
var target = mafia.votes[pname];
if (!(target in voted)) {
voted[target] = 0;
}
if (player.role.actions.vote !== undefined) {
voted[target] += player.role.actions.vote;
} else {
voted[target] += 1;
}
}
var tie = true;
var maxi = 0;
var downed = noPlayer;
for (var x in voted) {
if (voted[x] == maxi) {
tie = true;
} else if (voted[x] > maxi) {
tie = false;
maxi = voted[x];
downed = x;
}
}
if (tie) {
sys.sendAll("No one was voted off! :", mafiachan);
sys.sendAll("*** ************************************************************************************", mafiachan);
} else {
sys.sendAll("±Game: " + downed + " (" + mafia.players[downed].role.translation + ") was removed from the game!", mafiachan);
mafia.removePlayer(mafia.players[downed]);
if (mafia.testWin())
return;
}
sys.sendAll("Current Roles: " + mafia.getCurrentRoles() + ".", mafiachan);
sys.sendAll("Current Players: " + mafia.getCurrentPlayers() + ".", mafiachan);
sys.sendAll("Time: Night", mafiachan);
sys.sendAll("Make your moves, you only have 30 seconds! :", mafiachan);
sys.sendAll("*** ************************************************************************************", mafiachan);
mafia.ticks = 30;
mafia.state = "night";
mafia.resetTargets();
}
};
this.callHandler = function(state) {
if (state in this.handlers)
this.handlers[state]();
};
this.showCommands = function(src) {
sys.sendMessage(src, "", mafiachan);
sys.sendMessage(src, "Server Commands:", mafiachan);
for (x in mafia.commands["user"]) {
sys.sendMessage(src, "/" + cap(x) + " - " + mafia.commands["user"][x][1], mafiachan);
}
if (sys.auth(src) > 0) {
sys.sendMessage(src, "Authority Commands:", mafiachan);
for (x in mafia.commands["auth"]) {
sys.sendMessage(src, "/" + cap(x) + " - " + mafia.commands["auth"][x][1], mafiachan);
}
}
sys.sendMessage(src, "", mafiachan);
};
this.showHelp = function(src) {
var help = [
"*** *********************************************************************** ***",
"±Game: The objective in this game on how to win depends on the role you are given.",
"*** *********************************************************************** ***",
"±Role: Mafia",
"±Win: Eliminate the WereWolf and the Good People!",
"*** *********************************************************************** ***",
"±Role: WereWolf",
"±Win: Eliminate everyone else in the game!",
"*** *********************************************************************** ***",
"±Role: Good people (Inspector, Bodyguard, Pretty Lady, Villager, Mayor, Spy, Vigilante, Samurai)",
"±Win: Eliminate the WereWolf, Mafia (French and Italian if exists) and the Godfather!",
"*** *********************************************************************** ***",
"±Role: French Canadian Mafia, Don French Canadian Mafia",
"±Win: Eliminate the Italian Mafia, Godfather and the Good People!",
"*** *********************************************************************** ***",
"±Role: Italian Mafia, Don Italian Mafia",
"±Win: Eliminate the French Canadian Mafia, Godfather and the Good People!",
"*** *********************************************************************** ***",
"±More: Type /roles for more info on the characters in the game!",
"±More: Type /rules to see some rules you should follow during a game!",
"*** *********************************************************************** ***",
""
];
dump(src, help);
};
this.showRoles = function(src) {
var roles = [
"*** *********************************************************************** ***",
"±Role: Villager",
"±Ability: The Villager has no command during night time. They can only vote during the day!",
"±Game: 6-30 Players",
"*** *********************************************************************** ***",
"±Role: Inspector",
"±Ability: The Inspector can find out the identity of a player during the Night. ",
"±Game: 5-30 Players",
"*** *********************************************************************** ***",
"±Role: Bodyguard",
"±Ability: The Bodyguard can protect one person during the night from getting killed, but the bodyguard cant protect itself.",
"±Game: 5-30 Players",
"*** *********************************************************************** ***",
"±Role: Pretty Lady",
"±Ability: The Pretty Lady can distract people during the night thus cancelling their move, unless it's the WereWolf.",
"±Game: 5-30 Players",
"*** *********************************************************************** ***",
"±Role: Samurai",
"±Ability: The Samurai can kill people during the standby phase, but he will be revealed when doing so.",
"±Game: 25-30 Players",
"*** *********************************************************************** ***",
"±Role: Mafia",
"±Ability: The Mafia is a group of 2 people. They get one kill each night. They strike after the WereWolf.",
"±Game: 5-12 Players",
"*** *********************************************************************** ***",
"±Role: WereWolf",
"±Ability: The WereWolf is solo. To win it has to kill everyone else in the game. The Werewolf strikes first.",
"±Game: 5-12 27-30 Players",
"*** *********************************************************************** ***",
"±Role: Italian Mafia",
"±Ability: The Italian Mafia is a group of 2-3 people. They get one kill each night. They strike before the French Canadian Mafia.",
"±Game: 12-30 Players",
"*** *********************************************************************** ***",
"±Role: Italian Conspirator",
"±Ability: Italian Conspirator is sided with Italian Mafia, but doesn't have any special commands. Shows up as a Villager to inspector.",
"±Game: -",
"*** *********************************************************************** ***",
"±Role: Don Italian Mafia",
"±Ability: Don Italian Mafia is sided with Italian Mafia. He kills with Italian mafia each night. He can't be distracted.",
"±Game: 24-30 Players",
"*** *********************************************************************** ***",
"±Role: French Canadian Mafia",
"±Ability: The French Canadian Mafia is a group of 2-4 people. They get one kill each night. They strike after the Italian Mafia.",
"±Game: 12-30 Players",
"*** *********************************************************************** ***",
"±Role: French Canadian Conspirator",
"±Ability: French Canadian Conspirator is sided with French Canadian Mafia, but doesn't have any special commands. Shows up as a Villager to inspector.",
"±Game: -",
"*** *********************************************************************** ***",
"±Role: Don French Canadian Mafia",
"±Ability: Don French Canadian Mafia is sided with French Canadian Mafia. He kills with French Canadian mafia each night. He can't be distracted.",
"±Game: 18-30 Players",
"*** *********************************************************************** ***",
"±Role: Mayor",
"±Ability: The Mayor has no command during the night but his/her vote counts as 2.",
"±Game: 10-30 Players",
"*** *********************************************************************** ***",
"±Role: Spy",
"±Ability: The Spy has 33% chance of finding out who is going to get killed by The Italian or French Canadian Mafia during the night. And 10% chance to find out who is the killer!",
"±Game: 13-30 Players",
"*** *********************************************************************** ***",
"±Role: Vigilante",
"±Ability: The Vigilante can kill a person during the night! He/she strikes after The French Canadian and Italian Mafia.",
"±Game: 20-30 Players",
"*** *********************************************************************** ***",
"±Role: Godfather",
"±Ability: The Godfather can kill 2 people during the night! He/she strikes Last!",
"±Game: 22-30 Players",
"*** *********************************************************************** ***",
""
];
dump(src, roles);
};
this.showRules = function(src) {
var rules = [
"",
" Server Rules: ",
"±Rule: No Spamming / flooding ",
"±Rule: No insulting- especially not auth. ",
"±Rule: No asking for auth.",
"±Rule: No trolling.",
"",
" Game Rules: ",
"±Rule: Do not quote any of the Bots.",
"±Rule: Do not quit the game before you are dead.",
"±Rule: Do not talk once your dead or voted off. ",
"±Rule: Do not use a hard to type name.",
"±Rule: Do not group together to ruin the game",
"±Rule: DO NOT REVEAL YOUR PARTNER IF YOU ARE MAFIA",
"",
"±Game: Disobey them and you will be banned/muted/kicked according to the mod/admin's wish!",
""
];
dump(src, rules);
};
this.showThemes = function(src) {
var l = [];
for (var t in mafia.themes) {
l.push(mafia.themes[t].name);
}
var text = ["+MafiaBot: Installed themes are: " + l.join(", ")];
dump(src, text);
};
this.commands = {
user: {
commands : [this.showCommands, "To see the various commands."],
start: [this.startGame, "Starts a Game of Mafia."],
help: [this.showHelp, "For info on how to win in a game."],
roles: [this.showRoles, "For info on all the Roles in the game."],
rules: [this.showRules, "To see the Rules for the Game/Server."],
themes: [this.showThemes, "To view installed themes."]
},
auth: {
end: [this.endGame, "To cancel a Mafia game!"],
}
};
this.handleCommand = function(src, message) {
var command;
var commandData = '*';
var pos = message.indexOf(' ');
if (pos != -1) {
command = message.substring(0, pos).toLowerCase();
commandData = message.substr(pos+1);
} else {
command = message.substr(0).toLowerCase();
}
if (command in this.commands["user"]) {
this.commands["user"][command][0](src, commandData);
return;
}
if (this.state == "entry") {
if (command == "join") {
if (this.isInGame(sys.name(src))) {
sys.sendMessage(src, "±Game: You already joined!", mafiachan);
return;
}
if (this.ips.indexOf(sys.ip(src))!=-1) {
sys.sendMessage(src, "±Game: This IP is already in list. You cannot register two times!", mafiachan);
return;
}
if (this.signups.length >= 30) {
sys.sendMessage(src, "±Game: There can't be more than 30 players!", mafiachan);
return;
}
var name = sys.name(src);
for (x in name) {
var code = name.charCodeAt(x);
if (name[x] != ' ' && name[x] != '.' && (code < 'a'.charCodeAt(0) || code > 'z'.charCodeAt(0))
&& (code < 'A'.charCodeAt(0) || code > 'Z'.charCodeAt(0)) && name[x] != '-' && name[x] != '_' && name[x] !='<' && name[x] != '>' && (code < '0'.charCodeAt(0) || code > '9'.charCodeAt(0)))
{