Example #1
0
 public CompoundLevelData(ElementRarityClass rarityClass, float resistance, float attack, float weight, int price, int min, int max)
 {
     RarityClass       = rarityClass;
     Resistance        = resistance;
     Attack            = attack;
     PercentOfCompound = weight;
     Price             = price;
     Min = min;
     Max = max;
 }
Example #2
0
    private List <LifeElementModel> CreateCompoundElements(CompoundJSON compound, int level, ElementRarityClass rarityClass)
    {
        List <LifeElementModel> output = new List <LifeElementModel>();

        CompoundLevelData armorLevelData = _levelConfig[level][rarityClass];
        int   numberOfElements           = RandomUtil.FromRangeInt(armorLevelData.Min, armorLevelData.Max);
        float amountNeeded = Mathf.Ceil(armorLevelData.PercentOfCompound * armorLevelData.Price);
        List <WeightedValue> probabilities = GameModel.Copy(_elementsProbabilities[rarityClass]);
        WeightedValue        weightedValue;
        int index = 0;

        for (int i = 0; i < numberOfElements; i++)
        {
            weightedValue = RandomUtil.GetWeightedValueObject(probabilities);
            index         = (int)weightedValue.Value;
            output.Add(new LifeElementModel(index, _elements[index].Symbol, 0, 0));
            probabilities.Remove(weightedValue);
            foreach (WeightedValue item in probabilities)
            {
                item.Weight = 1f / probabilities.Count;
            }
        }
        //only exception is if Hydrogen is selected, we'll add another abundand element to avoid big numbers of Hydrogen
        if (rarityClass == ElementRarityClass.Abundant && index == 1 && level > 2)
        {
            weightedValue = RandomUtil.GetWeightedValueObject(probabilities);
            index         = (int)weightedValue.Value;
            output.Add(new LifeElementModel(index, _elements[index].Symbol, 0, 0));
            numberOfElements++;
        }


        float amountCollected = 0;
        int   fullElements    = 0;
        bool  isFull          = false;

        while (!isFull)
        {
            fullElements = 0;
            for (int i = 0; i < numberOfElements; i++)
            {
                if (_elements[output[i].Index].Weight + amountCollected > amountNeeded)
                {
                    fullElements++;
                }
                else
                {
                    output[i].MaxAmount++;
                    amountCollected += _elements[output[i].Index].Weight;
                }
            }
            if (fullElements == numberOfElements)
            {
                isFull = true;
            }
        }

        compound.MolecularMass += amountCollected;

        return(output);
    }