1 #region Copyright & License Information 2 /* 3 * Copyright 2007-2020 The OpenRA Developers (see AUTHORS) 4 * This file is part of OpenRA, which is free software. It is made 5 * available to you under the terms of the GNU General Public License 6 * as published by the Free Software Foundation, either version 3 of 7 * the License, or (at your option) any later version. For more 8 * information, see COPYING. 9 */ 10 #endregion 11 12 using OpenRA.Scripting; 13 using OpenRA.Traits; 14 15 namespace OpenRA.Mods.Common.Scripting 16 { 17 [ScriptPropertyGroup("General")] 18 public class HealthProperties : ScriptActorProperties, Requires<IHealthInfo> 19 { 20 IHealth health; HealthProperties(ScriptContext context, Actor self)21 public HealthProperties(ScriptContext context, Actor self) 22 : base(context, self) 23 { 24 health = self.Trait<IHealth>(); 25 } 26 27 [Desc("Current health of the actor.")] 28 public int Health 29 { 30 get { return health.HP; } 31 set { health.InflictDamage(Self, Self, new Damage(health.HP - value), true); } 32 } 33 34 [Desc("Maximum health of the actor.")] 35 public int MaxHealth { get { return health.MaxHP; } } 36 37 [Desc("Kill the actor.")] Kill()38 public void Kill() 39 { 40 health.InflictDamage(Self, Self, new Damage(health.MaxHP), true); 41 } 42 } 43 } 44