From b3342eb287f380800a7b1c37d67315725e85722e Mon Sep 17 00:00:00 2001 From: E Aakash <09e.aakash@gmail.com> Date: Wed, 26 Jun 2019 10:12:59 +0530 Subject: [PATCH 1/4] Update regen to depend on Health module --- .../RegenerationAlterationEffect.java | 7 +- .../RegenerationAuthoritySystem.java | 84 ------------------- 2 files changed, 5 insertions(+), 86 deletions(-) delete mode 100644 src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAuthoritySystem.java diff --git a/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAlterationEffect.java b/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAlterationEffect.java index 331c34e..d91cad6 100644 --- a/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAlterationEffect.java +++ b/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAlterationEffect.java @@ -22,6 +22,7 @@ import org.terasology.engine.Time; import org.terasology.entitySystem.entity.EntityRef; import org.terasology.logic.delay.DelayManager; +import org.terasology.logic.health.event.ActivateRegenEvent; import org.terasology.math.TeraMath; /** @@ -53,6 +54,7 @@ public RegenerationAlterationEffect(Context context) { * @param magnitude The magnitude of the regen effect. * @param duration The duration of the regen effect. */ + @SuppressWarnings("CheckStyle") @Override public void applyEffect(EntityRef instigator, EntityRef entity, float magnitude, long duration) { // First, determine if the entity already has a regeneration component attached. If so, just replace the amount @@ -124,12 +126,13 @@ else if (!modifiersFound || !effectModifyEvent.getHasInfDuration()) { * * @param instigator The entity who applied the regen effect. * @param entity The entity that the regen effect is being applied on. - * @param id Inapplicable to the regen effect. + * @param id Id is used for unique identification in regen scheduler. * @param magnitude The magnitude of the regen effect. * @param duration The duration of the regen effect. */ @Override public void applyEffect(EntityRef instigator, EntityRef entity, String id, float magnitude, long duration) { - applyEffect(instigator, entity, magnitude, duration); + //applyEffect(instigator, entity, magnitude, duration); + entity.send(new ActivateRegenEvent(id, (int) magnitude, ((float) duration) / 1000)); } } diff --git a/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAuthoritySystem.java b/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAuthoritySystem.java deleted file mode 100644 index 5e2e61e..0000000 --- a/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAuthoritySystem.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2014 MovingBlocks - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.terasology.alterationEffects.regenerate; - -import org.terasology.engine.Time; -import org.terasology.entitySystem.entity.EntityManager; -import org.terasology.entitySystem.entity.EntityRef; -import org.terasology.entitySystem.systems.BaseComponentSystem; -import org.terasology.entitySystem.systems.RegisterMode; -import org.terasology.entitySystem.systems.RegisterSystem; -import org.terasology.entitySystem.systems.UpdateSubscriberSystem; -import org.terasology.logic.health.DoHealEvent; -import org.terasology.logic.health.HealthComponent; -import org.terasology.registry.In; - -/** - * This authority system manages all the regeneration effects currently in-effect across all entities. By that, it - * handles what course of action to take when one expires, and applies the regen at regular intervals. - */ -@RegisterSystem(value = RegisterMode.AUTHORITY) -public class RegenerationAuthoritySystem extends BaseComponentSystem implements UpdateSubscriberSystem { - /** Integer storing when to check each effect. */ - private static final int CHECK_INTERVAL = 100; - - /** Integer storing when to apply regen health */ - private static final int REGENERATION_TICK = 1000; - - /** Last time the list of regen effects were checked. */ - private long lastUpdated; - - @In - private Time time; - @In - private EntityManager entityManager; - - /** - * For every update, check to see if the time's been over the CHECK_INTERVAL. If so, verify if a REGENERATION_TICK - * has passed for every regeneration effect. - * - * @param delta The time (in seconds) since the last engine update. - */ - @Override - public void update(float delta) { - final long currentTime = time.getGameTimeInMs(); - - // If the current time passes the CHECK_INTERVAL threshold, continue. - if (currentTime >= lastUpdated + CHECK_INTERVAL) { - // Set the lastUpdated time to be the currentTime. - lastUpdated = currentTime; - - // For every entity with the health and regeneration components, check to see if they have passed a - // REGENERATION_TICK. If so, apply a heal event to the applicable entities with the given - // regenerationAmount. - for (EntityRef entity : entityManager.getEntitiesWith(RegenerationComponent.class, HealthComponent.class)) { - final RegenerationComponent component = entity.getComponent(RegenerationComponent.class); - if (currentTime >= component.lastRegenerationTime + REGENERATION_TICK) { - // Calculate this multiplier to account for time delays. - int multiplier = (int) (currentTime - component.lastRegenerationTime) / REGENERATION_TICK; - component.lastRegenerationTime = component.lastRegenerationTime + REGENERATION_TICK * multiplier; - - // Save the regen component so that the latest changes don't get lost during exit. - entity.saveComponent(component); - - // Now send the heal event to this entity with the heal strength being the regen amount times the - // multiplier. - entity.send(new DoHealEvent(component.regenerationAmount * multiplier)); - } - } - } - } -} From 0bc5617631144e02376caa005218191ec6b1f723 Mon Sep 17 00:00:00 2001 From: E Aakash <09e.aakash@gmail.com> Date: Wed, 26 Jun 2019 10:27:01 +0530 Subject: [PATCH 2/4] Update other systems to depend on Health module --- .../breath/WaterBreathingAuthoritySystem.java | 2 +- .../damageOverTime/DamageOverTimeAuthoritySystem.java | 2 +- .../alterationEffects/decover/DecoverAuthoritySystem.java | 4 ++-- .../alterationEffects/resist/ResistDamageAuthoritySystem.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/terasology/alterationEffects/breath/WaterBreathingAuthoritySystem.java b/src/main/java/org/terasology/alterationEffects/breath/WaterBreathingAuthoritySystem.java index 58c87b8..e51309a 100644 --- a/src/main/java/org/terasology/alterationEffects/breath/WaterBreathingAuthoritySystem.java +++ b/src/main/java/org/terasology/alterationEffects/breath/WaterBreathingAuthoritySystem.java @@ -20,7 +20,7 @@ import org.terasology.entitySystem.systems.BaseComponentSystem; import org.terasology.entitySystem.systems.RegisterMode; import org.terasology.entitySystem.systems.RegisterSystem; -import org.terasology.logic.health.BeforeDamagedEvent; +import org.terasology.logic.health.event.BeforeDamagedEvent; import org.terasology.world.block.BlockComponent; import org.terasology.world.block.BlockUri; diff --git a/src/main/java/org/terasology/alterationEffects/damageOverTime/DamageOverTimeAuthoritySystem.java b/src/main/java/org/terasology/alterationEffects/damageOverTime/DamageOverTimeAuthoritySystem.java index 472f8c9..c7e51af 100644 --- a/src/main/java/org/terasology/alterationEffects/damageOverTime/DamageOverTimeAuthoritySystem.java +++ b/src/main/java/org/terasology/alterationEffects/damageOverTime/DamageOverTimeAuthoritySystem.java @@ -27,7 +27,7 @@ import org.terasology.entitySystem.systems.RegisterSystem; import org.terasology.entitySystem.systems.UpdateSubscriberSystem; import org.terasology.logic.delay.DelayedActionTriggeredEvent; -import org.terasology.logic.health.DoDamageEvent; +import org.terasology.logic.health.event.DoDamageEvent; import org.terasology.logic.health.HealthComponent; import org.terasology.registry.In; import org.terasology.utilities.Assets; diff --git a/src/main/java/org/terasology/alterationEffects/decover/DecoverAuthoritySystem.java b/src/main/java/org/terasology/alterationEffects/decover/DecoverAuthoritySystem.java index de1f6db..f8d90bc 100644 --- a/src/main/java/org/terasology/alterationEffects/decover/DecoverAuthoritySystem.java +++ b/src/main/java/org/terasology/alterationEffects/decover/DecoverAuthoritySystem.java @@ -20,7 +20,7 @@ import org.terasology.entitySystem.systems.BaseComponentSystem; import org.terasology.entitySystem.systems.RegisterMode; import org.terasology.entitySystem.systems.RegisterSystem; -import org.terasology.logic.health.BeforeHealEvent; +import org.terasology.logic.health.event.BeforeRestoreEvent; /** * This authority system handles events for entities with the decover effect. @@ -35,7 +35,7 @@ public class DecoverAuthoritySystem extends BaseComponentSystem { * @param component The decover component added to entities with the decover effect. */ @ReceiveEvent - public void cancelHeal(BeforeHealEvent event, EntityRef entity, DecoverComponent component) { + public void cancelHeal(BeforeRestoreEvent event, EntityRef entity, DecoverComponent component) { event.consume(); } } diff --git a/src/main/java/org/terasology/alterationEffects/resist/ResistDamageAuthoritySystem.java b/src/main/java/org/terasology/alterationEffects/resist/ResistDamageAuthoritySystem.java index 1a2a1ea..934359c 100644 --- a/src/main/java/org/terasology/alterationEffects/resist/ResistDamageAuthoritySystem.java +++ b/src/main/java/org/terasology/alterationEffects/resist/ResistDamageAuthoritySystem.java @@ -26,7 +26,7 @@ import org.terasology.entitySystem.systems.RegisterMode; import org.terasology.entitySystem.systems.RegisterSystem; import org.terasology.logic.delay.DelayedActionTriggeredEvent; -import org.terasology.logic.health.BeforeDamagedEvent; +import org.terasology.logic.health.event.BeforeDamagedEvent; import org.terasology.registry.In; import java.util.regex.Pattern; From 93f97987de582f720b6b2f02dbfeb37e649a3018 Mon Sep 17 00:00:00 2001 From: E Aakash <09e.aakash@gmail.com> Date: Sat, 29 Jun 2019 13:48:01 +0530 Subject: [PATCH 3/4] Update logic for 0 regen and remove checkstyle supression --- .../regenerate/RegenerationAlterationEffect.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAlterationEffect.java b/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAlterationEffect.java index d91cad6..d4d6006 100644 --- a/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAlterationEffect.java +++ b/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAlterationEffect.java @@ -54,7 +54,6 @@ public RegenerationAlterationEffect(Context context) { * @param magnitude The magnitude of the regen effect. * @param duration The duration of the regen effect. */ - @SuppressWarnings("CheckStyle") @Override public void applyEffect(EntityRef instigator, EntityRef entity, float magnitude, long duration) { // First, determine if the entity already has a regeneration component attached. If so, just replace the amount @@ -133,6 +132,8 @@ else if (!modifiersFound || !effectModifyEvent.getHasInfDuration()) { @Override public void applyEffect(EntityRef instigator, EntityRef entity, String id, float magnitude, long duration) { //applyEffect(instigator, entity, magnitude, duration); - entity.send(new ActivateRegenEvent(id, (int) magnitude, ((float) duration) / 1000)); + if (magnitude != 0) { + entity.send(new ActivateRegenEvent(id, (int) magnitude, ((float) duration) / 1000)); + } } } From c114a658f078fd1a934fabc6b0e79edf8bcf36ae Mon Sep 17 00:00:00 2001 From: E Aakash <09e.aakash@gmail.com> Date: Tue, 2 Jul 2019 14:47:14 +0530 Subject: [PATCH 4/4] Update applyEffect for changes in ActivateRegenEvent --- .../regenerate/RegenerationAlterationEffect.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAlterationEffect.java b/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAlterationEffect.java index d4d6006..743cf52 100644 --- a/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAlterationEffect.java +++ b/src/main/java/org/terasology/alterationEffects/regenerate/RegenerationAlterationEffect.java @@ -133,7 +133,7 @@ else if (!modifiersFound || !effectModifyEvent.getHasInfDuration()) { public void applyEffect(EntityRef instigator, EntityRef entity, String id, float magnitude, long duration) { //applyEffect(instigator, entity, magnitude, duration); if (magnitude != 0) { - entity.send(new ActivateRegenEvent(id, (int) magnitude, ((float) duration) / 1000)); + entity.send(new ActivateRegenEvent(id, magnitude, ((float) duration) / 1000)); } } }