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

Implementing names for characters #49

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.terasology.entitySystem.systems.RegisterMode;
import org.terasology.entitySystem.systems.RegisterSystem;
import org.terasology.entitySystem.systems.UpdateSubscriberSystem;
import org.terasology.logic.common.DisplayNameComponent;
import org.terasology.logic.inventory.InventoryManager;
import org.terasology.logic.inventory.events.GiveItemEvent;
import org.terasology.logic.location.LocationComponent;
Expand All @@ -40,10 +41,15 @@
import org.terasology.metalrenegades.economy.TraderComponent;
import org.terasology.metalrenegades.economy.actions.ShowTradingScreenAction;
import org.terasology.metalrenegades.minimap.events.AddCharacterToOverlayEvent;
import org.terasology.namegenerator.creature.CreatureAssetTheme;
import org.terasology.namegenerator.creature.CreatureNameProvider;
import org.terasology.registry.In;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;

import static org.terasology.namegenerator.creature.CreatureAssetTheme.COUNTRY;
Copy link
Contributor

Choose a reason for hiding this comment

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

As I've requested to change the name list prefix to "Old West" this (and probably other spots) need changes now... 🙄 I'm eager to merge Terasology/NameGenerator#23, though (after renames) 👍

Suggested change
import static org.terasology.namegenerator.creature.CreatureAssetTheme.COUNTRY;
import static org.terasology.namegenerator.creature.CreatureAssetTheme.OLD_WEST;


/**
* Spawns new citizens inside of available buildings with {@link PotentialHomeComponent}.
Expand All @@ -65,6 +71,8 @@ public class CitizenSpawnSystem extends BaseComponentSystem implements UpdateSub
@In
private InventoryManager inventoryManager;

private Random random = new Random();

@Override
public void update(float delta) {
spawnTimer += delta;
Expand Down Expand Up @@ -126,6 +134,12 @@ private EntityRef spawnCitizen(EntityRef homeEntity) {

EntityRef entityRef = entityBuilder.build();

if(entityRef.hasComponent(DisplayNameComponent.class)) {
DisplayNameComponent displayNameComponent = entityRef.getComponent(DisplayNameComponent.class);
CreatureNameProvider creatureNameProvider = new CreatureNameProvider(random.nextLong(), CreatureAssetTheme.COUNTRY);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
CreatureNameProvider creatureNameProvider = new CreatureNameProvider(random.nextLong(), CreatureAssetTheme.COUNTRY);
CreatureNameProvider creatureNameProvider = new CreatureNameProvider(random.nextLong(), CreatureAssetTheme.OLD_WEST);

displayNameComponent.name = creatureNameProvider.generateName();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you also need to save the component again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, will add that. However, I feel like it doesn't really make a difference here.

}

if (entityRef.hasComponent(TraderComponent.class)) {
entityRef.addComponent(createTradeDialogComponent());
setupStartInventory(entityRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@
import org.terasology.entitySystem.prefab.Prefab;
import org.terasology.entitySystem.systems.BaseComponentSystem;
import org.terasology.entitySystem.systems.RegisterSystem;
import org.terasology.logic.common.DisplayNameComponent;
import org.terasology.math.geom.Rect2i;
import org.terasology.math.geom.Vector3f;
import org.terasology.metalrenegades.economy.actions.ShowMarketScreenAction;
import org.terasology.metalrenegades.economy.events.TransactionType;
import org.terasology.metalrenegades.minimap.events.AddCharacterToOverlayEvent;
import org.terasology.namegenerator.creature.CreatureAssetTheme;
import org.terasology.namegenerator.creature.CreatureNameProvider;
import org.terasology.registry.In;
import org.terasology.utilities.Assets;

import java.util.ArrayList;
import java.util.Optional;
import java.util.Random;

/**
* Spawns a market citizen in all markets
Expand All @@ -55,6 +59,8 @@ public class MarketCitizenSpawnSystem extends BaseComponentSystem {

private Logger logger = LoggerFactory.getLogger(MarketCitizenSpawnSystem.class);

Random random = new Random();

@ReceiveEvent(components = GenericBuildingComponent.class)
public void onMarketPlaceSpawn(BuildingEntitySpawnedEvent event, EntityRef entityRef) {
GenericBuildingComponent genericBuildingComponent = entityRef.getComponent(GenericBuildingComponent.class);
Expand All @@ -70,6 +76,11 @@ public void onMarketPlaceSpawn(BuildingEntitySpawnedEvent event, EntityRef entit
SettlementRefComponent settlementRefComponent = entityRef.getComponent(SettlementRefComponent.class);
trader.addComponent(settlementRefComponent);
MarketComponent marketComponent = settlementRefComponent.settlement.getComponent(MarketComponent.class);
if(entityRef.hasComponent(DisplayNameComponent.class)) {
DisplayNameComponent displayNameComponent = entityRef.getComponent(DisplayNameComponent.class);
CreatureNameProvider creatureNameProvider = new CreatureNameProvider(random.nextLong(), CreatureAssetTheme.COUNTRY);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
CreatureNameProvider creatureNameProvider = new CreatureNameProvider(random.nextLong(), CreatureAssetTheme.COUNTRY);
CreatureNameProvider creatureNameProvider = new CreatureNameProvider(random.nextLong(), CreatureAssetTheme.OLD_WEST);

displayNameComponent.name = "shopkeeper " + creatureNameProvider.generateName();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here - save the component after modifying it?

}


DialogComponent dialogComponent = new DialogComponent();
Expand Down