コード例 #1
0
        /// <inheritdoc />
        protected override Task HandleMessage(IPeerSessionMessageContext <GameServerPacketPayload> context, ClientMovementDataUpdateRequest payload, NetworkEntityGuid guid)
        {
            try
            {
                IMovementGenerator <GameObject> generator = MovementGenerator.RetrieveEntity(guid);
                IMovementData movementData = MovementDataMap.RetrieveEntity(guid);
                PositionChangeMovementData changeMovementData = BuildPositionChangeMovementData(payload, generator, movementData);
                MovementDataMap.ReplaceObject(guid, changeMovementData);

                IActorRef playerActorRef = ActorReferenceMappable.RetrieveEntity(guid);

                playerActorRef.TellSelf(new PlayerMovementStateChangedMessage(changeMovementData.Direction));

                //If the generator is running, we should use its initial position instead of the last movement data's position.
                MovementGenerator.ReplaceObject(guid, BuildCharacterControllerMovementGenerator(guid, changeMovementData, generator, movementData));
            }
            catch (Exception e)
            {
                if (Logger.IsErrorEnabled)
                {
                    Logger.Error($"Failed to update MovementData for GUID: {guid} Reason: {e.Message}");
                }

                throw;
            }

            return(Task.CompletedTask);
        }
コード例 #2
0
        /// <inheritdoc />
        protected override Task HandleMessage(IPeerSessionMessageContext <GameServerPacketPayload> context, ClientSetClickToMovePathRequestPayload payload, NetworkEntityGuid guid)
        {
            try
            {
                IMovementGenerator <GameObject> generator = MovementGenerator.RetrieveEntity(guid);

                IMovementData         movementData       = MovementDataMap.RetrieveEntity(guid);
                PathBasedMovementData changeMovementData = BuildPathData(payload, generator, movementData, guid);

                //If it doesn't have more one point reject it
                if (changeMovementData.MovementPath.Count < 2)
                {
                    return(Task.CompletedTask);
                }

                MovementDataMap.ReplaceObject(guid, changeMovementData);

                IActorRef playerActorRef = ActorReferenceMappable.RetrieveEntity(guid);

                Vector3 direction3D = (changeMovementData.MovementPath[1] - changeMovementData.MovementPath[0]);
                Vector2 direction2D = new Vector2(direction3D.x, direction3D.z).normalized;
                playerActorRef.TellSelf(new PlayerMovementStateChangedMessage(direction2D));

                //If the generator is running, we should use its initial position instead of the last movement data's position.
                MovementGenerator.ReplaceObject(guid, new PathMovementGenerator(changeMovementData));
            }
            catch (Exception e)
            {
                if (Logger.IsErrorEnabled)
                {
                    Logger.Error($"Failed to update MovementData for GUID: {guid} Reason: {e.Message}");
                }

                throw;
            }

            return(Task.CompletedTask);
        }