Skip to content

Commit 4839de3

Browse files
committed
Add quest exclusivity checking
1 parent bc2b4a7 commit 4839de3

File tree

5 files changed

+104
-27
lines changed

5 files changed

+104
-27
lines changed

nuashworld-before-enclave.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/Backend.elm

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ getPlayerData_ worldName world player =
226226
|> Maybe.map (Tuple.first >> (+) 1)
227227
-- TODO find this info in a non-Maybe way?
228228
|> Maybe.withDefault 1
229+
230+
playerName =
231+
player
232+
|> Player.getPlayerData
233+
|> Maybe.map .name
229234
in
230235
{ worldName = worldName
231236
, description = world.description
@@ -274,15 +279,24 @@ getPlayerData_ worldName world player =
274279

275280
ticksGivenByPlayer : Int
276281
ticksGivenByPlayer =
277-
player
278-
|> Player.getPlayerData
279-
|> Maybe.andThen (\{ name } -> Dict.get name ticksGivenPerPlayer)
282+
playerName
283+
|> Maybe.andThen (\name -> Dict.get name ticksGivenPerPlayer)
280284
|> Maybe.withDefault 0
281285
in
282286
{ ticksGiven = ticksGiven
283287
, ticksPerHour = ticksPerHour
284288
, playersActive = engagedPlayersCount
285289
, ticksGivenByPlayer = ticksGivenByPlayer
290+
, alreadyPaidRequirements =
291+
playerName
292+
|> Maybe.map
293+
(\name ->
294+
world.questRequirementsPaid
295+
|> SeqDict.get quest
296+
|> Maybe.withDefault Set.empty
297+
|> Set.member name
298+
)
299+
|> Maybe.withDefault False
286300
}
287301
)
288302
, questRewardShops = world.questRewardShops
@@ -475,7 +489,7 @@ processGameTickForQuests worldName model =
475489
| questsProgress =
476490
SeqDict.map
477491
(\quest progressPerPlayer ->
478-
if World.isQuestDone_ quest progressPerPlayer then
492+
if World.isQuestDone_ progressPerPlayer quest then
479493
progressPerPlayer
480494

481495
else
@@ -515,8 +529,8 @@ processGameTickForQuests worldName model =
515529
Quest.all
516530
|> List.filter
517531
(\quest ->
518-
not (World.isQuestDone quest oldWorld)
519-
&& World.isQuestDone quest newWorld
532+
not (World.isQuestDone oldWorld quest)
533+
&& World.isQuestDone newWorld quest
520534
)
521535
|> SeqSet.fromList
522536
)
@@ -2327,14 +2341,13 @@ stopProgressing quest clientId _ worldName player model =
23272341

23282342
startProgressing : Quest.Name -> ClientId -> World -> World.Name -> SPlayer -> Model -> ( Model, Cmd BackendMsg )
23292343
startProgressing quest clientId world worldName player model =
2330-
-- TODO: check for exclusivity with already completed quest
23312344
let
23322345
locationQuestAllowed : Bool
23332346
locationQuestAllowed =
23342347
quest
23352348
|> Quest.location
23362349
|> Quest.locationQuestRequirements
2337-
|> List.all (\requiredQuest -> World.isQuestDone requiredQuest world)
2350+
|> List.all (\requiredQuest -> World.isQuestDone world requiredQuest)
23382351

23392352
playerRequirements : List Quest.PlayerRequirement
23402353
playerRequirements =
@@ -2351,8 +2364,34 @@ startProgressing quest clientId world worldName player model =
23512364
playerCanPayRequirements =
23522365
playerRequirements
23532366
|> List.all (\req -> Logic.passesPlayerRequirement req player)
2367+
2368+
completedQuests : SeqSet Quest.Name
2369+
completedQuests =
2370+
world.questsProgress
2371+
|> SeqDict.toList
2372+
|> List.filterMap
2373+
(\( quest_, progress ) ->
2374+
let
2375+
given =
2376+
progress
2377+
|> Dict.values
2378+
|> List.sum
2379+
in
2380+
if Quest.ticksNeeded quest_ <= given then
2381+
Just quest_
2382+
2383+
else
2384+
Nothing
2385+
)
2386+
|> SeqSet.fromList
2387+
2388+
isExclusiveWithCompletedQuest : Bool
2389+
isExclusiveWithCompletedQuest =
2390+
completedQuests
2391+
|> SeqSet.toList
2392+
|> List.any (\completedQuest -> Quest.isExclusiveWith completedQuest quest)
23542393
in
2355-
if locationQuestAllowed && (playerAlreadyPaidRequirements || playerCanPayRequirements) then
2394+
if locationQuestAllowed && (playerAlreadyPaidRequirements || playerCanPayRequirements) && not isExclusiveWithCompletedQuest then
23562395
let
23572396
ensurePlayerPresent : World -> World
23582397
ensurePlayerPresent world_ =
@@ -2377,7 +2416,7 @@ startProgressing quest clientId world worldName player model =
23772416
world_
23782417

23792418
newModel =
2380-
if World.isQuestDone quest world then
2419+
if World.isQuestDone world quest then
23812420
model
23822421

23832422
else

src/Data/Quest.elm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Data.Quest exposing
1212
, exclusiveWith
1313
, globalRewardTitle
1414
, globalRewards
15+
, isExclusiveWith
1516
, location
1617
, locationQuestRequirements
1718
, playerRequirementTitle
@@ -203,6 +204,7 @@ type alias Progress =
203204
, ticksPerHour : Int
204205
, ticksGiven : Int
205206
, ticksGivenByPlayer : Int
207+
, alreadyPaidRequirements : Bool
206208
}
207209

208210

@@ -2044,8 +2046,7 @@ playerRewards name =
20442046
]
20452047

20462048
DenFreeVicByPayingMetzger ->
2047-
[ ItemReward { what = ItemKind.SawedOffShotgun, amount = 1 }
2048-
, ItemReward { what = ItemKind.ShotgunShell, amount = 40 }
2049+
[ ItemReward { what = ItemKind.Stimpak, amount = 40 }
20492050
]
20502051

20512052
DenFreeVicByKillingOffSlaversGuild ->
@@ -3250,3 +3251,9 @@ decoder =
32503251
_ ->
32513252
JD.fail <| "Unknown quest name: '" ++ string ++ "'"
32523253
)
3254+
3255+
3256+
isExclusiveWith : Name -> Name -> Bool
3257+
isExclusiveWith quest1 quest2 =
3258+
exclusiveWith quest1
3259+
|> List.member quest2

src/Data/World.elm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,16 @@ decoder =
179179
|> JD.andMap (JD.field "questRequirementsPaid" (SeqDict.decoder Quest.decoder (JD.set JD.string)))
180180

181181

182-
isQuestDone : Quest.Name -> World -> Bool
183-
isQuestDone quest world =
182+
isQuestDone : World -> Quest.Name -> Bool
183+
isQuestDone world quest =
184184
world.questsProgress
185185
|> SeqDict.get quest
186186
|> Maybe.withDefault Dict.empty
187-
|> isQuestDone_ quest
187+
|> (\perPlayer -> isQuestDone_ perPlayer quest)
188188

189189

190-
isQuestDone_ : Quest.Name -> Dict PlayerName Int -> Bool
191-
isQuestDone_ quest perPlayer =
190+
isQuestDone_ : Dict PlayerName Int -> Quest.Name -> Bool
191+
isQuestDone_ perPlayer quest =
192192
Dict.values perPlayer
193193
|> List.sum
194194
|> (\sum -> sum >= Quest.ticksNeeded quest)

src/Frontend.elm

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ update msg ({ loginForm } as model) =
217217
( model, Cmd.none )
218218
in
219219
case msg of
220+
AskToTemporaryFinishQuest quest ->
221+
( model, Lamdera.sendToBackend (TemporaryFinishQuest quest) )
222+
223+
AskToTemporaryMaxOutTicks ->
224+
( model, Lamdera.sendToBackend TemporaryMaxOutTicks )
225+
220226
GoToRoute route ->
221227
let
222228
finalRoute =
@@ -1693,6 +1699,13 @@ townMainSquareView expandedQuests location { questsProgress, questRewardShops }
16931699
hasMaxTicks : Bool
16941700
hasMaxTicks =
16951701
player.ticks >= Tick.limit
1702+
1703+
isQuestDone : Quest.Name -> Bool
1704+
isQuestDone quest =
1705+
questsProgress
1706+
|> SeqDict.get quest
1707+
|> Maybe.map (\p -> p.ticksGiven >= Quest.ticksNeeded quest)
1708+
|> Maybe.withDefault False
16961709
in
16971710
[ pageTitleView <| "Town: " ++ Location.name location
16981711
, H.div [ HA.class "flex flex-col gap-4" ]
@@ -1724,6 +1737,7 @@ townMainSquareView expandedQuests location { questsProgress, questRewardShops }
17241737
, H.viewIf hasQuests <|
17251738
UI.ul []
17261739
(quests
1740+
|> List.filter (\q -> not (List.any isQuestDone (Quest.exclusiveWith q)))
17271741
|> List.map (questView player questsProgress expandedQuests)
17281742
)
17291743
]
@@ -1774,6 +1788,7 @@ collapsedQuestView progress quest =
17741788
, H.viewIf isDone <|
17751789
H.text " [DONE]"
17761790
]
1791+
, UI.button [ HE.onClick (AskToTemporaryFinishQuest quest) ] [ H.text "[TEMP FINISH]" ]
17771792
]
17781793

17791794

@@ -1830,6 +1845,10 @@ expandedQuestView player progress questsProgress quest =
18301845
|> Maybe.map (\q_ -> q_.ticksGiven >= Quest.ticksNeeded q)
18311846
|> Maybe.withDefault False
18321847

1848+
exclusiveQuests : List Quest.Name
1849+
exclusiveQuests =
1850+
Quest.exclusiveWith quest
1851+
18331852
canStart : Bool
18341853
canStart =
18351854
List.all isQuestDone questRequirements
@@ -1878,7 +1897,8 @@ expandedQuestView player progress questsProgress quest =
18781897
else
18791898
HA.class "!text-yellow"
18801899
, TW.mod "hover" "text-yellow"
1881-
, HE.onClickStopPropagation <| AskToStartProgressing quest
1900+
, HA.disabled (not canStart)
1901+
, HA.attributeIf canStart (HE.onClickStopPropagation <| AskToStartProgressing quest)
18821902
]
18831903
[ H.text "[START]" ]
18841904
]
@@ -1913,8 +1933,7 @@ expandedQuestView player progress questsProgress quest =
19131933
[ H.div
19141934
[ HA.class "mt-5" ]
19151935
[ H.text "Quest Requirements" ]
1916-
, UI.ul
1917-
[ HA.class "ps-[4ch]" ]
1936+
, UI.ul []
19181937
(List.map
19191938
(\q ->
19201939
Quest.title q
@@ -1935,13 +1954,12 @@ expandedQuestView player progress questsProgress quest =
19351954
[ H.div
19361955
[ HA.class "mt-5" ]
19371956
[ H.text "Player Requirements" ]
1938-
, UI.ul
1939-
[ HA.class "ps-[4ch]" ]
1957+
, UI.ul []
19401958
(List.map
19411959
(\req ->
19421960
let
19431961
isMet =
1944-
Logic.passesPlayerRequirement req player
1962+
progress.alreadyPaidRequirements || Logic.passesPlayerRequirement req player
19451963
in
19461964
Quest.playerRequirementTitle req
19471965
|> (if isMet then
@@ -1961,8 +1979,7 @@ expandedQuestView player progress questsProgress quest =
19611979
[ H.div
19621980
[ HA.class "mt-5" ]
19631981
[ H.text "Global Rewards" ]
1964-
, UI.ul
1965-
[ HA.class "ps-[4ch]" ]
1982+
, UI.ul []
19661983
(List.map
19671984
(Quest.globalRewardTitle
19681985
>> (if isDone then
@@ -1991,8 +2008,7 @@ expandedQuestView player progress questsProgress quest =
19912008
]
19922009
, H.text " ticks)"
19932010
]
1994-
, UI.ul
1995-
[ HA.class "ps-[4ch]" ]
2011+
, UI.ul []
19962012
(List.map
19972013
(Quest.playerRewardTitle
19982014
>> (if isDone then
@@ -2009,6 +2025,18 @@ expandedQuestView player progress questsProgress quest =
20092025
playerRewards
20102026
)
20112027
]
2028+
, if List.isEmpty exclusiveQuests then
2029+
[]
2030+
2031+
else
2032+
[ H.div
2033+
[ HA.class "mt-5" ]
2034+
[ H.text "Exclusive with:" ]
2035+
, UI.ul []
2036+
(exclusiveQuests
2037+
|> List.map (\q -> liText (Quest.title q))
2038+
)
2039+
]
20122040
]
20132041
]
20142042
]
@@ -5118,6 +5146,8 @@ createdPlayerInfoView tickFrequency worldName zone time player =
51185146
[ HA.class "text-green-100 mb-4" ]
51195147
[ H.text <| nextTickTime zone time freq ]
51205148
)
5149+
, H.div [] [ UI.button [ HE.onClick AskToTemporaryMaxOutTicks ] [ H.text "[MAX]" ] ]
5150+
, H.div [] []
51215151
, H.div
51225152
[ HA.class "text-right text-green-300" ]
51235153
[ H.text "Name:" ]

0 commit comments

Comments
 (0)