FutureButcherEngine.Player (future_butcher_engine v0.3.0) View Source
Player module handles buying/selling cuts, weapons; debt; muggings Player modules creates player, handles buying/selling of cuts and weapons, debt management, and muggings.
Link to this section Summary
Functions
Returns an updated Player struct with a higher debt amount. Debt increases by 5% each turn.
Returns an adjusted Player struct with funds increased or decreased by the passed in amount.
Returns an adjusted Player struct with either funds reduced by 10% to 30% if player funds exceed $500, or an owned cut zeroed out.
Returns an updated Player struct with reduced funds and an increased cut in the pack map.
Returns an updated Player struct with increased pack size and reduced funds.
Returns an updated Player struct with a new weapon and adjusted funds.
Returns an updated Player struct with no weapon, or returns an error tuple if no weapon is owned.
Returns an updated Player struct adjusted on the outcome of the fight. When the player has no weapon, they have a 20% chance of successfully running.
Returns a new Player struct with a starting values and an initialized pack.
Returns an updated Player struct with zeroed-out debt and decreased funds.
Returns an updated Player struct with a different weapon and adjusted funds.
Returns an updated Player struct with increased funds and a reduced cut in the pack map.
Link to this section Types
Specs
Link to this section Functions
Specs
Returns an updated Player struct with a higher debt amount. Debt increases by 5% each turn.
Returns an unchanged Player struct when debt is 0.
Examples
iex > FutureButcherEngine.Player.accrue_debt(%Player{debt: 5000, ...}, 5)
{:ok, %FutureButcherEngine.Player{debt: 6381, ...}}
Specs
Returns an adjusted Player struct with funds increased or decreased by the passed in amount.
## Examples
iex > FutureButcherEngine.Player.adjust_funds(%Player{funds: 5000, ...}, :increase, 1000)
%FutureButcherEngine.Player{funds: 6000, ...}
iex > FutureButcherEngine.Player.adjust_funds(%Player{funds: 5000, ...}, :decrease, 1000)
%FutureButcherEngine.Player{funds: 4000, ...}
Specs
Returns an adjusted Player struct with either funds reduced by 10% to 30% if player funds exceed $500, or an owned cut zeroed out.
Returns an error tuple if player funds are under $500 and no cuts are owned.
Specs
buy_cut(player(), cut :: atom(), amount :: integer(), cost :: integer()) :: {:ok, player()} | {:error, atom()}
Returns an updated Player struct with reduced funds and an increased cut in the pack map.
Returns an error tuple if the buy cost is greater than player funds.
Examples
iex > FutureButcherEngine.Player.buy_cut(%Player{funds: 5000, pack: %{}, ...}, :heart, 5, 1000)
{:ok, %FutureButcherEngine.Player{funds: 4000, pack: %{heart: 5}, ...}}
Specs
Returns an updated Player struct with increased pack size and reduced funds.
Returns an error tuple if either the pack cost is greater than player funds, or the new pack size is not greater than the current pack size.
Examples
iex > FutureButcherEngine.Player.buy_pack(%Player{funds: 5000, pack_space: 20, ...}, 30, 1000)
{:ok, FutureButcherEngine.Player%{funds: 4000, pack_space: 30, ...}}
iex > FutureButcherEngine.Player.buy_pack(%Player{funds: 1000, ...}, 30, 2000)
{:error, :insufficient_funds}
iex > FutureButcherEngine.Player.buy_pack(%Player{pack_space: 30, ...}, 20, 1000)
{:error, :must_upgrade_pack}
Specs
Returns an updated Player struct with a new weapon and adjusted funds.
Returns an error tuple if weapon cost is greater than player funds, or player already owns weapon.
Examples
iex > FutureButcherEngine.Player.buy_weapon(%Player{funds: 5000, weapon: nil, ...}, :axe, 1000)
{:ok, %FutureButcherEngine.Player{funds: 4000, weapon: :axe, ...}}
iex > FutureButcherEngine.Player.buy_weapon(%Player{funds: 5000, weapon: :knife, ...}, :axe, 1000)
{:error, :already_owns_weapon}
iex > FutureButcherEngine.Player.buy_weapon(%Player{funds: 1000, weapon: nil, ...}, :axe, 2000)
{:error, :insufficient_funds}
Specs
Returns an updated Player struct with no weapon, or returns an error tuple if no weapon is owned.
Specs
Returns an updated Player struct adjusted on the outcome of the fight. When the player has no weapon, they have a 20% chance of successfully running.
## Examples
iex > FutureButcherEngine.Player.fight_mugger(%Player{weapon: nil, ...})
{:ok, %FutureButcherEngine.Player{...}, :defeat}
iex > FutureButcherEngine.Player.fight_mugger(%Player{pack: %{heart: 1, ...}, weapon: :machete, ...})
{:ok, %FutureButcherEngine.Player{pack: %{heart: 2}}, :victory}
Specs
Returns a new Player struct with a starting values and an initialized pack.
Returns an error tuple if player_name
is invalid.
Examples
iex > FutureButcherEnging.Player.new("bob")
%FutureButcherEngine.Player{
debt: 5000,
funds: 5000,
pack: %{brains: 0, flank: 0, heart: 0, liver: 0, ribs: 0},
pack_space: 20,
player_name: "bob",
weapon: nil}
Specs
Returns an updated Player struct with zeroed-out debt and decreased funds.
Returns an error tuple if the debt amount to repay is greater than player funds.
Examples
iex > FutureButcherEngine.Player.pay_debt(%Player{debt: 5000, funds: 7000 ...})
{:ok, %FutureButcherEngine.Player{debt: 0, funds: 2000, ...}}
Specs
replace_weapon( player(), weapon :: atom(), cost :: integer(), value :: integer() ) :: {:ok, player()} | {:error, atom()}
Returns an updated Player struct with a different weapon and adjusted funds.
Specs
sell_cut(player(), cut :: atom(), amount :: integer(), profit :: integer()) :: {:ok, player()} | {:error, atom()}
Returns an updated Player struct with increased funds and a reduced cut in the pack map.
Returns an error tuple if the sell amount is greater than the cut owned.
Examples
iex > FutureButcherEngine.Player.sell_cut(%Player{funds: 5000, pack: %{heart: 5}, ...}, :heart, 3, 1000)
{:ok, %FutureButcherEngine.Player{funds: 5000, pack: %{heart: 2}, ...}}