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

Water/Thirst system improvements and modifications #69

Merged
merged 14 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/prefabs/blocks/waterCupSource.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
},
"InteractionTarget": {},
"UnbreathableBlock": {},
"WellSource": {},
"WellBlock": {},
"Network": {}
}
3 changes: 2 additions & 1 deletion assets/prefabs/buildings/marketPlace.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"waffles" : 10,
"Blueberry": 1,
"Raspberry": 1,
"Strawberry": 1
"Strawberry": 1,
"emptyCup" : 1
},
"productionInterval" : 100
},
Expand Down
3 changes: 2 additions & 1 deletion assets/prefabs/buildings/templates/wellTemplate.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{ "blockType": "CoreAssets:Cobblestone", "region": { "min": [-1, 0, -2], "size": [1, 1, 1]}},
{ "blockType": "CoreAssets:Cobblestone", "region": { "min": [1, 0, -2], "size": [1, 1, 1]}},
{ "blockType": "CoreAssets:Cobblestone", "region": { "min": [-1, 0, -1], "size": [3, 1, 1]}},
{ "blockType": "CoreAssets:Cobblestone", "region": { "min": [0, 0, -2], "size": [1, 1, 1]}},
{ "blockType": "CoreAssets:Cobblestone:engine:stair.BACK", "region": { "min": [0, 1, -1], "size": [1, 1, 1]}},
{ "blockType": "CoreAssets:Cobblestone:engine:stair.FRONT", "region": { "min": [0, 1, -3], "size": [1, 1, 1]}},
{ "blockType": "CoreAssets:Cobblestone:engine:stair.LEFT", "region": { "min": [-1, 1, -2], "size": [1, 1, 1]}},
Expand All @@ -25,7 +26,7 @@
{ "blockType": "engine:air", "region": { "min": [0, 2, -3], "size": [1, 2, 1]}},
{ "blockType": "engine:air", "region": { "min": [-1, 2, -2], "size": [3, 2, 1]}},
{ "blockType": "engine:air", "region": { "min": [0, 2, -1], "size": [1, 2, 1]}},
{ "blockType": "MetalRenegades:waterCupSource", "region": { "min": [0, 0, -2], "size": [1, 2, 1]}}
{ "blockType": "MetalRenegades:waterCupSource", "region": { "min": [0, 1, -2], "size": [1, 1, 1]}}
]
}
}
4 changes: 4 additions & 0 deletions assets/prefabs/buildings/well.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
},
"SimpleSource": {
"needType": "WATER"
},
"WellSource": {
"refillsLeft": 5,
"capacity": 5
}
}
15 changes: 15 additions & 0 deletions assets/prefabs/items/emptyCup.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"parent": "engine:iconItem",
"DisplayName": {
"name": "Empty Cup"
},
"Item": {
"stackId": "MetalRenegades:emptyCup",
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like that we copy-paste the cup icon around - we should find a way to share this between JS (ManualLabor?) and MetalRenegades. Please have a look at the discussion in Terasology/ManualLabor#31

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah it would be very nice to be able to take some of the more useful parts of ManualLabor without needing to use the more complicated portions of that module. If the fluid containers portion of ML could be separated into it's own module that would be fantastic.

If I remember right I think that a lot of the texture assets in ManualLabor come from a Spritesheet (I had to crop it out of the sheet myself). I don't know how easy that would be to separate into different modules.

"icon" : "MetalRenegades:emptyCup",
"cooldownTime": 500,
"maxStackSize": 1
},
"WaterCup": {
"filled": false
}
}
18 changes: 18 additions & 0 deletions assets/prefabs/items/filledCup.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"parent": "engine:iconItem",
"DisplayName": {
"name": "Filled Cup"
},
"Item": {
"stackId": "MetalRenegades:filledCup",
"icon" : "MetalRenegades:filledCup",
"cooldownTime": 500,
"maxStackSize": 1
},
"Drink": {
"filling": 100
},
"WaterCup": {
"filled": true
}
}
15 changes: 0 additions & 15 deletions assets/prefabs/items/waterCup.prefab

This file was deleted.

Binary file added assets/textures/items/emptyCup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions deltas/engine/prefabs/player.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
{ "uri": "CoreAdvancedAssets:gun", "quantity": 1 },
{ "uri": "CoreAssets:Torch", "quantity": 99 }
]
},
"Thirst": {
"maxWaterCapacity": 200
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public final class MarketItemBuilder {
private static boolean isInitialised = false;

private static void initialise() {
details.put("emptyCup", new MarketItem(
"emptyCup",
"A container to hold refreshing water from wells.",
25
));

details.put("waffles", new MarketItem(
"waffles",
"Hot and fresh waffles.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.metalrenegades.interaction.component;

import org.terasology.entitySystem.Component;

/**
* Component describing the status of particular water cup.
*/
public class WaterCupComponent implements Component {

/**
* True if the cup contains water, false otherwise.
*/
public boolean filled;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.metalrenegades.interaction.component;

import org.terasology.entitySystem.Component;

/**
* Indicates a water source block inside of a well entity, which the player interacts with to gather water.
*/
public class WellBlockComponent implements Component {

}
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
/*
* Copyright 2018 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.
*/
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.metalrenegades.interaction.component;

import org.terasology.entitySystem.Component;

/**
* Indicates a water cup source block, to be used inside wells.
* Indicates a water well entity, that the player can drink from.
*/
public class WellSourceComponent implements Component {

/**
* The number of water refills remaining in this well. Replenishes after a certain period of time.
*/
public int refillsLeft;

/**
* The maximum number of refills that this well can have.
*/
public int capacity;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.metalrenegades.interaction.events;

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

/**
* Fires when a cup item is filled from a well.
*/
public class CupFilledEvent implements Event {

/**
* The entity gathering the water. Assumed to be a player entity.
*/
private final EntityRef gatheringCharacter;

/**
* The new cup item given to the player upon refilling.
*/
private final EntityRef cupItem;

public CupFilledEvent(EntityRef gatheringCharacter, EntityRef cupItem) {
this.gatheringCharacter = gatheringCharacter;
this.cupItem = cupItem;
}

public EntityRef getGatheringCharacter() {
return gatheringCharacter;
}

public EntityRef getCupItem() {
return cupItem;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.metalrenegades.interaction.events;

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

/**
* Fires when a player drinks directly from a well.
*/
public class WellDrinkEvent implements Event {

/**
* The entity drinking the water. Assumed to be a player entity.
*/
private final EntityRef gatheringCharacter;

public WellDrinkEvent(EntityRef gatheringCharacter) {
this.gatheringCharacter = gatheringCharacter;
}

public EntityRef getGatheringCharacter() {
return gatheringCharacter;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.metalrenegades.interaction.events;

import org.terasology.entitySystem.event.Event;

/**
* Fires when a well gains one more refill.
*/
public class WellRefilledEvent implements Event {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.metalrenegades.interaction.systems;

import org.terasology.entitySystem.entity.EntityManager;
import org.terasology.entitySystem.entity.EntityRef;
import org.terasology.entitySystem.event.ReceiveEvent;
import org.terasology.entitySystem.systems.BaseComponentSystem;
import org.terasology.entitySystem.systems.RegisterMode;
import org.terasology.entitySystem.systems.RegisterSystem;
import org.terasology.logic.nameTags.NameTagComponent;
import org.terasology.metalrenegades.interaction.component.WellSourceComponent;
import org.terasology.metalrenegades.interaction.events.CupFilledEvent;
import org.terasology.metalrenegades.interaction.events.WellDrinkEvent;
import org.terasology.metalrenegades.interaction.events.WellRefilledEvent;
import org.terasology.registry.In;
import org.terasology.rendering.nui.Color;
import org.terasology.world.time.WorldTimeEvent;

/**
* Adds tooltips to wells about the number of thirst refills available.
*/
@RegisterSystem(value = RegisterMode.AUTHORITY)
public class WellTooltipSystem extends BaseComponentSystem {

@In
private EntityManager entityManager;

@ReceiveEvent
public void onWorldTimeEvent(WorldTimeEvent worldTimeEvent, EntityRef entityRef) {
for (EntityRef waterSource : entityManager.getEntitiesWith(WellSourceComponent.class)) {
if (waterSource.hasComponent(NameTagComponent.class)) {
continue;
}

NameTagComponent nameTagComponent = new NameTagComponent();
waterSource.addComponent(nameTagComponent);
updateNameTag(waterSource);
}
}

@ReceiveEvent(components = {WellSourceComponent.class, NameTagComponent.class})
public void onCupFilled(CupFilledEvent cupFilledEvent, EntityRef wellEntity) {
updateNameTag(wellEntity);
}

@ReceiveEvent(components = {WellSourceComponent.class, NameTagComponent.class})
public void onWellDrink(WellDrinkEvent wellDrinkEvent, EntityRef wellEntity) {
updateNameTag(wellEntity);
}

@ReceiveEvent(components = {WellSourceComponent.class, NameTagComponent.class})
public void onWellRefill(WellRefilledEvent wellRefilledEvent, EntityRef wellEntity) {
updateNameTag(wellEntity);
}

/**
* Updates the name tag above a well entity to show the number of remaining water refills.
*
* @param wellEntity The well entity to update.
*/
private void updateNameTag(EntityRef wellEntity) {
WellSourceComponent wellSourceComponent = wellEntity.getComponent(WellSourceComponent.class);
NameTagComponent nameTagComponent = wellEntity.getComponent(NameTagComponent.class);
AndyTechGuy marked this conversation as resolved.
Show resolved Hide resolved

nameTagComponent.text = String.format("Drinks: %d/%d", wellSourceComponent.refillsLeft, wellSourceComponent.capacity);
nameTagComponent.textColor = Color.BLUE;
nameTagComponent.yOffset = 2f;
nameTagComponent.scale = 1f;
wellEntity.saveComponent(nameTagComponent);
}

}
Loading