Exemplo n.º 1
0
    public TargetGO getTargetGO()
    {
        //check if we have any inactive in the list
        for (int i = 0; i < targets.Count; i++)
        {
            if (targets [i].IsActive == false && !targets[i].DoingAnimation)
            {
                return(targets [i]);
            }
        }

        //otherwise make one
        GameObject obj = Instantiate(targetPrefab) as GameObject;
        TargetGO   go  = obj.GetComponent <TargetGO> ();

        targets.Add(go);
        return(go);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Call a function after a set amount of time
    /// </summary>
    /// <param name="t">The function to perform</param>
    /// <param name="g">The game object to pass when called</param>
    /// <param name="time">The seconds to wait before calling</param>
    /// <returns></returns>
    public static IEnumerator DoAfterTime(TargetGO t, GameObject g, float time)
    {
        yield return(new WaitForSeconds(time));

        t(g);
    }
Exemplo n.º 3
0
 private void EnableTargetGO()
 {
     TargetGO.SetActive(true);
 }
    private void advanceAITurn()
    {
        if (gm.GameIsOver)
        {
            return;
        }

        aiTurnPhase++;
        Debug.Log("ai phase: " + aiTurnPhase);

        //check for reinforcements (this will happen for every AI unit even though there could only be reinforcements before the first one, but it will just be skipped if there are none)
        if (aiTurnPhase == -1)
        {
            ReinforcementMarker marker = gm.getNextReinforcementMarker();
            if (marker == null)
            {
                Debug.Log("no reinforcements, skip ahead");
                aiTurnPhase = 1;                        //skip ahead
            }
            else
            {
                //otherwise focus the cam
                Debug.Log("get ready to reinforce");
                cam.setTarget(marker.CurTilePos);

                return;
            }
        }
        if (aiTurnPhase == 0)
        {
            Debug.Log("time now to reinforce");
            Tile reinforcementTile = gm.spawnReinforcementAtNextMarker();
            //if there was nothing, move on
            if (reinforcementTile == null)
            {
                aiTurnPhase++;
            }
            //otherwise hang out here and focus the camera
            else
            {
                Debug.Log("we got more reinforcememnts");
                aiTurnPhase = -2;
                cam.setTarget(reinforcementTile.Pos);
                return;
            }
        }

        //if there is no active AI unit, move on
        if (gm.activeAIUnit == null)
        {
            if (intoTheBreachMode)
            {
                aiTurnPhase = -2;
                gm.startCleanupPhase();
            }
            else
            {
                aiTurnPhase = -2;
                gm.startPlayerTurn();
            }
            return;
        }


        //are we done with this AI unit's turn?
        Debug.Log("active ai: " + gm.activeAIUnit.idName);
        Debug.Log("   at: " + gm.activeAIUnit.CurTile.Pos.x + " , " + gm.activeAIUnit.CurTile.Pos.y);
        Debug.Log("active info: " + gm.activeAIUnit.aiTurnInfo);
        //Debug.Log("active moves: "+gm.activeAIUnit.aiTurnInfo.moves);
        //if the unit is out of moves or has none, end their turn
        if (aiTurnPhase == 1)
        {
            if (gm.activeAIUnit.aiTurnInfo == null)
            {
                gm.endAITurn();
                aiTurnPhase = -2;                       //reset for next time
                return;
            }
            if (gm.activeAIUnit.curAITurnStep >= gm.activeAIUnit.aiTurnInfo.moves.Count)
            {
                gm.endAITurn();
                aiTurnPhase = -2;
                return;
            }
        }

        //otherwise reveal the card and mark the target
        if (aiTurnPhase == 1)
        {
            //turn on the reveal flag
            if (gm.activeAIUnit.aiTurnInfo.moves [gm.activeAIUnit.curAITurnStep].passMove == false)
            {
                string  cardIDName = gm.activeAIUnit.aiTurnInfo.moves [gm.activeAIUnit.curAITurnStep].cardIDName;
                Card    thisCard   = gm.activeAIUnit.deck.getCardInHandFromID(cardIDName);
                TilePos targetPos  = gm.activeAIUnit.aiTurnInfo.moves [gm.activeAIUnit.curAITurnStep].targetTilePos;

                //if the unit or the target is visible, demo it
                if (gm.board.Grid [targetPos.x, targetPos.y].isVisibleToPlayer || gm.activeAIUnit.getIsVisibleToPlayer() || intoTheBreachMode)
                {
                    autoPlayAITurn = false;

                    thisCard.revealAICardFlag = true;
                    //spawn one or more targets
                    TargetGO target = GameObjectManager.instance.getTargetGO();
                    target.activate(targetPos, thisCard.baseHighlightColor);
                    //focus camera on the target
                    cam.setTarget(targetPos);

                    //if the target is a unit and the card is an attack, let's get some info about the hit
                    Unit thisUnit = gm.board.getUnitOnTile(targetPos);
                    if (thisUnit != null)
                    {
                        thisCard.setPotentialTargetInfo(thisUnit);
                    }
                }
                //otherwise, just move on
                else
                {
                    autoPlayAITurn = true;
                }
            }
            else
            {
                Instantiate(passTurnMarkerPrefab, gm.activeAIUnit.CurTile.Pos.getV3(), Quaternion.identity);
            }
        }

        //play the card
        if (aiTurnPhase == 2)
        {
            if (gm.activeAIUnit.aiTurnInfo.moves [gm.activeAIUnit.curAITurnStep].passMove == false)
            {
                gm.advanceAITurn();
                aiTurnPhase    = 0;
                autoPlayAITurn = !gm.activeAIUnit.getIsVisibleToPlayer() && !intoTheBreachMode;
                //remove targets
                GameObjectManager.instance.turnOffAllTargets();
            }
            else
            {
                aiTurnPhase = -2;                       //reset for next time
                gm.endAITurn();
            }
        }
    }