Esempio n. 1
0
File: Stats.cs Progetto: Deus0/zoxel
        public void SetAttributeMultiplier(int indexOf, float newValue)
        {
            AttributeStaz stat = attributes[indexOf];

            stat.multiplier     = newValue;
            attributes[indexOf] = stat;
        }
Esempio n. 2
0
File: Stats.cs Progetto: Deus0/zoxel
        public void SetAttributeValue(int indexOf, float newValue)
        {
            AttributeStaz stat = attributes[indexOf];

            stat.value          = newValue;
            attributes[indexOf] = stat;
        }
Esempio n. 3
0
File: Stats.cs Progetto: Deus0/zoxel
 public void InitializeAttributes(int count)
 {
     attributes = new BlitableArray <AttributeStaz>(count, Allocator.Persistent);
     for (int j = 0; j < attributes.Length; j++)
     {
         attributes[j] = new AttributeStaz {
         };
     }
 }
Esempio n. 4
0
            public void Execute(ref Stats stats)// ref ZoxID zoxID) // Entity e, int index,
            {
                if (stats.attributesApplied == 0)
                {
                    stats.attributesApplied = 1;
                    // do this when leveling up and gained alot of stats
                    // or did a big quest chain and got free stats as quest rewards

                    //Debug.LogError("Applying Attributes");
                    // first set all stats back to original

                    // now apply new stats
                    for (int j = 0; j < stats.attributes.Length; j++)
                    {
                        AttributeStaz attribute = stats.attributes[j];
                        bool          didFind   = false;
                        for (int i = 0; i < stats.states.Length; i++)
                        {
                            if (stats.states[i].id == attribute.targetID)
                            {
                                didFind = true;
                                if (attribute.previousAdded != 0)
                                {
                                    //Debug.LogError("Previous stat value was: " + attribute.previousAdded);
                                    float originalValue = stats.states[i].maxValue - attribute.previousAdded;
                                    stats.SetStateMaxValue(i, originalValue);
                                }
                                float bonusValue = attribute.value * attribute.multiplier;
                                float newValue   = stats.states[i].maxValue + bonusValue;
                                stats.SetStateMaxValue(i, newValue);
                                attribute.previousAdded = bonusValue;
                                stats.attributes[j]     = attribute;
                                //Debug.LogError("Adding bonus value to stat: " + bonusValue);
                                break;
                            }
                        }
                        if (!didFind)
                        {
                            //Debug.LogError("Could not find attribute target stat.");
                        }
                    }
                }
            }
Esempio n. 5
0
 protected override void OnUpdate()
 {
     Entities.WithAll <UpdateAttributeCommand>().ForEach((Entity e, ref UpdateAttributeCommand command) =>
     {
         //if (characterSpawnSystem.characters.ContainsKey(command.characterID))
         if (World.EntityManager.Exists(command.character))
         {
             //Entity character = characterSpawnSystem.characters[command.characterID];
             Stats stats   = World.EntityManager.GetComponentData <Stats>(command.character);
             int statIndex = (int)(command.statIndex);
             if ((StatType)command.statType == StatType.Attribute)
             {
                 if (statIndex >= 0 && statIndex < stats.attributes.Length)
                 {
                     AttributeStaz attribute     = stats.attributes[statIndex];
                     attribute.value            += command.amount;
                     stats.attributes[statIndex] = attribute;
                     stats.attributesApplied     = 0;
                     World.EntityManager.SetComponentData(command.character, stats);
                     StatsUISpawnSystem.OnUpdatedStat(World.EntityManager, command.character, (StatType)command.statType, command.statIndex);
                 }
             }
             else if ((StatType)command.statType == StatType.Base)
             {
                 if (statIndex >= 0 && statIndex < stats.stats.Length)
                 {
                     Staz stat              = stats.stats[statIndex];
                     stat.value            += command.amount;
                     stats.stats[statIndex] = stat;
                     World.EntityManager.SetComponentData(command.character, stats);
                     StatsUISpawnSystem.OnUpdatedStat(World.EntityManager, command.character, (StatType)command.statType, command.statIndex);
                 }
             }
             // StatUISystem.OnUpdated(command.characterIndex, attribute);
         }
         World.EntityManager.DestroyEntity(e);
         //SetText(characterID, originalArrayIndex, (int)improveStat.value);
     });
 }
Esempio n. 6
0
        public void UpdateStatUI(UpdateStatUICommand command)
        {
            ZoxID zoxID = World.EntityManager.GetComponentData <ZoxID>(command.character);

            if (!uis.ContainsKey(zoxID.id))
            {
                return; // character died
            }
            Stats     stats        = World.EntityManager.GetComponentData <Stats>(command.character);
            Entity    ui           = uis[zoxID.id];
            Childrens children     = World.EntityManager.GetComponentData <Childrens>(ui);
            int       uiArrayIndex = command.statIndex;

            if (command.statType == (byte)StatType.Base)
            {
                Staz      stat  = stats.stats[command.statIndex];
                Entity    icon  = children.children[uiArrayIndex];
                Childrens texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
            }
            else
            {
                uiArrayIndex += stats.stats.Length;
            }
            if (command.statType == (byte)StatType.State)
            {
                StateStaz stat  = stats.states[command.statIndex];
                Entity    icon  = children.children[uiArrayIndex];
                Childrens texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);

                /*Entity textEntity2 = texts.children[0];
                 * RenderText renderText2 = World.EntityManager.GetComponentData<RenderText>(textEntity2);
                 * renderText2.SetText(((int)stat.maxValue).ToString());
                 * World.EntityManager.SetComponentData(textEntity2, renderText2);*/
            }
            else
            {
                uiArrayIndex += stats.states.Length;
            }
            if (command.statType == (byte)StatType.Regen)
            {
                RegenStaz stat  = stats.regens[command.statIndex];
                Entity    icon  = children.children[uiArrayIndex];
                Childrens texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
            }
            else
            {
                uiArrayIndex += stats.regens.Length;
            }
            if (command.statType == (byte)StatType.Attribute)
            {
                AttributeStaz stat  = stats.attributes[command.statIndex];
                Entity        icon  = children.children[uiArrayIndex];
                Childrens     texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
            }
            else
            {
                uiArrayIndex += stats.attributes.Length;
            }
            if (command.statType == (byte)StatType.Level)
            {
                Level      stat       = stats.levels[command.statIndex];
                Entity     icon       = children.children[uiArrayIndex];
                Childrens  texts      = World.EntityManager.GetComponentData <Childrens>(icon);
                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
                // experience required

                /*Entity textEntity2 = texts.children[1];
                 * RenderText renderText2 = World.EntityManager.GetComponentData<RenderText>(textEntity2);
                 * renderText2.SetText(((int)stat.experienceGained).ToString());
                 * World.EntityManager.SetComponentData(textEntity2, renderText2);
                 * // experience gained
                 * Entity textEntity3 = texts.children[2];
                 * RenderText renderText3 = World.EntityManager.GetComponentData<RenderText>(textEntity3);
                 * renderText3.SetText(((int)stat.experienceRequired).ToString());
                 * World.EntityManager.SetComponentData(textEntity3, renderText3);*/
            }
        }
Esempio n. 7
0
File: Stats.cs Progetto: Deus0/zoxel
        public int AddStat(StatDatam statDatam)
        {
            int indexOf = -1;

            if (statDatam.type == StatType.Base)
            {
                Staz[] priorStates = stats.ToArray();
                stats = new BlitableArray <Staz>(stats.Length + 1, Allocator.Persistent);
                for (int i = 0; i < priorStates.Length; i++)
                {
                    stats[i] = priorStates[i];
                }
                Staz newState = new Staz();
                newState.id = statDatam.Value.id;
                stats[priorStates.Length] = newState;
                indexOf = priorStates.Length;
            }
            else if (statDatam.type == StatType.State)
            {
                StateStaz[] priorStates = states.ToArray();
                states = new BlitableArray <StateStaz>(states.Length + 1, Allocator.Persistent);
                for (int i = 0; i < priorStates.Length; i++)
                {
                    states[i] = priorStates[i];
                }
                StateStaz newState = new StateStaz();
                newState.id = statDatam.Value.id;
                states[priorStates.Length] = newState;
                indexOf = priorStates.Length;
            }
            else if (statDatam.type == StatType.Regen)
            {
                RegenStaz[] priorStates = regens.ToArray();
                regens = new BlitableArray <RegenStaz>(regens.Length + 1, Allocator.Persistent);
                for (int i = 0; i < priorStates.Length; i++)
                {
                    regens[i] = priorStates[i];
                }
                RegenStaz newState = new RegenStaz();
                newState.id                = statDatam.Value.id;
                newState.targetID          = statDatam.targetStatID;
                regens[priorStates.Length] = newState;
                indexOf = priorStates.Length;
            }
            else if (statDatam.type == StatType.Attribute)
            {
                AttributeStaz[] priorStats = attributes.ToArray();
                attributes = new BlitableArray <AttributeStaz>(attributes.Length + 1, Allocator.Persistent);
                for (int i = 0; i < priorStats.Length; i++)
                {
                    attributes[i] = priorStats[i];
                }
                AttributeStaz newStat = new AttributeStaz();
                newStat.id       = statDatam.Value.id;
                newStat.targetID = statDatam.targetStatID;
                attributes[priorStats.Length] = newStat;
                indexOf = priorStats.Length;
            }
            else if (statDatam.type == StatType.Level)
            {
                Level[] priorStats = levels.ToArray();
                levels = new BlitableArray <Level>(levels.Length + 1, Allocator.Persistent);
                for (int i = 0; i < priorStats.Length; i++)
                {
                    levels[i] = priorStats[i];
                }
                Level newStat = new Level();
                newStat.id = statDatam.Value.id;
                //newStat.targetID = statDatam.targetStatID;
                levels[priorStats.Length] = newStat;
                indexOf = priorStats.Length;
            }
            return(indexOf);
        }