screeps/helpers.js
2016-06-29 21:37:58 -04:00

19 lines
564 B
JavaScript

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);
});
},
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);
},
};
module.exports = helpers;