Example #1
0
    void RandomType()
    {
        int typeNum = rnd.Next(0, 5);

        //randomly set element type if one was not set
        switch (typeNum)
        {
        case 0:
            elementType = ElementEnum.Elements.Ash;
            break;

        case 1:
            elementType = ElementEnum.Elements.Water;
            break;

        case 2:
            elementType = ElementEnum.Elements.Grass;
            break;

        case 3:
            elementType = ElementEnum.Elements.Fire;
            break;

        case 4:
            elementType = ElementEnum.Elements.Cheese;
            break;
        }
    }
Example #2
0
 //Set the new element type for player if new element is picked up
 public void RpcSetType(ElementEnum.Elements element)
 {
     //cheese is temporary so store previous type
     if (element == ElementEnum.Elements.Cheese)
     {
         previousElementType = elementType;
     }
     //change material
     //Debug.Log(this+" Current Type: " + elementType.ToString());
     elementType = element;
     ChangeMaterial();
     //Debug.Log(this+" New Type: " + elementType.ToString());
 }
Example #3
0
    public void CmdSpawnPotions(ElementStruct p)
    {
        ElementEnum.Elements type = (ElementEnum.Elements)p.elementType;
        GameObject           temp = null;

        switch (type)
        {
        case ElementEnum.Elements.Ash:
            potionAsh.transform.position = p.position;
            potionAsh.GetComponent <Element>().elementType = type;
            temp = Instantiate(potionAsh);
            temp.gameObject.name  = "Ash";
            temp.transform.parent = null;
            break;

        case ElementEnum.Elements.Fire:
            potionFire.transform.position = p.position;
            potionFire.GetComponent <Element>().elementType = type;
            temp = Instantiate(potionFire);
            temp.gameObject.name  = "Fire";
            temp.transform.parent = null;
            break;

        case ElementEnum.Elements.Grass:
            potionGrass.transform.position = p.position;
            potionGrass.GetComponent <Element>().elementType = type;
            temp = Instantiate(potionGrass);
            temp.gameObject.name  = "Grass";
            temp.transform.parent = null;
            break;

        case ElementEnum.Elements.Water:
            potionWater.transform.position = p.position;
            potionWater.GetComponent <Element>().elementType = type;
            temp = Instantiate(potionWater);
            temp.gameObject.name = "Water";
            break;

        case ElementEnum.Elements.Cheese:
            potionCheese.transform.position = p.position;
            potionCheese.GetComponent <Element>().elementType = type;
            temp = Instantiate(potionCheese);
            temp.gameObject.name  = "Cheese";
            temp.transform.parent = null;
            break;
        }
        if (temp != null)
        {
            NetworkServer.Spawn(temp);
        }
    }
Example #4
0
    //set the material and element type
    public int ChangeMaterial()
    {
        int elementIndex = 0;

        if (currentElementsToSpawn < minNumOfElementsToSpawn && !spawnedEqualAmount[0].Item2)
        {
            elementIndex = 0;
        }
        else if (currentElementsToSpawn < minNumOfElementsToSpawn && !spawnedEqualAmount[1].Item2)
        {
            elementIndex = 1;
        }
        else if (currentElementsToSpawn < minNumOfElementsToSpawn && !spawnedEqualAmount[2].Item2)
        {
            elementIndex = 2;
        }
        else if (currentElementsToSpawn < minNumOfElementsToSpawn)
        {
            elementIndex = 3;
        }
        else if (spawnedEqualAmount[0].Item2 && spawnedEqualAmount[1].Item2 && spawnedEqualAmount[2].Item2)
        {
            //randomly choose element type
            //range 0-3
            elementIndex = rnd.Next(0, 4000);
            //for fire
            if (elementIndex <= 1000)
            {
                elementIndex = 0;
            }
            //for grass
            else if (elementIndex <= 2000)
            {
                elementIndex = 1;
            }
            //for water
            else if (elementIndex <= 3000)
            {
                elementIndex = 2;
            }
            //for cheese, based on the way the code is written, this is needed because cheese only has a chance of appearing in a round
            //once or not at all to keep it fair
            else if (elementIndex <= 4000)
            {
                elementIndex = 3;
            }
        }
        ElementEnum.Elements type = ElementEnum.Elements.None;

        //set the material according to the element type chosen
        switch (elementIndex)
        {
        //case 0:
        //   // potion.GetComponent<Renderer>().material = elements[0];
        //   // potion.GetComponent<Element>().elementType = ElementEnum.Elements.Ash;
        //    elementsSpawned++;
        //    type = ElementEnum.Elements.Ash;
        //    break;
        case 0:
            //potion.GetComponent<Renderer>().material = elements[1];
            //potion.GetComponent<Element>().elementType = ElementEnum.Elements.Fire;
            type = ElementEnum.Elements.Fire;
            if (currentElementsToSpawn < minNumOfElementsToSpawn)
            {
                currentElementsToSpawn++;
                if (currentElementsToSpawn >= minNumOfElementsToSpawn)
                {
                    currentElementsToSpawn = 0;
                    spawnedEqualAmount[0]  = new Tuple <string, bool>("Fire", true);
                }
            }
            elementsSpawned++;
            break;

        case 1:
            // potion.GetComponent<Renderer>().material = elements[2];
            //potion.GetComponent<Element>().elementType = ElementEnum.Elements.Grass;
            type = ElementEnum.Elements.Grass;
            if (currentElementsToSpawn < minNumOfElementsToSpawn)
            {
                currentElementsToSpawn++;
                if (currentElementsToSpawn >= minNumOfElementsToSpawn)
                {
                    currentElementsToSpawn = 0;
                    spawnedEqualAmount[1]  = new Tuple <string, bool>("Grass", true);
                }
            }
            elementsSpawned++;
            break;

        case 2:
            //potion.GetComponent<Renderer>().material = elements[3];
            //potion.GetComponent<Element>().elementType = ElementEnum.Elements.Water;
            type = ElementEnum.Elements.Water;
            if (currentElementsToSpawn < minNumOfElementsToSpawn)
            {
                currentElementsToSpawn++;
                if (currentElementsToSpawn >= minNumOfElementsToSpawn)
                {
                    currentElementsToSpawn = 0;
                    spawnedEqualAmount[2]  = new Tuple <string, bool>("Water", true);
                }
            }
            elementsSpawned++;
            break;

        //only one cheese potion should occur if any
        case 3:
            if (!spawnedCheese)
            {
                //potion.GetComponent<Renderer>().material = elements[4];
                // potion.GetComponent<Element>().elementType = ElementEnum.Elements.Cheese;
                type = ElementEnum.Elements.Cheese;
                if (currentElementsToSpawn < 1)
                {
                    currentElementsToSpawn++;
                    if (currentElementsToSpawn >= 1)
                    {
                        currentElementsToSpawn = minNumOfElementsToSpawn + 1;
                    }
                }
                elementsSpawned++;
                spawnedCheese = true;
            }
            break;
        }

        return((int)type);
    }
Example #5
0
 public void CmdSetType(ElementEnum.Elements elements)
 {
     RpcSetType(elements);
 }