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 867f112a3839e323aff01c76a598932255645ffb..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..b82cd90e054778b7e1e6e397896a3af71575bff4 --- /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 237ecb7e2e2a593ac3254312f6cbfe6e61d9c875..b9e958e23c2de76ef25ceff16681e5f9fa2b6f7b 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 391568e45ca8796152b1a3095fae2f58e671caa5..c2af8eccc6dbc4b20e399d352c1f2382cd43aedc 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 8bb4ab6748ff53f64b2057bd518e49b539091510..fc89641242c8853e4bf94e93ea1c6f8b6b7554b2 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 9ecac04a9469be490b7cbf142c5428922ef2928b..461ca808634b990019f239692bc3de8c7509813f 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 0e8bc7fbd7acf1834e65d1bb0a3896bd10161f70..c98c2e47952561fdc2f993ab164d844e89a60d34 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 d4cbcf4c5e07a1febea6e66c9baadfb8b65ac0e6..09f5932fc3612fc5c2cde83a072b7371e9fde56c 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 84ac7027097d93a02cf11837cc9ad0769e29ee85..0af1557083ab30ca6def956fc5a269e7f074327a 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 d26bec5408e87be3d62f7fc79a4bbdb64d818163..3076fed16ba077cb2c0d7b49f7f5e9b4e2a41370 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 bc4ca611a211aaeb425fd033ed258b792641e3aa..f9d3d2ba4e67649ebbcac50fac14ab0855fc9b3d 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 62f7acab1cea7b734fd02da0aabf8943d1b1ae6e..a97f5feb03e68a97ea59759adb21216ec020d511 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