s.printError("Invalid selection") } } else { index := utils.BestMatch(arg, items.Names()) if index == -1 { s.printError("Not found") } else if index == -2 { s.printError("Which one do you mean?") } else { item = items[index] } } if item != nil { confirmed := s.getConfirmation(fmt.Sprintf("Buy %s for %v? ", item.GetName(), item.GetValue())) if confirmed { // TODO - Transferring the item and money should be guarded by some kind of global session transaction if item.SetContainerId(s.pc.GetId(), store.GetId()) { s.pc.RemoveCash(item.GetValue()) store.AddCash(item.GetValue()) s.WriteLineColor(types.ColorGreen, "Bought %s", item.GetName()) } else { s.printError("Transaction failed") } } else { s.printError("Purchase canceled") } } },