// Calculate funds available public static int getMoney(Thing t) { Thing[] cash = t.getFlaggedContents("IsMoney"); int tot = 0; for (Thing element : cash) { tot += valueOf(element); } return tot; }
public static void removeMoney(Thing person, int amountInCoppers) { if (amountInCoppers <= 0) { addMoney(person, -amountInCoppers); return; } int funds = getMoney(person) - amountInCoppers; Thing[] cash = person.getFlaggedContents("IsMoney"); // TODO: make this spend coins effectively for (Thing element : cash) { element.remove(); } if (funds > 0) { addMoney(person, funds); } }