HealthComponent.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading.Tasks;
  5. using MineCase.Engine;
  6. namespace MineCase.Server.Game.Entities.Components
  7. {
  8. internal class HealthComponent : Component
  9. {
  10. public static readonly DependencyProperty<int> MaxHealthProperty =
  11. DependencyProperty.Register<int>("MaxHealth", typeof(HealthComponent));
  12. public static readonly DependencyProperty<int> HealthProperty =
  13. DependencyProperty.Register<int>("Health", typeof(HealthComponent));
  14. public int Health => AttachedObject.GetValue(HealthProperty);
  15. public int MaxHealth => AttachedObject.GetValue(MaxHealthProperty);
  16. public HealthComponent(string name = "health")
  17. : base(name)
  18. {
  19. }
  20. public void SetHealth(int value) =>
  21. AttachedObject.SetLocalValue(HealthProperty, value);
  22. public void SetMaxHealth(int value) =>
  23. AttachedObject.SetLocalValue(MaxHealthProperty, value);
  24. }
  25. }