public static void RegisterStatsHandler(StatsHandler handler)
 {
     if (!StatsManager.current.m_StatsHandler.Contains(handler))
     {
         StatsManager.current.m_StatsHandler.Add(handler);
     }
 }
        public static void Load()
        {
            string key  = PlayerPrefs.GetString(StatsManager.SavingLoading.savingKey) + ".StatSystem";
            string data = PlayerPrefs.GetString(key);

            if (string.IsNullOrEmpty(data))
            {
                return;
            }

            List <StatsHandler> results = Object.FindObjectsOfType <StatsHandler>().Where(x => x.saveable).ToList();
            List <object>       list    = MiniJSON.Deserialize(data) as List <object>;

            for (int i = 0; i < list.Count; i++)
            {
                Dictionary <string, object> handlerData = list[i] as Dictionary <string, object>;
                string       handlerName = (string)handlerData["Name"];
                StatsHandler handler     = results.Find(x => x.HandlerName == handlerName);
                if (handler != null)
                {
                    handler.SetObjectData(handlerData);
                    handler.UpdateStats();
                }
            }

            if (StatsManager.DefaultSettings.debugMessages)
            {
                Debug.Log("[Stat System] Stats loaded " + StatsManager.SavingLoading.savingKey + ".StatSystem" + data);
            }
        }
Esempio n. 3
0
        public void UpdateBaseValue(StatsHandler handler)
        {
            StatResult result = formula.nodes.Find(x => x.GetType() == typeof(StatResult)) as StatResult;

            this.m_BaseValue = result.GetInputValue <float>("value", result.value) + this.m_IncrementalValue;
            this.m_Delta     = result.GetInputValue <float>("delta", result.delta);
        }
Esempio n. 4
0
        //This is for testing
        private void SendDamage(Object data)
        {
            DamageData damageData  = data as DamageData;
            Stat       sendingStat = stats.FirstOrDefault(x => x.Name == damageData.sendingStat);

            if (sendingStat == null)
            {
                return;
            }

            Collider[] colliders = Physics.OverlapSphere(transform.position, damageData.maxDistance);
            for (int i = 0; i < colliders.Length; i++)
            {
                if (colliders[i].transform != transform)
                {
                    Vector3 direction = colliders[i].transform.position - transform.position;
                    float   angle     = Vector3.Angle(direction, transform.forward);
                    if (Mathf.Abs(angle) < damageData.maxAngle)
                    {
                        StatsHandler receiver = colliders[i].GetComponent <StatsHandler>();
                        if (receiver != null)
                        {
                            Stat criticalStrikeStat = stats.FirstOrDefault(x => x.Name == damageData.criticalStrikeStat);

                            bool  criticaleStrike = criticalStrikeStat != null && criticalStrikeStat.Value > UnityEngine.Random.Range(0f, 100f);
                            float damage          = sendingStat.Value;
                            if (criticaleStrike)
                            {
                                damage *= 2f;
                            }

                            receiver.ApplyDamageInternal(damageData.receivingStat, damage, 0, criticaleStrike);
                            if (damageData.particleEffect != null)
                            {
                                Vector3 pos     = colliders[i].ClosestPoint(transform.position + damageData.offset);
                                Vector3 right   = UnityEngine.Random.Range(-damageData.randomize.x, damageData.randomize.x) * transform.right;
                                Vector3 up      = UnityEngine.Random.Range(-damageData.randomize.y, damageData.randomize.y) * transform.up;
                                Vector3 forward = UnityEngine.Random.Range(-damageData.randomize.z, damageData.randomize.z) * transform.forward;

                                Vector3    relativePos = (transform.position + damageData.offset + right + up + forward) - pos;
                                GameObject effect      = Instantiate(damageData.particleEffect, pos, Quaternion.LookRotation(relativePos, Vector3.up));
                                Destroy(effect, damageData.lifeTime);
                            }

                            CameraEffects.Shake(damageData.duration, damageData.speed, damageData.amount);
                            if (damageData.hitSounds.Length > 0)
                            {
                                UnityTools.PlaySound(damageData.hitSounds[UnityEngine.Random.Range(0, damageData.hitSounds.Length)], damageData.volume);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
0
 public override void Initialize(StatsHandler handler, StatOverride statOverride)
 {
     base.Initialize(handler, statOverride);
     this.m_Experience = handler.GetStat(this.m_Experience.Name) as Attribute;
     this.m_Experience.onCurrentValueChange += () =>
     {
         if (this.m_Experience.CurrentValue >= this.m_Experience.Value)
         {
             this.m_Experience.CurrentValue = 0f;
             Add(1f);
         }
     };
 }
Esempio n. 6
0
        public void Initialize(StatsHandler handler)
        {
            this.m_Handler = handler;
            List <GetStat> statNodes = new List <GetStat>();

            for (int i = 0; i < handler.stats.Count; i++)
            {
                statNodes.AddRange(formula.nodes.Where(x => typeof(GetStat).IsAssignableFrom(x.GetType())).Cast <GetStat>());
            }
            for (int i = 0; i < statNodes.Count; i++)
            {
                statNodes[i].statValue = handler.GetStat(statNodes[i].stat.Trim());
            }
            if (this.m_Regenerate)
            {
                handler.StartCoroutine(Regeneration());
            }
        }
        public virtual void Initialize(StatsHandler handler, Stat stat)
        {
            this.m_Handler = handler;
            this.m_Stat    = stat;
            switch (this.m_ValueType)
            {
            case ValueType.Value:
                stat.onValueChange += OnValueChange;
                break;

            case ValueType.CurrentValue:
                if (stat is Attribute attribute)
                {
                    attribute.onCurrentValueChange += OnCurrentValueChange;
                }
                break;
            }
            this.m_Sequence          = new Sequence(handler.gameObject, new PlayerInfo("Player"), handler.GetComponent <Blackboard>(), this.m_Actions.actions.ToArray());
            this.m_Handler.onUpdate += Update;
        }
Esempio n. 8
0
        protected virtual void Update()
        {
            //TODO BETTER FIX, SelectableUIStat is displaying same values for all enemies
            //if (stat == null) {
            StatsHandler handler = GetStatsHandler();

            if (handler == null)
            {
                return;
            }
            stat = handler.GetStat(this.m_Stat);
            if (this.m_FreePoints != null)
            {
                freePoints = handler.GetStat(this.m_FreePoints);
            }

            if (this.m_StatName != null)
            {
                this.m_StatName.text = this.stat.Name;
            }
            //	}
            Repaint();
        }
Esempio n. 9
0
 public override void OnStart()
 {
     this.m_Handler = this.m_Target == TargetType.Self ? gameObject.GetComponent <StatsHandler>() : playerInfo.gameObject.GetComponent <StatsHandler>();
 }
Esempio n. 10
0
        private void SendDamage(GameObject receiver, Object data)
        {
            StatsHandler receiverHandler = receiver.GetComponent <StatsHandler>();
            DamageData   damageData      = data as DamageData;

            //Exclude self tag, needs some kind of frieds tag system
            if (gameObject.tag == receiver.tag)
            {
                return;
            }

            if (receiverHandler != null && receiverHandler.enabled && damageData != null)
            {
                Stat sendingStat = this.m_Stats.FirstOrDefault(x => x.Name == damageData.sendingStat);
                if (sendingStat == null)
                {
                    return;
                }

                Stat criticalStrikeStat = this.m_Stats.FirstOrDefault(x => x.Name == damageData.criticalStrikeStat);

                bool criticaleStrike = criticalStrikeStat != null && criticalStrikeStat.Value > UnityEngine.Random.Range(0f, 100f);
                sendingStat.CalculateValue();
                float damage = sendingStat.Value;

                if (criticaleStrike)
                {
                    damage *= 2f;
                }

                receiverHandler.ApplyDamage(damageData.receivingStat, damage);
                EventHandler.Execute(receiver, "OnGetHit", gameObject, damageData.receivingStat, damage);

                SendMessage("UseItem", SendMessageOptions.DontRequireReceiver);

                if (damageData.particleEffect != null)
                {
                    Vector3 pos     = receiver.GetComponent <Collider>().ClosestPoint(transform.position + damageData.offset);
                    Vector3 right   = UnityEngine.Random.Range(-damageData.randomize.x, damageData.randomize.x) * transform.right;
                    Vector3 up      = UnityEngine.Random.Range(-damageData.randomize.y, damageData.randomize.y) * transform.up;
                    Vector3 forward = UnityEngine.Random.Range(-damageData.randomize.z, damageData.randomize.z) * transform.forward;

                    Vector3    relativePos = (transform.position + damageData.offset + right + up + forward) - pos;
                    GameObject effect      = Instantiate(damageData.particleEffect, pos, Quaternion.LookRotation(relativePos, Vector3.up));
                    Destroy(effect, damageData.lifeTime);
                }
                if (damageData.enableShake)
                {
                    CameraEffects.Shake(damageData.duration, damageData.speed, damageData.amount);
                }

                if (damageData.hitSounds.Length > 0)
                {
                    receiverHandler.PlaySound(damageData.hitSounds[UnityEngine.Random.Range(0, damageData.hitSounds.Length)], damageData.audioMixerGroup, damageData.volumeScale);
                }

                if (damageData.displayDamage)
                {
                    receiverHandler.DisplayDamage(damageData.damagePrefab, damage, criticaleStrike?damageData.criticalDamageColor:damageData.damageColor, damageData.intensity);
                }

                if (damageData.enableKnockback && damageData.knockbackChance > Random.Range(0f, 1f))
                {
                    StartCoroutine(Knockback(receiver, damageData));
                }

                Animator animator = receiver.GetComponent <Animator>();
                if (animator != null && animator.GetCurrentAnimatorStateInfo(0).IsName("Locomotion") && !animator.IsInTransition(0))
                {
                    animator.SetTrigger("Hit");
                }
            }
        }
Esempio n. 11
0
 private void Start()
 {
     this.m_Handler = GetComponent <StatsHandler>();
     StartCoroutine(ApplyDamage());
 }