Beispiel #1
0
    //OLD STUFF BELOW
    //call to convert and generate new config
    public void ConvertOldConfigToNewFormat()
    {
        TextAsset configFile = Resources.Load <TextAsset>("Configs/Recipes-Common176");

        Items = JsonConvert.DeserializeObject <CompoundGenerator>(configFile.text).Items;

        CompoundJSON       compoundJSON;
        CompoundDefinition compoundDefinition;

        List <CompoundJSON> jsons = new List <CompoundJSON>();

        for (int i = 0; i < Items.Count; i++)
        {
            compoundDefinition = Items[i];
            compoundJSON       = new CompoundJSON
            {
                Name          = compoundDefinition.Name,
                Type          = (CompoundType)RandomUtil.FromRangeInt(0, 2),
                Formula       = compoundDefinition.Formula,
                MolecularMass = compoundDefinition.MolecularMass
            };
            compoundJSON.Elements = SplitFormula(compoundJSON.Formula);
            if (i < _buildings.Count)
            {
                compoundJSON.Effects = _buildings[i].Effects;
            }

            jsons.Add(compoundJSON);
        }

        Dictionary <string, int> eleDict = new Dictionary <string, int>();

        for (int i = 0; i < jsons.Count; i++)
        {
            for (int j = 0; j < jsons[i].Elements.Count; j++)
            {
                if (eleDict.ContainsKey(jsons[i].Elements[j].Symbol))
                {
                    eleDict[jsons[i].Elements[j].Symbol] += 1;
                }
                else
                {
                    eleDict.Add(jsons[i].Elements[j].Symbol, 1);
                }
            }
        }

        //Debug.Log( JsonConvert.SerializeObject( eleDict ) );

        File.WriteAllText(
            Application.persistentDataPath + "CompoundConfig.json",
            JsonConvert.SerializeObject(jsons)
            );

        Debug.Log("DOOOOOOOOOOOOONNNNNNNNNNNEEEEEEEEEEE");
    }
Beispiel #2
0
    internal void New(int type)
    {
        _selectedStar = GameModel.Copy(_starsConfig.Stars[type]);
        ConvertUnitsToSI();
        _selectedStar.Name = "Star" + _galaxy.CreatedStars;
        _selectedStar._AvailableElements = GenerateStarElements(_galaxy.CreatedStars + 1);
        _selectedStar.PlanetsCount       = RandomUtil.FromRangeInt(_starsConfig.MinPlanets, _starsConfig.MaxPlanets);
        _selectedStar.PlanetsCount       = 1;
        _stars.Add(_selectedStar);

        _galaxy.CreatedStars++;
        GameModel.Set <StarModel>(_selectedStar);
    }
Beispiel #3
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);
    }