Skip to content

Commit

Permalink
Add basic recruitment logic for Player
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunsch committed Oct 17, 2016
1 parent cb00d47 commit 9f6e839
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Gang.elm
Expand Up @@ -27,6 +27,11 @@ get =
Dict.get


add : Model -> Gang -> Gang
add model gang =
Dict.insert model.id model gang


map : (Id -> Model -> Model) -> Gang -> Gang
map =
Dict.map
Expand Down
16 changes: 16 additions & 0 deletions src/Model.elm
Expand Up @@ -149,6 +149,22 @@ init =
}


cost : Model -> Int
cost model =
case model.fighterType of
Leader ->
120

Ganger ->
50

Heavy ->
60

Juve ->
25


generator : Generator Model
generator =
uuid
Expand Down
34 changes: 34 additions & 0 deletions src/Player.elm
Expand Up @@ -10,6 +10,7 @@ type alias Player =
{ gang : Gang
, selection : Maybe Model.Id
, movementIntention : Position
, credits : Int
}


Expand All @@ -18,6 +19,7 @@ init table =
{ gang = Gang.empty
, selection = Nothing
, movementIntention = Tabletop.center table
, credits = 1000
}


Expand All @@ -44,3 +46,35 @@ deselectAll player =
getSelectedGangMember : Player -> Maybe Model
getSelectedGangMember player =
player.selection `andThen` (flip Gang.get) player.gang


{-| From the rulebook:
> You have 1000 Guilder credits to spend on recruiting and arming your
gang within the following guidelines.
+ Minimum 3 Fighers: A gang must have at least three models.
+ Leader: your gang must have one leader. Not more. Not less!
+ Gangers: You can include as many gangers as you can afford.
+ Heavies: A gang can have up to two heavies but no more.
+ Juves: No more than half the gang can be made up of juves.
+ Knifes: All fighters are assumed to have a knife even if the model doesn't have one.
-}
recruit : Model -> Player -> Maybe Player
recruit model player =
let
cost =
Model.cost model

remainingCredits =
player.credits - cost
in
if remainingCredits >= 0 then
Just
{ player
| credits = remainingCredits
, gang = Gang.add model player.gang
}
else
Nothing

0 comments on commit 9f6e839

Please sign in to comment.