Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- **** Example rudimentary code showing one disputed land
- // This example could use only a few bytes of memory in the server code and could
- // be updated with a very simple asymmetrical function call that uses little resource.
- */
- const WorldObjects = {}; // very huge.... much data
- const GlobalServer = {iron:{totalMined:148,lands:{disputed1:40,disputed2:60,disputed3:10,disputed4:20,disputed5:18}}};
- // These will be pulled from the already existing clusterData
- const DisputedLands = {disputed1:{x1:1050000,y1:240000,x2:1065000,y2:255000},d2:{},d3:{},etc:{}};
- var InsideDisputed = function(x,y,callback) {
- Object.keys(DisputedLands).forEach(function(idx) {
- var dl = DisputedLands[idx];
- if (x >= dl.x1 && x <= dl.x2 && y >= dl.y1 && y <= dl.y2) callback(idx);
- else callback(false);
- });
- };
- var worldObjectUse = function(WorldObjects,obj,callback) {
- console.log("worldObjectUse",obj);
- if (obj.objectTypeName === "IronRock") {
- GlobalServer.iron.totalMined++;
- InsideDisputed(obj.x,obj.y,function(ret) { return callback(ret); });
- }
- };
- var checkLowIron = function(callback) {
- var sortable = [];
- for (var idx in GlobalServer.iron.lands) {
- sortable.push([idx, GlobalServer.iron.lands[idx]]);
- }
- sortable.sort(function(a, b) { return a[1] - b[1]; });
- return callback(sortable);
- };
- console.log(GlobalServer.iron);
- // sample variable
- var jsonObject = {objectTypeName:"IronRock",x:1050001,y:241567};
- worldObjectUse(WorldObjects,jsonObject,function(ret) {
- console.log("worldObjectUse-callback",ret);
- if (typeof ret === "string" && typeof GlobalServer.iron.lands[ret] === "number") {
- GlobalServer.iron.lands[ret]++;
- console.log("Iron Mined",ret,GlobalServer.iron);
- } else console.log("Hmmm problem here, iron not mined inside boundary or global variable is bad!??");
- });
- checkLowIron(function(ret) {
- console.log("Low Iron",ret);
- console.log("The disputed lands that has been mined the least is: "+ret[0]);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement