Version 1.7

Can now add/edit "custom-name" entries to the config via
"/tbm-edit custom". These entries only apply to mobs with a matching
custom name.
This commit is contained in:
Stephen Seo 2018-10-26 13:35:20 +09:00
parent d17aee5994
commit aa229036ad
12 changed files with 261 additions and 55 deletions

View file

@ -1,3 +1,15 @@
# Version 1.7
Fix bug where after using "/tbm-edit", ignore_battle option is saved in
config with the wrong name.
Add "/tbm-edit custom", which lets an OP add an entity entry for entities with
custom names (via name-tags). The entry added into the config file will use
"custom_name" instead of "name" to specify if it is a regular entity entry
or an entry for a specific custom name.
Minor fixes and improvements.
# Version 1.6 # Version 1.6
Fix bug where player can start battle with self. Fix bug where player can start battle with self.

View file

@ -11,7 +11,7 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'com.github.johnrengelman.shadow'
version = "1.6" version = "1.7"
group = "com.seodisparate.TurnBasedMinecraft" group = "com.seodisparate.TurnBasedMinecraft"
archivesBaseName = "TurnBasedMinecraft" archivesBaseName = "TurnBasedMinecraft"

View file

@ -5,6 +5,7 @@ import java.util.Iterator;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage; import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketEditingMessage; import com.seodisparate.TurnBasedMinecraft.common.networking.PacketEditingMessage;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketGeneralMessage;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
@ -74,21 +75,41 @@ public class AttackEventHandler
{ {
editingInfo.isPendingEntitySelection = false; editingInfo.isPendingEntitySelection = false;
event.setCanceled(true); event.setCanceled(true);
editingInfo.entityInfo = config.getMatchingEntityInfo(event.getEntity()); if(editingInfo.isEditingCustomName)
{
if(event.getEntity().getCustomNameTag().isEmpty())
{
TurnBasedMinecraftMod.logger.error("Cannot edit custom name from entity without custom name");
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Cannot edit custom name from entity without custom name"), (EntityPlayerMP) editingInfo.editor);
return;
}
editingInfo.entityInfo = config.getCustomEntityInfo(event.getEntity().getCustomNameTag());
if(editingInfo.entityInfo == null)
{
editingInfo.entityInfo = new EntityInfo();
editingInfo.entityInfo.customName = event.getEntity().getCustomNameTag();
}
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Editing custom name \"" + event.getEntity().getCustomNameTag() + "\""), (EntityPlayerMP) editingInfo.editor);
TurnBasedMinecraftMod.logger.info("Begin editing custom \"" + event.getEntity().getCustomNameTag() + "\"");
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP) editingInfo.editor);
}
else
{
editingInfo.entityInfo = config.getMatchingEntityInfo(event.getEntity()).clone();
if(editingInfo.entityInfo == null) if(editingInfo.entityInfo == null)
{ {
editingInfo.entityInfo = new EntityInfo(); editingInfo.entityInfo = new EntityInfo();
editingInfo.entityInfo.classType = event.getEntity().getClass(); editingInfo.entityInfo.classType = event.getEntity().getClass();
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP)editingInfo.editor);
return;
} }
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Editing entity \"" + editingInfo.entityInfo.classType.getName() + "\""), (EntityPlayerMP) editingInfo.editor);
TurnBasedMinecraftMod.logger.info("Begin editing \"" + editingInfo.entityInfo.classType.getName() + "\"");
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP) editingInfo.editor); TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP) editingInfo.editor);
}
return; return;
} }
} }
} }
if((event.getEntity() != null && battleManager.isRecentlyLeftBattle(event.getEntity().getEntityId())) if(event.getEntity() != null && event.getSource().getTrueSource() != null && (battleManager.isRecentlyLeftBattle(event.getEntity().getEntityId()) || battleManager.isRecentlyLeftBattle(event.getSource().getTrueSource().getEntityId())))
|| (event.getSource().getTrueSource() != null && battleManager.isRecentlyLeftBattle(event.getSource().getTrueSource().getEntityId())))
{ {
event.setCanceled(true); event.setCanceled(true);
return; return;

View file

@ -139,7 +139,12 @@ public class Battle
{ {
for(Entity e : sideA) for(Entity e : sideA)
{ {
EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomNameTag());
if(entityInfo == null)
{
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
}
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning()) if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
{ {
continue; continue;
@ -167,7 +172,12 @@ public class Battle
{ {
for(Entity e : sideB) for(Entity e : sideB)
{ {
EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomNameTag());
if(entityInfo == null)
{
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
}
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning()) if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
{ {
continue; continue;
@ -297,7 +307,12 @@ public class Battle
public void addCombatantToSideA(Entity e) public void addCombatantToSideA(Entity e)
{ {
EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomNameTag());
if(entityInfo == null)
{
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
}
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning()) if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
{ {
return; return;
@ -353,7 +368,12 @@ public class Battle
public void addCombatantToSideB(Entity e) public void addCombatantToSideB(Entity e)
{ {
EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomNameTag());
if(entityInfo == null)
{
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
}
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning()) if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
{ {
return; return;

View file

@ -53,7 +53,12 @@ public class BattleManager
} }
// check if ignore battle in config // check if ignore battle in config
EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getEntity()); EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(event.getEntity().getCustomNameTag());
if(entityInfo == null)
{
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getEntity());
}
if(entityInfo != null && (TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType(entityInfo.category) || entityInfo.ignoreBattle)) if(entityInfo != null && (TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType(entityInfo.category) || entityInfo.ignoreBattle))
{ {
// attacked entity ignores battle // attacked entity ignores battle

View file

@ -11,7 +11,7 @@ import net.minecraft.server.MinecraftServer;
public class CommandTBMEdit extends CommandBase public class CommandTBMEdit extends CommandBase
{ {
public static final String usage = "/tbm-edit (Invoke without parameters to start edit)"; public static final String usage = "/tbm-edit [custom] (Invoke without parameters or with arg \"custom\" to start edit)";
private Config config; private Config config;
public CommandTBMEdit(Config config) public CommandTBMEdit(Config config)
@ -68,10 +68,17 @@ public class CommandTBMEdit extends CommandBase
{ {
if(args[0].toLowerCase().equals("finish")) if(args[0].toLowerCase().equals("finish"))
{ {
config.editEntityEntry(editingInfo.entityInfo); if(!config.editEntityEntry(editingInfo.entityInfo))
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("An error occurred while attempting to save an entry to the config, check the logs"), (EntityPlayerMP) senderEntity);
TurnBasedMinecraftMod.proxy.removeEditingInfo(senderEntity.getEntityId());
}
else
{
TurnBasedMinecraftMod.proxy.removeEditingInfo(senderEntity.getEntityId()); TurnBasedMinecraftMod.proxy.removeEditingInfo(senderEntity.getEntityId());
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Entity info saved in config and loaded."), (EntityPlayerMP) senderEntity); TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Entity info saved in config and loaded."), (EntityPlayerMP) senderEntity);
} }
}
else if(args[0].toLowerCase().equals("cancel")) else if(args[0].toLowerCase().equals("cancel"))
{ {
TurnBasedMinecraftMod.proxy.removeEditingInfo(senderEntity.getEntityId()); TurnBasedMinecraftMod.proxy.removeEditingInfo(senderEntity.getEntityId());
@ -91,10 +98,20 @@ public class CommandTBMEdit extends CommandBase
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), (EntityPlayerMP)senderEntity); TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), (EntityPlayerMP)senderEntity);
} }
else else
{
if(args[0].toLowerCase().equals("custom"))
{
TurnBasedMinecraftMod.proxy.setEditingPlayer(senderEntity);
TurnBasedMinecraftMod.proxy.getEditingInfo(senderEntity.getEntityId()).isEditingCustomName = true;
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), (EntityPlayerMP)senderEntity);
TurnBasedMinecraftMod.logger.info("Begin editing custom TBM Entity for player \"" + senderEntity.getName() + "\"");
}
else
{ {
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Cannot edit entity without starting editing process (use \"/tbm-edit\")."), (EntityPlayerMP)senderEntity); TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Cannot edit entity without starting editing process (use \"/tbm-edit\")."), (EntityPlayerMP)senderEntity);
} }
} }
}
else if(args.length == 2) else if(args.length == 2)
{ {
if(editingInfo != null && !editingInfo.isPendingEntitySelection) if(editingInfo != null && !editingInfo.isPendingEntitySelection)

View file

@ -20,6 +20,7 @@ public class Config
public static final long BATTLE_DECISION_DURATION_NANO_DEFAULT = 15000000000L; public static final long BATTLE_DECISION_DURATION_NANO_DEFAULT = 15000000000L;
private long battleDecisionDurationNanos = BATTLE_DECISION_DURATION_NANO_DEFAULT; private long battleDecisionDurationNanos = BATTLE_DECISION_DURATION_NANO_DEFAULT;
private Map<String, EntityInfo> entityInfoMap; private Map<String, EntityInfo> entityInfoMap;
private Map<String, EntityInfo> customEntityInfoMap;
private Set<String> ignoreBattleTypes; private Set<String> ignoreBattleTypes;
private Logger logger; private Logger logger;
private int playerSpeed = 50; private int playerSpeed = 50;
@ -47,6 +48,7 @@ public class Config
public Config(Logger logger) public Config(Logger logger)
{ {
entityInfoMap = new HashMap<String, EntityInfo>(); entityInfoMap = new HashMap<String, EntityInfo>();
customEntityInfoMap = new HashMap<String, EntityInfo>();
ignoreBattleTypes = new HashSet<String>(); ignoreBattleTypes = new HashSet<String>();
this.logger = logger; this.logger = logger;
musicBattleTypes = new HashSet<String>(); musicBattleTypes = new HashSet<String>();
@ -400,18 +402,32 @@ public class Config
{ {
TomlTable entity = entityArray.getTable(i); TomlTable entity = entityArray.getTable(i);
EntityInfo eInfo = new EntityInfo(); EntityInfo eInfo = new EntityInfo();
String name = null;
if(entity.contains("name") && entity.contains("custom_name"))
{
logger.error("Entity cannot have both \"name\" and \"custom_name\" entries");
continue;
}
else if(entity.contains("name"))
{
try try
{ {
eInfo.classType = Class.forName(entity.getString("name")); eInfo.classType = Class.forName(entity.getString("name"));
} name = eInfo.classType.getName();
catch (ClassNotFoundException e) } catch(ClassNotFoundException e)
{ {
logger.error("Entity with class name \"" + entity.getString("name") + "\" not found, skipping..."); logger.error("Entity with class name \"" + entity.getString("name") + "\" not found, skipping...");
continue; continue;
} }
catch (NullPointerException e) }
else if(entity.contains("custom_name"))
{ {
logger.error("Entity does not have \"name\", skipping..."); eInfo.customName = entity.getString("custom_name");
name = eInfo.customName;
}
else
{
logger.error("Entity must have \"name\" or \"custom_name\" entry");
continue; continue;
} }
@ -421,12 +437,12 @@ public class Config
if(eInfo.attackPower < 0) if(eInfo.attackPower < 0)
{ {
eInfo.attackPower = 0; eInfo.attackPower = 0;
logEntityInvalidValue("attack_power", eInfo.classType.getName(), "0"); logEntityInvalidValue("attack_power", name, "0");
} }
} }
catch (NullPointerException e) catch (NullPointerException e)
{ {
logEntityMissingRequiredValue("attack_power", eInfo.classType.getName()); logEntityMissingRequiredValue("attack_power", name);
continue; continue;
} }
@ -436,12 +452,12 @@ public class Config
if(eInfo.attackProbability < 0 || eInfo.attackProbability > 100) if(eInfo.attackProbability < 0 || eInfo.attackProbability > 100)
{ {
eInfo.attackProbability = 35; eInfo.attackProbability = 35;
logEntityInvalidValue("attack_probability", eInfo.classType.getName(), "35"); logEntityInvalidValue("attack_probability", name, "35");
} }
} }
catch (NullPointerException e) catch (NullPointerException e)
{ {
logEntityMissingRequiredValue("attack_probability", eInfo.classType.getName()); logEntityMissingRequiredValue("attack_probability", name);
continue; continue;
} }
@ -454,13 +470,14 @@ public class Config
if(eInfo.attackEffectProbability < 0 || eInfo.attackEffectProbability > 100) if(eInfo.attackEffectProbability < 0 || eInfo.attackEffectProbability > 100)
{ {
eInfo.attackEffectProbability = 35; eInfo.attackEffectProbability = 35;
logEntityInvalidValue("attack_effect", eInfo.classType.getName(), "35"); logEntityInvalidValue("attack_effect", name, "35");
} }
} }
} }
catch (NullPointerException e) catch (NullPointerException e)
{ {
eInfo.attackEffect = EntityInfo.Effect.UNKNOWN; eInfo.attackEffect = EntityInfo.Effect.UNKNOWN;
logEntityMissingOptionalValue("attack_effect", name, "unknown");
} }
try try
@ -469,12 +486,13 @@ public class Config
if(eInfo.attackVariance < 0) if(eInfo.attackVariance < 0)
{ {
eInfo.attackVariance = 0; eInfo.attackVariance = 0;
logEntityInvalidValue("attack_variance", eInfo.classType.getName(), "0"); logEntityInvalidValue("attack_variance", name, "0");
} }
} }
catch (NullPointerException e) catch (NullPointerException e)
{ {
eInfo.attackVariance = 0; eInfo.attackVariance = 0;
logEntityMissingOptionalValue("attack_variance", name, "0");
} }
try try
@ -483,7 +501,7 @@ public class Config
if(eInfo.defenseDamage < 0) if(eInfo.defenseDamage < 0)
{ {
eInfo.defenseDamage = 0; eInfo.defenseDamage = 0;
logEntityInvalidValue("defense_damage", eInfo.classType.getName(), "0"); logEntityInvalidValue("defense_damage", name, "0");
} }
else else
{ {
@ -491,13 +509,14 @@ public class Config
if(eInfo.defenseDamageProbability < 0 || eInfo.defenseDamageProbability > 100) if(eInfo.defenseDamageProbability < 0 || eInfo.defenseDamageProbability > 100)
{ {
eInfo.defenseDamageProbability = 35; eInfo.defenseDamageProbability = 35;
logEntityInvalidValue("defense_damage_probability", eInfo.classType.getName(), "35"); logEntityInvalidValue("defense_damage_probability", name, "35");
} }
} }
} }
catch (NullPointerException e) catch (NullPointerException e)
{ {
eInfo.defenseDamage = 0; eInfo.defenseDamage = 0;
logEntityMissingOptionalValue("defense_damage", name, "0");
} }
try try
@ -506,12 +525,12 @@ public class Config
if(eInfo.evasion < 0 || eInfo.evasion > 100) if(eInfo.evasion < 0 || eInfo.evasion > 100)
{ {
eInfo.evasion = 20; eInfo.evasion = 20;
logEntityInvalidValue("evasion", eInfo.classType.getName(), "20"); logEntityInvalidValue("evasion", name, "20");
} }
} }
catch (NullPointerException e) catch (NullPointerException e)
{ {
logEntityMissingRequiredValue("evasion", eInfo.classType.getName()); logEntityMissingRequiredValue("evasion", name);
continue; continue;
} }
@ -521,7 +540,8 @@ public class Config
} }
catch (NullPointerException e) catch (NullPointerException e)
{ {
logEntityMissingRequiredValue("speed", eInfo.classType.getName()); logEntityMissingRequiredValue("speed", name);
continue;
} }
try try
@ -531,12 +551,13 @@ public class Config
catch (NullPointerException e) catch (NullPointerException e)
{ {
eInfo.ignoreBattle = false; eInfo.ignoreBattle = false;
logEntityMissingOptionalValue("ignore_battle", name, "false");
} }
eInfo.category = entity.getString("category"); eInfo.category = entity.getString("category");
if(eInfo.category == null) if(eInfo.category == null)
{ {
logEntityMissingRequiredValue("category", eInfo.classType.getName()); logEntityMissingRequiredValue("category", name);
continue; continue;
} }
@ -546,7 +567,7 @@ public class Config
} }
catch (NullPointerException e) catch (NullPointerException e)
{ {
logEntityMissingRequiredValue("decision_attack_probability", eInfo.classType.getName()); logEntityMissingRequiredValue("decision_attack_probability", name);
continue; continue;
} }
@ -556,7 +577,7 @@ public class Config
} }
catch (NullPointerException e) catch (NullPointerException e)
{ {
logEntityMissingRequiredValue("decision_defend_probability", eInfo.classType.getName()); logEntityMissingRequiredValue("decision_defend_probability", name);
continue; continue;
} }
@ -566,12 +587,23 @@ public class Config
} }
catch (NullPointerException e) catch (NullPointerException e)
{ {
logEntityMissingRequiredValue("decision_flee_probability", eInfo.classType.getName()); logEntityMissingRequiredValue("decision_flee_probability", name);
continue; continue;
} }
if(eInfo.classType != null)
{
entityInfoMap.put(eInfo.classType.getName(), eInfo); entityInfoMap.put(eInfo.classType.getName(), eInfo);
} }
else if(!eInfo.customName.isEmpty())
{
customEntityInfoMap.put(eInfo.customName, eInfo);
}
else
{
logger.error("Cannot add entity to internal config, no \"name\" or \"custom_name\"");
}
}
} }
return true; return true;
} }
@ -596,22 +628,51 @@ public class Config
logger.error("Entity \"" + name + "\" does not have option \"" + option + "\", skipping..."); logger.error("Entity \"" + name + "\" does not have option \"" + option + "\", skipping...");
} }
private void logEntityMissingOptionalValue(String option, String name, String defaultValue)
{
logger.info("Entity \"" + name + "\" does not have optional option \"" + option + "\", defaulting to \"" + defaultValue + "\"...");
}
private String getRegexEntityName(String name) private String getRegexEntityName(String name)
{ {
String regex = "^\\s*name\\s*=\\s*"; String regex = "^\\s*name\\s*=\\s*";
regex += "(\"" + name + "\""; regex += "(\"" + name + "\"";
regex += "|'" + name + "')"; regex += "|'" + name + "'";
regex += "|\"\"\"" + name + "\"\"\"";
regex += "|'''" + name + "''')";
return regex;
}
private String getRegexCustomEntityName(String name)
{
String regex = "^\\s*custom_name\\s*=\\s*";
regex += "(\"" + name + "\"";
regex += "|'" + name + "'";
regex += "|\"\"\"" + name + "\"\"\"";
regex += "|'''" + name + "''')";
return regex; return regex;
} }
private boolean addEntityEntry(EntityInfo eInfo) private boolean addEntityEntry(EntityInfo eInfo)
{ {
if(eInfo.classType == null && eInfo.customName.isEmpty())
{
logger.error("addEntityEntry: Got invalid eInfo, no name of any type");
return false;
}
try try
{ {
File config = new File(TurnBasedMinecraftMod.CONFIG_FILE_PATH); File config = new File(TurnBasedMinecraftMod.CONFIG_FILE_PATH);
FileWriter fw = new FileWriter(config, true); FileWriter fw = new FileWriter(config, true);
fw.write("[[server_config.entity]]\n"); fw.write("[[server_config.entity]]\n");
if(eInfo.classType != null)
{
fw.write("name = \"" + eInfo.classType.getName() + "\"\n"); fw.write("name = \"" + eInfo.classType.getName() + "\"\n");
}
else
{
fw.write("custom_name = \"" + eInfo.customName + "\"\n");
}
fw.write("attack_power = " + eInfo.attackPower + "\n"); fw.write("attack_power = " + eInfo.attackPower + "\n");
fw.write("attack_probability = " + eInfo.attackProbability + "\n"); fw.write("attack_probability = " + eInfo.attackProbability + "\n");
if(eInfo.attackVariance > 0) if(eInfo.attackVariance > 0)
@ -632,7 +693,7 @@ public class Config
fw.write("speed = " + eInfo.speed + "\n"); fw.write("speed = " + eInfo.speed + "\n");
if(eInfo.ignoreBattle) if(eInfo.ignoreBattle)
{ {
fw.write("ignoreBattle = true\n"); fw.write("ignore_battle = true\n");
} }
fw.write("category = \"" + eInfo.category + "\"\n"); fw.write("category = \"" + eInfo.category + "\"\n");
fw.write("decision_attack_probability = " + eInfo.decisionAttack + "\n"); fw.write("decision_attack_probability = " + eInfo.decisionAttack + "\n");
@ -640,11 +701,25 @@ public class Config
fw.write("decision_flee_probability = " + eInfo.decisionFlee + "\n"); fw.write("decision_flee_probability = " + eInfo.decisionFlee + "\n");
fw.close(); fw.close();
if(eInfo.classType != null)
{
entityInfoMap.put(eInfo.classType.getName(), eInfo); entityInfoMap.put(eInfo.classType.getName(), eInfo);
} }
else
{
customEntityInfoMap.put(eInfo.customName, eInfo);
}
}
catch (Throwable t) catch (Throwable t)
{
if(eInfo.classType != null)
{ {
logger.error("Failed to add entity entry (name = \"" + eInfo.classType.getName() + "\")"); logger.error("Failed to add entity entry (name = \"" + eInfo.classType.getName() + "\")");
}
else
{
logger.error("Failed to add custom entity entry (custom_name = \"" + eInfo.customName + "\")");
}
return false; return false;
} }
return true; return true;
@ -670,6 +745,7 @@ public class Config
} }
int nameIndex = -1; int nameIndex = -1;
if(eInfo.classType != null)
{ {
Pattern p = Pattern.compile(getRegexEntityName(eInfo.classType.getName()), Pattern.MULTILINE); Pattern p = Pattern.compile(getRegexEntityName(eInfo.classType.getName()), Pattern.MULTILINE);
Matcher m = p.matcher(cached); Matcher m = p.matcher(cached);
@ -678,6 +754,20 @@ public class Config
nameIndex = m.start(); nameIndex = m.start();
} }
} }
else if(!eInfo.customName.isEmpty())
{
Pattern p = Pattern.compile(getRegexCustomEntityName(eInfo.customName), Pattern.MULTILINE);
Matcher m = p.matcher(cached);
if(m.find())
{
nameIndex = m.start();
}
}
else
{
logger.error("EntityInfo does not have classType or customName, cannot edit/add");
return false;
}
int entryIndex = -1; int entryIndex = -1;
int nextIndex = -1; int nextIndex = -1;
if(nameIndex != -1) if(nameIndex != -1)
@ -705,8 +795,15 @@ public class Config
} }
} }
else else
{
if(eInfo.classType != null)
{ {
logger.warn("editEntityEntry: could not find entry for \"" + eInfo.classType.getName() + "\", skipping to adding it..."); logger.warn("editEntityEntry: could not find entry for \"" + eInfo.classType.getName() + "\", skipping to adding it...");
}
else if(!eInfo.customName.isEmpty())
{
logger.warn("editEntityEntry: could not find entry for \"" + eInfo.customName + "\", skipping to adding it...");
}
return addEntityEntry(eInfo); return addEntityEntry(eInfo);
} }
@ -781,7 +878,12 @@ public class Config
*/ */
public EntityInfo getEntityInfo(String classFullName) public EntityInfo getEntityInfo(String classFullName)
{ {
return entityInfoMap.get(classFullName).clone(); EntityInfo eInfo = entityInfoMap.get(classFullName);
if(eInfo != null)
{
eInfo = eInfo.clone();
}
return eInfo;
} }
protected EntityInfo getEntityInfoReference(String classFullName) protected EntityInfo getEntityInfoReference(String classFullName)
@ -803,6 +905,26 @@ public class Config
return null; return null;
} }
/**
* Returns a clone of an EntityInfo (to prevent editing it).
* @param customName
* @return a clone of the stored custom EntityInfo or null if invalid String
*/
public EntityInfo getCustomEntityInfo(String customName)
{
EntityInfo eInfo = customEntityInfoMap.get(customName);
if(eInfo != null)
{
eInfo = eInfo.clone();
}
return eInfo;
}
protected EntityInfo getCustomEntityInfoReference(String customName)
{
return customEntityInfoMap.get(customName);
}
private int getConfigFileVersion(InputStream io) private int getConfigFileVersion(InputStream io)
{ {
int version = 0; int version = 0;

View file

@ -7,12 +7,14 @@ public class EditingInfo
public EntityPlayer editor; public EntityPlayer editor;
public EntityInfo entityInfo; public EntityInfo entityInfo;
public boolean isPendingEntitySelection; public boolean isPendingEntitySelection;
public boolean isEditingCustomName;
public EditingInfo() public EditingInfo()
{ {
editor = null; editor = null;
entityInfo = null; entityInfo = null;
isPendingEntitySelection = true; isPendingEntitySelection = true;
isEditingCustomName = false;
} }
public EditingInfo(EntityPlayer player) public EditingInfo(EntityPlayer player)
@ -20,5 +22,6 @@ public class EditingInfo
editor = player; editor = player;
entityInfo = null; entityInfo = null;
isPendingEntitySelection = true; isPendingEntitySelection = true;
isEditingCustomName = false;
} }
} }

View file

@ -21,6 +21,7 @@ public class EntityInfo
public int decisionAttack; public int decisionAttack;
public int decisionDefend; public int decisionDefend;
public int decisionFlee; public int decisionFlee;
public String customName;
public enum Effect public enum Effect
{ {
@ -379,6 +380,7 @@ public class EntityInfo
decisionAttack = 70; decisionAttack = 70;
decisionDefend = 20; decisionDefend = 20;
decisionFlee = 10; decisionFlee = 10;
customName = new String();
} }
public EntityInfo clone() public EntityInfo clone()
@ -399,6 +401,7 @@ public class EntityInfo
newEntityInfo.decisionAttack = decisionAttack; newEntityInfo.decisionAttack = decisionAttack;
newEntityInfo.decisionDefend = decisionDefend; newEntityInfo.decisionDefend = decisionDefend;
newEntityInfo.decisionFlee = decisionFlee; newEntityInfo.decisionFlee = decisionFlee;
newEntityInfo.customName = new String(customName);
return newEntityInfo; return newEntityInfo;
} }
} }

View file

@ -21,7 +21,7 @@ public class TurnBasedMinecraftMod
{ {
public static final String MODID = "com.seodisparate.turnbasedminecraft"; public static final String MODID = "com.seodisparate.turnbasedminecraft";
public static final String NAME = "Turn Based Minecraft Mod"; public static final String NAME = "Turn Based Minecraft Mod";
public static final String VERSION = "1.6"; public static final String VERSION = "1.7";
public static final String CONFIG_FILENAME = "TBM_Config.toml"; public static final String CONFIG_FILENAME = "TBM_Config.toml";
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/"; public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
public static final String CONFIG_FILE_PATH = CONFIG_DIRECTORY + CONFIG_FILENAME; public static final String CONFIG_FILE_PATH = CONFIG_DIRECTORY + CONFIG_FILENAME;

View file

@ -104,6 +104,7 @@ public class PacketEditingMessage implements IMessage
entityInfo.decisionAttack = buf.readInt(); entityInfo.decisionAttack = buf.readInt();
entityInfo.decisionDefend = buf.readInt(); entityInfo.decisionDefend = buf.readInt();
entityInfo.decisionFlee = buf.readInt(); entityInfo.decisionFlee = buf.readInt();
entityInfo.customName = ByteBufUtils.readUTF8String(buf);
} }
@Override @Override
@ -132,6 +133,7 @@ public class PacketEditingMessage implements IMessage
buf.writeInt(entityInfo.decisionAttack); buf.writeInt(entityInfo.decisionAttack);
buf.writeInt(entityInfo.decisionDefend); buf.writeInt(entityInfo.decisionDefend);
buf.writeInt(entityInfo.decisionFlee); buf.writeInt(entityInfo.decisionFlee);
ByteBufUtils.writeUTF8String(buf, entityInfo.customName);
} }
public static class HandlerEditingMessage implements IMessageHandler<PacketEditingMessage, IMessage> public static class HandlerEditingMessage implements IMessageHandler<PacketEditingMessage, IMessage>
@ -230,7 +232,7 @@ public class PacketEditingMessage implements IMessage
option = new TextComponentString("E"); option = new TextComponentString("E");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit evasion")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit evasion"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Evasion"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Evasion")));
value = new TextComponentString("(" + message.entityInfo.evasion + ") "); value = new TextComponentString("(" + message.entityInfo.evasion + "%) ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);

View file

@ -66,7 +66,8 @@ battle_turn_time_seconds = 15
# Each "server_config.entity" entry uses the following options: # Each "server_config.entity" entry uses the following options:
# name: full class name of the entity # name: full class name of the entity, cannot also have option "custom_name"
# custom_name: custom name-tag name, cannot also have option "name"
# attack_power: how much damage an entity does on successful attack # attack_power: how much damage an entity does on successful attack
# attack_probability: percentage of attack success. (Usually calculated with enemy's evasion to determine actual percentage) # attack_probability: percentage of attack success. (Usually calculated with enemy's evasion to determine actual percentage)
# attack_variance (optional): determines how much a successful attack's damage varies. # attack_variance (optional): determines how much a successful attack's damage varies.