Krythic

Diablo2.io Monster Auxillary Data Generator v1.1

Aug 25th, 2021
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 22.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5.  
  6. namespace D2MonsterAuxParser
  7. {
  8.     public class Program
  9.     {
  10.  
  11.         public static string[] SplitAggregateData(string data)
  12.         {
  13.  
  14.             data = data.Replace(" ", ""); // Remove spaces
  15.             data = data.Replace(",", ""); // Remove Commas (they exist for some pages and not others)
  16.             data = data.Trim(); // This may not be needed.
  17.             return data.Split('/');
  18.         }
  19.  
  20.         public static string[] SplitTreasureClassData(string data)
  21.         {
  22.             data = data.Replace(" ", ""); // Remove spaces
  23.             data = data.Trim(); // This may not be needed.
  24.             string[] split = data.Split(',');
  25.             return new string[] {
  26.                 split[0].Split('/')[0].Trim(),
  27.                 split[1].Split('/')[0].Trim(),
  28.                 split[2].Split('/')[0].Trim(),
  29.             };
  30.         }
  31.  
  32.         public static string[] ParseBlockData(string data)
  33.         {
  34.             // D2 Blocking data is basically a cluster fuck.
  35.             data = data.Trim();
  36.             data = data.Replace("--", "0");
  37.             data = data.Replace("%", "");
  38.             if (data.Equals("0"))
  39.             {
  40.                 return new string[] { "0", "0", "0" };
  41.             }
  42.             int count = 0;
  43.             foreach (char character in data)
  44.             {
  45.                 if (character == '/')
  46.                 {
  47.                     count++;
  48.                 }
  49.             }
  50.             if (count == 0)
  51.             {
  52.                 // Blocking is universal for all difficulties
  53.                 return new string[] { data, data, data };
  54.             }
  55.             if (count == 2)
  56.             {
  57.                 // There are three separate blocking values; one for each difficulty
  58.                 string[] split = data.Split("/");
  59.                 return new string[] {
  60.                     split[0],
  61.                     split[1],
  62.                     split[2] };
  63.             }
  64.             // Throw an error, because there is an edge case we're not prepared for!
  65.             throw new Exception("Blocking edge case detected!");
  66.         }
  67.  
  68.         public static void Main(string[] args)
  69.         {
  70.             bool isDebugging = false;
  71.             bool filterNullData = false;
  72.             Dictionary<string, string> auxData = new Dictionary<string, string>();
  73.             StringBuilder builder = new StringBuilder();
  74.             /**
  75.              * Parse First Row:  Name, Level Experience, Hit Points, Speed, and Max TC
  76.              */
  77.             Console.WriteLine("Input First Row 'Statistics' Data: ");
  78.             string input = Console.ReadLine();
  79.             string[] firstRowSegments = input.Split('_');
  80.             // Name
  81.             auxData.Add("imvariant_name", firstRowSegments[0].Trim());
  82.             // Level
  83.             string[] splitCache = SplitAggregateData(firstRowSegments[1]);
  84.             auxData.Add("imlvl_norm", splitCache[0]);
  85.             auxData.Add("imlvl_night", splitCache[1]);
  86.             auxData.Add("imlvl_hell", splitCache[2]);
  87.             // Max TC
  88.             splitCache = SplitTreasureClassData(firstRowSegments[5]);
  89.             auxData.Add("imtrclass_norm", splitCache[0]);
  90.             auxData.Add("imtrclass_night", splitCache[1]);
  91.             auxData.Add("imtrclass_hell", splitCache[2]);
  92.             // Experience
  93.             splitCache = SplitAggregateData(firstRowSegments[2]);
  94.             auxData.Add("imxp_norm", splitCache[0]);
  95.             auxData.Add("imxp_night", splitCache[1]);
  96.             auxData.Add("imxp_hell", splitCache[2]);
  97.             // Hitpoints
  98.             splitCache = SplitAggregateData(firstRowSegments[3]);
  99.             auxData.Add("imhp_norm", splitCache[0]);
  100.             auxData.Add("imhp_night", splitCache[1]);
  101.             auxData.Add("imhp_hell", splitCache[2]);
  102.             // Speed (Unused for Diablo2.io
  103.             // We won't parse it because we don't need to
  104.  
  105.             /**
  106.              * Parse Second Row: Defense, Blocking, Regen Rate, Drain Effectiveness, Chill Effectiveness
  107.              */
  108.             Console.WriteLine("Input Second Row 'Defense' Data:");
  109.             input = Console.ReadLine();
  110.             string[] secondRowSegments = input.Split('_');
  111.  
  112.             // Defense
  113.             splitCache = SplitAggregateData(secondRowSegments[0]);
  114.             auxData.Add("imdefense_norm", splitCache[0]);
  115.             auxData.Add("imdefense_night", splitCache[1]);
  116.             auxData.Add("imdefense_hell", splitCache[2]);
  117.             // Blocking
  118.             splitCache = ParseBlockData(secondRowSegments[1]);
  119.             auxData.Add("imblock_norm", splitCache[0]);
  120.             auxData.Add("imblock_night", splitCache[1]);
  121.             auxData.Add("imblock_hell", splitCache[2]);
  122.             // Regen Rate
  123.             // We won't parse it because we don't need to
  124.             // Drain Effectiveness
  125.             splitCache = SplitAggregateData(secondRowSegments[3]);
  126.             auxData.Add("imdrain_norm", splitCache[0]);
  127.             auxData.Add("imdrain_night", splitCache[1]);
  128.             auxData.Add("imdrain_hell", splitCache[2]);
  129.             // Chill Effectiveness
  130.             splitCache = SplitAggregateData(secondRowSegments[4]);
  131.             auxData.Add("imchill_norm", splitCache[0]);
  132.             auxData.Add("imchill_night", splitCache[1]);
  133.             auxData.Add("imchill_hell", splitCache[2]);
  134.  
  135.             /**
  136.              * Parse third Row: Physical, Fire, Cold, Lightning, Poison, Magic
  137.              */
  138.             Console.WriteLine("Input Third Row 'Resistances' Data:");
  139.             input = Console.ReadLine();
  140.             string[] thirdRowSegments = input.Split('_');
  141.             // Physical
  142.             splitCache = SplitAggregateData(thirdRowSegments[0]);
  143.             auxData.Add("imdmgres_norm", splitCache[0].Replace("%", ""));
  144.             auxData.Add("imdmgres_night", splitCache[1].Replace("%", ""));
  145.             auxData.Add("imdmgres_hell", splitCache[2].Replace("%", ""));
  146.             // Fire
  147.             splitCache = SplitAggregateData(thirdRowSegments[1]);
  148.             auxData.Add("imfireres_norm", splitCache[0].Replace("%", ""));
  149.             auxData.Add("imfireres_night", splitCache[1].Replace("%", ""));
  150.             auxData.Add("imfireres_hell", splitCache[2].Replace("%", ""));
  151.             // Cold
  152.             splitCache = SplitAggregateData(thirdRowSegments[2]);
  153.             auxData.Add("imcoldres_norm", splitCache[0].Replace("%", ""));
  154.             auxData.Add("imcoldres_night", splitCache[1].Replace("%", ""));
  155.             auxData.Add("imcoldres_hell", splitCache[2].Replace("%", ""));
  156.             // Lightning
  157.             splitCache = SplitAggregateData(thirdRowSegments[3]);
  158.             auxData.Add("imlightres_norm", splitCache[0].Replace("%", ""));
  159.             auxData.Add("imlightres_night", splitCache[1].Replace("%", ""));
  160.             auxData.Add("imlightres_hell", splitCache[2].Replace("%", ""));
  161.             // Poison
  162.             splitCache = SplitAggregateData(thirdRowSegments[4]);
  163.             auxData.Add("impoisres_norm", splitCache[0].Replace("%", ""));
  164.             auxData.Add("impoisres_night", splitCache[1].Replace("%", ""));
  165.             auxData.Add("impoisres_hell", splitCache[2].Replace("%", ""));
  166.             // Magic
  167.             splitCache = SplitAggregateData(thirdRowSegments[5]);
  168.             auxData.Add("immagicres_norm", splitCache[0].Replace("%", ""));
  169.             auxData.Add("immagicres_night", splitCache[1].Replace("%", ""));
  170.             auxData.Add("immagicres_hell", splitCache[2].Replace("%", ""));
  171.  
  172.             /**
  173.              * We need to manually input attack1 and attack2 as well as attackrating1 and attackrating2
  174.              * because there are far too many ways of inputing this data, and it's nearly
  175.              * impossible, if not literally impossible to parse.
  176.              */
  177.             Console.WriteLine("Input Attack1 Damage and Attack Rating");
  178.             Console.WriteLine("Format Hint: 'DamageNormal/DamageNightmare/DamageHell_ARNormal/ARNightmare/ARHell'");
  179.             Console.WriteLine("Format Example: '1-4/1-4/1-4_20/20/20'");
  180.             input = Console.ReadLine();
  181.             string[] attack1DamAndARSegments = input.Split("_");
  182.             // Attack1 Damage
  183.             splitCache = SplitAggregateData(attack1DamAndARSegments[0]);
  184.             auxData.Add("imattack1_norm", splitCache[0].Replace(",", "").Trim());
  185.             auxData.Add("imattack1_night", splitCache[1].Replace(",", "").Trim());
  186.             auxData.Add("imattack1_hell", splitCache[2].Replace(",", "").Trim());
  187.             // Attack1 Attack Rating
  188.             splitCache = SplitAggregateData(attack1DamAndARSegments[1]);
  189.             auxData.Add("imrating1_norm", splitCache[0].Replace(",", "").Trim());
  190.             auxData.Add("imrating1_night", splitCache[1].Replace(",", "").Trim());
  191.             auxData.Add("imrating1_hell", splitCache[2].Replace(",", "").Trim());
  192.  
  193.             Console.WriteLine("Input Attack2 Damage and Attack Rating");
  194.             Console.WriteLine("Format Hint: 'DamageNormal/DamageNightmare/DamageHell_ARNormal/ARNightmare/ARHell'");
  195.             Console.WriteLine("Format Example: '1-4/1-4/1-4_20/20/20'");
  196.             input = Console.ReadLine();
  197.             string[] attack2DamAndARSegments = input.Split("_");
  198.             // Attack1 Damage
  199.             splitCache = SplitAggregateData(attack2DamAndARSegments[0]);
  200.             auxData.Add("imattack2_norm", splitCache[0].Replace(",", "").Trim());
  201.             auxData.Add("imattack2_night", splitCache[1].Replace(",", "").Trim());
  202.             auxData.Add("imattack2_hell", splitCache[2].Replace(",", "").Trim());
  203.             // Attack1 Attack Rating
  204.             splitCache = SplitAggregateData(attack2DamAndARSegments[1]);
  205.             auxData.Add("imrating2_norm", splitCache[0].Replace(",", "").Trim());
  206.             auxData.Add("imrating2_night", splitCache[1].Replace(",", "").Trim());
  207.             auxData.Add("imrating2_hell", splitCache[2].Replace(",", "").Trim());
  208.  
  209.             /**
  210.              * Next, we need to parse for immunities using the data we already gained.
  211.              * If any resistance is greater than or equal to 100, we treat it as an immunity.
  212.              * This seems to be standard in all the tables I looked at.
  213.              */
  214.             Dictionary<string, int> immunities = new Dictionary<string, int>();
  215.  
  216.             string normalImmunity = "0";
  217.             string nightmareImmunity = "0";
  218.             string hellImmunity1 = "0";
  219.             string hellImmunity2 = "0";
  220.  
  221.             foreach (KeyValuePair<string, string> pair in auxData)
  222.             {
  223.                 switch (pair.Key)
  224.                 {
  225.  
  226.                     case "imdmgres_norm":
  227.                     case "immagicres_norm":
  228.                     case "imfireres_norm":
  229.                     case "imcoldres_norm":
  230.                     case "imlightres_norm":
  231.                     case "impoisres_norm":
  232.                         if (normalImmunity.Equals("0"))
  233.                         {
  234.                             if (pair.Value.StartsWith("-"))
  235.                             {
  236.                                 // The resistance is negative
  237.                                 continue;
  238.                             }
  239.                             else
  240.                             {
  241.                                 if (Int32.TryParse(pair.Value, out int normalResistance))
  242.                                 {
  243.                                     if (normalResistance >= 100)
  244.                                     {
  245.                                         switch (pair.Key)
  246.                                         {
  247.                                             case "imdmgres_norm":
  248.                                                 normalImmunity = "Physical";
  249.                                                 break;
  250.                                             case "immagicres_norm":
  251.                                                 normalImmunity = "Magic";
  252.                                                 break;
  253.                                             case "imfireres_norm":
  254.                                                 normalImmunity = "Fire";
  255.                                                 break;
  256.                                             case "imcoldres_norm":
  257.                                                 normalImmunity = "Cold";
  258.                                                 break;
  259.                                             case "imlightres_norm":
  260.                                                 normalImmunity = "Lightning";
  261.                                                 break;
  262.                                             case "impoisres_norm":
  263.                                                 normalImmunity = "Poison";
  264.                                                 break;
  265.                                             default:
  266.                                                 break; // Should never happen.
  267.                                         }
  268.                                     }
  269.                                 }
  270.                             }
  271.                         }
  272.                         break;
  273.                     case "imdmgres_night":
  274.                     case "immagicres_night":
  275.                     case "imfireres_night":
  276.                     case "imcoldres_night":
  277.                     case "imlightres_night":
  278.                     case "impoisres_night":
  279.                         if (nightmareImmunity.Equals("0"))
  280.                         {
  281.                             if (pair.Value.StartsWith("-"))
  282.                             {
  283.                                 // The resistance is negative
  284.                                 continue;
  285.                             }
  286.                             else
  287.                             {
  288.                                 if (Int32.TryParse(pair.Value, out int nightmareResistance))
  289.                                 {
  290.                                     if (nightmareResistance >= 100)
  291.                                     {
  292.                                         switch (pair.Key)
  293.                                         {
  294.                                             case "imdmgres_night":
  295.                                                 nightmareImmunity = "Physical";
  296.                                                 break;
  297.                                             case "immagicres_night":
  298.                                                 nightmareImmunity = "Magic";
  299.                                                 break;
  300.                                             case "imfireres_night":
  301.                                                 nightmareImmunity = "Fire";
  302.                                                 break;
  303.                                             case "imcoldres_night":
  304.                                                 nightmareImmunity = "Cold";
  305.                                                 break;
  306.                                             case "imlightres_night":
  307.                                                 nightmareImmunity = "Lightning";
  308.                                                 break;
  309.                                             case "impoisres_night":
  310.                                                 nightmareImmunity = "Poison";
  311.                                                 break;
  312.                                             default:
  313.                                                 break; // Should never happen.
  314.                                         }
  315.                                     }
  316.                                 }
  317.                             }
  318.                         }
  319.                         break;
  320.                     case "imdmgres_hell":
  321.                     case "immagicres_hell":
  322.                     case "imfireres_hell":
  323.                     case "imcoldres_hell":
  324.                     case "imlightres_hell":
  325.                     case "impoisres_hell":
  326.                         /**
  327.                          * An inherent edge case exists here, because Hell difficulty
  328.                          * is listed as having two possible immunities.
  329.                          */
  330.                         if (pair.Value.StartsWith("-"))
  331.                         {
  332.                             // The resistance is negative
  333.                             continue;
  334.                         }
  335.                         else
  336.                         {
  337.                             if (Int32.TryParse(pair.Value, out int hellResistance))
  338.                             {
  339.                                 if (hellResistance >= 100)
  340.                                 {
  341.                                     switch (pair.Key)
  342.                                     {
  343.                                         case "imdmgres_hell":
  344.                                             if (hellImmunity1.Equals("0"))
  345.                                             {
  346.                                                 hellImmunity1 = "Physical";
  347.                                             }
  348.                                             else
  349.                                             {
  350.                                                 hellImmunity2 = "Physical";
  351.                                             }
  352.                                             break;
  353.                                         case "immagicres_hell":
  354.                                             if (hellImmunity1.Equals("0"))
  355.                                             {
  356.                                                 hellImmunity1 = "Magic";
  357.                                             }
  358.                                             else
  359.                                             {
  360.                                                 hellImmunity2 = "Magic";
  361.                                             }
  362.                                             break;
  363.                                         case "imfireres_hell":
  364.                                             if (hellImmunity1.Equals("0"))
  365.                                             {
  366.                                                 hellImmunity1 = "Fire";
  367.                                             }
  368.                                             else
  369.                                             {
  370.                                                 hellImmunity2 = "Fire";
  371.                                             }
  372.                                             break;
  373.                                         case "imcoldres_hell":
  374.                                             if (hellImmunity1.Equals("0"))
  375.                                             {
  376.                                                 hellImmunity1 = "Cold";
  377.                                             }
  378.                                             else
  379.                                             {
  380.                                                 hellImmunity2 = "Cold";
  381.                                             }
  382.                                             break;
  383.                                         case "imlightres_hell":
  384.                                             if (hellImmunity1.Equals("0"))
  385.                                             {
  386.                                                 hellImmunity1 = "Lightning";
  387.                                             }
  388.                                             else
  389.                                             {
  390.                                                 hellImmunity2 = "Lightning";
  391.                                             }
  392.                                             break;
  393.                                         case "impoisres_hell":
  394.                                             if (hellImmunity1.Equals("0"))
  395.                                             {
  396.                                                 hellImmunity1 = "Poison";
  397.                                             }
  398.                                             else
  399.                                             {
  400.                                                 hellImmunity2 = "Poison";
  401.                                             }
  402.                                             break;
  403.                                         default:
  404.                                             break; // Should never happen.
  405.                                     }
  406.                                 }
  407.                             }
  408.                         }
  409.                         break;
  410.                     default:
  411.                         break;
  412.                 }
  413.             }
  414.  
  415.             /**
  416.              * Add the new immunity data to the auxdata
  417.              */
  418.             auxData.Add("imimm_norm", normalImmunity);
  419.             auxData.Add("imimm_night", nightmareImmunity);
  420.             auxData.Add("imimm_hell", hellImmunity1);
  421.             auxData.Add("imimm_hell2", hellImmunity2);
  422.  
  423.             /**
  424.              * Continue to debugging and then finally generating
  425.              * and printing data out.
  426.              */
  427.  
  428.             if (isDebugging)
  429.             {
  430.                 Console.WriteLine();
  431.                 Console.WriteLine("Printing Debug Log...");
  432.                 foreach (KeyValuePair<string, string> pair in auxData)
  433.                 {
  434.                     Console.WriteLine(pair.Key + " " + pair.Value);
  435.                 }
  436.                 Console.WriteLine("Debug Log Finished.");
  437.  
  438.             }
  439.  
  440.             Console.WriteLine();
  441.             Console.WriteLine("Generating Diablo2.io Markup...");
  442.             ///**
  443.             // * Generate Diablo2.io Markup
  444.             // */
  445.             builder.AppendLine("[zform][form][b]irarity[/b][/form][fbox]Monster (Auxiliary)[/fbox][/zform]");
  446.             builder.AppendLine("[zform][form][b]igraphic[/b][/form][att][attachment=0][/attachment][/att][/zform]");
  447.             foreach (KeyValuePair<string, string> pair in auxData)
  448.             {
  449.                 if (filterNullData)
  450.                 {
  451.                     if (pair.Value.Equals("0"))
  452.                     {
  453.                         continue;
  454.                     }
  455.                 }
  456.                 builder.AppendLine("[zform][form][b]" + pair.Key + "[/b][/form][fbox]" + pair.Value + "[/fbox][/zform]");
  457.             }
  458.  
  459.             Console.WriteLine("Finished generating markup!");
  460.             Console.WriteLine("Printing Diablo2.io Aux Markup!");
  461.             Console.WriteLine(builder.ToString());
  462.         }
  463.     }
  464. }
  465.  
Add Comment
Please, Sign In to add comment