Пример #1
0
        /// <summary>
        /// Initialize Stat Value
        /// </summary>
        /// <param name="owner"></param>
        public void Initialize(StatsCog owner)
        {
            ActiveModifiers = new List <StatModifier>();

            // Set parent stats cog
            Parent = owner;

            // Subscribe
            Subscribe();

            // Set Base values
            UpdateMinValue(0, 0);
            UpdateMaxValue(0, 0);
            UpdateValue(0, 0);
            UpdateRegenAmount(0, 0);
            UpdateRegenDelay(0, 0);
            nextRegen = -1;

            // Max
            if (startWithMaxValue && value.IsNumeric())
            {
                CurrentBaseValue = CurrentBaseMaximum;
            }

            // Finalize
            Initialized = true;
            if (onInit != null)
            {
                onInit.Invoke();
            }
        }
Пример #2
0
        public void SetStatsCog(StatsCog statsCog)
        {
            ClearEffects();

            StatMonitorTMP[] monitors = GetComponentsInChildren <StatMonitorTMP>();
            for (int i = 0; i < monitors.Length; i++)
            {
                monitors[i].statsCog = statsCog;
            }

            EnemyInfoList[] infoLists = GetComponentsInChildren <EnemyInfoList>();
            for (int i = 0; i < infoLists.Length; i++)
            {
                infoLists[i].statsCog = statsCog;
            }

            foreach (StatEffect effect in statsCog.Effects)
            {
                Instantiate(effectPrefab, effectsContainer).SetEffect(effect);
            }

            StatValue info = statsCog.FindStat(infoStat);

            if (info != null)
            {
                enemySprite.sprite = info.icon;
                enemyName.text     = info.displayName;
            }

            // Subscribe to new effects
            statsCog.onEffectAdded.AddListener(AddEffect);
        }
Пример #3
0
 public void LoadStat(StatsCog statsCog, string statName)
 {
     StatsCog  = statsCog;
     StatValue = StatsCog.FindStat(statName);
     Subscribe();
     UpdateUI(0, 0);
 }
Пример #4
0
        private bool HaveStats()
        {
            GameObject activeObj = Selection.activeObject as GameObject;

            if (activeObj == null)
            {
                stats = null;
                return(false);
            }

            prefabRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(activeObj);

            warnPrefab = prefabRoot != null;

            StatsCog newStats = activeObj.GetComponent <StatsCog>();

            if (stats != newStats || (stats == null && newStats != null))
            {
                stats = newStats;
                if (stats == null)
                {
                    statsEditor      = null;
                    lastEffects      = null;
                    effectListEditor = null;
                    return(false);
                }
                else
                {
                    statsEditor = (StatsCogEditor)Editor.CreateEditor(stats, typeof(StatsCogEditor));
                    return(true);
                }
            }

            return(stats != null);
        }
Пример #5
0
        private void OnEnable()
        {
            if (target is StatsCog)
            {
                myTarget = (StatsCog)target;

                stats = new ReorderableList(serializedObject, serializedObject.FindProperty("stats"), true, true, true, true);
                stats.elementHeight       = EditorGUIUtility.singleLineHeight + 2;
                stats.drawHeaderCallback  = (Rect rect) => { EditorGUI.LabelField(rect, "Stats"); };
                stats.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
                {
                    var element = stats.serializedProperty.GetArrayElementAtIndex(index);
                    EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), element);
                };
            }
        }
        private void Start()
        {
            if (lockCursor)
            {
                Cursor.lockState = CursorLockMode.Locked;
            }

            m_Animator      = GetComponent <Animator>();
            m_Rigidbody     = GetComponent <Rigidbody>();
            m_Capsule       = GetComponent <CapsuleCollider>();
            m_CapsuleHeight = m_Capsule.height;
            m_CapsuleCenter = m_Capsule.center;

            m_Rigidbody.constraints   = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
            m_OrigGroundCheckDistance = m_GroundCheckDistance;

            // get the transform of the main camera
            if (Camera.main != null)
            {
                m_Cam = Camera.main.transform;
            }
            else
            {
                Debug.LogWarning(
                    "Warning: no main camera found. Third person character needs a Camera tagged \"MainCamera\", for camera-relative controls.", gameObject);
                // we use self-relative controls in this case, which probably isn't what the user wants, but hey, we warned them!
            }

            // get the third person character ( this should never be null due to require component )
            m_Character = GetComponent <BasicPersonController>();

#if STATS_COG
            statsCog = GetComponentInChildren <Stats.StatsCog>();
            if (statsCog != null)
            {
                health = statsCog.FindStat(healthStatName);
            }
#endif

#if INVENTORY_COG
            inventory = GetComponent <Inventory.InventoryCog>();
#endif
        }
Пример #7
0
        private void Update()
        {
            if (Physics.Raycast(RectTransformUtility.ScreenPointToRay(Camera.main, caster.position), out RaycastHit hit))
            {
                if (hit.transform.gameObject.CompareTag("Player"))
                {
                    return;
                }

                StatsCog statsCog = hit.transform.gameObject.GetComponentInChildren <StatsCog>();
                if (statsCog == null)
                {
                    display.gameObject.SetActive(false);
                }
                else
                {
                    display.SetStatsCog(statsCog);
                    display.gameObject.SetActive(true);
                }
            }
        }
Пример #8
0
        private void ApplyDamage(GameObject otherObject)
        {
            if (waitList == null) waitList = new Dictionary<DamageReceiver, float>();

            // Check for shield first
            DamageShield shield = otherObject.GetComponentInChildren<DamageShield>();
            if (shield != null && shield.ShieldCollider.enabled)
            {
                if (shield.StatsSource != StatsSource)
                {
                    Destroy(gameObject);
                }
            }

            // Check for receiver
            DamageReceiver receiver = otherObject.GetComponentInChildren<DamageReceiver>();
            if (receiver != null)
            {
                // Check for self
                if (receiver.gameObject == gameObject) return;
                StatsCog statsCog = receiver.gameObject.GetComponent<StatsCog>();
                if (statsCog != null && statsCog == StatsSource) return;

                if (waitList.ContainsKey(receiver))
                {
                    if (Time.time >= waitList[receiver])
                    {
                        DealDamage(receiver);
                        waitList[receiver] = Time.time + minBetweenDamage;
                    }
                }
                else
                {
                    DealDamage(receiver);
                    waitList.Add(receiver, Time.time + minBetweenDamage);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Adds subscription and immediately evaluates for inital value
        /// </summary>
        /// <param name="statsCog"></param>
        public void Subscribe(StatsCog statsCog)
        {
            Unsubscribe();

            StatsCog = statsCog;

            // Increment
            StatValue stat;

            Subscriptions = new List <StatValue>();
            List <string> req = StatsCog.GetSubscriptionRequirements(Expression);

            foreach (string statName in req)
            {
                stat = StatsCog.FindStat(statName);
                if (stat != null && !Subscriptions.Contains(stat))
                {
                    stat.onValueChanged.AddListener(UpdateResult);
                    Subscriptions.Add(stat);
                }
            }

            UpdateResult(0, 0);
        }
Пример #10
0
 private void UpdateResult(float oldValue, float newValue)
 {
     ExpressionUpdate?.Invoke(StatsCog.EvaluateCondition(Expression));
 }
Пример #11
0
        /// <summary>
        /// Take damage
        /// </summary>
        /// <param name="damageDealer"></param>
        /// <returns></returns>
        private void TakeDamage(DamageDealer damageDealer, GameObject damageSourceObject)
        {
            // check if damage dealer is self
            if (GetComponentsInChildren <DamageDealer>().ToList().Contains(damageDealer))
            {
                return;
            }

            // Get hit direction
            HitDirection hitDirection = GetHitDirection(damageDealer.gameObject.transform.position);

            // Check for immunity
            if (directionImmunity != 0 && (directionImmunity | hitDirection) == hitDirection)
            {
                onImmuneToDamage?.Invoke();
                return;
            }

            if (immuneRemaining > 0)
            {
                return;
            }

            // Add Effects
#if STATS_COG
            if (damageDealer.effects != null)
            {
                foreach (StatEffect effect in damageDealer.effects)
                {
                    if (effectList.availableEffects.Contains(effect))
                    {
                        AddEffect(effect);
                    }
                }
            }
#endif

            float adjustedDamage      = 0;
            float totalAdjustedDamage = 0;

            // Apply weakness
            foreach (Damage damage in damageDealer.damage)
            {
#if STATS_COG
                if (damageDealer.StatsSource != null)
                {
                    adjustedDamage = damageDealer.StatsSource.GetExpressionValue(damage.baseAmount);
                }
                else
                {
                    adjustedDamage = float.Parse(damage.baseAmount);
                }
#endif
                if (damage.damageType != null)
                {
                    List <DamageModifier> modifiers = FindDamageModifiers(damage.damageType.name);
                    foreach (DamageModifier dm in modifiers)
                    {
                        if (dm.modifierType == DamageModType.Resistance)
                        {
                            adjustedDamage -= adjustedDamage * dm.CurrentValue;
                            if (dm.CurrentValue == 1)
                            {
                                onImmuneToDamage?.Invoke();
                            }
                        }
                        else
                        {
                            adjustedDamage *= dm.CurrentValue;
                        }
                    }
                }
                else
                {
                    Debug.LogError("Damage is missing a DamageType");
                }

                totalAdjustedDamage += adjustedDamage;
            }

            // Apply damage
            StatValue hp = FindStat(healthStat);
            if (hp != null)
            {
                adjustedDamage = Mathf.Clamp(GetExpressionValue(ReplaceInsensitive(damageValue, "[damage]", totalAdjustedDamage.ToString())), 0, float.MaxValue);
                hp.SetValue(hp.CurrentValue - adjustedDamage);
                lastDmgSource = damageDealer.StatsSource;
                onDamageTaken?.Invoke(adjustedDamage, damageDealer, damageSourceObject);
                onHitDamageDirection?.Invoke(hitDirection);
                immuneRemaining = immunityAfterHit;
                onHitDirection?.Invoke(hitDirection);
                if (hp.CurrentValue <= 0)
                {
                    onDeath?.Invoke();
                }
            }
            else
            {
                Debug.LogWarning("Could not find '" + healthStat + "' to apply damage");
            }
        }
Пример #12
0
 private void Awake()
 {
     Stats = GetComponentInChildren <StatsCog>();
     Stats.onHitDirection.AddListener(StartKnockback);
     Controller = GetComponentInChildren <CharacterController>();
 }
Пример #13
0
 private void Start()
 {
     statsCog = GameObject.FindGameObjectWithTag("Player").GetComponentInChildren <StatsCog>();
     statsCog.onEffectAdded.AddListener(EffectAdded);
 }