Major item refactor, still broken
This commit is contained in:
@@ -20,17 +20,18 @@ For now, though, this cannot fail.
|
||||
crMvBy ::
|
||||
-- | Movement translation vector, will be made relative to creature direction
|
||||
Point2 ->
|
||||
LWorld ->
|
||||
Creature ->
|
||||
Creature
|
||||
crMvBy p cr = crMvAbsolute (rotateV (_crDir cr) p) cr
|
||||
crMvBy p lw cr = crMvAbsolute lw (rotateV (_crDir cr) p) cr
|
||||
|
||||
crMvAbsolute :: Point2 -> Creature -> Creature
|
||||
crMvAbsolute p' cr =
|
||||
crMvAbsolute :: LWorld -> Point2 -> Creature -> Creature
|
||||
crMvAbsolute lw p' cr =
|
||||
advanceStepCounter (magV p) cr
|
||||
& crPos +~ p
|
||||
& crMvDir .~ argV p
|
||||
where
|
||||
p = strengthFactor (getCrMoveSpeed cr) *.* p'
|
||||
p = strengthFactor (getCrMoveSpeed lw cr) *.* p'
|
||||
|
||||
strengthFactor :: Int -> Float
|
||||
strengthFactor i
|
||||
@@ -38,7 +39,7 @@ strengthFactor i
|
||||
| i < 1 = 0
|
||||
| otherwise = 0.02 * fromIntegral i
|
||||
|
||||
crMvForward :: Float -> Creature -> Creature
|
||||
crMvForward :: Float -> LWorld -> Creature -> Creature
|
||||
crMvForward speed = crMvBy (V2 speed 0)
|
||||
|
||||
advanceStepCounter :: Float -> Creature -> Creature
|
||||
|
||||
@@ -18,7 +18,7 @@ import qualified IntMapHelp as IM
|
||||
useItem :: Int -> Int -> World -> Maybe World
|
||||
useItem invid pt w = fmap (worldEventFlags . at InventoryChange ?~ ()) $ do
|
||||
cr <- w ^? cWorld . lWorld . creatures . ix 0
|
||||
itmloc <- invIndents (_crInv cr) ^? ix invid . _2
|
||||
itmloc <- invIndents (fmap (\k -> w ^?! cWorld . lWorld . items . ix k) $ _crInv cr) ^? ix invid . _2
|
||||
useItemLoc cr itmloc pt w
|
||||
|
||||
useItemLoc :: Creature -> LocationDT OItem -> Int -> World -> Maybe World
|
||||
@@ -68,34 +68,37 @@ toggleEquipmentAt invid cr w = case getEquipmentAllocation invid w of
|
||||
PutOnEquipment{_allocNewPos = newp} ->
|
||||
w
|
||||
& crpoint . crEquipment . at newp ?~ invid
|
||||
& crpoint . crInv . ix invid . itLocation . ilEquipSite ?~ newp
|
||||
& toitems . ix itid . itLocation . ilEquipSite ?~ newp
|
||||
& onequip itm cr
|
||||
MoveEquipment{_allocNewPos = newp, _allocOldPos = oldp} ->
|
||||
w
|
||||
& crpoint . crEquipment . at newp ?~ invid
|
||||
& crpoint . crEquipment . at oldp .~ Nothing
|
||||
& crpoint . crInv . ix invid . itLocation . ilEquipSite ?~ newp
|
||||
& toitems . ix itid . itLocation . ilEquipSite ?~ newp
|
||||
SwapEquipment{_allocNewPos = newp, _allocOldPos = oldp, _allocSwapID = sid} ->
|
||||
w
|
||||
& crpoint . crEquipment . at newp ?~ invid
|
||||
& crpoint . crEquipment . at oldp ?~ sid
|
||||
& crpoint . crInv . ix invid . itLocation . ilEquipSite ?~ newp
|
||||
& crpoint . crInv . ix sid . itLocation . ilEquipSite ?~ oldp
|
||||
& toitems . ix itid . itLocation . ilEquipSite ?~ newp
|
||||
& toitems . ix (invidtoitid sid) . itLocation . ilEquipSite ?~ oldp
|
||||
ReplaceEquipment{_allocNewPos = newp, _allocRemoveID = rid} ->
|
||||
w
|
||||
& crpoint . crEquipment . at newp ?~ invid
|
||||
& crpoint . crInv . ix invid . itLocation . ilEquipSite ?~ newp
|
||||
& crpoint . crInv . ix rid . itLocation . ilEquipSite .~ Nothing
|
||||
& toitems . ix itid . itLocation . ilEquipSite ?~ newp
|
||||
& toitems . ix (invidtoitid rid) . itLocation . ilEquipSite .~ Nothing
|
||||
& onremove (itmat rid) cr
|
||||
& onequip itm cr
|
||||
RemoveEquipment{_allocOldPos = oldp} ->
|
||||
w
|
||||
& crpoint . crEquipment . at oldp .~ Nothing
|
||||
& crpoint . crInv . ix invid . itLocation . ilEquipSite .~ Nothing
|
||||
& toitems . ix itid . itLocation . ilEquipSite .~ Nothing
|
||||
& onremove itm cr
|
||||
where
|
||||
invidtoitid i = _crInv cr IM.! i
|
||||
toitems = cWorld . lWorld . items
|
||||
itid = _crInv cr IM.! invid
|
||||
crpoint = cWorld . lWorld . creatures . ix (_crID cr)
|
||||
itmat i = _crInv cr IM.! i
|
||||
itmat i = w ^?! cWorld . lWorld . items . ix (_crInv cr IM.! i)
|
||||
itm = itmat invid
|
||||
onequip itm' = effectOnEquip itm'
|
||||
onremove itm' = effectOnRemove itm'
|
||||
|
||||
Reference in New Issue
Block a user