Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle less than 1 regen and removing Regen logic #10

Merged
merged 5 commits into from Jun 15, 2019

Conversation

e-aakash
Copy link
Member

@e-aakash e-aakash commented Jun 11, 2019

Solves #9

How to test:

  1. Create a new game with BSG and Health module
  2. Attack more than one block
  3. They get properly regenerated, without throwing an exception

How to test multiplayer

  1. Create a server
  2. Join using another client
  3. Attack each other
  4. Both get regenerated

@e-aakash e-aakash changed the title Handle less than 1 regen Handle less than 1 regen and removing Regen logic Jun 12, 2019
Copy link
Member

@syntaxi syntaxi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Structure of the system looks good, only small issues here and there.

invokeRegenOperations(currentTime);
if (currentTime > lastTick + CHECK_INTERVAL) {
invokeRegenOperations(currentTime);
lastTick = currentTime;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very minor point but to reduce the work done every frame you should do the addition of CHECK_INTERVAL here and not in the if condition

entity.removeComponent(RegenComponent.class);
entity.send(new OnFullyHealedEvent(entity));
}
entity.saveComponent(health);
}
}
for (Long endTime : regenToBeRemoved) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you feel like being fancy you can use a lambda here.
Not suggesting that you do do this, leaving it as a loop is clear. But just giving you more info.

public void onRegenRemoved(DeactivateRegenEvent event, EntityRef entity, HealthComponent health,
RegenComponent regen) {
regenSortedByTime.remove(regen.getLowestEndTime(), entity);
if (event.id.equals("all")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get these strings ("all" and "baseRegen") as public static fields.

for (float value: regenValue.values()) {
totalValue += value;
}
if (totalValue < 0) {
totalValue = 0;
remainder = Math.min(1, remainder);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually do

remainder = totalValue % 1 //modulo 1

To get the remainder when dividing by 1.
This saves you having to floor to int and then subtract to get the return value

RegenComponent regen = entity.getComponent(RegenComponent.class);
HealthComponent health = entity.getComponent(HealthComponent.class);
if (health.nextRegenTick < currentTime) {
if (health != null && health.nextRegenTick < currentTime) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added null check because NPE is thrown when blocks are destroyed.

@@ -33,6 +33,7 @@
import org.terasology.logic.health.event.OnFullyHealedEvent;
import org.terasology.protobuf.EntityData;
import org.terasology.registry.In;
import org.terasology.world.generation.BaseFacetedWorldGenerator;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidental import?

@Cervator Cervator merged commit 6b98375 into Terasology:master Jun 15, 2019
@Cervator
Copy link
Member

Tested out and merged :-)

I added a tiny commit to remove a few unused bits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants