using CoreGame; using Proto; namespace CoreGame.Render { public class Trigger_OnLossHp : TriggerBase { // self.param1 为计数, // 若 triggerCfg.Param2 不为0,每损失百分比的生命值触发 // 否则,损失百分比生命值触发一次后每次损失生命值都会触发 public override void OnEvent(TriggerSpec self, int eventId, object param1) { if (self.param1.intVal <= 0) self.param1.intVal = 1; if (OnTrigger(self, eventId, param1)) { if (triggerCfg.param2 != 0) //计数 { self.param1.intVal += 1; } } } public override bool OnPreExecuteCheck(TriggerSpec self, int eventId, object param1) { var rate = 1f - triggerCfg.param1 / 100f * self.param1.intVal ; var prop = self.owner.property; if (prop == null) return false; var curHp = prop.GetProperty_Long(PropertyDef.CurHp); var maxHp = prop.TotalHp; return (float)curHp / maxHp < rate; } public override void Init(TriggerSpec self) { RegEntityEvent(self, ClientEvent.OnLossHp); } public override void UnInit(TriggerSpec self) { UnRegEntityEvent(self, ClientEvent.OnLossHp); } } }