-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathscripts.js
113 lines (96 loc) · 2.79 KB
/
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
function require(file) {
return sys["import"](file);
}
function User(id)
{
this.id = id;
this.team = null;
this.channel = null;
this.phase = null;
this.rpg = null;
}
require ("utilities.js");
require ("teamChanger.js");
pokeinfo = require ("pokeinfo.js");
require ("printer.js");
commands = require ("commands.js");
SESSION.identifyScriptAs("RPG Script");
//SESSION.registerGlobalFactory(POGlobal);
SESSION.registerUserFactory(User);
//SESSION.registerChannelFactory(POChannel);
/* Function to clear chat - endless text
may lag the server at one point. */
lastMemUpdate = sys.time();
function testClearChat() {
if (parseInt(sys.time(), 10) - lastMemUpdate > 1000) {
sys.clearChat();
lastMemUpdate = parseInt(sys.time(), 10);
}
}
pokeinfo.loadData(); //loads all the data from pokeinfo
poScripts = ({
afterLogIn : function(source) {
var user = SESSION.users(source);
user.print("Abra", "Type /commands to get a list of commands!");
user.print("blank", "");
}
,
beforeBattleMatchup : function() {
sys.stopEvent();
}
,
beforeChatMessage : function(src, msg, chan) {
var user = SESSION.users(src);
user.channel = chan;
/* This variable is used to capture user input if they're in the middle of doing something */
if (user.phase) {
var phase = user.phase;
var res = phase(msg);
if (res) {
/* All went well, stopping message */
sys.stopEvent();
if (user.phase === phase) user.phase = null;
} else {
/* Something went wrong, doing nothing */
}
return;
}
if (msg.substr(0, 1) === "/") {
sys.stopEvent();
testClearChat();
var data, command, tar;
var pos = msg.indexOf(' ');
if (pos !== -1) {
command = msg.substring(1, pos).toLowerCase();
data = msg.substr(pos+1);
tar = sys.id(data);
} else {
command = msg.substr(1).toLowerCase();
}
commands.handleCommand(src, command, data, tar, chan);
}
},
beforeBattleEnded : function(winner,loser,desc,battleid) {
/* Keeps "used" teams, aka teams with HP loss */
if (sys.loggedIn(winner)) {
var uwinner = SESSION.users(winner);
if (uwinner && uwinner.rpg) {
sys.setTeamToBattleTeam(winner, 0, battleid);
uwinner.rpg.team = uwinner.getTeam();
}
}
if (sys.loggedIn(loser)) {
var uloser = SESSION.users(loser);
if (uloser && uloser.rpg) {
sys.setTeamToBattleTeam(loser, 0, battleid);
uloser.rpg.team = uloser.getTeam();
}
}
},
afterChangeTeam : function(src) {
var user = SESSION.users(src);
if (user && user.rpg && user.rpg.team) {
user.rpg.team.syncToUser(user.id);
}
}
});