Exemplo n.º 1
0
    /*public void GetClickTile () {
     * }*/

    // Find the next NPC that hasn't moved and move it randomly.
    // Return true if an NPC moved
    // TEMP function
    public bool MoveNextNPC()
    {
        // Find the NEAREST fan that hasn't moved
        GameObject nextFan = null;

        foreach (GameObject fanObj in fans)
        {
            TokenHandler fan = fanObj.GetComponent <TokenHandler> ();
            if (fan.MovedThisTurn)
            {
                continue;
            }

            // Set/compare it
            if (nextFan == null)
            {
                nextFan = fanObj;
            }
            else
            {
                TokenHandler curr     = nextFan.GetComponent <TokenHandler> ();
                int          currDist = getMinDistFromPlayer(new IntPoint(curr.TileX, curr.TileY));
                int          nxtDist  = getMinDistFromPlayer(new IntPoint(fan.TileX, fan.TileY));
                if (nxtDist < currDist)
                {
                    nextFan = fanObj;
                }
            }
        }

        // Anything?
        if (nextFan != null)
        {
            TokenHandler fan = nextFan.GetComponent <TokenHandler> ();
            fan.MovedThisTurn = true;

            // Are we moving or attacking?
            foreach (char s in "NSEW")
            {
                IntPoint next = IntPoint.FromCardinal(fan.TileX, fan.TileY, s);
                if (SingleCollide(leadPlayer, next) || SingleCollide(leadDate, next))
                {
                    //leadPlayer.GetComponent<TokenHandler> ().LeadObj.SelfEsteem -= 1;

                    // TODO: Show animation

                    // TODO: Play damage sound (placeholder)
                    //sfxSource.clip = movementSFX[ Random.Range(0, movementSFX.Length) ];
                    //sfxSource.Play();
                    GameObject source = Instantiate(soundSource, mainCamera.transform.position, Quaternion.identity);
                    source.transform.SetParent(mainCamera.transform);
                    source.GetComponent <AudioSource>().clip = movementSFX[Random.Range(0, movementSFX.Length)];
                    source.GetComponent <AudioSource> ().Play();

                    // Destroy this fan
                    leadPlayer.GetComponent <TokenHandler>().HighlightToken();
                    leadDate.GetComponent <TokenHandler> ().HighlightToken();

                    DestroyFanNew(nextFan);

                    // Damage player
                    LeadPlayerScript.SelfEsteem -= 1;

                    return(true);
                }
            }

            // Ok, we're walking
            bool didAWalk = fan.FanWalkTowards(LeadDate, LeadPlayer);

            // Safety save
            if (!didAWalk)
            {
                // Find the two closest tiles, and choose between them (if moveable).
                // Never move heuristically away
                List <IntPoint> options = new List <IntPoint>();

                // Horizontal
                IntPoint eTile = IntPoint.FromCardinal(fan.TileX, fan.TileY, 'E');
                IntPoint wTile = IntPoint.FromCardinal(fan.TileX, fan.TileY, 'W');
                if (getMinDistFromPlayer(eTile) < getMinDistFromPlayer(wTile))
                {
                    options.Add(eTile);
                }
                else
                {
                    options.Add(wTile);
                }



                // Vertical
                IntPoint nTile = IntPoint.FromCardinal(fan.TileX, fan.TileY, 'N');
                IntPoint sTile = IntPoint.FromCardinal(fan.TileX, fan.TileY, 'S');
                if (getMinDistFromPlayer(nTile) < getMinDistFromPlayer(sTile))
                {
                    options.Add(nTile);
                }
                else
                {
                    options.Add(sTile);
                }

                // Now check.
                if (!CanMove(options [1]))
                {
                    options.RemoveAt(1);
                }
                if (!CanMove(options [0]))
                {
                    options.RemoveAt(0);
                }

                // Anything left?
                if (options.Count > 0)
                {
                    IntPoint pt = options[GameState.rng.Next(options.Count)];
                    fan.MoveToTile(pt.x, pt.y);
                    didAWalk = true;
                    Debug.Log("SAVE");
                }
            }

            // Play movement SFX
            if (didAWalk)
            {
                GameObject source = Instantiate(soundSource, mainCamera.transform.position, Quaternion.identity);
                source.transform.SetParent(mainCamera.transform);
                source.GetComponent <AudioSource>().clip = movementSFX[Random.Range(0, movementSFX.Length)];
                source.GetComponent <AudioSource> ().Play();

                return(true);
            }
            else
            {
                return(false);
            }
        }
        return(false);
    }