/// <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); }
// 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); } }
/// <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()); }
/// <summary>Causes the OnChangeHealth event to be triggered</summary> /// <returns>Health change amount</returns> public void InvokeOnChangeHealthEvent(HealthEvent healthEvent) { if (_onChangeHealth != null) { _onChangeHealth(healthEvent); } }
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}"); }
void OnDeath(HealthEvent health) { if (spawnOnDeath) { Spawn("OnDeath", health); } }
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); }
/// <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(); }
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); } }
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); } }
public void RemoveHealth(float healthToRemove) { HealthEvent hEvent = ChangeHealth(-Mathf.Abs(healthToRemove)); if (OnRemoveHealth != null) { OnAddHealth(hEvent); } }
public void AddHealth(float healthToAdd) { HealthEvent hEvent = ChangeHealth(Mathf.Abs(healthToAdd)); if (OnAddHealth != null) { OnAddHealth(hEvent); } }
public virtual void Reset() { OnHurt = new HealthEvent(); OnDeath = new HealthEvent(); Animator = GetComponentInParent <Animator>(); HurtTrigger = ""; HurtDamageFloat = ""; DeathTrigger = ""; }
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; }
/// <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; }
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); }
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); }
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")); }
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; }
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(); }
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; } }
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; } }
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); }
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); }