Esempio n. 1
0
    void OnMouseEnter()
    {
        //show preview stats window and Hide the delay bar stuff

        if (pm.get_battle().allowPreview&& pm.search_unit(x, y) != null)  //y, x? needs testing
        {
            pm.get_battle().showStatPreviewWindow(pm.search_unit(x, y));
        }

        if (pm.allowHover || repositionPlace)
        {
            //call coloring function. makes and other affected tiles red.
            //sprite.color = new Color(250f / 255f, 100f / 255f, 100f / 255f);
            //Debug.Log("colouring");
            if (repositionPlace)
            {
                //Debug.Log("repositionplace is true");
                pm.highlight_helper(x, y, useGreen: false, isRepo: true);
            }
            else
            {
                pm.highlight_helper(x, y);
            }
        }
        //also: everytime, even if allowHover is false, hovering a tile will show its unit's status profile.
    }
Esempio n. 2
0
    //checks for targets. for enemy's checkUp ticks.
    public bool f_check_targets(PlayerMap pMap, Enemy unit)
    {
        //returns false if there are no targets left in the area.
        EnemyMove move = unit.nextMove;

        //index:
        //0: rectangular
        //1: 1x1 self
        //2: 3x3 centerless cross
        //3: 3x3 cross
        switch (move.get_highlightType())
        {
        case 0:     //standard rectangular
            for (int c = unit.nextX; c < (unit.nextX + move.get_ysize()); c++)
            {
                for (int r = unit.nextY; r < (unit.nextY + move.get_xsize()); r++)
                {
                    if (pMap.search_unit(c, r) != null)
                    {
                        return(true);
                    }
                }
            }
            break;

        case 2:     //3x3 centerless cross.
            if (pMap.search_unit(unit.nextX - 1, unit.nextY) != null)
            {
                return(true);
            }


            if (pMap.search_unit(unit.nextX + 1, unit.nextY) != null)
            {
                return(true);
            }

            if (pMap.search_unit(unit.nextX, unit.nextY - 1) != null)
            {
                return(true);
            }

            if (pMap.search_unit(unit.nextX, unit.nextY + 1) != null)
            {
                return(true);
            }
            break;
        }
        return(false);
    }
Esempio n. 3
0
    //PLAYER heals PLAYER
    public void f_resolve_heal(PlayerUnit unit, PlayerMap pMap)
    {
        //method:
        //first assemble targets (keeping in mind cases)
        //then deal damage
        reset_targetLists();
        PlayerMove move = unit.nextMove;

        //gather targets
        switch (move.get_highlightType())
        {
        case 0:     //standard rectangular
            for (int c = unit.nextX; c < (unit.nextX + move.get_ysize()); c++)
            {
                for (int r = unit.nextY; r < (unit.nextY + move.get_xsize()); r++)
                {
                    if (pMap.search_unit(c, r) != null)
                    {
                        if (!f_targets.Contains(pMap.search_unit(c, r)))
                        {
                            f_targets.Add(pMap.search_unit(c, r));
                        }
                    }
                    else
                    {
                        pMap.tilegrid[r, c].GetComponent <PlayerTile>().show_damage_text("miss");
                    }
                }
            }
            break;

        case 1:
            //self
            f_targets.Add(unit);
            break;

        case 2:     //3x3 centerless cross.
            if (pMap.search_unit(unit.nextX - 1, unit.nextY) != null)
            {
                if (!f_targets.Contains(pMap.search_unit(unit.nextX - 1, unit.nextY)))
                {
                    f_targets.Add(pMap.search_unit(unit.nextX - 1, unit.nextY));
                }
            }
            else
            {
                pMap.tilegrid[unit.nextY, unit.nextX - 1].GetComponent <PlayerTile>().show_damage_text("miss");
            }

            if (pMap.search_unit(unit.nextX + 1, unit.nextY) != null)
            {
                if (!f_targets.Contains(pMap.search_unit(unit.nextX + 1, unit.nextY)))
                {
                    f_targets.Add(pMap.search_unit(unit.nextX + 1, unit.nextY));
                }
            }
            else
            {
                pMap.tilegrid[unit.nextY, unit.nextX + 1].GetComponent <PlayerTile>().show_damage_text("miss");
            }

            if (pMap.search_unit(unit.nextX, unit.nextY - 1) != null)
            {
                if (!f_targets.Contains(pMap.search_unit(unit.nextX, unit.nextY - 1)))
                {
                    f_targets.Add(pMap.search_unit(unit.nextX, unit.nextY - 1));
                }
            }
            else
            {
                pMap.tilegrid[unit.nextY - 1, unit.nextX].GetComponent <PlayerTile>().show_damage_text("miss");
            }

            if (pMap.search_unit(unit.nextX, unit.nextY + 1) != null)
            {
                if (!f_targets.Contains(pMap.search_unit(unit.nextX, unit.nextY + 1)))
                {
                    f_targets.Add(pMap.search_unit(unit.nextX, unit.nextY + 1));
                }
            }
            else
            {
                pMap.tilegrid[unit.nextY + 1, unit.nextX].GetComponent <PlayerTile>().show_damage_text("miss");
            }
            break;
        }
        //now, heal the targets
        foreach (PlayerUnit target in f_targets)
        {
            //calc heal:
            bool ignoreMax = false;
            int  heal      = 0;
            if (move.get_hasCustomHeal())
            {
                //Debug.Log("custom heal going");
                StartCoroutine(show_battleNumbers(target.stats.get_floatingHp().gameObject, 2.25f));
                heal      = move.calc_custom_heal(unit);
                ignoreMax = move.get_ignoreHealMax();
            }
            else
            {
                StartCoroutine(show_battleNumbers(target.stats.get_floatingHp().gameObject, 1));
                heal = f_calc_heal(unit, target);
            }

            //display heal number
            if (heal != -1)
            {
                f_do_heal(target, heal, ignoreMax);
                pMap.tilegrid[target.get_x(), target.get_y()].GetComponent <PlayerTile>().show_heal_text(heal.ToString());
            }
        }
    }
Esempio n. 4
0
    //=====================================================================

    //ENEMY attacks PLAYER
    public void e_resolve_attack(Enemy unit, PlayerMap pMap)
    {
        reset_targetLists();
        EnemyMove move = unit.nextMove;

        //gather targets
        switch (move.get_highlightType())
        {
        case 0:     //standard rectangular
            for (int c = unit.nextX; c < (unit.nextX + move.get_ysize()); c++)
            {
                for (int r = unit.nextY; r < (unit.nextY + move.get_xsize()); r++)
                {
                    if (pMap.search_unit(c, r) != null)
                    {
                        if (!f_targets.Contains(pMap.search_unit(c, r)))
                        {
                            f_targets.Add(pMap.search_unit(c, r));
                        }
                    }
                    else
                    {
                        pMap.tilegrid[r, c].GetComponent <PlayerTile>().show_damage_text("miss");
                    }
                }
            }
            break;

        case 2:     //3x3 centerless cross.
            if (pMap.search_unit(unit.nextX - 1, unit.nextY) != null)
            {
                if (!f_targets.Contains(pMap.search_unit(unit.nextX - 1, unit.nextY)))
                {
                    f_targets.Add(pMap.search_unit(unit.nextX - 1, unit.nextY));
                }
            }
            else
            {
                pMap.tilegrid[unit.nextY, unit.nextX - 1].GetComponent <PlayerTile>().show_damage_text("miss");
            }

            if (pMap.search_unit(unit.nextX + 1, unit.nextY) != null)
            {
                if (!f_targets.Contains(pMap.search_unit(unit.nextX + 1, unit.nextY)))
                {
                    f_targets.Add(pMap.search_unit(unit.nextX + 1, unit.nextY));
                }
            }
            else
            {
                pMap.tilegrid[unit.nextY, unit.nextX + 1].GetComponent <PlayerTile>().show_damage_text("miss");
            }

            if (pMap.search_unit(unit.nextX, unit.nextY - 1) != null)
            {
                if (!f_targets.Contains(pMap.search_unit(unit.nextX, unit.nextY - 1)))
                {
                    f_targets.Add(pMap.search_unit(unit.nextX, unit.nextY - 1));
                }
            }
            else
            {
                pMap.tilegrid[unit.nextY - 1, unit.nextX].GetComponent <PlayerTile>().show_damage_text("miss");
            }

            if (pMap.search_unit(unit.nextX, unit.nextY + 1) != null)
            {
                if (!f_targets.Contains(pMap.search_unit(unit.nextX, unit.nextY + 1)))
                {
                    f_targets.Add(pMap.search_unit(unit.nextX, unit.nextY + 1));
                }
            }
            else
            {
                pMap.tilegrid[unit.nextY + 1, unit.nextX].GetComponent <PlayerTile>().show_damage_text("miss");
            }
            break;
        }

        //now, damage the targets
        //foreach (PlayerUnit target in f_targets)
        if (f_targets.Count > 0)
        {
            all_ooa = true;
        }
        int runs = f_targets.Count;

        for (int i = 0; i < runs; i++)
        {
            int damage = e_calc_damage(unit, f_targets[0]);

            if (move.get_appliesStatus())
            {
                StartCoroutine(show_battleNumbers(f_targets[0].stats.get_floatingHp().gameObject, 2.25f));
            }
            else
            {
                StartCoroutine(show_battleNumbers(f_targets[0].stats.get_floatingHp().gameObject, 1));
            }



            if (damage == -1)
            {
                pMap.tilegrid[f_targets[0].get_x(), f_targets[0].get_y()].GetComponent <PlayerTile>().show_damage_text("dodge");
                f_targets.RemoveAt(i);
            }
            else if (damage > 0)
            {
                e_do_damage(f_targets[0], damage);
                pMap.tilegrid[f_targets[0].get_x(), f_targets[0].get_y()].GetComponent <PlayerTile>().show_damage_text(damage.ToString());


                //check if enemy was killed
                if (f_targets[0].ooa != true)
                {
                    all_ooa = false;
                }
                else
                {
                    //change sprite to ooa version or something
                    f_targets.RemoveAt(0);
                }
            }
        }
    }
Esempio n. 5
0
    //on return false, the move is not selectable
    public bool check_post(int unit_x, int unit_y, PlayerMap pMap, int mp)
    {
        //called in exert() to make sure the move can still be used.
        //MP CHECK
        if (mp < mpDrain)
        {
            return(false);
        }

        //check if translation would move unit off of grid or if unit would bump someone during their traversal
        if (clearType == 0)
        {
            return(true);
        }

        if ((unit_x + clearX >= 0) && (unit_x + clearX < 5) && (unit_y + clearY >= 0) && (unit_y + clearY < 4)) //<-- this line.
        {
            //hop: needs only end tile clear
            if (clearType == 1 && pMap.search_unit(unit_y + clearY, unit_x + clearX) == null)  //works as intended. tested, good to go.
            {
                return(true);
            }
            else //full path: needs every time in path to be clear
            {
                //NOTE:
                //units ALWAYS move vertical part first, followed by horizontal part.

                if (clearType == 2)
                {
                    //VERTICAL PORTION
                    if (clearY > 0)                                         //if we're moving forwards
                    {
                        for (int i = unit_y + 1; i <= unit_y + clearY; i++) //vertical part
                        {
                            if (pMap.search_unit(i, unit_x) != null)
                            {
                                return(false);
                            }
                        }
                    }
                    else if (clearY < 0)                                    //if we're moving backwards
                    {
                        for (int i = unit_y - 1; i >= unit_y + clearY; i--) //vertical part
                        {
                            if (pMap.search_unit(i, unit_x) != null)
                            {
                                return(false);
                            }
                        }
                    }


                    //HORIZONTAL PORTION
                    if (clearX > 0) //we're moving to the right
                    {
                        for (int i = unit_x + 1; i <= unit_x + clearX; i++)
                        {
                            if (pMap.search_unit(unit_y + clearY, i) != null)
                            {
                                return(false);
                            }
                        }
                    }
                    else if (clearX < 0) //we're moving to the left
                    {
                        for (int i = unit_x - 1; i >= unit_x + clearX; i--)
                        {
                            if (pMap.search_unit(unit_y + clearY, i) != null)
                            {
                                return(false);
                            }
                        }
                    }


                    return(true);
                }
            }
        }
        return(false);
    }
Esempio n. 6
0
    void pick_hostile_target(int targeting, PlayerMap pMap, PlayerUnit[] pl, int aoe_x, int aoe_y)
    {
        //check chosen move's targeting prioritization. picks a unit's tile and returns the x, y of their tile.
        //LEGEND:
        // 0: hit random target
        // 1: hit enemy closest to the front
        // 2: hit enemy closest to the back
        // 3: hit enemy with lowest hp
        // 4: hit enemy with highest hp
        // 5: hit enemy with lowest pdef
        // 6: hit enemy with lowest mdef
        // 7: hit enemy weak to move's element
        // 8: aoe, most targets
        int chosen;
        int chosenIndex;
        List <PlayerUnit> f_targets = new List <PlayerUnit>();

        switch (targeting)
        {
        case 0:
            // 0: hits a random target.
            bool find = true;
            while (find)
            {
                chosen = UnityEngine.Random.Range(0, pl.Length);
                if (pl[chosen].ooa == false)
                {
                    nextX = pl[chosen].get_y();
                    nextY = pl[chosen].get_x();

                    find = false;
                }
            }
            break;

        case 1:
            // 1: hits enemy nearest to the front. if multiple units equally close to the front, randomly pick between them.
            for (int c = 3; c >= 0; c--)
            {
                for (int r = 4; r >= 0; r--)
                {
                    if (pMap.search_unit(c, r) != null)
                    {
                        if (!f_targets.Contains(pMap.search_unit(c, r)) && pMap.search_unit(c, r).ooa == false)
                        {
                            f_targets.Add(pMap.search_unit(c, r));
                        }
                    }
                }

                //after we've finished a row, check if there's any units in f_targets
                if (f_targets.Count > 0)
                {
                    chosen = UnityEngine.Random.Range(0, f_targets.Count);

                    nextX = f_targets[chosen].get_y();
                    nextY = f_targets[chosen].get_x();
                    break;
                }
            }
            break;

        case 2:
            // 2: hits enemy nearest to the back. if multiple units equally close to the back, randomly pick between them.
            for (int c = 0; c < 4; c++)
            {
                for (int r = 0; r < 5; r++)
                {
                    if (pMap.search_unit(c, r) != null)
                    {
                        if (!f_targets.Contains(pMap.search_unit(c, r)) && pMap.search_unit(c, r).ooa == false)
                        {
                            f_targets.Add(pMap.search_unit(c, r));
                        }
                    }
                }
                //after we've finished a row, check if there's any units in f_targets
                if (f_targets.Count > 0)
                {
                    chosen = UnityEngine.Random.Range(0, f_targets.Count);

                    nextX = f_targets[chosen].get_y();
                    nextY = f_targets[chosen].get_x();
                    break;
                }
            }
            break;

        case 3:
            // 3: hit enemy with lowest hp
            chosen = pl[0].get_hp();

            for (int i = 1; i < pl.Length; i++)
            {
                if (pl[i].ooa == false && pl[i].get_hp() <= chosen)
                {
                    if (chosen == pl[i].get_hp())
                    {
                        f_targets.Add(pl[i]);
                    }
                    else
                    {
                        f_targets.Clear();
                        f_targets.Add(pl[i]);
                    }
                    chosen = pl[i].get_hp();
                }
            }
            chosen = UnityEngine.Random.Range(0, f_targets.Count);
            nextX  = f_targets[chosen].get_y();
            nextY  = f_targets[chosen].get_x();
            break;

        case 4:
            // 4: hit enemy with highest hp
            chosen = pl[0].get_hp();

            for (int i = 1; i < pl.Length; i++)
            {
                if (pl[i].ooa == false && pl[i].get_hp() >= chosen)
                {
                    if (chosen == pl[i].get_hp())
                    {
                        f_targets.Add(pl[i]);
                    }
                    else
                    {
                        f_targets.Clear();
                        f_targets.Add(pl[i]);
                    }
                    chosen = pl[i].get_hp();
                }
            }
            chosen = UnityEngine.Random.Range(0, f_targets.Count);
            nextX  = f_targets[chosen].get_y();
            nextY  = f_targets[chosen].get_x();
            break;

        case 5:
            // 5: hit enemy with lowest pdef
            chosen = pl[0].get_physd_actual();
            f_targets.Add(pl[0]);

            for (int i = 1; i < pl.Length; i++)
            {
                if (pl[i].ooa == false && pl[i].get_physd_actual() <= chosen)
                {
                    if (chosen == pl[i].get_physd_actual())
                    {
                        f_targets.Add(pl[i]);
                    }
                    else
                    {
                        f_targets.Clear();
                        f_targets.Add(pl[i]);
                    }
                    chosen = pl[i].get_physd_actual();
                }
            }
            chosen = UnityEngine.Random.Range(0, f_targets.Count);
            nextX  = f_targets[chosen].get_y();
            nextY  = f_targets[chosen].get_x();
            break;

        case 6:
            // 6: hit enemy with lowest mdef
            chosen = pl[0].get_magd_actual();
            f_targets.Add(pl[0]);

            for (int i = 1; i < pl.Length; i++)
            {
                if (pl[i].ooa == false && pl[i].get_magd_actual() <= chosen)
                {
                    if (chosen == pl[i].get_magd_actual())
                    {
                        f_targets.Add(pl[i]);
                    }
                    else
                    {
                        f_targets.Clear();
                        f_targets.Add(pl[i]);
                    }
                    chosen = pl[i].get_magd_actual();
                }
            }
            chosen = UnityEngine.Random.Range(0, f_targets.Count);
            nextX  = f_targets[chosen].get_y();
            nextY  = f_targets[chosen].get_x();
            break;

        case 7:
            // 7: hit enemy weakest to move's element

            double chosend = WorldManager.get_eleMod(pl[0].get_aff(), nextMove.get_ele());
            f_targets.Add(pl[0]);

            for (int i = 1; i < pl.Length; i++)
            {
                if (pl[i].ooa == false && WorldManager.get_eleMod(pl[i].get_aff(), nextMove.get_ele()) <= chosend)
                {
                    if (chosend == WorldManager.get_eleMod(pl[i].get_aff(), nextMove.get_ele()))
                    {
                        f_targets.Add(pl[i]);
                    }
                    else
                    {
                        f_targets.Clear();
                        f_targets.Add(pl[i]);
                    }
                    chosend = WorldManager.get_eleMod(pl[i].get_aff(), nextMove.get_ele());
                }
            }
            chosen = UnityEngine.Random.Range(0, f_targets.Count);
            nextX  = f_targets[chosen].get_y();
            nextY  = f_targets[chosen].get_x();
            break;

        case 8:
            // 8: aoe, most targets
            List <PlayerUnit> max_f_targets = new List <PlayerUnit>();
            int currentTargetNumber         = 0;
            int maxTargetNumber             = 0;
            //method:
            //for each tile:
            //  gen list of affected targets
            //  take running max targetlist.

            for (int c = 0; c < 5 - aoe_y; c++)
            {
                for (int r = 0; r < 6 - aoe_x; r++)
                {
                    //generate aoe area for each tile
                    currentTargetNumber = 0;
                    for (int i = c; i < c + aoe_y; i++)
                    {
                        for (int j = r; j < r + aoe_x; j++)
                        {
                            //if tile is occupied
                            if (pMap.search_unit(i, j) != null)
                            {
                                //and if unit on tile is not already in f_targets and is not ooa
                                if (!f_targets.Contains(pMap.search_unit(i, j)) && pMap.search_unit(i, j).ooa == false)
                                {
                                    f_targets.Add(pMap.search_unit(i, j));
                                    currentTargetNumber++;
                                }
                            }
                        }
                    }
                    if (currentTargetNumber > 0 && currentTargetNumber >= maxTargetNumber)
                    {
                        if (currentTargetNumber == maxTargetNumber)
                        {
                            //50% chance to replace if same target count,
                            chosen = UnityEngine.Random.Range(0, 2);     //can be 0 or 1
                            //Debug.Log(chosen);
                            if (chosen == 0)
                            {
                                max_f_targets = f_targets;
                                nextX         = c;
                                nextY         = r;
                            }     //else, do nothing
                        }
                        else
                        {
                            max_f_targets   = f_targets;
                            maxTargetNumber = currentTargetNumber;
                            nextX           = c;
                            nextY           = r;
                        }
                    }

                    f_targets.Clear();
                }
            }
            break;
        }
        //Debug.Log(nom + ":attack logged at x,y = " + nextX + "," + nextY);
    }