public void Initialize(int id, string name, PieceRole role, Vector2 position, Path currentPath, PieceType pType, Team team) { //Debug.Log("initialize"); //_debugStrings = new List<string>(); SetStandardStats(); _id = id; _name = name; _role = role; _team = team; _position = position; _currentPath = currentPath; if (_currentPath != null) { GetNextDestination(); } else { _destination = _position; } _type = pType; _dir = PieceDir.NONE; _moveState = PieceMoveState.NONE; CalculateStatsFromData(); if (_role == PieceRole.DEFENSE) { _coolDownTime = 1.0f; } else { _coolDownTime = 1.0f; } _ammo = new AmmoBandelier(); GenerateRandomAmmo(); SetPosition(); switch (_type) { case PieceType.GENDER_NEUTRAL_1: Anim.speed = UnityEngine.Random.Range(0.9f, 0.95f); break; case PieceType.GENDER_NEUTRAL_2: Anim.speed = UnityEngine.Random.Range(1.0f, 1.05f); break; case PieceType.MALE: Anim.speed = UnityEngine.Random.Range(0.95f, 1.0f); break; case PieceType.FEMALE: Anim.speed = UnityEngine.Random.Range(1.05f, 1.1f); break; } }
void SetStandardStats() { _status = PieceStatus.NORMAL; _pathIndex = 0; _dir = PieceDir.NONE; _moveState = PieceMoveState.NONE; _hasFlag = false; _coolDownTimer = 0.0f; _animationState = PieceAnimationState.NONE; _closestToFlag = false; _downs = 0; _takedowns = 0; _pickups = 0; _balloonsThrown = 0; _distanceWithFlag = 0.0f; }
void GetNextDestination() { if (_moveState == PieceMoveState.NONE) { //Debug.Log("getnextdest - pathIndex = " + _pathIndex + " current x count = " + _currentPath.X.Count); if (_currentPath != null && _currentPath.Points.Count > _pathIndex) { _destination = new Vector2(_currentPath.Points[_pathIndex].x, _currentPath.Points[_pathIndex].y); //Debug.Log("destination = " + _destination); } } else { if (_moveState == PieceMoveState.SET_NODE) { _moveState = PieceMoveState.HIT_NODE; } } }
public void SetDestinationForCapturedFlag(Flag enemyFlag) { if (enemyFlag.Status == FlagStatus.CAPTURED) { MapNode closestNode = null; switch (_moveState) { case PieceMoveState.NONE: closestNode = PathManager.Instance.GetClosestNodePos(_position); if (closestNode != null) { _destination = new Vector2(closestNode.Point.x, closestNode.Point.y); _moveState = PieceMoveState.SET_NODE; _lastNode = _currentNode; _currentNode = closestNode; } break; case PieceMoveState.SET_NODE: case PieceMoveState.HIT_NODE: if (Utilities.CloseEnough(_position, _destination)) { if (_lastNode != null) { closestNode = PathManager.Instance.GetLinkedNodeClosestToPosNotLastNode(_currentNode, enemyFlag.Position, _lastNode); } else { closestNode = PathManager.Instance.GetLinkedNodeClosestToPos(_currentNode, enemyFlag.Position); } if (closestNode != null) { _destination = new Vector2(closestNode.Point.x, closestNode.Point.y); _moveState = PieceMoveState.SET_NODE; _lastNode = _currentNode; _currentNode = closestNode; } } break; } } else { MapNode closestNode = null; float distanceToFlag = (_position - enemyFlag.Position).magnitude; if (_closestToFlag && distanceToFlag < 1.0f) { _destination = enemyFlag.Position; } else { switch (_moveState) { case PieceMoveState.NONE: closestNode = PathManager.Instance.GetClosestNodePos(_position); if (closestNode != null) { _destination = new Vector2(closestNode.Point.x, closestNode.Point.y); _moveState = PieceMoveState.SET_NODE; _currentNode = closestNode; } break; case PieceMoveState.SET_NODE: case PieceMoveState.HIT_NODE: if (Utilities.CloseEnough(_position, _destination)) { if (_lastNode != null) { closestNode = PathManager.Instance.GetLinkedNodeClosestToPosNotLastNode(_currentNode, enemyFlag.Position, _lastNode); } else { closestNode = PathManager.Instance.GetLinkedNodeClosestToPos(_currentNode, enemyFlag.Position); } if (closestNode != null) { _destination = new Vector2(closestNode.Point.x, closestNode.Point.y); _moveState = PieceMoveState.SET_NODE; _currentNode = closestNode; } } break; } } } }