-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 'questing-interactions' (#3) from questing-interac…
…tions into master
- Loading branch information
Showing
101 changed files
with
5,916 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,4 +81,5 @@ cabal.project.local~ | |
|
||
**/.idea | ||
.pyc | ||
__pycache__ | ||
__pycache__ | ||
venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[style] | ||
INDENT_DICTIONARY_VALUE = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/PotatoCactus/Client/GroundItemsUpdate/EncodeGroundItemsUpdate.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module PotatoCactus.Client.GroundItemsUpdate.EncodeGroundItemsUpdate (encodeGroundItemsUpdate) where | ||
|
||
import Data.ByteString (ByteString, concat, empty) | ||
import PotatoCactus.Client.GroundItemsUpdate.GroundItemsUpdateDiff (GroundItemClientView, GroundItemDiff (Added, Removed, Retained), computeDiff, fromGroundItem) | ||
import PotatoCactus.Game.Entity.GroundItem.GroundItem (GroundItem) | ||
import PotatoCactus.Game.Entity.GroundItem.GroundItemCollection (findByChunkXYForPlayer) | ||
import PotatoCactus.Game.Movement.MovementEntity (hasChangedRegion) | ||
import PotatoCactus.Game.Player (Player) | ||
import qualified PotatoCactus.Game.Player as P | ||
import PotatoCactus.Game.Position (GetPosition (getPosition), chunkX, chunkY) | ||
import qualified PotatoCactus.Game.Position as Pos | ||
import PotatoCactus.Game.World (World (groundItems)) | ||
import PotatoCactus.Network.Packets.Out.AddGroundItemPacket (addGroundItemPacket) | ||
import PotatoCactus.Network.Packets.Out.RemoveGroundItemPacket (removeGroundItemPacket) | ||
import PotatoCactus.Network.Packets.Out.SetPlacementReferencePacket (setPlacementReferencePacket) | ||
|
||
encodeGroundItemsUpdate :: [GroundItemClientView] -> World -> Player -> ([GroundItemClientView], ByteString) | ||
encodeGroundItemsUpdate oldGroundItems world player = | ||
let newItems = findItemsAround player world | ||
in if hasChangedRegion (P.movement player) | ||
then | ||
( newItems, | ||
Data.ByteString.concat | ||
( -- clearChunksAroundPlayer player : -- Assuming | ||
-- already cleared by game object update. We should | ||
-- probably handle both in the same function to get | ||
-- rid of this implicit dependency. | ||
map (encodeSingle player) (computeDiff [] newItems) | ||
) | ||
) | ||
else | ||
( newItems, | ||
Data.ByteString.concat | ||
(map (encodeSingle player) (computeDiff oldGroundItems newItems)) | ||
) | ||
|
||
encodeSingle :: Player -> GroundItemDiff -> ByteString | ||
encodeSingle p (Added groundItem) = | ||
Data.ByteString.concat | ||
[ setPlacementReferencePacket p (getPosition groundItem), | ||
addGroundItemPacket (getPosition groundItem) groundItem | ||
] | ||
encodeSingle p (Removed groundItem) = | ||
Data.ByteString.concat | ||
[ setPlacementReferencePacket p (getPosition groundItem), | ||
removeGroundItemPacket (getPosition groundItem) groundItem | ||
] | ||
encodeSingle p (Retained _) = empty | ||
|
||
findItemsAround :: Player -> World -> [GroundItemClientView] | ||
findItemsAround player world = | ||
let refPos = getPosition player | ||
in Prelude.concat | ||
[ map fromGroundItem $ | ||
findByChunkXYForPlayer | ||
(groundItems world) | ||
(P.username player) | ||
(x + chunkX refPos, y + chunkY refPos, Pos.z refPos) | ||
| x <- [-2 .. 1], | ||
y <- [-2 .. 1] | ||
] |
44 changes: 44 additions & 0 deletions
44
app/PotatoCactus/Client/GroundItemsUpdate/GroundItemsUpdateDiff.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module PotatoCactus.Client.GroundItemsUpdate.GroundItemsUpdateDiff (fromGroundItem, computeDiff, GroundItemClientView (..), GroundItemDiff (..)) where | ||
|
||
import Data.Maybe (mapMaybe) | ||
import PotatoCactus.Game.Definitions.ItemDefinitions (ItemId) | ||
import PotatoCactus.Game.Entity.GroundItem.GroundItem (GroundItem) | ||
import qualified PotatoCactus.Game.Entity.GroundItem.GroundItem as GroundItem | ||
import PotatoCactus.Game.Position (GetPosition (getPosition), Position) | ||
|
||
data GroundItemClientView = GroundItemClientView | ||
{ itemId :: ItemId, | ||
quantity :: Int, | ||
position :: Position | ||
} | ||
deriving (Eq, Show) | ||
|
||
instance GetPosition GroundItemClientView where | ||
getPosition = position | ||
|
||
fromGroundItem :: GroundItem -> GroundItemClientView | ||
fromGroundItem i = | ||
GroundItemClientView | ||
{ itemId = GroundItem.itemId i, | ||
quantity = GroundItem.quantity i, | ||
position = GroundItem.position i | ||
} | ||
|
||
data GroundItemDiff = Added GroundItemClientView | Retained GroundItemClientView | Removed GroundItemClientView deriving (Eq, Show) | ||
|
||
computeDiff :: [GroundItemClientView] -> [GroundItemClientView] -> [GroundItemDiff] | ||
computeDiff old new = | ||
map (mapNewObject old) new | ||
++ mapMaybe (mapOldObject new) old | ||
|
||
mapNewObject :: [GroundItemClientView] -> GroundItemClientView -> GroundItemDiff | ||
mapNewObject oldSet object = | ||
if object `elem` oldSet | ||
then Retained object | ||
else Added object | ||
|
||
mapOldObject :: [GroundItemClientView] -> GroundItemClientView -> Maybe GroundItemDiff | ||
mapOldObject newSet object = | ||
if object `notElem` newSet | ||
then Just $ Removed object | ||
else Nothing |
40 changes: 40 additions & 0 deletions
40
app/PotatoCactus/Client/Interface/EncodeInterfaceUpdate.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module PotatoCactus.Client.Interface.EncodeInterfaceUpdate (encodeInterfaceUpdate) where | ||
|
||
import Data.ByteString (ByteString, concat, empty) | ||
import Data.Maybe (catMaybes) | ||
import PotatoCactus.Game.Interface.InterfaceController (Interface (Interface, configuredElements), InterfaceController (inputInterface, mainInterface, shouldCloseInterfaces, walkableInterface)) | ||
import PotatoCactus.Game.Scripting.Actions.CreateInterface (InterfaceElement (ChatboxRootWindowElement, ModelAnimationElement, NpcChatheadElement, PlayerChatheadElement, TextElement)) | ||
import PotatoCactus.Network.Packets.Out.ChatboxInterfacePacket (chatboxInterfacePacket) | ||
import PotatoCactus.Network.Packets.Out.CloseInterfacesPacket (closeInterfacesPacket) | ||
import PotatoCactus.Network.Packets.Out.InterfaceAnimationPacket (interfaceAnimationPacket) | ||
import PotatoCactus.Network.Packets.Out.InterfaceChatheadPacket (interfaceNpcChatheadPacket, interfacePlayerChatheadPacket) | ||
import PotatoCactus.Network.Packets.Out.InterfaceTextPacket (interfaceTextPacket) | ||
|
||
encodeInterfaceUpdate :: InterfaceController -> ByteString | ||
encodeInterfaceUpdate c = | ||
if shouldCloseInterfaces c | ||
then closeInterfacesPacket | ||
else | ||
Data.ByteString.concat $ | ||
map encodeInterface_ $ | ||
catMaybes | ||
[ mainInterface c, | ||
walkableInterface c, | ||
inputInterface c | ||
] | ||
|
||
encodeInterface_ :: Interface -> ByteString | ||
encodeInterface_ Interface {configuredElements = elements} = | ||
Data.ByteString.concat $ map encodeInterfaceElement_ elements | ||
|
||
encodeInterfaceElement_ :: InterfaceElement -> ByteString | ||
encodeInterfaceElement_ (ChatboxRootWindowElement widgetId) = | ||
chatboxInterfacePacket . fromIntegral $ widgetId | ||
encodeInterfaceElement_ (TextElement widgetId text) = | ||
interfaceTextPacket (fromIntegral widgetId) text | ||
encodeInterfaceElement_ (NpcChatheadElement widgetId npcId) = | ||
interfaceNpcChatheadPacket (fromIntegral widgetId) npcId | ||
encodeInterfaceElement_ (PlayerChatheadElement widgetId) = | ||
interfacePlayerChatheadPacket (fromIntegral widgetId) | ||
encodeInterfaceElement_ (ModelAnimationElement widgetId animationId) = | ||
interfaceAnimationPacket (fromIntegral widgetId) (fromIntegral animationId) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module PotatoCactus.Game.Entity.EntityData (EntityData, create, setValue) where | ||
|
||
import Data.Aeson (Value) | ||
import qualified Data.Map.Lazy as Map | ||
|
||
type EntityData = Map.Map String Value | ||
|
||
create :: EntityData | ||
create = Map.empty | ||
|
||
setValue :: EntityData -> String -> Value -> EntityData | ||
setValue store key val = | ||
Map.insert key val store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module PotatoCactus.Game.Entity.GroundItem.GroundItem where | ||
|
||
import PotatoCactus.Game.Definitions.ItemDefinitions (ItemId) | ||
import qualified PotatoCactus.Game.ItemContainer as ItemStack | ||
import PotatoCactus.Game.Position (GetPosition (getPosition), Position) | ||
|
||
data GroundItem = GroundItem | ||
{ itemId :: ItemId, | ||
quantity :: Int, | ||
position :: Position, | ||
player :: Maybe String, | ||
despawnTime :: Int | ||
} | ||
deriving (Show) | ||
|
||
instance GetPosition GroundItem where | ||
getPosition = position | ||
|
||
instance Eq GroundItem where | ||
x == y = (itemId x, quantity x, position x) == (itemId y, quantity y, position y) | ||
|
||
type GroundItemKey = (ItemId, Int, Position) | ||
|
||
matches :: GroundItemKey -> GroundItem -> Bool | ||
matches (keyItemId, keyQuantity, keyPosition) item = | ||
itemId item == keyItemId | ||
&& quantity item == keyQuantity | ||
&& position item == keyPosition | ||
|
||
isExpired :: Int -> GroundItem -> Bool | ||
isExpired time i = | ||
time >= despawnTime i | ||
|
||
toItemStack :: GroundItem -> ItemStack.ItemStack | ||
toItemStack item = | ||
ItemStack.ItemStack (itemId item) (quantity item) |
Oops, something went wrong.