예제 #1
0
    internal void Setup(CompoundJSON compound)
    {
        disposables.Clear();

        _compound = compound;
        _compound._CanCraft.Subscribe(_ => SetState(_ ? 1 : 0)).AddTo(disposables);
        _compoundSelectMessage.Index  = _compound.Index;
        _compoundControlMessage.Index = _compound.Index;

        Name.SetProperty(_compound.Name);

        compoundIcon.Setup(_compound);

        for (int i = 0; i < ElementsGrid.childCount; i++)
        {
            if (i >= _compound.Elements.Count)
            {
                ElementsGrid.GetChild(i).GetComponent <CompoundElementAmountView>().Setup(null);
            }
            else
            {
                ElementsGrid.GetChild(i).GetComponent <CompoundElementAmountView>().Setup(_compound.Elements[i]);
            }
        }

        foreach (KeyValuePair <R, float> effect in _compound.Effects)
        {
            AddEffect(effect.Key, effect.Value);
        }
    }
예제 #2
0
    private void ApplyCompoundEffects(CompoundJSON compound, int sign = -1)
    {
        if (compound.Type == CompoundType.Armor)
        {
            foreach (KeyValuePair <R, float> item in compound.Effects)
            {
                if (item.Key == R.Temperature || item.Key == R.Pressure || item.Key == R.Humidity || item.Key == R.Radiation)
                {
                    _unitController.SelectedUnit.Resistance[item.Key].ChangePosition(PPMath.Round((sign * item.Value) / 100f));
                }
                else
                {
                    _unitController.SelectedUnit.Props[item.Key].Value += (int)item.Value * sign;
                }
            }

            _unitDefenseUpdateCommand.Execute(_unitController.SelectedUnit);
        }

        if (compound.Type == CompoundType.Weapon)
        {
            foreach (KeyValuePair <R, float> item in compound.Effects)
            {
                if (item.Key == R.Temperature || item.Key == R.Pressure || item.Key == R.Humidity || item.Key == R.Radiation)
                {
                    _unitController.SelectedUnit.Impact[item.Key].Value     += (int)(item.Value * sign);
                    _planetController.SelectedPlanet.Impact[item.Key].Value += (int)(item.Value * sign);
                }
                else
                {
                    _unitController.SelectedUnit.Props[item.Key].Delta += (int)item.Value * sign;
                }
            }
        }
    }
예제 #3
0
    private void CreateCompound(R effect, int level, bool isPositive, CompoundType compoundType = CompoundType.Armor)
    {
        float        sign     = isPositive ? 1 : -1;
        CompoundJSON compound = new CompoundJSON
        {
            Index = _indexer,
            Type  = compoundType,
            Name  = compoundType.ToString() + " #" + _indexer
        };

        if (compoundType == CompoundType.Weapon)
        {
            compound.Effects.Add(effect, level * sign);
            compound.Effects.Add(R.Attack, _levelConfig[level][ElementRarityClass.Abundant].Attack);
        }
        else
        {
            compound.Effects.Add(effect, _levelConfig[level][ElementRarityClass.Abundant].Resistance * sign);
        }

        compound.Elements.AddRange(CreateCompoundElements(compound, level, ElementRarityClass.Rare));
        compound.Elements.AddRange(CreateCompoundElements(compound, level, ElementRarityClass.Uncommon));
        compound.Elements.AddRange(CreateCompoundElements(compound, level, ElementRarityClass.Common));
        compound.Elements.AddRange(CreateCompoundElements(compound, level, ElementRarityClass.Abundant));

        foreach (LifeElementModel item in compound.Elements)
        {
            compound.Formula += item.Symbol + item.MaxAmount + " ";
        }

        CreateCompoundTexture(compound);

        _compounds.Add(compound);
        _indexer++;
    }
예제 #4
0
 internal void Setup(CompoundJSON compound, IntReactiveProperty amount)
 {
     disposables.Clear();
     Compound = compound;
     _controlMessage.Index = compound.Index;
     amount.Subscribe(_ => OnAmountChange(_)).AddTo(disposables);
     Icon.Setup(compound);
 }
예제 #5
0
 public override void OnDestroy()
 {
     base.OnDestroy();
     _compound = null;
     _compoundControlMessage = null;
     _compoundSelectMessage  = null;
     _buttonStream           = null;
     GameMessage.StopListen <CompoundSelectMessage>(OnCompoundSelected);
 }
예제 #6
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");
    }
예제 #7
0
    public void Setup(CompoundJSON compound)
    {
        _tooltipMessage.Text = compound.Name + "\n";
        foreach (KeyValuePair <R, float> effect in compound.Effects)
        {
            _tooltipMessage.Text += effect.Key + " " + effect.Value + "\n";
        }

        TextureImage.texture  = Resources.Load("CompoundTexture/" + compound.Index) as Texture2D;
        BackgoundImage.sprite = BackgroundSprites[(int)compound.Type];
        MaskImage.sprite      = MaskSprites[(int)compound.Type];
    }
예제 #8
0
 private void SetModel()
 {
     RemoveAllChildren(Container);
     for (int i = 0; i < _compoundConfig.Count; i++)
     {
         _compound = _compoundConfig[i];
         if (_compound.Type == _type)
         {
             GameObject go = Instantiate(CompoundUnlockPrefab, Container);
             go.GetComponent <CompoundView>().Setup(_compound);
         }
     }
 }
예제 #9
0
    private void Unequip()
    {
        if (_unitSlotCompoundIndex.Value != Int32.MaxValue)
        {
            _message.Index = _unitSlotCompoundIndex.Value;
            GameMessage.Send(_message);

            _compound = _compounds[_unitSlotCompoundIndex.Value];
            _unitSlotCompoundIndex.Value = Int32.MaxValue;

            ApplyCompoundEffects(_compound, -1);
        }
    }
예제 #10
0
    private void GenerateConsumableCompounds()
    {
        //load json exported from a spreadsheet
        TextAsset configFile = Resources.Load <TextAsset>("Configs/CompoundExcelConfig");

        _rawCompounds = JsonConvert.DeserializeObject <List <CompoundExcelJSON> >(configFile.text);

        for (int i = 0; i < _rawCompounds.Count; i++)
        {
            CompoundExcelJSON rawCompound = _rawCompounds[i];
            CompoundJSON      compound    = new CompoundJSON
            {
                Index         = _indexer,
                Type          = rawCompound.Type,
                Name          = rawCompound.Name,
                MolecularMass = rawCompound.MolecularMass
            };
            if (rawCompound.Effect != R.Default)
            {
                compound.Effects.Add(rawCompound.Effect, rawCompound.EffectDelta);
            }

            for (int j = 0; j < 5; j++)
            {
                string symbol = (string)GetPropValue(rawCompound, "E" + j);
                if (symbol != "-")
                {
                    compound.Elements.Add(
                        new LifeElementModel(
                            GetAtom(symbol).Index,
                            symbol,
                            0, (int)GetPropValue(rawCompound, "A" + j)));
                }
            }

            foreach (LifeElementModel item in compound.Elements)
            {
                compound.Formula += item.Symbol + item.MaxAmount + " ";
            }

            CreateCompoundTexture(compound);

            _compounds.Add(compound);
            _indexer++;
        }
    }
예제 #11
0
    public void CreateCompoundTexture(CompoundJSON compound)
    {
        Gradient gradient = new Gradient();

        GradientColorKey[] gradientColorKeys = new GradientColorKey[compound.Elements.Count];
        GradientAlphaKey[] gradientAlphaKeys = new GradientAlphaKey[compound.Elements.Count];

        float increment = 1f / compound.Elements.Count;
        float time      = increment / 2f;
        Color mColor;

        for (int i = 0; i < compound.Elements.Count; i++)
        {
            gradientAlphaKeys[i].alpha = 1f;
            gradientAlphaKeys[i].time  = time;

            ColorUtility.TryParseHtmlString(_elements[compound.Elements[i].Index].Color, out mColor);
            gradientColorKeys[i].color = mColor;
            gradientColorKeys[i].time  = time;

            time += increment;
        }
        gradient.SetKeys(gradientColorKeys, gradientAlphaKeys);

        _pixels = new Color[100];
        for (int y = 0; y < 100; y++)
        {
            _pixels[y] = gradient.Evaluate(y / 100f);
        }
        Texture2D _texture = new Texture2D(1, 100, TextureFormat.RGB24, false);

        _texture.SetPixels(_pixels);
        _texture.wrapMode = TextureWrapMode.Clamp;
        _texture.Apply();

        byte[] bytes = _texture.EncodeToPNG();
        File.WriteAllBytes("Assets/Resources/CompoundTexture/" + _indexer + ".png", bytes);
    }
예제 #12
0
 public override void OnDestroy()
 {
     base.OnDestroy();
     Compound        = null;
     _controlMessage = null;
 }
예제 #13
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);
    }
예제 #14
0
 public CompoundViewModel(CompoundJSON compound)
 {
     _compound = compound;
 }
예제 #15
0
 private void Add(CompoundJSON compoundJSON, IntReactiveProperty value)
 {
     Instantiate(CompoundInventoryPrefab, transform)
     .GetComponent <CompoundInventoryView>()
     .Setup(compoundJSON, value);
 }