Allow equipment on both wrists

This commit is contained in:
2022-05-21 15:26:58 +01:00
parent 8ad332aced
commit c5818271d8
6 changed files with 42 additions and 50 deletions
+3
View File
@@ -174,6 +174,9 @@ inventoryA = IM.fromList $ zip [0..]
testInventory :: IM.IntMap Item
testInventory = IM.fromList $ zip [0..]
[ makeTypeCraftNum 9 PIPE
, autoSonar
, autoRadar
, autoRadar
, frontArmour
, flameShield
, powerLegs
+29 -24
View File
@@ -41,49 +41,54 @@ itemEffect cr it w = case it ^? itUse of
setuhamdown = creatures . ix (_crID cr) . crHammerPosition .~ HammerDown
toggleEquipmentAt :: Int -> Item -> Creature -> Creature
toggleEquipmentAt invid itm cr
| invid `IM.member` _crInvEquipped cr = cr & crInvEquipped . at invid .~ Nothing
& removeEquipmentUsingSite esite
& setEquipmentSite esite Nothing'
| otherwise = cr & crInvEquipped . at invid .~ Just epos
& removeEquipmentUsingSite esite
& setEquipmentSite esite (Just' invid)
toggleEquipmentAt invid itm cr = case cr ^? crInvEquipped . ix invid of
Just epos -> cr & crInvEquipped . at invid .~ Nothing
& crEquipment . at epos .~ Nothing
Nothing -> equipUsingSite invid itm cr
equipUsingSite :: Int -> Item -> Creature -> Creature
equipUsingSite invid itm cr = cr
& crInvEquipped . at invid .~ Just epos
& crEquipment . at epos .~ Just invid
& removeOtherEquipment
where
esite = _eqSite (_itUse itm)
epos = eqSiteToPos cr esite
f Nothing = Just ()
f (Just ()) = Nothing
epos = eqSiteToPos cr (_eqSite $ _itUse itm)
removeOtherEquipment = case cr ^? crEquipment . ix epos of
Nothing -> id
Just oid -> crInvEquipped . at oid .~ Nothing
eqSiteToPos :: Creature -> EquipSite -> EquipPosition
eqSiteToPos cr es = case es of
GoesOnHead -> OnHead
GoesOnChest -> OnChest
GoesOnBack -> OnBack
GoesOnWrist -> OnLeftWrist
GoesOnLegs -> OnLegs
GoesOnSpecial -> OnSpecial
GoesOnWrist -> case cr ^? crEquipment . ix OnLeftWrist of
Nothing -> OnLeftWrist
_ -> OnRightWrist
removeEquipmentUsingSite :: EquipSite -> Creature -> Creature
removeEquipmentUsingSite esite cr = case esite of
GoesOnSpecial -> cr
_ -> case cr ^? crEquipment . esiteToPoint . _Just' of
_ -> case cr ^? crEquipment . esiteToPoint of
Just invid -> cr & crInvEquipped . at invid .~ Nothing
_ -> cr
where
esiteToPoint = case esite of
GoesOnHead -> onHead
GoesOnChest -> onChest
GoesOnBack -> onBack
GoesOnWrist -> onWristL
GoesOnLegs -> onLegs
GoesOnHead -> ix OnHead
GoesOnChest -> ix OnChest
GoesOnBack -> ix OnBack
GoesOnWrist -> ix OnLeftWrist
GoesOnLegs -> ix OnLegs
setEquipmentSite :: EquipSite -> Maybe' Int -> Creature -> Creature
setEquipmentSite :: EquipSite -> Maybe Int -> Creature -> Creature
setEquipmentSite esite = case esite of
GoesOnHead -> set (crEquipment . onHead)
GoesOnChest -> set (crEquipment . onChest)
GoesOnBack -> set (crEquipment . onBack)
GoesOnWrist -> set (crEquipment . onWristL)
GoesOnLegs -> set (crEquipment . onLegs)
GoesOnHead -> set (crEquipment . at OnHead)
GoesOnChest -> set (crEquipment . at OnChest)
GoesOnBack -> set (crEquipment . at OnBack)
GoesOnWrist -> set (crEquipment . at OnLeftWrist)
GoesOnLegs -> set (crEquipment . at OnLegs)
GoesOnSpecial -> const id
useLeftItem :: Int -> World -> World
+1 -10
View File
@@ -278,7 +278,7 @@ data Creature = Creature
, _crInvCapacity :: Int
, _crInvLock :: Bool
, _crInvEquipped :: IM.IntMap EquipPosition
, _crEquipment :: CreatureEquipment
, _crEquipment :: M.Map EquipPosition Int
, _crLeftInvSel :: Maybe Int
, _crState :: CreatureState
, _crCorpse :: Picture
@@ -297,14 +297,6 @@ data Creature = Creature
, _crHammerPosition :: HammerPosition
, _crName :: String
}
data CreatureEquipment = CreatureEquipment
{_onHead :: Maybe' Int
,_onChest :: Maybe' Int
,_onBack :: Maybe' Int
,_onWristL :: Maybe' Int
,_onWristR :: Maybe' Int
,_onLegs :: Maybe' Int
}
data Vocalization
= Mute
| Vocalization
@@ -1315,4 +1307,3 @@ makeLenses ''Beam
makeLenses ''BeamType
makeLenses ''WorldBeams
makeLenses ''ArcStep
makeLenses ''CreatureEquipment
+1 -8
View File
@@ -46,14 +46,7 @@ defaultCreature = Creature
, _crCorpse = setLayer BottomLayer $ setDepth 5 $ color (greyN 0.5) $ circleSolid 10
, _crApplyDamage = defaultApplyDamage
, _crPastDamage = 0
, _crEquipment = CreatureEquipment
{_onHead = Nothing'
,_onChest = Nothing'
,_onBack = Nothing'
,_onWristL = Nothing'
,_onWristR = Nothing'
,_onLegs = Nothing'
}
, _crEquipment = M.empty
, _crStance = Stance
{_carriage=Walking 0 WasLeftForward
,_posture=AtEase
+2 -2
View File
@@ -61,7 +61,7 @@ autoSonar = defaultEquipment
, _itEquipPict = \_ _ -> (,) emptySH blank
, _itEffect = autoSonarEffect
, _itID = Nothing
}
} & itUse . eqSite .~ GoesOnWrist
{- |
Automatically sends out pulses that display walls. -}
autoRadar :: Item
@@ -71,4 +71,4 @@ autoRadar = defaultEquipment
, _itEquipPict = \_ _ -> (,) emptySH blank
, _itEffect = autoRadarEffect
, _itID = Nothing
}
} & itUse . eqSite .~ GoesOnWrist
+6 -6
View File
@@ -134,12 +134,12 @@ subInventoryDisplay subinv cfig w = case subinv of
eqPosText :: EquipPosition -> String
eqPosText ep = case ep of
OnHead -> "HEAD"
OnChest -> "CHEST"
OnBack -> "BACK"
OnLeftWrist -> "L-WRIST"
OnRightWrist -> "R-WRIST"
OnLegs -> "LEGS"
OnHead -> "ON HEAD"
OnChest -> "ON CHEST"
OnBack -> "ON BACK"
OnLeftWrist -> "ON LEFT WRIST"
OnRightWrist -> "ON RIGHT WRIST"
OnLegs -> "ON LEGS"
OnSpecial -> "EQUIPPED"
topInvW :: Int