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.Battle;
import com.seodisparate.TurnBasedMinecraft.common.Combatant; import com.seodisparate.TurnBasedMinecraft.common.Combatant;
import com.seodisparate.TurnBasedMinecraft.common.Config;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecision; import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecision;
@ -16,9 +17,9 @@ import net.minecraft.client.gui.GuiScreen;
public class BattleGui extends GuiScreen public class BattleGui extends GuiScreen
{ {
public AtomicInteger timeRemaining; private AtomicInteger timeRemaining;
public long lastInstant; private long lastInstant;
public long elapsedTime; private long elapsedTime;
private MenuState state; private MenuState state;
private boolean stateChanged; private boolean stateChanged;
private String info; private String info;
@ -104,7 +105,7 @@ public class BattleGui extends GuiScreen
public BattleGui() public BattleGui()
{ {
timeRemaining = new AtomicInteger(TurnBasedMinecraftMod.getBattleDurationSeconds()); timeRemaining = new AtomicInteger((int)(Config.BATTLE_DECISION_DURATION_NANO_DEFAULT / 1000000000L));
lastInstant = System.nanoTime(); lastInstant = System.nanoTime();
elapsedTime = 0; elapsedTime = 0;
state = MenuState.MAIN_MENU; state = MenuState.MAIN_MENU;
@ -119,20 +120,20 @@ public class BattleGui extends GuiScreen
public void turnBegin() 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); setState(MenuState.WAITING);
} }
public void turnEnd() 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; elapsedTime = 0;
lastInstant = System.nanoTime(); lastInstant = System.nanoTime();
setState(MenuState.MAIN_MENU); setState(MenuState.MAIN_MENU);
@ -156,15 +157,15 @@ public class BattleGui extends GuiScreen
{ {
case MAIN_MENU: case MAIN_MENU:
info = "What will you do?"; 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.ATTACK.getValue(), width*3/7 - 25, 40, 50, 20, "Attack"));
buttonList.add(new GuiButton(ButtonAction.DEFEND.getValue(), width*4/7 - 25, height - 90, 50, 20, "Defend")); 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, height - 70, 50, 20, "Item")); 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, height - 70, 50, 20, "Flee")); buttonList.add(new GuiButton(ButtonAction.FLEE.getValue(), width*4/7 - 25, 60, 50, 20, "Flee"));
break; break;
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.commonProxy.getLocalBattle().getSideAEntrySet()) for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle().getSideAEntrySet())
{ {
if(e.getValue().entity != null) if(e.getValue().entity != null)
{ {
@ -177,7 +178,7 @@ public class BattleGui extends GuiScreen
y += 20; y += 20;
} }
y = 30; 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) if(e.getValue().entity != null)
{ {
@ -222,12 +223,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.commonProxy.getLocalBattle() == null) if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
{ {
drawHoveringText("Waiting...", width / 2 - 50, height / 2); drawHoveringText("Waiting...", width / 2 - 50, height / 2);
return; 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(); long nextInstant = System.nanoTime();
elapsedTime += nextInstant - lastInstant; elapsedTime += nextInstant - lastInstant;
@ -273,20 +274,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.commonProxy.getLocalBattle().getId(), Battle.Decision.DEFEND, 0)); TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.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.commonProxy.getLocalBattle().getId(), Battle.Decision.FLEE, 0)); TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.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.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); setState(MenuState.WAITING);
} }
else else
@ -306,7 +307,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.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) 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;
@ -321,7 +322,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.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); setState(MenuState.WAITING);
} }
else else
@ -358,4 +359,9 @@ public class BattleGui extends GuiScreen
super.keyTyped(typedChar, keyCode); super.keyTyped(typedChar, keyCode);
} }
} }
public void setTimeRemaining(int remaining)
{
timeRemaining.set(remaining);
}
} }

View file

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

View file

@ -16,7 +16,7 @@ public class AttackEventHandler
{ {
return false; return false;
} }
else if(event.getSource().getTrueSource().equals(TurnBasedMinecraftMod.attackingEntity)) else if(event.getSource().getTrueSource().equals(TurnBasedMinecraftMod.proxy.getAttackingEntity()))
{ {
return true; return true;
} }
@ -25,9 +25,9 @@ public class AttackEventHandler
Queue<AttackerViaBow> removeQueue = new ArrayDeque<AttackerViaBow>(); Queue<AttackerViaBow> removeQueue = new ArrayDeque<AttackerViaBow>();
final long now = System.nanoTime(); final long now = System.nanoTime();
boolean isValid = false; 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) if(now - attacker.attackTime >= AttackerViaBow.ATTACK_TIMEOUT)
{ {
@ -38,7 +38,7 @@ public class AttackEventHandler
removeQueue.add(attacker); removeQueue.add(attacker);
if(!isValid) if(!isValid)
{ {
Battle b = TurnBasedMinecraftMod.battleManager.getBattleByID(attacker.battleID); Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(attacker.battleID);
if(b != null) if(b != null)
{ {
b.sendMessageToAllPlayers(PacketBattleMessage.MessageType.ARROW_HIT, attacker.entity.getEntityId(), event.getEntity().getEntityId(), 0); 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()) for(AttackerViaBow next = removeQueue.poll(); next != null; next = removeQueue.poll())
{ {
TurnBasedMinecraftMod.attackerViaBow.remove(next); TurnBasedMinecraftMod.proxy.getAttackerViaBowSet().remove(next);
} }
} }
return isValid; return isValid;
@ -64,18 +64,18 @@ public class AttackEventHandler
return; 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); event.setCanceled(true);
} }
else else
{ {
// TurnBasedMinecraftMod.logger.debug("Did not cancel attack"); // 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) for(Entity e : sideA)
{ {
EntityInfo entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(e); EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.commonProxy.isServerRunning()) if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
{ {
continue; continue;
} }
@ -148,7 +148,7 @@ public class Battle
playerCount.incrementAndGet(); playerCount.incrementAndGet();
players.put(e.getEntityId(), newCombatant); players.put(e.getEntityId(), newCombatant);
} }
if(TurnBasedMinecraftMod.config.isFreezeCombatantsEnabled()) if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
{ {
newCombatant.x = e.posX; newCombatant.x = e.posX;
newCombatant.z = e.posZ; newCombatant.z = e.posZ;
@ -161,8 +161,8 @@ public class Battle
{ {
for(Entity e : sideB) for(Entity e : sideB)
{ {
EntityInfo entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(e); EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.commonProxy.isServerRunning()) if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
{ {
continue; continue;
} }
@ -176,7 +176,7 @@ public class Battle
playerCount.incrementAndGet(); playerCount.incrementAndGet();
players.put(e.getEntityId(), newCombatant); players.put(e.getEntityId(), newCombatant);
} }
if(TurnBasedMinecraftMod.config.isFreezeCombatantsEnabled()) if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
{ {
newCombatant.x = e.posX; newCombatant.x = e.posX;
newCombatant.z = e.posZ; newCombatant.z = e.posZ;
@ -220,7 +220,7 @@ public class Battle
lastInstant = System.nanoTime(); lastInstant = System.nanoTime();
state = State.DECISION; state = State.DECISION;
undecidedCount.set(playerCount.get()); undecidedCount.set(playerCount.get());
timer = TurnBasedMinecraftMod.getBattleDurationNanos(); timer = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
battleEnded = false; battleEnded = false;
notifyPlayersBattleInfo(); notifyPlayersBattleInfo();
@ -258,8 +258,8 @@ public class Battle
public void addCombatantToSideA(Entity e) public void addCombatantToSideA(Entity e)
{ {
EntityInfo entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(e); EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.commonProxy.isServerRunning()) if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
{ {
return; return;
} }
@ -287,7 +287,7 @@ public class Battle
undecidedCount.incrementAndGet(); undecidedCount.incrementAndGet();
} }
} }
if(TurnBasedMinecraftMod.config.isFreezeCombatantsEnabled()) if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
{ {
newCombatant.x = e.posX; newCombatant.x = e.posX;
newCombatant.z = e.posZ; newCombatant.z = e.posZ;
@ -311,8 +311,8 @@ public class Battle
public void addCombatantToSideB(Entity e) public void addCombatantToSideB(Entity e)
{ {
EntityInfo entityInfo = TurnBasedMinecraftMod.config.getMatchingEntityInfo(e); EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.commonProxy.isServerRunning()) if(entityInfo == null && !(e instanceof EntityPlayer) && TurnBasedMinecraftMod.proxy.isServerRunning())
{ {
return; return;
} }
@ -340,7 +340,7 @@ public class Battle
undecidedCount.incrementAndGet(); undecidedCount.incrementAndGet();
} }
} }
if(TurnBasedMinecraftMod.config.isFreezeCombatantsEnabled()) if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
{ {
newCombatant.x = e.posX; newCombatant.x = e.posX;
newCombatant.z = e.posZ; newCombatant.z = e.posZ;
@ -681,7 +681,7 @@ public class Battle
combatantsChanged = true; combatantsChanged = true;
} }
} }
if(TurnBasedMinecraftMod.config.isFreezeCombatantsEnabled()) if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
{ {
enforceFreezePositions(); enforceFreezePositions();
} }
@ -731,7 +731,7 @@ public class Battle
} }
} }
state = State.ACTION; state = State.ACTION;
timer = TurnBasedMinecraftMod.getBattleDurationNanos(); timer = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_BEGIN, 0, 0, 0); sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_BEGIN, 0, 0, 0);
turnOrderQueue.clear(); turnOrderQueue.clear();
for(Combatant c : sideA.values()) for(Combatant c : sideA.values())
@ -797,7 +797,7 @@ public class Battle
final Entity targetEntity = target.entity; final Entity targetEntity = target.entity;
final float yawDirection = Utility.yawDirection(next.entity.posX, next.entity.posZ, target.entity.posX, target.entity.posZ); 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); 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.yaw = yawDirection;
next.pitch = pitchDirection; next.pitch = pitchDirection;
@ -806,9 +806,9 @@ public class Battle
// have player look at attack target // have player look at attack target
((EntityPlayerMP)nextEntity).connection.setPlayerLocation(nextEntity.posX, nextEntity.posY, nextEntity.posZ, yawDirection, pitchDirection); ((EntityPlayerMP)nextEntity).connection.setPlayerLocation(nextEntity.posX, nextEntity.posY, nextEntity.posZ, yawDirection, pitchDirection);
ItemBow itemBow = (ItemBow)heldItemStack.getItem(); 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)); 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); sendMessageToAllPlayers(PacketBattleMessage.MessageType.FIRED_ARROW, nextEntity.getEntityId(), targetEntity.getEntityId(), 0);
@ -820,18 +820,18 @@ public class Battle
} }
continue; continue;
} }
int hitChance = TurnBasedMinecraftMod.config.getPlayerAttackProbability(); int hitChance = TurnBasedMinecraftMod.proxy.getConfig().getPlayerAttackProbability();
if(target.entity instanceof EntityPlayer) if(target.entity instanceof EntityPlayer)
{ {
hitChance -= TurnBasedMinecraftMod.config.getPlayerEvasion(); hitChance -= TurnBasedMinecraftMod.proxy.getConfig().getPlayerEvasion();
} }
else else
{ {
hitChance -= target.entityInfo.evasion; 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) if((int)(Math.random() * 100) < hitChance)
{ {
@ -843,7 +843,7 @@ public class Battle
final EntityInfo targetEntityInfo = target.entityInfo; final EntityInfo targetEntityInfo = target.entityInfo;
final float yawDirection = Utility.yawDirection(next.entity.posX, next.entity.posZ, target.entity.posX, target.entity.posZ); 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); 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.yaw = yawDirection;
next.pitch = pitchDirection; next.pitch = pitchDirection;
@ -851,20 +851,20 @@ public class Battle
next.entity.getServer().addScheduledTask(() -> { next.entity.getServer().addScheduledTask(() -> {
// have player look at attack target // have player look at attack target
((EntityPlayerMP)nextEntity).connection.setPlayerLocation(nextEntity.posX, nextEntity.posY, nextEntity.posZ, yawDirection, pitchDirection); ((EntityPlayerMP)nextEntity).connection.setPlayerLocation(nextEntity.posX, nextEntity.posY, nextEntity.posZ, yawDirection, pitchDirection);
TurnBasedMinecraftMod.attackingEntity = nextEntity; TurnBasedMinecraftMod.proxy.setAttackingEntity(nextEntity);
TurnBasedMinecraftMod.attackingDamage = 0; TurnBasedMinecraftMod.proxy.setAttackingDamage(0);
((EntityPlayer)nextEntity).attackTargetEntityWithCurrentItem(targetEntity); ((EntityPlayer)nextEntity).attackTargetEntityWithCurrentItem(targetEntity);
TurnBasedMinecraftMod.attackingEntity = null; TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getEntityId(), targetEntity.getEntityId(), TurnBasedMinecraftMod.attackingDamage); sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getEntityId(), targetEntity.getEntityId(), TurnBasedMinecraftMod.proxy.getAttackingDamage());
if(!(targetEntity instanceof EntityPlayer) && targetEntityInfo.defenseDamage > 0) if(!(targetEntity instanceof EntityPlayer) && targetEntityInfo.defenseDamage > 0)
{ {
if((int)(Math.random() * 100) < targetEntityInfo.defenseDamageProbability) if((int)(Math.random() * 100) < targetEntityInfo.defenseDamageProbability)
{ {
// defense damage // defense damage
DamageSource defenseDamageSource = DamageSource.causeMobDamage((EntityLivingBase)targetEntity); DamageSource defenseDamageSource = DamageSource.causeMobDamage((EntityLivingBase)targetEntity);
TurnBasedMinecraftMod.attackingEntity = targetEntity; TurnBasedMinecraftMod.proxy.setAttackingEntity(targetEntity);
nextEntity.attackEntityFrom(defenseDamageSource, targetEntityInfo.defenseDamage); nextEntity.attackEntityFrom(defenseDamageSource, targetEntityInfo.defenseDamage);
TurnBasedMinecraftMod.attackingEntity = null; TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENSE_DAMAGE, targetEntity.getEntityId(), nextEntity.getEntityId(), targetEntityInfo.defenseDamage); sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENSE_DAMAGE, targetEntity.getEntityId(), nextEntity.getEntityId(), targetEntityInfo.defenseDamage);
} }
} }
@ -916,15 +916,15 @@ public class Battle
int hitChance = next.entityInfo.attackProbability; int hitChance = next.entityInfo.attackProbability;
if(target.entity instanceof EntityPlayer) if(target.entity instanceof EntityPlayer)
{ {
hitChance -= TurnBasedMinecraftMod.config.getPlayerEvasion(); hitChance -= TurnBasedMinecraftMod.proxy.getConfig().getPlayerEvasion();
} }
else else
{ {
hitChance -= target.entityInfo.evasion; 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) if((int)(Math.random() * 100) < hitChance)
{ {
@ -943,9 +943,9 @@ public class Battle
final EntityInfo targetEntityInfo = target.entityInfo; final EntityInfo targetEntityInfo = target.entityInfo;
final int finalDamageAmount = damageAmount; final int finalDamageAmount = damageAmount;
next.entity.getServer().addScheduledTask(() -> { next.entity.getServer().addScheduledTask(() -> {
TurnBasedMinecraftMod.attackingEntity = nextEntity; TurnBasedMinecraftMod.proxy.setAttackingEntity(nextEntity);
targetEntity.attackEntityFrom(damageSource, finalDamageAmount); targetEntity.attackEntityFrom(damageSource, finalDamageAmount);
TurnBasedMinecraftMod.attackingEntity = null; TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getEntityId(), targetEntity.getEntityId(), finalDamageAmount); sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getEntityId(), targetEntity.getEntityId(), finalDamageAmount);
if(!(targetEntity instanceof EntityPlayer) && targetEntityInfo.defenseDamage > 0) if(!(targetEntity instanceof EntityPlayer) && targetEntityInfo.defenseDamage > 0)
{ {
@ -953,9 +953,9 @@ public class Battle
{ {
// defense damage // defense damage
DamageSource defenseDamageSource = DamageSource.causeMobDamage((EntityLivingBase)targetEntity); DamageSource defenseDamageSource = DamageSource.causeMobDamage((EntityLivingBase)targetEntity);
TurnBasedMinecraftMod.attackingEntity = targetEntity; TurnBasedMinecraftMod.proxy.setAttackingEntity(targetEntity);
nextEntity.attackEntityFrom(defenseDamageSource, targetEntityInfo.defenseDamage); nextEntity.attackEntityFrom(defenseDamageSource, targetEntityInfo.defenseDamage);
TurnBasedMinecraftMod.attackingEntity = null; TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENSE_DAMAGE, targetEntity.getEntityId(), nextEntity.getEntityId(), targetEntityInfo.defenseDamage); sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENSE_DAMAGE, targetEntity.getEntityId(), nextEntity.getEntityId(), targetEntityInfo.defenseDamage);
} }
} }
@ -986,7 +986,7 @@ public class Battle
} }
break; break;
case DEFEND: case DEFEND:
next.remainingDefenses = TurnBasedMinecraftMod.config.getDefenseDuration(); next.remainingDefenses = TurnBasedMinecraftMod.proxy.getConfig().getDefenseDuration();
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENDING, next.entity.getEntityId(), 0, 0); sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENDING, next.entity.getEntityId(), 0, 0);
break; break;
case FLEE: case FLEE:
@ -997,9 +997,9 @@ public class Battle
{ {
if(c.entity instanceof EntityPlayer) 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 else
@ -1017,9 +1017,9 @@ public class Battle
{ {
if(c.entity instanceof EntityPlayer) 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 else
@ -1034,24 +1034,24 @@ public class Battle
int fleeProbability = 0; int fleeProbability = 0;
if(next.entity instanceof EntityPlayer) 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 else
{ {
fleeProbability = TurnBasedMinecraftMod.config.getFleeGoodProbability(); fleeProbability = TurnBasedMinecraftMod.proxy.getConfig().getFleeGoodProbability();
} }
} }
else else
{ {
if(fastestEnemySpeed >= next.entityInfo.speed) if(fastestEnemySpeed >= next.entityInfo.speed)
{ {
fleeProbability = TurnBasedMinecraftMod.config.getFleeBadProbability(); fleeProbability = TurnBasedMinecraftMod.proxy.getConfig().getFleeBadProbability();
} }
else else
{ {
fleeProbability = TurnBasedMinecraftMod.config.getFleeGoodProbability(); fleeProbability = TurnBasedMinecraftMod.proxy.getConfig().getFleeGoodProbability();
} }
} }
if((int)(Math.random() * 100) < fleeProbability) if((int)(Math.random() * 100) < fleeProbability)

View file

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

View file

@ -71,15 +71,15 @@ public class Combatant
} }
if(isHaste && !isSlow) if(isHaste && !isSlow)
{ {
c0.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerHasteSpeed(); c0.entityInfo.speed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerHasteSpeed();
} }
else if(isSlow && !isHaste) else if(isSlow && !isHaste)
{ {
c0.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerSlowSpeed(); c0.entityInfo.speed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSlowSpeed();
} }
else else
{ {
c0.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerSpeed(); c0.entityInfo.speed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSpeed();
} }
} }
@ -105,15 +105,15 @@ public class Combatant
} }
if(isHaste && !isSlow) if(isHaste && !isSlow)
{ {
c1.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerHasteSpeed(); c1.entityInfo.speed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerHasteSpeed();
} }
else if(isSlow && !isHaste) else if(isSlow && !isHaste)
{ {
c1.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerSlowSpeed(); c1.entityInfo.speed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSlowSpeed();
} }
else 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; package com.seodisparate.TurnBasedMinecraft.common;
import java.util.HashSet;
import java.util.Set;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -7,24 +10,34 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
public class CommonProxy 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()
{
if(battleManager == null)
{ {
TurnBasedMinecraftMod.battleManager = new BattleManager(TurnBasedMinecraftMod.logger); battleManager = new BattleManager(TurnBasedMinecraftMod.logger);
return true; return true;
} }
return false; return false;
} }
public boolean cleanupBattleManager () public final boolean cleanupBattleManager ()
{ {
if(TurnBasedMinecraftMod.battleManager != null) if(battleManager != null)
{ {
TurnBasedMinecraftMod.battleManager.cleanup(); battleManager.cleanup();
TurnBasedMinecraftMod.battleManager = null; battleManager = null;
return true; return true;
} }
return false; return false;
@ -44,9 +57,15 @@ public class CommonProxy
public void battleEnded() {} 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() {} public void playBattleMusic() {}
@ -58,8 +77,6 @@ public class CommonProxy
public void typeLeftBattle(String type) {} public void typeLeftBattle(String type) {}
public void setConfig(Config config) {}
public void displayString(String message) {} public void displayString(String message) {}
public Entity getEntityByID(int id) public Entity getEntityByID(int id)
@ -67,9 +84,9 @@ public class CommonProxy
return FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getEntityByID(id); return FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getEntityByID(id);
} }
public boolean isServerRunning() public final boolean isServerRunning()
{ {
return TurnBasedMinecraftMod.battleManager != null; return battleManager != null;
} }
public Battle getLocalBattle() public Battle getLocalBattle()
@ -78,4 +95,44 @@ public class CommonProxy
} }
public void createLocalBattle(int id) {} 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 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 Map<String, EntityInfo> entityInfoMap;
private Set<String> ignoreBattleTypes; private Set<String> ignoreBattleTypes;
private Logger logger; private Logger logger;
@ -39,6 +43,7 @@ public class Config
private Set<String> musicSillyTypes; private Set<String> musicSillyTypes;
private boolean freezeCombatantsInBattle = false; private boolean freezeCombatantsInBattle = false;
private int sillyMusicThreshold = 40; private int sillyMusicThreshold = 40;
private int configVersion = 0;
public Config(Logger logger) public Config(Logger logger)
{ {
@ -68,7 +73,7 @@ public class Config
} }
else else
{ {
TurnBasedMinecraftMod.setConfigVersion(internalVersion); configVersion = internalVersion;
} }
try try
@ -93,7 +98,7 @@ public class Config
} }
int configVersion = getConfigFileVersion(configFile); int configVersion = getConfigFileVersion(configFile);
if(configVersion < TurnBasedMinecraftMod.getConfigVersion()) if(configVersion < this.configVersion)
{ {
logger.warn("Config file " + TurnBasedMinecraftMod.CONFIG_FILENAME + " is older version, renaming..."); logger.warn("Config file " + TurnBasedMinecraftMod.CONFIG_FILENAME + " is older version, renaming...");
moveOldConfig(); moveOldConfig();
@ -267,15 +272,22 @@ public class Config
} }
else if(xmlReader.getLocalName().equals("BattleTurnTimeSeconds")) else if(xmlReader.getLocalName().equals("BattleTurnTimeSeconds"))
{ {
int seconds = TurnBasedMinecraftMod.getBattleDurationSeconds();
try try
{ {
seconds = Integer.parseInt(xmlReader.getElementText()); int seconds = Integer.parseInt(xmlReader.getElementText());
TurnBasedMinecraftMod.setBattleDurationSeconds(seconds); 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) } catch (Throwable t)
{ {
logger.warn("Unable to get value for \"BattleTurnTimeSeconds\" from config, using default"); 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")) else if(xmlReader.getLocalName().equals("SillyMusicThreshold"))
@ -539,4 +551,19 @@ public class Config
{ {
return sillyMusicThreshold; 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; package com.seodisparate.TurnBasedMinecraft.common;
import java.util.HashSet;
import java.util.Set;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecision; 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.PacketBattleMessage;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleRequestInfo; import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleRequestInfo;
import net.minecraft.entity.Entity;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler; 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_SILLY = MUSIC_ROOT + "silly/";
public static final String MUSIC_BATTLE = MUSIC_ROOT + "battle/"; 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"); public static final SimpleNetworkWrapper NWINSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("seodisparate.tbmc");
protected static Logger logger; protected static Logger logger;
protected static BattleManager battleManager;
private static int packetHandlerID = 0; 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") @SidedProxy(modId=MODID, serverSide="com.seodisparate.TurnBasedMinecraft.common.CommonProxy", clientSide="com.seodisparate.TurnBasedMinecraft.client.ClientProxy")
public static CommonProxy commonProxy; public static CommonProxy proxy;
@EventHandler @EventHandler
public void preInit(FMLPreInitializationEvent event) public void preInit(FMLPreInitializationEvent event)
{ {
logger = event.getModLog(); logger = event.getModLog();
proxy.setLogger(logger);
} }
@EventHandler @EventHandler
public void init(FMLInitializationEvent event) public void init(FMLInitializationEvent event)
{ {
commonProxy.initialize(); proxy.initialize();
battleManager = null;
attackerViaBow = new HashSet<AttackerViaBow>();
commonProxy.setLogger(logger);
// register packets // register packets
NWINSTANCE.registerMessage( NWINSTANCE.registerMessage(
@ -100,16 +82,14 @@ public class TurnBasedMinecraftMod
@EventHandler @EventHandler
public void postInit(FMLPostInitializationEvent event) public void postInit(FMLPostInitializationEvent event)
{ {
config = new Config(logger); proxy.postInit();
commonProxy.setConfig(config);
commonProxy.postInit();
} }
@EventHandler @EventHandler
public void serverStarting(FMLServerStartingEvent event) public void serverStarting(FMLServerStartingEvent event)
{ {
logger.debug("About to initialize BattleManager"); logger.debug("About to initialize BattleManager");
if(commonProxy.initializeBattleManager()) if(proxy.initializeBattleManager())
{ {
logger.debug("Initialized BattleManager"); logger.debug("Initialized BattleManager");
} }
@ -119,52 +99,9 @@ public class TurnBasedMinecraftMod
public void serverStopping(FMLServerStoppingEvent event) public void serverStopping(FMLServerStoppingEvent event)
{ {
logger.debug("About to cleanup BattleManager"); logger.debug("About to cleanup BattleManager");
if(commonProxy.cleanupBattleManager()) if(proxy.cleanupBattleManager())
{ {
logger.debug("Cleaned up BattleManager"); 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 @Override
public IMessage onMessage(PacketBattleDecision message, MessageContext ctx) 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) if(b != null)
{ {
EntityPlayerMP player = ctx.getServerHandler().player; EntityPlayerMP player = ctx.getServerHandler().player;

View file

@ -21,7 +21,7 @@ public class PacketBattleInfo implements IMessage
{ {
sideA = new ArrayList<Integer>(); sideA = new ArrayList<Integer>();
sideB = 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) public PacketBattleInfo(Collection<Integer> sideA, Collection<Integer> sideB, long decisionNanos)
@ -68,21 +68,21 @@ public class PacketBattleInfo implements IMessage
@Override @Override
public IMessage onMessage(PacketBattleInfo message, MessageContext ctx) public IMessage onMessage(PacketBattleInfo message, MessageContext ctx)
{ {
if(TurnBasedMinecraftMod.commonProxy.getLocalBattle() == null) if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
{ {
return null; return null;
} }
TurnBasedMinecraftMod.commonProxy.getLocalBattle().clearCombatants(); TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants();
for(Integer id : message.sideA) 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) 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.proxy.setBattleGuiTime((int)(message.decisionNanos / 1000000000L));
TurnBasedMinecraftMod.commonProxy.setBattleGuiBattleChanged(); TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
return null; return null;
} }
} }

View file

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

View file

@ -36,7 +36,7 @@ public class PacketBattleRequestInfo implements IMessage
@Override @Override
public PacketBattleInfo onMessage(PacketBattleRequestInfo message, MessageContext ctx) 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) if(b == null)
{ {
return null; return null;