public override void SetMovementAndPosition()
        {
            LocalCharacterHandler.MovementType movementType = LocalCharacterHandler.MovementType.Idle;
            if (_details.State.Equals("moving", GlobalData.InputDataStringComparison))
            {
                movementType = LocalCharacterHandler.MovementType.Moving;
            }

            int timeArrivalMs = 0;

            if (movementType == LocalCharacterHandler.MovementType.Moving)
            {
                DateTime movingStartTime = DateTime.Now;
                DateTime movingEndTime   = DateTime.Now;

                if
                (
                    DateTime.TryParseExact(_details.MovingStartTime, GlobalData.MovementTimeExchangeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out movingStartTime) &&
                    DateTime.TryParseExact(_details.MovingEndTime, GlobalData.MovementTimeExchangeFormat, CultureInfo.InstalledUICulture, DateTimeStyles.None, out movingEndTime)
                )
                {
                    timeArrivalMs = Measure.GetTimeMsBetween(movingEndTime, movingStartTime);
                }
            }

            _localCharacterHandler.UpdateMovement
            (
                movementType,
                _details.DestinationLoc,
                _details.Angle,
                timeArrivalMs,
                false
            );
        }
Example #2
0
    private async void HandlePositionCorrectionAsync()
    {
        try
        {
            while (true)
            {
                await Task.Factory.StartNew(() => Thread.Sleep(1000));

                if (_playerCharacter == null || _timeArrivalTotal > 0f)
                {
                    continue;
                }

                if (this == null || this.gameObject == null || !_isWorking)
                {
                    break;
                }

                _currentDistance = Vector3.Distance(this.gameObject.transform.position, _playerCharacter.transform.position);

                if (_currentDistance >= _correctionDistance)
                {
                    _distanceCorrectionTimeCounter++;
                }
                else
                {
                    _distanceCorrectionTimeCounter = 0;
                }

                if (_distanceCorrectionTimeCounter >= _correctionTime)
                {
                    LocalCharacterHandler charHandler = _playerCharacter.GetComponent <LocalCharacterHandler>();

                    charHandler.UpdateMovement
                    (
                        LocalCharacterHandler.MovementType.Idle,
                        this.gameObject.transform.position,
                        charHandler.CurrentAngle,
                        0,
                        false
                    );

                    _distanceCorrectionTimeCounter = 0;
                }
            }
        }
        catch (Exception exception)
        {
            _chat.UpdateLog($"Position mark handler - position correction handling error: {exception.Message}");
        }
    }
Example #3
0
    private void MoveNonPlayerCharacter(int charId, /*Vector3 oldPosition,*/ Vector3 newPosition, int timeArrivalMs)
    {
        GameObject            character   = null;
        LocalCharacterHandler charHandler = null;
        LocalCharacterDetails details     = null;

        foreach (GameObject item in _localCharacterObjectList)
        {
            charHandler = item.GetComponent <LocalCharacterHandler>();
            details     = charHandler.GetDetails();

            if (details.CharId == charId)
            {
                character = item;
                break;
            }
        }

        if (character == null)
        {
            Debug.Log($"Local place manager - MoveCharacterAsync() - cannot find character by char ID [{charId}]");
            return;
        }

        if (charHandler.IsPlayerMainCharacter)
        {
            Debug.Log($"Local place manager - MoveCharacterAsync() - cannot move player main character. Use MovePlayerCharacter() instead!");
            return;
        }

        Vector3 oldPosition = character.transform.position;
        float   angle       = Measure.CalculateMovingAngle(oldPosition, newPosition);

        charHandler.UpdateMovement
        (
            LocalCharacterHandler.MovementType.Moving,
            //oldPosition,
            newPosition,
            angle,
            timeArrivalMs,
            false
        );
    }
Example #4
0
    private void MovePlayerCharacter(Vector3 newPosition)
    {
        if (_playerCharacter == null)
        {
            _chat.UpdateLog("MovePlayerCharacter() - cannot find player character instance");
            return;
        }

        LocalCharacterHandler charHandler = _playerCharacter.GetComponent <LocalCharacterHandler>();
        int   timeArrivalMs = Measure.CalculateTimeArrivalInMs(_playerCharacter.transform.position, newPosition, charHandler.MovingVelocity);
        float angle         = Measure.CalculateMovingAngle(_playerCharacter.transform.position, newPosition);

        charHandler.UpdateMovement
        (
            LocalCharacterHandler.MovementType.Moving,
            /*_playerCharacter.transform.position,*/
            newPosition,
            angle,
            timeArrivalMs,
            true
        );
    }
    private async void CheckCollisionAsync()
    {
        await Task.Factory.StartNew(() => Thread.Sleep(100));

        if (this == null || this.gameObject == null || _parentObject == null)
        {
            return;
        }

        if (!_isCollisionDetected)
        {
            _checkpointX         = _parentObject.transform.position.x;
            _checkpointY         = _parentObject.transform.position.y;
            _checkpointZ         = _parentObject.transform.position.z;
            _isCheckpointReached = true;
            return;
        }

        if (_isCheckpointReached)
        {
            LocalCharacterHandler handler = _parentObject.GetComponent <LocalCharacterHandler>();
            Vector3 pointTo = new Vector3(_checkpointX, _checkpointY, _checkpointZ);
            double  angle   = Measure.CalculateMovingAngle(_parentObject.transform.position, pointTo);

            handler.UpdateMovement
            (
                LocalCharacterHandler.MovementType.Moving,
                /*new Vector3(_checkpointX, _checkpointY, _checkpointZ), */
                pointTo,
                angle,
                0,
                true
            );
        }

        _isCollisionDetected = false;
    }