SHARE
TWEET

Untitled

a guest Jan 10th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. **** Example rudimentary code showing one disputed land
  4.  
  5. //  This example could use only a few bytes of memory in the server code and could
  6. //  be updated with a very simple asymmetrical function call that uses little resource.
  7.  
  8. */
  9.  
  10. const WorldObjects = {}; // very huge.... much data
  11. const GlobalServer = {iron:{totalMined:148,lands:{disputed1:40,disputed2:60,disputed3:10,disputed4:20,disputed5:18}}};
  12.  
  13. // These will be pulled from the already existing clusterData
  14. const DisputedLands = {disputed1:{x1:1050000,y1:240000,x2:1065000,y2:255000},d2:{},d3:{},etc:{}};
  15.  
  16.  
  17. var InsideDisputed = function(x,y,callback) {
  18.   Object.keys(DisputedLands).forEach(function(idx) {
  19.     var dl = DisputedLands[idx];
  20.     if (x >= dl.x1 && x <= dl.x2 && y >= dl.y1 && y <= dl.y2) callback(idx);
  21.     else callback(false);
  22.   });
  23. };
  24.  
  25.  
  26.  
  27. var worldObjectUse = function(WorldObjects,obj,callback) {
  28. console.log("worldObjectUse",obj);
  29.   if (obj.objectTypeName === "IronRock") {
  30.     GlobalServer.iron.totalMined++;
  31.     InsideDisputed(obj.x,obj.y,function(ret) { return callback(ret); });
  32.   }
  33. };
  34.  
  35.  
  36. var checkLowIron = function(callback) {
  37.   var sortable = [];
  38.   for (var idx in GlobalServer.iron.lands) {
  39.     sortable.push([idx, GlobalServer.iron.lands[idx]]);
  40.   }
  41.   sortable.sort(function(a, b) { return a[1] - b[1]; });
  42.   return callback(sortable);
  43. };
  44.  
  45.  
  46.  
  47.  
  48. console.log(GlobalServer.iron);
  49.  
  50. // sample variable
  51. var jsonObject = {objectTypeName:"IronRock",x:1050001,y:241567};
  52.  
  53.  
  54. worldObjectUse(WorldObjects,jsonObject,function(ret) {
  55. console.log("worldObjectUse-callback",ret);
  56.   if (typeof ret === "string" && typeof GlobalServer.iron.lands[ret] === "number") {
  57.     GlobalServer.iron.lands[ret]++;
  58.     console.log("Iron Mined",ret,GlobalServer.iron);
  59.   } else console.log("Hmmm problem here, iron not mined inside boundary or global variable is bad!??");
  60. });
  61.  
  62. checkLowIron(function(ret) {
  63.   console.log("Low Iron",ret);
  64.   console.log("The disputed lands that has been mined the least is: "+ret[0]);
  65. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top