public void FeedMoneyTest_HappyRoad() { InventoryReader inventoryReader = new InventoryReader(); Dictionary <string, VendingMachineItem> inventory = inventoryReader.ReadInventory(); VendingMachineBrain happyRoad = new VendingMachineBrain(inventory); happyRoad.FeedMoney(5); Assert.AreEqual(5, happyRoad.Balance, "Balance should be updated to $5."); }
public void FeedMoneyTest_InvalidBill_DoesNotProceed() { InventoryReader inventoryReader = new InventoryReader(); Dictionary <string, VendingMachineItem> inventory = inventoryReader.ReadInventory(); VendingMachineBrain badRoad = new VendingMachineBrain(inventory); badRoad.FeedMoney(8.75M); Assert.AreEqual(0, badRoad.Balance, "Balance should not be updated."); }
/// <summary> /// Vending machine program. /// </summary> /// <param name="args"></param> static void Main(string[] args) { InventoryReader inventoryReader = new InventoryReader(); Dictionary <string, VendingMachineItem> inventory = inventoryReader.ReadInventory(); VendingMachineBrain vm = new VendingMachineBrain(inventory); Logger log = new Logger(vm); MainMenu menu = new MainMenu(vm, log); menu.Run(); }
public void AddToCartTest_ReducesItemQuantity() { InventoryReader inventoryReader = new InventoryReader(); Dictionary <string, VendingMachineItem> inventory = inventoryReader.ReadInventory(); VendingMachineBrain happyRoad = new VendingMachineBrain(inventory); happyRoad.FeedMoney(5); happyRoad.AddToCart("A1"); Assert.AreEqual(4, happyRoad.SeeItemAt("A1").Quantity, "Item quantity should reduce when added to cart."); }
public void AddToCartTest_Functional_AddedItemToCard() { InventoryReader inventoryReader = new InventoryReader(); Dictionary <string, VendingMachineItem> inventory = inventoryReader.ReadInventory(); VendingMachineBrain happyRoad = new VendingMachineBrain(inventory); happyRoad.FeedMoney(5); happyRoad.AddToCart("A1"); Assert.AreEqual(1, happyRoad.Cart.Count, "Item should be added to the shopping cart count."); }
public static void Options(IList <InventoryItem> inventoryList) { Menu options = new Menu() .Add("View Inventory", () => InventoryReader.Read(inventoryList)) .Add("Add an Item", () => InventoryCreator.Create(inventoryList)) .Add("Mature Inventory", () => InventoryMaturer.Mature(inventoryList)) .Add("Load Demo Inventory", () => DemoInventory.Load(inventoryList)) .Add("Exit Program", () => Exit()); options.Display(); }
public void ChargeTest_RemovesProperAmount() { InventoryReader inventoryReader = new InventoryReader(); Dictionary <string, VendingMachineItem> inventory = inventoryReader.ReadInventory(); VendingMachineBrain happyRoad = new VendingMachineBrain(inventory); happyRoad.FeedMoney(5); happyRoad.AddToCart("A1"); happyRoad.Charge(); Assert.AreEqual(1.95M, happyRoad.Balance, "Item added updates the balance"); }
public void ChangeTest_ReturnsBalanceToZero() { InventoryReader inventoryReader = new InventoryReader(); Dictionary <string, VendingMachineItem> inventory = inventoryReader.ReadInventory(); VendingMachineBrain happyRoad = new VendingMachineBrain(inventory); happyRoad.FeedMoney(5); happyRoad.AddToCart("A1"); happyRoad.Charge(); happyRoad.Change(); Assert.AreEqual(0, happyRoad.Balance, "Updates balance to zero."); }
public void ItemSlotAction(List <BodyLocation> slots, Action <ItemReader, D2Unit> action) { if (reader == null) { return; } var inventoryReader = new InventoryReader(reader, memory); // Add all items found in the slots. Func <D2ItemData, bool> filterSlots = data => slots.FindIndex(x => x == data.BodyLoc && data.InvPage == InventoryPage.Equipped) >= 0; foreach (var item in inventoryReader.EnumerateInventory(filterSlots)) { if (action != null) { action(inventoryReader.ItemReader, item); } } }
/// <summary> /// In this section I call 2 seperate methods which collect initial information, the first GetInventory obtains all of the /// inventory informatio which is saved in a CSV file and populates the inventory. The second method obtains all of the items /// that are in the 'shopping basket' which is saved in a textfile. /// </summary> public static void Main(string[] args) { try { Inventory inventory = InventoryReader.GetInventory(); ReceiptDislplay receiptPrinter = new ReceiptDislplay(); var receipt = ShopingBasketReader.GetShoppingBasketInfo(inventory); receiptPrinter.PrintReciept(receipt); } catch (ApplicationException a) { Console.WriteLine(a.Message); } finally { Console.WriteLine("Thank you for shopping at GroceryCo. Press any key to exit"); Console.ReadLine(); } }
private void UpdateAutoSplits(GameInfo gameInfo, Character character) { foreach (AutoSplit autosplit in main.Settings.Autosplits) { if (autosplit.IsReached) { continue; } if (autosplit.Type != AutoSplit.SplitType.Special) { continue; } if (autosplit.Value == (int)AutoSplit.Special.GameStart) { CompleteAutoSplit(autosplit, character); } if (autosplit.Value == (int)AutoSplit.Special.Clear100Percent && character.CompletedQuestCounts[gameInfo.Game.Difficulty] == D2QuestHelper.Quests.Count && autosplit.MatchesDifficulty(gameInfo.Game.Difficulty)) { CompleteAutoSplit(autosplit, character); } if (autosplit.Value == (int)AutoSplit.Special.Clear100PercentAllDifficulties && character.CompletedQuestCounts[0] == D2QuestHelper.Quests.Count && character.CompletedQuestCounts[1] == D2QuestHelper.Quests.Count && character.CompletedQuestCounts[2] == D2QuestHelper.Quests.Count) { CompleteAutoSplit(autosplit, character); } } bool haveUnreachedCharLevelSplits = false; bool haveUnreachedAreaSplits = false; bool haveUnreachedItemSplits = false; bool haveUnreachedQuestSplits = false; foreach (AutoSplit autosplit in main.Settings.Autosplits) { if (autosplit.IsReached || !autosplit.MatchesDifficulty(gameInfo.Game.Difficulty)) { continue; } switch (autosplit.Type) { case AutoSplit.SplitType.CharLevel: haveUnreachedCharLevelSplits = true; break; case AutoSplit.SplitType.Area: haveUnreachedAreaSplits = true; break; case AutoSplit.SplitType.Item: haveUnreachedItemSplits = true; break; case AutoSplit.SplitType.Quest: haveUnreachedQuestSplits = true; break; } } // if no unreached splits, return if (!(haveUnreachedCharLevelSplits || haveUnreachedAreaSplits || haveUnreachedItemSplits || haveUnreachedQuestSplits)) { return; } List <int> itemsIds = new List <int>(); int area = -1; if (haveUnreachedItemSplits) { // Get all item IDs. var inventoryReader = new InventoryReader(reader, memory); itemsIds = (from item in inventoryReader.EnumerateInventory() select item.eClass).ToList(); } if (haveUnreachedAreaSplits) { area = reader.ReadByte(memory.Address.Area, AddressingMode.Relative); } ushort[] questBuffer = null; if (haveUnreachedQuestSplits) { questBuffer = GetQuestBuffer(gameInfo.PlayerData, gameInfo.Game.Difficulty); } foreach (AutoSplit autosplit in main.Settings.Autosplits) { if (autosplit.IsReached || !autosplit.MatchesDifficulty(gameInfo.Game.Difficulty)) { continue; } switch (autosplit.Type) { case AutoSplit.SplitType.CharLevel: if (autosplit.Value <= character.Level) { CompleteAutoSplit(autosplit, character); } break; case AutoSplit.SplitType.Area: if (autosplit.Value == area) { CompleteAutoSplit(autosplit, character); } break; case AutoSplit.SplitType.Item: if (itemsIds.Contains(autosplit.Value)) { CompleteAutoSplit(autosplit, character); } break; case AutoSplit.SplitType.Quest: if (D2QuestHelper.IsQuestComplete((D2QuestHelper.Quest)autosplit.Value, questBuffer)) { CompleteAutoSplit(autosplit, character); } break; } } }
public void UpdateItemStats(ProcessMemoryReader r, D2MemoryTable memory, D2Unit pl) { InventoryReader inventoryReader = new InventoryReader(r, memory); UnitReader unitReader = new UnitReader(r, memory); // Build filter to get only equipped items. Func <D2ItemData, bool> filter = data => data.BodyLoc != BodyLocation.None; foreach (D2Unit item in inventoryReader.EnumerateInventory(filter)) { List <D2Stat> itemStats = unitReader.GetStats(item); if (itemStats == null) { continue; } StringBuilder statBuilder = new StringBuilder(); statBuilder.Append(inventoryReader.ItemReader.GetFullItemName(item)); statBuilder.Append("\n"); List <string> magicalStrings = inventoryReader.ItemReader.GetMagicalStrings(item); foreach (string str in magicalStrings) { statBuilder.Append(" "); statBuilder.Append(str); statBuilder.Append("\n"); } Control c = null; D2ItemData itemData = r.Read <D2ItemData>(item.UnitData); switch (itemData.BodyLoc) { case BodyLocation.Head: c = tabPageHead; break; case BodyLocation.Amulet: c = tabPageAmulet; break; case BodyLocation.BodyArmor: c = tabPageBody; break; case BodyLocation.PrimaryRight: c = tabPageWeaponRight; break; case BodyLocation.PrimaryLeft: c = tabPageWeaponLeft; break; case BodyLocation.RingRight: c = tabPageRingRight; break; case BodyLocation.RingLeft: c = tabPageRingLeft; break; //case BodyLocation.SecondaryLeft: c = tabPageRingRight; break; //case BodyLocation.SecondaryRight: c = tabPageRingLeft; break; case BodyLocation.Belt: c = tabPageBelt; break; case BodyLocation.Boots: c = tabPageFeet; break; case BodyLocation.Gloves: c = tabPageHand; break; } if (c != null) { if (c.Controls.Count == 0) { c.Invoke(new Action(delegate() { c.Controls.Add(new RichTextBox()); c.Controls[0].Dock = DockStyle.Fill; })); } c.Controls[0].Invoke(new Action(() => c.Controls[0].Text = statBuilder.ToString())); } } }
public static bool HasResources(this InventoryReader inventory) { return(inventory.Data.Resources > 0); }
void ClearReaderCache() { unitReader = new UnitReader(reader, memory); inventoryReader = new InventoryReader(reader, memory); }
bool InitializeGameDataReaders() { try { reader = new ProcessMemoryReader(DiabloProcessName, DiabloModuleName, DiabloSubModules); } catch (ProcessNotFoundException) { CleanUpDataReaders(); } if (reader == null) { try { reader = new ProcessMemoryReader(D2SEProcessName, D2SEModuleName, DiabloSubModules); } catch (ProcessNotFoundException) { CleanUpDataReaders(); } } if (reader == null) { return(false); } try { memory = CreateGameMemoryTableForReader(reader); unitReader = new UnitReader(reader, memory); inventoryReader = new InventoryReader(reader, memory); Logger.Info($"Found the Diablo II process (version {reader.FileVersion})."); return(true); } catch (ModuleNotLoadedException e) { Logger.Error($"Diablo II Process was found, but the module {e.ModuleName} was not yet loaded. Try launching a game."); CleanUpDataReaders(); return(false); } catch (GameVersionUnsupportedException e) { Logger.Error($"Diablo II Process was found, but the version {e.GameVersion} is not supported."); CleanUpDataReaders(); return(false); } catch (ProcessMemoryReadException) { Logger.Error("Diablo II Process was found but failed to read memory."); CleanUpDataReaders(); return(false); } void CleanUpDataReaders() { reader?.Dispose(); reader = null; memory = null; unitReader = null; inventoryReader = null; } }