Beispiel #1
0
 void QueryResultReceived(WorldCommands.EntityQuery.ReceivedResponse response)
 {
     if (response.StatusCode == StatusCode.Success)
     {
         if (response.Result.Count > 0)
         {
             var v = response.Result[entityIdHit].GetComponentSnapshot <Position.Snapshot>();
             if (v != null)
             {
                 Vector3 hitPosition = v.Value.Coords.ToUnityVector();
                 Vector3 myPosition  = transform.position - workerOrigin;
                 var     distance    = Vector3.Distance(hitPosition, myPosition);
                 if (distance <= GameConstants.MaxFireDistance)
                 {
                     HealthModifier request = new HealthModifier(damage);
                     healthCommandSender.SendUpdateHealthCommand(entityIdHit, request, UpdateHealthCommandCallback);
                 }
                 else
                 {
                     logger.HandleLog(LogType.Warning, new LogEvent($"Potential cheat: {entityId.Id} - Reason: Hitting from too far " +
                                                                    $"(max distance {GameConstants.MaxFireDistance} - current distance {distance})"));
                 }
             }
         }
     }
 }
        public void LaunchRagdoll(HealthModifier deathDetails)
        {
            // Launch the ragdoll in direction of modifier.
            var forceOrigin     = deathDetails.Origin.ToVector3();
            var launchDirection = (deathDetails.AppliedLocation.ToVector3() - forceOrigin).normalized;
            var launchVector    = launchDirection * ragdollLaunchForce;

            centreBone.AddForce(launchVector, ForceMode.Impulse);
        }
Beispiel #3
0
 private void OnCollisionEnter2D(Collision2D coll) {
     if(coll.gameObject.tag == "HealthMod") {
         HealthModifier other = coll.gameObject.GetComponent<HealthModifier>();
         if(!other.isHit) {
             this.Heal(other.healthAmount);
             other.Hit();
         }
     }
 }
        private HealthComponent.ModifyHealth.Request BuildModifyHealthCommand(float delta)
        {
            var zeroStandardType = new IntAbsolute();
            var healthModifier   = new HealthModifier(0, delta, zeroStandardType, zeroStandardType);

            return(new HealthComponent.ModifyHealth.Request(
                       LocalPlayerLink.EntityId,
                       healthModifier));
        }
Beispiel #5
0
        public void LaunchRagdoll(HealthModifier deathDetails)
        {
            // Launch the ragdoll in direction of modifier.
            var launchVector = MakeLaunchVector(
                deathDetails.Origin.ToVector3(),
                deathDetails.AppliedLocation.ToVector3());

            centreBone.AddForce(launchVector, ForceMode.Impulse);
        }
Beispiel #6
0
 public virtual void ActiveIt(Vector3 RespawnPos, Vector3 Euler, int Damage, string TargetTag)
 {
     DamageValue          = Damage;
     transform.localScale = Scale;
     transform.position   = RespawnPos;
     m_euler = Euler;
     transform.Rotate(Euler);
     AttackTag        = TargetTag;
     gameObject.layer = LayerMask.NameToLayer(TargetTag == "Player" ? "Enemy" : "Player");
     modifier         = new HealthModifier(-DamageValue);
 }
Beispiel #7
0
    public override void HitRecycleNow()
    {
        transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
        if (IsNotRecycled)
        {
            if (HitEffect != null || HitEffect != "")
            {
                GameObject shootHitEffect = ObjectPool.GetObject(HitEffect, "Effects");
                shootHitEffect.transform.position = transform.position + Vector3.forward * 10f;
            }
            Nowtime = 0;

            List <GameObject> targets = GetAttackTargets();
            if (targets != null && targets.Count != 0)
            {
                foreach (var t in targets)
                {
                    gravitationModifier = new GravitationModifier(transform.position, GravitationInternal, GravitationPower);
                    gravitationModifier.TakeEffect(t.GetComponent <Entity>());
                    AnimatorParameterFragment animator = new AnimatorParameterFragment();
                    for (int i = 0; i < 3; i++)
                    {
                        HealthModifier hm = new HealthModifier(-30);
                        hm.TakeEffect(t.GetComponent <Entity>());
                        animator.Animator = t.transform.GetChild(0).GetComponent <Animator>();
                        animator.Name     = "Hit";
                        animator.TakeEffect();
                    }
                    if (t.gameObject.GetComponent <Entity>().GetCapability <Health>().Value < 0)
                    {
                        animator.Name = "Die";
                        animator.TakeEffect();
                        if (t.gameObject.CompareTag("Player"))
                        {
                            StopPlayerMovementFragment stopPlayerMovementFragment = new StopPlayerMovementFragment(0f);
                            stopPlayerMovementFragment.TakeEffect(t.GetComponent <Entity>());

                            StopPlayerStateFragment stopPlayerStateFragment = new StopPlayerStateFragment(0f);
                            stopPlayerStateFragment.TakeEffect(t.GetComponent <Entity>());
                        }
                        ;
                        gameObject.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll;
                    }
                }
            }
            flyingDistance = 0;
            targetDistance = 0;
            ObjectPool.RecycleObject(gameObject);
            IsNotRecycled = false;
        }
    }
Beispiel #8
0
        void OnTriggerEnter2D(Collider2D other)
        {
            HealthModifier hm = other.gameObject.GetComponent <HealthModifier>();

            if (hm != null)
            {
                if (CompareTag(hm.targetTag))
                {
                    if (!dead)
                    {
                        health += hm.healthDelta;
                    }
                }
            }
        }
Beispiel #9
0
        private void HandleHealthModifier(HealthModifier modifyReq)
        {
            var oldHealth = healthWriter.Data.Health;
            var newHealth = Mathf.Clamp(oldHealth + modifyReq.Amount, 0, healthWriter.Data.MaxHealth);
            var died      = newHealth <= 0;

            healthWriter.SendUpdate(new HealthComponent.Update()
            {
                Health = newHealth
            });

            var healthModifiedInfo = new HealthModifiedInfo(modifyReq, oldHealth, newHealth, died);

            healthWriter.SendHealthModifiedEvent(healthModifiedInfo);
        }
Beispiel #10
0
    public IEnumerator DealDamage()
    {
        yield return(new WaitForSeconds(healRate));

        colliders = Physics.OverlapSphere(transform.position, radius, mask);
        if (colliders.Length > 0)
        {
            foreach (Collider c in colliders)
            {
                var            entityIdHit = c.gameObject.GetComponent <LinkedEntityComponent>().EntityId;
                HealthModifier request     = new HealthModifier(turretHeal);
                healthCommandSender.SendUpdateHealthCommand(entityIdHit, request, OnUpdateResponseReceived);
            }
        }
        StartCoroutine(nameof(DealDamage));
    }
Beispiel #11
0
        private void OnDeath(HealthModifier deathDetails)
        {
            var ragdoll = pool.Get();

            if (transformToMatch != null)
            {
                ragdoll.MatchTransforms(transformToMatch);
            }
            else
            {
                ragdoll.transform.position = transform.position;
            }

            OnRagdollSpawned?.Invoke(ragdoll.gameObject);

            ragdoll.LaunchRagdoll(deathDetails);
        }
Beispiel #12
0
        private async void Delay(float ms, Entity actor)
        {
            int step = (int)(0.2 * 1000 / ms);      // 延迟释放攻击,与动画配合
            List <Collider2D> HurtTargets = new List <Collider2D>();

            do
            {
                step++;
                await Task.Delay((int)ms);

                if (step == SkillInternal * 500 / ms)
                {
                    HurtTargets.Clear();
                }
                Collider2D[] cols = Physics2D.OverlapCircleAll(actor.transform.position, actor.GetComponent <Entity>().GetCapability <Attack>().Range);
                if (cols.Length > 0)
                {
                    List <GameObject> Targets = new List <GameObject>();
                    foreach (var c in cols)
                    {
                        if (c.transform.CompareTag(actor.transform.GetComponent <WeaponController>().AttackTag) && !HurtTargets.Contains(c))
                        {
                            Targets.Add(c.gameObject);
                            HurtTargets.Add(c);
                        }
                    }
                    if (Targets.Count != 0)
                    {
                        HealthModifier     healthModifier     = new HealthModifier(-Damage);
                        MoveTowardFragment moveTowardFragment = new MoveTowardFragment();
                        foreach (var t in Targets)
                        {
                            moveTowardFragment.Direction    = (t.transform.position - actor.transform.position);
                            moveTowardFragment.InternalTime = 0.2f;
                            moveTowardFragment.Speed        = HitPower;
                            moveTowardFragment.TakeEffect(t.GetComponent <Entity>());
                            healthModifier.TakeEffect(t.GetComponent <Entity>());
                        }
                    }
                }
            } while (step < SkillInternal * 1000 / ms);
        }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Bullets"))
        {
            return;
        }
        if (AttackTag != null && AttackTag != "")
        {
            if (collision.gameObject.CompareTag(AttackTag))
            {
                HealthModifier     healthModifier     = new HealthModifier(-25); //角色定值技能()写死
                MoveTowardFragment moveTowardFragment = new MoveTowardFragment();

                moveTowardFragment.Direction    = ((collision.transform.position - transform.position).normalized);
                moveTowardFragment.InternalTime = 0.5f;
                moveTowardFragment.Speed        = 0.2f;
                moveTowardFragment.TakeEffect(collision.GetComponent <Entity>());
            }
        }
    }
Beispiel #14
0
    public void LevelUpCharacter()
    {
        if (GameInformation.CurrentXP > GameInformation.RequiredXP)
        {
            GameInformation.CurrentXP -= GameInformation.RequiredXP;
        }
        else
        {
            GameInformation.CurrentXP = 0;
        }
        if (GameInformation.PlayerLevel < maxPlayerLevel)
        {
            GameInformation.PlayerLevel += 1;
        }
        else
        {
            GameInformation.PlayerLevel = maxPlayerLevel;
        }

        //plan je da dodam 5 poena svaki put kad se slevelujem
        GameInformation.AvailableLevelPoints = GameInformation.AvailableLevelPoints + 5;
        // postavljam da kad se leveluje igrac poveca svoje helte za odredjeni nivo koliji he maxiumum
        Combat.healthCheckedOnce = false;
        Combat.energyCheckOnce   = false;
        Combat.manaCheckOnce     = false;
        //posalti level healthModifieru da bi povecali maximalni health
        HealthModifier.healthLevelIncrease(GameInformation.PlayerLevel);

        EnergyModifier.energyLevelIncrease(GameInformation.PlayerLevel);

        ManaModifier.manaLevelIncrease(GameInformation.PlayerLevel);
        //saljem broj poena u staticku klasu kod koje cu moci da pristupim
        Points.LevelUpPoints(GameInformation.AvailableLevelPoints);

        DetermineRequiredXP();
        //Debug.Log(GameInformation.CurrentXP);
        //Debug.Log(GameInformation.RequiredXP);
        //Debug.Log(GameInformation.PlayerLevel);
    }
 /// <summary>Lets a modifier that is in the list of modifiers modify max</summary>
 public void ModifyMax(HealthModifier modifier, int value)
 {
     if (activeModifiers.Contains(modifier))
     {
         if (value > 0)
         {
             max += value;
         }
         else if (value < 0 && max != minimalMax)
         {
             max += value;
             if (max < minimalMax)
             {
                 max = minimalMax;
             }
             if (current > max)
             {
                 current = max;
             }
         }
     }
 }
 /// <summary>Lets a modifier that is in the list of modifiers modify current</summary>
 public void ModifyCurrent(HealthModifier modifier, int value)
 {
     if (activeModifiers.Contains(modifier))
     {
         if (value > 0 && current != max)
         {
             current += value;
             if (current > max)
             {
                 current = max;
             }
         }
         else if (value < 0 && current != 0)
         {
             current += value;
             if (current < 0)
             {
                 current = 0;
             }
         }
     }
 }
    /// <summary>Adds modifier to system modifiers if it is valid and fires start events if condition is right</summary>
    public void AddModifier(HealthModifier modifier)
    {
        if (modifier as TimedHealthModifier != null)
        {
            TimedHealthModifier timed = (TimedHealthModifier)modifier;
            if (!timed.HasValidTime)
            {
                Debug.LogWarning($"Didn't add timed modifier to health system :: time was invalid");
                return;
            }
            else if (!timed.HasValidValue)
            {
                Debug.LogWarning($"Didn't add timed modifier to health system :: value was invalid");
                return;
            }

            if (activeModifiers.Count(m => m.Regenerate) == 0 && timed.Regenerate)
            {
                Debug.Log("started regen");
                OnRegenStart?.Invoke();
            }
            else if (activeModifiers.Count(m => !m.Regenerate) == 0 && !timed.Regenerate)
            {
                Debug.Log("stared decay");
                OnDecayStart?.Invoke();
            }
        }
        else if (modifier as ConditionalHealthModifier != null)
        {
            ConditionalHealthModifier conditional = (ConditionalHealthModifier)modifier;
            if (!conditional.HasValidValuePerSecond)
            {
                Debug.LogWarning($"Didn't add conditional modifier to health system :: value per second was invalid");
                return;
            }
            else if (!conditional.HasValidCondition)
            {
                Debug.LogWarning($"Didn't add conditional modifier to health system :: condition threw exception");
                return;
            }

            if (activeModifiers.Count(m => m.Regenerate) == 0 && conditional.Regenerate)
            {
                Debug.Log("started regen");
                OnRegenStart?.Invoke();
            }
            else if (activeModifiers.Count(m => !m.Regenerate) == 0 && !conditional.Regenerate)
            {
                Debug.Log("started decay");
                OnDecayStart?.Invoke();
            }
        }

        if (!modifier.CanStack && activeModifiers.Any(m => m.Name == modifier.Name))
        {
            queuedModifiers.Add(modifier);
        }
        else
        {
            activeModifiers.Add(modifier);
        }
    }
Beispiel #18
0
    private void Create()
    {
        // Create root gameobject

        GameObject gameObject = new GameObject("NewMissile");

        Selection.activeGameObject = gameObject;

        // Create 3D model

        if (missileModel != null)
        {
            GameObject meshObject = Instantiate(missileModel, gameObject.transform);
            meshObject.name = "Model";
            meshObject.transform.localPosition = Vector3.zero;
            meshObject.transform.localRotation = Quaternion.identity;
        }

        // Create the visual effects

        if (exhaustVisualEffects != null)
        {
            GameObject exhaustVisualEffectsObject = Instantiate(exhaustVisualEffects, gameObject.transform);
            exhaustVisualEffectsObject.name = "ExhaustVisualEffects";
            exhaustVisualEffectsObject.transform.localPosition = Vector3.zero;
            exhaustVisualEffectsObject.transform.localRotation = Quaternion.identity;
        }

        // ************************ AUDIO ***************************

        // Create an object to store the audio under
        GameObject audioObject = new GameObject("Audio");

        audioObject.transform.parent        = gameObject.transform;
        audioObject.transform.localPosition = Vector3.zero;
        audioObject.transform.localRotation = Quaternion.identity;

        // Create the launch audio

        if (launchAudioClip != null)
        {
            GameObject launchAudioObject = new GameObject("LaunchAudio");
            launchAudioObject.transform.parent        = audioObject.transform;
            launchAudioObject.transform.localPosition = Vector3.zero;
            launchAudioObject.transform.localRotation = Quaternion.identity;

            AudioSource launchAudioSource = launchAudioObject.AddComponent <AudioSource>();
            launchAudioSource.clip        = launchAudioClip;
            launchAudioSource.playOnAwake = true;
            launchAudioSource.loop        = false;
        }

        // Create the exhaust audio

        if (exhaustAudioClip != null)
        {
            GameObject exhaustAudioObject = new GameObject("ExhaustAudio");
            exhaustAudioObject.transform.parent        = audioObject.transform;
            exhaustAudioObject.transform.localPosition = Vector3.zero;
            exhaustAudioObject.transform.localRotation = Quaternion.identity;

            AudioSource exhaustAudioSource = exhaustAudioObject.AddComponent <AudioSource>();
            exhaustAudioSource.clip        = exhaustAudioClip;
            exhaustAudioSource.playOnAwake = true;
            exhaustAudioSource.loop        = true;
        }

        // ************************ Main Components ***************************

        // Add a rigidbody

        Rigidbody rBody = gameObject.AddComponent <Rigidbody>();

        rBody.useGravity = false;

        // Add the Missile component

        Missile          missile   = gameObject.AddComponent <Missile>();
        SerializedObject missileSO = new SerializedObject(missile);

        missileSO.Update();

        // Add a Target Locker

        TargetLocker     targetLocker   = gameObject.AddComponent <TargetLocker>();
        SerializedObject targetLockerSO = new SerializedObject(targetLocker);

        targetLockerSO.Update();

        targetLockerSO.FindProperty("lockingEnabled").boolValue = false;
        targetLockerSO.ApplyModifiedProperties();

        // Add a target leader

        TargetLeader     targetLeader   = gameObject.AddComponent <TargetLeader>();
        SerializedObject targetLeaderSO = new SerializedObject(targetLeader);

        targetLeaderSO.Update();

        // Add engines

        VehicleEngines3D engines   = gameObject.AddComponent <VehicleEngines3D>();
        SerializedObject enginesSO = new SerializedObject(engines);

        enginesSO.Update();

        // Add a guidance system

        GuidanceController guidanceController   = gameObject.AddComponent <GuidanceController>();
        SerializedObject   guidanceControllerSO = new SerializedObject(guidanceController);

        guidanceControllerSO.Update();

        // Update the guidance system settings
        guidanceControllerSO.FindProperty("engines").objectReferenceValue = engines;
        guidanceControllerSO.ApplyModifiedProperties();

        // Add a Detonator

        Detonator        detonator   = gameObject.AddComponent <Detonator>();
        SerializedObject detonatorSO = new SerializedObject(detonator);

        detonatorSO.Update();

        if (explosion != null)
        {
            detonatorSO.FindProperty("detonatingDuration").floatValue         = 2;
            detonatorSO.FindProperty("detonatingStateSpawnObjects").arraySize = 1;
            detonatorSO.FindProperty("detonatingStateSpawnObjects").GetArrayElementAtIndex(0).objectReferenceValue = explosion;
            detonatorSO.ApplyModifiedProperties();
        }

        UnityEventTools.AddBoolPersistentListener(detonator.onDetonating, engines.SetRigidbodyKinematic, true);
        UnityEventTools.AddBoolPersistentListener(detonator.onDetonated, gameObject.SetActive, false);
        UnityEventTools.AddBoolPersistentListener(detonator.onReset, engines.SetRigidbodyKinematic, false);

        // Add Health Modifier

        HealthModifier   healthModifier   = gameObject.AddComponent <HealthModifier>();
        SerializedObject healthModifierSO = new SerializedObject(healthModifier);

        healthModifierSO.Update();


        if (areaDamage)
        {
            // Add a damage receiver scanner for the area damage

            GameObject areaDamageScannerObject = new GameObject("AreaDamageScanner");
            areaDamageScannerObject.transform.parent        = gameObject.transform;
            areaDamageScannerObject.transform.localPosition = Vector3.zero;
            areaDamageScannerObject.transform.localRotation = Quaternion.identity;

            // Add a kinematic rigidbody

            Rigidbody areaDamageScannerRigidbody = areaDamageScannerObject.AddComponent <Rigidbody>();
            areaDamageScannerRigidbody.isKinematic = true;

            // Add a sphere trigger collider and set the radius

            SphereCollider areaDamageScannerCollider = areaDamageScannerObject.AddComponent <SphereCollider>();
            areaDamageScannerCollider.isTrigger = true;
            areaDamageScannerCollider.radius    = 20;

            // Add a damage receiver scanner

            DamageReceiverScanner areaDamageScanner   = areaDamageScannerObject.AddComponent <DamageReceiverScanner>();
            SerializedObject      areaDamageScannerSO = new SerializedObject(areaDamageScanner);
            areaDamageScannerSO.FindProperty("scannerTriggerCollider").objectReferenceValue = areaDamageScannerCollider;
            areaDamageScannerSO.ApplyModifiedProperties();

            healthModifierSO.FindProperty("areaDamageReceiverScanner").objectReferenceValue = areaDamageScanner;
            healthModifierSO.ApplyModifiedProperties();
        }

        // Add a collision scanner

        CollisionScanner collisionScanner   = gameObject.AddComponent <CollisionScanner>();
        SerializedObject collisionScannerSO = new SerializedObject(collisionScanner);

        collisionScannerSO.Update();

        // Collision scanner settings
        if (areaDamage)
        {
            UnityEventTools.AddPersistentListener(collisionScanner.onHitDetected, healthModifier.RaycastHitAreaDamage);
        }
        else
        {
            UnityEventTools.AddPersistentListener(collisionScanner.onHitDetected, healthModifier.RaycastHitDamage);
        }

        UnityEventTools.AddPersistentListener(collisionScanner.onHitDetected, detonator.Detonate);


        if (targetProximityDetonation)
        {
            // Add a target proximity trigger to the root transform

            TargetProximityTrigger targetProximityTrigger   = gameObject.AddComponent <TargetProximityTrigger>();
            SerializedObject       targetProximityTriggerSO = new SerializedObject(targetProximityTrigger);
            targetProximityTriggerSO.Update();


            // Create an object for the proximity scanner trigger collider

            GameObject proximityTriggerColliderObject = new GameObject("TargetProximityScanner");
            proximityTriggerColliderObject.transform.parent        = gameObject.transform;
            proximityTriggerColliderObject.transform.localPosition = Vector3.zero;
            proximityTriggerColliderObject.transform.localRotation = Quaternion.identity;

            // Add a kinematic rigidbody

            Rigidbody proximityTriggerColliderRigidbody = proximityTriggerColliderObject.AddComponent <Rigidbody>();
            proximityTriggerColliderRigidbody.isKinematic = true;

            // Add a sphere trigger collider and set the radius

            SphereCollider sphereCollider = proximityTriggerColliderObject.AddComponent <SphereCollider>();
            sphereCollider.isTrigger = true;
            sphereCollider.radius    = 20;

            // Add a damage receiver scanner

            DamageReceiverScanner damageReceiverScanner   = proximityTriggerColliderObject.AddComponent <DamageReceiverScanner>();
            SerializedObject      damageReceiverScannerSO = new SerializedObject(damageReceiverScanner);
            damageReceiverScannerSO.Update();

            // Link the collider to the damage receiver scanner

            damageReceiverScannerSO.FindProperty("scannerTriggerCollider").objectReferenceValue = sphereCollider;
            damageReceiverScannerSO.ApplyModifiedProperties();
            damageReceiverScannerSO.Update();

            // Link the scanner to the proximity trigger

            targetProximityTriggerSO.FindProperty("scanner").objectReferenceValue = damageReceiverScanner;
            targetProximityTriggerSO.ApplyModifiedProperties();
            targetProximityTriggerSO.Update();

            UnityEventTools.AddPersistentListener(targetProximityTrigger.onTriggered, healthModifier.EmitDamage);
            UnityEventTools.AddPersistentListener(targetProximityTrigger.onTriggered, detonator.Detonate);

            UnityEventTools.AddPersistentListener(targetLocker.onLocked, targetProximityTrigger.SetTarget);
        }

        // Update the target locker settings

        UnityEventTools.AddPersistentListener(targetLocker.onLocked, targetLeader.SetTarget);
        UnityEventTools.AddVoidPersistentListener(targetLocker.onNoLock, targetLeader.ClearTarget);
        UnityEventTools.AddFloatPersistentListener(targetLocker.onNoLock, detonator.BeginDelayedDetonation, 4);

        // Update the target leader settings
        UnityEventTools.AddPersistentListener(targetLeader.onLeadTargetPositionUpdated, guidanceController.SetTargetPosition);

        missileSO.FindProperty("targetLocker").objectReferenceValue = targetLocker;
        missileSO.ApplyModifiedProperties();
    }
Beispiel #19
0
 // RVA: 0x62CBB0 Offset: 0x62CBB0 VA: 0x62CBB0
 public int ModifyHealth(int delta, List <string> modifier_types, Combatant damage_dealer, float ignoreShieldPercent, HealthModifier source_effect, float shieldDamageFactor = 1)
 {
 }
Beispiel #20
0
 private void HealthCheck()
 {
     health = 0;
     HealthModifier.healthStaminalIncrease();
     health = HealthModifier.maxHealth;
 }
Beispiel #21
0
 public Bleeding(int value)
 {
     Value    = value;
     modifier = new HealthModifier(-value);
 }
    public void Update()
    {
        //if there are systems with higher priority being modified we dont update
        if (highPrioritySystems.Any(system => system.BeingModified))
        {
            return;
        }

        bool currentIsMax  = current == max;
        bool currentIsZero = current == 0f;

        //let each modifier modify this system and remove it if it is finished giving callbacks if the condition is right
        for (int i = activeModifiers.Count - 1; i >= 0; i--)
        {
            HealthModifier modifier = activeModifiers[i];
            modifier.Modify(this);

            bool finished = modifier.Finished;
            if (finished)
            {
                if (queuedModifiers.Count != 0 && queuedModifiers.Any(m => m.Name == modifier.Name))
                {
                    //if there are queued modifiers an one has the same name as this one, replace this one with the queued one
                    for (int j = queuedModifiers.Count - 1; j >= 0; j--)
                    {
                        if (queuedModifiers[j].Name == modifier.Name)
                        {
                            activeModifiers[i] = queuedModifiers[j];
                            queuedModifiers.RemoveAt(j);
                            break;
                        }
                    }
                }
                else
                {
                    //if this modifier cannot be replaced by a queued one, remove it
                    activeModifiers.RemoveAt(i);
                }

                if (activeModifiers.Count(m => m.Regenerate) == 0 && modifier.Regenerate)
                {
                    Debug.Log("stopped regen");
                    //if there are no more regenerating over time modifiers and this one (which was removed) was, the regeneration has ended
                    OnRegenStop?.Invoke();
                }
                else if (activeModifiers.Count(m => !m.Regenerate) == 0 && !modifier.Regenerate)
                {
                    Debug.Log("stopped decay");
                    //if there are no more decay over time modifiers and this one (which was removed) was, the decaying has ended
                    OnDecayStop?.Invoke();
                }

                if (finished)
                {
                    //if the modifier is finished (and thus removed from the list) it can be cleaned up
                    modifier = null;
                }
            }
        }

        //show feedback of data on healthbar and text if showable
        if (healthBar != null)
        {
            healthBar.fillAmount = current / max;
        }
        if (showText && healthText != null)
        {
            healthText.text = $"{Current}/{max}";
        }

        //if current was not equal to max before modification but is now equal after modification, on reached max is called
        if (!currentIsMax && current == max)
        {
            Debug.Log("reached max");
            OnReachedMax?.Invoke();
        }

        //if current was not equal to zero before modification but is now equal after modification, on reached zero is called
        if (!currentIsZero && current == 0f)
        {
            Debug.Log("reached zero");
            OnReachedZero?.Invoke();
        }
    }
Beispiel #23
0
 public void Damage(HealthModifier modifier)
 {
     hitPointSystem.AddModifier(modifier);
 }