Пример #1
0
    // unassign and reset treasure being opened
    void OpenTreasure(CastleObstacle treasure)
    {
        // peel off relevant treasure settings
        string treasureName       = treasure.obstacleName;
        int    treasureTrickiness = treasure.obstacleValue;

        Debug.Log(string.Format("Rogue {0} is struggling to open a {1}", this.name, treasureName));

        // roll for a zero-to-one plus luck chance
        float rollPlusLuck = Random.Range(0f, 1f + luck);

        // be sly or lucky enough to open
        if ((this.thievery >= treasureTrickiness) || (rollPlusLuck > (0.85f + (treasureTrickiness / 100))))
        {
            // store loot and skills gained
            runPoints["treasure"] += treasureTrickiness;
            runPoints["luck"]     += rollPlusLuck;

            Debug.Log(string.Format("Pried it! The {0} gold ups rogue treasure to {1}", treasureTrickiness, runPoints["treasure"]));
        }
        else
        {
            Debug.Log("Failed to crack it open. Not yet thieverious enough for its secrets.");
        }
    }
Пример #2
0
    /* Adventuring through generated obstacles */

    void FightEnemy(CastleObstacle enemy)
    {
        // reference relevant values from enemy
        string enemyName   = enemy.obstacleName;
        string enemyType   = enemy.obstacleType;
        int    enemyHealth = enemy.obstacleValue;
        int    enemyAttack = enemy.obstacleValue;

        Debug.Log(string.Format("Rogue {0} is taking up arms against a {1}", this.name, enemyName));

        // roll for a zero-to-one plus luck chance for immediate evasion
        float rollPlusLuck = Random.Range(0f, 1f + this.luck);

        // attempt to run away from non-boss enemy
        //  ?- also try to evade "miniBoss"
        if (enemyType == "enemy" && rollPlusLuck > 0.8f)
        {
            Debug.Log(string.Format("{0} ran away from a {1}", this.name, enemyName));

            // store skills gained
            runPoints["enemy"] += (0.5f * enemyAttack);
            runPoints["luck"]  += rollPlusLuck;

            return;
        }

        // play through encounter taking turns fighting and defending against the enemy
        CycleAttackDefend(enemyName, enemyType, enemyAttack, enemyHealth);
    }
Пример #3
0
    /* Castle interaction */

    // TODO: make obstacles GameObjects to combine features instead of balancing dictionaries and lists
    public bool FeedObstacle(CastleObstacle obstacle)
    {
        // TODO: just assign the obstacle, even let it communicate back to call the right methods in rogue

        // assign and react to the obstacle depending on its type
        switch (obstacle.obstacleType)
        {
        case "hazard":
            EvadeHazard(obstacle);
            break;

        case "enemy":
        case "boss":
        case "miniBoss":
        case "finalBoss":
            FightEnemy(obstacle);
            break;

        case "treasure":
            OpenTreasure(obstacle);
            break;

        default:
            return(false);
        }

        return(true);
    }
Пример #4
0
    // add castle obstacle to level list a bounded random number of times
    void AddRandomTimes(List <CastleObstacle> levelList, string obstacleType, string obstacleName, int minTimes, int maxTimes)
    {
        // check if entry exists for obstacle matching the given type and name
        if (!obstacles.ContainsKey(obstacleType) || !obstacles[obstacleType].ContainsKey(obstacleName))
        {
            return;
        }

        // locate the obstacle data and store relevant info
        int obstacleStat = obstacles[obstacleType][obstacleName];

        // add obstacle a bounded random number of times
        int times = Random.Range(minTimes, maxTimes + 1);

        // back out if didn't roll a positive integer
        if (times < 1)
        {
            return;
        }

        // spawn and add obstacle as many times as rng rolled
        for (int i = 0; i < times; i++)
        {
            // spawn the obstacle within this castle
            CastleObstacle obstacle = Instantiate(castleObstacle, this.transform).GetComponent <CastleObstacle> ();

            // pass along the basic obstacle attributes
            obstacle.obstacleName  = obstacleName;
            obstacle.obstacleType  = obstacleType;
            obstacle.obstacleValue = obstacleStat;

            // append the new obstacle to the level
            levelList.Add(obstacle);
        }
    }
Пример #5
0
 // iterate through one level's obstacle behaviors and randomly swap obstacles
 // modified from: https://stackoverflow.com/questions/273313/randomize-a-listt
 List <CastleObstacle> ShuffleList(List <CastleObstacle> l)
 {
     for (int i = l.Count - 1; i > 1; i--)
     {
         int            random_i = Random.Range(0, i + 1);
         CastleObstacle value    = l[random_i];
         l [random_i] = l [i];
         l [i]        = value;
     }
     return(l);
 }
Пример #6
0
    // advance current position one obstacle and return traversed obstacle key
    public CastleObstacle RunObstacle(bool advanceLevel = false)
    {
        // catch obstacle index beyond current level obstacles
        if (currentObstacle >= levelObstacles [currentLevel].Count)
        {
            Debug.Log("Reached the end of the obstacles list for level " + currentLevel);
            // optionally update the level index
            if (advanceLevel)
            {
                currentLevel++;
            }
            return(null);
        }

        // store the current obstacle reference and advance the obstacle pointer
        CastleObstacle currentObstacleBehavior = levelObstacles[currentLevel][currentObstacle];

        currentObstacle++;

        return(currentObstacleBehavior);
    }
Пример #7
0
    // unassign and reset hazard facing rogue
    void EvadeHazard(CastleObstacle hazard)
    {
        // peel off relevant hazard values
        string hazardName   = hazard.obstacleName;
        int    hazardAttack = hazard.obstacleValue;

        Debug.Log(string.Format("Rogue {0} is craftily evading a {1}", this.name, hazardName));

        // roll for a zero-to-one plus luck chance
        float rollPlusLuck = Random.Range(0f, 1f + this.luck);

        // be agile or lucky enough to evade
        if ((agility > hazardAttack) || (rollPlusLuck > (0.3f + (hazardAttack / 100))))
        {
            Debug.Log(string.Format("Smoothly sidestepped it! Health still {0}", this.health));
            return;
        }
        else
        {
            // determine hazard damage
            int hazardAttackStrength = Mathf.RoundToInt(
                hazardAttack - rollPlusLuck * (defense - armorEquipment.GetComponent <Armor> ().defense)
                );
            // decrease health by calculated damage
            this.health -= Mathf.Max(0, hazardAttackStrength);
            Debug.Log(string.Format("Stumbled into the {0} - health fell to {1}", hazardName, this.health));
        }

        if (this.health <= 0)
        {
            Die(hazardName, hazard.obstacleType);
            return;
        }

        // store skills gained
        runPoints["hazard"] += hazardAttack;
    }