Krythic

Diablo2.io Monster Auxillary Data Generator v1.2

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