Skip to content

Commit

Permalink
Ammo used / ammo available
Browse files Browse the repository at this point in the history
  • Loading branch information
Janiczek committed Oct 16, 2024
1 parent fe518f6 commit 7c08cd9
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 24 deletions.
36 changes: 36 additions & 0 deletions src/Data/Fight/Generator.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,24 @@ evalValue who state value =
)
|> List.sum

MyAmmoCount ->
case state.you.equippedWeapon of
Nothing ->
0

Just weapon ->
state.you.items
|> Dict.toList
|> List.filterMap
(\( _, item ) ->
if ItemKind.isUsableAmmoForWeapon weapon item.kind then
Just item.count

else
Nothing
)
|> List.sum

ItemsUsed itemKind ->
state.yourItemsUsed
|> SeqDict.get itemKind
Expand All @@ -1392,6 +1410,24 @@ evalValue who state value =
)
|> List.sum

AmmoUsed ->
case state.you.equippedWeapon of
Nothing ->
0

Just weapon ->
state.yourItemsUsed
|> SeqDict.toList
|> List.filterMap
(\( kind, count ) ->
if ItemKind.isUsableAmmoForWeapon weapon kind then
Just count

else
Nothing
)
|> List.sum

ChanceToHit attackStyle ->
Logic.chanceToHit
{ attackerAddedSkillPercentages = state.you.addedSkillPercentages
Expand Down
18 changes: 18 additions & 0 deletions src/Data/FightStrategy.elm
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ type Value
| MyAP
| MyItemCount ItemKind.Kind
| MyHealingItemCount
| MyAmmoCount
| ItemsUsed ItemKind.Kind
| HealingItemsUsed
| AmmoUsed
| ChanceToHit AttackStyle
| RangeNeeded AttackStyle
| Distance
Expand Down Expand Up @@ -177,13 +179,19 @@ valueToString value =
MyHealingItemCount ->
"number of available healing items"

MyAmmoCount ->
"number of available ammo"

ItemsUsed kind ->
"number of used "
++ ItemKind.name kind

HealingItemsUsed ->
"number of used healing items"

AmmoUsed ->
"number of used ammo"

ChanceToHit attackStyle ->
"chance to hit ("
++ AttackStyle.toString attackStyle
Expand Down Expand Up @@ -370,6 +378,11 @@ encodeValue value =
[ ( "type", JE.string "MyHealingItemCount" )
]

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

ItemsUsed itemKind ->
JE.object
[ ( "type", JE.string "ItemsUsed" )
Expand All @@ -381,6 +394,11 @@ encodeValue value =
[ ( "type", JE.string "HealingItemsUsed" )
]

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

ChanceToHit attackStyle ->
JE.object
[ ( "type", JE.string "ChanceToHit" )
Expand Down
45 changes: 23 additions & 22 deletions src/Data/FightStrategy/Help.elm
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,26 @@ help =
- heal ([ITEM]) - my AP
- heal with anything - number of available [ITEM]
- move forward - number of available healing items
- do whatever - number of used [ITEM]
- skip turn - number of used healing items
- opponent's level
- chance to hit ([ATTACK])
[CONDITION] - range needed ([ATTACK])
- opponent is player - distance
- opponent is NPC - [NUMBER]
- [VALUE] [OPERATOR] [VALUE]
- ([CONDITION] or [CONDITION])
- ([CONDITION] and [CONDITION]) [ATTACK] [AIM]
- unarmed - head
- unarmed, [AIM] - eyes
[OPERATOR] - melee - torso
- < (less than) - melee, [AIM] - groin
- <= (less than or equal) - throw - left arm
- == (equals) - shoot - right arm
- != (doesn't equal) - shoot, [AIM] - left leg
- >= (greater than or equal) - burst - right leg
- > (greater than)
- do whatever - number of available ammo
- skip turn - number of used [ITEM]
- number of used healing items
- number of used ammo
[CONDITION] - opponent's level
- opponent is player - chance to hit ([ATTACK])
- opponent is NPC - range needed ([ATTACK])
- [VALUE] [OPERATOR] [VALUE] - distance
- ([CONDITION] or [CONDITION]) - [NUMBER]
- ([CONDITION] and [CONDITION])
[ATTACK] [AIM]
[OPERATOR] - unarmed - head
- < (less than) - unarmed, [AIM] - eyes
- <= (less than or equal) - melee - torso
- == (equals) - melee, [AIM] - groin
- != (doesn't equal) - throw - left arm
- >= (greater than or equal) - shoot - right arm
- > (greater than) - shoot, [AIM] - left leg
- burst - right leg
"""
|> P.run parser
|> Result.withDefault [ Text "BUG: couldn't parse the syntax help!" ]
Expand Down Expand Up @@ -221,14 +222,14 @@ Example usage:
- my HP
- chance to hit (left leg)
- number of available healing items
- number of available Stimpak"""
- number of available Stimpak
- number of used ammo"""

Operator ->
"""Example usage:
- distance > 1
- my HP <= 80
- my AP == 3
"""
- my AP == 3"""

Number ->
"""Can be positive or negative integers (no decimal point).
Expand Down
21 changes: 20 additions & 1 deletion src/Data/FightStrategy/Named.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Data.FightStrategy.Named exposing
, default
)

import Data.Fight.AttackStyle exposing (AttackStyle(..))
import Data.Fight.AttackStyle as AttackStyle exposing (AttackStyle(..))
import Data.FightStrategy
exposing
( Command(..)
Expand All @@ -23,6 +23,7 @@ all : List ( String, FightStrategy )
all =
[ dontCare
, conservative
, smart
]


Expand Down Expand Up @@ -50,3 +51,21 @@ conservative =
}
}
)


smart : ( String, FightStrategy )
smart =
( "Smart"
, If
{ condition =
And (Operator { lhs = MyAmmoCount, op = GT_, rhs = Number 0 })
(Operator { lhs = ChanceToHit AttackStyle.ShootSingleUnaimed, op = GT_, rhs = Number 50 })
, then_ = Command (Attack ShootSingleUnaimed)
, else_ =
If
{ condition = Operator { lhs = Distance, op = GT_, rhs = Number 1 }
, then_ = Command MoveForward
, else_ = Command (Attack UnarmedUnaimed)
}
}
)
2 changes: 2 additions & 0 deletions src/Data/FightStrategy/Parser.elm
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ itemCount =
|. nonemptySpaces
|= P.oneOf
[ P.map (\_ -> MyHealingItemCount) (P.keyword "healing items")
, P.map (\_ -> MyAmmoCount) (P.keyword "ammo")
, P.map MyItemCount itemKind
]

Expand All @@ -206,6 +207,7 @@ itemsUsed =
|. nonemptySpaces
|= P.oneOf
[ P.map (\_ -> HealingItemsUsed) (P.keyword "healing items")
, P.map (\_ -> AmmoUsed) (P.keyword "ammo")
, P.map ItemsUsed itemKind
]

Expand Down
1 change: 0 additions & 1 deletion src/Frontend/News.elm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ items =
- More enemies?
- burst: multiple bullets, each with a chance to hit
- Weapon/ammo part of item loot of enemies?
- Fight Strategy: number of available ammo
- Fight Strategy: walk away
- refactoring: fight Opponents shouldn't hold attackStats and naturalArmorClass?
- make movement on the map challenging (random encounters, fights you can't skip, have to heal...)
Expand Down
2 changes: 2 additions & 0 deletions tests/Data/FightStrategy/ParserTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ value =
, ( "used HealingPowder", "number of used Healing Powder", Just (ItemsUsed ItemKind.HealingPowder) )
, ( "used - non-healing item also works", "number of used Metal Armor", Just (ItemsUsed ItemKind.MetalArmor) )
, ( "used healing items", "number of used healing items", Just HealingItemsUsed )
, ( "item count - ammo", "number of available ammo", Just MyAmmoCount )
, ( "used ammo", "number of used ammo", Just AmmoUsed )
]
, AttackStyle.all
|> List.fastConcatMap
Expand Down

0 comments on commit 7c08cd9

Please sign in to comment.