/// <summary>
        ///
        /// </summary>
        /// <param name="healthThreshold"></param>
        /// <param name="allowSkip">True will execute the action even if the chunk of health is big enough to reach the next threshold before this one.</param>
        /// <param name="action">The action to execute</param>
        public void AddHealthEvent(float healthThreshold, bool allowSkip, PastaGameLibrary.Action action)
        {
            if (m_healthEvents == null)
            {
                m_healthEvents = new List <HealthEvent>();
            }

            HealthEvent newEvent = new HealthEvent();

            newEvent.action          = action;
            newEvent.healthThreshold = healthThreshold;
            newEvent.allowSkip       = allowSkip;
            if (m_healthEvents.Count == 0)
            {
                m_healthEvents.Add(newEvent);
                return;
            }
            int i;

            for (i = 0; i < m_healthEvents.Count; ++i)
            {
                if (newEvent.healthThreshold > m_healthEvents[i].healthThreshold)
                {
                    break;
                }
            }
            m_healthEvents.Insert(i, newEvent);
        }
Exemple #2
0
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     HealthEvent.RegisterListener(UpdateHealthbar);
     UIEvent.RegisterListener(UpdateUI);
     healthbar     = GetNode <TextureProgress>("Healthbar");
     waveCountDown = GetNode <Label>("CountDown");
 }
	void Spawn(string method, HealthEvent health) {
		if(indicatorPrefab) {
			GameObject go = Instantiate(indicatorPrefab, spawnPosition ? spawnPosition.position : transform.position, transform.rotation) as GameObject;

			go.SendMessage(method, health, SendMessageOptions.DontRequireReceiver);
		}
	}
Exemple #4
0
        /// <summary>
        /// Overloaded ToString function for formatting the output on the console.
        /// </summary>
        /// <param name="healthEvent"> Object of type HealthEvent </param>
        /// <returns>
        /// Returns formatted string.
        /// </returns>
        public static string ToString(HealthEvent healthEvent)
        {
            var strBuilder = new StringBuilder();

            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -25} : {1}", "SourceId", healthEvent.SourceId));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -25} : {1}", "Property", healthEvent.Property));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -25} : {1}", "HealthState", healthEvent.HealthState));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -25} : {1}", "TTL", healthEvent.TimeToLiveInMilliSeconds));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -25} : {1}", "Description", healthEvent.Description));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -25} : {1}", "SequenceNumber", healthEvent.SequenceNumber));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -25} : {1}", "SentAt", healthEvent.SourceUtcTimestamp));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -25} : {1}", "RemoveWhenExpired", healthEvent.RemoveWhenExpired));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -25} : {1}", "IsExpired", healthEvent.IsExpired));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -25} : {1}", "LastOkTransitionAt", healthEvent.LastOkTransitionAt));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -25} : {1}", "LastWarningTransitionAt", healthEvent.LastWarningTransitionAt));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -25} : {1}", "LastErrorTransitionAt", healthEvent.LastErrorTransitionAt));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -25} : {1}", "HealthReportId", healthEvent.HealthReportId));
            strBuilder.Append(Environment.NewLine);

            return(strBuilder.ToString());
        }
Exemple #5
0
 /// <summary>Causes the OnChangeHealth event to be triggered</summary>
 /// <returns>Health change amount</returns>
 public void InvokeOnChangeHealthEvent(HealthEvent healthEvent)
 {
     if (_onChangeHealth != null)
     {
         _onChangeHealth(healthEvent);
     }
 }
Exemple #6
0
        private static void WriteHealth(this HealthEvent he)
        {
            var hi = he.HealthInformation;

            WriteLine($"{he.SourceUtcTimestamp}, {he.LastModifiedUtcTimestamp}, {he.IsExpired}, {he.LastOkTransitionAt}, {he.LastWarningTransitionAt}, {he.LastErrorTransitionAt}");
            WriteLine($"State={hi.HealthState}, Source={hi.SourceId}, Property={hi.Property}, TTL={hi.TimeToLive}, RemoveWhenExpired={hi.RemoveWhenExpired}, Desc={hi.Description}, Seq={hi.SequenceNumber}");
        }
Exemple #7
0
 void OnDeath(HealthEvent health)
 {
     if (spawnOnDeath)
     {
         Spawn("OnDeath", health);
     }
 }
Exemple #8
0
 void OnDamaged(HealthEvent health)
 {
     if (spawnOnDamaged)
     {
         Spawn("OnDamaged", health);
     }
 }
    private void GiveHealth(GameObject player)
    {
        HealthScript playerHealth = player.GetComponent <HealthScript>();                        // Noah: get the players health

        if (playerHealth == null)
        {
            return;
        }

        // Noah: Add to the players health
        playerHealth._currentHealth += _gainAmount;
        if (playerHealth._currentHealth < _maxHealth)
        {
            playerHealth._currentHealth = _maxHealth;
        }

        // Noah: update the health bar
        HealthEvent?.Invoke(HealthPercentage);
        HealthBar.RuntimeSOBar.HealthBarRef.UpdateBar(playerHealth.HealthPercentage);

        // Noah: Instantiate the particles and lerp them to the enemies position
        enemyPosition    = transform.position;
        _healthParticles = Instantiate(_healthParticles, transform.position, transform.rotation);
        _healthParticles.GetComponent <ParticleLerp>().Particle      = _healthParticles;
        _healthParticles.GetComponent <ParticleLerp>().EnemyPosition = enemyPosition;
        AkSoundEngine.PostEvent(_playerGainMana, gameObject);
    }
Exemple #10
0
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, HealthEvent obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            writer.WriteProperty(obj.HealthState, "HealthState", HealthStateConverter.Serialize);
            writer.WriteProperty(obj.SourceId, "SourceId", JsonWriterExtensions.WriteStringValue);
            writer.WriteProperty(obj.Property, "Property", JsonWriterExtensions.WriteStringValue);
            if (obj.TimeToLiveInMilliSeconds != null)
            {
                writer.WriteProperty(obj.TimeToLiveInMilliSeconds, "TimeToLiveInMilliSeconds", JsonWriterExtensions.WriteTimeSpanValue);
            }

            if (obj.Description != null)
            {
                writer.WriteProperty(obj.Description, "Description", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.SequenceNumber != null)
            {
                writer.WriteProperty(obj.SequenceNumber, "SequenceNumber", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.RemoveWhenExpired != null)
            {
                writer.WriteProperty(obj.RemoveWhenExpired, "RemoveWhenExpired", JsonWriterExtensions.WriteBoolValue);
            }

            if (obj.IsExpired != null)
            {
                writer.WriteProperty(obj.IsExpired, "IsExpired", JsonWriterExtensions.WriteBoolValue);
            }

            if (obj.SourceUtcTimestamp != null)
            {
                writer.WriteProperty(obj.SourceUtcTimestamp, "SourceUtcTimestamp", JsonWriterExtensions.WriteDateTimeValue);
            }

            if (obj.LastModifiedUtcTimestamp != null)
            {
                writer.WriteProperty(obj.LastModifiedUtcTimestamp, "LastModifiedUtcTimestamp", JsonWriterExtensions.WriteDateTimeValue);
            }

            if (obj.LastOkTransitionAt != null)
            {
                writer.WriteProperty(obj.LastOkTransitionAt, "LastOkTransitionAt", JsonWriterExtensions.WriteDateTimeValue);
            }

            if (obj.LastWarningTransitionAt != null)
            {
                writer.WriteProperty(obj.LastWarningTransitionAt, "LastWarningTransitionAt", JsonWriterExtensions.WriteDateTimeValue);
            }

            if (obj.LastErrorTransitionAt != null)
            {
                writer.WriteProperty(obj.LastErrorTransitionAt, "LastErrorTransitionAt", JsonWriterExtensions.WriteDateTimeValue);
            }

            writer.WriteEndObject();
        }
Exemple #11
0
 private void UpdateHealthbar(HealthEvent healthEvent)
 {
     //Update the healthbar to the players current health
     if (healthEvent.target.IsInGroup("Player"))
     {
         healthbar.Value = healthEvent.health;
     }
 }
 void Awake()
 {
     OnDamageEvent        = new HealthDamageEvent();
     OnHealEvent          = new HealthEvent();
     OnDeathEvent         = new DeathEvent();
     OnNegatedDamageEvent = new UnityEvent();
     currentHealth        = maxHealth;
 }
 /// <summary>
 /// Adds health
 /// </summary>
 /// <param name="health"></param>
 public void Heal(HealthEvent health)
 {
     if (!disableChanges)
     {
         health.amount = Mathf.Abs(health.amount);
         ChangeHealth(health);
     }
 }
Exemple #14
0
    void Spawn(string method, HealthEvent health)
    {
        if (indicatorPrefab)
        {
            GameObject go = Instantiate(indicatorPrefab, spawnPosition ? spawnPosition.position : transform.position, transform.rotation) as GameObject;

            go.SendMessage(method, health, SendMessageOptions.DontRequireReceiver);
        }
    }
Exemple #15
0
    public void RemoveHealth(float healthToRemove)
    {
        HealthEvent hEvent = ChangeHealth(-Mathf.Abs(healthToRemove));

        if (OnRemoveHealth != null)
        {
            OnAddHealth(hEvent);
        }
    }
Exemple #16
0
    public void AddHealth(float healthToAdd)
    {
        HealthEvent hEvent = ChangeHealth(Mathf.Abs(healthToAdd));

        if (OnAddHealth != null)
        {
            OnAddHealth(hEvent);
        }
    }
Exemple #17
0
        public virtual void Reset()
        {
            OnHurt  = new HealthEvent();
            OnDeath = new HealthEvent();

            Animator        = GetComponentInParent <Animator>();
            HurtTrigger     = "";
            HurtDamageFloat = "";
            DeathTrigger    = "";
        }
Exemple #18
0
        private void Start()
        {
            if (playerHealthDecrease == null)
            {
                playerHealthDecrease = new HealthEvent();
            }
            playerHealthDecrease.AddListener(HealthDecrease);

            StartCoroutine(Regeneration());
        }
 internal EntityHealthEvent(HealthEvent healthEvent)
 {
     Guard.IsNotNull(healthEvent, nameof(healthEvent));
     this.HealthState    = healthEvent.HealthInformation.HealthState;
     this.Description    = healthEvent.HealthInformation.Description;
     this.Property       = healthEvent.HealthInformation.Property;
     this.SequenceNumber = healthEvent.HealthInformation.SequenceNumber;
     this.SourceId       = healthEvent.HealthInformation.SourceId;
     this.IsExpired      = healthEvent.IsExpired;
 }
Exemple #20
0
    /// <summary>Set the <see cref="CurrentValue"/> to a specified value</summary>
    /// <returns>Health change amount</returns>
    public int SetHealth(int value, GameObject effectedGameObject, GameObject effectorGameObject, bool invokeChangeEvent = true)
    {
        int currentHealth = _currentValue;
        var newHealth     = Mathf.Clamp(value, 0, byte.MaxValue);

        if (newHealth < 0)
        {
            newHealth = 0;
        }
        else if (newHealth > _maximumValue)
        {
            newHealth = _maximumValue;
        }

        var healthChange = newHealth - currentHealth;

        if (healthChange != 0)
        {
            HealthEventState eventState;

            if (healthChange > 0)
            {
                if (_incurable)
                {
                    return(0);
                }

                eventState = newHealth == _maximumValue ? HealthEventState.Full : HealthEventState.Healed;
            }
            else
            {
                if (_invincible)
                {
                    return(0);
                }

                eventState = newHealth == 0 ? HealthEventState.Died : HealthEventState.Damaged;
            }

            _currentValue = (byte)newHealth;

            var healthEvent = new HealthEvent(healthChange, _maximumValue - _currentValue, _currentValue, eventState, this, effectedGameObject, effectorGameObject);

            _lastHealthState = eventState;

            if (invokeChangeEvent)
            {
                InvokeOnChangeHealthEvent(healthEvent);
            }

            return(healthChange);
        }

        return(healthChange);
    }
 public HealthEventEntity(HealthEvent healthEvent)
 {
     Assert.IsNotNull(healthEvent, "Health Event can't be null");
     this.IsExpired                = healthEvent.IsExpired;
     this.LastErrorTransitionAt    = healthEvent.LastErrorTransitionAt;
     this.LastModifiedUtcTimestamp = healthEvent.LastModifiedUtcTimestamp;
     this.LastWarningTransitionAt  = healthEvent.LastWarningTransitionAt;
     this.SourceUtcTimestamp       = healthEvent.SourceUtcTimestamp;
     this.HealthInformation        = new HealthInformationEntity(healthEvent.HealthInformation);
     this.LastOkTransitionAt       = healthEvent.LastOkTransitionAt;
 }
Exemple #22
0
    private HealthEvent ChangeHealth(float h)
    {
        previousHealth = currentHealth;
        currentHealth  = Mathf.Clamp(currentHealth + h, 0, maxHealth);
        HealthEvent hEvent = new HealthEvent(previousHealth, currentHealth, this);

        if (OnHealthChange != null)
        {
            OnHealthChange(hEvent);
        }
        return(hEvent);
    }
Exemple #23
0
        public virtual void Awake()
        {
            OnHurt  = OnHurt ?? new HealthEvent();
            OnDeath = OnDeath ?? new HealthEvent();

            InvincibleTimer = 0f;
            Invincible      = false;

            HurtTriggerHash     = Animator.StringToHash(HurtTrigger);
            HurtDamageFloatHash = Animator.StringToHash(HurtDamageFloat);
            DeathTriggerHash    = Animator.StringToHash(DeathTrigger);
        }
Exemple #24
0
    void Start()
    {
        Init();

        if (announceHealth)
        {
            healthEvent = GetComponent <HealthEvent> ();
        }
        if (transform.GetComponent <PlayerController>() != null)
        {
            levelUi = FindObjectOfType <LevelUIController>();
        }
    }
 public ActionResult GetEditForm(int contentId = 0)
 {
     if (contentId != 0)
     {
         IPublishedContent content = Umbraco.Content(contentId);
         HealthEvent       health  = new HealthEvent
         {
             ID          = contentId,
             Title       = content.GetPropertyValue("healthEventTitle").ToString(),
             Description = content.GetPropertyValue("healthEventDescription").ToString(),
             IsReported  = Convert.ToBoolean(content.GetPropertyValue("healthEventReport").ToString())
         };
         return(PartialView(PARTIAL_VIEW_FOLDER + "Edit.cshtml", health));
     }
     return(PartialView(PARTIAL_VIEW_FOLDER + "Edit.cshtml"));
 }
    private void Start()
    {
        animator    = GetComponent <Animator>();
        audioSource = GetComponent <AudioSource>();

        if (onTakeDamage == null)
        {
            onTakeDamage = new HealthEvent();
        }
        onTakeDamage.AddListener(UIManager.instance.ChangeHealth);

        if (onDie == null)
        {
            onDie = new UnityEvent();
        }
        onDie.AddListener(UIManager.instance.Die);
    }
 public ActionResult EditHealth(HealthEvent healthEvent)
 {
     TempData["elemId"] = "health";
     if (ModelState.IsValid)
     {
         IContent content = Services.ContentService.GetById(healthEvent.ID);
         content.SetValue("healthEventTitle", healthEvent.Title);
         content.SetValue("healthEventDescription", healthEvent.Description);
         if (Services.ContentService.SaveAndPublishWithStatus(content).Success)
         {
             TempData["Msg"] = "Health event successfully edited";
             return(PartialView("~/Views/Partials/FormSuccess.cshtml"));
         }
     }
     TempData["Msg"] = "Cannot edit health event";
     return(PartialView("~/Views/Partials/FormError.cshtml"));
 }
Exemple #28
0
	public float ChangeHealth(HealthEvent amount) {
		if(!disableChanges) {
			float healthChange = health;

			health = Mathf.Clamp(health + amount.amount, 0, maxHealth);
			if(OnSetHealth != null) OnSetHealth(health);

			healthChange = health - healthChange;

			HealthEvent received = new HealthEvent(amount.gameObject, healthChange);
			HealthEvent caused = new HealthEvent(gameObject, healthChange);

			if(health == 0) {
				if(healthChange < 0) {
					if(OnDeath != null)
						OnDeath(received);

					if(amount.gameObject != null && OnCausedDeath != null)
						OnCausedDeath(amount.gameObject, caused);
				}
			}
			else {
				if(healthChange > 0) {
					if(OnHealed != null)
						OnHealed(received);

					if(amount.gameObject != null && OnCausedHeal != null)
						OnCausedHeal(amount.gameObject, caused);

				}
				else if(healthChange < 0) {
					if(OnDamaged != null)
						OnDamaged(received);

					if(amount.gameObject != null && OnCausedDamage != null)
						OnCausedDamage(amount.gameObject, caused);
				}
			}
		}

		return health;
	}
Exemple #29
0
    void OnChangeHealth(HealthEvent healthEvent)
    {
        switch (healthEvent.eventState)
        {
        case HealthEventState.Died:
        case HealthEventState.Damaged:
            _timeTillHeal = _healDelay;
            _healSeconds  = 0;

            break;

        case HealthEventState.Full:
            //case HealthEventState.Healed:
            _healSeconds = 0;

            break;
        }

        _propertyBlock.SetColor("_Color", GetLerpedColor());
        UpdateRendererColor();
    }
Exemple #30
0
    public void HealthAction(HealthEvent hEvent)
    {
        Vector2 fromPlayer = (transform.position - pController.transform.position).normalized;

        internalRest      = false;
        internalVelocity += Vector2.up * Mathf.Sqrt(2f * InternalGravity * DamagedBounceHeight);
        velocity         += fromPlayer * 3f;

        switch (hEvent)
        {
        case HealthEvent.Death:
            currentState = OrcState.Dead;
            anim.SetBool("Dead", true);
            rb.mass = 0.1f;
            break;

        case HealthEvent.Hurt:

            break;
        }
    }
Exemple #31
0
    public void HealthAction(HealthEvent hEvent)
    {
        switch (hEvent)
        {
        case HealthEvent.Hurt:
            internalRest = false;
            // Don't bounce past our max bounce height
            float curBounceHeight = DamagedBounceHeight - childSprite.transform.localPosition.y;
            internalVelocity = Vector2.up * Mathf.Sqrt(2f * InternalGravity * curBounceHeight);
            break;

        case HealthEvent.Death:
            anim.SetBool("Dead", true);
            CurrentState = PlayerState.Dead;
            break;

        case HealthEvent.Heal:

            break;
        }
    }
Exemple #32
0
        public JsonResult InsertHealthEvent(HDB context, HealthEvent healthEvent)
        {
            if (context.HealthEvents.Count() > 0)
            {
                if (context.HealthEvents.Select(he => he.ID).Contains(healthEvent.ID))
                {
                    return(Json(new InsertionOutcome {
                        outcome = "Found", ID = healthEvent.ID.ToString()
                    }));
                }
            }
            if (healthEvent.ID < 0)
            {
                healthEvent.ID = 0;
            }
            context.HealthEvents.Add(healthEvent);
            context.SaveChanges();

            return(Json(new InsertionOutcome {
                outcome = "Success", ID = healthEvent.ID.ToString()
            }));
        }
	void OnDamaged(HealthEvent health) {
		if(spawnOnDamaged) Spawn("OnDamaged", health);
	}
 /// <summary>
 /// Adds health
 /// </summary>
 /// <param name="health"></param>
 public void Heal(HealthEvent health)
 {
     if(!disableChanges) {
         health.amount = Mathf.Abs(health.amount);
         ChangeHealth(health);
     }
 }
 public void OnRestored(HealthEvent health)
 {
     if(spawnOnRestored) Spawn("OnRestored", health);
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="healthThreshold"></param>
        /// <param name="allowSkip">True will execute the action even if the chunk of health is big enough to reach the next threshold before this one.</param>
        /// <param name="action">The action to execute</param>
        public void AddHealthEvent(float healthThreshold, bool allowSkip, PastaGameLibrary.Action action)
        {
            if(m_healthEvents == null)
                m_healthEvents = new List<HealthEvent>();

            HealthEvent newEvent = new HealthEvent();
            newEvent.action = action;
            newEvent.healthThreshold = healthThreshold;
            newEvent.allowSkip = allowSkip;
            if (m_healthEvents.Count == 0)
            {
                m_healthEvents.Add(newEvent);
                return;
            }
            int i;
            for (i = 0; i < m_healthEvents.Count; ++i)
                if (newEvent.healthThreshold > m_healthEvents[i].healthThreshold)
                    break;
            m_healthEvents.Insert(i, newEvent);
        }
 void SendOnCausedHeal(GameObject cause, HealthEvent health)
 {
     cause.SendMessage("OnCausedHeal", health, SendMessageOptions.DontRequireReceiver);
 }
 public void OnDeath(HealthEvent health)
 {
     Destroy(destroyThis);
 }
Exemple #39
0
	public void Damage(HealthEvent health) {
		owner.SendMessage("Damage", health, SendMessageOptions.DontRequireReceiver);
	}
	void OnDeath(HealthEvent health) {
		amount = health.amount;
	}
	void OnDamaged(HealthEvent health) {
		amount = health.amount;
	}
	void OnHealed(HealthEvent health) {
		amount = health.amount;
	}
	void OnDeath(HealthEvent health) {
		if(spawnOnDeath) Spawn("OnDeath", health);
	}
 void SendOnHealed(HealthEvent health)
 {
     SendMessage("OnHealed", health, SendMessageOptions.DontRequireReceiver);
 }
	public IEnumerator OnDeath(HealthEvent health) {
		anim.SetTrigger("Death");
		yield return new WaitForSeconds (deathLength);
		Destroy(destroyThis);
	}
	void OnDamaged(HealthEvent gotHit){
		anim.SetTrigger("Damage");
		//yield return new WaitForSeconds (DamageAnimationLength);
	}