Exemple #1
0
    /* @brief This function serves as a way to remove stamina from an entity at the given string key (name).
     *        Once the entity is found, remove the amount of stamina according to the argument passed.
     * @param The string key (name) to lookup within the entity list.
     * @param The amount of stamina to deplete from the entity.
     */
    public void DeminishStaminaOffEntity(string _entityName, float _amountToDeminish)
    {
        // The index of the entity is stored because it is used multiple times throughout the function.
        // Rather than doign the loop each time, just store it the first and only time.
        int entityIndex = DoesEntityExist(_entityName);

        // If the entityIndex is the error value returned, no reason to continue the function.
        if (entityIndex == ENTITY_INDEX_OUT_OF_RANGE)
        {
            return;
        }

        // See the last two lines of commented code in this function.
        newData = entityList[entityIndex];

        // Due to C# poor design in handling struct properties, I cant just assign an individual member of the entityData struct
        // for the given entity at the index. Instead I had to assign an entire struct... Please modifiy this if there is a work around.
        newData.stamina -= _amountToDeminish;

        // Begin the countdown for stamina regeneration.
        newData.timeSinceLastStaminaDeminish = Time.time;

        entityList[entityIndex] = newData;

        if (onStaminaTaken != null)
        {
            onStaminaTaken(this, EventArgs.Empty);
        }
    }
Exemple #2
0
    void FindRange(GameObject player)
    {
        entityData data = player.GetComponent <entityData>();

        rangebfs(currentPlayerData.movementPoints, data.tileOn);
        inEnemyRange = false;
    }
Exemple #3
0
    public void RestoreAllStats()
    {
        restoreInProcess = true;

        int bossIndex   = DoesEntityExist("Boss");
        int playerIndex = DoesEntityExist("Player");

        if (entityList[bossIndex].health >= entityList[bossIndex].maxHealth && entityList[playerIndex].health >= entityList[playerIndex].maxHealth)
        {
            restoreInProcess = false;

            // Make sure both entities are not about the max.
            newData               = entityList[bossIndex];
            newData.health        = newData.maxHealth;
            entityList[bossIndex] = newData;

            newData                 = entityList[playerIndex];
            newData.health          = newData.maxHealth;
            entityList[playerIndex] = newData;
        }

        if (onHealthReplenish != null)
        {
            onHealthReplenish(this, EventArgs.Empty);
        }

        for (int i = 0; i < entityList.Count; i++)
        {
            RestoreStatsOfEntity(entityList[i].name);
        }
    }
Exemple #4
0
    /* @brief Handles replenishing the entities stamina based on set conditions on if they are able to replenish as well as
     *        if they actually need to replenish.
     */
    private void ReplenishStamina()
    {
        // Loop over each entity in the entity list.
        for (int i = 0; i < entityList.Count; i++)
        {
            // If the entity is not at the maximum amount of stamina they have elegated, they can move onto further checks.
            if (entityList[i].stamina < entityList[i].maxStamina)
            {
                // If the entity has not deminished stamina after a set period, they can begin to regain stamina.
                if ((entityList[i].timeSinceLastStaminaDeminish + entityList[i].timeBeforeStaminaRegain) < Time.time)
                {
                    newData          = entityList[i];
                    newData.stamina += newData.speedOfStaminaRegain;
                    entityList[i]    = newData;

                    if (onStaminaReplenish != null)
                    {
                        onStaminaReplenish(this, EventArgs.Empty);
                    }
                }
            }
            else
            {
                // If the entity is at full stamina, have a fail safe to insure they do not go above max.
                newData         = entityList[i];
                newData.stamina = newData.maxStamina;

                entityList[i] = newData;
            }
        }
    }
Exemple #5
0
    /* @brief Set the instance of the singleton to this class data.
     */
    private void Awake()
    {
        // Assure that the object can be destroyed if has to be created again later.
        if (instance != null && instance != this)
        {
            Destroy(this.gameObject);
        }
        else
        {
            instance = this;
        }

        // Loop over all entities in the entity list and set the max health/stamina to the first state of current health/stamina.
        for (int i = 0; i < entityList.Count; i++)
        {
            newData = entityList[i];

            newData.maxHealth  = entityList[i].health;
            newData.maxStamina = entityList[i].stamina;

            if (entityList[i].name == "Boss")
            {
                newData.lives = entityList[i].entityObject.GetComponent <BossBrain>().m_bossPhaseList.Count;
            }

            newData.maxLives = entityList[i].lives;

            entityList[i] = newData;
        }
    }
Exemple #6
0
 public void initialEnemyTurn(GameObject player)
 {
     findTileOn();
     currentPlayerData = player.GetComponent <entityData>();
     currentPlayerData.movementPoints = currentPlayerData.movementRange;
     FindRange(player);
     initialRun = false;
 }
Exemple #7
0
 public void resolveHealthUI()
 {
     foreach (GameObject x in players)
     {
         entityData playerData = x.GetComponent <entityData>();
         playerData.healthBar.GetComponent <Slider>().value = (float)playerData.currentHealth / (float)playerData.maxHealth;
     }
 }
Exemple #8
0
 public void initialPlayerTurn(GameObject player)
 {
     findTileOn();
     currentPlayerData = player.GetComponent <entityData>();
     currentPlayerData.movementPoints = currentPlayerData.movementRange;
     currentPlayer = player;
     playerUI.SetActive(true);
     action = false;
 }
Exemple #9
0
    public void SetMaxStaminaOfEntity(string _entityName, float _newMaxStamina)
    {
        int entityIndex = DoesEntityExist(_entityName);

        newData = entityList[entityIndex];

        newData.maxStamina = _newMaxStamina;

        entityList[entityIndex] = newData;
    }
Exemple #10
0
    public void SetMaxHealthOfEntity(string _entityName, float newMaxHP)
    {
        int entityIndex = DoesEntityExist(_entityName);

        newData = entityList[entityIndex];

        newData.maxHealth = newMaxHP;

        entityList[entityIndex] = newData;
    }
Exemple #11
0
 public void findTileOn()
 {
     foreach (GameObject x in players)
     {
         //Logic for if players are dead or not recruited
         //Set player tile on
         if (x.activeInHierarchy)
         {
             entityData data = x.GetComponent <entityData>();
             foreach (GameObject y in tileMap)
             {
                 TileData tiledata = y.GetComponent <TileData>();
                 tiledata.setMap(this);
                 if (data.tileOn == null)
                 {
                     data.tileOn = y;
                 }
                 else
                 {
                     if (Vector3.Distance(x.transform.position, data.tileOn.transform.position) > Vector3.Distance(x.transform.position, y.transform.position))
                     {
                         data.tileOn = y;
                     }
                 }
             }
             data.tileOn.GetComponent <TileData>().entityOn = x;
         }
     }
     foreach (GameObject x in enemies)
     {
         //Logic for if players are dead or not recruited
         //Set player tile on
         if (x.activeInHierarchy)
         {
             entityData data = x.GetComponent <entityData>();
             foreach (GameObject y in tileMap)
             {
                 TileData tiledata = y.GetComponent <TileData>();
                 tiledata.setMap(this);
                 if (data.tileOn == null)
                 {
                     data.tileOn = y;
                 }
                 else
                 {
                     if (Vector3.Distance(x.transform.position, data.tileOn.transform.position) > Vector3.Distance(x.transform.position, y.transform.position))
                     {
                         data.tileOn = y;
                     }
                 }
             }
             data.tileOn.GetComponent <TileData>().entityOn = x;
         }
     }
 }
Exemple #12
0
    public void SetHealthOfEntity(string _entityName, float _newHealth)
    {
        int playerIndex = DoesEntityExist(_entityName);

        newData                 = entityList[playerIndex];
        newData.health          = _newHealth;
        entityList[playerIndex] = newData;

        if (onHealthReplenish != null)
        {
            onHealthReplenish(this, EventArgs.Empty);
        }
    }
Exemple #13
0
    void FindRangeAttack(GameObject player)
    {
        entityData data = player.GetComponent <entityData>();

        if (currentPlayerData.attackRange == 1)
        {
            rangebfsAttackM(currentPlayerData.minAttackRange, currentPlayerData.attackRange, data.tileOn);
        }
        else
        {
            rangebfsAttack(currentPlayerData.minAttackRange, currentPlayerData.attackRange, data.tileOn);
        }
        inEnemyRange = false;
    }
Exemple #14
0
    public EntityContainer(Entity entity, byte[] serialData) : this(entity)
    {
        Dictionary <entityData, ChildEntityData> cd = MessagePackSerializer.Deserialize <Dictionary <entityData, ChildEntityData> >(serialData);

        foreach (KeyValuePair <entityData, ChildEntityData> pair in cd)
        {
            entityData      ed  = pair.Key;
            ChildEntityData ced = pair.Value;

            // we manually call this because we store position in relative coords (raw vec2), so we don't want to convert to fixed
            // we basically discard the position and rotation of the entityData when it's parented
            var ne = new Entity(entity.Position + ced.relativePosition, entity.Rotation + ced.relativeRotation, ed.components);

            AddChild(ne, ced.inheritRotation, ced.inheritPosition);
        }
    }
Exemple #15
0
    public void RestoreAllStatsInstant()
    {
        int bossIndex   = DoesEntityExist("Boss");
        int playerIndex = DoesEntityExist("Player");

        newData               = entityList[bossIndex];
        newData.health        = newData.maxHealth;
        entityList[bossIndex] = newData;

        newData                 = entityList[playerIndex];
        newData.health          = newData.maxHealth;
        entityList[playerIndex] = newData;

        if (onHealthReplenish != null)
        {
            onHealthReplenish(this, EventArgs.Empty);
        }
    }
Exemple #16
0
 public RoundController.roundStateEnum playerTurnAttack(GameObject player)
 {
     action = true;
     if (selectedTile)
     {
         GameObject enemy      = tileClicked.GetComponent <TileData>().entityOn;
         entityData playerData = player.GetComponent <entityData>();
         entityData enemyData  = enemy.GetComponent <entityData>();
         if (dice.TwentyDice() + playerData.attackMod >= enemyData.armorClass)
         {
             //Hit
             Debug.Log("Hit!");
             Debug.Log("Current Enemy Health : " + enemyData.currentHealth);
             for (int i = 0; i < playerData.numDice; i++)
             {
                 enemyData.currentHealth -= dice.diceRoll(playerData.attackDice);
             }
             enemyData.currentHealth -= playerData.attackMod;
             Debug.Log("New Enemy Health : " + enemyData.currentHealth);
         }
         else
         {
             //Miss
             Debug.Log("Miss");
         }
         if (enemyData.currentHealth <= 0)
         {
             enemy.SetActive(false);
         }
         resetMap();
         roundController.playerRound = RoundController.playerStates.playerBase;
         playerUI.SetActive(true);
         resolveHealthUI();
     }
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         resetMap();
         roundController.playerRound = RoundController.playerStates.playerBase;
         playerUI.SetActive(true);
     }
     return(RoundController.roundStateEnum.CharacterTurn);
 }
Exemple #17
0
    public bool EnemyInRange(GameObject player)
    {
        entityData data = player.GetComponent <entityData>();

        if (data.attackRange == 1)
        {
            foreach (GameObject x in players)
            {
                if (Vector3.Distance(player.transform.position, x.transform.position) < 1.5f && x.activeInHierarchy)
                {
                    return(true);
                }
            }
            return(false);
        }
        else
        {
            return(false);
        }
    }
Exemple #18
0
    /* @brief This function serves as a way to remove health from an entity at the given string key (name).
     *        Once the entity is found, remove the amount of health according to the argument passed.
     * @param The string key (name) to lookup within the entity list.
     * @param The amount of health to deplete from the entity.
     */
    public void DeminishHealthOffEntity(string _entityName, float _amountToDeminish)
    {
        // The index of the entity is stored because it is used multiple times throughout the function.
        // Rather than doign the loop each time, just store it the first and only time.
        int entityIndex = DoesEntityExist(_entityName);

        // If the entityIndex is the error value returned, no reason to continue the function.
        if (entityIndex == ENTITY_INDEX_OUT_OF_RANGE)
        {
            return;
        }

        restoreInProcess = false;

        // See the last two lines of commented code in this function.
        newData = entityList[entityIndex];

        // If the entity already has zero health, don't continue the function.
        if (entityList[entityIndex].health <= 0f)
        {
            newData.health          = 0;
            entityList[entityIndex] = newData;

            return;
        }

        // Due to C# poor design in handling struct properties, I cant just assign an individual member of the entityData struct
        // for the given entity at the index. Instead I had to assign an entire struct... Please modifiy this if there is a work around.
        newData.health -= _amountToDeminish;
        if (newData.health <= 0f)
        {
            newData.health = 0f;
        }

        entityList[entityIndex] = newData;

        if (onDamageTaken != null)
        {
            onDamageTaken(this, EventArgs.Empty);
        }
    }
Exemple #19
0
    public void RestoreStatsOfEntity(string _entityName)
    {
        int entityIndex = DoesEntityExist(_entityName);

        newData = entityList[entityIndex];

        if (entityList[entityIndex].name != "Player")
        {
            newData.stamina = newData.maxStamina;
        }

        if (entityList[entityIndex].health != entityList[entityIndex].maxHealth)
        {
            newData.health += newData.speedOfHealthRegain;
        }
        else
        {
            newData.health = newData.maxHealth;
        }

        entityList[entityIndex] = newData;
    }
Exemple #20
0
    public RoundController.roundStateEnum enemyTurn(GameObject player)
    {
        if (!initialRun)
        {
            FindRange(player);
            roundController.enemyWait(RoundController.roundStateEnum.CharacterTurn);
            initialRun = true;
            return(RoundController.roundStateEnum.EnemyPause);
        }
        else
        {
            bool inRange = EnemyInRange(player);
            if (inRange)
            {
                if (action)
                {
                    return(RoundController.roundStateEnum.CharacterEnd);
                }
                else
                {
                    //Do Action
                    Debug.Log("Attack!");
                    GameObject attackedPlayer = players[0];
                    foreach (GameObject x in players)
                    {
                        if (Vector3.Distance(x.transform.position, player.transform.position) < 1.5f && x.activeInHierarchy)
                        {
                            attackedPlayer = x;
                        }
                    }
                    entityData playerData = player.GetComponent <entityData>();
                    entityData enemyData  = attackedPlayer.GetComponent <entityData>();
                    if (dice.TwentyDice() + playerData.attackMod >= enemyData.armorClass)
                    {
                        //Hit
                        Debug.Log("Hit!");
                        Debug.Log("Current Enemy Health : " + enemyData.currentHealth);
                        for (int i = 0; i < playerData.numDice; i++)
                        {
                            enemyData.currentHealth -= dice.diceRoll(playerData.attackDice);
                        }
                        enemyData.currentHealth -= playerData.attackMod;
                        Debug.Log("New Enemy Health : " + enemyData.currentHealth);
                    }
                    else
                    {
                        //Miss
                        Debug.Log("Miss");
                    }
                    if (enemyData.currentHealth <= 0)
                    {
                        attackedPlayer.SetActive(false);
                    }
                    resetMap();
                    resolveHealthUI();
                    return(RoundController.roundStateEnum.CharacterEnd);
                }
            }
            else
            {
                if (!moved)
                {
                    Debug.Log("Moving Enemy");
                    GameObject closestPlayer = GameObject.FindGameObjectWithTag("Player");
                    foreach (GameObject x in players)
                    {
                        if (Vector3.Distance(x.transform.position, player.transform.position) < Vector3.Distance(player.transform.position, closestPlayer.transform.position) && x.activeInHierarchy)
                        {
                            closestPlayer = x;
                        }
                    }
                    shortestPath = new Queue <GameObject>();
                    // Find shortest path to inrange tile

                    /*
                     * moveCharacter(player, closestPlayer.GetComponent<entityData>().tileOn.GetComponent<TileData>().tileWest.GetComponent<TileData>().tileNorth);
                     * moveCharacter(player, closestPlayer.GetComponent<entityData>().tileOn.GetComponent<TileData>().tileWest);
                     * moveCharacter(player, closestPlayer.GetComponent<entityData>().tileOn.GetComponent<TileData>().tileWest.GetComponent<TileData>().tileSouth);
                     * moveCharacter(player, closestPlayer.GetComponent<entityData>().tileOn.GetComponent<TileData>().tileNorth);
                     * moveCharacter(player, closestPlayer.GetComponent<entityData>().tileOn.GetComponent<TileData>().tileEast.GetComponent<TileData>().tileNorth);
                     * moveCharacter(player, closestPlayer.GetComponent<entityData>().tileOn.GetComponent<TileData>().tileEast);
                     * moveCharacter(player, closestPlayer.GetComponent<entityData>().tileOn.GetComponent<TileData>().tileEast.GetComponent<TileData>().tileSouth);
                     * moveCharacter(player, closestPlayer.GetComponent<entityData>().tileOn.GetComponent<TileData>().tileSouth);
                     */
                    moveCharacter(player, closestPlayer.GetComponent <entityData>().tileOn);
                    return(RoundController.roundStateEnum.EnemyMovement);
                }
                else
                {
                    return(RoundController.roundStateEnum.CharacterEnd);
                }
            }
        }
    }
Exemple #21
0
    private void HandleZeroHealthEntity(int _entityIndex)
    {
        newData = entityList[_entityIndex];
        //newData.health = newData.maxHealth;
        newData.lives--;
        entityList[_entityIndex] = newData;

        // Still lives available.
        if (entityList[_entityIndex].lives > 0)
        {
            // Handle player losing a life.
            // if(entityList[_entityIndex].name == "Player")
            if (entityList[_entityIndex].name == "Player")
            {
                if (onPlayerLifeLost != null)
                {
                    onPlayerLifeLost(this, EventArgs.Empty);
                }

                PhaseReset(_entityIndex);
            }
            else // Handle boss losing a life (phase).
            {
                if (onBossPhaseChange != null)
                {
                    onBossPhaseChange(this, EventArgs.Empty);
                }

                NextPhase(_entityIndex);

                entityList[_entityIndex].entityObject.GetComponent <BossBrain>().m_bossPhaseList.RemoveAt(0);
            }
        }
        else // No lives available, end of game.
        {
            if (entityList[_entityIndex].name == "Player") // Handle player losing final life.
            {
                // Remove the final life indicator.
                if (onPlayerLifeLost != null)
                {
                    onPlayerLifeLost(this, EventArgs.Empty);
                }

                GameOverLose();
            }
            else // Handle boss losing final life.
            {
                // Remove the final phase indicator.
                if (onBossPhaseChange != null)
                {
                    onBossPhaseChange(this, EventArgs.Empty);
                }
                entityList[_entityIndex].entityObject.GetComponent <BossBrain>().m_bossPhaseList.RemoveAt(0);

                GameOverWin();
            }

            newData.lives            = 0;
            entityList[_entityIndex] = newData;
        }
    }