Coin Functions for Mocha


Handling coin objects

Coin objects come in several varieties. In Mocha, a coin type must be one of the following constants:
The default_coin should be used whenever a generic value is given to a player. Note that the object member function value returns the value of any object in the default coin. The default is currently obsidian.

boolean obj.is_coins;
Returns true if the object obj is coins.

integer obj.coin_type;
Returns the type of a coin object (one of the coin types listed above).

integer obj.num_coins;
Returns the number of coins in a coin object.

integer coin_type_value (integer type);
Returns the value of a single coin in the default coin.

string coin_name (integer type);
Returns the name of a coin type (e.g., "gold").

object make_coins (integer type, integer amt);
Creates a coin object of the given type. The value of the object must fall between 1 and 8000 default coins.


Counting the value of coins

integer pc.coins;
Returns the total value of coins in the person pc's purse in units of the default coin.

integer pc.total_coins;
Returns the total value of coins owned by the person pc in units of the default coin.

integer value_contents (entity ent, integer type, integer pct);
Returns the value of all objects of type type inside of ent in the default coin and scaled by a percentage from 1 to 100. If anything is used as the type, the function totals the value of all objects inside of ent. For person entities, this function checks the inventory.

integer value_stack (entity ent, integer type, integer pct);
Returns the value of all objects of type type on top of ent in the default coin and scaled by a percentage from 1 to 100. If anything is used as the type, the function totals the value of all objects on top of ent. For person entities, this function checks the equipment.


Giving and taking coins

integer give_coins (person pc, integer amt, integer style);
Gives pc coins of total value amt (in the default coin), putting them into coin bags if necessary. The coins given are in the lightest form possible. One of the following constants must be given for the style:
The function returns the number of coins received by the pc (not counting coins in bags).

void take_coins (person pc, integer amt);
Takes coins valued at amt default coins from the pc's purse. No extra action is taken if the pc's purse lacks sufficient coins.

void take_total_coins (person pc, integer amt);
Takes coins valued at amt default coins from the pc, first from the purse, then from coins in containers in the inventory, and finally from coins in containers in the equipment. No extra action is taken if the pc lacks sufficient coins.

void take_contents (entity ent, integer type, integer pct, integer amt);
Takes objects of type type valued at at least amt default coins from inside ent. The value of each object is first scaled by a percentage from 1 to 100. Cheaper items are taken before more expensive ones, and any change on objects taken is returned to the pc's purse in coin, provided that the pc can carry the coins. If anything is used as the type, the function selects from all objects inside of ent. For person entities, this function checks the inventory.

void take_stack (entity ent, integer type, integer pct, integer amt);
Takes objects of type type valued at at least amt default coins from on top of ent. The value of each object is first scaled by a percentage from 1 to 100. Cheaper items are taken before more expensive ones, and any change on objects taken is returned to the pc's purse in coin, provided that the pc can carry the coins. If anything is used as the type, the function selects fr(garbage text deleted)