@verb #1409:"buy" none none none rxdo #8084 @program #1409:"buy" none none none caller_perms() == player || raise(E_PERM) index = player in this.user_objs if (!index) return player:tell("error: not a user of the FO.") endif ui = this.user_info[index] while ((stock = $cmd_utils:read("stock symbol (or ? for a list)")) == "?") data = {} for x in (this.quotes) if (x[2] == -1) x[2] = this:_get_index() endif data = {@data, {x[1], $su:currency(x[2]), x[3]}} endfor data = $list_utils:sort(data, $list_utils:slice(data, 1)) player:tellcolumnsex(2, "lll", {3, 2, 1}, {"Symbol", "Price", "Ticker"}, @data) endwhile if (!(stock = listassoc(stock, this.quotes))) return player:tell("Unrecognized symbol.") endif this:force_update(stock[1]) stock = listassoc(stock[1], this.quotes) price = stock[2] if (price == -1) price = this:_get_index() endif affordable = toint(ui[1] / price) while (tofloat(affordable) * price + tofloat(affordable) * price * 0.02 > ui[1]) affordable = affordable - 1 $cmd_utils:suspend_if_needeD(0) endwhile player:tell("That stock is ", $su:currency(price), " per share (plus 2% commission). You can afford ", $su:group_number(affordable), " shares.") if (ui[1] < price) return endif count = $cmd_utils:read("number of shares to buy") count = toint(count) if (count <= 0) return player:tell("Well, that'd be no good.") elseif (!$cmd_utils:yes_or_no("Commission will be " + $su:currency(comm = tofloat(count) * price * 0.02) + ". Accept?")) return player:tell("Alright.") elseif (tofloat(count) * price + comm > ui[1]) return player:tell("You can't afford the shares and the commission.") endif ui[1] = ui[1] - tofloat(count) * price - comm if (i = listiassoc(stock[1], ui[2])) ui[2][i][2] = ui[2][i][2] + count ui[2][i][3] = ui[2][i][3] + tofloat(count) * price else ui[2] = {@ui[2], {stock[1], count, tofloat(count) * price}} endif this.user_info[index] = ui this.user_info[$smbroker in this.user_objs][1] = this.user_info[$smbroker in this.user_objs][1] + comm fork (0) $smbroker:more_money() endfork player:tell("Purchase complete.") "Last modified by Dax (#789) on Tue May 3 14:09:33 2005 MDT." .