FutureButcherEngine.Player (future_butcher_engine v1.3.0) 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 has_oil set to true. If the player can't afford the oil, or is already holding oil, will return an erro.

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 50% chance of successfully running. Each weapon increases the chance of winning the fight. If the player has essential oil, their chance of successfully running is 100%. 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.

Returns an updated Player struct with has_oil set to false. If the player has no oil, it is a no-op.

Link to this section Types

Specs

player() :: %FutureButcherEngine.Player{
  cash: integer(),
  debt: integer(),
  has_oil: boolean(),
  health: 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_cash(player, atom, amount)

View Source

Specs

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

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

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

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.

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 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

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

Returns an updated Player struct with has_oil set to true. If the player can't afford the oil, or is already holding oil, will return an erro.

## Examples

iex > FutureButcherEngine.Player.buy_oil(%Player{has_oil: true, ...})
{:error, :already_has_oil}

iex > FutureButcherEngine.Player.buy_oil(%Player{cash: 19_999, ...})
{:error, :insufficient_cash}

iex > FutureButcherEngine.Player.buy_oil(%Player{cash: 30_000, has_oil: false, ...})
{:ok, %Player{cash: 10_000, has_oil: true, ...}}
Link to this function

buy_pack(player, new_space, cost)

View Source

Specs

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

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

decrease_health(player, amount)

View Source

Specs

decrease_health(player(), amount :: integer()) ::
  {:ok, player()} | {:error, atom()}

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 50% chance of successfully running. Each weapon increases the chance of winning the fight. If the player has essential oil, their chance of successfully running is 100%. 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{weapon: nil, has_oil: true ...})
  {:ok, %FutureButcherEngine.Player{...}, :victory}

  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

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

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,
  has_oil: false,
  health: 100,
  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 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, ...}}
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 cash.

Specs

restore_health(player()) :: {:ok, player()} | {:error, atom()}
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 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}, ...}}

Specs

use_oil(player()) :: {:ok, player()}

Returns an updated Player struct with has_oil set to false. If the player has no oil, it is a no-op.

## Examples

iex > FutureButcherEngine.Player.use_oil(%Player{has_oil: false, ...})
{:ok, %Player{has_oil: false, ...}}

iex > FutureButcherEngine.Player.use_oil(%Player{has_oil: true, ...})
{:ok, %Player{has_oil: false, ...}}