Skip to content

Commit

Permalink
Barter: Even up the trade
Browse files Browse the repository at this point in the history
  • Loading branch information
Janiczek committed Oct 31, 2024
1 parent e2d06d1 commit d108b8d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 6 deletions.
88 changes: 83 additions & 5 deletions src/Frontend.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2234,7 +2234,6 @@ townStoreView barter shop location world player =
[ HA.class "w-[6ch] !bg-green-800 px-[4px]"
, HA.value transferNValue
, HE.onInput <| BarterMsg << SetTransferNInput transferNPosition
, HA.title "Transfer N caps"
]
[]
, case String.toInt transferNValue of
Expand All @@ -2243,7 +2242,6 @@ townStoreView barter shop location world player =
[ HA.disabled True
, HA.class "py-0.5 px-1 mx-1 bg-green-800 text-green-200"
, TW.mod "disabled" "text-green-300 opacity-50 pointer-events-none"
, HA.title "Transfer N caps"
]
[ H.text "OK" ]

Expand All @@ -2253,7 +2251,6 @@ townStoreView barter shop location world player =
, HA.disabled <| n <= 0 || n > caps
, HA.class "py-0.5 px-1 mx-1 bg-green-800 text-green-200"
, TW.mod "disabled" "text-green-300 opacity-50 pointer-events-none"
, HA.title "Transfer N caps"
]
[ H.text "OK" ]
, UI.highContrastButton
Expand All @@ -2269,10 +2266,10 @@ townStoreView barter shop location world player =
[ HA.class "py-0.5 px-1 mx-1 bg-green-800 text-green-200"
, TW.mod "disabled" "text-green-300 opacity-50 pointer-events-none"
, HA.disabled <| caps <= 0
, HA.title "Transfer N items"
, HE.onClick <| BarterMsg <| SetTransferNActive transferNPosition
]
[ H.text "N" ]
|> UI.withTooltip "Transfer N caps"

transferOneView =
UI.highContrastButton
Expand All @@ -2296,6 +2293,85 @@ townStoreView barter shop location world player =
]
[ H.text <| Barter.doubleArrow arrowsDirection ]

balanceAmount : Maybe { needed : Int, available : Int }
balanceAmount =
case transferNPosition of
Barter.PlayerKeptCaps ->
let
needed =
vendorTradedValue - playerTradedValue

available =
clamp 0 playerKeptCaps needed
in
if available == 0 then
Nothing

else
Just { available = available, needed = needed }

Barter.VendorKeptCaps ->
let
needed =
playerTradedValue - vendorTradedValue

available =
clamp 0 vendorKeptCaps needed
in
if available == 0 then
Nothing

else
Just { available = available, needed = needed }

Barter.PlayerTradedCaps ->
Nothing

Barter.VendorTradedCaps ->
Nothing

Barter.PlayerKeptItem _ ->
Nothing

Barter.VendorKeptItem _ ->
Nothing

Barter.PlayerTradedItem _ ->
Nothing

Barter.VendorTradedItem _ ->
Nothing

balanceView =
balanceAmount
|> H.viewMaybe
(\{ available, needed } ->
let
hasEnough =
available == needed
in
UI.highContrastButton
[ HE.onClick <| transfer available
, HA.class "py-0.5 px-1 mx-1 bg-green-800"
, if hasEnough then
HA.class "text-green-200"

else
HA.class "text-yellow"
, HA.classList [ ( "hidden", isNActive ) ]
]
[ H.text "=" ]
|> UI.withTooltip
("Even up the trade (transfer " ++ String.fromInt available ++ " caps)"
++ (if hasEnough then
""

else
". This is not enough (" ++ String.fromInt needed ++ " needed)."
)
)
)

itemView =
H.span
[ HA.class <| "flex-1 " ++ itemLabelClass ]
Expand All @@ -2313,11 +2389,13 @@ townStoreView barter shop location world player =
[ transferAllView
, transferNView
, transferOneView
, balanceView
, itemView
]

Barter.ArrowRight ->
[ itemView
, balanceView
, transferOneView
, transferNView
, transferAllView
Expand Down Expand Up @@ -2401,10 +2479,10 @@ townStoreView barter shop location world player =
[ HA.class "py-0.5 px-1 mx-1 bg-green-800 text-green-200"
, TW.mod "disabled" "text-green-300 opacity-50 pointer-events-none"
, HA.disabled <| count <= 0
, HA.title "Transfer N items"
, HE.onClick <| BarterMsg <| SetTransferNActive (transferNPosition id)
]
[ H.text "N" ]
|> UI.withTooltip "Transfer N items"

transferOneView =
UI.highContrastButton
Expand Down
1 change: 0 additions & 1 deletion src/Frontend/News.elm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ Ideas floating around:
- make movement on the map challenging (random encounters, fights you can't skip, have to be alive to move...)
- steal skill gives you % chance of looting a random item from a player's inventory in PVP after defeating them
- inventory: help on hover - show how much it will heal (either in a help section or in the "HP: ..." section of left nav
- left nav: on hover of "Heal", show how much it will heal in the "HP: ..." section
~janiczek
"""
Expand Down

0 comments on commit d108b8d

Please sign in to comment.