public void InitiateBuy(InputEventArgs args) { if (args.InputState != InputState.Released) { return; } Console.WriteLine("Initiated buy operation!"); AABB queryRegion = new AABB(Owner.Position.X, Owner.Position.Y - 5f, 32f, 32f); foreach (var proxy in Owner.Game.World.QueryAABB(ref queryRegion)) { GameObject slot = proxy.Client.Owner; if (slot.ContainsTag("ShopSlot")) { Console.WriteLine("Found ShopSlot, lets see if there's anything for sale.."); if (slot.ChildsCount != 0) { Wallet wallet = Owner.FirstComponentOfType <Wallet>(); ItemComponent item = slot.ChildAtIndex(0).FirstComponentOfType <ItemComponent>(); if (wallet.CanAfford(item.Price)) { Console.WriteLine("Can buy {0}, {1} dolans because i have {2} dolans", item.ItemName, item.Price, wallet.Coins); var inventory = Owner.FirstComponentOfType <Inventory>(); if (!inventory.IsFull) { inventory.Add(item.PrepareBuy(Owner)); wallet.RemoveCoins(item.Price); } else { Console.WriteLine("Invi on täynnä!"); } } else { Console.WriteLine("Cant afford to buy {0}, {1} dolans because i have {2} dolans", item.ItemName, item.Price, wallet.Coins); } } else { Console.WriteLine("All gone from " + slot.Name); } return; } } Console.WriteLine("Didn't find anything to buy!"); }