Esempio n. 1
0
    private bool MoveCharacter(Character activeChar, List <Character> myChars, Player enemyPlayer)
    {
        if (activeChar == null)
        {
            return(false);
        }

        List <Character> enemyChars = new List <Character>(enemyPlayer.characters.Values);
        GameState        gameState  = new GameState(myChars, enemyChars, htc.FindHex(activeChar.gameCharacter.position), activeChar);

        MiniAction miniAction = Search.DecideAction(gameState, htc);

        //Debug.Log(character.name+" will "+miniAction.type);

        switch (miniAction.type)
        {
        case "Move":
            HexTile  startTile = htc.FindHex(activeChar.gameCharacter.position);
            MiniMove move      = miniAction as MiniMove;

            List <int> path = Search.GreedySearch(startTile, move.Dest, htc);
            //Path ends on the tile you want to move to
            List <Vector3> moves = new List <Vector3>();
            if (path.Count > 0)
            {
                moves.Add(startTile.nexts[path[0]].Position);
                for (int i = 1; i < path.Count; i++)
                {
                    int neighbor = path[i];
                    moves.Add(htc.FindHex(moves[i - 1]).nexts[path[i]].Position);
                }
            }
            else
            {
                moves.Add(activeChar.gameCharacter.position);
            }

            //Debug.Log(activeChar.name+" is Moving to " + moves[moves.Count - 1]);
            //Action a = MoveActionFactory.getInstance().CreateAction(character, moves[moves.Count-1]);

            Action m = MoveActionFactory.getInstance().CreateAction(activeChar, moves.ToArray());
            GameSystem.CurrentGame().ExecuteCharacterAction(player, m);

            //StartCoroutine(Move(character.gameCharacter.gameObject, path, 0.5f));
            break;

        case "Attack":
            MiniAttack attack = miniAction as MiniAttack;
            Action     a      = AttackActionFactory.GetInstance().CreateAction(activeChar, attack.toAttack.gameCharacter.position);
            GameSystem.CurrentGame().ExecuteCharacterAction(player, a);
            break;

        case "AOEAttack":
            MiniAttack aoeAttack = miniAction as MiniAttack;
            Action     aoeA      = AttackActionFactory.GetInstance().CreateAction(activeChar, aoeAttack.attackLocation);
            GameSystem.CurrentGame().ExecuteCharacterAction(player, aoeA);
            break;
        }
        return(true);
    }
Esempio n. 2
0
    public static float EvaluateAOEAttackState(GameState gameState, HexTileController htc)
    {
        //Data is going into a MinQ, smaller number is better
        float          aiHealthLost = 0;
        float          playerLost   = 0;
        List <HexTile> attackRange  = htc.FindRadius(gameState.selfTile, gameState.selfChar.stats.aoeRange);

        attackRange.Add(gameState.selfTile);
        foreach (HexTile hex in attackRange)
        {
            foreach (Character c in gameState.aiChars)
            {
                if (hex.Equals(htc.FindHex(c.gameCharacter.position)))
                {
                    aiHealthLost += gameState.selfChar.stats.attackdmg;
                }
            }
            foreach (Character c in gameState.playerChars)
            {
                if (hex.Equals(htc.FindHex(c.gameCharacter.position)))
                {
                    playerLost += gameState.selfChar.stats.attackdmg;
                }
            }
        }


        return(aiHealthLost - playerLost);
    }
Esempio n. 3
0
    public void Start()
    {
        surrounding = new List <HexTile>();

        sprite  = GetComponentInChildren <SpriteRenderer>();
        hexTile = hexTileController.FindHex(transform.position);
        hexTile.setHighlight(true);
        transform.position = hexTile.Position;
        MoveHighlight();
    }
Esempio n. 4
0
 public void Start()
 {
     hexTileController  = GameObject.FindGameObjectWithTag("HexController").GetComponent <HexTileController>();
     hexTile            = hexTileController.FindHex(transform.position);
     transform.position = hexTile.Position;
     hexTile.SetObject(gameObject, true);
 }
Esempio n. 5
0
    void Attack()
    {
        HexTile attackedtile = htc.FindHex(space);

        //parker
        takenby.gameCharacter.GetComponent <Agent>().SpawnProjectile(attackedtile.Position);

        if (takenby.characterclass.Equals(CharacterClass.HACKER))
        {
            //deals AOE
            ///2 is hard coded, in future replace with a character class variable
            List <Character> inarea = GetAllInAOERange(attackedtile, takenby.stats.aoeRange);
            foreach (Character c in inarea)
            {
                //c.stats.health += damage;
                c.gameCharacter.GetComponent <Agent>().Health(damage);
                Debug.Log(c.name + " takes " + damage);
                foreach (Player p in GameSystem.CurrentGame().Players())
                {
                    if (GameSystem.CurrentGame().CheckDeath(c, p))
                    {
                        htc.FindHex(c.gameCharacter.position).SetObject(null, false);
                    }
                }
            }
        }
        // else
        // {//deal damage to single object
        if (attackedtile.HoldingObject != null)
        {
            Agent totakedamage = attackedtile.HoldingObject.GetComponent <Agent>();

            if (totakedamage != null)
            {
                totakedamage.Health(damage);
                Debug.Log(totakedamage.character.name + " takes " + damage);
                foreach (Player p in GameSystem.CurrentGame().Players())
                {
                    if (GameSystem.CurrentGame().CheckDeath(totakedamage.character, p))
                    {
                        htc.FindHex(totakedamage.character.gameCharacter.position).SetObject(null, false);
                    }
                }
            }
        }
        // }
    }
Esempio n. 6
0
 public IEnumerator MoveTo(params Vector3[] positions)
 {
     while (current_move_action != total_move_action)
     {
         //get the tile to goto
         HexTile tile = htc.FindHex(positions[current_move_action]);
         //take character off the current tile
         takenby.gameCharacter.GetComponent <Agent>().currentlyOn.SetObject(null, false);
         //put character onto the next tile
         takenby.gameCharacter.position = tile.transform.position;
         tile.SetObject(takenby.gameCharacter.gameObject, false);
         //update the tile character refernce
         takenby.gameCharacter.GetComponent <Agent>().currentlyOn = tile;
         //increment the action
         current_move_action++;
         yield return(new WaitForSecondsRealtime(0.25f));
     }
 }
Esempio n. 7
0
    // public void AddActionTo(Player p , Action a) {
    //     //put the action into the players list of actions
    //     // gameSystem.AddCharacterAction();
    // }

    //get rid of this
    public void RandomlyPlace()
    {
        HexTileController htc = GameObject.Find("TileController").GetComponent <HexTileController>();

        Debug.Log(htc.Head.Position);
        // hexTileController.FindHex(mousePos, hexTile);

        int totalcharactercount = GameSystem.CurrentGame().PlayerCount() * classes.Length;

        HashSet <HexTile> tiles = new HashSet <HexTile>();

        while (tiles.Count < totalcharactercount)
        {
            try{
                tiles.Add(
                    htc.FindHex(new Vector3(
                                    UnityEngine.Random.Range(-10f, 10f),
                                    UnityEngine.Random.Range(-10f, 10), 0f)
                                )
                    );
            } catch (Exception e) {}
        }

        HexTile[] tilearray = new HexTile[totalcharactercount];
        tiles.CopyTo(tilearray);

        int cc = 0;

        foreach (Player p in GameSystem.CurrentGame().Players())
        {
            foreach (Character c in p.characters.Values)
            {
                Agent a = c.gameCharacter.GetComponent <Agent>();
                // c.gameCharacter.position
                //update character ref
                a.currentlyOn        = tilearray[cc];
                a.transform.position = tilearray[cc].transform.position;
                //update tile ref
                tilearray[cc].SetObject(c.gameCharacter.gameObject, false);
                cc++;
            }
        }
    }
Esempio n. 8
0
    public static HexTile MoveTowards(Character target, GameState gameState, HexTileController htc, bool runFromEnemy = false)
    {
        //choose the tile you want to move to, either the character directly, or a tile next to the character that is away from the enemy
        HexTile targetTile = htc.FindHex(target.gameCharacter.position);

        if (runFromEnemy)
        {
            List <HexTile> tilesAroundTarget = htc.FindRadius(targetTile, 1);
            int            farthest          = 0;
            foreach (HexTile hexTile in tilesAroundTarget)
            {
                if (!hexTile.IsObstacle && hexTile.HoldingObject == null)
                {
                    //Find distance to all player characters
                    int newDist = 0;
                    foreach (Character c in gameState.playerChars)
                    {
                        newDist += htc.FindHexDistance(hexTile.Position, c.gameCharacter.position);
                    }
                    //You want the distance to the player to be largest
                    if (newDist > farthest)
                    {
                        farthest   = newDist;
                        targetTile = hexTile;
                    }
                }
            }
        }
        List <int> moves = GreedySearch(gameState.selfTile, targetTile, htc);

        //If run from enemy is false, your target in ON a character, so remove that last step
        if (!runFromEnemy)
        {
            //Remove the last step (the one on the distination character)
            if (moves.Count > 0)
            {
                moves.RemoveAt(moves.Count - 1);
            }
        }

        Debug.Log("Psyonic wants to move ...");
        foreach (int i in moves)
        {
            Debug.Log(i);
        }
        Debug.Log("To get to " + target.name);

        //If you were already right next to the target, don't go anywhere
        if (moves.Count == 0)
        {
            return(gameState.selfTile);
        }
        //Only keep the number of steps that you are allowed to move
        //Starting hex is your own
        HexTile hex = gameState.selfTile;

        //Repet until you hit your step count, or you run out of moves
        for (int i = 0; i < Mathf.Min(gameState.selfChar.stats.speed, moves.Count); i++)
        {
            //Get the neighbor that the path tells you too
            hex = hex.nexts[moves[i]];
        }
        return(hex);
    }
Esempio n. 9
0
    //filler code for now
    public void PutCharactersOnBoard()
    {
        GameObject tc = GameObject.Find("TileController");

        foreach (Player p in gameSystem.Players())
        {
            foreach (Character c in p.characters.Values)
            {
                //Debug.Log(c.name);
                //game is ready, show characters
                SpriteRenderer r = c.gameCharacter.gameObject.GetComponent <SpriteRenderer>();
                r.enabled          = true;
                r.sortingLayerName = "Characters";
            }
        }
        //GameObject.Find("Start").SetActive(false);
        //RandomlyPlace();

        HexTileController htc = GameObject.Find("TileController").GetComponent <HexTileController>();

        Player player1 = GameSystem.CurrentGame().Players()[0];
        int    index   = 0;

        foreach (Character c in player1.characters.Values)
        {
            Agent a = c.gameCharacter.GetComponent <Agent>();
            // c.gameCharacter.position
            //update character ref
            HexTile hex = htc.FindHex(player1_chars[index]);
            a.currentlyOn        = hex;
            a.transform.position = player1_chars[index];
            //update tile ref
            hex.SetObject(c.gameCharacter.gameObject, false);
            index++;

            //Add highlight to players
            Instantiate(playerHighlight, c.gameCharacter);
            GameObject temp = Instantiate(selectHighlight, c.gameCharacter);
            c.selectedHighlight = temp;
            c.SetSelected(false);
        }
        Player player2 = GameSystem.CurrentGame().Players()[1];

        index = 0;
        foreach (Character c in player2.characters.Values)
        {
            Agent a = c.gameCharacter.GetComponent <Agent>();
            // c.gameCharacter.pte character ref
            HexTile hex = htc.FindHex(player2_chars[index]);
            a.currentlyOn        = hex;
            a.transform.position = player2_chars[index];
            //update tile ref
            hex.SetObject(c.gameCharacter.gameObject, false);
            index++;

            //Add highlight to enemies
            Instantiate(enemyHighlight, c.gameCharacter);
            GameObject temp = Instantiate(selectHighlight, c.gameCharacter);
            c.selectedHighlight = temp;
            c.SetSelected(false);
        }
    }