コード例 #1
0
ファイル: Stats.cs プロジェクト: Deus0/zoxel
        public void SetStateMaxValue(int indexOf, float newValue)
        {
            StateStaz stat = states[indexOf];

            stat.maxValue   = newValue;
            states[indexOf] = stat;
        }
コード例 #2
0
ファイル: Stats.cs プロジェクト: Deus0/zoxel
 public void InitializeStates(int count)
 {
     states = new BlitableArray <StateStaz>(count, Allocator.Persistent);
     for (int j = 0; j < states.Length; j++)
     {
         states[j] = new StateStaz {
         };
     }
 }
コード例 #3
0
 protected override void OnUpdate()
 {
     Entities.WithAll <StatBarUI>().ForEach((Entity e, ref StatBarUI statbar) =>
     {
         if (World.EntityManager.Exists(statbar.character) && World.EntityManager.HasComponent <Stats>(statbar.character))
         {
             Stats characterStats = World.EntityManager.GetComponentData <Stats>(statbar.character);
             if (characterStats.states.Length > 0)
             {
                 StateStaz staz           = characterStats.states[0];
                 statbar.targetPercentage = staz.value / staz.maxValue;
             }
         }
     });
 }
コード例 #4
0
ファイル: RegenCompleterSystem.cs プロジェクト: Deus0/zoxel
        protected void UpdateStatbar(Stats stats, Entity character, int stateIndex)
        {
            ZoxID zoxID       = World.EntityManager.GetComponentData <ZoxID>(character);
            int   characterID = zoxID.id;

            if (stateIndex != -1)
            {
                StateStaz targetStateStat = stats.states[stateIndex];
                if (targetStateStat.value == targetStateStat.maxValue)
                {
                    // new system needed - struct that contains multiple bars, for various state stats
                    if (StatbarSystem.frontBars.ContainsKey(characterID))
                    {
                        StatBarUI statBarUI = World.EntityManager.GetComponentData <StatBarUI>(StatbarSystem.frontBars[characterID]);
                        if (statBarUI.isTakingDamage == 1)
                        {
                            statBarUI.isTakingDamage = 0;
                            //statBarUI.timeStateChanged = UnityEngine.Time.time;
                            World.EntityManager.SetComponentData(StatbarSystem.frontBars[characterID], statBarUI);
                        }
                    }
                }
                //RegenStaz[] regens = stats.regens.ToArray();
                // later check for all regens, if the value increase to max
                //foreach (RegenStaz regen in regens)
                {
                    //RegenStaz regen = stats.regens[regenIndex];
                    // get index id

                    /*int targetStatIndex = -1;
                     * for (int i = 0; i < stats.states.Length; i++)
                     * {
                     *  if (stats.states[i].id == targetStatIndex)
                     *  {
                     *      targetStatIndex = i;
                     *      break;
                     *  }
                     * }
                     */
                }
            }
        }
コード例 #5
0
ファイル: StatsUISystem.cs プロジェクト: Deus0/zoxel
        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);*/
            }
        }
コード例 #6
0
ファイル: Stats.cs プロジェクト: 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);
        }
コード例 #7
0
            public void Execute(ref Stats stats)
            {
                if (stats.leveledUp == 1)
                {
                    stats.leveledUp = 0;

                    /*
                     #region Indexes
                     * int levelIndex = -1;
                     * for (int i = 0; i < stats.stats.Length; i++)
                     * {
                     *  if (stats.stats[i].id == levelID)
                     *  {
                     *      levelIndex = i;
                     *      break;
                     *  }
                     * }
                     * if (levelIndex == -1)
                     * {
                     *  return;
                     * }
                     * int experienceIndex = -1;
                     * for (int i = 0; i < stats.states.Length; i++)
                     * {
                     *  if (stats.states[i].id == experienceID)
                     *  {
                     *      experienceIndex = i;
                     *      break;
                     *  }
                     * }
                     * if (experienceIndex == -1)
                     * {
                     *  return;
                     * }
                     #endregion
                     */
                    Level level = stats.levels[0];
                    //StateStaz experience = stats.states[experienceIndex];

                    int counter          = 0;
                    int statPointsGained = 0;
                    while (level.experienceGained >= level.experienceRequired)
                    {
                        level.experienceGained   -= level.experienceRequired;
                        level.experienceRequired *= 1.2f;
                        // increase SkillPoints (base stat)
                        level.value++;
                        statPointsGained += 3;
                        counter++;
                        if (counter >= 255)
                        {
                            break;
                        }
                    }
                    stats.levels[0] = level;


                    //stats.states[0] = health; // until i made attribute value, then need AI to spend points
                    // also give some skill points
                    // give some attribute points too
                    stats.leveledUpEffects = 1; // now add particles and sound
                    // restore states
                    for (int j = 0; j < stats.states.Length; j++)
                    {
                        StateStaz state = stats.states[j];
                        if (state.id != experienceID)
                        {
                            state.value     = state.maxValue * 0.99f;
                            stats.states[j] = state;
                        }
                    }
                    // give stat points
                    int statPointIndex = -1;
                    for (int i = 0; i < stats.stats.Length; i++)
                    {
                        if (stats.stats[i].id == statPointID)
                        {
                            statPointIndex = i;
                            break;
                        }
                    }
                    if (statPointIndex == -1)
                    {
                        return;
                    }
                    Staz statPoint = stats.stats[statPointIndex];
                    statPoint.value            += statPointsGained;
                    stats.stats[statPointIndex] = statPoint;
                }
            }
コード例 #8
0
ファイル: DamageSystem.cs プロジェクト: Deus0/zoxel
        private void ApplyDamage(Entity attacker, Entity defender, float damageDone)
        {
            // now get components
            if (!(World.EntityManager.HasComponent <Stats>(attacker) && World.EntityManager.HasComponent <Stats>(defender)))
            {
                return;
            }
            ZoxID       defenderID          = World.EntityManager.GetComponentData <ZoxID>(defender);
            Stats       defenderStats       = World.EntityManager.GetComponentData <Stats>(defender);
            ZoxID       attackerID          = World.EntityManager.GetComponentData <ZoxID>(attacker);
            Stats       attackerStats       = World.EntityManager.GetComponentData <Stats>(attacker);
            Translation defenderTranslation = World.EntityManager.GetComponentData <Translation>(defender);
            int         healthIndex         = 0;

            // decrease health
            if (defenderStats.states.Length == 0)
            {
                return; // cannot apply damage to gods
            }
            StateStaz healthStat = defenderStats.states[healthIndex];

            if (damageDone > 0 && healthStat.IsMaxValue())
            {
                // add regening to them
                RegenCompleterSystem.StartRegening(World.EntityManager, defender);
            }
            healthStat.value -= damageDone;
            //Debug.Log("Damage done: " + damageDone + " to " + defender.Index
            //    + " - " + defenderStats.states[0].value + " out of " + defenderStats.states[0].maxValue);
            if (healthStat.value < 0)
            {
                healthStat.value = 0;
            }
            defenderStats.states[healthIndex] = healthStat;
            // health pop up here
            damagePopupSystem.SpawnPopup(damageDone, defenderTranslation.Value);

            // Death
            if (healthStat.value == 0)// && defenderStats.isDead == 0)
            {
                //Debug.LogError("Defender ID has died: " + defender.Index + " at " + UnityEngine.Time.time);
                // Give rewards to Victor
                int metaID = 0;
                if (World.EntityManager.HasComponent <Character>(defender))
                {
                    metaID = World.EntityManager.GetComponentData <Character>(defender).metaID;
                }
                RewardVictor(ref defenderStats, attacker, ref attackerStats, defenderID.clanID,
                             metaID);
                defenderStats.willDie = 1;
                //defenderStats.timeDied = UnityEngine.Time.time;
                // Spawn Item
                //body.velocity = float3.zero;
                // give xp to attacker
            }
            else
            {
                // Attack back!
                RespondToAttack(defender, attacker);
                TriggerStatbar(defender, defenderID.id);
            }
            World.EntityManager.SetComponentData(defender, defenderStats);
        }