FutureButcherEngine.Player (future_butcher_engine v1.0.1) View Source
Player modules creates player, handles buying/selling of cuts and weapons, debt and health 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 cash increased or decreased by the passed in amount.
Returns an adjusted Player struct with either cash reduced by 10% to 30% if player cash exceed $500, or an owned cut zeroed out.
Returns an updated Player struct with reduced cash and an increased cut in the pack map.
Returns an updated Player struct with increased pack size and reduced cash.
Returns an updated Player struct with a new weapon and adjusted cash.
Returns an updated Player struct with the health field decreased by the passed-in amount.
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. If the player's health drops to 0 or below, will return a game-ending outcome.
Returns a new Player struct with starting values and an initialized pack.
Returns an updated Player struct with zeroed-out debt and decreased cash.
Returns an updated Player struct with a different weapon and adjusted cash.
Returns an updated Player struct with increased cash 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 cash increased or decreased by the passed in amount.
## Examples
iex > FutureButcherEngine.Player.adjust_cash(%Player{cash: 5000, ...}, :increase, 1000)
%FutureButcherEngine.Player{cash: 6000, ...}
iex > FutureButcherEngine.Player.adjust_cash(%Player{cash: 5000, ...}, :decrease, 1000)
%FutureButcherEngine.Player{cash: 4000, ...}
Specs
Returns an adjusted Player struct with either cash reduced by 10% to 30% if player cash exceed $500, or an owned cut zeroed out.
Returns an error tuple if player cash 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 cash and an increased cut in the pack map.
Returns an error tuple if the buy cost is greater than player cash.
Examples
iex > FutureButcherEngine.Player.buy_cut(%Player{cash: 5000, pack: %{}, ...}, :heart, 5, 1000)
{:ok, %FutureButcherEngine.Player{cash: 4000, pack: %{heart: 5}, ...}}
Specs
Returns an updated Player struct with increased pack size and reduced cash.
Returns an error tuple if either the pack cost is greater than player cash, or the new pack size is not greater than the current pack size.
Examples
iex > FutureButcherEngine.Player.buy_pack(%Player{cash: 5000, pack_space: 20, ...}, 30, 1000)
{:ok, FutureButcherEngine.Player%{cash: 4000, pack_space: 30, ...}}
iex > FutureButcherEngine.Player.buy_pack(%Player{cash: 1000, ...}, 30, 2000)
{:error, :insufficient_cash}
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 cash.
Returns an error tuple if weapon cost is greater than player cash, or player already owns weapon.
Examples
iex > FutureButcherEngine.Player.buy_weapon(%Player{cash: 5000, weapon: nil, ...}, :axe, 1000)
{:ok, %FutureButcherEngine.Player{cash: 4000, weapon: :axe, ...}}
iex > FutureButcherEngine.Player.buy_weapon(%Player{cash: 5000, weapon: :knife, ...}, :axe, 1000)
{:error, :already_owns_weapon}
iex > FutureButcherEngine.Player.buy_weapon(%Player{cash: 1000, weapon: nil, ...}, :axe, 2000)
{:error, :insufficient_cash}
Returns an updated Player struct with the health field decreased by the passed-in amount.
Examples
iex > FutureButcherEngine.Player.decrease_health(%Player{health: 20}, 30)
{:ok, FutureButcherEngine.Player%{health: -10, ...}}
Specs
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. If the player's health drops to 0 or below, will return a game-ending outcome.
## 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}
iex > FutureButcherEngine.Player.fight_mugger(%Player{health: 20})
{:ok, %FutureButcherEngine.Player{health: -10}, :death}
Specs
Returns a new Player struct with starting values and an initialized pack.
Returns an error tuple if player_name
is invalid.
Examples
iex > FutureButcherEnging.Player.new("bob")
%FutureButcherEngine.Player{
cash: 5000,
debt: 5000,
health: 100,
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 cash.
Returns an error tuple if the debt amount to repay is greater than player cash.
Examples
iex > FutureButcherEngine.Player.pay_debt(%Player{debt: 5000, cash: 7000 ...})
{:ok, %FutureButcherEngine.Player{debt: 0, cash: 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 cash.
Specs
Specs
sell_cut(player(), cut :: atom(), amount :: integer(), profit :: integer()) :: {:ok, player()} | {:error, atom()}
Returns an updated Player struct with increased cash 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{cash: 5000, pack: %{heart: 5}, ...}, :heart, 3, 1000)
{:ok, %FutureButcherEngine.Player{cash: 5000, pack: %{heart: 2}, ...}}