Beispiel #1
0
        private void TickPathForward(IWorldObject entity, long currentTime, bool instant = false)
        {
            int xOffset = (int)MovementData.MovementPath[CurrentPathIndex].x - Client.baseX;
            int yOffset = (int)MovementData.MovementPath[CurrentPathIndex].z - Client.baseY;

            int localYOffset = Math.Sign((int)yOffset - (int)entity.CurrentY);
            int localXOffset = Math.Sign((int)xOffset - (int)entity.CurrentX);

            if (localYOffset == 0 && 0 == localXOffset)
            {
                //If we have no Y or X diff this tick and we're on the final path
                //point then it's over.
                if (isPathEndReached())
                {
                    StopGenerator();
                    return;
                }

                CurrentPathIndex++;
                InternalUpdate(entity, currentTime);
            }
            else
            {
                if (instant)
                {
                    entity.DirectSetPosition(entity.CurrentX + localXOffset, entity.CurrentY + localYOffset);
                }
                else
                {
                    entity.setPos(entity.CurrentX + localXOffset, entity.CurrentY + localYOffset);
                }
            }
        }
        private void InitializePosition([JetBrains.Annotations.NotNull] NetworkEntityGuid guid,
                                        [JetBrains.Annotations.NotNull] IMovementData movementData,
                                        [JetBrains.Annotations.NotNull] IMovementGenerator <IWorldObject> movementGenerator,
                                        [JetBrains.Annotations.NotNull] IWorldObject entityWorldObject)
        {
            if (guid == null)
            {
                throw new ArgumentNullException(nameof(guid));
            }
            if (movementData == null)
            {
                throw new ArgumentNullException(nameof(movementData));
            }
            if (movementGenerator == null)
            {
                throw new ArgumentNullException(nameof(movementGenerator));
            }
            if (entityWorldObject == null)
            {
                throw new ArgumentNullException(nameof(entityWorldObject));
            }

            //We need to fast forward the fake/stub WorldObject so that we can get an accurate initial position.
            if (movementData is PathBasedMovementData)
            {
                IWorldObject worldObjectStub = new WorldObjectStub((int)movementData.InitialPosition.x - Client.baseX, (int)movementData.InitialPosition.z - Client.baseY);

                //At this point, the worldObjectStub actually will have the correct initial position
                movementGenerator.Update(worldObjectStub, TimeService.CurrentRemoteTime);
                entityWorldObject.DirectSetPosition(worldObjectStub.CurrentX, worldObjectStub.CurrentY);
            }
            else
            {
                entityWorldObject.setPos((int)movementData.InitialPosition.x - Client.baseX, (int)movementData.InitialPosition.z - Client.baseY);
            }
        }