protected override void OnExecuteEvent(VEntity entity) { LowLevelDealDamageEvent damageEvent = entity.GetVComponent <LowLevelDealDamageEvent>(); if (damageEvent.damageAmount <= 0) { return; } VEntity damageDealtEntity = ecsManager.GetVEntityById(damageEvent.receiverId); HealthComponent h = VEntityComponentSystemManager.GetVComponent <HealthComponent>(damageDealtEntity); h.currHealth -= damageEvent.damageAmount; if (h.currHealth <= 0) { h.currHealth = 0; ecsManager.CreateEvent("unitDeath", component: new DeathEventComponent { id = damageDealtEntity.id }); } ecsManager.QueueAnimationEvent("setHealth", components: new VComponent[] { new HealthSetAnimationEvent { targetEntity = damageDealtEntity.id, currHealth = h.currHealth, maxHealth = h.maxHealth }, new UnitDamagedAnimationEvent { targetEntity = damageDealtEntity.id } }); }
protected override void OnBeforeEvent(VEntity entity) { LowLevelDealDamageEvent dealDamage = entity.GetVComponent <LowLevelDealDamageEvent>(); VEntity blockingEntity = ecsManager.GetVEntityById(dealDamage.receiverId); BlockBuffComponent block = blockingEntity.GetVComponent <BlockBuffComponent>(); if (block != null) { int blockDeduct = Math.Min(block.blockAmount, dealDamage.damageAmount); block.blockAmount -= blockDeduct; dealDamage.damageAmount -= blockDeduct; if (blockingEntity.HasVComponent <BlockDisplayComponent>()) { int newBlockAmount = block.blockAmount; NumberedIconDisplay blockDisplay = blockingEntity.GetVComponent <BlockDisplayComponent>().blockDisplay; ecsManager.QueueAnimationEvent("blockRemoveEvent", component: new GenericBlockingAnimationEvent { a = (passedEcsManager) => { blockDisplay.transform.DOShakePosition(.5f, .1f); blockDisplay.SetValue(newBlockAmount); }, duration = 0.5f }); } } }