screeps/helpers.js

19 lines
564 B
JavaScript
Raw Normal View History

2016-06-29 17:21:09 +00:00
var helpers = {
generateName: function(role){
return role + '_xxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
2016-06-30 01:26:39 +00:00
},
getLastFlag: function(flagName){
return Object.keys(Game.flags).reduce(function(m,f) {
if (f.startsWith(flagName)){
m = Math.max(m, f.slice(flagName.length));
}
return m;
},
-1);
2016-06-30 01:26:39 +00:00
},
2016-06-29 17:21:09 +00:00
};
module.exports = helpers;