Skip to content

Commit

Permalink
Merge branch 'develop' into fix/prevent-npe-on-player-death
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrueckert authored Dec 4, 2021
2 parents b724a97 + eb642ca commit 8d205a0
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 1 deletion.
5 changes: 5 additions & 0 deletions deltas/CombatSystem/prefabs/items/staff.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Item": {
"cooldownTime": 300
}
}
9 changes: 9 additions & 0 deletions deltas/CombatSystem/prefabs/items/sword.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Item": {
"cooldownTime": 500
},
"RandomDamage": {
"minDamage": 20,
"maxDamage": 25
}
}
9 changes: 9 additions & 0 deletions deltas/CombatSystem/prefabs/items/waraxe.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Item": {
"cooldownTime": 1000
},
"RandomDamage": {
"minDamage": 30,
"maxDamage": 40
}
}
5 changes: 5 additions & 0 deletions deltas/CombatSystem/prefabs/projectiles/fireBall.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Hurting": {
"amount": 10
}
}
5 changes: 5 additions & 0 deletions deltas/CombatSystem/prefabs/projectiles/spearThrow.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Hurting": {
"amount": 90
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,43 @@
// SPDX-License-Identifier: Apache-2.0
package org.terasology.module.lightandshadow.systems;

import org.terasology.economy.components.AllowShopScreenComponent;
import org.terasology.economy.ui.MarketUiClientSystem;
import org.terasology.engine.core.SimpleUri;
import org.terasology.engine.entitySystem.entity.EntityManager;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.entitySystem.entity.lifecycleEvents.OnAddedComponent;
import org.terasology.engine.entitySystem.event.EventPriority;
import org.terasology.engine.entitySystem.event.ReceiveEvent;
import org.terasology.engine.entitySystem.systems.BaseComponentSystem;
import org.terasology.engine.entitySystem.systems.RegisterMode;
import org.terasology.engine.entitySystem.systems.RegisterSystem;
import org.terasology.engine.input.InputSystem;
import org.terasology.engine.logic.players.LocalPlayer;
import org.terasology.engine.logic.players.event.LocalPlayerInitializedEvent;
import org.terasology.engine.network.ClientComponent;
import org.terasology.engine.registry.In;
import org.terasology.engine.rendering.nui.NUIManager;
import org.terasology.engine.unicode.EnclosedAlphanumerics;
import org.terasology.gestalt.assets.ResourceUrn;
import org.terasology.input.ButtonState;
import org.terasology.input.Input;
import org.terasology.module.inventory.input.InventoryButton;
import org.terasology.module.lightandshadow.events.GameStartMessageEvent;
import org.terasology.module.lightandshadow.events.TimerEvent;
import org.terasology.notifications.events.ExpireNotificationEvent;
import org.terasology.notifications.events.ShowNotificationEvent;
import org.terasology.notifications.model.Notification;
import org.terasology.notify.ui.DialogNotificationOverlay;
import org.terasology.nui.Color;
import org.terasology.nui.FontColor;

import java.util.Timer;
import java.util.TimerTask;

@RegisterSystem(RegisterMode.CLIENT)
public class ClientPregameSystem extends BaseComponentSystem {
private static final String NOTIFICATION_ID = "LightAndShadow:firstTimeShop";

public static final ResourceUrn ASSET_URI = new ResourceUrn("LightAndShadow:Timer");

Expand All @@ -30,6 +48,9 @@ public class ClientPregameSystem extends BaseComponentSystem {

private static Timer timer;

@In
InputSystem inputSystem;

@In
private EntityManager entityManager;
@In
Expand All @@ -54,6 +75,7 @@ public void shutdown() {
public void onPregameStart(GameStartMessageEvent event, EntityRef entity) {
if (localPlayer.getClientEntity().equals(entity)) {
window.addNotification(PREGAME_MESSAGE);
entity.upsertComponent(AllowShopScreenComponent.class, c -> c.orElse(new AllowShopScreenComponent()));
}
}

Expand Down Expand Up @@ -83,5 +105,57 @@ public void run() {
}
}

/**
* Handles the button event if in-game shop is enabled.
* Needs to have a higher priority than {@link MarketUiClientSystem#onToggleInventory(InventoryButton, EntityRef)}
* to receive the {@link InventoryButton} event before it is consumed.
*
* @param event the help button event.
* @param entity the entity to display the help screen to.
*/
@ReceiveEvent(components = {ClientComponent.class, AllowShopScreenComponent.class}, priority = EventPriority.PRIORITY_CRITICAL)
public void onInGameShopButton(InventoryButton event, EntityRef entity) {
if (event.getState() == ButtonState.DOWN) {
entity.send(new ExpireNotificationEvent(NOTIFICATION_ID));
}
}

/**
* Get a formatted representation of the primary {@link Input} associated with the given button binding.
*
* If the display name of the primary bound key is a single character this representation will be the encircled
* character. Otherwise the full display name is used. The bound key will be printed in yellow.
*
* If no key binding was found the text "n/a" in red color is returned.
*
* @param button the URI of a bindable button
* @return a formatted text to be used as representation for the player
*/
//TODO: put this in a common place? Duplicated in Dialogs, EventualSkills, and InGameHelp
private String getActivationKey(SimpleUri button) {
return inputSystem.getInputsForBindButton(button).stream()
.findFirst()
.map(Input::getDisplayName)
.map(key -> {
if (key.length() == 1) {
// print the key in yellow within a circle
int off = key.charAt(0) - 'A';
char code = (char) (EnclosedAlphanumerics.CIRCLED_LATIN_CAPITAL_LETTER_A + off);
return String.valueOf(code);
} else {
return key;
}
})
.map(key -> FontColor.getColored(key, Color.yellow))
.orElse(FontColor.getColored("n/a", Color.red));
}

@ReceiveEvent(components = AllowShopScreenComponent.class)
public void onShopComponentAdded(OnAddedComponent event, EntityRef entity) {
Notification notification = new Notification(NOTIFICATION_ID,
"Shut Up and Take My Money!",
"Press " + getActivationKey(new SimpleUri("Inventory:inventory")) + " to buy items",
"Economy:GoldCoin");
localPlayer.getClientEntity().send(new ShowNotificationEvent(notification));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
@RegisterSystem(RegisterMode.CLIENT)
public class ClientStatisticsSystem extends BaseComponentSystem {
private static final String NOTIFICATION_ID = "LightAndShadow:firstTime";
private static final String NOTIFICATION_ID = "LightAndShadow:firstTimeStatistics";

@In
InputSystem inputSystem;
Expand Down Expand Up @@ -88,6 +88,18 @@ public void onTab(TapButton event, EntityRef entity) {
}
}

/**
* Get a formatted representation of the primary {@link Input} associated with the given button binding.
*
* If the display name of the primary bound key is a single character this representation will be the encircled
* character. Otherwise the full display name is used. The bound key will be printed in yellow.
*
* If no key binding was found the text "n/a" in red color is returned.
*
* @param button the URI of a bindable button
* @return a formatted text to be used as representation for the player
*/
//TODO: put this in a common place? Duplicated in Dialogs, EventualSkills, and InGameHelp
private String getActivationKey(SimpleUri button) {
return inputSystem.getInputsForBindButton(button).stream()
.findFirst()
Expand Down

0 comments on commit 8d205a0

Please sign in to comment.