Example #1
0
 protected void Start()
 {
     CompactPath  = new List <Vector3>();
     DetailedPath = new List <Vector3>();
     AStarPathDictionary.Add(gameObject.name, gameObject);
     _mapPlatform = MapPlatformGameObject.GetComponent <MapPlatform>();
 }
Example #2
0
        private void _handleTileLocations()
        {
            if (_mobAttributesMono.Dead)
            {
                return;
            }

            if (_mapPlatform == null)
            {
                _mapPlatform = MapPlatform.Instance;
                return;
            }

            var nextTile = _mapPlatform.GetTile(transform.position);

            if (nextTile == null)
            {
                return;
            }

            _currentTile = nextTile;
            foreach (var t in _currentTile.TurretZonesList)
            {
                t.AlertOfMobPresence(transform.gameObject);
            }
        }
Example #3
0
 protected void Start()
 {
     _mobAttributesMono = GetComponents <MobAttributesMono>()[1];
     Destination        = transform.position;
     _prevLocation      = transform.position;
     _mobModifierRpc    = MobModifierRpcServer.Instance;
     _mapPlatform       = MapPlatform.Instance;
 }
Example #4
0
 protected void Start()
 {
     _mapPlatform           = MapPlatformGameObject.GetComponent <MapPlatform>();
     _pathGroupTeam1        = PathGroupTeam1.GetComponent <PathGroup>();
     _pathGroupTeam2        = PathGroupTeam2.GetComponent <PathGroup>();
     _currentShadowTiles2X2 = new List <GameObject>();
     if (Debugger)
     {
         _myDebugger = Debugger.GetComponent <MyDebugger>();
     }
     Instance = this;
 }
Example #5
0
        private void _handleMovement()
        {
            // Do not move if we do not have a path to move to!
            if (PathName == null)
            {
                return;
            }

            // Do not move the mob if its dead. corpses dont move!
            if (_mobAttributesMono.Dead)
            {
                return;
            }

            // Do not move if not tracked.
            if (MobNumber == 0)
            {
                return;
            }

            if (NetworkingManager.Instance.IsServer)
            {
                #region Server-sided movement handler

                #region Continuously find the platform and path objects.

                if (_mapPlatform == null)
                {
                    _mapPlatform = MapPlatform.Instance;
                    return;
                }

                if (_pathObject == null)
                {
                    AStarPath.AStarPathDictionary.TryGetValue(PathName, out _pathObject);
                    if (!_pathObject)
                    {
                        return;
                    }
                    _path          = _pathObject.GetComponent <AStarPath>();
                    _currPathIndex = _path.CompactPath.Count - 1;
                    _currPathList  = new List <Vector3>(_path.CompactPath);
                    Destination    = _currPathList[_currPathIndex];
                    return;
                }

                #endregion

                #region Check for path object and a checkpoint list.

                if (_path == null)
                {
                    return;
                }

                if (_currPathList.Count == 0)
                {
                    _currPathList  = new List <Vector3>(_path.CompactPath);
                    _currPathIndex = _currPathList.Count - 1;
                    Destination    = _currPathList[_currPathIndex];
                    _mobModifierRpc.UpdateMoveStateSendRpc(MobNumber, transform.position, Destination);
                    return;
                }

                #endregion

                var currPos = transform.position;
                var endPos  = _mobAttributesMono.Flying ? _currPathList[0] : Destination;
                endPos.y = currPos.y;
                var dir = Vector3.Normalize(endPos - currPos);
                var remainingDistance = Vector3.Distance(currPos, endPos);
                var travelDistance    = _mobAttributesMono.MoveSpeed * Time.fixedDeltaTime;
                var nextPosition      = currPos + (dir * travelDistance);

                var distanceAvaliable = remainingDistance > travelDistance;
                var nextPosIsBlocked  = _mapPlatform.LocationIsBlocked(nextPosition);

                #region Blocked path handler.

                if (nextPosIsBlocked && !_mobAttributesMono.Flying)
                {
                    List <Vector3> placeHolder;
                    _mapPlatform.FindAStarPath(currPos, _path.EndPoint.transform.position, out _currPathList, out placeHolder);
                    _currPathIndex = _currPathList.Count - 1;
                    Destination    = _currPathList[_currPathIndex];
                    _mobModifierRpc.UpdateMoveStateSendRpc(MobNumber, transform.position, Destination);
                    return;
                }

                #endregion

                #region Movement and path change handler.

                if (distanceAvaliable)
                {
                    transform.position = nextPosition;
                }
                else
                {
                    transform.position = endPos;

                    if (--_currPathIndex >= 0)
                    {
                        Destination = _currPathList[_currPathIndex];
                        _mobModifierRpc.UpdateMoveStateSendRpc(MobNumber, transform.position, Destination);
                    }
                    else
                    {
                        var nextPath = _path.NextPath.GetComponent <AStarPath>();
                        _path = (nextPath == null || nextPath == _path) ? null : nextPath;
                        if (_path != null)
                        {
                            _currPathIndex = _path.CompactPath.Count - 1;
                            _currPathList  = new List <Vector3>(_path.CompactPath);
                            Destination    = _currPathList[_currPathIndex];
                            _mobModifierRpc.UpdateMoveStateSendRpc(MobNumber, transform.position, Destination);
                        }
                    }
                }

                if (_prevLocation != transform.position)
                {
                    transform.LookAt(2 * transform.position - _prevLocation);
                }
                _prevLocation = transform.position;

                #endregion

                #endregion
            }
            else
            {
                #region Client-sided movement handler

                if (transform.position != Destination)
                {
                    transform.LookAt(Destination);
                }

                var currPos = transform.position;
                var endPos  = Destination;
                endPos.y = currPos.y;
                var dir = Vector3.Normalize(endPos - currPos);
                var remainingDistance = Vector3.Distance(currPos, endPos);
                var travelDistance    = _mobAttributesMono.MoveSpeed * Time.fixedDeltaTime;
                var nextPosition      = currPos + (dir * travelDistance);

                var distanceAvaliable = remainingDistance > travelDistance;

                if (distanceAvaliable)
                {
                    transform.position = nextPosition;
                }

                #endregion
            }
        }