-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtruco.js
942 lines (734 loc) · 24.9 KB
/
truco.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
var utils = require('utils');
var roundsToWin = 15;
var getCardList = function() {
var cards = [];
var cardNames = ['4', '5', '6', '7', 'Q', 'J', 'K', 'A', '2', '3'];
var suits = ['\u2663', '\u2665', '\u2660', '\u2666'];
for(var c = 0; c < cardNames.length; c++) {
for(var c2 = 0; c2 < suits.length; c2++) {
var name = cardNames[c] + ' ' + suits[c2];
var color = c2 == 0 || c2 == 2 ? '\u00A78' : '\u00A7c';
var card = { name: name, color: color };
switch(name) {
case '4 \u2663': {
card.power = 13;
break;
}
case '7 \u2665': {
card.power = 12;
break;
}
case 'A \u2660': {
card.power = 11;
break;
}
case '7 \u2666': {
card.power = 10;
break;
}
default: {
card.power = c;
}
}
cards.push(card);
}
}
return cards;
}
var cards = getCardList();
var playersCards = {};
var invites = [];
var games = [];
var trucoList = [];
var sixList = [];
var nineList = [];
var twelveList = [];
var generateRandomCards = function() {
var cardsNotInGame = JSON.parse(JSON.stringify(cards));
var randomCards = [];
echo(utils.player('Macintosh'), cards.length);
for(var c = 0; c < 2; c++) {
randomCards[c] = [];
for(var c2 = 0; c2 < 3; c2++) {
var randomNumber = Math.floor(Math.random() * cardsNotInGame.length);
randomCards[c].push(cardsNotInGame[randomNumber]);
cardsNotInGame.splice(randomNumber, 1);
}
}
return randomCards;
}
var echoPlayerCards = function(name, cards) {
var player = utils.player(name);
echo(player, '\u00A7bSuas cartas sao:');
for(var c = 0; c < cards.length; c++) {
var card = cards[c];
player.sendMessage(card.color + ' ' + card.name);
}
}
var invitePlayer = function(player, otherPlayerName) {
if(!otherPlayerName) {
return player.sendMessage('\u00A7eO nome do Marreco esta faltando');
}
var otherPlayer = utils.player(otherPlayerName);
if(!otherPlayer) {
return player.sendMessage('\u00A7eO Marreco ' + otherPlayerName + ' esta Offline');
}
var otherPlayerAlreadyInvited = false;
var otherPlayerAlreadyPlaying = false;
invites.forEach(function(invite) {
if(invite.challenger == otherPlayerName || invite.invited == otherPlayerName) {
otherPlayerAlreadyInvited = true;
}
});
if(otherPlayerAlreadyInvited) {
return player.sendMessage('\u00A7eO Marreco ' + otherPlayerName + ' ja foi Desafiado');
}
games.forEach(function(game) {
if(game.players[0] == otherPlayerName || game.players[1] == otherPlayerName) {
otherPlayerAlreadyPlaying = true;
}
});
if(otherPlayerAlreadyPlaying) {
return player.sendMessage('\u00A7eO Marreco ' + otherPlayerName + ' ja esta Jogando (e provavelmente perdendo)');
}
invites.push({
challenger: player.name,
invited: otherPlayerName
});
player.sendMessage('\u00A7e O Convite foi enviado para o Marreco');
otherPlayer.sendMessage('\u00A7e O Jogador ' + player.name + ' te desafiou para uma partida de Truco');
otherPlayer.sendMessage('\u00A7a Digite truco aceitar para Aceitar o Convite');
otherPlayer.sendMessage('\u00A7c Ou digite truco amarelar para Recusar o Convite');
setTimeout(function() {
removeInvite(otherPlayerName);
}, 20000);
}
var getInvite = function(invited) {
var returnInvite = null;
invites.forEach(function(invite, index) {
if(invite.invited == invited) {
returnInvite = invite;
}
});
return returnInvite;
}
var removeInvite = function(invited) {
invites.forEach(function(invite, index) {
if(invite.invited == invited) {
invites.splice(index, 1);
}
});
}
var removeGame = function(player) {
games.forEach(function(game, index) {
if(games.player[0] == player || games.player[1] == player) {
games.splice(index, 1);
}
});
}
var acceptInvite = function(player) {
var invite = getInvite(player.name);
if(!invite) {
player.sendMessage('\u00A7e O Convite foi expirado');
}
var gameId = Math.random();
games.push({
id: gameId,
players: [invite.challenger, player.name],
atual: 0,
hand: 0,
round: 0,
firstRoundWin: null,
roundValue: 1,
playersRoundValue: [0, 0],
playersValue: [0, 0],
playersCards: [],
sendedCards: [],
});
removeInvite(player);
player.sendMessage('\u00A72 Comecou a Diversao');
utils.player(invite.challenger).sendMessage('\u00A72 Comecou a Diversao');
startRound(player);
}
var updateGame = function(game) {
games.forEach(function(gameFe, index) {
if(gameFe.id == game.id) {
games[index] = game;
}
});
}
var getGame = function(player) {
game = null;
games.forEach(function(gameFe) {
if(gameFe.players.indexOf(player.name) !== -1) {
game = gameFe;
}
});
return game;
}
var startRound = function(player) {
var game = getGame(player);
utils.player(game.players[1]).sendMessage('\u00A73 Voce ' + game.playersValue[1] + ' vs ' + game.playersValue[0] + ' ' + game.players[0]);
utils.player(game.players[0]).sendMessage('\u00A73 Voce ' + game.playersValue[0] + ' vs ' + game.playersValue[1] + ' ' + game.players[1]);
if(game.playersValue[0] >= roundsToWin || game.playersValue[1] >= roundsToWin) {
utils.player(game.players[0]).sendMessage('');
utils.player(game.players[0]).sendMessage('\u00A72-------------------------------');
utils.player(game.players[0]).sendMessage('\u00A72 TEMOS UM VENCEDOR ');
utils.player(game.players[0]).sendMessage('\u00A72-------------------------------');
utils.player(game.players[0]).sendMessage('');
utils.player(game.players[1]).sendMessage('');
utils.player(game.players[1]).sendMessage('\u00A72-------------------------------');
utils.player(game.players[1]).sendMessage('\u00A72 TEMOS UM VENCEDOR ');
utils.player(game.players[1]).sendMessage('\u00A72-------------------------------');
utils.player(game.players[1]).sendMessage('');
if(game.playersValue[0] >= roundsToWin) {
utils.player(game.players[0]).sendMessage('\u00A72' + game.players[0] + ' Venceu de ' + game.players[1]);
utils.player(game.players[1]).sendMessage('\u00A72' + game.players[0] + ' Venceu de ' + game.players[1]);
} else {
utils.player(game.players[0]).sendMessage('\u00A72' + game.players[1] + ' Venceu de ' + game.players[0]);
utils.player(game.players[1]).sendMessage('\u00A72' + game.players[1] + ' Venceu de ' + game.players[0]);
}
utils.player(game.players[0]).sendMessage('');
utils.player(game.players[1]).sendMessage('');
return removeGame(player);
}
var playersCards = generateRandomCards();
game.playersCards = playersCards;
echoPlayerCards(game.players[1], playersCards[1]);
echoPlayerCards(game.players[0], playersCards[0]);
if(game.players[1] == roundsToWin - 1 && game.players[0] != roundsToWin - 1) {
game.ironHand = true;
game.ironHandAccepted = false;
utils.player(game.players[1]).sendMessage('\u00A7a Para aceitar a mao de ferro digite truco aceitarmao');
utils.player(game.players[1]).sendMessage('\u00A7c Para recusar a mao de ferro digite truco recusarmao');
utils.player(game.players[0]).sendMessage('\u00A7b O outro jogador ira ver se aceitara a mao de ferro');
return updateGame(game);
} else if (game.players[0] == roundsToWin - 1 && game.players[1] != roundsToWin - 1) {
game.ironHand = true;
game.ironHandAccepted = false;
utils.player(game.players[0]).sendMessage('\u00A7a Para aceitar a mao de ferro digite truco aceitarmao');
utils.player(game.players[0]).sendMessage('\u00A7c Para recusar a mao de ferro digite truco recusarmao');
utils.player(game.players[1]).sendMessage('\u00A7b O outro jogador ira ver se aceitara a mao de ferro');
return updateGame(game);
} else {
game.ironHand = false;
}
game.atual = game.hand;
utils.player(game.players[game.atual]).sendMessage('\u00A7b Sua vez de Jogar');
if(!game.round) {
utils.player(game.players[game.atual]).sendMessage('\u00A7b Para Jogar uma carta, digite truco jogarcarta [numero da carta (1, 2 ou 3)]');
}
updateGame(game);
}
var sendCard = function(player, cardNumber) {
var game = getGame(player);
if(!game) {
return player.sendMessage('\u00A7e Voce nem esta jogando, marreco!');
}
if(game.players[game.atual] !== player.name) {
return player.sendMessage('\u00A7e Nao e voce que joga, marreco!');
}
var card = game.playersCards[game.atual][cardNumber - 1];
if(!card || card.alreadyUsed) {
return player.sendMessage('\u00A7e Voce esta jogando uma carta que nem existe, marreco!');
}
var waitingPlayerResponse = false;
trucoList.forEach(function(truco) {
if(truco.waiting) {
waitingPlayerResponse = true;
}
});
sixList.forEach(function(six) {
if(six.waiting) {
waitingPlayerResponse = true;
}
});
nineList.forEach(function(nine) {
if(nine.waiting) {
waitingPlayerResponse = true;
}
});
twelveList.forEach(function(twelve) {
if(twelve.waiting) {
waitingPlayerResponse = true;
}
});
if(waitingPlayerResponse) {
return player.sendMessage('\u00A7e Espere a resposta do outro jogador marreco!');
}
if(game.ironHand ? game.ironHandAccepted : false) {
return player.sendMessage('\u00A7e Esperando aceitar a mao de ferro..');
}
game.playersCards[game.atual][cardNumber - 1].alreadyUsed = true;
try {
var anotherPlayer = utils.player(game.players[game.atual === 0 ? 1 : 0]);
player.sendMessage('\u00A77 Voce jogou a carta ' + card.name);
anotherPlayer.sendMessage('\u00A77 ' + player.name + ' jogou a carta ' + card.name);
if(game.sendedCards.length) {
if(card.power > game.sendedCards[0].power) {
player.sendMessage('\u00A7a Voce fez com o ' + card.name);
anotherPlayer.sendMessage('\u00A77 ' + player.name + ' fez com o ' + card.name);
game.playersRoundValue[game.atual]++;
if(game.firstRoundWin === null) {
game.firstRoundWin = game.atual;
}
if(game.playersRoundValue[game.atual] != 2 && game.firstRoundWin !== null) {
player.sendMessage('\u00A7b Torne');
}
}
if(card.power < game.sendedCards[0].power) {
anotherPlayer.sendMessage('\u00A7a Voce fez com o ' + game.sendedCards[0].name);
player.sendMessage('\u00A77 ' + anotherPlayer.name + ' fez com o ' + game.sendedCards[0].name);
game.atual = game.atual == 0 ? 1 : 0;
game.playersRoundValue[game.atual]++;
if(game.firstRoundWin === null) {
game.firstRoundWin = game.atual;
}
if(game.playersRoundValue[game.atual] != 2 && game.firstRoundWin !== null) {
anotherPlayer.sendMessage('\u00A7b Torne');
}
}
if(card.power == game.sendedCards[0].power) {
utils.player(game.players[game.atual === 0 ? 1 : 0]).sendMessage('\u00A76 Rodada Empatada');
if(game.playersRoundValue[0] == 0 && game.playersRoundValue[1] == 0) {
player.sendMessage('\u00A76 Rodada Empatada');
}
game.playersRoundValue[game.atual]++;
game.playersRoundValue[game.players[game.atual === 0 ? 1 : 0]]++;
game.atual = game.atual == 0 ? 1 : 0;
if(game.playersRoundValue[game.atual] != 2 && game.firstRoundWin !== null) {
anotherPlayer.sendMessage('\u00A7b Sua vez de Jogar');
}
}
game.sendedCards = [];
} else {
game.atual = game.atual == 0 ? 1 : 0;
game.sendedCards.push(card);
utils.player(game.players[game.atual]).sendMessage('\u00A7b Sua vez de Jogar');
if(!game.round) {
utils.player(game.players[game.atual]).sendMessage('\u00A7b Para Jogar uma carta, digite truco jogarcarta [numero da carta (1, 2 ou 3)]');
}
}
if(game.playersRoundValue[game.atual] == 2 && game.firstRoundWin !== null) {
if(game.playersRoundValue[0] === 2 && game.playersRoundValue[1] == 2) {
if(game.firstRoundWin === game.players[0]) {
game.atual = 0;
} else {
game.atual = 1;
}
}
player.sendMessage('\u00A73' + game.players[game.atual] + ' ganhou ' + game.roundValue + ' ' + (game.roundValue == 1 ? 'tento' : 'tentos'));
anotherPlayer.sendMessage('\u00A73' + game.players[game.atual] + ' ganhou ' + game.roundValue + ' ' + (game.roundValue == 1 ? 'tento' : 'tentos'));
resetRound(game, player);
return;
}
updateGame(game);
} catch(error) {
player.sendMessage(error.message);
}
}
var resetRound = function(game, player, automaticPlayerIncreaseValue) {
automaticPlayerIncreaseValue = automaticPlayerIncreaseValue === undefined ? true : automaticPlayerIncreaseValue;
if(automaticPlayerIncreaseValue) {
game.playersValue[game.atual] += game.roundValue;
}
game.roundValue = 1;
game.playersRoundValue = [0, 0];
game.firstRoundWin = null;
game.round++;
game.hand = game.hand == 0 ? 1 : 0;
game.atual = game.hand;
game.sendedCards = [];
trucoList.forEach(function(truco, index) {
if(truco.to == player.name || truco.by == player.name) {
trucoList.splice(index, 1);
}
});
sixList.forEach(function(six, index) {
if(six.to == player.name || six.by == player.name) {
sixList.splice(index, 1);
}
});
nineList.forEach(function(nine, index) {
if(nine.to == player.name || nine.by == player.name) {
nineList.splice(index, 1);
}
});
twelveList.forEach(function(twelve, index) {
if(twelve.to == player.name || twelve.by == player.name) {
twelveList.splice(index, 1);
}
});
updateGame(game);
startRound(player);
}
var trucar = function(player) {
var game = getGame(player);
var anotherPlayer = utils.player(game.players[game.atual === 0 ? 1 : 0]);
if(!game) {
return player.sendMessage('\u00A7e Voce nem esta jogando, marreco!');
}
if(game.players[game.atual] !== player.name) {
return player.sendMessage('\u00A7e Nao e voce que joga, marreco!');
}
if(game.roundValue >= 3) {
return player.sendMessage('\u00A7e Ja esta trucado, marreco!');
}
if(game.ironHand) {
player.sendMessage('\u00A7c CARAMBA MARRECO!');
player.sendMessage('\u00A7c CARAMBA MARRECO!');
player.sendMessage('\u00A7c CARAMBA MARRECO!');
player.sendMessage('\u00A7c NÃO SE TRUCA NA MAO DE FERRO!');
game.playersValue[game.atual === 0 ? 1 : 0] += roundsToWin;
resetRound(game, player);
}
trucoList.push({
gameId: game.id,
by: player.name,
to: anotherPlayer.name,
waiting: true
});
player.sendMessage('\u00A7a Voce pediu truco!');
anotherPlayer.sendMessage('\u00A7c Voce foi trucado! Digite truco fugir para fugir');
anotherPlayer.sendMessage('\u00A7a Voce foi trucado! Digite truco aceitartruco para aceitar');
anotherPlayer.sendMessage('\u00A72 Voce foi trucado! Digite truco seis para pedir seis');
}
var askSix = function(player) {
var game = getGame(player);
var anotherPlayer = utils.player(game.players[game.atual === 0 ? 1 : 0]);
if(!game) {
return player.sendMessage('\u00A7e Voce nem esta jogando, marreco!');
}
var truco;
trucoList.forEach(function(trucoFe) {
if(trucoFe.to == player.name) {
truco = trucoFe;
}
});
if(!truco) {
return player.sendMessage('\u00A7e Nao esta trucado, marreco!');
}
if(game.roundValue >= 6) {
return player.sendMessage('\u00A7e Ja esta valendo seis, marreco!');
}
game.roundValue = 3;
truco.waiting = false;
updateGame(game);
var anotherPlayer = utils.player(truco.by);
sixList.push({
gameId: game.id,
by: player.name,
to: anotherPlayer.name,
waiting: true
});
player.sendMessage('\u00A7a Voce pediu seis!');
anotherPlayer.sendMessage('\u00A7c SEEEEEEIS! Digite truco fugir para fugir');
anotherPlayer.sendMessage('\u00A7a SEEEEEEIS! Digite truco aceitarseis para aceitar');
anotherPlayer.sendMessage('\u00A72 SEEEEEEIS! Digite truco nove para pedir nove');
}
var askNine = function(player) {
var game = getGame(player);
var anotherPlayer = utils.player(game.players[game.atual === 0 ? 1 : 0]);
if(!game) {
return player.sendMessage('\u00A7e Voce nem esta jogando, marreco!');
}
var six;
sixList.forEach(function(sixFe) {
if(sixFe.to == player.name) {
six = sixFe;
}
});
if(!six) {
return player.sendMessage('\u00A7e Nao valendo seis, marreco!');
}
if(game.roundValue >= 9) {
return player.sendMessage('\u00A7e Ja esta valendo none, marreco!');
}
game.roundValue = 6;
six.waiting = false;
updateGame(game);
var anotherPlayer = utils.player(six.by);
nineList.push({
gameId: game.id,
by: player.name,
to: anotherPlayer.name,
waiting: true
});
player.sendMessage('\u00A7a Voce pediu nove!');
anotherPlayer.sendMessage('\u00A7c NOOOOOOOOOOOOOOVE! Digite truco fugir para fugir');
anotherPlayer.sendMessage('\u00A7a NOOOOOOOOOOOOOOVE! Digite truco aceitarnove para aceitar');
anotherPlayer.sendMessage('\u00A72 NOOOOOOOOOOOOOOVE! Digite truco doze para pedir doze');
}
var acceptTruco = function(player) {
var game = getGame(player);
var anotherPlayer = utils.player(game.players[game.atual]);
if(!game) {
return player.sendMessage('\u00A7e Voce nem esta jogando, marreco!');
}
var truco;
trucoList.forEach(function(trucoFe) {
if(trucoFe.to == player.name) {
truco = trucoFe;
}
});
if(!truco) {
return player.sendMessage('\u00A7e Nao esta trucado, marreco!');
}
game.roundValue = 3;
truco.waiting = false;
updateGame(game);
player.sendMessage('\u00A7a Voce aceitou o Truco!');
anotherPlayer.sendMessage('\u00A7a ' + player.name + ' aceitou o Truco!');
}
var acceptSix = function(player) {
var game = getGame(player);
var anotherPlayer = utils.player(game.players[game.atual === 0 ? 1 : 0]);
if(!game) {
return player.sendMessage('\u00A7e Voce nem esta jogando, marreco!');
}
var six;
sixList.forEach(function(sixFe) {
if(sixFe.to == player.name) {
six = sixFe;
}
});
if(!six) {
return player.sendMessage('\u00A7e Nao esta pedindo seis, marreco!');
}
game.roundValue = 6;
six.waiting = false;
updateGame(game);
player.sendMessage('\u00A7a Voce aceitou o Seis!');
anotherPlayer.sendMessage('\u00A7a ' + player.name + ' aceitou o Seis!');
}
var acceptNine = function(player) {
var game = getGame(player);
var anotherPlayer = utils.player(game.players[game.atual]);
if(!game) {
return player.sendMessage('\u00A7e Voce nem esta jogando, marreco!');
}
var nine;
nineList.forEach(function(nineFe) {
if(nineFe.to == player.name) {
nine = nineFe;
}
});
if(!nine) {
return player.sendMessage('\u00A7e Nao esta pedindo nove, marreco!');
}
game.roundValue = 9;
nine.waiting = false;
updateGame(game);
player.sendMessage('\u00A7a Voce aceitou o Nove!');
anotherPlayer.sendMessage('\u00A7a ' + player.name + ' aceitou o Nove!');
}
var askTwelve = function(player) {
var game = getGame(player);
var anotherPlayer = utils.player(game.players[game.atual === 0 ? 1 : 0]);
if(!game) {
return player.sendMessage('\u00A7e Voce nem esta jogando, marreco!');
}
var nine;
nineList.forEach(function(nineFe) {
if(nineFe.to == player.name) {
nine = nineFe;
}
});
if(!nine) {
return player.sendMessage('\u00A7e Nao valendo nove, marreco!');
}
if(game.roundValue >= 12) {
return player.sendMessage('\u00A7e Ja esta valendo doze, marreco!');
}
game.roundValue = 9;
nine.waiting = false;
updateGame(game);
var anotherPlayer = utils.player(nine.by);
twelveList.push({
gameId: game.id,
by: player.name,
to: anotherPlayer.name,
waiting: true
});
player.sendMessage('\u00A7a Voce pediu doze!');
anotherPlayer.sendMessage('\u00A7c DOOOOOOOOOOOOOOOZEEEE! Digite truco fugir para fugir');
anotherPlayer.sendMessage('\u00A7a DOOOOOOOOOOOOOOOZEEEE! Digite truco aceitardoze para aceitar');
}
var acceptTwelve = function(player) {
var game = getGame(player);
var anotherPlayer = utils.player(game.players[game.atual === 0 ? 1 : 0]);
if(!game) {
return player.sendMessage('\u00A7e Voce nem esta jogando, marreco!');
}
var twelve;
twelveList.forEach(function(twelveFe) {
if(twelveFe.to == player.name) {
twelve = twelveFe;
}
});
if(!twelve) {
return player.sendMessage('\u00A7e Nao esta pedindo doze, marreco!');
}
game.roundValue = 12;
twelve.waiting = false;
updateGame(game);
player.sendMessage('\u00A7a Voce aceitou o Doze!');
anotherPlayer.sendMessage('\u00A7a ' + player.name + ' aceitou o Doze!');
}
var acceptIronHand = function(player) {
var game = getGame(player);
if(!game.ironHand) {
return player.sendMessage('\u00A7e Nao esta na mao de ferro, marreco!');
}
if(game.ironHandAccepted) {
return player.sendMessage('\u00A7e Voce ja aceitou a mao, marreco!');
}
if(game.players[game.players.indexOf(player.name)] !== roundsToWin - 1) {
return player.sendMessage('\u00A7e Voce nao esta na mao de ferro, marreco!');
}
player.sendMessage('\u00A7b Voce aceitou a mao!');
game.roundValue = 3;
game.atual = game.hand;
utils.player(game.players[game.atual]).sendMessage('\u00A7b Sua vez de Jogar');
if(!game.round) {
utils.player(game.players[game.atual]).sendMessage('\u00A7b Para Jogar uma carta, digite truco jogarcarta [numero da carta (1, 2 ou 3)]');
}
updateGame(game);
}
var refuseHand = function(player) {
var game = getGame(player);
var anotherPlayer = utils.player(game.players[game.players.indexOf(player.name) == 0 ? 1 : 0]);
if(!game.ironHand) {
return player.sendMessage('\u00A7e Nao esta na mao de ferro, marreco!');
}
if(game.ironHandAccepted) {
return player.sendMessage('\u00A7e Voce ja aceitou a mao, marreco!');
}
if(game.players[game.players.indexOf(player.name)] !== roundsToWin - 1) {
return player.sendMessage('\u00A7e Voce nao esta na mao de ferro, marreco!');
}
player.sendMessage('\u00A7b Voce nao aceitou a mao!');
anotherPlayer.sendMessage('\u00A7b O outro jogador nao aceitou a mao!');
game.playersValue[game.players.indexOf(player.name) == 0 ? 1 : 0]++;
resetRound(game, player);
}
var run = function(player) {
var game = getGame(player);
if(!game) {
return player.sendMessage('\u00A7e Voce nem esta jogando, marreco!');
}
utils.player(game.players[0]).sendMessage('\u00A7c O marreco fugiu!');
utils.player(game.players[1]).sendMessage('\u00A7c O marreco fugiu!');
game.playersValue[game.players.indexOf(player.name) == 0 ? 1 : 0] += game.roundValue;
resetRound(game, player, false);
}
var refuseInvite = function(player) {
var invite = getInvite(player.name);
if(!invite) {
player.sendMessage('\u00A7e O Convite foi expirado');
}
removeInvite(player.name);
player.sendMessage('\u00A7e E um amarelao mesmo');
utils.player(invite.challenger).sendMessage('\u00A7e O marreco ' + player.name + ' amarelou');
}
var help = function(player) {
player.sendMessage('');
player.sendMessage('\u00A7e----------------------');
player.sendMessage('\u00A7eComandos do Truco');
player.sendMessage('\u00A7e desafiar [player] - Desafiar Player para Jogar Truco');
player.sendMessage('\u00A7e aceitar - Aceita Partida de Truco');
player.sendMessage('\u00A7e amarelar - Recusa Partida de Truco');
player.sendMessage('\u00A7e jogarcarta [numero da carta] - Joga carta');
player.sendMessage('\u00A7e trucar - Pede truco');
player.sendMessage('\u00A7e fugir - Foge da rodada');
player.sendMessage('\u00A7e aceitartruco - Aceita o Truco');
player.sendMessage('\u00A7e seis - Pede seis');
player.sendMessage('\u00A7e aceitarseis - Aceita o seis');
player.sendMessage('\u00A7e nove - Pede nove');
player.sendMessage('\u00A7e aceitarnove - Aceita o nove');
player.sendMessage('\u00A7e doze - Pede doze');
player.sendMessage('\u00A7e aceitardoze - Aceita o doze');
player.sendMessage('\u00A7e----------------------');
player.sendMessage('');
}
function truco(parameters, player) {
var param = parameters[0];
switch(param) {
case 'desafiar': {
invitePlayer(player, parameters[1]);
break;
}
case 'aceitar': {
acceptInvite(player);
break;
}
case 'amarelar': {
refuseInvite(player);
break;
}
case 'jogarcarta': {
sendCard(player, parameters[1]);
break;
}
case 'trucar': {
trucar(player);
break;
}
case 'fugir': {
run(player);
break;
}
case 'aceitartruco': {
acceptTruco(player);
break;
}
case 'seis': {
askSix(player);
break;
}
case 'aceitarseis': {
acceptSix(player);
break;
}
case 'nove': {
askNine(player);
break;
}
case 'aceitarnove': {
acceptNine(player);
break;
}
case 'doze': {
askTwelve(player);
break;
}
case 'aceitardoze': {
acceptTwelve(player);
break;
}
case 'aceitarmao': {
acceptIronHand(player);
break;
}
case 'recusarmao': {
refuseHand(player);
break;
}
case 'help': {
help(player);
break;
}
default: {
player.sendMessage('\u00A7e Digite algum comando valido ou "truco help" marreco!');
}
}
}
command('truco', truco);
events.playerChat(function(event) {
var words = event.message.split(' ');
if(words[0] == 'truco') {
words.splice(0, 1);
truco(words, event.player);
event.setCancelled(true);
}
});