notherbase-fs 3.2.12 → 3.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/models/user.js +0 -93
- package/package.json +1 -1
- package/public/js/chat-box.js +13 -0
- package/views/head.ejs +0 -1
package/models/user.js
CHANGED
|
@@ -101,98 +101,5 @@ export default class User extends Spirit {
|
|
|
101
101
|
this.email = email;
|
|
102
102
|
this.id = id;
|
|
103
103
|
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Attempts to offset the user's inventory of a certain item.
|
|
107
|
-
* @param {String} name The item's name.
|
|
108
|
-
* @param {Number} offset The amount to offset by.
|
|
109
|
-
* @returns True if successful.
|
|
110
|
-
*/
|
|
111
|
-
offsetItem = async (name, offset) => {
|
|
112
|
-
let item = await Item.recallOne(name);
|
|
113
|
-
|
|
114
|
-
if (!item) return false;
|
|
115
|
-
|
|
116
|
-
let inv = this.memory.data.inventory;
|
|
117
|
-
|
|
118
|
-
for (let j = 0; j < inv.length; j++) {
|
|
119
|
-
if (inv[j].name === name) {
|
|
120
|
-
if (inv[j].amount >= -Math.floor(offset)) {
|
|
121
|
-
inv[j].amount += Math.floor(offset);
|
|
122
|
-
|
|
123
|
-
if (inv[j].amount === 0) {
|
|
124
|
-
let empty = inv[j];
|
|
125
|
-
|
|
126
|
-
inv.splice(j, 1);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
this.memory._lastUpdate = Date.now();
|
|
130
|
-
await this.commit();
|
|
131
|
-
return true;
|
|
132
|
-
}
|
|
133
|
-
else return false;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (offset > 0) {
|
|
138
|
-
inv.push({
|
|
139
|
-
name: name,
|
|
140
|
-
amount: offset
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
this.memory._lastUpdate = Date.now();
|
|
144
|
-
|
|
145
|
-
await this.commit();
|
|
146
|
-
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
else return false;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Tests if an attribute meets a requirement.
|
|
154
|
-
* @param {String} check The attribute to check.
|
|
155
|
-
* @param {Number} against The number to meet.
|
|
156
|
-
* @returns
|
|
157
|
-
*/
|
|
158
|
-
checkAttribute = async (check, against) => {
|
|
159
|
-
let att = this.memory.data.attributes;
|
|
160
|
-
|
|
161
|
-
return att[check] >= against;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Sets a user's attribute score.
|
|
166
|
-
* @param {String} change The attribute to change.
|
|
167
|
-
* @param {Number} to The number to set it to.
|
|
168
|
-
* @returns Attributes set
|
|
169
|
-
*/
|
|
170
|
-
setAttribute = async (change, to) => {
|
|
171
|
-
let att = this.memory.data.attributes;
|
|
172
|
-
|
|
173
|
-
att[change] = to;
|
|
174
|
-
this.memory._lastUpdate = Date.now();
|
|
175
|
-
await this.commit();
|
|
176
|
-
|
|
177
|
-
return "Attributes set.";
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Increments a user's attribute by one.
|
|
182
|
-
* @param {String} change The attribute to increment.
|
|
183
|
-
* @param {Number} max The ceiling.
|
|
184
|
-
* @returns The resulting attribute score.
|
|
185
|
-
*/
|
|
186
|
-
incrementAttribute = async (change, max) => {
|
|
187
|
-
let att = this.memory.data.attributes;
|
|
188
|
-
|
|
189
|
-
if (att[change] < max) {
|
|
190
|
-
att[change]++;
|
|
191
|
-
this.memory._lastUpdate = Date.now();
|
|
192
|
-
await this.commit();
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return att[change];
|
|
196
|
-
}
|
|
197
104
|
}
|
|
198
105
|
|
package/package.json
CHANGED
package/public/js/chat-box.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
class ChatBox {
|
|
5
5
|
constructor(username, room) {
|
|
6
|
+
ChatBox.attemptStyle();
|
|
6
7
|
this.socket = null;
|
|
7
8
|
this.username = username;
|
|
8
9
|
this.room = room;
|
|
@@ -23,6 +24,18 @@ class ChatBox {
|
|
|
23
24
|
this.render();
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
static styled = false;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Adds the chat box styles if needed.
|
|
31
|
+
*/
|
|
32
|
+
static attemptStyle() {
|
|
33
|
+
if (!ChatBox.styled) {
|
|
34
|
+
$("head").append(`<link href='/styles/chat.css' rel='stylesheet' />`);
|
|
35
|
+
ChatBox.styled = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
26
39
|
/**
|
|
27
40
|
* Renders a new message in the chat.
|
|
28
41
|
* @param {Object} msg An object including the text to render.
|
package/views/head.ejs
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
<link href="https://fonts.googleapis.com/css2?family=Redacted+Script:wght@300&display=swap" rel="stylesheet">
|
|
14
14
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
|
15
15
|
<link rel="stylesheet" href="/styles/main.css">
|
|
16
|
-
<link rel="stylesheet" href="/styles/chat.css">
|
|
17
16
|
</head>
|
|
18
17
|
|
|
19
18
|
<body>
|