Advertisement
Guest User

Untitled

a guest
May 4th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict'
  2.  
  3. const luaTable = require('./luaTable')
  4. const areas = require('./WorldMapArea')
  5. const fs = require('fs')
  6.  
  7. for (let index in areas) {
  8.   areas[index].id = parseInt(index)
  9.   areas[index].xDiff = areas[index].x2 - areas[index].x1
  10.   areas[index].yDiff = areas[index].y2 - areas[index].y1
  11. }
  12.  
  13. const getArea = (x, y) => {
  14.   let value = []
  15.   for (let index in areas) {
  16.     let area = areas[index]
  17.     if (area.x2 < x && x < area.x1 && area.y2 < y && y < area.y1) {
  18.       value.push(area)
  19.     }
  20.   }
  21.   return value
  22. }
  23.  
  24. const knex = require('knex')({
  25.   client: 'mysql',
  26.   connection: {
  27.     host: 'augusta.gunsight',
  28.     user: 'jake',
  29.     password: 'Objoyfu1',
  30.     database: 'elysium'
  31.   },
  32.   pool: { min: 0, max: 7 }
  33. })
  34.  
  35. let GatherItems = {}
  36.  
  37. const nodeTypes = {
  38.   'Peacebloom': {
  39.     name: 'peacebloom',
  40.     icon: 1,
  41.   },
  42.   'Briarthorn': {
  43.     name: 'briarthorn',
  44.     icon: 1,
  45.   },
  46.   'Grave Moss': {
  47.     name: 'grave moss',
  48.     icon: 1,
  49.   },
  50.   'Gromsblood': {
  51.     name: 'gromsblood',
  52.     icon: 1,
  53.   },
  54.   'Wintersbite': {
  55.     name: 'wintersbite',
  56.     icon: 1,
  57.   },
  58.   'Swiftthistle': {
  59.     name: 'swiftthistle',
  60.     icon: 1,
  61.   },
  62.   'Golden Sansam': {
  63.     name: 'golden sansam',
  64.     icon: 1,
  65.   },
  66.   'Black Lotus': {
  67.     name: 'black lotus',
  68.     icon: 1,
  69.   },
  70.   'Earthroot': {
  71.     name: 'earthroot',
  72.     icon: 1,
  73.   },
  74.   'Sungrass': {
  75.     name: 'sungrass',
  76.     icon: 1,
  77.   },
  78.   'Firebloom': {
  79.     name: 'firebloom',
  80.     icon: 1,
  81.   },
  82.   'Goldthorn': {
  83.     name: 'goldthorn',
  84.     icon: 1,
  85.   },
  86.   'Mageroyal': {
  87.     name: 'mageroyal',
  88.     icon: 1,
  89.   },
  90.   'Icecap': {
  91.     name: 'icecap',
  92.     icon: 1,
  93.   },
  94.   "Arthas' Tears": {
  95.     name: "arthas' tears",
  96.     icon: 1,
  97.   },
  98.   'Silverleaf': {
  99.     name: 'silverleaf',
  100.     icon: 1,
  101.   },
  102.   'Wild Steelbloom': {
  103.     name: 'wild steelbloom',
  104.     icon: 1,
  105.   },
  106.   'Bruiseweed': {
  107.     name: 'bruiseweed',
  108.     icon: 1,
  109.   },
  110.   'Kingsblood': {
  111.     name: 'kingsblood',
  112.     icon: 1,
  113.   },
  114.   'Blindweed': {
  115.     name: 'blindweed',
  116.     icon: 1,
  117.   },
  118.   'Fadeleaf': {
  119.     name: 'fadeleaf',
  120.     icon: 1,
  121.   },
  122.   'Dreamfoil': {
  123.     name: 'dreamfoil',
  124.     icon: 1,
  125.   },
  126.   'Mountain Silversage': {
  127.     name: 'mountain silversage',
  128.     icon: 1,
  129.   },
  130.   'Plaguebloom': {
  131.     name: 'plaguebloom',
  132.     icon: 1,
  133.   },
  134.   'Purple Lotus': {
  135.     name: 'purple lotus',
  136.     icon: 1,
  137.   },
  138.   'Stranglekelp': {
  139.     name: 'stranglekelp',
  140.     icon: 1,
  141.   },
  142.   "Khadgar's Whisker": {
  143.     name: "khadgar's whisker",
  144.     icon: 1,
  145.   },
  146.   'Liferoot': {
  147.     name: 'liferoot',
  148.     icon: 1,
  149.   },
  150.   'Peacebloom': {
  151.     name: 'peacebloom',
  152.     icon: 1,
  153.   },
  154.   'Ghost Mushroom': {
  155.     name: 'ghost mushroom',
  156.     icon: 1,
  157.   },
  158.   'Wildvine': {
  159.     name: 'wildvine',
  160.     icon: 1,
  161.   },
  162.   'Dark Iron Deposit': {
  163.     name: 'dark iron',
  164.     icon: 1,
  165.   },
  166.   'Truesilver': {
  167.     name: 'truesilver',
  168.     icon: 1,
  169.   },
  170.   'Small Thorium Vein': {
  171.     name: 'thorium',
  172.     icon: 1
  173.   },
  174.   'Rich Thorium Vein': {
  175.     name: 'thorium (rich)',
  176.     icon: 1
  177.   },
  178.   'Ooze Covered Thorium Vein': {
  179.     name: 'thorium',
  180.     icon: 1
  181.   },
  182.   'Ooze Covered Rich Thorium Vein': {
  183.     name: 'thorium (rich)',
  184.     icon: 1
  185.   },
  186.   'Tin Vein': {
  187.     name: 'tin',
  188.     icon: 1
  189.   },
  190.   'Copper Vein': {
  191.     name: 'copper',
  192.     icon: 1
  193.   },
  194.   'Truesilver Deposit': {
  195.     name: 'truesilver',
  196.     icon: 1
  197.   },
  198.   'Ooze Covered Truesilver Deposit': {
  199.     name: 'truesilver',
  200.     icon: 1
  201.   },
  202.   'Mithril Deposit': {
  203.     name: 'mithril',
  204.     icon: 1
  205.   },
  206.   'Ooze Covered Mithril Deposit': {
  207.     name: 'mithril',
  208.     icon: 1
  209.   },
  210.   'Silver Vein': {
  211.     name: 'silver',
  212.     icon: 1
  213.   },
  214.   'Ooze Covered Silver Vein': {
  215.     name: 'silver',
  216.     icon: 1
  217.   },
  218.   'Gold Vein': {
  219.     name: 'gold',
  220.     icon: 1
  221.   },
  222.   'Ooze Covered Gold Vein': {
  223.     name: 'gold',
  224.     icon: 1
  225.   },
  226.   'Iron Deposit': {
  227.     name: 'iron',
  228.     icon: 1
  229.   },
  230.   'Ooze Covered Iron Deposit': {
  231.     name: 'iron',
  232.     icon: 1
  233.   },
  234. }
  235.  
  236. knex
  237.   .select('gt.name', 'g.map', 'g.position_x', 'g.position_y')
  238.   .from('gameobject AS g')
  239.   .leftJoin('gameobject_template AS gt', 'g.id', 'gt.entry')
  240.   .leftJoin('map_template AS m', 'm.entry', 'g.map')
  241.   .whereIn('gt.name', Object.keys(nodeTypes))
  242.   .whereIn('g.map', [0, 1])
  243.   .then(nodes => {
  244.  
  245.     for (let node of nodes) {
  246.       // Get the zone the node is in
  247.       let area = getArea(node.position_x, node.position_y)
  248.       console.log(node, area.length)
  249.       continue
  250.  
  251.       // Get the zone x,y coordinates of the node
  252.       let zone_x = Math.floor(Math.abs((node.position_x - area.x1) / area.xDiff * 100) * 1000) / 1000
  253.       let zone_y = Math.floor(Math.abs((node.position_y - area.y1) / area.yDiff * 100) * 1000) / 1000
  254.  
  255.       // Create Continent object
  256.       if (typeof (GatherItems[node.map]) === 'undefined') {
  257.         GatherItems[node.map] = {}
  258.       }
  259.  
  260.       // Create zone object
  261.       if (typeof (GatherItems[node.map][area.id]) === 'undefined') {
  262.         GatherItems[node.map][area.id] = {}
  263.       }
  264.  
  265.       // Create node object list
  266.       if (typeof (GatherItems[node.map][area.id][nodeTypes[node.name].name]) === 'undefined') {
  267.         GatherItems[node.map][area.id][nodeTypes[node.name].name] = []
  268.       }
  269.  
  270.       let newNode = {
  271.         gtype: 1,
  272.         x: zone_x,
  273.         y: zone_y,
  274.         count: 1,
  275.         icon: nodeTypes[node.name].icon
  276.       }
  277.  
  278.       GatherItems[node.map][area.id][nodeTypes[node.name].name].push(newNode)
  279.  
  280.     }
  281.  
  282.     fs.writeFile('output.lua', luaTable(GatherItems))
  283.  
  284.  
  285.   })
  286. knex.destroy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement