Advertisement
jargon

Roe2Js :: Entities Stats

Jun 4th, 2024 (edited)
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* HTML Template Asset: "entity table.html" */
  2. <table class="outertable" style="width: 50vw; height: 100vh;" ><tbody class="outertable">
  3. <tr class="outertable"><td class="bevel-border outertable" colspan="3">
  4.  
  5. <table class="outertable" style="width:100%;"><tbody class="outertable">
  6. <tr class="outertable"><td class="bevel-border lefttable" colspan="2">card</td></tr>
  7. <tr class="outertable"><td class="bevel-border lefttable">namesake</td><td class="bevel-border lefttable">"{{ @card::.namesake }}"</td></tr>
  8. <tr class="outertable"><td class="bevel-border lefttable">graphic</td><td class="bevel-border lefttable"><img src="http://{{ host }}/GFX/{{ @card::.graphic }}____.png" alt="{{ @card::.graphic }}"></td></tr>
  9. <tr class="outertable"><td class="bevel-border lefttable">action</td><td class="bevel-border lefttable">{{ @card::.action }}</td></tr>
  10. </tbody></table>
  11.  
  12. </td></tr>
  13. <tr class="outertable"><td>
  14.  
  15. <table class="outertable" style="width:100%;"><tbody class="outertable">
  16. <tr class="outertable"><td class="bevel-border lefttable" colspan="2">health</td></tr>
  17. <tr class="outertable"><td class="bevel-border lefttable">current</td><td class="bevel-border righttable">{{ @health::.current }}</td></tr>
  18. <tr class="outertable"><td class="bevel-border lefttable">maximum</td><td class="bevel-border righttable">{{ @health::.maximum }}</td></tr>
  19. <tr class="outertable"><td class="bevel-border lefttable">recovery</td><td class="bevel-border righttable">{{ @health::.recovery }}</td></tr>
  20. </tbody></table>
  21.  
  22. </td><td>
  23.  
  24. <table class="outertable" style="width:100%;"><tbody class="outertable">
  25. <tr class="outertable"><td class="bevel-border lefttable" colspan="2">stamina</td></tr>
  26. <tr class="outertable"><td class="bevel-border lefttable">current</td><td class="bevel-border righttable">{{ @stamina::.current }}</td></tr>
  27. <tr class="outertable"><td class="bevel-border lefttable">maximum</td><td class="bevel-border righttable">{{ @stamina::.maximum }}</td></tr>
  28. <tr class="outertable"><td class="bevel-border lefttable">recovery</td><td class="bevel-border righttable">{{ @stamina::.recovery }}</td></tr>
  29. </tbody></table>
  30.  
  31. </td><td>
  32.  
  33. <table class="outertable" style="width:100%;"><tbody class="outertable">
  34. <tr class="outertable"><td class="bevel-border lefttable" colspan="2">essence</td></tr>
  35. <tr class="outertable"><td class="bevel-border lefttable">current</td><td class="bevel-border righttable">{{ @essence::.current }}</td></tr>
  36. <tr class="outertable"><td class="bevel-border lefttable">maximum</td><td class="bevel-border righttable">{{ @essence::.maximum }}</td></tr>
  37. <tr class="outertable"><td class="bevel-border lefttable">recovery</td><td class="bevel-border righttable">{{ @essence::.recovery }}</td></tr>
  38. </tbody></table>
  39.  
  40. </td></tr>
  41. <tr class="outertable"><td>
  42.  
  43. <table class="outertable" style="width:100%;"><tbody class="outertable">
  44. <tr class="outertable"><td class="bevel-border lefttable" colspan="2">combat</td></tr>
  45. <tr class="outertable"><td class="bevel-border lefttable">piercing</td><td class="bevel-border righttable">{{ @combat::.piercing }}</td></tr>
  46. <tr class="outertable"><td class="bevel-border lefttable">armored</td><td class="bevel-border righttable">{{ @combat::.armored }}</td></tr>
  47. <tr class="outertable"><td class="bevel-border lefttable">evasion</td><td class="bevel-border righttable">{{ @combat::.evasion }}</td></tr>
  48. </tbody></table>
  49.  
  50. </td><td>
  51.  
  52. <table class="outertable" style="width:100%;"><tbody class="outertable">
  53. <tr class="outertable"><td class="bevel-border lefttable" colspan="2">skill</td></tr>
  54. <tr class="outertable"><td class="bevel-border lefttable">level</td><td class="bevel-border righttable">{{ @skill::.level }}</td></tr>
  55. <tr class="outertable"><td class="bevel-border lefttable">experience</td><td class="bevel-border righttable">{{ @skill::.experience }}</td></tr>
  56. <tr class="outertable"><td class="bevel-border lefttable">appraisal</td><td class="bevel-border righttable">{{ @skill::.appraisal }}</td></tr>
  57. </tbody></table>
  58.  
  59. </td><td>
  60.  
  61. <table class="outertable" style="width:100%;"><tbody class="outertable">
  62. <tr class="outertable"><td class="bevel-border lefttable" colspan="2">affinity</td></tr>
  63. <tr class="outertable"><td class="bevel-border lefttable">identity</td><td class="bevel-border righttable">{{ @affinity::.identity }}</td></tr>
  64. <tr class="outertable"><td class="bevel-border lefttable" colspan="2">&nbsp;</td></tr>
  65. <tr class="outertable"><td class="bevel-border lefttable" colspan="2">&nbsp;</td></tr>
  66. </tbody></table>
  67.  
  68. </td></tr>
  69. </tbody></table>
  70.  
  71. /* JSON Spreadsheet Asset: "pndx.js" */
  72.  
  73. {
  74.     "pndx": {
  75.         "stats": {
  76.             "card": {
  77.                 "namesake": "Poindexter",
  78.                 "action": "wstf",
  79.                 "graphic": "pndx"
  80.             },
  81.             "affinity": {
  82.                 "identity": 5
  83.             },
  84.             "health": {
  85.                 "current": 30,
  86.                 "maximum": 30,
  87.                 "recovery": 0
  88.             },
  89.             "stamina": {
  90.                 "current": 90,
  91.                 "maximum": 90,
  92.                 "recovery": 3
  93.             },
  94.             "essence": {
  95.                 "current": 0,
  96.                 "maximum": 30,
  97.                 "recovery": 0.1
  98.             },
  99.             "combat": {
  100.                 "armored": 2,
  101.                 "piercing": 2,
  102.                 "evasion": 0.07
  103.             },
  104.             "skill": {
  105.                 "experience": 10,
  106.                 "level": 1,
  107.                 "appraisal": 0
  108.             },
  109.         },
  110.         "dice": {
  111.             "rolls": {
  112.                 "dust": "ROLL(1d2)"
  113.             },
  114.             "reward": {
  115.                 "ON(dust);EQU;2": [
  116.                     "card::action;&=;dust"
  117.                 ]
  118.             }
  119.         }
  120.     }
  121. }
  122.  
  123.  
  124. /* Js Script: "files.js" */
  125.  
  126.     function loadDocument(filePath) {
  127.         var xhr = new XMLHttpRequest();
  128.         xhr.open("GET", filePath, false);  // 'false' makes the request synchronous
  129.         xhr.setRequestHeader("Accept", "text/plain");
  130.         xhr.send(null);
  131.    
  132.         if (xhr.status === 200) {
  133.             return xhr.responseText;
  134.         } else {
  135.             throw new Error('Error loading document: ' + xhr.status);
  136.         }
  137.     }
  138.  
  139.     function loadJSON(filePath) {
  140.         var xhr = new XMLHttpRequest();
  141.         xhr.open("GET", filePath, false);  // 'false' makes the request synchronous
  142.         xhr.setRequestHeader("Accept", "application/json");
  143.         xhr.send(null);
  144.    
  145.         if (xhr.status === 200) {
  146.             return JSON.parse(xhr.responseText);
  147.         } else {
  148.             throw new Error('Error loading JSON file: ' + xhr.status);
  149.         }
  150.     }
  151.     // return;
  152.            
  153.     async function loadFullMap() {
  154.                
  155.         // Load the full map
  156.         const full_map = await fetch(`http://${host}/maps/roe2a/${map}.json`).then(response => response.json());
  157.    
  158.         // Initialize full_stats array
  159.         const full_stats = [];
  160.    
  161.         for (let x = 0; x < full_map.length; x++) {
  162.             full_stats[x] = []; // Initialize the second dimension
  163.             for (let y = 0; y < full_map[x].length; y++) {
  164.                 full_stats[x][y] = []; // Initialize the third dimension
  165.    
  166.                 for (let z = 0; z < layers.gui; z++) {
  167.                     const sectionValue = section(full_map[x][y][z], 0);
  168.                     const url = `http://${host}/entity dictionary/json/${sectionValue}.json`;
  169.  
  170.                     if(preloaded.indexOf(sectionValue) !== -1){
  171.                         full_stats[x][y][z] = preloaded[section(full_map[x][y][z],0)];
  172.                         continue;
  173.                     }
  174.                    
  175.                     full_stats[x][y][z] = preloaded[section(full_map[x][y][z],0)];
  176.  
  177.                     // Check if the file exists before fetching it
  178.                     if (await fileExists(url)) {
  179.                         full_stats[x][y][z] = await fetch(url).then(response => response.json());
  180.                     } else {
  181.                         // console.warn(`File not found: ${url}`);
  182.                         full_stats[x][y][z] = null; // or handle the missing file case as needed
  183.                         continue;
  184.                     }
  185.                
  186.    
  187.                     // Capture the first key
  188.                     const keys = layers.Object.keys(full_stats[x][y][z]);
  189.                    
  190.                     if (keys.length === 0) {
  191.                         full_stats[x][y][z] = null;
  192.                         continue;
  193.                     }
  194.                    
  195.                     const key = keys[0];
  196.                     if ( key === section( full_map[x][y][z], 0 ) ){
  197.                         preloaded[section(full_map[x][y][z],0)] = full_stats[x][y][z][section(full_map[x][y][z],0)];
  198.                     }else{
  199.                         preloaded[section(full_map[x][y][z],0)] = null;
  200.                     }
  201.                 }
  202.             }
  203.         }
  204.         return full_stats;
  205.     }
  206.    
  207.  
  208.     // Function to check if a file exists using a HEAD request
  209.     async function fileExists(url) {
  210.         try {
  211.             // const response = await fetch(url, { method: 'HEAD' });
  212.             return response.ok;
  213.         } catch (error) {
  214.             // console.error(`Error checking file existence: ${error}`);
  215.             return false;
  216.         }
  217.     }
  218.  
  219.  
  220.  
  221. /* Js Script: "ini stats.js" */
  222.  
  223. var entities = [];
  224. var defaultStats = [];
  225.  
  226.  
  227. function loadStats(){
  228.    
  229.     entities =
  230.     {
  231.         terrain: ['dirt','hole','watr','stps','stpw'],
  232.    
  233.         critter: ['dtby','spdr','grml','imp_','emgd','shkt','pndx'],
  234.    
  235.         object: ['door','wall','bldr','ccts','chst','pwch'],
  236.    
  237.         ailment: ['web_','wing','cure','vnom','fire','loc1','loc2','loc3','dust','zzzz']
  238.     };
  239.    
  240.     defaultStats = [];
  241.  
  242.     for (let index = 0; index < entities.critter.length; index++) {
  243.    
  244.         const url = `http://${host}/entity%20dictionary/json/${section(entities.critter[index], 0)}.json`;
  245.    
  246.         console.log(url);
  247.    
  248.         const jsonData = loadJSON(url);
  249.         defaultStats.push(jsonData);
  250.     }
  251.  
  252.     console.log(defaultStats);
  253. }
  254.  
  255. /* Js Script: "generate tray stats.js" */
  256.  
  257.     function generateTrayStats ([x,y,z]){
  258.        
  259.         if(oob([x,y]) !== true){
  260.             return false;
  261.         }
  262.        
  263.         if(z !== layers.critter){
  264.             return false;
  265.         }
  266.        
  267.         full_stats[x][y][z] = defaultStats[section(full_map[x][y][z],0)];
  268.        
  269.         ledger = prefabLedger;
  270.        
  271.         ledger = ledger.replace(/@card::.namesake/, `${full_stats[x][y].card.namesake}`);
  272.  
  273.         ledger = ledger.replace(/@card::.graphic/, `${full_stats[x][y].card.graphic}`);
  274.        
  275.         ledger = ledger.replace(/@card::.action/, `${full_stats[x][y].card.action}`);
  276.        
  277.         ledger = ledger.replace(/@health::.current/, `${full_stats[x][y].health.current}`);
  278.         ledger = ledger.replace(/@health::.maximum/, `${full_stats[x][y].health.maximum}`);
  279.         ledger = ledger.replace(/@health::.recovery/, `${full_stats[x][y].health.recovery}`);
  280.        
  281.         ledger = ledger.replace(/@stamina::.current/, `${full_stats[x][y].stamina.current}`);
  282.         ledger = ledger.replace(/@stamina::.maximum/, `${full_stats[x][y].stamina.maximum}`);
  283.         ledger = ledger.replace(/@stamina::.recovery/, `${full_stats[x][y].stamina.recovery}`);
  284.        
  285.         ledger = ledger.replace(/@skill::.current/, `${full_stats[x][y].skill.current}`);
  286.         ledger = ledger.replace(/@skill::.maximum/, `${full_stats[x][y].skill.maximum}`);
  287.         ledger = ledger.replace(/@skill::.recovery/, `${full_stats[x][y].skill.recovery}`);
  288.        
  289.         ledger = ledger.replace(/@combat::.piercing/, `${full_stats[x][y].combat.piercing}`);
  290.         ledger = ledger.replace(/@combat::.armored/, `${full_stats[x][y].combat.armored}`);
  291.         ledger = ledger.replace(/@combat::.evasion/, `${full_stats[x][y].combat.evasion}`);
  292.        
  293.         ledger = ledger.replace(/@skill::.level/, `${full_stats[x][y].skill.level}`);
  294.         ledger = ledger.replace(/@skill::.experience/, `${full_stats[x][y].skill.experience}`);
  295.         ledger = ledger.replace(/@skill::.appraisal/, `${full_stats[x][y].skill.appraisal}`);
  296.        
  297.         ledger = ledger.replace(/@affinity::.identity/, `${full_stats[x][y].affinity.identity}`);
  298.        
  299.         return ledger;
  300.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement