Advertisement
Moolah60

Animal Island Floating Item Logic

Jul 15th, 2022
1,218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.55 KB | None | 0 0
  1. namespace AnimalIslandBalloonPredictor
  2. {
  3.     internal static class Logic
  4.     {
  5.         private static readonly string[] Names = {
  6.             "Fossils",
  7.             "Furniture",
  8.             "Gyroids",
  9.             "Apples",
  10.             "Oranges",
  11.             "Peaches",
  12.             "Pears",
  13.             "Cherries",
  14.             "Turnips",
  15.             "Mushrooms",
  16.             "Candy",
  17.             "100 Bells",
  18.             "Chest (Seedlings, Diaries, Tickets, & Grab Bags)",
  19.             "Signboards",
  20.             "Shirts",
  21.             "Trash",
  22.             "Pitfall",
  23.             "Conch Shell",
  24.             "Lion's Paw Shell",
  25.             "Coral",
  26.             "Purple Cosmos",
  27.             "Blue Cosmos",
  28.             "Yellow Cosmos",
  29.             "Red Tulips",
  30.             "White Tulips",
  31.             "Yellow Tulips",
  32.             "White Pansies",
  33.             "Purple Pansies",
  34.             "Yellow Pansies",
  35.             "Flower Leaves",
  36.             "Coconuts",
  37.             "Player Cabana",
  38.             "Islander House",
  39.             "Saplings",
  40.             "Small Trees",
  41.             "Medium Trees",
  42.             "Large Trees",
  43.             "Fully Grown Trees",
  44.             "Dead Saplings",
  45.             "Apple Trees",
  46.             "Orange Trees",
  47.             "Peach Trees",
  48.             "Pear Trees",
  49.             "Cherry Trees",
  50.             "Small Stumps",
  51.             "Medium Stumps",
  52.             "Large Stumps",
  53.             "Fully Grown Stumps",
  54.             "Palm Saplings",
  55.             "Small Palm Trees",
  56.             "Medium Palm Trees",
  57.             "Large Palm Trees",
  58.             "Palm Trees",
  59.             "Dead Palm Saplings",
  60.             "Palm Trees with Coconuts",
  61.             "Small Palm Stumps",
  62.             "Medium Palm Stumps",
  63.             "Large Palm Stumps",
  64.             "Fully Grown Palm Stumps",
  65.             "Island Flagpole",
  66.             "Holes",
  67.             "Buried Pitfalls",
  68.             "Cedar Saplings",
  69.             "Dead Cedar Saplings",
  70.             "Weeds",
  71.             "Rocks",
  72.             "1,000 Bell Bags",
  73.             "10,000 Bell Bags",
  74.             "30,000 Bell Bags",
  75.             "Nets",
  76.             "Golden Nets",
  77.             "Axes",
  78.             "Golden Axes",
  79.             "Shovels",
  80.             "Golden Shovels",
  81.             "Fishing Rods",
  82.             "Golden Rods",
  83.             "Umbrellas",
  84.             "Paint Cans",
  85.             "Balloons",
  86.             "Pinwheels",
  87.             "Fans",
  88.             "Carpets",
  89.             "Wallpaper",
  90.             "K.K. Airchecks",
  91.             "NES Games",
  92.             "Flower Bags",
  93.             "Reserved Tile"
  94.         };
  95.  
  96.         private sealed class ItemGenerationGroup
  97.         {
  98.             private readonly ushort item_no;
  99.             private readonly byte tile_no;
  100.             private readonly byte unk;
  101.             private readonly string? name;
  102.  
  103.             public ItemGenerationGroup(ushort ino, byte tno, byte u, string? n = null)
  104.             {
  105.                 item_no = ino;
  106.                 tile_no = tno;
  107.                 unk = u;
  108.                 name = n;
  109.             }
  110.  
  111.             public string Name => name ?? Names[tile_no];
  112.         }
  113.  
  114.         private static readonly ushort[][] rngTable = new ushort[160][]
  115.         {
  116.             new ushort[]{ 0x0001, 0x0016 }, new ushort[]{ 0x0052, 0x001a }, new ushort[]{ 0x0053, 0x001c }, new ushort[]{ 0x000e, 0x001e }, new ushort[]{ 0x0000, 0x0000 },
  117.             new ushort[]{ 0x000b, 0x0008 }, new ushort[]{ 0x001e, 0x0005 }, new ushort[]{ 0x0042, 0x0009 }, new ushort[]{ 0x004d, 0x0022 }, new ushort[]{ 0x0000, 0x0000 },
  118.             new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0000, 0x0000 },
  119.             new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0000, 0x0000 },
  120.  
  121.             new ushort[]{ 0x0001, 0x0017 }, new ushort[]{ 0x0052, 0x001b }, new ushort[]{ 0x0053, 0x001d }, new ushort[]{ 0x000e, 0x001f }, new ushort[]{ 0x0000, 0x0000 },
  122.             new ushort[]{ 0x0042, 0x0009 }, new ushort[]{ 0x0009, 0x0006 }, new ushort[]{ 0x0043, 0x000a }, new ushort[]{ 0x004d, 0x0022 }, new ushort[]{ 0x0000, 0x0000 },
  123.             new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0000, 0x0000 },
  124.             new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0000, 0x0000 },
  125.  
  126.             new ushort[]{ 0x0043, 0x000a }, new ushort[]{ 0x0007, 0x0004 }, new ushort[]{ 0x000b, 0x0008 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x0000, 0x0000 },
  127.             new ushort[]{ 0x0042, 0x0009 }, new ushort[]{ 0x0007, 0x0004 }, new ushort[]{ 0x000b, 0x0008 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x0000, 0x0000 },
  128.             new ushort[]{ 0x000b, 0x0008 }, new ushort[]{ 0x0007, 0x0004 }, new ushort[]{ 0x000b, 0x0008 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x0000, 0x0000 },
  129.             new ushort[]{ 0x000b, 0x0008 }, new ushort[]{ 0x0007, 0x0004 }, new ushort[]{ 0x000b, 0x0008 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x0000, 0x0000 },
  130.  
  131.             new ushort[]{ 0x0044, 0x000b }, new ushort[]{ 0x0009, 0x0006 }, new ushort[]{ 0x0042, 0x0009 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x0000, 0x0000 },
  132.             new ushort[]{ 0x0043, 0x000a }, new ushort[]{ 0x0009, 0x0006 }, new ushort[]{ 0x0042, 0x0009 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x0000, 0x0000 },
  133.             new ushort[]{ 0x0042, 0x0009 }, new ushort[]{ 0x0009, 0x0006 }, new ushort[]{ 0x000b, 0x0008 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x0000, 0x0000 },
  134.             new ushort[]{ 0x0042, 0x0009 }, new ushort[]{ 0x0009, 0x0006 }, new ushort[]{ 0x000b, 0x0008 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x0000, 0x0000 },
  135.  
  136.             new ushort[]{ 0x0002, 0x0021 }, new ushort[]{ 0x0001, 0x0017 }, new ushort[]{ 0x000e, 0x001f }, new ushort[]{ 0x004d, 0x0022 }, new ushort[]{ 0x0000, 0x0000 },
  137.             new ushort[]{ 0x0001, 0x0016 }, new ushort[]{ 0x0052, 0x001a }, new ushort[]{ 0x0053, 0x001c }, new ushort[]{ 0x000e, 0x001e }, new ushort[]{ 0x0000, 0x0000 },
  138.             new ushort[]{ 0x000e, 0x001e }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000e, 0x001e }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x0000, 0x0000 },
  139.             new ushort[]{ 0x000e, 0x001e }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000e, 0x001e }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x0000, 0x0000 },
  140.  
  141.             new ushort[]{ 0x0001, 0x0019 }, new ushort[]{ 0x0001, 0x0018 }, new ushort[]{ 0x0002, 0x0021 }, new ushort[]{ 0x000e, 0x001f }, new ushort[]{ 0x0000, 0x0000 },
  142.             new ushort[]{ 0x0001, 0x0017 }, new ushort[]{ 0x0052, 0x001b }, new ushort[]{ 0x0053, 0x001d }, new ushort[]{ 0x000e, 0x001f }, new ushort[]{ 0x0000, 0x0000 },
  143.             new ushort[]{ 0x000e, 0x001e }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000e, 0x001e }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x0000, 0x0000 },
  144.             new ushort[]{ 0x000e, 0x001e }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000e, 0x001e }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x0000, 0x0000 },
  145.  
  146.             new ushort[]{ 0x0001, 0x0018 }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0000, 0x0000 },
  147.             new ushort[]{ 0x0001, 0x0017 }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0000, 0x0000 },
  148.             new ushort[]{ 0x0001, 0x0016 }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0000, 0x0000 },
  149.             new ushort[]{ 0x0001, 0x0016 }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0000, 0x0000 },
  150.  
  151.             new ushort[]{ 0x0055, 0x0024 }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0000, 0x0000 },
  152.             new ushort[]{ 0x0001, 0x0019 }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0000, 0x0000 },
  153.             new ushort[]{ 0x0001, 0x0017 }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0000, 0x0000 },
  154.             new ushort[]{ 0x0001, 0x0017 }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0010, 0x000c }, new ushort[]{ 0x000f, 0x0025 }, new ushort[]{ 0x0000, 0x0000 }
  155.         };
  156.  
  157.         private static readonly ItemGenerationGroup[] grps =
  158.         {
  159.             new ItemGenerationGroup(0x2800, 0x03, 0x00), // 00
  160.             new ItemGenerationGroup(0x2804, 0x04, 0x00), // 01
  161.             new ItemGenerationGroup(0x2803, 0x05, 0x00), // 02
  162.             new ItemGenerationGroup(0x2802, 0x06, 0x00), // 03
  163.             new ItemGenerationGroup(0x2801, 0x07, 0x00), // 04
  164.             new ItemGenerationGroup(0x2807, 0x1e, 0x00), // 05
  165.             new ItemGenerationGroup(0x2805, 0x09, 0x00), // 06
  166.             new ItemGenerationGroup(0x2806, 0x0a, 0x00), // 07
  167.             new ItemGenerationGroup(0x2103, 0x0b, 0x00), // 08
  168.             new ItemGenerationGroup(0x2100, 0x42, 0x00), // 09
  169.             new ItemGenerationGroup(0x2101, 0x43, 0x00), // 0A
  170.             new ItemGenerationGroup(0x2102, 0x44, 0x00), // 0B
  171.             new ItemGenerationGroup(0x2512, 0x10, 0x00), // 0C
  172.             new ItemGenerationGroup(0x0849, 0x56, 0x00), // 0D
  173.             new ItemGenerationGroup(0x084a, 0x56, 0x00), // 0E
  174.             new ItemGenerationGroup(0x0848, 0x56, 0x00), // 0F
  175.             new ItemGenerationGroup(0x084b, 0x56, 0x00), // 10
  176.             new ItemGenerationGroup(0x084c, 0x56, 0x00), // 11
  177.             new ItemGenerationGroup(0x084d, 0x56, 0x00), // 12
  178.             new ItemGenerationGroup(0x0845, 0x56, 0x00), // 13
  179.             new ItemGenerationGroup(0x0846, 0x56, 0x00), // 14
  180.             new ItemGenerationGroup(0x0847, 0x56, 0x00), // 15
  181.             new ItemGenerationGroup(0x0000, 0x01, 0x01, "Common Furniture"), // 16
  182.             new ItemGenerationGroup(0x0001, 0x01, 0x01, "Rare Furniture"), // 17
  183.             new ItemGenerationGroup(0x0002, 0x01, 0x01, "50/50 Lottery/Event Furniture"), // 18
  184.             new ItemGenerationGroup(0x0003, 0x01, 0x01, "Island Furniture"), // 19
  185.             new ItemGenerationGroup(0x0009, 0x52, 0x01, "Common Carpet"), // 1A
  186.             new ItemGenerationGroup(0x000a, 0x52, 0x01, "Rare Carpet"), // 1B
  187.             new ItemGenerationGroup(0x000b, 0x53, 0x01, "Common Wallpaper"), // 1C
  188.             new ItemGenerationGroup(0x000c, 0x53, 0x01, "Rare Wallpaper"), // 1D
  189.             new ItemGenerationGroup(0x000d, 0x0e, 0x01, "Common Clothes"), // 1E
  190.             new ItemGenerationGroup(0x000e, 0x0e, 0x01, "Rare Clothes"), // 1F
  191.             new ItemGenerationGroup(0x0005, 0x00, 0x01, "50/50 Single-part Fossil/Multi-part Fossil"), // 20
  192.             new ItemGenerationGroup(0x0007, 0x02, 0x01, "Gyroid"), // 21
  193.             new ItemGenerationGroup(0x0008, 0x4d, 0x01, "Umbrella"), // 22
  194.             new ItemGenerationGroup(0x0006, 0x54, 0x01, "K.K. Aircheck"), // 23
  195.             new ItemGenerationGroup(0x0004, 0x55, 0x01, "Island NES"),  // 24
  196.             new ItemGenerationGroup(0x0011, 0x0f, 0x01, "Trash") // 25
  197.         };
  198.  
  199.         private static readonly int[] hour_adjust =
  200.         {
  201.             0, 0, 0, 0,
  202.             0, 0, 1, 1,
  203.             1, 2, 2, 2,
  204.             3, 3, 3, 4,
  205.             4, 4, 5, 5,
  206.             5, 6, 6, 6
  207.         };
  208.  
  209.         private static readonly int[] mood_adjust =
  210.         {
  211.             0x5, 0x15, 0xA, 0x0
  212.         };
  213.  
  214.         private static readonly int[] villager_adjust =
  215.         {
  216.             1, 1, 1, 0,
  217.             1, 1, 0, 0,
  218.             1, 1, 0, 0,
  219.             1, 0, 1, 0,
  220.             0, 1
  221.         };
  222.  
  223.         private static readonly ushort[] base_index_adjust =
  224.         {
  225.             0x0000, 0x0078, 0x0028, 0x0050, 0x0000, 0x0050, 0x0000, 0x0000, 0x0078, 0x0028,
  226.             0x0028, 0x0028, 0x0000, 0x0050, 0x0000, 0x0028, 0x0050, 0x0028, 0x0078, 0x0028,
  227.             0x0000, 0x0000, 0x0050, 0x0028, 0x0000, 0x0000, 0x0078, 0x0050, 0x0000, 0x0028,
  228.             0x0078, 0x0028, 0x0050, 0x0000, 0x0028, 0x0000, 0x0000, 0x0050, 0x0078, 0x0028,
  229.             0x0028, 0x0028, 0x0000, 0x0050, 0x0028, 0x0050, 0x0078, 0x0000, 0x0000, 0x0000,
  230.             0x0050, 0x0050, 0x0028, 0x0000, 0x0078, 0x0000, 0x0000, 0x0028, 0x0050, 0x0000,
  231.             0x0078, 0x0028, 0x0028, 0x0000, 0x0028, 0x0050, 0x0000, 0x0078, 0x0000, 0x0050,
  232.             0x0000, 0x0028, 0x0050, 0x0000, 0x0078, 0x0000, 0x0078, 0x0000, 0x0028, 0x0078,
  233.             0x0028, 0x0000, 0x0050, 0x0028, 0x0000, 0x0000, 0x0078, 0x0028, 0x0050, 0x0028,
  234.             0x0028, 0x0000, 0x0078, 0x0000, 0x0028, 0x0000, 0x0050, 0x0078, 0x0000, 0x0078,
  235.             0x0050, 0x0028, 0x0000, 0x0078, 0x0000, 0x0000, 0x0000, 0x0050, 0x0078, 0x0050,
  236.             0x0028, 0x0000, 0x0000, 0x0000, 0x0000, 0x0050, 0x0028, 0x0078, 0x0050, 0x0000,
  237.             0x0028, 0x0050, 0x0028, 0x0078, 0x0028, 0X0000
  238.         };
  239.  
  240.         public static Dictionary<string, float> GetPercentages(int islanderIdx, int hour, int mood_group, bool goldenShovel)
  241.         {
  242.             Dictionary<string, float> percentages = new();
  243.  
  244.             if (mood_group == 0)
  245.             {
  246.                 mood_group = 2 - villager_adjust[islanderIdx];
  247.             }
  248.             else if (mood_group == 1)
  249.             {
  250.                 mood_group = 0;
  251.             }
  252.             else
  253.             {
  254.                 mood_group = 3;
  255.             }
  256.  
  257.             int base_ofs = base_index_adjust[islanderIdx * 7 + hour_adjust[hour]] + mood_adjust[mood_group];
  258.             if (goldenShovel)
  259.             {
  260.                 base_ofs += 20;
  261.             }
  262.  
  263.             if (base_ofs >= 160)
  264.             {
  265.                 base_ofs = 0;
  266.             }
  267.  
  268.             for (int i = 0; i < 4; i++) // i < 5
  269.             {
  270.                 ushort val = rngTable[base_ofs + i][1];
  271.  
  272.                 string s = val == 4 ? "Random Fruit" : grps[val].Name;
  273.  
  274.                 if (percentages.ContainsKey(s))
  275.                 {
  276.                     percentages[s]++;
  277.                 }
  278.                 else
  279.                 {
  280.                     percentages.Add(s, 1);
  281.                 }
  282.             }
  283.  
  284.             foreach (var kv in percentages)
  285.             {
  286.                 //percentages[kv.Key] = (kv.Value / 5.0f) * 100.0f;
  287.                 percentages[kv.Key] = (kv.Value / 4.0f) * 100.0f;
  288.             }
  289.  
  290.             return percentages;
  291.         }
  292.     }
  293. }
  294.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement