Skip to content

Commit

Permalink
feat: affinity card pass
Browse files Browse the repository at this point in the history
  • Loading branch information
dennyabrain committed Nov 21, 2024
1 parent 915ae63 commit 90ee4ba
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
12 changes: 6 additions & 6 deletions lib/viral_spiral/canon/deck.ex
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,13 @@ defmodule ViralSpiral.Canon.Deck do
id: "card_01J69V12V7D5A1"
```
"""
def draw_card(set, opts) do
type = opts[:type]
veracity = opts[:veracity]
tgb = opts[:tgb]
target = opts[:target]
def draw_card(set, draw_type) do
type = draw_type[:type]
veracity = draw_type[:veracity]
tgb = draw_type[:tgb]
target = draw_type[:target]

case opts[:type] do
case draw_type[:type] do
:topical ->
set[{type, veracity}] |> filter_tgb(tgb) |> choose_one

Expand Down
9 changes: 5 additions & 4 deletions lib/viral_spiral/room/actions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ defmodule ViralSpiral.Room.Actions do
%Action{type: :draw_card, payload: %{draw_type: draw_type}}
end

@spec pass_card(String.t(), String.t(), String.t() | list(String.t())) :: Action.t()
def pass_card(card, from, to) when is_bitstring(to) or is_list(to) do
# @spec pass_card(String.t(), String.t(), String.t() | list(String.t())) :: Action.t()
def pass_card(card, veracity, from, to) when is_bitstring(to) or is_list(to) do
%Action{
type: :pass_card,
payload: %{
card: card,
veracity: veracity,
player: from,
target: to
}
}
end

def pass_card(%{"card" => card, "from" => from, "to" => to}) do
pass_card(card, from, to)
def pass_card(%{"card" => card, "veracity" => veracity, "from" => from, "to" => to}) do
pass_card(card, veracity, from, to)
end

def keep_card(card, from) do
Expand Down
21 changes: 8 additions & 13 deletions lib/viral_spiral/room/reducer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,15 @@ defmodule ViralSpiral.Room.Reducer do
State.apply_changes(state, changes)
end

def reduce(%State{} = state, %{type: pass_card} = action) do
%{card: card_id, player: from, target: to} = action
card = card_id
# card = store[card_id]
changes = Playable.pass(card, state, from, to)
def reduce(%State{} = state, %{type: :pass_card} = action) do
%{card: card_id, veracity: veracity, player: from, target: to} = action.payload
card = state.deck.store[{card_id, veracity}]

changes ++
[
{state.players[from], [type: :clout, offset: 1]},
{state.players[from], [type: :bias, target: card.target, offset: 1]}
] ++
(Map.keys(state.players)
|> Enum.filter(&(state.players[&1].identity == card.target))
|> Enum.map(&{state.players[&1], [type: :clout, offset: -1]}))
changes =
Playable.pass(card, state, from, to) ++
[{state.players[to], ChangeDescriptions.add_to_active(card_id)}]

State.apply_changes(state, changes)
end

def reduce(%State{} = state, %{type: discard_card} = action) do
Expand Down
41 changes: 27 additions & 14 deletions test/viral_spiral/reducers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,37 @@ defmodule ViralSpiral.ReducersTest do
end
end

# describe "pass card" do
# setup do
# :rand.seed(:exsss, {12356, 123_534, 345_345})
describe "pass card" do
setup do
:rand.seed(:exsss, {12356, 123_534, 345_345})

# room = Room.reserve("test-room") |> Room.start(4)
# state = State.new(room, ["adhiraj", "krys", "aman", "farah"])
room = Room.reserve("test-room") |> Room.start(4)
state = State.new(room, ["adhiraj", "krys", "aman", "farah"])

# %{state: state}
# end
players = StoreFixtures.player_by_names(state)

# test "passing an affinity card should increase player's clout", %{state: state} do
# sets = state.deck.available_cards
# type = [type: :affinity, veracity: true, tgb: 0, target: :skub]
# card_id = Deck.draw_card(sets, type)
%{state: state, players: players}
end

# IO.inspect(card_id)
# end
# end
test "passing affinity card", %{state: state, players: players} do
sets = state.deck.available_cards
store = state.deck.store
%{aman: aman, adhiraj: adhiraj} = players

draw_type = [type: :affinity, veracity: true, tgb: 2, target: :skub]
draw_result = Deck.draw_card(sets, draw_type)
card = store[{draw_result.id, true}]

new_state =
Reducer.reduce(state, Actions.pass_card(card.id, card.veracity, aman.id, adhiraj.id))

assert new_state.players[aman.id].affinities[:skub] == 1
assert new_state.players[aman.id].clout == 1
assert new_state.players[adhiraj.id].active_cards |> length == 1
assert new_state.turn.current == adhiraj.id
assert new_state.turn.pass_to |> length() == 2
end
end

# @tag timeout: :infinity
# test "temp" do
Expand Down

0 comments on commit 90ee4ba

Please sign in to comment.