Esempio n. 1
0
    //- [ ] Greed => Destroy more gems with skill
    public void destroySomeTiles(TileMeta.GemType toRemove, int min, int max)
    {
        min += (int)PanelManager.instance.getCurrentMonster().greed;
        max += (int)PanelManager.instance.getCurrentMonster().greed;

        int dmg = 0;
        List <GameObject> validTiles = new List <GameObject>();

        for (int x = 0; x < xSize; x++)
        {
            for (int y = 0; y < ySize; y++)
            {
                if (tiles[x, y].GetComponent <Tile>().type.type == toRemove)
                {
                    validTiles.Add(tiles[x, y]);
                }
            }
        }
        GameObject[] endTiles = validTiles.ToArray();
        GameUtilities.ShuffleArray(endTiles);
        int maxTls = UnityEngine.Random.Range(min, max + 1);

        for (int i = 0; i < maxTls && i < endTiles.Length; i++)
        {
            StartCoroutine(DestroyTile(endTiles[i].GetComponent <Tile>()));
            if (toRemove == TileMeta.GemType.Fight)
            {
                dmg++;
            }
        }
        Tile.characterHit(dmg);
        StartCoroutine(FindNullTiles());
    }
Esempio n. 2
0
    //- [ ] Lust => Change more gems with skill
    public void switchSomeTiles(TileMeta.GemType from, TileMeta.GemType to, int min, int max)
    {
        min += (int)PanelManager.instance.getCurrentMonster().lust;
        max += (int)PanelManager.instance.getCurrentMonster().lust;

        List <GameObject> validTiles = new List <GameObject>();

        for (int x = 0; x < xSize; x++)
        {
            for (int y = 0; y < ySize; y++)
            {
                if (tiles[x, y].GetComponent <Tile>().type.type == from)
                {
                    validTiles.Add(tiles[x, y]);
                }
            }
        }
        GameObject[] endTiles = validTiles.ToArray();
        GameUtilities.ShuffleArray(endTiles);
        int maxTls = UnityEngine.Random.Range(min, max + 1);

        for (int i = 0; i < maxTls && i < endTiles.Length; i++)
        {
            int idx = (new List <TileMeta.GemType>(gemTypes)).IndexOf(to);
            endTiles[i].GetComponent <Tile>().type.type = to;
            StartCoroutine(switchTwoTiles(endTiles[i].GetComponent <Tile>(), to, characters[idx]));
        }
        StartCoroutine(WaitThenCheck());
    }
Esempio n. 3
0
    public IEnumerator waitHint()
    {
        yield return(new WaitForSeconds(20f));

        if (!GameManager.instance.gameOver)
        {
            List <coords> validMoves = new List <coords>();
            int[,] tempBoard = new int[xSize, ySize];
            for (int x = 0; x < xSize; x++)
            {
                for (int y = 0; y < ySize; y++)
                {
                    tempBoard[x, y] = (int)tiles[x, y].GetComponent <Tile>().type.type;
                    tiles[x, y].GetComponent <Tile>().Deselect();
                }
            }

            List <Vector2> positions = new List <Vector2>();

            int[,] scoreBoard = new int[xSize, ySize];
            for (int x = 0; x < xSize; x++)
            {
                for (int y = 0; y < ySize; y++)
                {
                    foreach (Vector2 dir in Tile.adjacentDirections)
                    {
                        int[,] copyBoard = tempBoard.Clone() as int[, ];
                        if (dir.x + x >= 0 && dir.x + x < xSize && dir.y + y >= 0 && dir.y + y < ySize)
                        {
                            int temp = copyBoard[(int)dir.x + x, (int)dir.y + y];
                            copyBoard[(int)dir.x + x, (int)dir.y + y] = copyBoard[x, y];
                            copyBoard[x, y] = temp;
                            // At the two points selected, look out in all the directions and see if we've found a match
                            int mtchA = returnBoardMatches(copyBoard, new Vector2(x, y));
                            int mtchB = returnBoardMatches(copyBoard, new Vector2((int)dir.x + x, (int)dir.y + y));

                            int score = mtchA > mtchB ? mtchA : mtchB;
                            scoreBoard[x, y] = score;

                            if (score > 2)
                            {
                                positions.Add(new Vector2(x, y));
                                validMoves.Add(new coords(tiles[x, y].GetComponent <Tile>(), dir));
                            }
                        }
                    }
                }
            }

            coords[] moves = validMoves.ToArray();
            GameUtilities.ShuffleArray(moves);

            if (moves[0].tile.GetAdjacent(moves[0].dir) != null)
            {
                moves[0].tile.SelectHint();
                moves[0].tile.GetAdjacent(moves[0].dir).GetComponent <Tile>().SelectHint();
            }
        }
    }
Esempio n. 4
0
    /*
     * TODO:
     * Generate Monster given monster name and level
     * Add a function that returns a float[] with the level updates for the monster
     */

    public static PlayerRosterMeta returnMonster(MonsterMeta meta, int lvl, bool wild)
    {
        PlayerRosterMeta newMonster = meta.toAbbrev();
        List <String>    skills     = new List <string>();

        for (int i = 1; i <= lvl; i++)
        {
            float[] updates = returnLvlUpdates(meta, newMonster);
            newMonster.lust     += updates[0] * (wild ? .85f : 1f);
            newMonster.greed    += updates[1] * (wild ? .85f : 1f);
            newMonster.wrath    += updates[2] * (wild ? .85f : 1f);
            newMonster.pride    += updates[3] * (wild ? .85f : 1f);
            newMonster.gluttony += updates[4] * (wild ? .85f : 1f);
            newMonster.sloth    += updates[5] * (wild ? .85f : 1f);
            newMonster.envy     += updates[6] * (wild ? .85f : 1f);

            newMonster.gluttony_bonus += newMonster.gluttony + .55f;
            if (newMonster.gluttony_bonus >= 1)
            {
                newMonster.maxHealth     += (int)newMonster.gluttony_bonus;
                newMonster.gluttony_bonus = newMonster.gluttony_bonus - ((int)newMonster.gluttony_bonus);
            }

            foreach (lvlUpSkills skill in meta.skillsGainedOnLvlUp)
            {
                if (skill.lvl == i)
                {
                    skills.Add(skill.skill);
                    while (skills.Count > 4)
                    {
                        skills.RemoveAt(UnityEngine.Random.Range(0, skills.Count));
                    }
                }
            }
            // Level 1 monsters don't have any exp
            if (i > 1)
            {
                int[] lvlExp = CalcLvl(newMonster, meta.lvlSpeed);
                newMonster.exp += lvlExp[2];
            }
        }
        newMonster.lvl       = lvl;
        newMonster.curHealth = newMonster.maxHealth;
        string[] monsterSkills = skills.ToArray();
        GameUtilities.ShuffleArray(monsterSkills);
        newMonster.skills = monsterSkills;
        return(newMonster);
    }
Esempio n. 5
0
    public IEnumerator WaitTrigger(float wait)
    {
        int roll = Random.Range(0, 10);

        if (roll < 1 && GetComponent <Move>().Moving() && !PauseManager.instance.IsOpen() && !DialogManager.instance.ShopActive() && !DialogManager.instance.DialogActive())
        {
            Debug.Log("Hit");

            //GetComponent<Move>().disableMove();
            AdventureMeta meta      = BaseSaver.getAdventure();
            Glossary      glossy    = GameObject.Find("PauseCanvas").GetComponent <PauseManager>().glossaryObj.GetComponent <Glossary>();
            SceneMeta     thisScene = glossy.GetScene(BaseSaver.getMap()).meta;

            List <PlayerRosterMeta> monsters = new List <PlayerRosterMeta>();
            foreach (string mons in thisScene.monsters)
            {
                if (!mons.Equals(lastMonster))
                {
                    MonsterMeta met = glossy.GetMonsterMain(mons).meta;
                    int         lvl = Random.Range(thisScene.monsterLvls[0], thisScene.monsterLvls[1]);
                    monsters.Add(MonsterMeta.returnMonster(met, lvl, true));
                }
            }

            PlayerRosterMeta[] scrbMons = monsters.ToArray();
            GameUtilities.ShuffleArray(scrbMons);

            meta.trainer            = null;
            meta.wild               = scrbMons[0];
            meta.isTrainerEncounter = false;
            lastMonster             = meta.wild.name;

            BaseSaver.putAdventure(meta);
            BaseSaver.putBoard(GameUtilities.getBoardState(BaseSaver.getMap(), new PosMeta(transform.position)));

            StartCoroutine(DialogManager.FightFlash(false));
            //Initiate.Fade("BejeweledScene", Color.black, 1.0f);
        }
        yield return(new WaitForSeconds(wait));

        waitingForRoll = false;
        yield return(null);
    }
Esempio n. 6
0
    /*
     * ai sometimes moves for player
     * gems sometimes given to player when they are not players gems
     */
    public IEnumerator MoveAI()
    {
        bool             hasSpecial = false;
        List <SkillMeta> compSkills = new List <SkillMeta>(PanelManager.instance.getComputerSkills());

        for (int i = 0; i < compSkills.Count; i++)
        {
            bool ready = true;
            foreach (SkillReq req in new SkillReq[] { compSkills[i].req1, compSkills[i].req2 })
            {
                if (req.has != req.req)
                {
                    ready = false;
                }
            }
            if (ready)
            {
                hasSpecial = true;
                PanelManager.instance.setActiveSkill(i);
                yield return(new WaitForSeconds(.5f));

                bool        found  = false;
                List <Tile> toPoke = new List <Tile>();
                SkillMeta   meta   = compSkills[i];
                foreach (SkillEffect eff in meta.effects)
                {
                    if (eff.effect == SkillEffect.Effect.Poke || eff.effect == SkillEffect.Effect.Slice)
                    {
                        TileMeta.GemType tileType;
                        if (eff.effect == SkillEffect.Effect.Poke)
                        {
                            tileType = ((SkillEffect.PokeSkill)eff).toRemove;
                        }
                        else
                        {
                            tileType = ((SkillEffect.SliceSkill)eff).toRemove;
                        }
                        for (int x = 0; x < xSize; x++)
                        {
                            for (int y = 0; y < ySize; y++)
                            {
                                if (tiles[x, y].GetComponent <Tile>().type.type == tileType)
                                {
                                    toPoke.Add(tiles[x, y].GetComponent <Tile>());
                                }
                            }
                        }
                        found = true;
                    }
                }

                if (!found)
                {
                    tiles[0, 0].GetComponent <Tile>().computerUseSkill();
                }
                else if (toPoke.Count > 0)
                {
                    Tile[] pkArr = toPoke.ToArray();
                    GameUtilities.ShuffleArray(pkArr);
                    pkArr[0].computerUseSkill();
                }

                yield return(new WaitForSeconds(.5f));

                //        while(IsShifting && IsProcessing){}
                //Debug.Log("IsShifting: " + isShifting().ToString());
                Debug.Log("IsProcessing: " + IsThinking().ToString());
                int counter      = 0;
                int checksPassed = 0;
                while (checksPassed < 3 && counter < 30)
                {
                    yield return(new WaitForSeconds(.25f));

                    counter++;
                    if (!IsThinking())
                    {
                        checksPassed++;
                    }
                    else
                    {
                        checksPassed = 0;
                    }
                }
                //yield return new WaitForSeconds(.25f);
                StartCoroutine(loopAIMovement());
                break;
            }
        }
        if (!hasSpecial)
        {
            // See which gems the computer needs to complete it's skills
            List <TileMeta.GemType> preferredGems = new List <TileMeta.GemType>();
            preferredGems.Add(TileMeta.GemType.Fight);
            for (int i = 0; i < compSkills.Count; i++)
            {
                foreach (SkillReq req in new SkillReq[] { compSkills[i].req1, compSkills[i].req2 })
                {
                    if (req.has != req.req && !preferredGems.Contains(req.gem))
                    {
                        preferredGems.Add(req.gem);
                    }
                }
            }

            int counter      = 0;
            int checksPassed = 0;
            while (checksPassed < 3 && counter < 30)
            {
                yield return(new WaitForSeconds(.25f));

                counter++;
                if (!IsThinking())
                {
                    checksPassed++;
                }
                else
                {
                    checksPassed = 0;
                }
            }

            List <coords> validMoves     = new List <coords>();
            List <coords> preferredMoves = new List <coords>();
            int           max            = 0;
            int[,] tempBoard = new int[xSize, ySize];
            for (int x = 0; x < xSize; x++)
            {
                for (int y = 0; y < ySize; y++)
                {
                    tempBoard[x, y] = (int)tiles[x, y].GetComponent <Tile>().type.type;
                }
            }

            // board 0,0 = temp 0,9

            List <Vector2> positions = new List <Vector2>();

            int[,] scoreBoard = new int[xSize, ySize];
            for (int x = 0; x < xSize; x++)
            {
                for (int y = 0; y < ySize; y++)
                {
                    foreach (Vector2 dir in Tile.adjacentDirections)
                    {
                        int[,] copyBoard = tempBoard.Clone() as int[, ];
                        if (dir.x + x >= 0 && dir.x + x < xSize && dir.y + y >= 0 && dir.y + y < ySize)
                        {
                            int temp = copyBoard[(int)dir.x + x, (int)dir.y + y];
                            copyBoard[(int)dir.x + x, (int)dir.y + y] = copyBoard[x, y];
                            copyBoard[x, y] = temp;
                            // At the two points selected, look out in all the directions and see if we've found a match
                            int mtchA = returnBoardMatches(copyBoard, new Vector2(x, y));
                            int mtchB = returnBoardMatches(copyBoard, new Vector2((int)dir.x + x, (int)dir.y + y));

                            int score = mtchA > mtchB ? mtchA : mtchB;
                            scoreBoard[x, y] = score;

                            if (score > 2)
                            {
                                positions.Add(new Vector2(x, y));

                                validMoves.Add(new coords(tiles[x, y].GetComponent <Tile>(), dir));
                                if (preferredGems.Contains(tiles[x, y].GetComponent <Tile>().type.type))
                                {
                                    score++;
                                }

                                if (max < score)
                                {
                                    Debug.Log("New Max!" + score.ToString());
                                    preferredMoves.Clear();
                                    max = score;
                                }
                                if (max == score)
                                {
                                    preferredMoves.Add(new coords(tiles[x, y].GetComponent <Tile>(), dir));
                                }
                            }
                        }
                    }
                }
            }

            coords[] moves     = validMoves.ToArray();
            coords[] prefMoves = preferredMoves.ToArray();

            GameUtilities.ShuffleArray(moves);
            GameUtilities.ShuffleArray(prefMoves);

            if (prefMoves.Length > 0)
            {
                Debug.Log("prefMoves: " + prefMoves.Length.ToString());
                prefMoves[0].tile.Select();
                yield return(new WaitForSeconds(.6f));

                prefMoves[0].tile.computerSwap(prefMoves[0].dir);
                moveWait = WaitForMovement();
                StartCoroutine(moveWait);
                yield return(null);
            }
            else if (moves.Length > 0)
            {
                Debug.Log("moves: " + moves.Length.ToString());
                Debug.Log("moves: " + moves.Length.ToString());
                moves[0].tile.Select();
                yield return(new WaitForSeconds(.6f));

                moves[0].tile.computerSwap(moves[0].dir);
                moveWait = WaitForMovement();
                StartCoroutine(moveWait);
                yield return(null);
            }
            else
            {
                // There aren't any moves to make, reset the board and try again
                reset(true);
                counter = 0;
                while (IsThinking() && counter < 30)
                {
                    yield return(new WaitForSeconds(.25f));

                    counter++;
                    Debug.Log("Counter: " + counter);
                    //Debug.Log("IsShifting: " + isShifting().ToString());
                    Debug.Log("IsProcessing: " + IsThinking().ToString());
                }
                //yield return new WaitForSeconds(.25f);
                StartCoroutine(loopAIMovement());
            }
        }
    }