Beispiel #1
0
    /* This method will return the species ID of whatever the passed creature can evolve into*/

    public static void CheckEvolve(Simple_Creature c)
    {
        string path = "Assets/Resources/Creatures.json";
        string data = File.ReadAllText(path);

        //  TextAsset file = (TextAsset)Resources.Load("Creatures");
        Debug.Log(data);
        //gets the table

        Creature [] j = new Creature[3];
        j[0] = new Creature(0, "egg");
        j[1] = new Creature(1, "nerd");
        j[2] = new Creature(2, "test");

        string jArray = JsonHelper.ToJson(j);

        Debug.Log(jArray);

        j = JsonHelper.FromJson <Creature>(data);
        Debug.Log(j[c.species_id].evolution.Length);
        Evolution[] possibles = j[c.species_id].evolution;

        //Check through evolutions to see if it satisfys any
        int toEvolve = Evolution.getEvolution(possibles, c);

        //If evolution found
        if (toEvolve != -1)
        {
            c.species_id = j[toEvolve].id;
            c.species    = j[toEvolve].species;
        }
    }
Beispiel #2
0
    public int luc;   // Luck



    public static int getEvolution(Evolution [] e, Simple_Creature c)
    {
        int[] match = new int[e.Length];

        for (int i = 0; i < e.Length; i++)
        {
            Evolution evo = e[i];
            if ((c.age >= evo.age) && (c.pow_stat >= evo.pow) &&
                (c.run_stat >= evo.run) && (c.swm_stat >= evo.swm) &&
                (c.fly_stat >= evo.fly) && (c.sta_stat >= evo.sta) &&
                (c.int_stat >= evo.intel) && (c.luc_stat >= evo.luc)
                )
            {
                match[i] = 1;
            }

            //Now pick a match
        }
        for (int i = 0; i < match.Length; i++)
        {
            if (match[i] == 1)
            {
                return(e[i].id);
            }
        }

        return(-1);
    }
 public void AddCreature(Simple_Creature c)
 {
     for (int i = 0; i < stable.Length; i++)
     {
         if (stable[i] == null)
         {
             stable[i] = c; break;
         }
     }
 }