|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Text; |
| 4 | +using System.IO; |
| 5 | +using System.Linq; |
| 6 | +using Newtonsoft.Json; |
| 7 | +namespace Tappy_UI.ViewModels |
| 8 | +{ |
| 9 | + public class MainWindowViewModel : ViewModelBase |
| 10 | + { |
| 11 | + public string Greeting => "Welcome to Avalonia!"; |
| 12 | + |
| 13 | + public void ButtonClicked() { |
| 14 | + Random random = new Random(); |
| 15 | + Console.WriteLine("Tappy | Tappable Loot Table Generation System"); |
| 16 | + |
| 17 | + /* Load Data Files */ |
| 18 | + Console.WriteLine("Loading data files"); |
| 19 | + Directory.CreateDirectory("./inputdata"); |
| 20 | + string[] files = Directory.GetFiles("./inputdata", "*.json"); |
| 21 | + Directory.CreateDirectory("./outputdata"); |
| 22 | + foreach (string filePath in files) |
| 23 | + { |
| 24 | + Utils.TableData tableData = JsonConvert.DeserializeObject<Utils.TableData>(File.ReadAllText(filePath)); |
| 25 | + Console.WriteLine("Processing Tappable Data for tappable type " + tableData.tappableID); |
| 26 | + Utils.TappableLootTable resultLootTable = new Utils.TappableLootTable(); |
| 27 | + resultLootTable.possibleDropSets ??= new List<List<string>>(); |
| 28 | + resultLootTable.tappableID = tableData.tappableID; |
| 29 | + //we generate 100 dropTables (no, not Bobby Tables drop tables) |
| 30 | + for (int i = 0; i < 100; i++) |
| 31 | + { |
| 32 | + List<string> rewards = new List<string>(); |
| 33 | + //how many do we want |
| 34 | + int numRewards = random.Next(tableData.minItemsPerTap, tableData.maxItemsPerTap); |
| 35 | + Console.WriteLine("Set " + i + " Will have " + numRewards + " rewards."); |
| 36 | + for (int i2 = 0; i2 < numRewards; i2++) |
| 37 | + { |
| 38 | + while (true) |
| 39 | + { |
| 40 | + //we get a random item from the table |
| 41 | + int randIndex = random.Next(0, tableData.percentages.Count); |
| 42 | + var targetItem = tableData.percentages.ElementAt(randIndex); |
| 43 | + //try and add it based on percentage |
| 44 | + int roll = random.Next(0, 100); |
| 45 | + Console.WriteLine("Got role of " + roll + " for item with percentage " + targetItem.Value + " Target item: " + targetItem.Key); |
| 46 | + if (targetItem.Value <= roll || targetItem.Value == 100) |
| 47 | + { |
| 48 | + Console.WriteLine("Added item to rewards"); |
| 49 | + rewards.Add(targetItem.Key); |
| 50 | + break; |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + //Add our rewards to the main loot table |
| 55 | + resultLootTable.possibleDropSets.Add(rewards); |
| 56 | + } |
| 57 | + //Now we save it |
| 58 | + string table = JsonConvert.SerializeObject(resultLootTable); |
| 59 | + // Console.WriteLine(table); |
| 60 | + File.WriteAllText("./outputdata/" + resultLootTable.tappableID.Split(":")[1] + ".json", table); |
| 61 | + } |
| 62 | + Console.WriteLine("Done! "); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments