/
guessing.cs
109 lines (90 loc) · 2.78 KB
/
guessing.cs
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
function GameConnection::guessWord(%this, %guess) {
%guess = strLwr(stripChars(%guess, " !@#$%^&*()_+-={}|[]\\:\";',./<>?~`0123456789"));
%correctAll = strLwr(strReplace($DefaultMinigame.word, " ", ""));
%mg = $DefaultMinigame;
for(%i=0;%i<getFieldCount(%correctAll);%i++) {
%correct = getField(%correctAll, %i);
if(stripos(%guess, %correct) != -1) {
if(!%this.guessed) {
%this.guessed = 1;
messageClient(%this, '', "\c5CORRECT! The word is \c3" @ getAltWords(%mg.word, "/"));
%this.play2D(errorSound);
messageAll('', "\c3" @ %this.name SPC "\c5guessed the word");
%this.score++;
%mg.checkGuessed();
$Pictionary::Guessed++;
if($Pictionary::Guessed/%mg.numMembers > 0.75) {
if(%mg.endingAt - $Sim::Time > 50) {
cancel(%mg.endRoundSched);
%mg.endRoundSched = %mg.schedule(50000, endRound);
%mg.endingAt = $Sim::Time + 50;
}
}
}
return 1;
}
}
return 0;
}
function GameConnection::spamLoop(%this) {
cancel(%this.spamSched);
%this.spamSched = %this.schedule(2000, spamLoop);
%this.msgCount--;
if(%this.msgCount < 0) {
%this.msgCount = 0;
}
}
package PictionaryGuessingPackage {
function serverCmdMessageSent(%client, %msg) {
if(!$Pictionary::CanGuess) {
return parent::serverCmdMessageSent(%client, %msg);
}
if(%client.guessed && !%client.isAdmin) {
%format = '\c7%1\c3%2\c7%3\c6: %4';
if(%client.lastMsg $= %msg) {
return;
}
%client.lastMsg = %msg;
%client.msgCount++;
if(%client.msgCount > 3) {
return;
}
for(%i=0;%i<ClientGroup.getCount();%i++) {
%tmp = ClientGroup.getObject(%i);
if(%tmp.guessed || %tmp.canDraw || %tmp.isAdmin) {
commandToClient(%tmp, 'chatMessage', %tmp, '', '', %format, "\c0[GUESSED]\c7" SPC %client.clanPrefix, %client.name, %client.clanSuffix, "<color:cccccc>" @ %msg);
}
}
return;
}
if(%client.isAdmin && %client.guessWord(%msg)) {
return;
}
if(%client.isAdmin && !%client.guessWord(%msg)) {
return parent::serverCmdMessageSent(%client, %msg);
}
if(!isEventPending(%client.spamSched)) {
%client.spamLoop();
}
%msg = stripMLControlChars(%msg);
if(%client.canDraw) {
//messageClient(%client, '', "\c4[DRAWER] \c3" @ %client.name @ "\c6: " @ %msg);
%format = '\c7%1\c3%2\c7%3\c6: %4';
for(%i=0;%i<ClientGroup.getCount();%i++) {
%tmp = ClientGroup.getObject(%i);
if(%tmp.isAdmin || %tmp.guessed || %tmp == %client) {
// for now
commandToClient(%tmp, 'chatMessage', %tmp, '', '', %format, "\c4[DRAWER]" SPC %client.clanPrefix, %client.name, %client.clanSuffix, %msg);
}
}
return;
}
if(!%client.guessWord(%msg)) {
return parent::serverCmdMessageSent(%client, %msg);
}
}
function serverCmdTeamMessageSent(%client, %msg) {
return;
}
};
activatePackage(PictionaryGuessingPackage);