Skip to content

Commit

Permalink
Equipped left/right hand
Browse files Browse the repository at this point in the history
  • Loading branch information
Janiczek committed Oct 1, 2024
1 parent 5725281 commit d28e64a
Show file tree
Hide file tree
Showing 18 changed files with 378 additions and 700 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
"\\bclassList[\\s\\[\\(]+\"[^\"]*\",\\s[^\\)]+\\)[\\s\\[\\(,]+\"[^\"]*\",\\s[^\\)]+\\)[\\s\\[\\(,]+\"([^\"]*)\"",
],
"elmLS.elmPath": "lamdera",
"elmLS.elmReviewDiagnostics": "warning"
"elmLS.elmReviewDiagnostics": "warning",
"files.exclude": {
"src/Evergreen": true
}
}
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
SEED ?= "$$RANDOM"
FUZZ ?= "100"

.PHONY: watch
watch:
elmid --watched-folder=src src/DummyMain.elm

.PHONY: start
start:
lamdera live
Expand Down
45 changes: 23 additions & 22 deletions src/Admin.elm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Dict
import Dict.ExtraExtra as Dict
import Json.Decode as JD exposing (Decoder)
import Json.Encode as JE
import Logic
import Queue
import Random
import Set.ExtraExtra as Set
Expand All @@ -35,30 +34,12 @@ encodeBackendModel model =
backendModelDecoder : Random.Seed -> Decoder BackendModel
backendModelDecoder seed =
JD.oneOf
[ backendModelDecoderV2 seed
, backendModelDecoderV1 seed
[ backendModelDecoderV1 seed
]


backendModelDecoderV1 : Random.Seed -> Decoder BackendModel
backendModelDecoderV1 seed =
JD.map
(\world ->
{ worlds = Dict.singleton Logic.mainWorldName world
, loggedInPlayers = BiDict.empty
, time = Time.millisToPosix 0
, adminLoggedIn = Nothing
, lastTenToBackendMsgs = Queue.empty
, randomSeed = seed
, playerDataCache = Dict.empty
}
)
World.decoder


backendModelDecoderV2 : Random.Seed -> Decoder BackendModel
backendModelDecoderV2 seed =
-- adds support for multiple worlds
JD.map
(\worlds ->
{ worlds = worlds
Expand Down Expand Up @@ -118,16 +99,36 @@ encodeToBackendMsg msg =
JE.object
[ ( "type", JE.string "Wander" ) ]

EquipItem itemId ->
EquipArmor itemId ->
JE.object
[ ( "type", JE.string "EquipItem" )
[ ( "type", JE.string "EquipArmor" )
, ( "itemId", JE.int itemId )
]

EquipLeftHand itemId ->
JE.object
[ ( "type", JE.string "EquipLeftHand" )
, ( "itemId", JE.int itemId )
]

EquipRightHand itemId ->
JE.object
[ ( "type", JE.string "EquipRightHand" )
, ( "itemId", JE.int itemId )
]

UnequipArmor ->
JE.object
[ ( "type", JE.string "UnequipArmor" ) ]

UnequipLeftHand ->
JE.object
[ ( "type", JE.string "UnequipLeftHand" ) ]

UnequipRightHand ->
JE.object
[ ( "type", JE.string "UnequipRightHand" ) ]

SetFightStrategy ( strategy, text ) ->
JE.object
[ ( "type", JE.string "SetFightStrategy" )
Expand Down
82 changes: 75 additions & 7 deletions src/Backend.elm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import Queue
import Random exposing (Generator)
import Random.List
import SeqDict exposing (SeqDict)
import SeqSet exposing (SeqSet)
import SeqSet
import Set exposing (Set)
import Task
import Time exposing (Posix)
Expand Down Expand Up @@ -854,12 +854,24 @@ updateFromFrontend sessionId clientId msg model =
Wander ->
withLoggedInCreatedPlayer wander

EquipItem itemId ->
withLoggedInCreatedPlayer <| equipItem itemId
EquipArmor itemId ->
withLoggedInCreatedPlayer <| equipArmor itemId

EquipLeftHand itemId ->
withLoggedInCreatedPlayer <| equipLeftHand itemId

EquipRightHand itemId ->
withLoggedInCreatedPlayer <| equipRightHand itemId

UnequipArmor ->
withLoggedInCreatedPlayer unequipArmor

UnequipLeftHand ->
withLoggedInCreatedPlayer unequipLeftHand

UnequipRightHand ->
withLoggedInCreatedPlayer unequipRightHand

SetFightStrategy ( strategy, text ) ->
withLoggedInCreatedPlayer <| setFightStrategy ( strategy, text )

Expand Down Expand Up @@ -1404,16 +1416,48 @@ healMe clientId _ worldName player model =
|> sendCurrentWorld worldName player.name clientId


equipItem : Item.Id -> ClientId -> World -> World.Name -> SPlayer -> Model -> ( Model, Cmd BackendMsg )
equipItem itemId clientId _ worldName player model =
equipArmor : Item.Id -> ClientId -> World -> World.Name -> SPlayer -> Model -> ( Model, Cmd BackendMsg )
equipArmor itemId clientId _ worldName player model =
case Dict.get itemId player.items of
Nothing ->
( model, Cmd.none )

Just item ->
if Item.isArmor item.kind then
model
|> updatePlayer worldName player.name (SPlayer.equipArmor item)
|> sendCurrentWorld worldName player.name clientId

else
( model, Cmd.none )


equipLeftHand : Item.Id -> ClientId -> World -> World.Name -> SPlayer -> Model -> ( Model, Cmd BackendMsg )
equipLeftHand itemId clientId _ worldName player model =
case Dict.get itemId player.items of
Nothing ->
( model, Cmd.none )

Just item ->
if Item.isHandEquippable item.kind then
model
|> updatePlayer worldName player.name (SPlayer.equipLeftHand item)
|> sendCurrentWorld worldName player.name clientId

else
( model, Cmd.none )


equipRightHand : Item.Id -> ClientId -> World -> World.Name -> SPlayer -> Model -> ( Model, Cmd BackendMsg )
equipRightHand itemId clientId _ worldName player model =
case Dict.get itemId player.items of
Nothing ->
( model, Cmd.none )

Just item ->
if Item.isEquippable item.kind then
if Item.isHandEquippable item.kind then
model
|> updatePlayer worldName player.name (SPlayer.equipItem item)
|> updatePlayer worldName player.name (SPlayer.equipRightHand item)
|> sendCurrentWorld worldName player.name clientId

else
Expand Down Expand Up @@ -1512,6 +1556,30 @@ unequipArmor clientId _ worldName player model =
|> sendCurrentWorld worldName player.name clientId


unequipLeftHand : ClientId -> World -> World.Name -> SPlayer -> Model -> ( Model, Cmd BackendMsg )
unequipLeftHand clientId _ worldName player model =
case player.equippedLeftHand of
Nothing ->
( model, Cmd.none )

Just _ ->
model
|> updatePlayer worldName player.name SPlayer.unequipLeftHand
|> sendCurrentWorld worldName player.name clientId


unequipRightHand : ClientId -> World -> World.Name -> SPlayer -> Model -> ( Model, Cmd BackendMsg )
unequipRightHand clientId _ worldName player model =
case player.equippedRightHand of
Nothing ->
( model, Cmd.none )

Just _ ->
model
|> updatePlayer worldName player.name SPlayer.unequipRightHand
|> sendCurrentWorld worldName player.name clientId


wander : ClientId -> World -> World.Name -> SPlayer -> Model -> ( Model, Cmd BackendMsg )
wander clientId world worldName player model =
let
Expand Down
69 changes: 60 additions & 9 deletions src/Calculator/Meta/Individual.elm
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ healingItemKindGenerator =
Random.uniform x xs


itemKindGenerator : Generator Item.Kind
itemKindGenerator =
let
( x, xs ) =
Item.allNonempty
in
Random.uniform x xs


shotTypeGenerator : Generator ShotType
shotTypeGenerator =
Random.uniform ShotType.NormalShot
Expand All @@ -79,15 +88,54 @@ shotTypeGenerator =

conditionGenerator : Generator FightStrategy.Condition
conditionGenerator =
let
self =
Random.lazy (\() -> conditionGenerator)
in
Random.uniform
(FightStrategy.Operator
{ value = FightStrategy.MyHP
, op = FightStrategy.LT_
, number_ = 50
}
(Random.map3
(\lhs op rhs ->
FightStrategy.Operator
{ lhs = lhs
, op = op
, rhs = rhs
}
)
valueGenerator
operatorGenerator
valueGenerator
)
[ FightStrategy.OpponentIsPlayer
, FightStrategy.OpponentIsNPC
[ Random.constant FightStrategy.OpponentIsPlayer
, Random.constant FightStrategy.OpponentIsNPC
, Random.map2 FightStrategy.Or self self
, Random.map2 FightStrategy.And self self
]
|> Random.andThen identity


valueGenerator : Generator FightStrategy.Value
valueGenerator =
Random.uniform
(Random.constant FightStrategy.MyHP)
[ Random.constant FightStrategy.MyMaxHP
, Random.constant FightStrategy.MyAP
, Random.map FightStrategy.MyItemCount itemKindGenerator
, Random.map FightStrategy.ItemsUsed itemKindGenerator
, Random.map FightStrategy.ChanceToHit shotTypeGenerator
, Random.constant FightStrategy.Distance
, Random.map FightStrategy.Number (Random.int -50 300)
]
|> Random.andThen identity


operatorGenerator : Generator FightStrategy.Operator
operatorGenerator =
Random.uniform FightStrategy.LT_
[ FightStrategy.LTE
, FightStrategy.EQ_
, FightStrategy.NE
, FightStrategy.GTE
, FightStrategy.GT_
]


Expand Down Expand Up @@ -130,9 +178,9 @@ moveForwardIfNeeded strategy =
FightStrategy.If
{ condition =
FightStrategy.Operator
{ value = FightStrategy.Distance
{ lhs = FightStrategy.Distance
, op = FightStrategy.GT_
, number_ = 0
, rhs = FightStrategy.Number 0
}
, then_ = FightStrategy.Command FightStrategy.MoveForward
, else_ = strategy
Expand Down Expand Up @@ -477,6 +525,9 @@ mutateFightStrategy str =
FightStrategy.MoveForward ->
Random.constant FightStrategy.MoveForward

FightStrategy.SkipTurn ->
Random.constant FightStrategy.SkipTurn

FightStrategy.DoWhatever ->
Random.constant FightStrategy.DoWhatever

Expand Down
11 changes: 1 addition & 10 deletions src/Data/Auth.elm
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,12 @@ encodePassword password =
verifiedDecoder : Decoder (Auth Verified)
verifiedDecoder =
JD.oneOf
[ verifiedDecoderV2
, verifiedDecoderV1
[ verifiedDecoderV1
]


verifiedDecoderV1 : Decoder (Auth Verified)
verifiedDecoderV1 =
JD.succeed Auth
|> JD.andMap (JD.field "name" JD.string)
|> JD.andMap (JD.field "password" verifiedPasswordDecoder)
|> JD.andMap (JD.succeed Logic.mainWorldName)


verifiedDecoderV2 : Decoder (Auth Verified)
verifiedDecoderV2 =
JD.succeed Auth
|> JD.andMap (JD.field "name" JD.string)
|> JD.andMap (JD.field "password" verifiedPasswordDecoder)
Expand Down
Loading

0 comments on commit d28e64a

Please sign in to comment.