diff --git a/src/main/java/com/comandante/creeper/npc/Npc.java b/src/main/java/com/comandante/creeper/npc/Npc.java index 7b6a51c6c43c354ea0226bd18f210e0ecee7564e..159973a7c2d8ec5a412e1b017516b16bf6a984b5 100644 --- a/src/main/java/com/comandante/creeper/npc/Npc.java +++ b/src/main/java/com/comandante/creeper/npc/Npc.java @@ -2,6 +2,7 @@ package com.comandante.creeper.npc; import com.comandante.creeper.common.AttackMessage; +import com.comandante.creeper.common.ColorizedTextTemplate; import com.comandante.creeper.core_game.GameManager; import com.comandante.creeper.core_game.SentryManager; import com.comandante.creeper.entity.CreeperEntity; @@ -65,11 +66,6 @@ public class Npc extends CreeperEntity { private final Experience experience = new Experience(); private final Set<AttackMessage> attackMessages; - - public Set<AttackMessage> getAttackMessages() { - return 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) { this.gameManager = gameManager; this.name = name; @@ -459,4 +455,17 @@ public class Npc extends CreeperEntity { } return null; } + + public Set<AttackMessage> getAttackMessages() { + return attackMessages; + } + + public String buildAttackMessage(String playerName) { + AttackMessage 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()); + } } diff --git a/src/main/java/com/comandante/creeper/player/Player.java b/src/main/java/com/comandante/creeper/player/Player.java index f58812c3006719ae4d35a8e7fbb90f5404dc9631..ac16c9282756cbc82550a533fc59137c52efae48 100644 --- a/src/main/java/com/comandante/creeper/player/Player.java +++ b/src/main/java/com/comandante/creeper/player/Player.java @@ -1372,7 +1372,7 @@ public class Player extends CreeperEntity { int chanceToHitBack = npcDamageProcessor.getChanceToHit(this, npc); long damageBack = npcDamageProcessor.getAttackAmount(this, npc); if (randInt(0, 100) < chanceToHitBack) { - final String fightMsg = Color.BOLD_ON + Color.RED + "[attack] " + Color.RESET + npc.getColorName() + Color.BOLD_ON + Color.RED + " DAMAGES" + Color.RESET + " you for " + Color.RED + "-" + NumberFormat.getNumberInstance(Locale.US).format(damageBack) + Color.RESET; + final String fightMsg = Color.BOLD_ON + Color.RED + "[attack] " + Color.RESET + npc.buildAttackMessage(this.getPlayerName()) + " -" + NumberFormat.getNumberInstance(Locale.US).format(damageBack) + Color.RESET; npcStatsChangeBuilder.setPlayerStatsChange(new StatsBuilder().setCurrentHealth(-damageBack).createStats()); npcStatsChangeBuilder.setPlayerDamageStrings(Collections.singletonList(fightMsg));