Minor fixes/changes
Added option in config to change battle timer time
This commit is contained in:
parent
9119f42e5b
commit
a4c3a28028
9 changed files with 70 additions and 22 deletions
|
@ -104,7 +104,7 @@ public class BattleGui extends GuiScreen
|
|||
|
||||
public BattleGui()
|
||||
{
|
||||
timeRemaining = new AtomicInteger((int)TurnBasedMinecraftMod.BattleDecisionTime.getSeconds());
|
||||
timeRemaining = new AtomicInteger(TurnBasedMinecraftMod.getBattleDurationSeconds());
|
||||
lastInstant = System.nanoTime();
|
||||
elapsedTime = 0;
|
||||
state = MenuState.MAIN_MENU;
|
||||
|
@ -129,7 +129,7 @@ public class BattleGui extends GuiScreen
|
|||
{
|
||||
TurnBasedMinecraftMod.currentBattle.setState(Battle.State.DECISION);
|
||||
}
|
||||
timeRemaining.set((int)TurnBasedMinecraftMod.BattleDecisionTime.getSeconds());
|
||||
timeRemaining.set(TurnBasedMinecraftMod.getBattleDurationSeconds());
|
||||
elapsedTime = 0;
|
||||
lastInstant = System.nanoTime();
|
||||
setState(MenuState.MAIN_MENU);
|
||||
|
|
|
@ -41,7 +41,7 @@ public class BattleMusic
|
|||
try {
|
||||
sequencer = MidiSystem.getSequencer();
|
||||
sequencer.open();
|
||||
} catch (Exception e)
|
||||
} catch (Throwable t)
|
||||
{
|
||||
logger.error("Failed to load midi sequencer");
|
||||
return;
|
||||
|
@ -198,7 +198,7 @@ public class BattleMusic
|
|||
}
|
||||
try {
|
||||
sequencer.setSequence(new BufferedInputStream(new FileInputStream(next)));
|
||||
} catch (Exception e)
|
||||
} catch (Throwable t)
|
||||
{
|
||||
logger.error("Failed to play battle music (midi)");
|
||||
return;
|
||||
|
@ -221,7 +221,7 @@ public class BattleMusic
|
|||
try
|
||||
{
|
||||
clip.open(AudioSystem.getAudioInputStream(next));
|
||||
} catch(Exception e)
|
||||
} catch(Throwable t)
|
||||
{
|
||||
logger.error("Failed to load battle music (wav)");
|
||||
return;
|
||||
|
|
|
@ -130,7 +130,7 @@ public class Battle
|
|||
for(Entity e : sideA)
|
||||
{
|
||||
EntityInfo entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(e);
|
||||
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.battleManager != null)
|
||||
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.commonProxy.isServerRunning())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ public class Battle
|
|||
for(Entity e : sideB)
|
||||
{
|
||||
EntityInfo entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(e);
|
||||
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.battleManager != null)
|
||||
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.commonProxy.isServerRunning())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ public class Battle
|
|||
lastInstant = System.nanoTime();
|
||||
state = State.DECISION;
|
||||
undecidedCount.set(playerCount.get());
|
||||
timer = TurnBasedMinecraftMod.BattleDecisionTime.getSeconds() * 1000000000;
|
||||
timer = TurnBasedMinecraftMod.getBattleDurationNanos();
|
||||
battleEnded = false;
|
||||
|
||||
notifyPlayersBattleInfo();
|
||||
|
@ -249,7 +249,7 @@ public class Battle
|
|||
public void addCombatantToSideA(Entity e)
|
||||
{
|
||||
EntityInfo entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(e);
|
||||
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.battleManager != null)
|
||||
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.commonProxy.isServerRunning())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ public class Battle
|
|||
public void addCombatantToSideB(Entity e)
|
||||
{
|
||||
EntityInfo entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(e);
|
||||
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.battleManager != null)
|
||||
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.commonProxy.isServerRunning())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -653,7 +653,7 @@ public class Battle
|
|||
}
|
||||
}
|
||||
state = State.ACTION;
|
||||
timer = TurnBasedMinecraftMod.BattleDecisionTime.getSeconds() * 1000000000;
|
||||
timer = TurnBasedMinecraftMod.getBattleDurationNanos();
|
||||
sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_BEGIN, 0, 0, 0);
|
||||
turnOrderQueue.clear();
|
||||
for(Combatant c : sideA.values())
|
||||
|
|
|
@ -33,7 +33,7 @@ public class BattleUpdater implements Runnable
|
|||
{
|
||||
manager.battleMap.remove(ended);
|
||||
}
|
||||
try { Thread.sleep(250); } catch (Exception e) { /* ignored */ }
|
||||
try { Thread.sleep(250); } catch (Throwable t) { /* ignored */ }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,4 +64,9 @@ public class CommonProxy
|
|||
{
|
||||
return FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getEntityByID(id);
|
||||
}
|
||||
|
||||
public boolean isServerRunning()
|
||||
{
|
||||
return TurnBasedMinecraftMod.battleManager != null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,8 +55,11 @@ public class Config
|
|||
{
|
||||
logger.error("Internal resource is null");
|
||||
}
|
||||
else
|
||||
{
|
||||
internalVersion = getConfigFileVersion(is);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
} catch (Throwable t) {}
|
||||
|
||||
if(internalVersion == 0)
|
||||
{
|
||||
|
@ -75,7 +78,7 @@ public class Config
|
|||
writeConfig();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Throwable t)
|
||||
{
|
||||
logger.error("Failed to check/create-new config file");
|
||||
}
|
||||
|
@ -96,7 +99,7 @@ public class Config
|
|||
try
|
||||
{
|
||||
writeConfig();
|
||||
} catch (Exception e)
|
||||
} catch (Throwable t)
|
||||
{
|
||||
logger.error("Failed to write config file!");
|
||||
}
|
||||
|
@ -104,7 +107,7 @@ public class Config
|
|||
try
|
||||
{
|
||||
parseConfig(configFile);
|
||||
} catch (Exception e)
|
||||
} catch (Throwable t)
|
||||
{
|
||||
logger.error("Failed to parse config file!");
|
||||
}
|
||||
|
@ -261,6 +264,19 @@ public class Config
|
|||
minimumHitPercentage = 1;
|
||||
}
|
||||
}
|
||||
else if(xmlReader.getLocalName().equals("BattleTurnTimeSeconds"))
|
||||
{
|
||||
int seconds = TurnBasedMinecraftMod.getBattleDurationSeconds();
|
||||
try
|
||||
{
|
||||
seconds = Integer.parseInt(xmlReader.getElementText());
|
||||
TurnBasedMinecraftMod.setBattleDurationSeconds(seconds);
|
||||
} catch (Throwable t)
|
||||
{
|
||||
logger.warn("Unable to get value for \"BattleTurnTimeSeconds\" from config, using default");
|
||||
TurnBasedMinecraftMod.setBattleDurationSeconds(TurnBasedMinecraftMod.BATTLE_DECISION_DURATION_NANO_DEFAULT / 1000000000L);
|
||||
}
|
||||
}
|
||||
else if(xmlReader.getLocalName().equals("EntityEntry"))
|
||||
{
|
||||
EntityInfo eInfo = new EntityInfo();
|
||||
|
@ -468,7 +484,7 @@ public class Config
|
|||
}
|
||||
}
|
||||
xmlReader.close();
|
||||
} catch (Exception e)
|
||||
} catch (Throwable t)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.seodisparate.TurnBasedMinecraft.common;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -31,7 +30,6 @@ public class TurnBasedMinecraftMod
|
|||
public static final String MODID = "com.seodisparate.turnbasedminecraft";
|
||||
public static final String NAME = "Turn Based Minecraft Mod";
|
||||
public static final String VERSION = "0.3";
|
||||
public static final Duration BattleDecisionTime = Duration.ofSeconds(15);
|
||||
public static final String CONFIG_FILENAME = "TBM_Config.xml";
|
||||
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
|
||||
public static final String CONFIG_FILE_PATH = CONFIG_DIRECTORY + CONFIG_FILENAME;
|
||||
|
@ -51,6 +49,10 @@ public class TurnBasedMinecraftMod
|
|||
protected static int attackingDamage = 0;
|
||||
protected static Set<AttackerViaBow> attackerViaBow;
|
||||
protected static Config config;
|
||||
public static final long BATTLE_DECISION_DURATION_NANO_MIN = 5000000000L;
|
||||
public static final long BATTLE_DECISION_DURATION_NANO_MAX = 60000000000L;
|
||||
public static final long BATTLE_DECISION_DURATION_NANO_DEFAULT = 15000000000L;
|
||||
private static long BATTLE_DECISION_DURATION_NANOSECONDS = BATTLE_DECISION_DURATION_NANO_DEFAULT;
|
||||
|
||||
public static Battle currentBattle = null;
|
||||
|
||||
|
@ -140,4 +142,27 @@ public class TurnBasedMinecraftMod
|
|||
{
|
||||
return CONFIG_FILE_VERSION;
|
||||
}
|
||||
|
||||
public static long getBattleDurationNanos()
|
||||
{
|
||||
return BATTLE_DECISION_DURATION_NANOSECONDS;
|
||||
}
|
||||
|
||||
public static int getBattleDurationSeconds()
|
||||
{
|
||||
return (int)(BATTLE_DECISION_DURATION_NANOSECONDS / 1000000000L);
|
||||
}
|
||||
|
||||
protected static void setBattleDurationSeconds(long seconds)
|
||||
{
|
||||
BATTLE_DECISION_DURATION_NANOSECONDS = seconds * 1000000000L;
|
||||
if(BATTLE_DECISION_DURATION_NANOSECONDS < BATTLE_DECISION_DURATION_NANO_MIN)
|
||||
{
|
||||
BATTLE_DECISION_DURATION_NANOSECONDS = BATTLE_DECISION_DURATION_NANO_MIN;
|
||||
}
|
||||
else if(BATTLE_DECISION_DURATION_NANOSECONDS > BATTLE_DECISION_DURATION_NANO_MAX)
|
||||
{
|
||||
BATTLE_DECISION_DURATION_NANOSECONDS = BATTLE_DECISION_DURATION_NANO_MAX;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public class PacketBattleInfo implements IMessage
|
|||
{
|
||||
sideA = new ArrayList<Integer>();
|
||||
sideB = new ArrayList<Integer>();
|
||||
decisionNanos = TurnBasedMinecraftMod.BattleDecisionTime.getSeconds() * 1000000000;
|
||||
decisionNanos = TurnBasedMinecraftMod.getBattleDurationNanos();
|
||||
}
|
||||
|
||||
public PacketBattleInfo(Collection<Integer> sideA, Collection<Integer> sideB, long decisionNanos)
|
||||
|
@ -81,7 +81,7 @@ public class PacketBattleInfo implements IMessage
|
|||
{
|
||||
TurnBasedMinecraftMod.currentBattle.addCombatantToSideB(Minecraft.getMinecraft().world.getEntityByID(id));
|
||||
}
|
||||
TurnBasedMinecraftMod.commonProxy.setBattleGuiTime((int)(message.decisionNanos / 1000000000));
|
||||
TurnBasedMinecraftMod.commonProxy.setBattleGuiTime((int)(message.decisionNanos / 1000000000L));
|
||||
TurnBasedMinecraftMod.commonProxy.setBattleGuiBattleChanged();
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
<FleeBadProbability>40</FleeBadProbability>
|
||||
<!-- Minimum hit percentage for every entity. If less than 1, it will be stored as 1 anyways. -->
|
||||
<MinimumHitPercentage>4</MinimumHitPercentage>
|
||||
<!-- Number of seconds to wait in battle for all players to make a decision. Minimum of 5 and maximum of 60. -->
|
||||
<BattleTurnTimeSeconds>15</BattleTurnTimeSeconds>
|
||||
|
||||
<!-- Battle stats for entities should be specified here. If an entity is not listed it cannot enter battle. -->
|
||||
<!-- Name: The full class name of an entity. -->
|
||||
|
|
Loading…
Reference in a new issue