@screeps/common 2.15.3 → 2.15.4
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/LICENSE.txt +9 -9
- package/index.js +192 -192
- package/lib/config-manager.js +57 -57
- package/lib/constants.js +1590 -1590
- package/lib/rpc.js +150 -150
- package/lib/storage.js +164 -164
- package/lib/strongholds.js +272 -272
- package/lib/system.js +140 -140
- package/package.json +17 -17
- package/calc.js +0 -37
package/lib/system.js
CHANGED
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
const _ = require('lodash'),
|
|
2
|
-
C = require('./constants');
|
|
3
|
-
|
|
4
|
-
const transforms = {
|
|
5
|
-
'string': value => "" + value,
|
|
6
|
-
'number': parseInt,
|
|
7
|
-
'boolean': value => !!value,
|
|
8
|
-
'price': value => parseInt((1000 * value).toFixed(0)),
|
|
9
|
-
'string[]': value => _.isArray(value) ? _.map(value, i => "" + i) : undefined,
|
|
10
|
-
'number[]': value => _.isArray(value) ? _.map(value, i => parseInt(i)) : undefined,
|
|
11
|
-
'bodypart[]': value => _.filter(value, i => _.contains(C.BODYPARTS_ALL, i)),
|
|
12
|
-
'userString': value => ("" + (value||"")).substring(0, 100),
|
|
13
|
-
'userText': value => ("" + (value||"")).substring(0, 1000)
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const intentTypes = {
|
|
17
|
-
notify: { message: 'userText', groupInterval: 'number' },
|
|
18
|
-
createConstructionSite: { roomName: 'string', x: 'number', y: 'number', structureType: 'string', name: 'userString' },
|
|
19
|
-
createFlag: { roomName: 'string', x: 'number', y: 'number', name: 'userString', color: 'number', secondaryColor: 'number' },
|
|
20
|
-
destroyStructure: { roomName: 'string', id: 'string' },
|
|
21
|
-
removeConstructionSite: { roomName: 'string', id: 'string' },
|
|
22
|
-
removeFlag: { roomName: 'string', name: 'userString' },
|
|
23
|
-
cancelOrder: { orderId: 'string' },
|
|
24
|
-
changeOrderPrice: { orderId: 'string', newPrice: 'price' },
|
|
25
|
-
createOrder: { type: 'string', resourceType: 'string', price: 'price', totalAmount: 'number', roomName: 'string' },
|
|
26
|
-
createPowerCreep: { name: 'userString', className: 'string' },
|
|
27
|
-
deal: { orderId: 'string', amount: 'number', targetRoomName: 'string' },
|
|
28
|
-
deletePowerCreep: { id: 'string', cancel: 'boolean' },
|
|
29
|
-
extendOrder: { orderId: 'string', addAmount: 'number' },
|
|
30
|
-
renamePowerCreep: { id: 'string', name: 'userString' },
|
|
31
|
-
spawnPowerCreep: { id: 'string', name: 'userString' },
|
|
32
|
-
suicidePowerCreep: { id: 'string' },
|
|
33
|
-
upgradePowerCreep: { id: 'string', power: 'number' },
|
|
34
|
-
activateSafeMode: {},
|
|
35
|
-
attack: { id: 'string', x: 'number', y: 'number' },
|
|
36
|
-
attackController: { id: 'string' },
|
|
37
|
-
boostCreep: { id: 'string', bodyPartsCount: 'number' },
|
|
38
|
-
build: { id: 'string', x: 'number', y: 'number' },
|
|
39
|
-
cancelSpawning: {},
|
|
40
|
-
claimController: { id: 'string' },
|
|
41
|
-
createCreep: { name: 'userString', body: 'bodypart[]', energyStructures: 'string[]', directions: 'number[]'},
|
|
42
|
-
destroy: {},
|
|
43
|
-
dismantle: { id: 'string' },
|
|
44
|
-
drop: { amount: 'number', resourceType: 'string' },
|
|
45
|
-
enableRoom: { id: 'string' },
|
|
46
|
-
generateSafeMode: { id: 'string' },
|
|
47
|
-
harvest: { id: 'string' },
|
|
48
|
-
heal: { id: 'string', x: 'number', y: 'number' },
|
|
49
|
-
launchNuke: { x: 'number', y: 'number', roomName: 'string' },
|
|
50
|
-
move: { id: 'string', direction: 'number' },
|
|
51
|
-
notifyWhenAttacked: { enabled: 'boolean' },
|
|
52
|
-
observeRoom: { roomName: 'string' },
|
|
53
|
-
pickup: { id: 'string' },
|
|
54
|
-
processPower: {},
|
|
55
|
-
produce: { resourceType: 'string', amount: 'number' },
|
|
56
|
-
pull: { id: 'string' },
|
|
57
|
-
rangedAttack: { id: 'string' },
|
|
58
|
-
rangedHeal: { id: 'string' },
|
|
59
|
-
rangedMassAttack: {},
|
|
60
|
-
recycleCreep: { id: 'string' },
|
|
61
|
-
renew: { id: 'string' },
|
|
62
|
-
renewCreep: { id: 'string' },
|
|
63
|
-
reverseReaction: { lab1: 'string', lab2: 'string' },
|
|
64
|
-
runReaction: { lab1: 'string', lab2: 'string' },
|
|
65
|
-
remove: {},
|
|
66
|
-
repair: { id: 'string', x: 'number', y: 'number' },
|
|
67
|
-
reserveController: { id: 'string' },
|
|
68
|
-
say: { message: 'userString', isPublic: 'boolean' },
|
|
69
|
-
send: { targetRoomName: 'string', resourceType: 'string', amount: 'number', description: 'userString' },
|
|
70
|
-
setColor: { color: 'number', secondaryColor: 'number' },
|
|
71
|
-
setPosition: { x: 'number', y: 'number', roomName: 'string' },
|
|
72
|
-
setPublic: { isPublic: 'boolean' },
|
|
73
|
-
setSpawnDirections: { directions: 'number[]' },
|
|
74
|
-
signController: { id: 'string', sign: 'userString'},
|
|
75
|
-
suicide: {},
|
|
76
|
-
transfer: { id: 'string', amount: 'number', resourceType: 'string' },
|
|
77
|
-
unboostCreep: { id: 'string' },
|
|
78
|
-
unclaim: {},
|
|
79
|
-
upgradeController: { id: 'string' },
|
|
80
|
-
usePower: { power: 'number', id: 'string' },
|
|
81
|
-
withdraw: { id: 'string', amount: 'number', resourceType: 'string' }
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const sanitizeIntent = function sanitizeIntent(name, intent, customIntentTypes = {}) {
|
|
85
|
-
const result = {};
|
|
86
|
-
|
|
87
|
-
const intentType = intentTypes[name] || customIntentTypes[name];
|
|
88
|
-
for(let field in intentType) {
|
|
89
|
-
result[field] = transforms[intentType[field]](intent[field]);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return result;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
exports.sanitizeUserIntents = function sanitizeUserIntents(input, customIntentTypes = {}) {
|
|
96
|
-
const intentResult = {};
|
|
97
|
-
for(let name in intentTypes) {
|
|
98
|
-
if(input[name]) {
|
|
99
|
-
intentResult[name] = _.isArray(input[name]) ?
|
|
100
|
-
_.map(input[name], i => sanitizeIntent(name, i)) :
|
|
101
|
-
sanitizeIntent(name, input[name], customIntentTypes);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
for(let name in customIntentTypes) {
|
|
106
|
-
if(input[name]) {
|
|
107
|
-
intentResult[name] = _.isArray(input[name]) ?
|
|
108
|
-
_.map(input[name], i => sanitizeIntent(name, i, customIntentTypes)) :
|
|
109
|
-
sanitizeIntent(name, input[name], customIntentTypes);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return intentResult;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
exports.sanitizeUserRoomIntents = function sanitizeUserRoomIntents(input, result, customIntentTypes = {}, groupingField = 'roomName') {
|
|
117
|
-
for(let name in intentTypes) {
|
|
118
|
-
if(input[name]) {
|
|
119
|
-
for(let intent of input[name]) {
|
|
120
|
-
const sanitized = sanitizeIntent(name, intent);
|
|
121
|
-
const groupingValue = sanitized[groupingField];
|
|
122
|
-
const roomNameResult = result[groupingValue] = result[groupingValue] || {};
|
|
123
|
-
const roomResult = roomNameResult.room = roomNameResult.room || {};
|
|
124
|
-
(roomResult[name] = roomResult[name] || []).push(sanitized);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
for(let name in customIntentTypes) {
|
|
130
|
-
if(input[name]) {
|
|
131
|
-
for(let intent of input[name]) {
|
|
132
|
-
const sanitized = sanitizeIntent(name, intent, customIntentTypes);
|
|
133
|
-
const groupingValue = sanitized[groupingField];
|
|
134
|
-
const roomNameResult = result[groupingValue] = result[groupingValue] || {};
|
|
135
|
-
const roomResult = roomNameResult.room = roomNameResult.room || {};
|
|
136
|
-
(roomResult[name] = roomResult[name] || []).push(sanitized);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
1
|
+
const _ = require('lodash'),
|
|
2
|
+
C = require('./constants');
|
|
3
|
+
|
|
4
|
+
const transforms = {
|
|
5
|
+
'string': value => "" + value,
|
|
6
|
+
'number': parseInt,
|
|
7
|
+
'boolean': value => !!value,
|
|
8
|
+
'price': value => parseInt((1000 * value).toFixed(0)),
|
|
9
|
+
'string[]': value => _.isArray(value) ? _.map(value, i => "" + i) : undefined,
|
|
10
|
+
'number[]': value => _.isArray(value) ? _.map(value, i => parseInt(i)) : undefined,
|
|
11
|
+
'bodypart[]': value => _.filter(value, i => _.contains(C.BODYPARTS_ALL, i)),
|
|
12
|
+
'userString': value => ("" + (value||"")).substring(0, 100),
|
|
13
|
+
'userText': value => ("" + (value||"")).substring(0, 1000)
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const intentTypes = {
|
|
17
|
+
notify: { message: 'userText', groupInterval: 'number' },
|
|
18
|
+
createConstructionSite: { roomName: 'string', x: 'number', y: 'number', structureType: 'string', name: 'userString' },
|
|
19
|
+
createFlag: { roomName: 'string', x: 'number', y: 'number', name: 'userString', color: 'number', secondaryColor: 'number' },
|
|
20
|
+
destroyStructure: { roomName: 'string', id: 'string' },
|
|
21
|
+
removeConstructionSite: { roomName: 'string', id: 'string' },
|
|
22
|
+
removeFlag: { roomName: 'string', name: 'userString' },
|
|
23
|
+
cancelOrder: { orderId: 'string' },
|
|
24
|
+
changeOrderPrice: { orderId: 'string', newPrice: 'price' },
|
|
25
|
+
createOrder: { type: 'string', resourceType: 'string', price: 'price', totalAmount: 'number', roomName: 'string' },
|
|
26
|
+
createPowerCreep: { name: 'userString', className: 'string' },
|
|
27
|
+
deal: { orderId: 'string', amount: 'number', targetRoomName: 'string' },
|
|
28
|
+
deletePowerCreep: { id: 'string', cancel: 'boolean' },
|
|
29
|
+
extendOrder: { orderId: 'string', addAmount: 'number' },
|
|
30
|
+
renamePowerCreep: { id: 'string', name: 'userString' },
|
|
31
|
+
spawnPowerCreep: { id: 'string', name: 'userString' },
|
|
32
|
+
suicidePowerCreep: { id: 'string' },
|
|
33
|
+
upgradePowerCreep: { id: 'string', power: 'number' },
|
|
34
|
+
activateSafeMode: {},
|
|
35
|
+
attack: { id: 'string', x: 'number', y: 'number' },
|
|
36
|
+
attackController: { id: 'string' },
|
|
37
|
+
boostCreep: { id: 'string', bodyPartsCount: 'number' },
|
|
38
|
+
build: { id: 'string', x: 'number', y: 'number' },
|
|
39
|
+
cancelSpawning: {},
|
|
40
|
+
claimController: { id: 'string' },
|
|
41
|
+
createCreep: { name: 'userString', body: 'bodypart[]', energyStructures: 'string[]', directions: 'number[]'},
|
|
42
|
+
destroy: {},
|
|
43
|
+
dismantle: { id: 'string' },
|
|
44
|
+
drop: { amount: 'number', resourceType: 'string' },
|
|
45
|
+
enableRoom: { id: 'string' },
|
|
46
|
+
generateSafeMode: { id: 'string' },
|
|
47
|
+
harvest: { id: 'string' },
|
|
48
|
+
heal: { id: 'string', x: 'number', y: 'number' },
|
|
49
|
+
launchNuke: { x: 'number', y: 'number', roomName: 'string' },
|
|
50
|
+
move: { id: 'string', direction: 'number' },
|
|
51
|
+
notifyWhenAttacked: { enabled: 'boolean' },
|
|
52
|
+
observeRoom: { roomName: 'string' },
|
|
53
|
+
pickup: { id: 'string' },
|
|
54
|
+
processPower: {},
|
|
55
|
+
produce: { resourceType: 'string', amount: 'number' },
|
|
56
|
+
pull: { id: 'string' },
|
|
57
|
+
rangedAttack: { id: 'string' },
|
|
58
|
+
rangedHeal: { id: 'string' },
|
|
59
|
+
rangedMassAttack: {},
|
|
60
|
+
recycleCreep: { id: 'string' },
|
|
61
|
+
renew: { id: 'string' },
|
|
62
|
+
renewCreep: { id: 'string' },
|
|
63
|
+
reverseReaction: { lab1: 'string', lab2: 'string' },
|
|
64
|
+
runReaction: { lab1: 'string', lab2: 'string' },
|
|
65
|
+
remove: {},
|
|
66
|
+
repair: { id: 'string', x: 'number', y: 'number' },
|
|
67
|
+
reserveController: { id: 'string' },
|
|
68
|
+
say: { message: 'userString', isPublic: 'boolean' },
|
|
69
|
+
send: { targetRoomName: 'string', resourceType: 'string', amount: 'number', description: 'userString' },
|
|
70
|
+
setColor: { color: 'number', secondaryColor: 'number' },
|
|
71
|
+
setPosition: { x: 'number', y: 'number', roomName: 'string' },
|
|
72
|
+
setPublic: { isPublic: 'boolean' },
|
|
73
|
+
setSpawnDirections: { directions: 'number[]' },
|
|
74
|
+
signController: { id: 'string', sign: 'userString'},
|
|
75
|
+
suicide: {},
|
|
76
|
+
transfer: { id: 'string', amount: 'number', resourceType: 'string' },
|
|
77
|
+
unboostCreep: { id: 'string' },
|
|
78
|
+
unclaim: {},
|
|
79
|
+
upgradeController: { id: 'string' },
|
|
80
|
+
usePower: { power: 'number', id: 'string' },
|
|
81
|
+
withdraw: { id: 'string', amount: 'number', resourceType: 'string' }
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const sanitizeIntent = function sanitizeIntent(name, intent, customIntentTypes = {}) {
|
|
85
|
+
const result = {};
|
|
86
|
+
|
|
87
|
+
const intentType = intentTypes[name] || customIntentTypes[name];
|
|
88
|
+
for(let field in intentType) {
|
|
89
|
+
result[field] = transforms[intentType[field]](intent[field]);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
exports.sanitizeUserIntents = function sanitizeUserIntents(input, customIntentTypes = {}) {
|
|
96
|
+
const intentResult = {};
|
|
97
|
+
for(let name in intentTypes) {
|
|
98
|
+
if(input[name]) {
|
|
99
|
+
intentResult[name] = _.isArray(input[name]) ?
|
|
100
|
+
_.map(input[name], i => sanitizeIntent(name, i)) :
|
|
101
|
+
sanitizeIntent(name, input[name], customIntentTypes);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
for(let name in customIntentTypes) {
|
|
106
|
+
if(input[name]) {
|
|
107
|
+
intentResult[name] = _.isArray(input[name]) ?
|
|
108
|
+
_.map(input[name], i => sanitizeIntent(name, i, customIntentTypes)) :
|
|
109
|
+
sanitizeIntent(name, input[name], customIntentTypes);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return intentResult;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
exports.sanitizeUserRoomIntents = function sanitizeUserRoomIntents(input, result, customIntentTypes = {}, groupingField = 'roomName') {
|
|
117
|
+
for(let name in intentTypes) {
|
|
118
|
+
if(input[name]) {
|
|
119
|
+
for(let intent of input[name]) {
|
|
120
|
+
const sanitized = sanitizeIntent(name, intent);
|
|
121
|
+
const groupingValue = sanitized[groupingField];
|
|
122
|
+
const roomNameResult = result[groupingValue] = result[groupingValue] || {};
|
|
123
|
+
const roomResult = roomNameResult.room = roomNameResult.room || {};
|
|
124
|
+
(roomResult[name] = roomResult[name] || []).push(sanitized);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
for(let name in customIntentTypes) {
|
|
130
|
+
if(input[name]) {
|
|
131
|
+
for(let intent of input[name]) {
|
|
132
|
+
const sanitized = sanitizeIntent(name, intent, customIntentTypes);
|
|
133
|
+
const groupingValue = sanitized[groupingField];
|
|
134
|
+
const roomNameResult = result[groupingValue] = result[groupingValue] || {};
|
|
135
|
+
const roomResult = roomNameResult.room = roomNameResult.room || {};
|
|
136
|
+
(roomResult[name] = roomResult[name] || []).push(sanitized);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@screeps/common",
|
|
3
|
-
"version": "2.15.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"author": "Artem Chivchalov <contact@screeps.com>",
|
|
7
|
-
"license": "ISC",
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "https://github.com/screeps/common.git"
|
|
11
|
-
},
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"eslint": "^5.12.1",
|
|
14
|
-
"lodash": "^3.10.1",
|
|
15
|
-
"q": "^1.4.1"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@screeps/common",
|
|
3
|
+
"version": "2.15.4",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"author": "Artem Chivchalov <contact@screeps.com>",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/screeps/common.git"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"eslint": "^5.12.1",
|
|
14
|
+
"lodash": "^3.10.1",
|
|
15
|
+
"q": "^1.4.1"
|
|
16
|
+
}
|
|
17
|
+
}
|
package/calc.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const _ = require('lodash'),
|
|
2
|
-
C = require('./lib/constants');
|
|
3
|
-
|
|
4
|
-
const rawResources = [
|
|
5
|
-
C.RESOURCE_UTRIUM,
|
|
6
|
-
C.RESOURCE_LEMERGIUM,
|
|
7
|
-
C.RESOURCE_ZYNTHIUM,
|
|
8
|
-
C.RESOURCE_KEANIUM,
|
|
9
|
-
C.RESOURCE_OXYGEN,
|
|
10
|
-
C.RESOURCE_HYDROGEN,
|
|
11
|
-
C.RESOURCE_CATALYST,
|
|
12
|
-
C.RESOURCE_GHODIUM,
|
|
13
|
-
C.RESOURCE_POWER,
|
|
14
|
-
C.RESOURCE_ENERGY,
|
|
15
|
-
C.RESOURCE_BIOMASS,
|
|
16
|
-
C.RESOURCE_MIST,
|
|
17
|
-
C.RESOURCE_SILICON,
|
|
18
|
-
C.RESOURCE_METAL
|
|
19
|
-
];
|
|
20
|
-
|
|
21
|
-
const topLevel = _.filter(_.map(C.COMMODITIES, (v,k)=>_.merge({resourceType:k},v)), c => c.level == 5);
|
|
22
|
-
|
|
23
|
-
const totalResources = function(resourceType, amount) {
|
|
24
|
-
//console.log(`${amount} of ${resourceType}`);
|
|
25
|
-
let result = {[resourceType]: amount};
|
|
26
|
-
if(C.COMMODITIES[resourceType] && !_.contains(rawResources, resourceType)) {
|
|
27
|
-
_.forEach(C.COMMODITIES[resourceType].components, (a, component) => {
|
|
28
|
-
result = _.merge(result, totalResources(component, a*amount/C.COMMODITIES[resourceType].amount), (a,b) => (a||0)+b);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
//console.log(JSON.stringify(totalResources(C.RESOURCE_ORGANISM, 1), null, 2));
|
|
36
|
-
//_.forEach(topLevel, c => console.log(`${c.resourceType}: ${JSON.stringify(totalResources(c.resourceType, 1), null,2)}`));
|
|
37
|
-
console.log(`${totalResources(C.RESOURCE_DEVICE, 1)['energy']}\t${totalResources(C.RESOURCE_ORGANISM, 1)['energy']}\t${totalResources(C.RESOURCE_MACHINE, 1)['energy']}\t${totalResources(C.RESOURCE_ESSENCE, 1)['energy']}`);
|