/// <summary>
    /// Spawns a creature // detailed instructions
    /// </summary>
    /// <param name="spawnable">the creature</param>
    public bool Spawn(Spawnable creature, int lane)
    {
        LaneNode  node     = TournamentManager._instance.lanes[lane - 1].GetFirstLaneNode(logicBase);
        IResponse response = new ActionResponse(creature == Spawnable.Bunny ? TournamentManager._instance.bunnyPrefab.GetComponent <CreatureBase> () : TournamentManager._instance.unicornPrefab.GetComponent <CreatureBase> (), lane, logicBase, ResponseActionType.Spawn, node);

        /* fail the Spawn */
        // LogStack.Log ("Tokens: " + tokens, LogLevel.Debug);
        // LogStack.Log ("Node Creature Count: " + (node.activeCreature != null ? 1 : 0), LogLevel.System);
        if (lane > TournamentManager._instance.lanes.Count || node.activeCreature != null || spawnNodesTaken.Contains(node))
        {
            // LogStack.Log ("Response | Spawn Failed Lane: " + lane, LogLevel.Stack);
            return(false);
        }
        else
        {
            if (!SpendToken())
            {
                return(false);
            }
            // LogStack.Log ("Response | Spawn Success Lane: " + lane, LogLevel.Stack);
            spawnNodesTaken.Add(node);
            if (!ResponseChain.Contains(response))
            {
                ResponseChain.Add(response);
            }
            else
            {
                LogStack.Log("##### Duplicate Spawn Response", LogLevel.System);
                RefundToken();
            }
            return(true);
        }
    }
        public CreatureBase[] GetNearestEnemies(LaneManager[] Board)
        {
            LogStack.Log("GetNearestEnemies()", Logging.LogLevel.Color);
            List <CreatureBase> nearestCreatures = new List <CreatureBase> ();

            foreach (LaneManager lane in Board)
            {
                LaneNode            startNode     = lane.GetFirstLaneNode(this);
                List <CreatureBase> tempCreatures = lane.GetEnemiesInLane(this);
                if (tempCreatures.Count > 0)
                {
                    nearestCreatures.Add(tempCreatures[0]);
                }
            }
            LogStack.Log("Three nearest enemies: " + nearestCreatures.Count, Logging.LogLevel.Debug);
            // Func<int, int, bool> FindNearestOfTwoDependatOnPlayerSide = (x, y) => _PlayerNumber == 1 ? x > y : x < y;

            if (_PlayerNumber == 1)
            {
                nearestCreatures.Sort((a, b) => a.LaneIndex.CompareTo(b.LaneIndex));   // ascending sort
            }
            else
            {
                nearestCreatures.Sort((a, b) => - 1 * a.LaneIndex.CompareTo(b.LaneIndex));  // descending sort
            }
            return(nearestCreatures.ToArray());
        }
    public int GetOpenNodes(LaneNode currentNode, bool rightFacing)
    {
        int openNodes = 0;

        // if (rightFacing) {
        //     for (int i = 1; i < currentNode.laneManager.allNodes.Count; i++) {
        //         LaneNode nextNode = allNodes[allNodes.IndexOf (currentNode) + i];
        //         if (nextNode.activeCreature == null) {
        //             openNodes ++;
        //         }
        //     }
        // }

        for (int i = 1; i < currentNode.laneManager.allNodes.Count; i++)
        {
            LaneNode nextNode = allNodes[Mathf.Clamp(allNodes.IndexOf(currentNode) + (rightFacing ? i : -i), 0, currentNode.laneManager.allNodes.Count - 1)];
            if (nextNode != null && nextNode.activeCreature == null)
            {
                openNodes++;
            }
            else if (nextNode.activeCreature != null)
            {
                break;
            }
        }
        return(openNodes);
    }
    public LaneNode GetNextLaneNode(LaneNode currentNode, bool rightFacing, int range, bool forced = false)
    {
        //TODO: Something not right
        //If the next block has a creature in it, fail the move
        LaneNode nextNode    = null;
        bool     nodeBlocked = false;

        for (int i = 1; i < range + 1; i++)
        {
            nextNode = allNodes[Mathf.Clamp(allNodes.IndexOf(currentNode) + (rightFacing ? i : -i), 0, currentNode.laneManager.allNodes.Count - 1)];
            if (nextNode.activeCreature != null && !forced)
            {
                nodeBlocked = true;
            }
        }

        if (nextNode != null && (!lanesTakenThisRound.Contains(nextNode) || forced) && !nodeBlocked)
        {
            // LogStack.Log (currentNode.activeCreature + " - " + currentNode.activeCreature.GetInstanceID () + " nextNode not null and available | from: " + allNodes.IndexOf (currentNode) + " to: " + allNodes.IndexOf (nextNode) + " | Progress: " + currentNode.activeCreature.LaneProgress, LogLevel.System);
            if (!forced)
            {
                lanesTakenThisRound.Add(nextNode);
            }
            return(nextNode);
        }
        else
        {
            return(null);
        }
    }
Exemple #5
0
 public ActionResponse(CreatureBase Creature, int Lane, AI.LogicBase LogicBase, ResponseActionType ResponseActionType, LaneNode LaneNode)
 {
     _lane               = Lane;
     _creatureBase       = Creature;
     _logicBase          = LogicBase;
     _responseActionType = ResponseActionType;
     _laneNode           = LaneNode;
 }
Exemple #6
0
 public void Init(LogicBase _owner, LaneManager _lane, Spawnable _type, UIHealth _healthUI, float _damageAmount)
 {
     if (init == false)
     {
         owner          = _owner;
         lane           = _lane;
         creatureType   = _type;
         uiHealth       = _healthUI;
         damageAmount   = _damageAmount;
         range          = _type == Spawnable.Bunny ? TournamentManager._instance.bunnyRange : TournamentManager._instance.unicornRange;
         init           = true;
         activeLaneNode = lane.GetFirstLaneNode(owner);
         activeLaneNode.activeCreature = this;
         owner._Creatures.Add(this);
         rightFacing = owner._RightFacing;
         // Debug.Log ("Creature owned by " + owner);
     }
 }
    public bool Move(CreatureBase creature, int range = 1)
    {
        if (creature == null || creature.isDead)
        {
            return(false);
        }
        range = Mathf.Clamp(range, 0, tokens);

        LogStack.Log("creature.ActiveLaneNode: " + creature.ActiveLaneNode, LogLevel.System);
        LogStack.Log("creature.Owner._RightFacing: " + creature.Owner._RightFacing, LogLevel.System);

        LaneNode nextNode = creature.ActiveLaneNode.laneManager.GetNextLaneNode(creature.ActiveLaneNode, creature.Owner._RightFacing, creature.ActiveLaneNode.laneManager.GetMaxNodes(creature.ActiveLaneNode, creature.Owner._RightFacing, Mathf.Abs(range)));

        // LaneNode nextNode = creature.ActiveLaneNode.laneManager.GetNextLaneNode (creature.ActiveLaneNode, creature.Owner._RightFacing, Mathf.Abs (range)); LogStack.Log ("nextNode: " + nextNode, LogLevel.System);

        if (creature != null && nextNode != null && nextNode.activeCreature == null)
        {
            LogStack.Log("Next Node: " + nextNode.GetInstanceID(), LogLevel.System);
            if (SpendToken(range))
            {
                LogStack.Log("Response | Move " + range, LogLevel.Stack);
                IResponse response = new ActionResponse(creature, 0, logicBase, ResponseActionType.Move, nextNode);
                if (!ResponseChain.Contains(response))
                {
                    ResponseChain.Add(response);
                }
                else
                {
                    LogStack.Log("##### Duplicate Move Response", LogLevel.System);
                    RefundToken();
                    return(false);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            return(false);
        }
    }
Exemple #8
0
    public void Move(LaneNode nextNode)
    {
        LogStack.Log("Moving Creature", LogLevel.Stack);
        CameraShake._CameraShake.DoCameraShake(0.2f, rightFacing ? 0.2f : -0.2f);
        if (activeLaneNode.activeCreature == this)
        {
            activeLaneNode.activeCreature = null;
        }
        LogStack.Log("MOVING: Current Node - " + activeLaneNode.name, LogLevel.System);
        activeLaneNode = nextNode;
        if (nextNode != null)
        {
            LogStack.Log("MOVING: New Node - " + activeLaneNode.name, LogLevel.System);
            activeLaneNode.activeCreature = this;

            transform.position = activeLaneNode.transform.position;
        }
        laneProgress = LaneProgress;
        Win();
    }
    public List <CreatureBase> SearchRange(int range, LaneNode currentNode, LogicBase player)
    {
        List <CreatureBase> creaturesInRange = new List <CreatureBase> ();

        for (int i = -range; i < range + 1; i++)
        {
            if (allNodes.IndexOf(currentNode) + i >= 0 && allNodes.IndexOf(currentNode) + i < allNodes.Count)
            {
                if (allNodes[allNodes.IndexOf(currentNode) + i].activeCreature != null)
                {
                    creaturesInRange.Add(allNodes[allNodes.IndexOf(currentNode) + i].activeCreature);
                }
            }
        }
        if (player._PlayerNumber == 2)
        {
            creaturesInRange.Reverse();
        }

        return(creaturesInRange);
    }
    IEnumerator PerformActions(IResponse[] ResponseChain)
    {
        // LogStack.Log ("--- PerformActions BEGIN", LogLevel.System);
        //Spawning
        foreach (IResponse response in ResponseChain)
        {
            if (response.responseActionType == ResponseActionType.Spawn)
            {
                // LogStack.Log ("Response: " + response.player + " | " + response.responseActionType + " in lane " + response.Lane, LogLevel.System);
                Spawn(response);
            }
        }
        yield return(new WaitForSeconds(TournamentManager._instance.laneReadyWait));

        //Move
        foreach (IResponse response in ResponseChain)
        {
            if (response.creature.CreatureType == Spawnable.Bunny && response.responseActionType == ResponseActionType.Move)
            {
                // LogStack.Log ("Response: " + response.player + " | " + response.responseActionType + " in lane " + response.Lane, LogLevel.System);
                if (!response.creature.isDead)
                {
                    if (response.laneNode.activeCreature == null)
                    {
                        response.creature.Move(response.laneNode);
                    }
                    else
                    {
                        LaneNode nodeBack = response.laneNode.laneManager.PreviousNode(response.laneNode, response.creature.Owner);
                        response.creature.Move(nodeBack);
                        response.creature.Owner.AIResponse.RefundToken();
                        response.creature.Owner.AIResponse.RefundToken(response.laneNode.laneManager.GetNodeDistance(nodeBack, response.laneNode));
                    }
                }
                else
                {
                    response.creature.Owner.AIResponse.RefundToken(response.laneNode.laneManager.GetNodeDistance(response.creature.ActiveLaneNode, response.laneNode));
                }
            }
            else if (response.creature.CreatureType == Spawnable.Unicorn && response.responseActionType == ResponseActionType.Attack)
            {
                yield return(new WaitForSeconds(TournamentManager._instance.moveWait));

                // LogStack.Log ("Response: " + response.player + " | " + response.responseActionType + " in lane " + response.Lane, LogLevel.System);
                response.creature.Attack();
                LaneNode nextNode = response.laneNode.laneManager.GetNextLaneNode(response.laneNode, response.creature.RightFacing, 1, true);
                if (response.creature.LaneProgress + 1 >= response.creature.ActiveLaneNode.laneManager.allNodes.Count && nextNode.activeCreature == null)   //One node before end
                {
                    if (!response.creature.isDead)
                    {
                        response.creature.Move(nextNode);
                    }
                    else
                    {
                        response.creature.Owner.AIResponse.RefundToken();
                    }
                }
            }
        }
        yield return(new WaitForSeconds(TournamentManager._instance.moveWait));

        //Attack
        foreach (IResponse response in ResponseChain)
        {
            if (response.creature.CreatureType == Spawnable.Bunny && response.responseActionType == ResponseActionType.Attack)
            {
                // LogStack.Log ("Response: " + response.player + " | " + response.responseActionType + " in lane " + response.Lane, LogLevel.System);
                response.creature.Attack();
                LaneNode nextNode = response.laneNode.laneManager.GetNextLaneNode(response.laneNode, response.creature.RightFacing, 1, true);
                if (response.creature.LaneProgress + 1 >= response.creature.ActiveLaneNode.laneManager.allNodes.Count && nextNode.activeCreature == null)   //One node before end
                {
                    if (!response.creature.isDead)
                    {
                        if (nextNode.activeCreature == null)
                        {
                            response.creature.Move(nextNode);
                        }
                        else
                        {
                            LaneNode nodeBack = nextNode.laneManager.PreviousNode(nextNode, response.creature.Owner);
                            response.creature.Move(nodeBack);
                            response.creature.Owner.AIResponse.RefundToken();
                            response.creature.Owner.AIResponse.RefundToken(nextNode.laneManager.GetNodeDistance(nodeBack, nextNode));
                        }
                    }
                    else
                    {
                        response.creature.Owner.AIResponse.RefundToken(response.laneNode.laneManager.GetNodeDistance(response.creature.ActiveLaneNode, nextNode));
                    }
                }
            }
            else if (response.creature.CreatureType == Spawnable.Unicorn && response.responseActionType == ResponseActionType.Move)
            {
                yield return(new WaitForSeconds(TournamentManager._instance.attackWait));

                // LogStack.Log ("Response: " + response.player + " | " + response.responseActionType + " in lane " + response.Lane, LogLevel.System);
                if (!response.creature.isDead)
                {
                    response.creature.Move(response.laneNode);
                }
                else
                {
                    response.creature.Owner.AIResponse.RefundToken();
                }
            }
        }
        yield return(new WaitForSeconds(TournamentManager._instance.attackWait));

        tickState = TickState.FireTick;
        OnResponse(null);
        // LogStack.Log ("--- PerformActions END", LogLevel.System);
    }
 public LaneNode PreviousNode(LaneNode nextNode, LogicBase owner)
 {
     nextNode = nextNode.laneManager.allNodes[nextNode.laneManager.allNodes.IndexOf(nextNode) + (owner._RightFacing ? -1 : 1)];
     return(nextNode);
 }
 public int GetNodeDistance(LaneNode firstNode, LaneNode secondNode)
 {
     return(Mathf.Abs(firstNode.laneManager.allNodes.IndexOf(firstNode) - firstNode.laneManager.allNodes.IndexOf(secondNode)));
 }