private void HandleTakeDamage(GameEvent_TakeDamage ev) { var slottedContainer = this.Parent.GetComponentOfType <Component_SlottedContainer>(); if (slottedContainer == null) { return; } int remainingSlottedStructure = GetRemainingSlottedStructure(slottedContainer); if (remainingSlottedStructure == 0) { return; } else if (ev.DamageRemaining >= remainingSlottedStructure) { ev.Notify_DamageTaken(remainingSlottedStructure); for (int i = 0; i < remainingSlottedStructure; i++) { this.AssignDamagePoint(slottedContainer); } } else { int damageToTake = ev.DamageRemaining; for (int i = 0; i < damageToTake; i++) { this.AssignDamagePoint(slottedContainer); } ev.Notify_DamageTaken(damageToTake); } }
public void TestTakeDamageWithNoSlottedEntities() { var ev = new GameEvent_TakeDamage(3); this.bodyPart.HandleEvent(ev); Assert.AreEqual(0, ev.DamageRemaining); Assert.IsTrue(ev.Completed); Assert.AreEqual(7, this.bodyPart.GetComponentOfType <Component_InternalStructure>().StructureRemaining); }
public void CanTakeDamageOverflowsProperly() { var ev = new GameEvent_TakeDamage(20); this.internalStructure.HandleEvent(ev); Assert.AreEqual(10, ev.DamageRemaining); Assert.IsFalse(ev.Completed); Assert.AreEqual(0, this.internalStructure.GetComponentOfType <Component_InternalStructure>().StructureRemaining); }
public void CanTakeExactDamage() { var ev = new GameEvent_TakeDamage(10); this.internalStructure.HandleEvent(ev); Assert.AreEqual(0, ev.DamageRemaining); Assert.IsTrue(ev.Completed); Assert.AreEqual(0, this.internalStructure.GetComponentOfType <Component_InternalStructure>().StructureRemaining); }
public void TestTakeDamageFallsThrough() { Entity tinySlotted = this.SlotEntityWithStructure(this.bodyPart, 5); var ev = new GameEvent_TakeDamage(100); this.bodyPart.HandleEvent(ev); Assert.AreEqual(85, ev.DamageRemaining); Assert.IsFalse(ev.Completed); Assert.AreEqual(0, this.bodyPart.GetComponentOfType <Component_InternalStructure>().StructureRemaining); Assert.AreEqual(0, tinySlotted.GetComponentOfType <Component_InternalStructure>().StructureRemaining); }
public void TestTakeDamageWithSlottedEntities() { Entity slotted = this.SlotEntityWithStructure(this.bodyPart, 5); var ev = new GameEvent_TakeDamage(3); this.bodyPart.HandleEvent(ev); Assert.AreEqual(0, ev.DamageRemaining); Assert.IsTrue(ev.Completed); Assert.AreEqual(this.structureMax, this.bodyPart.GetComponentOfType <Component_InternalStructure>().StructureRemaining); Assert.AreEqual(2, slotted.GetComponentOfType <Component_InternalStructure>().StructureRemaining); }
private void HandleTakeDamage(GameEvent_TakeDamage ev) { if (ev.DamageRemaining >= this.StructureRemaining) { ev.Notify_DamageTaken(this.StructureRemaining); this.structureDestroyed += this.StructureRemaining; } else { int damageToTake = ev.DamageRemaining; this.structureDestroyed += damageToTake; ev.Notify_DamageTaken(damageToTake); } }
public void TestAssignsDamageToLargestSlottedEntity() { Entity tinySlotted = this.SlotEntityWithStructure(this.bodyPart, 3); Entity hugeSlotted = this.SlotEntityWithStructure(this.bodyPart, 9999); var ev = new GameEvent_TakeDamage(100); this.bodyPart.HandleEvent(ev); Assert.AreEqual(0, ev.DamageRemaining); Assert.IsTrue(ev.Completed); Assert.AreEqual(this.structureMax, this.bodyPart.GetComponentOfType <Component_InternalStructure>().StructureRemaining); Assert.AreEqual(3, tinySlotted.GetComponentOfType <Component_InternalStructure>().StructureRemaining); Assert.AreEqual(9899, hugeSlotted.GetComponentOfType <Component_InternalStructure>().StructureRemaining); }
private void AssignDamagePoint(Component_SlottedContainer slottedContainer) { // Damge from the BOTTOM UP, so that the hand goes last // TODO: Maybe kinda counterintuitive? var target = slottedContainer.InspectStoredEntities() .Where(e => this.GetRemainingInternalStructure(e) > 0) .Reverse() .First(); var damageEvent = new GameEvent_TakeDamage(1); target.HandleEvent(damageEvent); if (!damageEvent.Completed) { throw new ArgumentException("Target didn't take damage when it should have!"); } }
// Since there is no damage transfer, will *always* complete the event! private void HandleTakeDamage(GameEvent_TakeDamage ev) { throw new NotImplementedException(); }