Exemplo n.º 1
0
        protected override void HandleMessage(EntityActorMessageContext messageContext, DefaultEntityActorStateContainer state, CreatureSetPathMovementMessage message)
        {
            PathBasedMovementData           data      = new PathBasedMovementData(message.PathPoints, TimeService.CurrentLocalTime);
            IMovementGenerator <GameObject> generator = MovementGeneratorFactory.Create(new EntityAssociatedData <IMovementData>(state.EntityGuid, data));

            MovementDataMappable.ReplaceObject(state.EntityGuid, data);
            MovementGeneratorMappable.ReplaceObject(state.EntityGuid, generator);
        }
Exemplo n.º 2
0
        protected override void OnEventFired(object source, EntityCreationFinishedEventArgs args)
        {
            IMovementData movementData = MovementDataMappable.RetrieveEntity(args.EntityGuid);

            IMovementGenerator <IWorldObject> generator = MovementGeneratorFactory.Create(new EntityAssociatedData <IMovementData>(args.EntityGuid, movementData));

            MovementGeneratorMappable.AddObject(args.EntityGuid, generator);
        }
        protected override void OnEventFired(object source, EntityWorldObjectCreatedEventArgs args)
        {
            IMovementData movementData = MovementDataMappable.RetrieveEntity(args.EntityGuid);

            IMovementGenerator <IWorldObject> generator = MovementGeneratorFactory.Create(new EntityAssociatedData <IMovementData>(args.EntityGuid, movementData));

            MovementGeneratorMappable.AddObject(args.EntityGuid, generator);

            InitializePosition(args.EntityGuid, movementData, generator, args.WorldReprensetation);
        }
        /// <inheritdoc />
        public override Task HandleMessage(IPeerMessageContext <GameClientPacketPayload> context, MovementDataUpdateEventPayload payload)
        {
            if (!payload.HasMovementData)
            {
                if (Logger.IsWarnEnabled)
                {
                    Logger.Warn($"Empty movement update packet received.");
                }

                return(Task.CompletedTask);
            }

            foreach (var movementUpdate in payload.MovementDatas)
            {
                if (!KnownEntities.isEntityKnown(movementUpdate.EntityGuid))
                {
                    if (Logger.IsInfoEnabled)
                    {
                        Logger.Info($"TODO: Received movement update too soon. Must enable deferred movement update queueing for entities that are about to spawn.");
                    }

                    continue;
                }

                try
                {
                    IMovementGenerator <IWorldObject> generator = MovementGeneratorFactory.Create(movementUpdate);

                    //We just initialize this casually, the next update tick in Unity3D will start the movement generator, the old generator actually might be running right now
                    //at the time this is set.
                    MovementGeneratorMappable.ReplaceObject(movementUpdate.EntityGuid, generator);
                    MovementDataMappable.ReplaceObject(movementUpdate.EntityGuid, movementUpdate.Data);
                }
                catch (Exception e)
                {
                    string error = $"Failed to handle Movement Data for Entity: {movementUpdate.EntityGuid} Type: {movementUpdate.Data.GetType().Name} Error: {e.Message}";

                    if (Logger.IsErrorEnabled)
                    {
                        Logger.Error(error);
                    }

                    throw new InvalidOperationException(error, e);
                }
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 5
0
        public void HandleMovementUpdate(EntityAssociatedData <IMovementData> movementUpdate, bool forceHandleLocal = false)
        {
            if (!KnownEntities.isEntityKnown(movementUpdate.EntityGuid))
            {
                if (Logger.IsInfoEnabled)
                {
                    Logger.Info($"TODO: Received movement update too soon. Must enable deferred movement update queueing for entities that are about to spawn.");
                }

                return;
            }

            try
            {
                if (!forceHandleLocal)
                {
                    //Cheap check, and we're on another thread so performance doesn't really matter
                    if (movementUpdate.EntityGuid == PlayerDetails.LocalPlayerGuid)
                    {
                        if (movementUpdate.Data.isUserCreated)
                        {
                            return;                             //don't handle user created movement data about ourselves. It'll just make movement abit janky locally.
                        }
                    }
                }

                IMovementGenerator <GameObject> generator = MovementGeneratorFactory.Create(movementUpdate);

                //We just initialize this casually, the next update tick in Unity3D will start the movement generator, the old generator actually might be running right now
                //at the time this is set.
                MovementGeneratorMappable.ReplaceObject(movementUpdate.EntityGuid, generator);
                MovementDataMappable.ReplaceObject(movementUpdate.EntityGuid, movementUpdate.Data);
            }
            catch (Exception e)
            {
                string error = $"Failed to handle Movement Data for Entity: {movementUpdate.EntityGuid} Type: {movementUpdate.Data.GetType().Name} Error: {e.Message}";

                if (Logger.IsErrorEnabled)
                {
                    Logger.Error(error);
                }

                throw new InvalidOperationException(error, e);
            }
        }