Fix passive-type battle music occurrences, fixes

This commit is contained in:
Stephen Seo 2018-09-27 18:09:40 +09:00
parent 3e234ea94e
commit c2c19f6af2
6 changed files with 178 additions and 63 deletions

View file

@ -133,9 +133,11 @@ public class BattleMusic
if(!initialized || battleMusic.isEmpty())
{
nextBattle = null;
return;
}
nextBattle = battleMusic.get((int)(Math.random() * battleMusic.size()));
else
{
nextBattle = battleMusic.get((int)(Math.random() * battleMusic.size()));
}
}
private void pickNextSilly()
@ -143,9 +145,11 @@ public class BattleMusic
if(!initialized || sillyMusic.isEmpty())
{
nextSilly = null;
return;
}
nextSilly = sillyMusic.get((int)(Math.random() * sillyMusic.size()));
else
{
nextSilly = sillyMusic.get((int)(Math.random() * sillyMusic.size()));
}
}
public void playBattle(float volume)
@ -191,15 +195,9 @@ public class BattleMusic
String suffix = next.getName().substring(next.getName().length() - 3).toLowerCase();
if(suffix.equals("mid"))
{
if(sequencer.isRunning())
{
sequencer.stop();
}
if(clip.isActive())
{
clip.stop();
clip.close();
}
sequencer.stop();
clip.stop();
clip.close();
try {
sequencer.setSequence(new BufferedInputStream(new FileInputStream(next)));
} catch (Throwable t)
@ -243,15 +241,9 @@ public class BattleMusic
public void stopMusic(boolean resumeMCSounds)
{
if(sequencer.isRunning())
{
sequencer.stop();
}
if(clip.isActive())
{
clip.stop();
clip.close();
}
sequencer.stop();
clip.stop();
clip.close();
if(resumeMCSounds)
{
Minecraft.getMinecraft().addScheduledTask(() -> {
@ -270,4 +262,14 @@ public class BattleMusic
{
return isPlaying || sequencer.isRunning() || clip.isActive();
}
public boolean hasBattleMusic()
{
return !battleMusic.isEmpty();
}
public boolean hasSillyMusic()
{
return !sillyMusic.isEmpty();
}
}

View file

@ -17,12 +17,16 @@ public class ClientProxy extends CommonProxy
private BattleMusic battleMusic;
private Logger logger;
private Config config;
private int battleMusicCount;
private int sillyMusicCount;
@Override
public void initialize()
{
battleGui = new BattleGui();
battleMusic = null; // will be initialized in postInit()
battleMusicCount = 0;
sillyMusicCount = 0;
}
@Override
@ -76,6 +80,8 @@ public class ClientProxy extends CommonProxy
Minecraft.getMinecraft().setIngameFocus();
});
stopMusic(true);
battleMusicCount = 0;
sillyMusicCount = 0;
}
@Override
@ -114,36 +120,45 @@ public class ClientProxy extends CommonProxy
@Override
public void typeEnteredBattle(String type)
{
if(TurnBasedMinecraftMod.currentBattle == null)
{
return;
}
if(type == null || type.isEmpty() || config.isBattleMusicType(type))
{
if(battleMusic.isPlaying())
{
if(battleMusic.isPlayingSilly())
{
stopMusic(false);
playBattleMusic();
}
}
else
{
playBattleMusic();
}
++battleMusicCount;
}
else if(config.isSillyMusicType(type))
{
if(battleMusic.isPlaying())
{
if(!battleMusic.isPlayingSilly())
{
stopMusic(false);
playSillyMusic();
}
}
else
{
playSillyMusic();
}
++sillyMusicCount;
}
else
{
++battleMusicCount;
}
checkBattleTypes();
}
@Override
public void typeLeftBattle(String type)
{
if(TurnBasedMinecraftMod.currentBattle == null)
{
return;
}
if(type == null || type.isEmpty() || config.isBattleMusicType(type))
{
--battleMusicCount;
}
else if(config.isSillyMusicType(type))
{
--sillyMusicCount;
}
else
{
--battleMusicCount;
}
checkBattleTypes();
}
@Override
@ -163,4 +178,38 @@ public class ClientProxy extends CommonProxy
{
return Minecraft.getMinecraft().world.getEntityByID(id);
}
private void checkBattleTypes()
{
if(battleMusicCount <= 1 && sillyMusicCount > 0)
{
if(battleMusic.isPlaying())
{
if(!battleMusic.isPlayingSilly() && battleMusic.hasSillyMusic())
{
stopMusic(false);
playSillyMusic();
}
}
else if(battleMusic.hasSillyMusic())
{
playSillyMusic();
}
}
else
{
if(battleMusic.isPlaying())
{
if(battleMusic.isPlayingSilly() && battleMusic.hasBattleMusic())
{
stopMusic(false);
playBattleMusic();
}
}
else if(battleMusic.hasBattleMusic())
{
playBattleMusic();
}
}
}
}

View file

@ -192,6 +192,10 @@ public class Battle
{
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, c.entity.getEntityId(), 0, id, c.entityInfo.category);
}
else if(c.entity instanceof EntityPlayer)
{
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, c.entity.getEntityId(), 0, id, "player");
}
else
{
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, c.entity.getEntityId(), 0, id);
@ -203,6 +207,10 @@ public class Battle
{
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, c.entity.getEntityId(), 0, id, c.entityInfo.category);
}
else if(c.entity instanceof EntityPlayer)
{
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, c.entity.getEntityId(), 0, id, "player");
}
else
{
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, c.entity.getEntityId(), 0, id);
@ -290,6 +298,10 @@ public class Battle
{
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, newCombatant.entity.getEntityId(), 0, id, newCombatant.entityInfo.category);
}
else if(newCombatant.entity instanceof EntityPlayer)
{
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, newCombatant.entity.getEntityId(), 0, id, "player");
}
else
{
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, newCombatant.entity.getEntityId(), 0, id);
@ -339,6 +351,10 @@ public class Battle
{
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, newCombatant.entity.getEntityId(), 0, id, newCombatant.entityInfo.category);
}
else if(newCombatant.entity instanceof EntityPlayer)
{
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, newCombatant.entity.getEntityId(), 0, id, "player");
}
else
{
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, newCombatant.entity.getEntityId(), 0, id);
@ -350,6 +366,8 @@ public class Battle
{
sideA.clear();
sideB.clear();
sideAEntryQueue.clear();
sideBEntryQueue.clear();
players.clear();
playerCount.set(0);
undecidedCount.set(0);
@ -506,7 +524,16 @@ public class Battle
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketBattleMessage(PacketBattleMessage.MessageType.ENDED, c.entity.getEntityId(), 0, 0), (EntityPlayerMP)c.entity);
}
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DIED, c.entity.getEntityId(), 0, 0);
String category = new String();
if(c.entityInfo != null)
{
category = c.entityInfo.category;
}
else if(c.entity instanceof EntityPlayer)
{
category = "player";
}
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DIED, c.entity.getEntityId(), 0, 0, category);
}
}
for(Combatant c : sideB.values())
@ -518,7 +545,16 @@ public class Battle
{
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketBattleMessage(PacketBattleMessage.MessageType.ENDED, c.entity.getEntityId(), 0, 0), (EntityPlayerMP)c.entity);
}
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DIED, c.entity.getEntityId(), 0, 0);
String category = new String();
if(c.entityInfo != null)
{
category = c.entityInfo.category;
}
else if(c.entity instanceof EntityPlayer)
{
category = "player";
}
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DIED, c.entity.getEntityId(), 0, 0, category);
}
}
boolean didRemove = !removeQueue.isEmpty();
@ -538,13 +574,15 @@ public class Battle
}
else if(didRemove)
{
notifyPlayersBattleInfo();
resetUndecidedCount();
}
return didRemove;
}
/**
* @return true if at least one combatant was removed
*/
private boolean isCreativeCheck()
{
Queue<Integer> removeQueue = new ArrayDeque<Integer>();
@ -568,7 +606,6 @@ public class Battle
}
if(didRemove)
{
notifyPlayersBattleInfo();
resetUndecidedCount();
}
@ -627,11 +664,13 @@ public class Battle
{
return true;
}
boolean combatantsChanged = false;
synchronized(sideAEntryQueue)
{
for(Combatant c = sideAEntryQueue.poll(); c != null; c = sideAEntryQueue.poll())
{
sideA.put(c.entity.getEntityId(), c);
combatantsChanged = true;
}
}
synchronized(sideBEntryQueue)
@ -639,6 +678,7 @@ public class Battle
for(Combatant c = sideBEntryQueue.poll(); c != null; c = sideBEntryQueue.poll())
{
sideB.put(c.entity.getEntityId(), c);
combatantsChanged = true;
}
}
if(TurnBasedMinecraftMod.config.isFreezeCombatantsEnabled())
@ -706,8 +746,14 @@ public class Battle
}
else
{
healthCheck();
isCreativeCheck();
if(healthCheck())
{
combatantsChanged = true;
}
if(isCreativeCheck())
{
combatantsChanged = true;
}
}
break;
case ACTION:
@ -1019,7 +1065,17 @@ public class Battle
{
sideB.remove(next.entity.getEntityId());
}
sendMessageToAllPlayers(PacketBattleMessage.MessageType.FLEE, next.entity.getEntityId(), 0, 1);
combatantsChanged = true;
String fleeingCategory = new String();
if(next.entityInfo != null)
{
fleeingCategory = next.entityInfo.category;
}
else if(next.entity instanceof EntityPlayer)
{
fleeingCategory = "player";
}
sendMessageToAllPlayers(PacketBattleMessage.MessageType.FLEE, next.entity.getEntityId(), 0, 1, fleeingCategory);
if(next.entity instanceof EntityPlayer)
{
players.remove(next.entity.getEntityId());
@ -1094,8 +1150,14 @@ public class Battle
}
state = State.DECISION;
undecidedCount.set(players.size());
healthCheck();
isCreativeCheck();
if(healthCheck())
{
combatantsChanged = true;
}
if(isCreativeCheck())
{
combatantsChanged = true;
}
FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(() -> {
sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_END, 0, 0, 0);
});
@ -1105,6 +1167,10 @@ public class Battle
state = State.DECISION;
break;
} // switch(state)
if(combatantsChanged)
{
notifyPlayersBattleInfo();
}
return battleEnded;
} // update(final long dt)
}

View file

@ -56,6 +56,8 @@ public class CommonProxy
public void typeEnteredBattle(String type) {}
public void typeLeftBattle(String type) {}
public void setConfig(Config config) {}
public void displayString(String message) {}

View file

@ -233,19 +233,13 @@ public class PacketBattleMessage implements IMessage
TurnBasedMinecraftMod.currentBattle = new Battle(message.amount, null, null, false);
}
TurnBasedMinecraftMod.commonProxy.battleStarted();
if(message.custom.isEmpty())
{
TurnBasedMinecraftMod.commonProxy.typeEnteredBattle(null);
}
else
{
TurnBasedMinecraftMod.commonProxy.typeEnteredBattle(message.custom);
}
TurnBasedMinecraftMod.commonProxy.typeEnteredBattle(message.custom);
break;
case FLEE:
if(message.amount != 0)
{
TurnBasedMinecraftMod.commonProxy.displayString(from + " fled battle!");
TurnBasedMinecraftMod.commonProxy.typeLeftBattle(message.custom);
}
else
{
@ -254,6 +248,7 @@ public class PacketBattleMessage implements IMessage
break;
case DIED:
TurnBasedMinecraftMod.commonProxy.displayString(from + " died in battle!");
TurnBasedMinecraftMod.commonProxy.typeLeftBattle(message.custom);
break;
case ENDED:
TurnBasedMinecraftMod.commonProxy.displayString("Battle has ended!");

View file

@ -18,6 +18,7 @@
<monster></monster>
<animal></animal>
<boss></boss>
<player></player>
</Normal>
<Silly>
<passive></passive>