Cleanup of code, move BattleGui main menu

This commit is contained in:
Stephen Seo 2018-09-28 17:45:32 +09:00
parent 38fd9da186
commit 857ff2539b
13 changed files with 270 additions and 260 deletions

View file

@ -7,6 +7,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import com.seodisparate.TurnBasedMinecraft.common.Battle;
import com.seodisparate.TurnBasedMinecraft.common.Combatant;
import com.seodisparate.TurnBasedMinecraft.common.Config;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecision;
@ -16,9 +17,9 @@ import net.minecraft.client.gui.GuiScreen;
public class BattleGui extends GuiScreen
{
public AtomicInteger timeRemaining;
public long lastInstant;
public long elapsedTime;
private AtomicInteger timeRemaining;
private long lastInstant;
private long elapsedTime;
private MenuState state;
private boolean stateChanged;
private String info;
@ -104,7 +105,7 @@ public class BattleGui extends GuiScreen
public BattleGui()
{
timeRemaining = new AtomicInteger(TurnBasedMinecraftMod.getBattleDurationSeconds());
timeRemaining = new AtomicInteger((int)(Config.BATTLE_DECISION_DURATION_NANO_DEFAULT / 1000000000L));
lastInstant = System.nanoTime();
elapsedTime = 0;
state = MenuState.MAIN_MENU;
@ -119,20 +120,20 @@ public class BattleGui extends GuiScreen
public void turnBegin()
{
if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() != null)
if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
{
TurnBasedMinecraftMod.commonProxy.getLocalBattle().setState(Battle.State.ACTION);
TurnBasedMinecraftMod.proxy.getLocalBattle().setState(Battle.State.ACTION);
}
setState(MenuState.WAITING);
}
public void turnEnd()
{
if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() != null)
if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
{
TurnBasedMinecraftMod.commonProxy.getLocalBattle().setState(Battle.State.DECISION);
TurnBasedMinecraftMod.proxy.getLocalBattle().setState(Battle.State.DECISION);
}
timeRemaining.set(TurnBasedMinecraftMod.getBattleDurationSeconds());
timeRemaining.set(TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationSeconds());
elapsedTime = 0;
lastInstant = System.nanoTime();
setState(MenuState.MAIN_MENU);
@ -156,15 +157,15 @@ public class BattleGui extends GuiScreen
{
case MAIN_MENU:
info = "What will you do?";
buttonList.add(new GuiButton(ButtonAction.ATTACK.getValue(), width*3/7 - 25, height - 90, 50, 20, "Attack"));
buttonList.add(new GuiButton(ButtonAction.DEFEND.getValue(), width*4/7 - 25, height - 90, 50, 20, "Defend"));
buttonList.add(new GuiButton(ButtonAction.ITEM.getValue(), width*3/7 - 25, height - 70, 50, 20, "Item"));
buttonList.add(new GuiButton(ButtonAction.FLEE.getValue(), width*4/7 - 25, height - 70, 50, 20, "Flee"));
buttonList.add(new GuiButton(ButtonAction.ATTACK.getValue(), width*3/7 - 25, 40, 50, 20, "Attack"));
buttonList.add(new GuiButton(ButtonAction.DEFEND.getValue(), width*4/7 - 25, 40, 50, 20, "Defend"));
buttonList.add(new GuiButton(ButtonAction.ITEM.getValue(), width*3/7 - 25, 60, 50, 20, "Item"));
buttonList.add(new GuiButton(ButtonAction.FLEE.getValue(), width*4/7 - 25, 60, 50, 20, "Flee"));
break;
case ATTACK_TARGET:
info = "Who will you attack?";
int y = 30;
for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.commonProxy.getLocalBattle().getSideAEntrySet())
for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle().getSideAEntrySet())
{
if(e.getValue().entity != null)
{
@ -177,7 +178,7 @@ public class BattleGui extends GuiScreen
y += 20;
}
y = 30;
for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.commonProxy.getLocalBattle().getSideBEntrySet())
for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle().getSideBEntrySet())
{
if(e.getValue().entity != null)
{
@ -222,12 +223,12 @@ public class BattleGui extends GuiScreen
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() == null)
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
{
drawHoveringText("Waiting...", width / 2 - 50, height / 2);
return;
}
if(TurnBasedMinecraftMod.commonProxy.getLocalBattle().getState() == Battle.State.DECISION && timeRemaining.get() > 0)
if(TurnBasedMinecraftMod.proxy.getLocalBattle().getState() == Battle.State.DECISION && timeRemaining.get() > 0)
{
long nextInstant = System.nanoTime();
elapsedTime += nextInstant - lastInstant;
@ -273,20 +274,20 @@ public class BattleGui extends GuiScreen
setState(MenuState.ATTACK_TARGET);
break;
case DEFEND:
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.commonProxy.getLocalBattle().getId(), Battle.Decision.DEFEND, 0));
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.DEFEND, 0));
setState(MenuState.WAITING);
break;
case ITEM:
setState(MenuState.ITEM_ACTION);
break;
case FLEE:
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.commonProxy.getLocalBattle().getId(), Battle.Decision.FLEE, 0));
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.FLEE, 0));
setState(MenuState.WAITING);
break;
case ATTACK_TARGET:
if(button instanceof EntitySelectionButton)
{
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.commonProxy.getLocalBattle().getId(), Battle.Decision.ATTACK, ((EntitySelectionButton)button).entityID));
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.ATTACK, ((EntitySelectionButton)button).entityID));
setState(MenuState.WAITING);
}
else
@ -306,7 +307,7 @@ public class BattleGui extends GuiScreen
case DO_ITEM_SWITCH:
if(button instanceof ItemSelectionButton)
{
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.commonProxy.getLocalBattle().getId(), Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton)button).itemStackID));
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton)button).itemStackID));
if(((ItemSelectionButton)button).itemStackID >= 0 && ((ItemSelectionButton)button).itemStackID < 9)
{
Minecraft.getMinecraft().player.inventory.currentItem = ((ItemSelectionButton)button).itemStackID;
@ -321,7 +322,7 @@ public class BattleGui extends GuiScreen
case DO_USE_ITEM:
if(button instanceof ItemSelectionButton)
{
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.commonProxy.getLocalBattle().getId(), Battle.Decision.USE_ITEM, ((ItemSelectionButton)button).itemStackID));
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.USE_ITEM, ((ItemSelectionButton)button).itemStackID));
setState(MenuState.WAITING);
}
else
@ -358,4 +359,9 @@ public class BattleGui extends GuiScreen
super.keyTyped(typedChar, keyCode);
}
}
public void setTimeRemaining(int remaining)
{
timeRemaining.set(remaining);
}
}

View file

@ -1,11 +1,7 @@
package com.seodisparate.TurnBasedMinecraft.client;
import org.apache.logging.log4j.Logger;
import com.seodisparate.TurnBasedMinecraft.common.Battle;
import com.seodisparate.TurnBasedMinecraft.common.CommonProxy;
import com.seodisparate.TurnBasedMinecraft.common.Config;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
@ -14,17 +10,16 @@ import net.minecraft.util.text.TextComponentString;
public class ClientProxy extends CommonProxy
{
private BattleGui battleGui;
private BattleMusic battleMusic;
private Logger logger;
private Config config;
private int battleMusicCount;
private int sillyMusicCount;
private Battle localBattle;
private BattleGui battleGui = null;
private BattleMusic battleMusic = null;
private int battleMusicCount = 0;
private int sillyMusicCount = 0;
private Battle localBattle = null;
@Override
public void initialize()
{
super.initialize();
battleGui = new BattleGui();
battleMusic = null; // will be initialized in postInit()
battleMusicCount = 0;
@ -35,7 +30,7 @@ public class ClientProxy extends CommonProxy
@Override
public void setBattleGuiTime(int timeRemaining)
{
battleGui.timeRemaining.set(timeRemaining);
battleGui.setTimeRemaining(timeRemaining);
}
@Override
@ -90,13 +85,8 @@ public class ClientProxy extends CommonProxy
@Override
public void postInit()
{
battleMusic = new BattleMusic(logger);
}
@Override
public void setLogger(Logger logger)
{
this.logger = logger;
super.postInit();
battleMusic = new BattleMusic(getLogger());
}
@Override
@ -127,11 +117,11 @@ public class ClientProxy extends CommonProxy
{
return;
}
if(type == null || type.isEmpty() || config.isBattleMusicType(type))
if(type == null || type.isEmpty() || getConfig().isBattleMusicType(type))
{
++battleMusicCount;
}
else if(config.isSillyMusicType(type))
else if(getConfig().isSillyMusicType(type))
{
++sillyMusicCount;
}
@ -149,11 +139,11 @@ public class ClientProxy extends CommonProxy
{
return;
}
if(type == null || type.isEmpty() || config.isBattleMusicType(type))
if(type == null || type.isEmpty() || getConfig().isBattleMusicType(type))
{
--battleMusicCount;
}
else if(config.isSillyMusicType(type))
else if(getConfig().isSillyMusicType(type))
{
--sillyMusicCount;
}
@ -164,12 +154,6 @@ public class ClientProxy extends CommonProxy
checkBattleTypes();
}
@Override
public void setConfig(Config config)
{
this.config = config;
}
@Override
public void displayString(String message)
{
@ -198,7 +182,7 @@ public class ClientProxy extends CommonProxy
percentage = 100.0f * (float)sillyMusicCount / (float)(sillyMusicCount + battleMusicCount);
}
if(percentage >= (float)TurnBasedMinecraftMod.getConfig().getSillyMusicThreshold())
if(percentage >= (float)getConfig().getSillyMusicThreshold())
{
if(battleMusic.isPlaying())
{

View file

@ -16,7 +16,7 @@ public class AttackEventHandler
{
return false;
}
else if(event.getSource().getTrueSource().equals(TurnBasedMinecraftMod.attackingEntity))
else if(event.getSource().getTrueSource().equals(TurnBasedMinecraftMod.proxy.getAttackingEntity()))
{
return true;
}
@ -25,9 +25,9 @@ public class AttackEventHandler
Queue<AttackerViaBow> removeQueue = new ArrayDeque<AttackerViaBow>();
final long now = System.nanoTime();
boolean isValid = false;
synchronized(TurnBasedMinecraftMod.attackerViaBow)
synchronized(TurnBasedMinecraftMod.proxy.getAttackerViaBowSet())
{
for(AttackerViaBow attacker : TurnBasedMinecraftMod.attackerViaBow)
for(AttackerViaBow attacker : TurnBasedMinecraftMod.proxy.getAttackerViaBowSet())
{
if(now - attacker.attackTime >= AttackerViaBow.ATTACK_TIMEOUT)
{
@ -38,7 +38,7 @@ public class AttackEventHandler
removeQueue.add(attacker);
if(!isValid)
{
Battle b = TurnBasedMinecraftMod.battleManager.getBattleByID(attacker.battleID);
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(attacker.battleID);
if(b != null)
{
b.sendMessageToAllPlayers(PacketBattleMessage.MessageType.ARROW_HIT, attacker.entity.getEntityId(), event.getEntity().getEntityId(), 0);
@ -49,7 +49,7 @@ public class AttackEventHandler
}
for(AttackerViaBow next = removeQueue.poll(); next != null; next = removeQueue.poll())
{
TurnBasedMinecraftMod.attackerViaBow.remove(next);
TurnBasedMinecraftMod.proxy.getAttackerViaBowSet().remove(next);
}
}
return isValid;
@ -64,18 +64,18 @@ public class AttackEventHandler
return;
}
if(!isAttackerValid(event) && event.getEntity() != null && event.getSource().getTrueSource() != null && TurnBasedMinecraftMod.battleManager.checkAttack(event))
if(!isAttackerValid(event) && event.getEntity() != null && event.getSource().getTrueSource() != null && TurnBasedMinecraftMod.proxy.getBattleManager().checkAttack(event))
{
// TurnBasedMinecraftMod.logger.debug("Canceled LivingAttackEvent between " + TurnBasedMinecraftMod.attackingEntity + " and " + event.getEntity());
// TurnBasedMinecraftMod.logger.debug("Canceled LivingAttackEvent between " + TurnBasedMinecraftMod.commonProxy.getAttackingEntity() + " and " + event.getEntity());
event.setCanceled(true);
}
else
{
// TurnBasedMinecraftMod.logger.debug("Did not cancel attack");
}
if(TurnBasedMinecraftMod.attackingDamage < (int) event.getAmount())
if(TurnBasedMinecraftMod.proxy.getAttackingDamage() < (int) event.getAmount())
{
TurnBasedMinecraftMod.attackingDamage = (int) event.getAmount();
TurnBasedMinecraftMod.proxy.setAttackingDamage((int) event.getAmount());
}
}
}

View file

@ -133,8 +133,8 @@ public class Battle
{
for(Entity e : sideA)
{
EntityInfo entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(e);
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.commonProxy.isServerRunning())
EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
{
continue;
}
@ -148,7 +148,7 @@ public class Battle
playerCount.incrementAndGet();
players.put(e.getEntityId(), newCombatant);
}
if(TurnBasedMinecraftMod.config.isFreezeCombatantsEnabled())
if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
{
newCombatant.x = e.posX;
newCombatant.z = e.posZ;
@ -161,8 +161,8 @@ public class Battle
{
for(Entity e : sideB)
{
EntityInfo entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(e);
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.commonProxy.isServerRunning())
EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
{
continue;
}
@ -176,7 +176,7 @@ public class Battle
playerCount.incrementAndGet();
players.put(e.getEntityId(), newCombatant);
}
if(TurnBasedMinecraftMod.config.isFreezeCombatantsEnabled())
if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
{
newCombatant.x = e.posX;
newCombatant.z = e.posZ;
@ -220,7 +220,7 @@ public class Battle
lastInstant = System.nanoTime();
state = State.DECISION;
undecidedCount.set(playerCount.get());
timer = TurnBasedMinecraftMod.getBattleDurationNanos();
timer = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
battleEnded = false;
notifyPlayersBattleInfo();
@ -258,8 +258,8 @@ public class Battle
public void addCombatantToSideA(Entity e)
{
EntityInfo entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(e);
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.commonProxy.isServerRunning())
EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
{
return;
}
@ -287,7 +287,7 @@ public class Battle
undecidedCount.incrementAndGet();
}
}
if(TurnBasedMinecraftMod.config.isFreezeCombatantsEnabled())
if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
{
newCombatant.x = e.posX;
newCombatant.z = e.posZ;
@ -311,8 +311,8 @@ public class Battle
public void addCombatantToSideB(Entity e)
{
EntityInfo entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(e);
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.commonProxy.isServerRunning())
EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
{
return;
}
@ -340,7 +340,7 @@ public class Battle
undecidedCount.incrementAndGet();
}
}
if(TurnBasedMinecraftMod.config.isFreezeCombatantsEnabled())
if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
{
newCombatant.x = e.posX;
newCombatant.z = e.posZ;
@ -681,7 +681,7 @@ public class Battle
combatantsChanged = true;
}
}
if(TurnBasedMinecraftMod.config.isFreezeCombatantsEnabled())
if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
{
enforceFreezePositions();
}
@ -731,7 +731,7 @@ public class Battle
}
}
state = State.ACTION;
timer = TurnBasedMinecraftMod.getBattleDurationNanos();
timer = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_BEGIN, 0, 0, 0);
turnOrderQueue.clear();
for(Combatant c : sideA.values())
@ -797,7 +797,7 @@ public class Battle
final Entity targetEntity = target.entity;
final float yawDirection = Utility.yawDirection(next.entity.posX, next.entity.posZ, target.entity.posX, target.entity.posZ);
final float pitchDirection = Utility.pitchDirection(next.entity.posX, next.entity.posY, next.entity.posZ, target.entity.posX, target.entity.posY, target.entity.posZ);
if(TurnBasedMinecraftMod.config.isFreezeCombatantsEnabled())
if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
{
next.yaw = yawDirection;
next.pitch = pitchDirection;
@ -806,9 +806,9 @@ public class Battle
// have player look at attack target
((EntityPlayerMP)nextEntity).connection.setPlayerLocation(nextEntity.posX, nextEntity.posY, nextEntity.posZ, yawDirection, pitchDirection);
ItemBow itemBow = (ItemBow)heldItemStack.getItem();
synchronized(TurnBasedMinecraftMod.attackerViaBow)
synchronized(TurnBasedMinecraftMod.proxy.getAttackerViaBowSet())
{
TurnBasedMinecraftMod.attackerViaBow.add(new AttackerViaBow(nextEntity, getId()));
TurnBasedMinecraftMod.proxy.getAttackerViaBowSet().add(new AttackerViaBow(nextEntity, getId()));
}
itemBow.onPlayerStoppedUsing(((EntityPlayer)nextEntity).getHeldItemMainhand(), nextEntity.getEntityWorld(), (EntityLivingBase)nextEntity, (int)(Math.random() * (itemBow.getMaxItemUseDuration(heldItemStack)) / 3));
sendMessageToAllPlayers(PacketBattleMessage.MessageType.FIRED_ARROW, nextEntity.getEntityId(), targetEntity.getEntityId(), 0);
@ -820,18 +820,18 @@ public class Battle
}
continue;
}
int hitChance = TurnBasedMinecraftMod.config.getPlayerAttackProbability();
int hitChance = TurnBasedMinecraftMod.proxy.getConfig().getPlayerAttackProbability();
if(target.entity instanceof EntityPlayer)
{
hitChance -= TurnBasedMinecraftMod.config.getPlayerEvasion();
hitChance -= TurnBasedMinecraftMod.proxy.getConfig().getPlayerEvasion();
}
else
{
hitChance -= target.entityInfo.evasion;
}
if(hitChance < TurnBasedMinecraftMod.config.getMinimumHitPercentage())
if(hitChance < TurnBasedMinecraftMod.proxy.getConfig().getMinimumHitPercentage())
{
hitChance = TurnBasedMinecraftMod.config.getMinimumHitPercentage();
hitChance = TurnBasedMinecraftMod.proxy.getConfig().getMinimumHitPercentage();
}
if((int)(Math.random() * 100) < hitChance)
{
@ -843,7 +843,7 @@ public class Battle
final EntityInfo targetEntityInfo = target.entityInfo;
final float yawDirection = Utility.yawDirection(next.entity.posX, next.entity.posZ, target.entity.posX, target.entity.posZ);
final float pitchDirection = Utility.pitchDirection(next.entity.posX, next.entity.posY, next.entity.posZ, target.entity.posX, target.entity.posY, target.entity.posZ);
if(TurnBasedMinecraftMod.config.isFreezeCombatantsEnabled())
if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
{
next.yaw = yawDirection;
next.pitch = pitchDirection;
@ -851,20 +851,20 @@ public class Battle
next.entity.getServer().addScheduledTask(() -> {
// have player look at attack target
((EntityPlayerMP)nextEntity).connection.setPlayerLocation(nextEntity.posX, nextEntity.posY, nextEntity.posZ, yawDirection, pitchDirection);
TurnBasedMinecraftMod.attackingEntity = nextEntity;
TurnBasedMinecraftMod.attackingDamage = 0;
TurnBasedMinecraftMod.proxy.setAttackingEntity(nextEntity);
TurnBasedMinecraftMod.proxy.setAttackingDamage(0);
((EntityPlayer)nextEntity).attackTargetEntityWithCurrentItem(targetEntity);
TurnBasedMinecraftMod.attackingEntity = null;
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getEntityId(), targetEntity.getEntityId(), TurnBasedMinecraftMod.attackingDamage);
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getEntityId(), targetEntity.getEntityId(), TurnBasedMinecraftMod.proxy.getAttackingDamage());
if(!(targetEntity instanceof EntityPlayer) && targetEntityInfo.defenseDamage > 0)
{
if((int)(Math.random() * 100) < targetEntityInfo.defenseDamageProbability)
{
// defense damage
DamageSource defenseDamageSource = DamageSource.causeMobDamage((EntityLivingBase)targetEntity);
TurnBasedMinecraftMod.attackingEntity = targetEntity;
TurnBasedMinecraftMod.proxy.setAttackingEntity(targetEntity);
nextEntity.attackEntityFrom(defenseDamageSource, targetEntityInfo.defenseDamage);
TurnBasedMinecraftMod.attackingEntity = null;
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENSE_DAMAGE, targetEntity.getEntityId(), nextEntity.getEntityId(), targetEntityInfo.defenseDamage);
}
}
@ -916,15 +916,15 @@ public class Battle
int hitChance = next.entityInfo.attackProbability;
if(target.entity instanceof EntityPlayer)
{
hitChance -= TurnBasedMinecraftMod.config.getPlayerEvasion();
hitChance -= TurnBasedMinecraftMod.proxy.getConfig().getPlayerEvasion();
}
else
{
hitChance -= target.entityInfo.evasion;
}
if(hitChance < TurnBasedMinecraftMod.config.getMinimumHitPercentage())
if(hitChance < TurnBasedMinecraftMod.proxy.getConfig().getMinimumHitPercentage())
{
hitChance = TurnBasedMinecraftMod.config.getMinimumHitPercentage();
hitChance = TurnBasedMinecraftMod.proxy.getConfig().getMinimumHitPercentage();
}
if((int)(Math.random() * 100) < hitChance)
{
@ -943,9 +943,9 @@ public class Battle
final EntityInfo targetEntityInfo = target.entityInfo;
final int finalDamageAmount = damageAmount;
next.entity.getServer().addScheduledTask(() -> {
TurnBasedMinecraftMod.attackingEntity = nextEntity;
TurnBasedMinecraftMod.proxy.setAttackingEntity(nextEntity);
targetEntity.attackEntityFrom(damageSource, finalDamageAmount);
TurnBasedMinecraftMod.attackingEntity = null;
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getEntityId(), targetEntity.getEntityId(), finalDamageAmount);
if(!(targetEntity instanceof EntityPlayer) && targetEntityInfo.defenseDamage > 0)
{
@ -953,9 +953,9 @@ public class Battle
{
// defense damage
DamageSource defenseDamageSource = DamageSource.causeMobDamage((EntityLivingBase)targetEntity);
TurnBasedMinecraftMod.attackingEntity = targetEntity;
TurnBasedMinecraftMod.proxy.setAttackingEntity(targetEntity);
nextEntity.attackEntityFrom(defenseDamageSource, targetEntityInfo.defenseDamage);
TurnBasedMinecraftMod.attackingEntity = null;
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENSE_DAMAGE, targetEntity.getEntityId(), nextEntity.getEntityId(), targetEntityInfo.defenseDamage);
}
}
@ -986,7 +986,7 @@ public class Battle
}
break;
case DEFEND:
next.remainingDefenses = TurnBasedMinecraftMod.config.getDefenseDuration();
next.remainingDefenses = TurnBasedMinecraftMod.proxy.getConfig().getDefenseDuration();
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENDING, next.entity.getEntityId(), 0, 0);
break;
case FLEE:
@ -997,9 +997,9 @@ public class Battle
{
if(c.entity instanceof EntityPlayer)
{
if(TurnBasedMinecraftMod.config.getPlayerSpeed() > fastestEnemySpeed)
if(TurnBasedMinecraftMod.proxy.getConfig().getPlayerSpeed() > fastestEnemySpeed)
{
fastestEnemySpeed = TurnBasedMinecraftMod.config.getPlayerSpeed();
fastestEnemySpeed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSpeed();
}
}
else
@ -1017,9 +1017,9 @@ public class Battle
{
if(c.entity instanceof EntityPlayer)
{
if(TurnBasedMinecraftMod.config.getPlayerSpeed() > fastestEnemySpeed)
if(TurnBasedMinecraftMod.proxy.getConfig().getPlayerSpeed() > fastestEnemySpeed)
{
fastestEnemySpeed = TurnBasedMinecraftMod.config.getPlayerSpeed();
fastestEnemySpeed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSpeed();
}
}
else
@ -1034,24 +1034,24 @@ public class Battle
int fleeProbability = 0;
if(next.entity instanceof EntityPlayer)
{
if(fastestEnemySpeed >= TurnBasedMinecraftMod.config.getPlayerSpeed())
if(fastestEnemySpeed >= TurnBasedMinecraftMod.proxy.getConfig().getPlayerSpeed())
{
fleeProbability = TurnBasedMinecraftMod.config.getFleeBadProbability();
fleeProbability = TurnBasedMinecraftMod.proxy.getConfig().getFleeBadProbability();
}
else
{
fleeProbability = TurnBasedMinecraftMod.config.getFleeGoodProbability();
fleeProbability = TurnBasedMinecraftMod.proxy.getConfig().getFleeGoodProbability();
}
}
else
{
if(fastestEnemySpeed >= next.entityInfo.speed)
{
fleeProbability = TurnBasedMinecraftMod.config.getFleeBadProbability();
fleeProbability = TurnBasedMinecraftMod.proxy.getConfig().getFleeBadProbability();
}
else
{
fleeProbability = TurnBasedMinecraftMod.config.getFleeGoodProbability();
fleeProbability = TurnBasedMinecraftMod.proxy.getConfig().getFleeGoodProbability();
}
}
if((int)(Math.random() * 100) < fleeProbability)

View file

@ -39,15 +39,15 @@ public class BattleManager
public boolean checkAttack(final LivingAttackEvent event)
{
// verify that both entities are EntityPlayer and not in creative or has a corresponding EntityInfo
if(!((event.getEntity() instanceof EntityPlayer && !((EntityPlayer)event.getEntity()).isCreative()) || TurnBasedMinecraftMod.config.getEntityInfoReference(event.getEntity().getClass().getName()) != null)
|| !((event.getSource().getTrueSource() instanceof EntityPlayer && !((EntityPlayer)event.getSource().getTrueSource()).isCreative()) || TurnBasedMinecraftMod.config.getEntityInfoReference(event.getSource().getTrueSource().getClass().getName()) != null))
if(!((event.getEntity() instanceof EntityPlayer && !((EntityPlayer)event.getEntity()).isCreative()) || TurnBasedMinecraftMod.proxy.getConfig().getEntityInfoReference(event.getEntity().getClass().getName()) != null)
|| !((event.getSource().getTrueSource() instanceof EntityPlayer && !((EntityPlayer)event.getSource().getTrueSource()).isCreative()) || TurnBasedMinecraftMod.proxy.getConfig().getEntityInfoReference(event.getSource().getTrueSource().getClass().getName()) != null))
{
return false;
}
// check if ignore battle in config
EntityInfo entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(event.getEntity());
if(entityInfo != null && (TurnBasedMinecraftMod.config.isIgnoreBattleType(entityInfo.category) || entityInfo.ignoreBattle))
EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getEntity());
if(entityInfo != null && (TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType(entityInfo.category) || entityInfo.ignoreBattle))
{
// attacked entity ignores battle
for(Battle b : battleMap.values())
@ -61,8 +61,8 @@ public class BattleManager
// logger.debug("Attack Not Canceled: attacked ignores battle");
return false;
}
entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(event.getSource().getTrueSource());
if(entityInfo != null && (TurnBasedMinecraftMod.config.isIgnoreBattleType(entityInfo.category) || entityInfo.ignoreBattle))
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getSource().getTrueSource());
if(entityInfo != null && (TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType(entityInfo.category) || entityInfo.ignoreBattle))
{
// attacker entity ignores battle
for(Battle b : battleMap.values())
@ -137,7 +137,7 @@ public class BattleManager
}
// at this point only one entity is in battle, so add entity to other side
if(battle.getSize() >= TurnBasedMinecraftMod.config.getMaxInBattle())
if(battle.getSize() >= TurnBasedMinecraftMod.proxy.getConfig().getMaxInBattle())
{
// battle limit reached, cannot add to battle
return true;

View file

@ -71,15 +71,15 @@ public class Combatant
}
if(isHaste && !isSlow)
{
c0.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerHasteSpeed();
c0.entityInfo.speed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerHasteSpeed();
}
else if(isSlow && !isHaste)
{
c0.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerSlowSpeed();
c0.entityInfo.speed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSlowSpeed();
}
else
{
c0.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerSpeed();
c0.entityInfo.speed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSpeed();
}
}
@ -105,15 +105,15 @@ public class Combatant
}
if(isHaste && !isSlow)
{
c1.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerHasteSpeed();
c1.entityInfo.speed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerHasteSpeed();
}
else if(isSlow && !isHaste)
{
c1.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerSlowSpeed();
c1.entityInfo.speed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSlowSpeed();
}
else
{
c1.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerSpeed();
c1.entityInfo.speed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSpeed();
}
}

View file

@ -1,5 +1,8 @@
package com.seodisparate.TurnBasedMinecraft.common;
import java.util.HashSet;
import java.util.Set;
import org.apache.logging.log4j.Logger;
import net.minecraft.entity.Entity;
@ -7,24 +10,34 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
public class CommonProxy
{
public void initialize() {}
private Set<AttackerViaBow> attackerViaBow = null;
private BattleManager battleManager = null;
private Entity attackingEntity = null;
private int attackingDamage = 0;
private Config config = null;
private Logger logger = null;
public boolean initializeBattleManager()
public void initialize()
{
if(TurnBasedMinecraftMod.battleManager == null)
attackerViaBow = new HashSet<AttackerViaBow>();
}
public final boolean initializeBattleManager()
{
TurnBasedMinecraftMod.battleManager = new BattleManager(TurnBasedMinecraftMod.logger);
if(battleManager == null)
{
battleManager = new BattleManager(TurnBasedMinecraftMod.logger);
return true;
}
return false;
}
public boolean cleanupBattleManager ()
public final boolean cleanupBattleManager ()
{
if(TurnBasedMinecraftMod.battleManager != null)
if(battleManager != null)
{
TurnBasedMinecraftMod.battleManager.cleanup();
TurnBasedMinecraftMod.battleManager = null;
battleManager.cleanup();
battleManager = null;
return true;
}
return false;
@ -44,9 +57,15 @@ public class CommonProxy
public void battleEnded() {}
public void postInit() {}
public void postInit()
{
config = new Config(logger);
}
public void setLogger(Logger logger) {}
public final void setLogger(Logger logger)
{
this.logger = logger;
}
public void playBattleMusic() {}
@ -58,8 +77,6 @@ public class CommonProxy
public void typeLeftBattle(String type) {}
public void setConfig(Config config) {}
public void displayString(String message) {}
public Entity getEntityByID(int id)
@ -67,9 +84,9 @@ public class CommonProxy
return FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getEntityByID(id);
}
public boolean isServerRunning()
public final boolean isServerRunning()
{
return TurnBasedMinecraftMod.battleManager != null;
return battleManager != null;
}
public Battle getLocalBattle()
@ -78,4 +95,44 @@ public class CommonProxy
}
public void createLocalBattle(int id) {}
public final Set<AttackerViaBow> getAttackerViaBowSet()
{
return attackerViaBow;
}
public final BattleManager getBattleManager()
{
return battleManager;
}
protected final void setAttackingEntity(Entity entity)
{
attackingEntity = entity;
}
protected final Entity getAttackingEntity()
{
return attackingEntity;
}
protected final void setAttackingDamage(int damage)
{
attackingDamage = damage;
}
protected final int getAttackingDamage()
{
return attackingDamage;
}
protected final Logger getLogger()
{
return logger;
}
public final Config getConfig()
{
return config;
}
}

View file

@ -22,6 +22,10 @@ import org.apache.logging.log4j.Logger;
public class 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 long battleDecisionDurationNanos = BATTLE_DECISION_DURATION_NANO_DEFAULT;
private Map<String, EntityInfo> entityInfoMap;
private Set<String> ignoreBattleTypes;
private Logger logger;
@ -39,6 +43,7 @@ public class Config
private Set<String> musicSillyTypes;
private boolean freezeCombatantsInBattle = false;
private int sillyMusicThreshold = 40;
private int configVersion = 0;
public Config(Logger logger)
{
@ -68,7 +73,7 @@ public class Config
}
else
{
TurnBasedMinecraftMod.setConfigVersion(internalVersion);
configVersion = internalVersion;
}
try
@ -93,7 +98,7 @@ public class Config
}
int configVersion = getConfigFileVersion(configFile);
if(configVersion < TurnBasedMinecraftMod.getConfigVersion())
if(configVersion < this.configVersion)
{
logger.warn("Config file " + TurnBasedMinecraftMod.CONFIG_FILENAME + " is older version, renaming...");
moveOldConfig();
@ -267,15 +272,22 @@ public class Config
}
else if(xmlReader.getLocalName().equals("BattleTurnTimeSeconds"))
{
int seconds = TurnBasedMinecraftMod.getBattleDurationSeconds();
try
{
seconds = Integer.parseInt(xmlReader.getElementText());
TurnBasedMinecraftMod.setBattleDurationSeconds(seconds);
int seconds = Integer.parseInt(xmlReader.getElementText());
battleDecisionDurationNanos = (long)(seconds) * 1000000000L;
if(battleDecisionDurationNanos < BATTLE_DECISION_DURATION_NANO_MIN)
{
battleDecisionDurationNanos = BATTLE_DECISION_DURATION_NANO_MIN;
}
else if(battleDecisionDurationNanos > BATTLE_DECISION_DURATION_NANO_MAX)
{
battleDecisionDurationNanos = BATTLE_DECISION_DURATION_NANO_MAX;
}
} catch (Throwable t)
{
logger.warn("Unable to get value for \"BattleTurnTimeSeconds\" from config, using default");
TurnBasedMinecraftMod.setBattleDurationSeconds(TurnBasedMinecraftMod.BATTLE_DECISION_DURATION_NANO_DEFAULT / 1000000000L);
battleDecisionDurationNanos = BATTLE_DECISION_DURATION_NANO_DEFAULT;
}
}
else if(xmlReader.getLocalName().equals("SillyMusicThreshold"))
@ -539,4 +551,19 @@ public class Config
{
return sillyMusicThreshold;
}
public int getConfigVersion()
{
return configVersion;
}
public long getDecisionDurationNanos()
{
return battleDecisionDurationNanos;
}
public int getDecisionDurationSeconds()
{
return (int)(battleDecisionDurationNanos / 1000000000L);
}
}

View file

@ -1,8 +1,5 @@
package com.seodisparate.TurnBasedMinecraft.common;
import java.util.HashSet;
import java.util.Set;
import org.apache.logging.log4j.Logger;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecision;
@ -10,7 +7,6 @@ import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleInfo;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleRequestInfo;
import net.minecraft.entity.Entity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
@ -38,38 +34,24 @@ public class TurnBasedMinecraftMod
public static final String MUSIC_SILLY = MUSIC_ROOT + "silly/";
public static final String MUSIC_BATTLE = MUSIC_ROOT + "battle/";
private static int CONFIG_FILE_VERSION = 0;
public static final SimpleNetworkWrapper NWINSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("seodisparate.tbmc");
protected static Logger logger;
protected static BattleManager battleManager;
private static int packetHandlerID = 0;
protected static Entity attackingEntity;
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;
@SidedProxy(modId=MODID, serverSide="com.seodisparate.TurnBasedMinecraft.common.CommonProxy", clientSide="com.seodisparate.TurnBasedMinecraft.client.ClientProxy")
public static CommonProxy commonProxy;
public static CommonProxy proxy;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
logger = event.getModLog();
proxy.setLogger(logger);
}
@EventHandler
public void init(FMLInitializationEvent event)
{
commonProxy.initialize();
battleManager = null;
attackerViaBow = new HashSet<AttackerViaBow>();
commonProxy.setLogger(logger);
proxy.initialize();
// register packets
NWINSTANCE.registerMessage(
@ -100,16 +82,14 @@ public class TurnBasedMinecraftMod
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
config = new Config(logger);
commonProxy.setConfig(config);
commonProxy.postInit();
proxy.postInit();
}
@EventHandler
public void serverStarting(FMLServerStartingEvent event)
{
logger.debug("About to initialize BattleManager");
if(commonProxy.initializeBattleManager())
if(proxy.initializeBattleManager())
{
logger.debug("Initialized BattleManager");
}
@ -119,52 +99,9 @@ public class TurnBasedMinecraftMod
public void serverStopping(FMLServerStoppingEvent event)
{
logger.debug("About to cleanup BattleManager");
if(commonProxy.cleanupBattleManager())
if(proxy.cleanupBattleManager())
{
logger.debug("Cleaned up BattleManager");
}
}
public static BattleManager getBattleManager()
{
return battleManager;
}
public static void setConfigVersion(int version)
{
CONFIG_FILE_VERSION = version;
}
public static int getConfigVersion()
{
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;
}
}
public static Config getConfig()
{
return config;
}
}

View file

@ -46,7 +46,7 @@ public class PacketBattleDecision implements IMessage
@Override
public IMessage onMessage(PacketBattleDecision message, MessageContext ctx)
{
Battle b = TurnBasedMinecraftMod.getBattleManager().getBattleByID(message.battleID);
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(message.battleID);
if(b != null)
{
EntityPlayerMP player = ctx.getServerHandler().player;

View file

@ -21,7 +21,7 @@ public class PacketBattleInfo implements IMessage
{
sideA = new ArrayList<Integer>();
sideB = new ArrayList<Integer>();
decisionNanos = TurnBasedMinecraftMod.getBattleDurationNanos();
decisionNanos = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
}
public PacketBattleInfo(Collection<Integer> sideA, Collection<Integer> sideB, long decisionNanos)
@ -68,21 +68,21 @@ public class PacketBattleInfo implements IMessage
@Override
public IMessage onMessage(PacketBattleInfo message, MessageContext ctx)
{
if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() == null)
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
{
return null;
}
TurnBasedMinecraftMod.commonProxy.getLocalBattle().clearCombatants();
TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants();
for(Integer id : message.sideA)
{
TurnBasedMinecraftMod.commonProxy.getLocalBattle().addCombatantToSideA(Minecraft.getMinecraft().world.getEntityByID(id));
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideA(Minecraft.getMinecraft().world.getEntityByID(id));
}
for(Integer id : message.sideB)
{
TurnBasedMinecraftMod.commonProxy.getLocalBattle().addCombatantToSideB(Minecraft.getMinecraft().world.getEntityByID(id));
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideB(Minecraft.getMinecraft().world.getEntityByID(id));
}
TurnBasedMinecraftMod.commonProxy.setBattleGuiTime((int)(message.decisionNanos / 1000000000L));
TurnBasedMinecraftMod.commonProxy.setBattleGuiBattleChanged();
TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(message.decisionNanos / 1000000000L));
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
return null;
}
}

View file

@ -3,7 +3,6 @@ package com.seodisparate.TurnBasedMinecraft.common.networking;
import java.util.HashMap;
import java.util.Map;
import com.seodisparate.TurnBasedMinecraft.common.Battle;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import io.netty.buffer.ByteBuf;
@ -151,7 +150,7 @@ public class PacketBattleMessage implements IMessage
@Override
public IMessage onMessage(PacketBattleMessage message, MessageContext ctx)
{
Entity fromEntity = TurnBasedMinecraftMod.commonProxy.getEntityByID(message.entityIDFrom);
Entity fromEntity = TurnBasedMinecraftMod.proxy.getEntityByID(message.entityIDFrom);
String from = "Unknown";
if(fromEntity != null)
{
@ -168,9 +167,9 @@ public class PacketBattleMessage implements IMessage
from = fromEntity.getName();
}
}
else if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() != null)
else if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
{
fromEntity = TurnBasedMinecraftMod.commonProxy.getLocalBattle().getCombatantEntity(message.entityIDFrom);
fromEntity = TurnBasedMinecraftMod.proxy.getLocalBattle().getCombatantEntity(message.entityIDFrom);
if(fromEntity != null)
{
if(fromEntity.hasCustomName())
@ -187,7 +186,7 @@ public class PacketBattleMessage implements IMessage
}
}
}
Entity toEntity = TurnBasedMinecraftMod.commonProxy.getEntityByID(message.entityIDTo);
Entity toEntity = TurnBasedMinecraftMod.proxy.getEntityByID(message.entityIDTo);
String to = "Unknown";
if(toEntity != null)
{
@ -204,9 +203,9 @@ public class PacketBattleMessage implements IMessage
to = toEntity.getName();
}
}
else if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() != null)
else if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
{
toEntity = TurnBasedMinecraftMod.commonProxy.getLocalBattle().getCombatantEntity(message.entityIDTo);
toEntity = TurnBasedMinecraftMod.proxy.getLocalBattle().getCombatantEntity(message.entityIDTo);
if(toEntity != null)
{
if(toEntity.hasCustomName())
@ -227,110 +226,110 @@ public class PacketBattleMessage implements IMessage
switch(message.messageType)
{
case ENTERED:
TurnBasedMinecraftMod.commonProxy.displayString(from + " entered battle!");
if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() == null || TurnBasedMinecraftMod.commonProxy.getLocalBattle().getId() != message.amount)
TurnBasedMinecraftMod.proxy.displayString(from + " entered battle!");
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null || TurnBasedMinecraftMod.proxy.getLocalBattle().getId() != message.amount)
{
TurnBasedMinecraftMod.commonProxy.createLocalBattle(message.amount);
TurnBasedMinecraftMod.proxy.createLocalBattle(message.amount);
}
TurnBasedMinecraftMod.commonProxy.battleStarted();
TurnBasedMinecraftMod.commonProxy.typeEnteredBattle(message.custom);
TurnBasedMinecraftMod.proxy.battleStarted();
TurnBasedMinecraftMod.proxy.typeEnteredBattle(message.custom);
break;
case FLEE:
if(message.amount != 0)
{
TurnBasedMinecraftMod.commonProxy.displayString(from + " fled battle!");
TurnBasedMinecraftMod.commonProxy.typeLeftBattle(message.custom);
TurnBasedMinecraftMod.proxy.displayString(from + " fled battle!");
TurnBasedMinecraftMod.proxy.typeLeftBattle(message.custom);
}
else
{
TurnBasedMinecraftMod.commonProxy.displayString(from + " tried to flee battle but failed!");
TurnBasedMinecraftMod.proxy.displayString(from + " tried to flee battle but failed!");
}
break;
case DIED:
TurnBasedMinecraftMod.commonProxy.displayString(from + " died in battle!");
TurnBasedMinecraftMod.commonProxy.typeLeftBattle(message.custom);
TurnBasedMinecraftMod.proxy.displayString(from + " died in battle!");
TurnBasedMinecraftMod.proxy.typeLeftBattle(message.custom);
break;
case ENDED:
TurnBasedMinecraftMod.commonProxy.displayString("Battle has ended!");
TurnBasedMinecraftMod.commonProxy.battleEnded();
TurnBasedMinecraftMod.proxy.displayString("Battle has ended!");
TurnBasedMinecraftMod.proxy.battleEnded();
break;
case ATTACK:
TurnBasedMinecraftMod.commonProxy.displayString(from + " attacked " + to + " and dealt " + message.amount + " damage!");
TurnBasedMinecraftMod.proxy.displayString(from + " attacked " + to + " and dealt " + message.amount + " damage!");
break;
case DEFEND:
TurnBasedMinecraftMod.commonProxy.displayString(from + " blocked " + to + "'s attack!");
TurnBasedMinecraftMod.proxy.displayString(from + " blocked " + to + "'s attack!");
break;
case DEFENSE_DAMAGE:
TurnBasedMinecraftMod.commonProxy.displayString(from + " retaliated from " + to + "'s attack and dealt " + message.amount + " damage!");
TurnBasedMinecraftMod.proxy.displayString(from + " retaliated from " + to + "'s attack and dealt " + message.amount + " damage!");
break;
case MISS:
TurnBasedMinecraftMod.commonProxy.displayString(from + " attacked " + to + " but missed!");
TurnBasedMinecraftMod.proxy.displayString(from + " attacked " + to + " but missed!");
break;
case DEFENDING:
TurnBasedMinecraftMod.commonProxy.displayString(from + " is defending!");
TurnBasedMinecraftMod.proxy.displayString(from + " is defending!");
break;
case DID_NOTHING:
TurnBasedMinecraftMod.commonProxy.displayString(from + " did nothing!");
TurnBasedMinecraftMod.proxy.displayString(from + " did nothing!");
break;
case USED_ITEM:
switch(UsedItemAction.valueOf(message.amount))
{
case USED_NOTHING:
TurnBasedMinecraftMod.commonProxy.displayString(from + " tried to use nothing!");
TurnBasedMinecraftMod.proxy.displayString(from + " tried to use nothing!");
break;
case USED_INVALID:
if(message.custom.length() > 0)
{
TurnBasedMinecraftMod.commonProxy.displayString(from + " tried to consume " + message.custom + " and failed!");
TurnBasedMinecraftMod.proxy.displayString(from + " tried to consume " + message.custom + " and failed!");
}
else
{
TurnBasedMinecraftMod.commonProxy.displayString(from + " tried to consume an invalid item and failed!");
TurnBasedMinecraftMod.proxy.displayString(from + " tried to consume an invalid item and failed!");
}
break;
case USED_FOOD:
TurnBasedMinecraftMod.commonProxy.displayString(from + " ate a " + message.custom + "!");
TurnBasedMinecraftMod.proxy.displayString(from + " ate a " + message.custom + "!");
break;
case USED_POTION:
TurnBasedMinecraftMod.commonProxy.displayString(from + " drank a " + message.custom + "!");
TurnBasedMinecraftMod.proxy.displayString(from + " drank a " + message.custom + "!");
break;
}
break;
case TURN_BEGIN:
TurnBasedMinecraftMod.commonProxy.displayString("The turn begins!");
TurnBasedMinecraftMod.commonProxy.battleGuiTurnBegin();
TurnBasedMinecraftMod.proxy.displayString("The turn begins!");
TurnBasedMinecraftMod.proxy.battleGuiTurnBegin();
break;
case TURN_END:
if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() != null)
if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
{
TurnBasedMinecraftMod.commonProxy.displayString("The turn ended!");
TurnBasedMinecraftMod.proxy.displayString("The turn ended!");
}
TurnBasedMinecraftMod.commonProxy.battleGuiTurnEnd();
TurnBasedMinecraftMod.proxy.battleGuiTurnEnd();
break;
case SWITCHED_ITEM:
if(message.amount != 0)
{
TurnBasedMinecraftMod.commonProxy.displayString(from + " switched to a different item!");
TurnBasedMinecraftMod.proxy.displayString(from + " switched to a different item!");
}
else
{
TurnBasedMinecraftMod.commonProxy.displayString(from + " switched to a different item but failed because it was invalid!");
TurnBasedMinecraftMod.proxy.displayString(from + " switched to a different item but failed because it was invalid!");
}
break;
case WAS_AFFECTED:
TurnBasedMinecraftMod.commonProxy.displayString(to + " was " + message.custom + " by " + from + "!");
TurnBasedMinecraftMod.proxy.displayString(to + " was " + message.custom + " by " + from + "!");
break;
case BECAME_CREATIVE:
TurnBasedMinecraftMod.commonProxy.displayString(from + " entered creative mode and left battle!");
TurnBasedMinecraftMod.proxy.displayString(from + " entered creative mode and left battle!");
break;
case FIRED_ARROW:
TurnBasedMinecraftMod.commonProxy.displayString(from + " let loose an arrow towards " + to + "!");
TurnBasedMinecraftMod.proxy.displayString(from + " let loose an arrow towards " + to + "!");
break;
case ARROW_HIT:
TurnBasedMinecraftMod.commonProxy.displayString(to + " was hit by " + from + "'s arrow!");
TurnBasedMinecraftMod.proxy.displayString(to + " was hit by " + from + "'s arrow!");
break;
case BOW_NO_AMMO:
TurnBasedMinecraftMod.commonProxy.displayString(from + " tried to use their bow but ran out of ammo!");
TurnBasedMinecraftMod.proxy.displayString(from + " tried to use their bow but ran out of ammo!");
break;
}
return null;

View file

@ -36,7 +36,7 @@ public class PacketBattleRequestInfo implements IMessage
@Override
public PacketBattleInfo onMessage(PacketBattleRequestInfo message, MessageContext ctx)
{
Battle b = TurnBasedMinecraftMod.getBattleManager().getBattleByID(message.battleID);
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(message.battleID);
if(b == null)
{
return null;