From 3c402eb09d3fd44b706be23980ee4de17e08d453 Mon Sep 17 00:00:00 2001 From: Liru Date: Sun, 17 May 2020 23:24:01 +0200 Subject: [PATCH] Add basic Health implementation --- Seraphina/Health.cs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Seraphina/Health.cs diff --git a/Seraphina/Health.cs b/Seraphina/Health.cs new file mode 100644 index 0000000..f5a0096 --- /dev/null +++ b/Seraphina/Health.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Text; + +using Seraphina.Core; + +namespace Seraphina +{ + public class Health + { + public HitPoint Current { get; set; } + public HitPoint Max { get; set; } + + /// + /// The percentage of health remaining. + /// + public double Percent => Current.Value * 100.0 / Max.Value; + + /// + /// Indicates if the owner of this health component is incapacitated, ie, has <= 0 HP left. + /// + public bool IsIncapacitated => Current <= 0; + + /// + /// Indicates the missing amount of HitPoint on this component. Returns 0 if overhealed. + /// + public HitPoint Missing => Current > Max ? 0 : Max - Current; + + public Color GetColor() => PlayerHealthColor.GetColor(Current, Max); + + public (int num, int remainder) Div(int numerator, int denominator) + { + var result = Current.Value * numerator / denominator; + + return (result, Current.Value - result); + } + + } +}