Move client Battle to ClientProxy

This commit is contained in:
Stephen Seo 2018-09-28 12:13:07 +09:00
parent bb8ebf561b
commit 0e0a7ea562
6 changed files with 51 additions and 29 deletions

View file

@ -119,15 +119,18 @@ public class BattleGui extends GuiScreen
public void turnBegin() public void turnBegin()
{ {
TurnBasedMinecraftMod.currentBattle.setState(Battle.State.ACTION); if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() != null)
{
TurnBasedMinecraftMod.commonProxy.getLocalBattle().setState(Battle.State.ACTION);
}
setState(MenuState.WAITING); setState(MenuState.WAITING);
} }
public void turnEnd() public void turnEnd()
{ {
if(TurnBasedMinecraftMod.currentBattle != null) if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() != null)
{ {
TurnBasedMinecraftMod.currentBattle.setState(Battle.State.DECISION); TurnBasedMinecraftMod.commonProxy.getLocalBattle().setState(Battle.State.DECISION);
} }
timeRemaining.set(TurnBasedMinecraftMod.getBattleDurationSeconds()); timeRemaining.set(TurnBasedMinecraftMod.getBattleDurationSeconds());
elapsedTime = 0; elapsedTime = 0;
@ -161,7 +164,7 @@ public class BattleGui extends GuiScreen
case ATTACK_TARGET: case ATTACK_TARGET:
info = "Who will you attack?"; info = "Who will you attack?";
int y = 30; int y = 30;
for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.currentBattle.getSideAEntrySet()) for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.commonProxy.getLocalBattle().getSideAEntrySet())
{ {
if(e.getValue().entity != null) if(e.getValue().entity != null)
{ {
@ -174,7 +177,7 @@ public class BattleGui extends GuiScreen
y += 20; y += 20;
} }
y = 30; y = 30;
for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.currentBattle.getSideBEntrySet()) for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.commonProxy.getLocalBattle().getSideBEntrySet())
{ {
if(e.getValue().entity != null) if(e.getValue().entity != null)
{ {
@ -219,12 +222,12 @@ public class BattleGui extends GuiScreen
@Override @Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) public void drawScreen(int mouseX, int mouseY, float partialTicks)
{ {
if(TurnBasedMinecraftMod.currentBattle == null) if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() == null)
{ {
drawHoveringText("Waiting...", width / 2 - 50, height / 2); drawHoveringText("Waiting...", width / 2 - 50, height / 2);
return; return;
} }
if(TurnBasedMinecraftMod.currentBattle.getState() == Battle.State.DECISION && timeRemaining.get() > 0) if(TurnBasedMinecraftMod.commonProxy.getLocalBattle().getState() == Battle.State.DECISION && timeRemaining.get() > 0)
{ {
long nextInstant = System.nanoTime(); long nextInstant = System.nanoTime();
elapsedTime += nextInstant - lastInstant; elapsedTime += nextInstant - lastInstant;
@ -270,20 +273,20 @@ public class BattleGui extends GuiScreen
setState(MenuState.ATTACK_TARGET); setState(MenuState.ATTACK_TARGET);
break; break;
case DEFEND: case DEFEND:
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.DEFEND, 0)); TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.commonProxy.getLocalBattle().getId(), Battle.Decision.DEFEND, 0));
setState(MenuState.WAITING); setState(MenuState.WAITING);
break; break;
case ITEM: case ITEM:
setState(MenuState.ITEM_ACTION); setState(MenuState.ITEM_ACTION);
break; break;
case FLEE: case FLEE:
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.FLEE, 0)); TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.commonProxy.getLocalBattle().getId(), Battle.Decision.FLEE, 0));
setState(MenuState.WAITING); setState(MenuState.WAITING);
break; break;
case ATTACK_TARGET: case ATTACK_TARGET:
if(button instanceof EntitySelectionButton) if(button instanceof EntitySelectionButton)
{ {
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.ATTACK, ((EntitySelectionButton)button).entityID)); TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.commonProxy.getLocalBattle().getId(), Battle.Decision.ATTACK, ((EntitySelectionButton)button).entityID));
setState(MenuState.WAITING); setState(MenuState.WAITING);
} }
else else
@ -303,7 +306,7 @@ public class BattleGui extends GuiScreen
case DO_ITEM_SWITCH: case DO_ITEM_SWITCH:
if(button instanceof ItemSelectionButton) if(button instanceof ItemSelectionButton)
{ {
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton)button).itemStackID)); TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.commonProxy.getLocalBattle().getId(), Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton)button).itemStackID));
if(((ItemSelectionButton)button).itemStackID >= 0 && ((ItemSelectionButton)button).itemStackID < 9) if(((ItemSelectionButton)button).itemStackID >= 0 && ((ItemSelectionButton)button).itemStackID < 9)
{ {
Minecraft.getMinecraft().player.inventory.currentItem = ((ItemSelectionButton)button).itemStackID; Minecraft.getMinecraft().player.inventory.currentItem = ((ItemSelectionButton)button).itemStackID;
@ -318,7 +321,7 @@ public class BattleGui extends GuiScreen
case DO_USE_ITEM: case DO_USE_ITEM:
if(button instanceof ItemSelectionButton) if(button instanceof ItemSelectionButton)
{ {
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.currentBattle.getId(), Battle.Decision.USE_ITEM, ((ItemSelectionButton)button).itemStackID)); TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.commonProxy.getLocalBattle().getId(), Battle.Decision.USE_ITEM, ((ItemSelectionButton)button).itemStackID));
setState(MenuState.WAITING); setState(MenuState.WAITING);
} }
else else

View file

@ -2,6 +2,7 @@ package com.seodisparate.TurnBasedMinecraft.client;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import com.seodisparate.TurnBasedMinecraft.common.Battle;
import com.seodisparate.TurnBasedMinecraft.common.CommonProxy; import com.seodisparate.TurnBasedMinecraft.common.CommonProxy;
import com.seodisparate.TurnBasedMinecraft.common.Config; import com.seodisparate.TurnBasedMinecraft.common.Config;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
@ -19,6 +20,7 @@ public class ClientProxy extends CommonProxy
private Config config; private Config config;
private int battleMusicCount; private int battleMusicCount;
private int sillyMusicCount; private int sillyMusicCount;
private Battle localBattle;
@Override @Override
public void initialize() public void initialize()
@ -27,6 +29,7 @@ public class ClientProxy extends CommonProxy
battleMusic = null; // will be initialized in postInit() battleMusic = null; // will be initialized in postInit()
battleMusicCount = 0; battleMusicCount = 0;
sillyMusicCount = 0; sillyMusicCount = 0;
localBattle = null;
} }
@Override @Override
@ -74,7 +77,7 @@ public class ClientProxy extends CommonProxy
@Override @Override
public void battleEnded() public void battleEnded()
{ {
TurnBasedMinecraftMod.currentBattle = null; localBattle = null;
Minecraft.getMinecraft().addScheduledTask(() -> { Minecraft.getMinecraft().addScheduledTask(() -> {
Minecraft.getMinecraft().displayGuiScreen(null); Minecraft.getMinecraft().displayGuiScreen(null);
Minecraft.getMinecraft().setIngameFocus(); Minecraft.getMinecraft().setIngameFocus();
@ -120,7 +123,7 @@ public class ClientProxy extends CommonProxy
@Override @Override
public void typeEnteredBattle(String type) public void typeEnteredBattle(String type)
{ {
if(TurnBasedMinecraftMod.currentBattle == null) if(localBattle == null)
{ {
return; return;
} }
@ -142,7 +145,7 @@ public class ClientProxy extends CommonProxy
@Override @Override
public void typeLeftBattle(String type) public void typeLeftBattle(String type)
{ {
if(TurnBasedMinecraftMod.currentBattle == null) if(localBattle == null)
{ {
return; return;
} }
@ -226,4 +229,16 @@ public class ClientProxy extends CommonProxy
} }
} }
} }
@Override
public Battle getLocalBattle()
{
return localBattle;
}
@Override
public void createLocalBattle(int id)
{
localBattle = new Battle(id, null, null, false);
}
} }

View file

@ -71,4 +71,11 @@ public class CommonProxy
{ {
return TurnBasedMinecraftMod.battleManager != null; return TurnBasedMinecraftMod.battleManager != null;
} }
public Battle getLocalBattle()
{
return null;
}
public void createLocalBattle(int id) {}
} }

View file

@ -54,8 +54,6 @@ public class TurnBasedMinecraftMod
public static final long BATTLE_DECISION_DURATION_NANO_DEFAULT = 15000000000L; public static final long BATTLE_DECISION_DURATION_NANO_DEFAULT = 15000000000L;
private static long BATTLE_DECISION_DURATION_NANOSECONDS = BATTLE_DECISION_DURATION_NANO_DEFAULT; private static long BATTLE_DECISION_DURATION_NANOSECONDS = BATTLE_DECISION_DURATION_NANO_DEFAULT;
public static Battle currentBattle = null;
@SidedProxy(modId=MODID, serverSide="com.seodisparate.TurnBasedMinecraft.common.CommonProxy", clientSide="com.seodisparate.TurnBasedMinecraft.client.ClientProxy") @SidedProxy(modId=MODID, serverSide="com.seodisparate.TurnBasedMinecraft.common.CommonProxy", clientSide="com.seodisparate.TurnBasedMinecraft.client.ClientProxy")
public static CommonProxy commonProxy; public static CommonProxy commonProxy;
@ -69,7 +67,6 @@ public class TurnBasedMinecraftMod
public void init(FMLInitializationEvent event) public void init(FMLInitializationEvent event)
{ {
commonProxy.initialize(); commonProxy.initialize();
currentBattle = null;
battleManager = null; battleManager = null;
attackerViaBow = new HashSet<AttackerViaBow>(); attackerViaBow = new HashSet<AttackerViaBow>();
commonProxy.setLogger(logger); commonProxy.setLogger(logger);

View file

@ -68,18 +68,18 @@ public class PacketBattleInfo implements IMessage
@Override @Override
public IMessage onMessage(PacketBattleInfo message, MessageContext ctx) public IMessage onMessage(PacketBattleInfo message, MessageContext ctx)
{ {
if(TurnBasedMinecraftMod.currentBattle == null) if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() == null)
{ {
return null; return null;
} }
TurnBasedMinecraftMod.currentBattle.clearCombatants(); TurnBasedMinecraftMod.commonProxy.getLocalBattle().clearCombatants();
for(Integer id : message.sideA) for(Integer id : message.sideA)
{ {
TurnBasedMinecraftMod.currentBattle.addCombatantToSideA(Minecraft.getMinecraft().world.getEntityByID(id)); TurnBasedMinecraftMod.commonProxy.getLocalBattle().addCombatantToSideA(Minecraft.getMinecraft().world.getEntityByID(id));
} }
for(Integer id : message.sideB) for(Integer id : message.sideB)
{ {
TurnBasedMinecraftMod.currentBattle.addCombatantToSideB(Minecraft.getMinecraft().world.getEntityByID(id)); TurnBasedMinecraftMod.commonProxy.getLocalBattle().addCombatantToSideB(Minecraft.getMinecraft().world.getEntityByID(id));
} }
TurnBasedMinecraftMod.commonProxy.setBattleGuiTime((int)(message.decisionNanos / 1000000000L)); TurnBasedMinecraftMod.commonProxy.setBattleGuiTime((int)(message.decisionNanos / 1000000000L));
TurnBasedMinecraftMod.commonProxy.setBattleGuiBattleChanged(); TurnBasedMinecraftMod.commonProxy.setBattleGuiBattleChanged();

View file

@ -168,9 +168,9 @@ public class PacketBattleMessage implements IMessage
from = fromEntity.getName(); from = fromEntity.getName();
} }
} }
else if(TurnBasedMinecraftMod.currentBattle != null) else if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() != null)
{ {
fromEntity = TurnBasedMinecraftMod.currentBattle.getCombatantEntity(message.entityIDFrom); fromEntity = TurnBasedMinecraftMod.commonProxy.getLocalBattle().getCombatantEntity(message.entityIDFrom);
if(fromEntity != null) if(fromEntity != null)
{ {
if(fromEntity.hasCustomName()) if(fromEntity.hasCustomName())
@ -204,9 +204,9 @@ public class PacketBattleMessage implements IMessage
to = toEntity.getName(); to = toEntity.getName();
} }
} }
else if(TurnBasedMinecraftMod.currentBattle != null) else if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() != null)
{ {
toEntity = TurnBasedMinecraftMod.currentBattle.getCombatantEntity(message.entityIDTo); toEntity = TurnBasedMinecraftMod.commonProxy.getLocalBattle().getCombatantEntity(message.entityIDTo);
if(toEntity != null) if(toEntity != null)
{ {
if(toEntity.hasCustomName()) if(toEntity.hasCustomName())
@ -228,9 +228,9 @@ public class PacketBattleMessage implements IMessage
{ {
case ENTERED: case ENTERED:
TurnBasedMinecraftMod.commonProxy.displayString(from + " entered battle!"); TurnBasedMinecraftMod.commonProxy.displayString(from + " entered battle!");
if(TurnBasedMinecraftMod.currentBattle == null || TurnBasedMinecraftMod.currentBattle.getId() != message.amount) if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() == null || TurnBasedMinecraftMod.commonProxy.getLocalBattle().getId() != message.amount)
{ {
TurnBasedMinecraftMod.currentBattle = new Battle(message.amount, null, null, false); TurnBasedMinecraftMod.commonProxy.createLocalBattle(message.amount);
} }
TurnBasedMinecraftMod.commonProxy.battleStarted(); TurnBasedMinecraftMod.commonProxy.battleStarted();
TurnBasedMinecraftMod.commonProxy.typeEnteredBattle(message.custom); TurnBasedMinecraftMod.commonProxy.typeEnteredBattle(message.custom);
@ -301,7 +301,7 @@ public class PacketBattleMessage implements IMessage
TurnBasedMinecraftMod.commonProxy.battleGuiTurnBegin(); TurnBasedMinecraftMod.commonProxy.battleGuiTurnBegin();
break; break;
case TURN_END: case TURN_END:
if(TurnBasedMinecraftMod.currentBattle != null) if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() != null)
{ {
TurnBasedMinecraftMod.commonProxy.displayString("The turn ended!"); TurnBasedMinecraftMod.commonProxy.displayString("The turn ended!");
} }