Beispiel #1
0
        private void AgentMove()
        {
            moveDelta.Set((_currentTile.GetFlowFieldPath(VariableFlag.Strategy.CastleFirst).x),
                          _currentTile.GetFlowFieldPath(VariableFlag.Strategy.CastleFirst).y, 0);

            moveDelta          *= Time.deltaTime * _monsterStats.moveSpeed * 0.3f;
            transform.position += moveDelta;
        }
Beispiel #2
0
        public void Execute(TileNode currentNode, VariableFlag.Strategy strategy)
        {
            if (currentNode.towerUnit != null)
            {
                //Enter attack mode
                AttackOnTower(currentNode.towerUnit);
                return;
            }


            if (strategy == VariableFlag.Strategy.None)
            {
                return;
            }

            moveDelta.Set((currentNode.GetFlowFieldPath(strategy).x),
                          currentNode.GetFlowFieldPath(strategy).y, 0);

            moveDelta *= Time.deltaTime * monsterStat.moveSpeed * 0.3f;

            unit.transform.position += moveDelta;
        }
Beispiel #3
0
        protected VariableFlag.Strategy ChooseMoveStrategy(TileNode currentNode, VariableFlag.Strategy[] strategyOrder, VariableFlag.Strategy defaultStrategy)
        {
            if (strategyOrder == null || strategyOrder.Length <= 0)
            {
                return(defaultStrategy);
            }

            int sLength = strategyOrder.Length;

            for (int i = 0; i < sLength; i++)
            {
                if (currentNode.GetFlowFieldPath(strategyOrder[i]) != zeroDelta)
                {
                    return(strategyOrder[i]);
                }
            }

            return(defaultStrategy);
        }
        public override VariableFlag.Strategy Think(TileNode currentNode, VariableFlag.Strategy currentStrategy)
        {
            //If is under destination block, then go with other strategy
            if (!currentNode.IsValidNode || currentNode.BlockComponent.map_type == BlockComponent.Type.Exist)
            {
                return(ChooseMoveStrategy(currentNode, _strategyList, _fallbackStrategy));
            }

            //Find destination direction
            Vector3 direction = (mapGrid.DestinationNode[0].WorldSpace - unit.transform.position).normalized;

            directionVector.Set(0, (direction.y > 0) ? 1 : -1);

            //Move toward castle, but in straight line
            _modifiedVector2.Set(currentNode.GridIndex.x, currentNode.GridIndex.y + (int)directionVector.y);

            //Go Straight Forward
            TileNode nextStraightNode = mapGrid.FindTileNodeByIndex(_modifiedVector2);

            //During Castle/Tower, if movement is downwward and the next step is empty, back to MoveStraight
            if (currentStrategy == VariableFlag.Strategy.CastleFirst || currentStrategy == VariableFlag.Strategy.TowersFirst)
            {
                if (nextStraightNode.IsValidNode && nextStraightNode.IsWalkable && currentNode.GetFlowFieldPath(currentStrategy) == directionVector)
                {
                    return(VariableFlag.Strategy.MoveStraight);
                }
                return(currentStrategy);
            }

            //Go Straight Forward
            if (nextStraightNode.IsValidNode && nextStraightNode.IsWalkable)
            {
                return(VariableFlag.Strategy.MoveStraight);
            }

            return(ChooseMoveStrategy(currentNode, _strategyList, _fallbackStrategy));
        }