Skip to content

Commit

Permalink
Use Either type library for strength modifier
Browse files Browse the repository at this point in the history
equip models with a knife
  • Loading branch information
mwunsch committed Nov 8, 2016
1 parent 4215c5c commit ac7db0c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion elm-package.json
Expand Up @@ -13,7 +13,8 @@
"elm-lang/keyboard": "1.0.0 <= v < 2.0.0",
"elm-lang/mouse": "1.0.0 <= v < 2.0.0",
"elm-lang/svg": "1.1.0 <= v < 2.0.0",
"elm-lang/window": "1.0.0 <= v < 2.0.0"
"elm-lang/window": "1.0.0 <= v < 2.0.0",
"toastal/either": "2.0.0 <= v < 3.0.0"
},
"elm-version": "0.17.1 <= v < 0.18.0"
}
3 changes: 3 additions & 0 deletions src/Model.elm
Expand Up @@ -24,6 +24,7 @@ import Svg.Attributes exposing (..)
import Tabletop exposing (Position, Inch, posX, posY)
import Utilities exposing (textNode, onClickWithoutPropagation)
import Uuid exposing (Uuid, uuid)
import Weapons exposing (Weapon, knife)


type alias Model =
Expand All @@ -37,6 +38,7 @@ type alias Model =
, id : Id
, fighterType : FighterType
, name : String
, equipment : List Weapon
}


Expand Down Expand Up @@ -186,6 +188,7 @@ init role =
, id = Uuid.scheme
, fighterType = role
, name = "Mac McMadd"
, equipment = [ knife ]
}


Expand Down
25 changes: 18 additions & 7 deletions src/Weapons.elm
@@ -1,6 +1,7 @@
module Weapons exposing (..)

import Tabletop exposing (Inch)
import Either exposing (Either(..))


type Weapon
Expand All @@ -15,37 +16,47 @@ type Weapon
type alias Profile =
{ range : Range
, toHit : ( Maybe Modifier, Maybe Modifier )
, strength : Int
, strength : Either Modifier Int
, damage : Int
, saveModifier : Maybe Modifier
, saveModifier : Modifier
, ammoRoll : Maybe Int
}


type Range
= Close
| Ranged Short Long
| Template
| Ranged ShortRange LongRange


type alias Short =
type alias ShortRange =
( Inch, Inch )


type alias Long =
type alias LongRange =
( Inch, Inch )


{-| For some attributes, like Strength or To Hit, they are a modifier
applied to either the wielders strength or to dice rolls.
-}
type alias Modifier =
Int -> Int


asUser : Modifier
asUser =
(+) 0


knife : Weapon
knife =
Combat
{ range = Close
, toHit = ( Nothing, Nothing )
, strength = 1
, strength = Left asUser
, damage = 1
, saveModifier = Nothing
, saveModifier = asUser
, ammoRoll = Nothing
}

0 comments on commit ac7db0c

Please sign in to comment.