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

Add javadoc to restore events and RestorationAuthoritySystem #17

Merged
merged 4 commits into from
Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
import org.terasology.logic.players.event.OnPlayerRespawnedEvent;
import org.terasology.math.TeraMath;

/**
* This system takes care of restoration of entities with HealthComponent.
* To increase the health of an entity, send DoRestoreEvent
* <p>
* Logic flow for restoration:
* - DoRestoreEvent
Copy link
Member

Choose a reason for hiding this comment

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

This is too big to consider as part of this PR (since the same word is in use many other places) but I wonder if do is a good term in general for the starting phase of an event chain like this one. "Do" to me very much means that the thing is happening right now. Maybe "Perform" would give a better impression that it is more like an action that is being performed, almost like a stage play might be going through several phases to arrive at an action :-)

This could be overly subjective as interpreting these kinds of words may differ subtly between individuals.

* - BeforeRestoreEvent
* - (HealthComponent saved)
* - OnRestoredEvent
* - OnFullyHealedEvent (if healed to full health)
*/
@RegisterSystem(RegisterMode.AUTHORITY)
public class RestorationAuthoritySystem extends BaseComponentSystem {

Expand All @@ -39,7 +50,8 @@ public void onRestore(DoRestoreEvent event, EntityRef entity, HealthComponent he
if (modifiedRestoreAmount > 0) {
restore(entity, health, modifiedRestoreAmount);
} else {
entity.send(new DoDamageEvent(-modifiedRestoreAmount));
// Cause "healing" damage to entity if modified value of restoration is negative
entity.send(new DoDamageEvent(-modifiedRestoreAmount, EngineDamageTypes.HEALING.get()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,14 @@
* Modifications are accumulated as modifiers (additions), multipliers and postModifiers (additions after multipliers).
*/
public class BeforeRestoreEvent extends AbstractConsumableValueModifiableEvent {
/** The entity which is being regenerated. */
/** The entity which is being restored. */
private EntityRef entity;

/**
* Constructor to create a new BeforeRestoreEvent.
*
* @param amount The amount by which the entity is restored.
* @param entity The entity which is being restored.
*/
public BeforeRestoreEvent(int amount, EntityRef entity) {
super(amount);
this.entity = entity;
}

/**
* Method to get the EntityRef of entity being restored.
* @return Entity being restored.
*/
public EntityRef getEntity() {
return entity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.terasology.logic.health.event;

import org.terasology.entitySystem.entity.EntityRef;
import org.terasology.entitySystem.event.Event;

/**
Expand All @@ -23,20 +24,23 @@
public class DoRestoreEvent implements Event {
/** The amount of health points being restored. */
private int amount;
/** The entity that caused the restoration */
private EntityRef instigator;

/**
* Constructor for event providing amount of restoration.
* @param amount The amount of restoration.
*/
public DoRestoreEvent(int amount) {
this(amount, EntityRef.NULL);
}

public DoRestoreEvent(int amount, EntityRef entity) {
this.amount = amount;
this.instigator = entity;
}

/**
* Method to get the amount of restoration.
* @return amount of regeneration.
*/
public int getAmount() {
return amount;
}

public EntityRef getInstigator() {
return instigator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@

import org.terasology.entitySystem.entity.EntityRef;

/**
* This event is sent after the entity is restored. Final event of restoration logic.
*/
public class OnRestoredEvent extends HealthChangedEvent {
/**
* The amount by which the entity is restored.
*/
private int amount;

public OnRestoredEvent(int amount, EntityRef instigator) {
Expand Down