//When a change occurs, the static variable will be equal to this class.

    private void OnValidate()
    {
        if (moves == null)
        {
            _moves = this;
        }
    }
    private void explorePath(MoveAction move, Vector2 target, PathAction parent, PriorityQueue front, Hashtable map, ContactFilter2D filter)
    {
        RaycastHit2D[] hits   = new RaycastHit2D[1];
        Vector2        newPos = centerVector(parent.pos + move.dir.normalized * move.dist);

        //Debug.Log(parent.pos + " -> " + newPos);
        if (!map.Contains(newPos))
        {
            if (MoveSets.checkMove(move.type, parent.pos, move, filter))
            {
                PathAction newAct = new PathAction(newPos, parent, move, target);
                map.Add(newPos, newAct);
                front.Push(newAct);
            }
        }
        else
        {
            //check if should update value in frontier
            if (MoveSets.checkMove(move.type, parent.pos, move, filter) /*Physics2D.Raycast(parent.pos, move.dir, filter, hits, move.dist+.1f) <= 0*/)
            {
                PathAction oldAct = (PathAction)map[newPos];
                if (parent.dist + move.dist < oldAct.dist)
                {
                    oldAct.move   = move;
                    oldAct.parent = parent;
                    front.Update(oldAct, parent.dist + move.dist);
                }
            }
        }
    }
    // Move towards the player
    protected void MoveTowards()
    {
        float nowSecs = Time.time;

        if (nowSecs - lastRefresh >= pathingRefresh && actionLock <= 0)
        {
            lastRefresh = nowSecs;
            if (calcPath())
            {
                actionLock = 1;
            }
        }
        //Debug.Log(moveActions.Count);
        if (moving && moveActions != null && moveActions.Count > 0)
        {
            //myBase.myRigid.velocity = (myBase.player.transform.position - this.transform.position).normalized
            //    * myBase.myStats.movementSpeed;
            Vector2 correction = .5f * (centerVector(myBase.myRigid.position) - myBase.myRigid.position);

            MoveAction currAction = moveActions.First.Value;
            if (currAction.dist <= 0)
            {
                moveActions.RemoveFirst();
                actionLock--;
                if (moveActions.Count > 0)
                {
                    currAction = moveActions.First.Value;
                }
            }
            if (moveActions.Count > 0)
            {
                currAction.dist -= Time.deltaTime * myBase.myStats.movementSpeed;
                MoveSets.executeMove(currAction, myBase, correction);
            }
        }
        if (moving && ((moveActions != null && moveActions.Count <= 0) || moveActions == null))
        {
            if (Vector3.Distance(myBase.myRigid.position, myBase.player.transform.position) <= 2.5f)
            {
                myBase.myRigid.velocity = ((Vector2)myBase.player.transform.position - myBase.myRigid.position).normalized * myBase.myStats.movementSpeed;
            }
            else
            {
                myBase.myRigid.velocity = Vector2.zero;
            }
        }
    }
Exemple #4
0
        /// <summary>
        /// Writes out all of the .XML files.
        /// </summary>
        public void Write()
        {
            if (!Directory.Exists(Utils.OutputDataFileFolder))
            {
                Directory.CreateDirectory(Utils.OutputDataFileFolder);
            }

            // Must be written first so other Write() methods can leverage calculated values.
            Constants.Write();
            GAME_MASTERS.Write(GameMasters, GameMasterStatsCalculator);

            Moves.Write(PokeMoves.Values, GameMasterStatsCalculator);
            MoveSets.Write(Pokemon.Values, Forms, PokeMoves, ManualDataSettings, GameMasterStatsCalculator);
            PokeStats.Write(Pokemon.Values, ManualDataSettings, GameMasterStatsCalculator);
            RaidBoss.Write(ManualDataSettings, GameMasterStatsCalculator);
            Encounter.Write(ManualDataSettings, GameMasterStatsCalculator);
            Friendship.Write(Friendships, GameMasterStatsCalculator);

            // Must be written last so other Write() methods can update.
            Settings.Write(ManualDataSettings, GameMasterStatsCalculator);
        }
    public bool calcPath()
    {
        Hashtable pathMap = new Hashtable();
        LinkedList <MoveAction> moveActionsBuild = new LinkedList <MoveAction>();
        //Queue<PathAction> frontier = new Queue<PathAction>();
        PriorityQueue frontier  = new PriorityQueue();
        Vector2       myPos     = centerVector(myBase.myRigid.position);
        Vector2       playerPos = centerVector(myBase.player.transform.position);

        //Adjust enemy and player position so that player/enemy not located inside 2.5D wall
        RaycastHit2D wallStartCheck = Physics2D.Raycast(myPos + Vector2.down * .2f, Vector2.up, .4f, LayerMask.GetMask("Wall"));

        if (wallStartCheck.collider != null)
        {
            myPos = myPos + Vector2.down;
        }
        wallStartCheck = Physics2D.Raycast(playerPos + Vector2.down * .2f, Vector2.up, .4f, LayerMask.GetMask("Wall"));
        if (wallStartCheck.collider != null)
        {
            playerPos = playerPos + Vector2.down;
        }

        PathAction startAct = new PathAction(new Vector2(myPos.x, myPos.y), null, new MoveAction(Vector2.zero, 0));

        pathMap.Add(myPos, startAct);
        //frontier.Enqueue(startAct);
        frontier.Push(startAct);
        ContactFilter2D filter = new ContactFilter2D();

        filter.SetLayerMask(1 << 8);

        //Debug.Log("Start: " + myPos);
        MoveAction[] nextMoves = MoveSets.getDirections(moveTypes);

        while (frontier.Count() > 0)
        {
            PathAction curr = frontier.Pop();
            if (Mathf.Abs(curr.pos.x - playerPos.x) <= targetProximity + .1 && Mathf.Abs(curr.pos.y - playerPos.y) <= targetProximity + .1)
            {
                while (curr.parent != null)
                {
                    //Debug.Log(curr.pos + " dir: "+curr.move.dir+ " dist: " + curr.dist);
                    moveActionsBuild.AddFirst(curr.move.copy());
                    curr = curr.parent;
                }
                break;
            }
            if (Vector2.Distance(curr.pos, playerPos) < maxDist)
            {
                foreach (MoveAction direction in nextMoves)
                {
                    explorePath(direction, playerPos, curr, frontier, pathMap, filter);
                }
            }
        }
        moveActions = moveActionsBuild;
        if (moveActionsBuild.Count > 0)
        {
            return(true);
        }
        return(false);
    }
Exemple #6
0
    public void TileIsClicked()
    {
        if (GameScene.playerTurnHasStarted)
        {
            if (EventSystem.current.currentSelectedGameObject.GetComponent <Image>().sprite.Equals(defaultSprite))
            {
                var selectedTile = EventSystem.current.currentSelectedGameObject;
                selectedTile.GetComponent <Image>().sprite = EventSystem.current.currentSelectedGameObject.GetComponent <Tile>().tile;

                if (Input.touches.Length < 2)
                {
                    flipXValue = 0.2f;    // Initial localscale.x value of the selected tile when it begins to flip.

                    doneFlipping = false; // Flip card.
                }

                selectedTiles.Add(EventSystem.current.currentSelectedGameObject);

                if (selectedTiles.Count > 1)
                {
                    chosenTile1 = selectedTiles[0];
                    chosenTile2 = selectedTiles[1];

                    if (chosenTile1.GetComponent <Tile>().effectId == chosenTile2.GetComponent <Tile>().effectId&& chosenTile1.GetComponent <Tile>().tileType == chosenTile2.GetComponent <Tile>().tileType)
                    {
                        Debug.Log("Tiles are similar!");

                        Tile tile = chosenTile1.GetComponent <Tile>();

                        GameScene.pairedTiles.Add(tile);

                        if (tile.tileType == TileType.Item)
                        {
                            switch (tile.effectId)
                            {
                            case 1:
                                GameScene.player.IncreaseHealth(20);
                                break;

                            case 2:
                                GameScene.player.IncreaseHealth(30);
                                break;

                            case 3:
                                GameScene.potionCount++;
                                break;

                            default:
                                Debug.LogError("PlayerTurnEnded(): Healing tiles switch case defaulted!");
                                GameScene.player.IncreaseHealth(30);
                                break;
                            }
                        }
                        else if (tile.tileType == TileType.Move)
                        {
                            Move move = MoveSets.RetrieveMove(tile);
                            Debug.Log("Selected Tile: " + move.name + "\nDamage: " + move.attack);

                            if (GameScene.player.charge < GameScene.player.maxCharge && !GameScene.specialAttackModeActivated)
                            {
                                GameScene.player.IncreaseCharge(10);
                            }

                            StartCoroutine(gameScene.ExecuteMove(move));
                        }

                        sounds.PlayCorrectMatchSound();

                        CreateGhostTile(selectedTiles[0]);
                        CreateGhostTile(selectedTiles[1]);

                        GameScene.matches++;
                    }
                    else
                    {
                        sounds.PlayWrongMatchSound();

                        Debug.Log("Tiles are different!");
                        StartCoroutine(HideSelectedTiles());
                    }

                    selectedTiles.Clear();
                }
            }
        }
    }