Exemple #1
0
    IEnumerator GenerateAttackAnims(UnitProxy oppUnit, GameObject baseProj, Vector3 start, Vector3 finish)
    {
        TileProxy dTile = BoardProxy.instance.GetTileAtPosition(GetPosition());

        dTile.CreateAnimation(Glossary.GetAtkFx(oppUnit.GetData().GetFactionType(), oppUnit.GetData().GetUnitType()), AnimationInteractionController.NO_WAIT);
        yield return(null);
    }
Exemple #2
0
    public bool IsAttacked(UnitProxy oppUnit, bool useAttack = true)
    {
        Debug.Log("IsAttacked");
        if (useAttack)
        {
            oppUnit.GetData().GetTurnActions().Attack();
        }
        PanelControllerNew.SwitchChar(oppUnit);

        //Damage the unit

        /*
         * Trigger the opponent's attack trigger here
         */

        Vector3Int animStart = oppUnit.GetPosition();
        Vector3Int animEnd   = GetPosition();

        Debug.Log("animStart: " + animStart.ToString());
        Debug.Log("animEnd: " + animEnd.ToString());

        Vector3Int diff = animEnd - animStart;

        if (_data.GetAegis())
        {
            Debug.Log("Aegis!");
            //_data.SetAegis(false);
            StartCoroutine(AttackAnim(oppUnit, oppUnit.gameObject.transform.GetChild(0).GetComponent <Animator>(),
                                      oppUnit.gameObject.transform, diff, "", useAttack));
            //LostAegisAnim();
            SetAegis(false, AnimationInteractionController.ATK_WAIT);
            return(false);
        }
        Debug.Log("No Aegis");

        StartCoroutine(AttackAnim(oppUnit, oppUnit.gameObject.transform.GetChild(0).GetComponent <Animator>(),
                                  oppUnit.gameObject.transform, diff, "-" + oppUnit.GetData().GetAttack().ToString(), useAttack));

        GetData().IsAttacked(oppUnit.GetData().GetAttack());
        if (GetData().IsDead())
        {
            if (oppUnit == this)
            {
                BoardProxy.instance.GiveLowestCharLvl(this);
            }
            else
            {
                oppUnit.AddLevel();
            }
            return(true);
        }
        return(false);
    }
Exemple #3
0
    public void HighlightSelectedAdv(UnitProxy inRangeUnit, List <TileProxy> visitable, List <TileProxy> attackable)
    {
        bool canAtk = inRangeUnit.GetData().GetTurnActions().CanAttack();
        bool canMv  = inRangeUnit.GetData().GetTurnActions().CanMove();

        if (BoardProxy.instance.GetTileAtPosition(inRangeUnit.GetPosition()) == this)
        {
            if (!canAtk && !canMv)
            {
                GetComponent <Renderer>().material.color = SHADING_UNDERLAY;
                transform.GetChild(0).gameObject.SetActive(true);
                transform.GetChild(0).gameObject.GetComponent <SpriteRenderer>().color = MOVE;
            }
            return;
        }

        if (canAtk)
        {
            if (attackable.Contains(this))
            {
                if (HasUnit() && inRangeUnit.GetData().GetTeam() != GetUnit().GetData().GetTeam())
                {
                    //GetComponent<Renderer>().material.color = ATK_ACTIVE;
                    GetComponent <Renderer>().material.color = SHADING_UNDERLAY;
                    transform.GetChild(0).gameObject.SetActive(true);
                    transform.GetChild(0).gameObject.GetComponent <SpriteRenderer>().color = ATK_ACTIVE;
                }
                else if (!HasObstacle())
                {
                    GetComponent <Renderer>().material.color = SHADING_UNDERLAY;
                    transform.GetChild(0).gameObject.SetActive(true);
                    transform.GetChild(0).gameObject.GetComponent <SpriteRenderer>().color = ATK_INACTIVE;
                    //GetComponent<Renderer>().material.color = ATK_INACTIVE;
                }
            }
        }
        if (canMv)
        {
            if (visitable.Contains(this))
            {
                if (!(HasUnit() && canAtk))
                {
                    GetComponent <Renderer>().material.color = SHADING_UNDERLAY;
                    transform.GetChild(0).gameObject.SetActive(true);
                    transform.GetChild(0).gameObject.GetComponent <SpriteRenderer>().color = MOVE;
                    //GetComponent<Renderer>().material.color = MOVE;
                }
            }
        }
    }
 public override void OnTileSelected(TileProxy tile)
 {
     if (currentUnit != null && visitableTiles.Contains(tile))
     {
         TileProxy startTile = BoardProxy.instance.GetTileAtPosition(currentUnit.GetPosition());
         if (startTile != tile)
         {
             UnitProxy unit = startTile.GetUnit();
             if (unit.GetData().GetTurnActions().CanMove())
             {
                 unit.GetData().GetTurnActions().Move();
                 PanelController.SwitchChar(unit);
                 StartCoroutine(currentUnit.CreatePathToTileAndLerpToPosition(tile,
                                                                              () =>
                 {
                     tile.ReceiveGridObjectProxy(currentUnit);
                     startTile.RemoveGridObjectProxy(currentUnit);
                     UnHighlightTiles();
                     InteractivityManager.instance.EnterDefaultMode();
                 }));
             }
             else
             {
                 Debug.Log("Out of actions. Send signal to player they can't move unit.");
             }
         }
         else
         {
             StartCoroutine(currentUnit.CreatePathToTileAndLerpToPosition(tile,
                                                                          () =>
             {
                 StartCoroutine(ResetTiles());
             }));
         }
     }
     else if (currentUnit != null)
     {
         //Select all the tiles with opp team in all tiles
         //List<TileProxy> visitableTiles = allTiles.Where(tl => tl.GetUnit().GetData().GetTeam() != currentUnit.GetData().GetTeam()).ToList<TileProxy>();
         if (!allTiles.Where(tl => tl.HasUnit() && (tl.GetUnit().GetData().GetTeam() != currentUnit.GetData().GetTeam())).ToList <TileProxy>().Contains(tile))
         {
             BoardProxy.instance.FlushTiles();
             PanelController.SwitchChar(null);
         }
         ////Player clicked out of unit range, reset tiles/UI so player can click somewhere else instead
         //BoardProxy.instance.FlushTiles();
         //PanelController.SwitchChar(null);
     }
 }
Exemple #5
0
    public bool IsAttacked(UnitProxy oppUnit)
    {
        //Decrement the attacking units attack actions and update the ui
        oppUnit.GetData().GetTurnActions().Attack();
        PanelController.SwitchChar(oppUnit);

        //Damage the unit
        GetData().IsAttacked(oppUnit.GetData().GetAttack());
        StartCoroutine(Shake());
        if (GetData().IsDead())
        {
            return(true);
        }
        return(false);
    }
    //public void ResetAtThis()
    //{
    //    StartCoroutine(ResetTiles());
    //}

    public override void OnUnitSelected(UnitProxy obj)
    {
        if (currentUnit == null)
        {
            UnHighlightTiles();
            currentUnit = obj;
            //The maximum range in which a player has actions
            allTiles = BoardProxy.instance.GetAllVisitableNodes(obj, obj.GetMoveSpeed() > obj.GetAttackRange() ? obj.GetMoveSpeed() : obj.GetAttackRange(), true);
            //The attackable tiles
            attackableTiles = BoardProxy.instance.GetAllVisitableNodes(obj, obj.GetAttackRange(), true);
            //The visitable tiles
            visitableTiles = BoardProxy.instance.GetAllVisitableNodes(obj, obj.GetMoveSpeed());
            HighlightTiles(obj);
            PanelController.SwitchChar(obj);
        }
        else
        {
            if (obj.GetData().GetTeam() != currentUnit.GetData().GetTeam() &&
                allTiles.Contains(BoardProxy.instance.GetTileAtPosition(obj.GetPosition())) &&
                currentUnit.GetData().GetTurnActions().CanAttack())
            {
                if (obj.IsAttacked(currentUnit))
                {
                    //If the unit has died, remove it from the board and destroy the gameobject
                    BoardProxy.instance.GetTileAtPosition(obj.GetPosition()).RemoveGridObjectProxy(obj);
                    Destroy(obj.gameObject);
                    ConditionTracker.instance.EvaluateGame();
                    //Turn off the tiles
                    StartCoroutine(ResetTiles());
                }
                OnDisable();
                PanelController.SwitchChar(currentUnit);
            }
        }
    }
 void SetCharMv(UnitProxy unit)
 {
     if (unit == null)
     {
         MvPnl.SetActive(false);
         return;
     }
     MvPnl.SetActive(true);
     MvPnl.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = unit.GetData().GetMoveSpeed().ToString();
 }
 void SetCharAtkRng(UnitProxy unit)
 {
     if (unit == null)
     {
         AtkRngPnl.SetActive(false);
         return;
     }
     AtkRngPnl.SetActive(true);
     AtkRngPnl.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = unit.GetData().GetAtkRange().ToString();
 }
Exemple #9
0
    IEnumerator FloatUpAnim(string msg, Color color, float wait, Transform oTransform, bool shakeChar = false, bool deathConsideration = false)
    {
        yield return(new WaitForSeconds(wait));

        //Debug.Log("FloatUpAnim");
        if (oTransform != null)
        {
            Vector3 pos = oTransform.position;
            //Debug.Log("FloatUpAnim pos: " + pos.ToString());
            //pos.x += .3f;
            //pos.y += 1f;
            if (oTransform.GetComponent <TileProxy>() != null)
            {
                pos.x -= .3f;
                pos.y += .5f;
            }
            else
            {
                //pos.x -= .3f;
                pos.y += 1f;
            }
            if (shakeChar)
            {
                yield return(new WaitForSeconds(.2f));

                oTransform.GetComponent <UnitProxy>().Shake();
                PlayImpactSound();
            }
            if (deathConsideration)
            {
                UnitProxy unit = oTransform.GetComponent <UnitProxy>();
                if (unit.GetData().IsDead())
                {
                    ConditionTracker.instance.EvalDeath(unit);
                }
            }
            else
            {
                GameObject numObj = new GameObject();
                numObj.transform.position = pos;
                numObj.transform.rotation = Quaternion.identity;
                numObj.transform.parent   = oTransform;
                numObj.AddComponent <TextMesh>();
                numObj.GetComponent <MeshRenderer>().sortingLayerName = "Emotes";
                numObj.GetComponent <TextMesh>().characterSize        = .2f;
                numObj.GetComponent <TextMesh>().text  = msg;
                numObj.GetComponent <TextMesh>().color = color;
                iTween.ShakePosition(numObj, new Vector3(0, .5f, 0), .3f);
                iTween.MoveTo(numObj, new Vector3(pos.x, pos.y + .3f, pos.z), .3f);
                yield return(new WaitForSeconds(.4f));

                Destroy(numObj);
            }
        }
    }
 void SetCharHealth(UnitProxy unit)
 {
     if (unit == null)
     {
         HealthPanel.SetActive(false);
         return;
     }
     HealthPanel.SetActive(true);
     HealthPanel.GetComponent <Image>().enabled = true;
     foreach (Transform t in HealthPanel.transform)
     {
         if (t.name.Equals("HealthFillBar"))
         {
             t.GetComponent <Image>().fillAmount = (float)unit.GetData().GetCurrHealth() / (float)unit.GetData().mxHlth;
         }
         else if (t.name.Equals("HealthText"))
         {
             t.GetComponent <TextMeshProUGUI>().text = unit.GetData().GetCurrHealth().ToString() + " / " + unit.GetData().mxHlth.ToString();
         }
     }
 }
    public static void SwitchChar(UnitProxy player, UnitProxy enemy)
    {
        ClearPanels();
        if (player != null && enemy != null)
        {
            //Debug.Log("Attacking Chars: " + player.GetData().characterMoniker + "-" + enemy.GetData().characterMoniker);
            int playerDmg = enemy.GetData().GetTurnActions().CanAttack() ? (TurnController.instance.currentTeam == BoardProxy.PLAYER_TEAM ? 0 : enemy.GetData().GetAttack()) : 0;
            int enemyDmg  = player.GetData().GetTurnActions().CanAttack() ? (TurnController.instance.currentTeam == BoardProxy.ENEMY_TEAM ? 0 : player.GetData().GetAttack()) : 0;

            LoadPlayerPanel(player, playerDmg);
            LoadEnemyPanel(enemy, enemyDmg);
        }
    }
 void SetTeam(UnitProxy unit)
 {
     if (unit == null)
     {
         TeamPanel.SetActive(false);
     }
     else
     {
         TeamPanel.SetActive(true);
         // TODO: Change the outline banner here based on the faction
         TeamPanel.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = unit.GetData().GetTeam().ToString();
     }
 }
    public void HighlightSelectedAdv(UnitProxy inRangeUnit, List <TileProxy> visitable, List <TileProxy> attackable)
    {
        bool canAtk = inRangeUnit.GetData().GetTurnActions().CanAttack();
        bool canMv  = inRangeUnit.GetData().GetTurnActions().CanMove();

        if (BoardProxy.instance.GetTileAtPosition(inRangeUnit.GetPosition()) == this)
        {
            if (!canAtk && !canMv)
            {
                GetComponent <Renderer>().material.color = Color.red;
            }
            return;
        }

        if (canAtk)
        {
            if (attackable.Contains(this))
            {
                if (HasUnit() && inRangeUnit.GetData().GetTeam() != GetUnit().GetData().GetTeam())
                {
                    GetComponent <Renderer>().material.color = Color.blue;
                }
                else
                {
                    GetComponent <Renderer>().material.color = Color.cyan;
                }
            }
        }
        if (canMv)
        {
            if (visitable.Contains(this))
            {
                if (!(HasUnit() && canAtk))
                {
                    GetComponent <Renderer>().material.color = Color.red;
                }
            }
        }
    }
Exemple #14
0
 public override void DidWait(UnitProxy unit)
 {
     foreach (TileProxy tl in BoardProxy.instance.GetAllVisitableNodes(unit, value + 1, true))
     {
         bool isUnit = tl == BoardProxy.instance.GetTileAtPosition(unit.GetPosition());
         if (!isUnit)
         {
             tl.FloatUp(Skill.Actions.DidWait, "+bide", Color.green, "+1 hp allies from waiting");
             if (tl.HasUnit() && tl.GetUnit().GetData().GetTeam() == unit.GetData().GetTeam())
             {
                 tl.GetUnit().ReceiveHPBuff(1);
             }
         }
     }
 }
Exemple #15
0
 public override void DidAttack(UnitProxy attacker, UnitProxy defender)
 {
     foreach (TileProxy tl in BoardProxy.instance.GetAllVisitableNodes(attacker, value + 1, true))
     {
         bool isAttacker = tl == BoardProxy.instance.GetTileAtPosition(attacker.GetPosition());
         if (!isAttacker)
         {
             //tl.FloatUp(Skill.Actions.DidAttack, "+aegis", Color.blue, "Aegis Allies");
             tl.CreateAnimation(Glossary.fx.fireShield, AnimationInteractionController.ATK_WAIT);
             if (tl.HasUnit() && tl.GetUnit().GetData().GetTeam() == attacker.GetData().GetTeam())
             {
                 tl.GetUnit().SetAegis(true, AnimationInteractionController.ATK_WAIT);
             }
         }
     }
 }
Exemple #16
0
 public override void DidWait(UnitProxy unit)
 {
     foreach (TileProxy tl in BoardProxy.instance.GetAllVisitableNodes(unit, value + 1, true))
     {
         bool isUnit = tl == BoardProxy.instance.GetTileAtPosition(unit.GetPosition());
         if (!isUnit)
         {
             tl.FloatUp(Skill.Actions.DidWait, "+rage", Color.yellow, "+1 atk allies from waiting");
             //tl.CreateAnimation(Glossary.fx.fireShield, AnimationInteractionController.NO_WAIT);
             if (tl.HasUnit() && tl.GetUnit().GetData().GetTeam() == unit.GetData().GetTeam())
             {
                 tl.GetUnit().ReceiveAtkBuff(1);
             }
         }
     }
 }
Exemple #17
0
    IEnumerator PopulateSkeleton(Vector3Int pos, UnitProxy unit, int team, int val)
    {
        yield return(new WaitForSeconds(2.2f));

        TileProxy tl = tiles[pos.x, pos.y];
        //if (!tl.HasUnit()) {
        UnitProxy newUnit = Instantiate(unit, transform);

        //newUnit.Init();
        newUnit.PutData(Unit.BuildInitial(Unit.FactionType.Cthulhu, Unit.UnitType.Soldier, team, new CthulhuBaseWisp(), val));
        newUnit.Init();
        newUnit.GetData().SetSummoned(true);
        tl.ReceiveGridObjectProxy(newUnit);
        newUnit.SnapToCurrentPosition();
        //}
    }
Exemple #18
0
    public override void DidWait(UnitProxy unit)
    {
        TileProxy uTile = BoardProxy.instance.GetTileAtPosition(unit.GetPosition());

        foreach (TileProxy tl in BoardProxy.instance.GetAllVisitableNodes(unit, value + 1, true))
        {
            bool isAttacker = tl == uTile;
            if (!isAttacker)
            {
                tl.FloatUp(Skill.Actions.DidAttack, "enfeeble", Color.grey, "Player enfeebled from atk");
                if (tl.HasUnit() && tl.GetUnit().GetData().GetTeam() != unit.GetData().GetTeam())
                {
                    tl.GetUnit().SetEnfeebled(value);
                }
            }
        }
    }
Exemple #19
0
 public override void DidWait(UnitProxy unit)
 {
     foreach (TileProxy tl in BoardProxy.instance.GetAllVisitableNodes(unit, value + 1, true))
     {
         bool isUnit = tl == BoardProxy.instance.GetTileAtPosition(unit.GetPosition());
         if (!isUnit)
         {
             tl.FloatUp(Skill.Actions.DidAttack, "+move", Color.blue, "Quicken Allies");
             if (tl.HasUnit() && tl.GetUnit().GetData().GetTeam() == unit.GetData().GetTeam())
             {
                 //TurnActions ta = tl.GetUnit().GetData().GetTurnActions();
                 //ta.SetMoves(ta.GetMoves() + 1);
                 tl.GetUnit().SetQuickened(true);
             }
         }
     }
 }
Exemple #20
0
 public override void DidAttack(UnitProxy attacker, UnitProxy defender)
 {
     foreach (TileProxy tl in BoardProxy.instance.GetAllVisitableNodes(attacker, value + 1, true))
     {
         bool isAttacker = tl == BoardProxy.instance.GetTileAtPosition(attacker.GetPosition());
         if (!isAttacker)
         {
             //tl.FloatUp(Skill.Actions.DidAttack, "heal", Color.green, "Allies healed from another unit's attack");
             tl.CreateAnimation(Glossary.fx.healSmoke, AnimationInteractionController.ATK_WAIT);
             if (tl.HasUnit() && tl.GetUnit().GetData().GetTeam() == attacker.GetData().GetTeam())
             {
                 Debug.Log("Attempting to heal unit");
                 tl.GetUnit().HealUnit(1, Skill.Actions.DidAttack);
             }
         }
     }
 }
 public static void SwitchChar(UnitProxy unit)
 {
     ClearPanels();
     if (unit != null)
     {
         //Debug.Log("SwitchChar: " + unit.GetData().characterMoniker);
         if (unit.GetData().GetTeam() == BoardProxy.PLAYER_TEAM)
         {
             //Debug.Log("Player Panel");
             LoadPlayerPanel(unit);
         }
         else
         {
             //Debug.Log("Enemy Panel");
             LoadEnemyPanel(unit);
         }
     }
 }
    public override void DidWait(UnitProxy unit)
    {
        TileProxy uTile = BoardProxy.instance.GetTileAtPosition(unit.GetPosition());

        foreach (TileProxy tl in BoardProxy.instance.GetAllVisitableNodes(unit, value + 1, true))
        {
            bool isAttacker = tl == uTile;
            if (!isAttacker)
            {
                tl.FloatUp(Skill.Actions.DidAttack, "nullified", Color.grey, "Unit's skills are nullified");
                if (tl.HasUnit() && tl.GetUnit().GetData().GetTeam() != unit.GetData().GetTeam())
                {
                    //tl.GetUnit().GetData().SetNullified(true);
                    tl.GetUnit().SetNullified(true);
                }
            }
        }
    }
 static void RefreshSubPanel(GameObject panel, UnitProxy unit)
 {
     panel.SetActive(true);
     foreach (Transform child in panel.transform)
     {
         if (child.name.Equals("type"))
         {
             child.GetComponent <TextMeshProUGUI>().text = unit.GetData().GetUnitType().ToString();
         }
         if (child.name.Equals("mv"))
         {
             string txt = unit.GetData().GetTurnActions().GetMoves().ToString();
             if (TurnController.instance.GetTeam() != unit.GetData().GetTeam())
             {
                 txt = "<color=red>" + unit.GetData().GetTurnMoves() + "</color>";
             }
             child.GetChild(0).GetComponent <TextMeshProUGUI>().text = txt;
         }
         if (child.name.Equals("atk"))
         {
             string txt = unit.GetData().GetTurnActions().GetAttacks().ToString();
             if (TurnController.instance.GetTeam() != unit.GetData().GetTeam())
             {
                 txt = "<color=red>" + unit.GetData().GetTurnAttacks() + "</color>";
             }
             child.GetChild(0).GetComponent <TextMeshProUGUI>().text = txt;
         }
         if (child.name.Equals("HealthOutline"))
         {
             child.GetChild(0).GetComponent <Image>().fillAmount = (float)unit.GetData().GetCurrHealth() / (float)unit.GetData().GetMaxHP();
         }
         if (child.name.Equals("img"))
         {
             child.GetComponent <Image>().sprite = unit.transform.GetChild(0).GetComponent <SpriteRenderer>().sprite;
         }
     }
 }
Exemple #24
0
    /*
     *  We are trying to turn the computer into the biggest dick possible here.
     *  If the computer can kill a unit, they will kill the unit with the highest lvl
     *  If they cannot, they will attack the unit with the lowest level;
     */
    public UnitProxy GetWeakestUnit(UnitProxy unit, List <UnitProxy> enemies)
    {
        TileProxy start  = BoardProxy.instance.GetTileAtPosition(unit.GetPosition());
        int       maxLvl = int.MaxValue;

        List <UnitProxy> killableUnits = new List <UnitProxy>();
        UnitProxy        weakestUnit   = null;
        int atk = unit.GetData().GetAttack();

        foreach (UnitProxy enemy in enemies)
        {
            int currHP = enemy.GetData().GetCurrHealth();
            if (atk >= currHP)
            {
                killableUnits.Add(enemy);
            }
            if (enemy.GetData().GetLvl() < maxLvl)
            {
                maxLvl      = enemy.GetData().GetLvl();
                weakestUnit = enemy;
            }
        }
        if (killableUnits.Count() > 0)
        {
            maxLvl = int.MinValue;
            foreach (UnitProxy enemy in killableUnits)
            {
                if (enemy.GetData().GetLvl() > maxLvl)
                {
                    maxLvl      = enemy.GetData().GetLvl();
                    weakestUnit = enemy;
                }
            }
        }
        return(weakestUnit);
    }
    void SwitchCharName(UnitProxy unit)
    {
        string txt = unit == null ? "" : unit.GetData().characterMoniker;

        NamePanel.GetComponent <TextMeshProUGUI>().text = txt;
    }
    void SetTypeText(UnitProxy unit)
    {
        string txt = unit == null ? "" : unit.GetData().uType.ToString();

        TypeTxt.text = txt;
    }
    void SetTurnText(UnitProxy unit)
    {
        string txt = unit == null ? "" : unit.GetData().GetTurnActions().ToString();

        TurnTxt.text = txt;
    }
    //public void ResetAtThis()
    //{
    //    StartCoroutine(ResetTiles());
    //}

    public override void OnUnitSelected(UnitProxy obj)
    {
        if (!UnitMoving)
        {
            if (currentUnit == null)
            {
                toAttack = null;
                UnHighlightTiles();
                currentUnit = obj;
                //The maximum range in which a player has actions
                allTiles = BoardProxy.instance.GetAllVisitableNodes(obj, obj.GetMoveSpeed() > obj.GetAttackRange() ? obj.GetMoveSpeed() : obj.GetAttackRange(), true);
                //The attackable tiles
                attackableTiles = BoardProxy.instance.GetAllVisitableNodes(obj, obj.GetAttackRange(), true);
                //The visitable tiles
                visitableTiles = BoardProxy.instance.GetAllVisitableNodes(obj, obj.GetMoveSpeed());
                HighlightTiles(obj);
                PanelControllerNew.SwitchChar(obj);
                if (currentUnit.GetData().GetTeam() == TurnController.instance.currentTeam)
                {
                    currentUnit.SaySomething(Skill.Actions.None);
                }
                CheckFocusAI();
            }
            else
            {
                if (toAttack != obj && currentUnit != obj)
                {
                    if (TurnController.instance.currentTeam == BoardProxy.PLAYER_TEAM && currentUnit.GetData().GetTeam() == BoardProxy.ENEMY_TEAM)
                    {
                        currentUnit = null;
                        OnUnitSelected(obj);
                    }
                    else
                    {
                        toAttack = obj;
                        UnitProxy player = currentUnit.GetData().GetTeam() == BoardProxy.PLAYER_TEAM ? currentUnit : toAttack;
                        UnitProxy enemy  = currentUnit.GetData().GetTeam() == BoardProxy.ENEMY_TEAM ? currentUnit : toAttack;
                        PanelControllerNew.SwitchChar(player, enemy);
                    }
                }
                else
                {
                    if (obj.GetData().GetTeam() != currentUnit.GetData().GetTeam() &&
                        attackableTiles.Contains(BoardProxy.instance.GetTileAtPosition(obj.GetPosition())) &&
                        currentUnit.GetData().GetTurnActions().CanAttack() &&
                        !obj.GetData().IsDead())
                    {
                        CheckFocusAI();

                        toAttack = null;

                        bool charDead = obj.IsAttacked(currentUnit);
                        if (currentUnit != null)
                        {
                            currentUnit.AcceptAction(Skill.Actions.DidAttack, obj);
                        }

                        if (charDead)
                        {
                            UnitProxy victor = BoardProxy.instance.GetTileAtPosition(currentUnit.GetPosition()).GetUnit();
                            victor.SaySomething(Skill.Actions.DidKill);
                            obj.DelayedKill(obj, victor);
                            StartCoroutine(ResetTiles());
                        }
                        else
                        {
                            currentUnit.SaySomething(Skill.Actions.DidAttack);
                            obj.SaySomething(Skill.Actions.DidDefend);
                        }
                        OnDisable();
                        PanelControllerNew.SwitchChar(currentUnit);
                    }
                }
            }
        }
    }
Exemple #29
0
    //Vector2 ReturnIntersection(Vector3 left, Vector3 right, Vector3 up, Vector3 down){
    //    float A1 = right.y - left.y;
    //    float B1 = left.x - right.x;
    //    float C1 = A1 + B1;

    //    float A2 = right.y - left.y;
    //    float B2 = left.x - right.x;
    //    float C2 = A2 + B2;

    //    float delta = A1 * B2 - A2 * B1;

    //    if ((int) delta == 0)
    //        return Vector2.zero;

    //    float x = (B2 * C1 - B1 * C2) / delta;
    //    float y = (A1 * C2 - A2 * C1) / delta;

    //    return new Vector2(x,y);
    //}

    //public void FocusOnUnit(UnitProxy unt){
    //    cam.orthographicSize = 3;
    //    //BoardProxy.instance.transform.position = new Vector3(-1.5f,-1.5f,0);
    //    BoardProxy.instance.transform.position = new Vector3(0,-1.5f,0);

    //    Vector2Int dims = BoardProxy.instance.GetDimensions();
    //    Vector3 bLeft = BoardProxy.instance.GetTileAtPosition(new Vector3Int(0,dims[1]-1,0)).transform.position;
    //    Vector3 bRight = BoardProxy.instance.GetTileAtPosition(new Vector3Int(dims[0]-1,0,0)).transform.position;
    //    Vector3 bUp = BoardProxy.instance.GetTileAtPosition(new Vector3Int(dims[0]-1,dims[1]-1,0)).transform.position;
    //    Vector3 bDown = BoardProxy.instance.GetTileAtPosition(new Vector3Int(0,0,0)).transform.position;
    //    Vector3 bCenter = ReturnIntersection(bLeft, bRight, bUp, bDown);

    //    Vector3 pos = unt.transform.position;
    //    Vector3 diff = pos - bCenter;

    //    Debug.Log("bCenter pos: " + bCenter.ToString());
    //    Debug.Log("pos pos: " + pos.ToString());
    //    Debug.Log("diff pos: " + diff.ToString());

    //    bCenter.x -= diff.x;
    //    bCenter.y -= diff.y;

    //    BoardProxy.instance.transform.position = bCenter;
    //}

    public IEnumerator BeginProcess()
    {
        yield return(new WaitForSeconds(.5f));

        //List<UnitProxy> aiUnits = new List<UnitProxy>(BoardProxy.instance.GetUnits().Where(unit => unit.GetData().GetTeam() == BoardProxy.ENEMY_TEAM));
        List <UnitProxy> opposingUnits = new List <UnitProxy>(BoardProxy.instance.GetUnits().Where(unit => unit.GetData().GetTeam() == BoardProxy.PLAYER_TEAM));

        //Debug.Log("Beginning AI Turn");
        ////Debug.Log("aiUnits: " + aiUnits.Count.ToString());
        //Debug.Log("playerUnits: " + opposingUnits.Count.ToString());

        Queue <UnitProxy> unitQueue = new Queue <UnitProxy>(BoardProxy.instance.GetUnits().Where(unit => unit.GetData().GetTeam() == BoardProxy.ENEMY_TEAM));

        while (unitQueue.Count() > 0)
        {
            UnitProxy unit         = unitQueue.Dequeue();
            bool      didSomething = true;
            while (didSomething && unit.IsAlive())
            {
                if (!AnimationInteractionController.AllAnimationsFinished())
                {
                    yield return(new WaitForSeconds(AnimationInteractionController.ATK_WAIT));
                }
                //Debug.Log("AI Char: " + unit.GetData().characterMoniker + " : " + unit.GetData().GetTurnActions().GetMoves() +
                //"/" + unit.GetData().GetTurnActions().GetAttacks());
                didSomething = false;
                //Look at all the visitable tiles
                //List<TileProxy> visitableTiles = BoardProxy.instance.GetAllVisitableNodes(unit, unit.GetMoveSpeed(), true);
                //Look at all the attackable tiles
                List <TileProxy> attackableTiles = BoardProxy.instance.GetAllVisitableNodes(unit, unit.GetAttackRange(), true);
                //Look at all the tiles the opposing team is on from the visitable tiles
                List <TileProxy> opposingTeamTiles = new List <TileProxy>(attackableTiles.Where(tile => tile.HasUnit() && !tile.GetUnit().GetData().IsDead() &&
                                                                                                opposingUnits.Contains(tile.GetUnit())));
                //Look at all the tiles in range
                List <TileProxy> validTiles = BoardProxy.instance.GetAllVisitableNodes(unit, unit.GetMoveSpeed());
                if (opposingTeamTiles.Count > 0 && unit.GetData().GetTurnActions().CanAttack())
                {
                    //unit.FocusOnUnit();
                    //Unit in range. Attack!
                    //Debug.Log("Trying to Attack");
                    TileProxy oppTile = BoardProxy.instance.GetTileAtPosition(opposingTeamTiles[0].GetPosition());
                    unit.OnSelected();
                    yield return(new WaitForSeconds(.1f));

                    oppTile.ForceHighlight();
                    yield return(new WaitForSeconds(.3f));

                    oppTile.UnHighlight();
                    opposingTeamTiles[0].GetUnit().OnSelected();
                    yield return(new WaitForSeconds(.5f));

                    opposingTeamTiles[0].GetUnit().OnSelected();
                    didSomething = true;
                    bool zap = unit.GetData().GetSkills().Where(skll => skll.Contains("Force") || skll.Contains("Void") || skll.Contains("Warp")).Any();
                    if (zap)
                    {
                        yield return(new WaitForSeconds(AnimationInteractionController.AFTER_KILL));
                    }
                    else
                    {
                        yield return(new WaitForSeconds(AnimationInteractionController.ATK_WAIT));
                    }
                }
                else if (opposingTeamTiles.Count == 0 && unit.GetData().GetTurnActions().CanMove())
                {
                    //FocusOnUnit(unit);
                    //Debug.Log("Trying to Move");
                    TileProxy start = BoardProxy.instance.GetTileAtPosition(unit.GetPosition());
                    //Calculate a path from the unit to the first opposing unit (should be optimized)
                    Path <TileProxy> path = BoardProxy.instance.GetPathAIConsideration(start, BoardProxy.instance.GetTileAtPosition(opposingUnits[0].GetPosition()), unit);
                    if (path.Count() > 0 && path.Where(tile => validTiles.Contains(tile) && !tile.HasUnit()).Any())
                    {
                        //See how many of those tiles are in the tiles we are allowed to move
                        TileProxy dest = path.Where(tile => validTiles.Contains(tile) && !tile.HasUnit()).First();
                        //Get the path for highlighting
                        path = BoardProxy.instance.GetPath(start, dest, unit);

                        Debug.Log("Dest: " + dest.GetPosition().ToString() + " Start: " + start.GetPosition().ToString());

                        if (dest != start)
                        {
                            //unit.FocusOnUnit();
                            didSomething = true;
                            foreach (TileProxy tl in path)
                            {
                                tl.ForceHighlight();
                            }
                            yield return(new WaitForSeconds(.25f));

                            foreach (TileProxy tl in path)
                            {
                                tl.UnHighlight();
                            }
                            unit.OnSelected();
                            yield return(new WaitForSeconds(.25f));

                            InteractivityManager.instance.OnTileSelected(dest);
                            yield return(new WaitForSeconds(1f));
                        }
                        else
                        {
                            Debug.Log("Dest not equal to start");
                            if (unitQueue.Count() > 0 && !unit.GetData().GetTurnActions().idle)
                            {
                                //If there are more ai units left to move and this ai hasn't been put in the back of the queue yet
                                //Put unit at the end of the queue, wait for other units to move
                                Debug.Log("Rotating AI");
                                unit.GetData().GetTurnActions().idle = true;
                                unitQueue.Enqueue(unit);
                                break;
                            }
                            else
                            {
                                Debug.Log("Removing Action");
                                //The unit has already failed to move twice. Stop trying. Move On.
                                unit.GetData().GetTurnActions().Move();
                                didSomething = true;
                                yield return(new WaitForSeconds(.25f));
                            }
                        }
                    }
                }
                yield return(new WaitForSeconds(.25f));
            }
        }
        //yield return new WaitForSeconds(AnimationInteractionController.NO_ATK_WAIT);
        //No more actions, end turn
        TurnController.instance.EndTurn();
        yield return(null);
    }
Exemple #30
0
    //Vector2 ReturnIntersection(Vector3 left, Vector3 right, Vector3 up, Vector3 down){
    //    float A1 = right.y - left.y;
    //    float B1 = left.x - right.x;
    //    float C1 = A1 + B1;

    //    float A2 = right.y - left.y;
    //    float B2 = left.x - right.x;
    //    float C2 = A2 + B2;

    //    float delta = A1 * B2 - A2 * B1;

    //    if ((int) delta == 0)
    //        return Vector2.zero;

    //    float x = (B2 * C1 - B1 * C2) / delta;
    //    float y = (A1 * C2 - A2 * C1) / delta;

    //    return new Vector2(x,y);
    //}

    //public void FocusOnUnit(UnitProxy unt){
    //    cam.orthographicSize = 3;
    //    //BoardProxy.instance.transform.position = new Vector3(-1.5f,-1.5f,0);
    //    BoardProxy.instance.transform.position = new Vector3(0,-1.5f,0);

    //    Vector2Int dims = BoardProxy.instance.GetDimensions();
    //    Vector3 bLeft = BoardProxy.instance.GetTileAtPosition(new Vector3Int(0,dims[1]-1,0)).transform.position;
    //    Vector3 bRight = BoardProxy.instance.GetTileAtPosition(new Vector3Int(dims[0]-1,0,0)).transform.position;
    //    Vector3 bUp = BoardProxy.instance.GetTileAtPosition(new Vector3Int(dims[0]-1,dims[1]-1,0)).transform.position;
    //    Vector3 bDown = BoardProxy.instance.GetTileAtPosition(new Vector3Int(0,0,0)).transform.position;
    //    Vector3 bCenter = ReturnIntersection(bLeft, bRight, bUp, bDown);

    //    Vector3 pos = unt.transform.position;
    //    Vector3 diff = pos - bCenter;

    //    Debug.Log("bCenter pos: " + bCenter.ToString());
    //    Debug.Log("pos pos: " + pos.ToString());
    //    Debug.Log("diff pos: " + diff.ToString());

    //    bCenter.x -= diff.x;
    //    bCenter.y -= diff.y;

    //    BoardProxy.instance.transform.position = bCenter;
    //}

    public IEnumerator BeginProcess()
    {
        yield return(new WaitForSeconds(.5f));

        //List<UnitProxy> aiUnits = new List<UnitProxy>(BoardProxy.instance.GetUnits().Where(unit => unit.GetData().GetTeam() == BoardProxy.ENEMY_TEAM));
        //List<UnitProxy> opposingUnits = new List<UnitProxy>(BoardProxy.instance.GetUnits().Where(unit => unit.GetData().GetTeam() == BoardProxy.PLAYER_TEAM));

        //Debug.Log("Beginning AI Turn");
        ////Debug.Log("aiUnits: " + aiUnits.Count.ToString());
        //Debug.Log("playerUnits: " + opposingUnits.Count.ToString());

        Queue <UnitProxy> unitQueue = new Queue <UnitProxy>(BoardProxy.instance.GetUnits().Where(unit => unit.GetData().GetTeam() == BoardProxy.ENEMY_TEAM));

        while (unitQueue.Count() > 0)
        {
            UnitProxy unit         = unitQueue.Dequeue();
            bool      didSomething = true;
            while (didSomething && unit.IsAlive())
            {
                if (!AnimationInteractionController.AllAnimationsFinished())
                {
                    yield return(new WaitForSeconds(AnimationInteractionController.ATK_WAIT));
                }
                List <UnitProxy> opposingUnits = new List <UnitProxy>(BoardProxy.instance.GetUnits().Where(unt => unt.GetData().GetTeam() == BoardProxy.PLAYER_TEAM));
                //Debug.Log("AI Char: " + unit.GetData().characterMoniker + " : " + unit.GetData().GetTurnActions().GetMoves() +
                //"/" + unit.GetData().GetTurnActions().GetAttacks());
                didSomething = false;
                //Look at all the visitable tiles
                //List<TileProxy> visitableTiles = BoardProxy.instance.GetAllVisitableNodes(unit, unit.GetMoveSpeed(), true);
                //Look at all the attackable tiles
                List <TileProxy> attackableTiles = BoardProxy.instance.GetAllVisitableNodes(unit, unit.GetAttackRange(), true);
                //Look at all the tiles the opposing team is on from the visitable tiles
                List <TileProxy> opposingTeamTiles = new List <TileProxy>(attackableTiles.Where(tile => tile.HasUnit() && !tile.GetUnit().GetData().IsDead() &&
                                                                                                opposingUnits.Contains(tile.GetUnit())));
                //Look at all the tiles in range
                List <TileProxy> validTiles = BoardProxy.instance.GetAllVisitableNodes(unit, unit.GetMoveSpeed());
                bool             coward     = unit.GetData().LowHP() && HasHealthyUnits();
                //Logic for when to wait in battle:
                //If you have multiple moves at the start of the turn with only one move left with more than one attack and nobody around.
                bool wait = false;

                wait = unit.GetData().GetSkills().Where(skll => skll.Contains("Wait")).Any();
                wait = wait && unit.GetData().GetTurnActions().GetMoves() == 1 &&
                       unit.GetData().GetTurnActions().GetAttacks() >= 1 && opposingTeamTiles.Count == 0;

                //If you have multiple moves at the start of the turn with only one move left with more than one attack and nobody around.
                bool waitA = wait && unit.GetData().GetTurnMoves() > 1 && unit.GetData().GetTurnActions().GetMoves() == 1 &&
                             unit.GetData().GetTurnActions().GetAttacks() >= 1 && opposingTeamTiles.Count == 0;

                //If you didn't wait last turn, have a wait bonus, and are not somewhat injured, then go for bonus
                bool waitB = wait && unit.GetData().GetTurnActions().GetMoves() == 1 && unit.GetData().GetTurnActions().GetAttacks() == 1 &&
                             !unit.GetData().ModerateHP();

                wait = waitA || waitB;

                if (waitB && unit.WaitedLastTurn())
                {
                    wait = false;
                    unit.SetWaitedLastTurn(false);
                }
                else if (waitB)
                {
                    unit.SetWaitedLastTurn(true);
                }

                if (!coward)
                {
                    //If the ai can still move, but has used their attacks, move them away from the enemy team.
                    //These are usually actions a scout would take, so we are trying to protect them here
                    coward = !unit.GetData().GetTurnActions().CanAttack() && unit.GetData().GetTurnActions().CanMove();
                }
                if (opposingTeamTiles.Count > 0 && unit.GetData().GetTurnActions().CanAttack() && !wait)
                {
                    //unit.FocusOnUnit();
                    //Unit in range. Attack!
                    TileProxy oppTile = BoardProxy.instance.GetTileAtPosition(opposingTeamTiles[0].GetPosition());
                    unit.OnSelected();
                    yield return(new WaitForSeconds(.1f));

                    oppTile.ForceHighlight();
                    yield return(new WaitForSeconds(.3f));

                    oppTile.UnHighlight();
                    opposingTeamTiles[0].GetUnit().OnSelected();
                    yield return(new WaitForSeconds(.5f));

                    opposingTeamTiles[0].GetUnit().OnSelected();
                    didSomething = true;
                    bool zap = unit.GetData().GetSkills().Where(skll => skll.Contains("Force") || skll.Contains("Void") || skll.Contains("Warp")).Any();
                    if (zap)
                    {
                        yield return(new WaitForSeconds(AnimationInteractionController.AFTER_KILL));
                    }
                    else
                    {
                        yield return(new WaitForSeconds(AnimationInteractionController.ATK_WAIT));
                    }
                }
                //If you need to move towards the enemies or run away, logic through here
                else if ((opposingTeamTiles.Count == 0 || coward) && unit.GetData().GetTurnActions().CanMove() && !wait)
                {
                    //FocusOnUnit(unit);
                    Debug.Log("Unit: " + unit.GetData().characterMoniker + " - Coward: " + coward.ToString());
                    TileProxy start = BoardProxy.instance.GetTileAtPosition(unit.GetPosition());
                    //Find the closest opposing unit
                    UnitProxy nearestUnit = GetClosestUnit(unit, opposingUnits);
                    //Calculate a path from the unit to the closest opposing unit
                    Path <TileProxy> path = BoardProxy.instance.GetPathAIConsideration(start, BoardProxy.instance.GetTileAtPosition(nearestUnit.GetPosition()), unit);
                    if (coward)
                    {
                        Debug.Log("Unit: " + unit.GetData().characterMoniker + " is trying to escape!");
                        TileProxy escapeTile = GetRetreatDest(unit, opposingUnits);
                        if (escapeTile != null)
                        {
                            Debug.Log("Escape tile: " + escapeTile.GetPosition().ToString());
                            //Calculate a path from the unit to the closest opposing unit
                            path = BoardProxy.instance.GetPath(start, escapeTile, unit);
                        }
                    }
                    if (path.Count() > 0 && path.Where(tile => validTiles.Contains(tile) && !tile.HasUnit()).Any())
                    {
                        //See how many of those tiles are in the tiles we are allowed to move
                        TileProxy dest = path.Where(tile => validTiles.Contains(tile) && !tile.HasUnit()).First();
                        //if (unit.GetData().ModerateHP() && path.Where(tile => validTiles.Contains(tile) && !tile.HasUnit() && !tile.OnFire()).Any()) {
                        //    //Avoid bad tiles if we don't have too much hp
                        //    dest = path.Where(tile => validTiles.Contains(tile) && !tile.HasUnit() && !tile.OnFire()).First();
                        //}

                        //If the unit is not trying to run away from battle
                        if (!coward)
                        {
                            /*
                             * If the ai is allowed to move to a tile and it has ranged,
                             * you want to land it a bit further away from it's target.
                             * If the dest and the original target are the same we need to
                             * subtract moves from the path over 2 moves
                             */
                            int atkDiff = unit.GetData().GetAtkRange() - 1;
                            //The distance between the ai's destination and the enemy the ai is planning to attack in the future
                            TileProxy[] rngPth = BoardProxy.instance.GetPath(dest, BoardProxy.instance.GetTileAtPosition(nearestUnit.GetPosition()), unit).ToArray();
                            if (atkDiff > 0 && rngPth.Count() <= atkDiff)
                            {
                                List <TileProxy> listPth = path.ToList();
                                int dstIdx = listPth.IndexOf(dest);
                                if (dstIdx + atkDiff - 1 <= listPth.Count() - 1)
                                {
                                    dest = listPth[dstIdx + atkDiff - 1];
                                }
                            }
                        }
                        //Get the path for highlighting
                        path = BoardProxy.instance.GetPath(start, dest, unit);
                        if (dest != start)
                        {
                            //unit.FocusOnUnit();
                            didSomething = true;
                            foreach (TileProxy tl in path)
                            {
                                tl.ForceHighlight();
                            }
                            yield return(new WaitForSeconds(.25f));

                            foreach (TileProxy tl in path)
                            {
                                tl.UnHighlight();
                            }
                            unit.OnSelected();
                            yield return(new WaitForSeconds(.25f));

                            InteractivityManager.instance.OnTileSelected(dest);
                            yield return(new WaitForSeconds(1f));

                            if (path.Where(tl => tl.OnFire()).Any())
                            {
                                yield return(new WaitForSeconds(1f));
                            }
                        }
                        else
                        {
                            if (unitQueue.Count() > 0 && !unit.GetData().GetTurnActions().idle)
                            {
                                //If there are more ai units left to move and this ai hasn't been put in the back of the queue yet
                                //Put unit at the end of the queue, wait for other units to move
                                unit.GetData().GetTurnActions().idle = true;
                                unitQueue.Enqueue(unit);
                                break;
                            }
                            else
                            {
                                //The unit has already failed to move twice. Stop trying. Move On.
                                unit.GetData().GetTurnActions().Move();
                                didSomething = true;
                                yield return(new WaitForSeconds(.25f));
                            }
                        }
                    }
                }
                yield return(new WaitForSeconds(.25f));
            }
        }
        //yield return new WaitForSeconds(AnimationInteractionController.NO_ATK_WAIT);
        //No more actions, end turn
        TurnController.instance.EndTurn();
        yield return(null);
    }