Example #1
0
    //Test method : pick one among a selection of player stats.
    //Parameters : a list of character stats (possibly a fake one for a numeric value)
    //Return : one of the input stats. Each stat has a chance of being chosen that is proportionate to its value
    public Character.Stat Test(List <Character.Stat> stats)
    {
        string str = "testing : ";

        foreach (Character.Stat s in stats)
        {
            str += "\n - " + s.owner + "'s BIG = " + s.value;
        }
        //	Debug.Log(str);


        float ran = Random.value * stats.Sum(s => s.value);         //Random value between 0 and sum of all input stat values

        float interval = 0;

        Character.Stat chosen = new Character.Stat();

        foreach (Character.Stat s in stats)
        {
            interval += s.value;
            if (ran < interval)
            {
                chosen = s;
                break;
            }
        }

        return(chosen);
    }
Example #2
0
    protected void Fight()        //Play one round of fight
    //Test all fighters' BIG, result is the one who lands a blow
    {
        Character.Stat enemyBig = new Character.Stat(null, Character.StatType.BIG, fightState.enemyBig); //Placeholder stat for enemy's BIG

        List <Character.Stat> fighters = new List <Character.Stat>();                                    //Make a list of all the fighters

        foreach (Character character in charactersInvolved)
        {
            fighters.Add(character.big);                                                         //Add all characters
        }
        for (int i = 0; i < fightState.amountOfEnemies; i++)
        {
            fighters.Add(enemyBig);                           //Add all enemies
        }
        Character attacker = sm.Test(fighters).owner;         //Test values against each other, owner of the winning stat becomes attacker

        //If enemy is hit (attacker is a character)
        if (attacker != null)
        {
            ui.Log(attacker.name + " defeated an enemy !");
            fightState.amountOfEnemies--;
        }

        //If character is hit (attacker is null, i.e. an enemy)
        else
        {
            Character target = charactersInvolved[Random.Range(0, charactersInvolved.Count)];    //Pick random character
            float     damage = Random.Range(fightState.minDamage, fightState.maxDamage);         //Generate damage

            //Handle log messages
            if (target.hp > damage && target.hp < Random.value)                                //Character takes damage and runs away
            {
                ui.Log(target.name + " took " + sm.Intify(damage) + " damage and ran away !"); //Chance to run away after being hit = % hp missing
                target.ExitStopover();
            }

            else
            {
                ui.Log(target.name + " took " + sm.Intify(damage) + " damage !"); //Character takes damage
            }
            target.Damage(damage);                                                //Deduct character hp
        }

        //Check if one side has been defeated
        if (fightState.amountOfEnemies == 0)
        {
            Victory();
        }
        else if (charactersInvolved.Count == 0)
        {
            Defeat();
        }
    }
Example #3
0
    //--------------------
    // EVENTS
    //--------------------

    protected override void OnEvent()
    {
        // INTRODUCTION
        if (round == 1)
        {
            ui.Log(charactersInvolved[0].name + " sees " + fightState.amountOfEnemies + " people");
            ui.Log("Their motives are yet unclear.");
            ui.Log("...");
        }

        // DECISION
        if (round == 4)
        {
            List <Character.Stat> characterStats = new List <Character.Stat> ();
            foreach (Character character in charactersInvolved)
            {
                characterStats.Add(character.big);
                characterStats.Add(character.chill);
                characterStats.Add(character.sharp);
                characterStats.Add(character.smooth);
            }
            pick = sm.Test(characterStats);
        }

        // BIG
        if (pick.type == Character.StatType.BIG)
        {
            if (round == 4)
            {
                ui.Log(pick.owner.name + " loses their cool and attacks !");
            }
            if (round > 4)
            {
                Fight();
            }
        }

        // CHILL
        if (pick.type == Character.StatType.CHILL)
        {
            if (round == 4)
            {
                ui.Log(pick.owner.name + " makes friends with the locals.");
                ui.Log("They offer to share some of their food.");
            }
            if (round == 5)
            {
                food.AddFood(Random.Range(minFoodGift, maxFoodGift + 1));
            }
            if (round == 6)
            {
                Evacuate();
            }
        }

        // SHARP
        if (pick.type == Character.StatType.SHARP)
        {
            if (round == 4)
            {
                int foodShared = Random.Range(minFoodShared, maxFoodShared);
                if (food.EnoughFood(foodShared))
                {
                    ui.Log(pick.owner.name + " gives them " + foodShared + " food. They offer to heal your crew.");
                    food.RemoveFood(foodShared);
                    foreach (Character c in charactersInvolved)
                    {
                        if (Random.value < healChance)
                        {
                            c.AddHP(Random.Range(minHeal, maxHeal));
                        }
                    }
                    Evacuate();
                }

                else if (food.EnoughFood(1))
                {
                    ui.Log(pick.owner.name + " shares the few provisions you have with them. They offer to heal one of your passengers.");
                    food.RemoveFood(food.food);
                    charactersInvolved[Random.Range(0, charactersInvolved.Count - 1)].AddHP(Random.Range(minHeal, maxHeal) * healPercentIfInsufficientFood);
                    Evacuate();
                }

                else
                {
                    ui.Log("They ask you for food. " + pick.owner.name + " politely declines and leaves quickly.");
                    Evacuate();
                }
            }
        }

        // SMOOTH
        if (pick.type == Character.StatType.SMOOTH)
        {
            if (round == 4)
            {
                ui.Log(pick.owner.name + " convinces one of them to join your crew !");
                characterManager.Add();
                Evacuate();
            }
        }
    }
Example #4
0
 //TODO: move to character or game manager
 private void LevelUp(Goblin gob, Character.Stat stat)
 {
     stat.LevelUp();
 }
Example #5
0
 //Out : the degree of success for the test (a random value between 0 and the value of the chosen stat)
 public Character.Stat Test(List <Character.Stat> stats, out float bonus)
 {
     Character.Stat result = Test(stats);
     bonus = Random.Range(0, result.value);
     return(result);
 }