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

player() :: %FutureButcherEngine.Player{
  debt: integer(),
  funds: integer(),
  pack: map(),
  pack_space: integer(),
  player_name: String.t(),
  weapon: atom() | nil
}

Link to this section Functions

Link to this function

accrue_debt(player, turns)

View Source

Specs

accrue_debt(player(), turns :: integer()) :: {:ok, player()} | {:error, atom()}

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, ...}}
Link to this function

adjust_funds(player, atom, amount)

View Source

Specs

adjust_funds(player(), direction :: atom(), amount :: integer()) ::
  {:ok, player()}

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

bribe_mugger(player()) :: {:ok, player()} | {:error, atom()}

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.

Link to this function

buy_cut(player, cut, amount, cost)

View Source

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}, ...}}
Link to this function

buy_pack(player, new_space, cost)

View Source

Specs

buy_pack(player(), funds :: integer(), cost :: integer()) ::
  {:ok, player()} | {:error, atom()}

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}
Link to this function

buy_weapon(player, weapon, cost)

View Source

Specs

buy_weapon(player(), weapon :: atom(), cost :: integer()) ::
  {:ok, player()} | {:error, atom()}

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

drop_weapon(player()) :: {:ok, player()} | {:error, atom()}

Returns an updated Player struct with no weapon, or returns an error tuple if no weapon is owned.

Specs

fight_mugger(player()) :: {:ok, player(), outcome :: atom()}

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

new(player_name :: String.t()) :: player() | {:error, atom()}

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

pay_debt(player()) :: {:ok, player()} | {:error, atom()}

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, ...}}
Link to this function

replace_weapon(player, weapon, cost, value)

View Source

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.

Link to this function

sell_cut(player, cut, amount, profit)

View Source

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}, ...}}