From 17901a35729ae57f4abc77729380b4c4cfca8748 Mon Sep 17 00:00:00 2001 From: Chris Kearney <chris@kearneymail.com> Date: Mon, 15 May 2017 21:32:36 -0700 Subject: [PATCH] CHANGED ALL THESE MESSAGES --- .../creeper/common/AttackMessage.java | 26 ------- .../creeper/common/CreeperMessage.java | 26 +++++++ .../java/com/comandante/creeper/npc/Npc.java | 58 ++++++++++++--- .../comandante/creeper/npc/NpcBuilder.java | 36 ++++++++-- .../creeper/storage/NpcMetadata.java | 39 +++++++++-- .../common/ColorizedTextTemplateTest.java | 70 +++++++++---------- world/npcs/blood_wolf.json | 24 +++++-- world/npcs/demon_cat.json | 24 +++++-- world/npcs/red-eyed_bear.json | 24 +++++-- world/npcs/swamp_bear.json | 24 +++++-- world/npcs/swamp_berserker.json | 24 +++++-- world/npcs/tree_berserker.json | 32 +++++---- 12 files changed, 285 insertions(+), 122 deletions(-) delete mode 100644 src/main/java/com/comandante/creeper/common/AttackMessage.java create mode 100644 src/main/java/com/comandante/creeper/common/CreeperMessage.java diff --git a/src/main/java/com/comandante/creeper/common/AttackMessage.java b/src/main/java/com/comandante/creeper/common/AttackMessage.java deleted file mode 100644 index 867f112a..00000000 --- a/src/main/java/com/comandante/creeper/common/AttackMessage.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.comandante.creeper.common; - - -public class AttackMessage { - - private final Type type; - private final String attackMessage; - - public AttackMessage(Type type, String attackMessage) { - this.type = type; - this.attackMessage = attackMessage; - } - - public Type getType() { - return type; - } - - public String getAttackMessage() { - return attackMessage; - } - - public enum Type { - NORMAL, - CRITICAL - } -} diff --git a/src/main/java/com/comandante/creeper/common/CreeperMessage.java b/src/main/java/com/comandante/creeper/common/CreeperMessage.java new file mode 100644 index 00000000..b82cd90e --- /dev/null +++ b/src/main/java/com/comandante/creeper/common/CreeperMessage.java @@ -0,0 +1,26 @@ +package com.comandante.creeper.common; + + +public class CreeperMessage { + + private final Type type; + private final String message; + + public CreeperMessage(Type type, String message) { + this.type = type; + this.message = message; + } + + public Type getType() { + return type; + } + + public String getMessage() { + return message; + } + + public enum Type { + NORMAL, + CRITICAL + } +} diff --git a/src/main/java/com/comandante/creeper/npc/Npc.java b/src/main/java/com/comandante/creeper/npc/Npc.java index 237ecb7e..b9e958e2 100644 --- a/src/main/java/com/comandante/creeper/npc/Npc.java +++ b/src/main/java/com/comandante/creeper/npc/Npc.java @@ -1,8 +1,8 @@ package com.comandante.creeper.npc; -import com.comandante.creeper.common.AttackMessage; import com.comandante.creeper.common.ColorizedTextTemplate; +import com.comandante.creeper.common.CreeperMessage; import com.comandante.creeper.core_game.GameManager; import com.comandante.creeper.core_game.SentryManager; import com.comandante.creeper.entity.CreeperEntity; @@ -64,9 +64,31 @@ public class Npc extends CreeperEntity { private int effectsTickBucket = 0; private Set<CoolDown> coolDowns = Sets.newHashSet(); private final Experience experience = new Experience(); - private final Set<AttackMessage> attackMessages; - - protected Npc(GameManager gameManager, String name, String colorName, long lastPhraseTimestamp, Stats stats, String dieMessage, Temperament temperament, Set<Area> roamAreas, Set<String> validTriggers, Loot loot, Set<SpawnRule> spawnRules, Set<AttackMessage> attackMessages) { + // The messages used when dealing damage + private final Set<CreeperMessage> attackMessages; + // The messages used when landing critical attacks + private final Set<CreeperMessage> criticalAttackMessages; + // Things the NPC randomly says during battle + private final Set<CreeperMessage> battleMessages; + // Things that npcs say randomly when idle + private final Set<CreeperMessage> idleMessages; + + + protected Npc(GameManager gameManager, + String name, + String colorName, + long lastPhraseTimestamp, + Stats stats, + String dieMessage, + Temperament temperament, + Set<Area> roamAreas, + Set<String> validTriggers, + Loot loot, + Set<SpawnRule> spawnRules, + Set<CreeperMessage> attackMessages, + Set<CreeperMessage> criticalAttackMessages, + Set<CreeperMessage> battleMessages, + Set<CreeperMessage> idleMessages) { this.gameManager = gameManager; this.name = name; this.colorName = colorName; @@ -79,7 +101,9 @@ public class Npc extends CreeperEntity { this.spawnRules = spawnRules; this.temperament = temperament; this.attackMessages = attackMessages; - + this.criticalAttackMessages = criticalAttackMessages; + this.battleMessages = battleMessages; + this.idleMessages = idleMessages; } @Override @@ -443,16 +467,16 @@ public class Npc extends CreeperEntity { } } - public AttackMessage getRandomAttackMessage() { + public CreeperMessage getRandomAttackMessage() { if (attackMessages == null || attackMessages.size() == 0) { - return new AttackMessage(AttackMessage.Type.NORMAL, "Somebody for got to configure attack messages. - " + this.getName()); + return new CreeperMessage(CreeperMessage.Type.NORMAL, "Somebody for got to configure attack messages. - " + this.getName()); } int size = attackMessages.size(); int item = random.nextInt(size); // In real life, the Random object should be rather more shared than this int i = 0; - for(AttackMessage attackMessage : attackMessages) { + for(CreeperMessage attackMessage : attackMessages) { if (i == item) { return attackMessage; } @@ -461,16 +485,28 @@ public class Npc extends CreeperEntity { return null; } - public Set<AttackMessage> getAttackMessages() { + public Set<CreeperMessage> getAttackMessages() { return attackMessages; } public String buildAttackMessage(String playerName) { - AttackMessage randomAttackMessage = getRandomAttackMessage(); + CreeperMessage randomAttackMessage = getRandomAttackMessage(); Map<String, String> valueMap = Maps.newHashMap(); valueMap.put("player-name", playerName); valueMap.put("npc-name", this.getName()); valueMap.put("npc-color-name", this.getColorName()); - return ColorizedTextTemplate.renderFromTemplateLanguage(valueMap, randomAttackMessage.getAttackMessage()); + return ColorizedTextTemplate.renderFromTemplateLanguage(valueMap, randomAttackMessage.getMessage()); + } + + public Set<CreeperMessage> getCriticalAttackMessages() { + return criticalAttackMessages; + } + + public Set<CreeperMessage> getBattleMessages() { + return battleMessages; + } + + public Set<CreeperMessage> getIdleMessages() { + return idleMessages; } } diff --git a/src/main/java/com/comandante/creeper/npc/NpcBuilder.java b/src/main/java/com/comandante/creeper/npc/NpcBuilder.java index 391568e4..c2af8ecc 100644 --- a/src/main/java/com/comandante/creeper/npc/NpcBuilder.java +++ b/src/main/java/com/comandante/creeper/npc/NpcBuilder.java @@ -1,6 +1,6 @@ package com.comandante.creeper.npc; -import com.comandante.creeper.common.AttackMessage; +import com.comandante.creeper.common.CreeperMessage; import com.comandante.creeper.core_game.GameManager; import com.comandante.creeper.items.Loot; import com.comandante.creeper.spawner.SpawnRule; @@ -24,7 +24,14 @@ public class NpcBuilder { private Loot loot; private Set<SpawnRule> spawnRules; private Temperament temperament; - private Set<AttackMessage> attackMessages; + // The messages used when dealing damage + private Set<CreeperMessage> attackMessages; + // The messages used when landing critical attacks + private Set<CreeperMessage> criticalAttackMessages; + // Things the NPC randomly says during battle + private Set<CreeperMessage> battleMessages; + // Things that npcs say randomly when idle + private Set<CreeperMessage> idleMessages; public NpcBuilder() { } @@ -42,6 +49,9 @@ public class NpcBuilder { this.gameManager = npc.getGameManager(); this.temperament = npc.getTemperament(); this.attackMessages = npc.getAttackMessages(); + this.criticalAttackMessages = npc.getCriticalAttackMessages(); + this.battleMessages = npc.getBattleMessages(); + this.idleMessages = npc.getIdleMessages(); } public NpcBuilder(NpcMetadata npcMetadata) { @@ -55,6 +65,9 @@ public class NpcBuilder { this.spawnRules = npcMetadata.getSpawnRules(); this.temperament = npcMetadata.getTemperament(); this.attackMessages = npcMetadata.getAttackMessages(); + this.criticalAttackMessages = npcMetadata.getCriticalAttackMessages(); + this.battleMessages = npcMetadata.getBattleMessages(); + this.idleMessages = npcMetadata.getIdleMessages(); } public NpcBuilder setGameManager(GameManager gameManager) { @@ -112,16 +125,31 @@ public class NpcBuilder { return this; } - public NpcBuilder setAttackMessages(Set<AttackMessage> attackMessages) { + public NpcBuilder setAttackMessages(Set<CreeperMessage> attackMessages) { this.attackMessages = attackMessages; return this; } + public NpcBuilder setCriticalAttackMessages(Set<CreeperMessage> criticalAttackMessages) { + this.criticalAttackMessages = criticalAttackMessages; + return this; + } + + public NpcBuilder setBattleMessages(Set<CreeperMessage> battleMessages) { + this.battleMessages = battleMessages; + return this; + } + + public NpcBuilder setIdleMessages(Set<CreeperMessage> idleMessages) { + this.idleMessages = idleMessages; + return this; + } + public Npc createNpc() { checkNotNull(gameManager); if (loot.getLootGoldMin() > loot.getLootGoldMax()) { throw new RuntimeException("Invalid loot configuration."); } - return new Npc(gameManager, name, colorName, lastPhraseTimestamp, stats, dieMessage, temperament, roamAreas, validTriggers, loot, spawnRules, attackMessages); + return new Npc(gameManager, name, colorName, lastPhraseTimestamp, stats, dieMessage, temperament, roamAreas, validTriggers, loot, spawnRules, attackMessages, criticalAttackMessages, battleMessages, idleMessages); } } \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/storage/NpcMetadata.java b/src/main/java/com/comandante/creeper/storage/NpcMetadata.java index 8bb4ab67..fc896412 100644 --- a/src/main/java/com/comandante/creeper/storage/NpcMetadata.java +++ b/src/main/java/com/comandante/creeper/storage/NpcMetadata.java @@ -1,6 +1,6 @@ package com.comandante.creeper.storage; -import com.comandante.creeper.common.AttackMessage; +import com.comandante.creeper.common.CreeperMessage; import com.comandante.creeper.items.Loot; import com.comandante.creeper.npc.Temperament; import com.comandante.creeper.spawner.SpawnRule; @@ -20,16 +20,47 @@ public class NpcMetadata { private Set<String> validTriggers; private Set<SpawnRule> spawnRules; private Loot loot; - private Set<AttackMessage> attackMessages; + // The messages used when dealing damage + private Set<CreeperMessage> attackMessages; + // The messages used when landing critical attacks + private Set<CreeperMessage> criticalAttackMessages; + // Things the NPC randomly says during battle + private Set<CreeperMessage> battleMessages; + // Things that npcs say randomly when idle + private Set<CreeperMessage> idleMessages; public NpcMetadata() { } - public Set<AttackMessage> getAttackMessages() { + public Set<CreeperMessage> getCriticalAttackMessages() { + return criticalAttackMessages; + } + + public void setCriticalAttackMessages(Set<CreeperMessage> criticalAttackMessages) { + this.criticalAttackMessages = criticalAttackMessages; + } + + public Set<CreeperMessage> getBattleMessages() { + return battleMessages; + } + + public void setBattleMessages(Set<CreeperMessage> battleMessages) { + this.battleMessages = battleMessages; + } + + public Set<CreeperMessage> getIdleMessages() { + return idleMessages; + } + + public void setIdleMessages(Set<CreeperMessage> idleMessages) { + this.idleMessages = idleMessages; + } + + public Set<CreeperMessage> getAttackMessages() { return attackMessages; } - public void setAttackMessages(Set<AttackMessage> attackMessages) { + public void setAttackMessages(Set<CreeperMessage> attackMessages) { this.attackMessages = attackMessages; } diff --git a/src/test/com/comandante/creeper/common/ColorizedTextTemplateTest.java b/src/test/com/comandante/creeper/common/ColorizedTextTemplateTest.java index 9ecac04a..461ca808 100644 --- a/src/test/com/comandante/creeper/common/ColorizedTextTemplateTest.java +++ b/src/test/com/comandante/creeper/common/ColorizedTextTemplateTest.java @@ -1,10 +1,10 @@ package com.comandante.creeper.common; -import com.comandante.creeper.items.ItemMetadata; import com.comandante.creeper.items.Loot; -import com.comandante.creeper.merchant.MerchantMetadata; import com.comandante.creeper.server.player_communication.Color; -import com.comandante.creeper.storage.*; +import com.comandante.creeper.storage.FilebasedJsonStorage; +import com.comandante.creeper.storage.NpcMetadata; +import com.comandante.creeper.storage.NpcStorage; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import com.google.gson.Gson; @@ -72,38 +72,38 @@ public class ColorizedTextTemplateTest { } }); - - MerchantStorage merchantStorage = new MerchantStorage(null, new FilebasedJsonStorage(gson)); - List<MerchantMetadata> merchantMetadatas = merchantStorage.getMerchantMetadatas(); - - merchantMetadatas.forEach(new Consumer<MerchantMetadata>() { - @Override - public void accept(MerchantMetadata merchantMetadata) { - - System.out.println(merchantMetadata.getColorName()); - try { - merchantStorage.saveMerchantMetadata(merchantMetadata); - } catch (IOException e) { - e.printStackTrace(); - } - } - }); - - ItemStorage itemStorage = new ItemStorage(new FilebasedJsonStorage(gson)); - - itemStorage.getItemMetadatas().forEach(new Consumer<ItemMetadata>() { - @Override - public void accept(ItemMetadata itemMetadata) { - System.out.println(itemMetadata.getItemName()); - try { - itemStorage.saveItemMetadata(itemMetadata); - } catch (IOException e) { - - - } - - } - }); +// +// MerchantStorage merchantStorage = new MerchantStorage(null, new FilebasedJsonStorage(gson)); +// List<MerchantMetadata> merchantMetadatas = merchantStorage.getMerchantMetadatas(); +// +// merchantMetadatas.forEach(new Consumer<MerchantMetadata>() { +// @Override +// public void accept(MerchantMetadata merchantMetadata) { +// +// System.out.println(merchantMetadata.getColorName()); +// try { +// merchantStorage.saveMerchantMetadata(merchantMetadata); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// }); + +// ItemStorage itemStorage = new ItemStorage(new FilebasedJsonStorage(gson)); +// +// itemStorage.getItemMetadatas().forEach(new Consumer<ItemMetadata>() { +// @Override +// public void accept(ItemMetadata itemMetadata) { +// System.out.println(itemMetadata.getItemName()); +// try { +// itemStorage.saveItemMetadata(itemMetadata); +// } catch (IOException e) { +// +// +// } +// +// } +// }); String green = Color.GREEN; String test = "\u001b[32m"; diff --git a/world/npcs/blood_wolf.json b/world/npcs/blood_wolf.json index 0e8bc7fb..c98c2e47 100644 --- a/world/npcs/blood_wolf.json +++ b/world/npcs/blood_wolf.json @@ -56,19 +56,33 @@ "attackMessages": [ { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ jumps into the air toward @player-name@!" + "message": "The @npc-color-name@ tries to bite @player-name@ in the leg!" }, { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ tries to bite @player-name@ in the leg!" + "message": "The @npc-color-name@ growls and charges slightly at @player-name@!" }, { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ growls and charges slightly at @player-name@!" - }, + "message": "The @npc-color-name@ howls maniacally to call its pack!" + } + ], + "criticalAttackMessages": [ + { + "type": "NORMAL", + "message": "The @npc-color-name@ jumps into the air toward and lands a critical attack! @player-name@!" + } + ], + "battleMessages": [ + { + "type": "NORMAL", + "message": "The @npc-color-name@ jumps into the air toward @player-name@!" + } + ], + "idleMessages": [ { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ howls maniacally to call its pack!" + "message": "A @npc-color-name@ scratches it\u0027s nose." } ] } \ No newline at end of file diff --git a/world/npcs/demon_cat.json b/world/npcs/demon_cat.json index d4cbcf4c..09f5932f 100644 --- a/world/npcs/demon_cat.json +++ b/world/npcs/demon_cat.json @@ -48,19 +48,33 @@ "attackMessages": [ { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ hisses and growls at @player-name@!" + "message": "The @npc-color-name@ tries to bite @player-name@ in the leg!" }, { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ attempts to bite @player-name@!" + "message": "The @npc-color-name@ growls and charges slightly at @player-name@!" }, { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ runs toward @player-name@ with exposed teeth!" - }, + "message": "The @npc-color-name@ howls maniacally to call its pack!" + } + ], + "criticalAttackMessages": [ + { + "type": "NORMAL", + "message": "The @npc-color-name@ jumps into the air toward and lands a critical attack! @player-name@!" + } + ], + "battleMessages": [ + { + "type": "NORMAL", + "message": "The @npc-color-name@ jumps into the air toward @player-name@!" + } + ], + "idleMessages": [ { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ attempts to scratch @player-name@!" + "message": "A @npc-color-name@ scratches it\u0027s nose." } ] } \ No newline at end of file diff --git a/world/npcs/red-eyed_bear.json b/world/npcs/red-eyed_bear.json index 84ac7027..0af15570 100644 --- a/world/npcs/red-eyed_bear.json +++ b/world/npcs/red-eyed_bear.json @@ -63,23 +63,33 @@ "attackMessages": [ { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ growls and charges at @player-name@!" + "message": "The @npc-color-name@ tries to bite @player-name@ in the leg!" }, { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ stomps around and charges at @player-name@!" + "message": "The @npc-color-name@ growls and charges slightly at @player-name@!" }, { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ swipes its paw toward @player-name@'s head!" - }, + "message": "The @npc-color-name@ howls maniacally to call its pack!" + } + ], + "criticalAttackMessages": [ { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ extends its claws and swings at @player-name@!" - }, + "message": "The @npc-color-name@ jumps into the air toward and lands a critical attack! @player-name@!" + } + ], + "battleMessages": [ + { + "type": "NORMAL", + "message": "The @npc-color-name@ jumps into the air toward @player-name@!" + } + ], + "idleMessages": [ { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ opens its jaws and attempts to bite @player-name@!" + "message": "A @npc-color-name@ scratches it\u0027s nose." } ] } \ No newline at end of file diff --git a/world/npcs/swamp_bear.json b/world/npcs/swamp_bear.json index d26bec54..3076fed1 100644 --- a/world/npcs/swamp_bear.json +++ b/world/npcs/swamp_bear.json @@ -62,23 +62,33 @@ "attackMessages": [ { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ growls and charges at @player-name@!" + "message": "The @npc-color-name@ tries to bite @player-name@ in the leg!" }, { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ stomps around and charges at @player-name@!" + "message": "The @npc-color-name@ growls and charges slightly at @player-name@!" }, { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ swipes its paw toward @player-name@'s head!" - }, + "message": "The @npc-color-name@ howls maniacally to call its pack!" + } + ], + "criticalAttackMessages": [ { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ extends its claws and swings at @player-name@!" - }, + "message": "The @npc-color-name@ jumps into the air toward and lands a critical attack! @player-name@!" + } + ], + "battleMessages": [ + { + "type": "NORMAL", + "message": "The @npc-color-name@ jumps into the air toward @player-name@!" + } + ], + "idleMessages": [ { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ opens its jaws and attempts to bite @player-name@!" + "message": "A @npc-color-name@ scratches it\u0027s nose." } ] } \ No newline at end of file diff --git a/world/npcs/swamp_berserker.json b/world/npcs/swamp_berserker.json index bc4ca611..f9d3d2ba 100644 --- a/world/npcs/swamp_berserker.json +++ b/world/npcs/swamp_berserker.json @@ -51,19 +51,33 @@ "attackMessages": [ { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ swings a berserker baton at @player-name@!" + "message": "The @npc-color-name@ tries to bite @player-name@ in the leg!" }, { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ charges at @player-name@!" + "message": "The @npc-color-name@ growls and charges slightly at @player-name@!" }, { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ wildly swings its fists at @player-name@!" - }, + "message": "The @npc-color-name@ howls maniacally to call its pack!" + } + ], + "criticalAttackMessages": [ + { + "type": "NORMAL", + "message": "The @npc-color-name@ jumps into the air toward and lands a critical attack! @player-name@!" + } + ], + "battleMessages": [ + { + "type": "NORMAL", + "message": "The @npc-color-name@ jumps into the air toward @player-name@!" + } + ], + "idleMessages": [ { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ foams at the mouth and lunges at @player-name@!" + "message": "A @npc-color-name@ scratches it\u0027s nose." } ] } \ No newline at end of file diff --git a/world/npcs/tree_berserker.json b/world/npcs/tree_berserker.json index 62f7acab..a97f5feb 100644 --- a/world/npcs/tree_berserker.json +++ b/world/npcs/tree_berserker.json @@ -42,30 +42,36 @@ "maxPerRoom": 6 } ], - "loot": { - "internalItemNames": [ - "beserker baton", - "beserker boots" - ], - "lootGoldMax": 14, - "lootGoldMin": 8 - }, "attackMessages": [ { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ swings a berserker baton at @player-name@!" + "message": "The @npc-color-name@ tries to bite @player-name@ in the leg!" }, { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ charges at @player-name@!" + "message": "The @npc-color-name@ growls and charges slightly at @player-name@!" }, { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ wildly swings its fists at @player-name@!" - }, + "message": "The @npc-color-name@ howls maniacally to call its pack!" + } + ], + "criticalAttackMessages": [ + { + "type": "NORMAL", + "message": "The @npc-color-name@ jumps into the air toward and lands a critical attack! @player-name@!" + } + ], + "battleMessages": [ + { + "type": "NORMAL", + "message": "The @npc-color-name@ jumps into the air toward @player-name@!" + } + ], + "idleMessages": [ { "type": "NORMAL", - "attackMessage": "The @npc-color-name@ foams at the mouth and lunges at @player-name@!" + "message": "A @npc-color-name@ scratches it\u0027s nose." } ] } \ No newline at end of file -- GitLab