Skip to content
76 changes: 49 additions & 27 deletions Core/Game/Abilities/Essential/Health.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,29 @@ public class Health : Ability
[SerializeField, FixedNumber]
private long _maxHealth = FixedMath.One * 100;

public long BaseHealth {get {return _maxHealth;}}
public long BaseHealth { get { return _maxHealth; } }

public long MaxHealth
{
get { return _maxHealth + MaxHealthModifier; }
}

private long _maxHealthModifier;
[Lockstep (true)]
public long MaxHealthModifier {
get {

[Lockstep(true)]
public long MaxHealthModifier
{
get
{
return _maxHealthModifier;
}
set {
if (value != _maxHealthModifier) {
set
{
if (value != _maxHealthModifier)
{
long dif = _maxHealthModifier - value;
if (dif > 0) {
if (dif > 0)
{
this.TakeDamage(-dif);
_maxHealthModifier = value;
}
Expand All @@ -39,16 +45,21 @@ public long DamageMultiplier
set;
}

public event Action onHealthChange ;
public event Action<long> onHealthDelta;
public event Action onHealthChange;
public event Action<long> onHealthDelta;

public bool CanLose {
get {
public bool CanLose
{
get
{
return HealthAmount > 0;
}
}
public bool CanGain {
get {

public bool CanGain
{
get
{
return HealthAmount < MaxHealth;
}
}
Expand All @@ -64,17 +75,17 @@ public long HealthAmount
}
set
{
long delta = value - _currentHealth;
long delta = value - _currentHealth;
_currentHealth = value;
if (onHealthChange != null)
onHealthChange();
if (onHealthDelta != null)
onHealthDelta (delta);
if (onHealthDelta != null)
onHealthDelta(delta);
}

}

public LSAgent LastDamageSource { get; set;}
public LSAgent LastDamageSource { get; set; }

protected override void OnSetup()
{
Expand All @@ -85,7 +96,7 @@ protected override void OnInitialize()
HealthAmount = MaxHealth;
OnTakeProjectile = null;
MaxHealthModifier = 0;
LastDamageSource = null;
LastDamageSource = null;
}

public void TakeProjectile(LSProjectile projectile)
Expand All @@ -99,14 +110,16 @@ public void TakeProjectile(LSProjectile projectile)
TakeDamage(projectile.CheckExclusiveDamage(Agent.Tag));
}
}

public void TakeDamage(long damage, LSAgent source = null)
{
if (damage >= 0)
{
damage.Mul(DamageMultiplier);
HealthAmount -= damage;
if (source != null)
LastDamageSource = source;
if (source != null)
LastDamageSource = source;

// don't let the health go below zero
if (HealthAmount <= 0)
{
Expand All @@ -117,24 +130,33 @@ public void TakeDamage(long damage, LSAgent source = null)
Die();
return;
}

}
}
else {
} else
{
HealthAmount -= damage;
if (HealthAmount >= this.MaxHealth) {
if (HealthAmount >= this.MaxHealth)
{
HealthAmount = MaxHealth;
}
}

}

public event Action<Health,LSAgent> onDie;

public void Die()
{
AgentController.DestroyAgent(Agent);
if (Agent.Animator.IsNotNull())
if (Agent.IsActive)
{
Agent.SetState(AnimState.Dying);
Agent.Animator.Visualize();
if (onDie != null)
this.onDie(this,this.LastDamageSource);
AgentController.DestroyAgent(Agent);
if (Agent.Animator.IsNotNull())
{
Agent.SetState(AnimState.Dying);
Agent.Animator.Visualize();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Core/Game/Abilities/Essential/Scan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ protected void CallExtraOnHit(LSAgent agent )
protected virtual void OnHit(LSAgent agent)
{
Health healther = agent.GetAbility<Health>();
healther.TakeDamage(Damage);
healther.TakeDamage(Damage, this.Agent);
CallExtraOnHit(agent);
}

Expand Down
176 changes: 88 additions & 88 deletions Core/Game/Abilities/Extra/SelectionRing/SelectionRing.cs
Original file line number Diff line number Diff line change
@@ -1,89 +1,89 @@
using UnityEngine;
using System.Collections;
namespace Lockstep
{
public class SelectionRing : MonoBehaviour
{
[SerializeField]
private Color _selectedColor = new Color(0f, .6f, 0f);
Color SelectedColor { get { return _selectedColor; } }
[SerializeField]
private Color _highlightedColor = new Color(0f, .7f, 0f, .5f);
Color HighlightedColor { get { return _highlightedColor; } }
[SerializeField]
private Color _noneColor = new Color(0, 0, 0, 0);
Color NoneColor { get { return _noneColor; } }
Renderer cachedRenderer;
public void Setup(float size)
{
this.OnSetup();
this.SetSize(size);
this.SetState(SelectionRingState.None);
}
protected virtual void OnSetup()
{
cachedRenderer = GetComponent<Renderer>();
}
private Color _tint;
public Color Tint
{
get
{
return _tint;
}
set
{
if (_tint != value)
{
_tint = value;
SetState(lastState);
}
}
}
SelectionRingState lastState;
public void SetState(SelectionRingState state)
{
Color setColor = default(Color);
switch (state)
{
case SelectionRingState.Selected:
setColor = SelectedColor;
break;
case SelectionRingState.Highlighted:
setColor = HighlightedColor;
break;
case SelectionRingState.None:
setColor = NoneColor;
break;
}
if (Tint != Color.clear)
setColor = setColor / 4 + Tint;
SetColor(setColor);
lastState = state;
}
public virtual void SetColor(Color color)
{
cachedRenderer.material.color = color;
}
public virtual void SetSize(float size)
{
if (size <= 0.0f)
{
size = 1.0f;
}
transform.localScale = Vector3.one * size;
}
}
using UnityEngine;
using System.Collections;

namespace Lockstep
{
public class SelectionRing : MonoBehaviour
{
[SerializeField]
private Color _selectedColor = new Color(0f, .6f, 0f);
Color SelectedColor { get { return _selectedColor; } }

[SerializeField]
private Color _highlightedColor = new Color(0f, .7f, 0f, .5f);
Color HighlightedColor { get { return _highlightedColor; } }

[SerializeField]
private Color _noneColor = new Color(0, 0, 0, 0);
Color NoneColor { get { return _noneColor; } }

Renderer cachedRenderer;

public void Setup(float size)
{
this.OnSetup();
this.SetSize(size);
this.SetState(SelectionRingState.None);
}
protected virtual void OnSetup()
{
cachedRenderer = GetComponent<Renderer>();
}

private Color _tint;
public Color Tint
{
get
{
return _tint;
}
set
{
if (_tint != value)
{
_tint = value;
SetState(lastState);
}
}
}

SelectionRingState lastState;
public void SetState(SelectionRingState state)
{
Color setColor = default(Color);
switch (state)
{
case SelectionRingState.Selected:
setColor = SelectedColor;
break;
case SelectionRingState.Highlighted:
setColor = HighlightedColor;
break;
case SelectionRingState.None:
setColor = NoneColor;
break;
}
if (Tint != Color.clear)
setColor = setColor / 4 + Tint;
SetColor(setColor);
lastState = state;
}

public virtual void SetColor(Color color)
{
cachedRenderer.material.color = color;

}

public virtual void SetSize(float size)
{
if (size <= 0.0f)
{
size = 1.0f;
}
transform.localScale = Vector3.one * size;
}


}
}
Loading