Work In Progress - Begin adding config

src/main/resources/TBM_Config.xml will be copied to this mod's config
directory. If a config file already exists and the version number is the
same, it won't be overridded. If the version number is less than the
mod's internal config file, then the old one will be renamed and the new
one will take its place. At least this is how it is planned.
This commit is contained in:
Stephen Seo 2018-08-30 16:15:20 +09:00
parent 957ad5ec38
commit 784cff7914
7 changed files with 172 additions and 7 deletions

View file

@ -30,7 +30,7 @@ public class TurnBasedMinecraftMod
public static final Duration BattleDecisionTime = Duration.ofSeconds(15); public static final Duration BattleDecisionTime = Duration.ofSeconds(15);
private static Logger logger; private static Logger logger;
public static BattleManager battleManager; private static BattleManager battleManager;
private static int packetHandlerID = 0; private static int packetHandlerID = 0;
public static Entity attackingEntity; public static Entity attackingEntity;
@ -103,4 +103,9 @@ public class TurnBasedMinecraftMod
event.setCanceled(true); event.setCanceled(true);
} }
} }
public static BattleManager getBattleManager()
{
return battleManager;
}
} }

View file

@ -6,18 +6,23 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List;
import java.util.Map; import java.util.Map;
import com.seodisparate.TurnBasedMinecraft.TurnBasedMinecraftMod; import com.seodisparate.TurnBasedMinecraft.TurnBasedMinecraftMod;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleInfo;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketHandler;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
public class Battle public class Battle
{ {
private final int id; private final int id;
private Map<Integer, Combatant> sideA; private Map<Integer, Combatant> sideA;
private Map<Integer, Combatant> sideB; private Map<Integer, Combatant> sideB;
private Map<Integer, EntityPlayer> players;
private Instant lastUpdated; private Instant lastUpdated;
private State state; private State state;
@ -72,6 +77,7 @@ public class Battle
this.id = id; this.id = id;
this.sideA = new Hashtable<Integer, Combatant>(); this.sideA = new Hashtable<Integer, Combatant>();
this.sideB = new Hashtable<Integer, Combatant>(); this.sideB = new Hashtable<Integer, Combatant>();
players = new HashMap<Integer, EntityPlayer>();
playerCount = 0; playerCount = 0;
if(sideA != null) if(sideA != null)
{ {
@ -81,6 +87,7 @@ public class Battle
if(e instanceof EntityPlayer) if(e instanceof EntityPlayer)
{ {
++playerCount; ++playerCount;
players.put(e.getEntityId(), (EntityPlayer)e);
} }
} }
} }
@ -92,6 +99,7 @@ public class Battle
if(e instanceof EntityPlayer) if(e instanceof EntityPlayer)
{ {
++playerCount; ++playerCount;
players.put(e.getEntityId(), (EntityPlayer)e);
} }
} }
} }
@ -123,6 +131,7 @@ public class Battle
if(e instanceof EntityPlayer) if(e instanceof EntityPlayer)
{ {
++playerCount; ++playerCount;
players.put(e.getEntityId(), (EntityPlayer)e);
if(state == State.DECISION) if(state == State.DECISION)
{ {
++undecidedCount; ++undecidedCount;
@ -136,6 +145,7 @@ public class Battle
if(e instanceof EntityPlayer) if(e instanceof EntityPlayer)
{ {
++playerCount; ++playerCount;
players.put(e.getEntityId(), (EntityPlayer)e);
if(state == State.DECISION) if(state == State.DECISION)
{ {
++undecidedCount; ++undecidedCount;
@ -147,6 +157,7 @@ public class Battle
{ {
sideA.clear(); sideA.clear();
sideB.clear(); sideB.clear();
players.clear();
playerCount = 0; playerCount = 0;
undecidedCount = 0; undecidedCount = 0;
} }
@ -219,6 +230,19 @@ public class Battle
return state; return state;
} }
public void notifyPlayersBattleInfo()
{
if(TurnBasedMinecraftMod.getBattleManager() == null)
{
return;
}
PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs());
for(EntityPlayer p : players.values())
{
PacketHandler.INSTANCE.sendTo(infoPacket, (EntityPlayerMP)p);
}
}
public void update() public void update()
{ {
if(lastUpdated == null) if(lastUpdated == null)

View file

@ -102,6 +102,8 @@ public class BattleManager
{ {
PacketHandler.INSTANCE.sendTo(new PacketBattleEntered(IDCounter), (EntityPlayerMP)notInBattle); PacketHandler.INSTANCE.sendTo(new PacketBattleEntered(IDCounter), (EntityPlayerMP)notInBattle);
} }
battle.notifyPlayersBattleInfo();
return true; return true;
} }
@ -127,6 +129,7 @@ public class BattleManager
PacketHandler.INSTANCE.sendTo(new PacketBattleEntered(IDCounter), (EntityPlayerMP)e); PacketHandler.INSTANCE.sendTo(new PacketBattleEntered(IDCounter), (EntityPlayerMP)e);
} }
} }
newBattle.notifyPlayersBattleInfo();
return newBattle; return newBattle;
} }

View file

@ -3,7 +3,6 @@ package com.seodisparate.TurnBasedMinecraft.common.networking;
import com.seodisparate.TurnBasedMinecraft.TurnBasedMinecraftMod; import com.seodisparate.TurnBasedMinecraft.TurnBasedMinecraftMod;
import com.seodisparate.TurnBasedMinecraft.common.Battle; import com.seodisparate.TurnBasedMinecraft.common.Battle;
import com.seodisparate.TurnBasedMinecraft.common.Battle.Decision; import com.seodisparate.TurnBasedMinecraft.common.Battle.Decision;
import com.seodisparate.TurnBasedMinecraft.common.Combatant;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
@ -43,7 +42,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.battleManager.getBattleByID(message.battleID); Battle b = TurnBasedMinecraftMod.getBattleManager().getBattleByID(message.battleID);
if(b != null && b.getState() == Battle.State.DECISION) if(b != null && b.getState() == Battle.State.DECISION)
{ {
EntityPlayerMP player = ctx.getServerHandler().player; EntityPlayerMP player = ctx.getServerHandler().player;

View file

@ -31,13 +31,13 @@ public class PacketBattleEntered implements IMessage
buf.writeInt(battleID); buf.writeInt(battleID);
} }
public static class HandlerBattleEntered implements IMessageHandler<PacketBattleEntered, PacketBattleRequestInfo> public static class HandlerBattleEntered implements IMessageHandler<PacketBattleEntered, IMessage>
{ {
@Override @Override
public PacketBattleRequestInfo onMessage(PacketBattleEntered message, MessageContext ctx) public IMessage onMessage(PacketBattleEntered message, MessageContext ctx)
{ {
TurnBasedMinecraftMod.currentBattle = new Battle(message.battleID, null, null); TurnBasedMinecraftMod.currentBattle = new Battle(message.battleID, null, null);
return new PacketBattleRequestInfo(message.battleID); 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.battleManager.getBattleByID(message.battleID); Battle b = TurnBasedMinecraftMod.getBattleManager().getBattleByID(message.battleID);
if(b == null) if(b == null)
{ {
return null; return null;

View file

@ -0,0 +1,134 @@
<TurnBasedMinecraftConfig>
<Version>1</Version>
<EntityStats>
<net.minecraft.entity.monster.EntityBlaze>
<AttackPower Probability="50">5</AttackPower>
<AttackEffect Probability="75">fire</AttackEffect>
<Evasion>5</Evasion>
</net.minecraft.entity.monster.EntityBlaze>
<net.minecraft.entity.monster.EntityCaveSpider>
<AttackPower Probability="75">2</AttackPower>
<AttackEffect Probability="90">poison</AttackEffect>
<Evasion>35</Evasion>
</net.minecraft.entity.monster.EntityCaveSpider>
<net.minecraft.entity.monster.EntityCreeper>
<IgnoreBattle>true</IgnoreBattle>
<AttackPower Probability="17" Variance="7">15</AttackPower>
<Evasion>5</Evasion>
</net.minecraft.entity.monster.EntityCreeper>
<net.minecraft.entity.monster.EntityElderGuardian>
<AttackPower Probability="65">8</AttackPower>
<DefenseDamage Probability="35">2</DefenseDamage>
<Evasion>25</Evasion>
</net.minecraft.entity.monster.EntityElderGuardian>
<net.minecraft.entity.monster.EntityEnderman>
<AttackPower Probability="80">7</AttackPower>
<Evasion>40</Evasion>
</net.minecraft.entity.monster.EntityEnderman>
<net.minecraft.entity.monster.EntityEndermite>
<AttackPower Probability="80">2</AttackPower>
<Evasion>40</Evasion>
</net.minecraft.entity.monster.EntityEndermite>
<net.minecraft.entity.monster.EntityEvoker>
<AttackPower Probability="60">6</AttackPower>
<Evasion>35</Evasion>
</net.minecraft.entity.monster.EntityEvoker>
<net.minecraft.entity.monster.EntityGhast>
<IgnoreBattle>true</IgnoreBattle>
<AttackPower Probability="20">13</AttackPower>
<Evasion>35</Evasion>
</net.minecraft.entity.monster.EntityGhast>
<net.minecraft.entity.monster.EntityGiantZombie>
<AttackPower Probability="35">11</AttackPower>
<Evasion>2</Evasion>
</net.minecraft.entity.monster.EntityGiantZombie>
<net.minecraft.entity.monster.EntityGuardian>
<AttackPower Probability="55">6</AttackPower>
<DefenseDamage Probability="30">2</DefenseDamage>
<Evasion>25</Evasion>
</net.minecraft.entity.monster.EntityGuardian>
<net.minecraft.entity.monster.EntityHusk>
<AttackPower Probability="70">3</AttackPower>
<AttackEffect Probability="95">hunger</AttackEffect>
<Evasion>5</Evasion>
</net.minecraft.entity.monster.EntityHusk>
<net.minecraft.entity.monster.EntityIronGolem>
<AttackPower Probability="85" Variance="7">14</AttackPower>
<Evasion>5</Evasion>
</net.minecraft.entity.monster.EntityIronGolem>
<net.minecraft.entity.monster.EntityMagmaCube>
<AttackPower Probability="35">3</AttackPower>
<Evasion>12</Evasion>
</net.minecraft.entity.monster.EntityMagmaCube>
<net.minecraft.entity.monster.EntityPigZombie>
<AttackPower Probability="70">8</AttackPower>
<Evasion>10</Evasion>
</net.minecraft.entity.monster.EntityPigZombie>
<net.minecraft.entity.monster.EntityPolarBear>
<AttackPower Probability="67">6</AttackPower>
<Evasion>5</Evasion>
</net.minecraft.entity.monster.EntityPolarBear>
<net.minecraft.entity.monster.EntityShulker>
<AttackPower Probability="80">4</AttackPower>
<Evasion>15</Evasion>
</net.minecraft.entity.monster.EntityShulker>
<net.minecraft.entity.monster.EntitySilverFish>
<AttackPower Probability="85">1</AttackPower>
<Evasion>37</Evasion>
</net.minecraft.entity.monster.EntitySilverFish>
<net.minecraft.entity.monster.EntitySkeleton>
<AttackPower Probability="75" Variance="1">3</AttackPower>
<Evasion>13</Evasion>
</net.minecraft.entity.monster.EntitySkeleton>
<net.minecraft.entity.monster.EntitySlime>
<AttackPower Probability="35">2</AttackPower>
<Evasion>10</Evasion>
</net.minecraft.entity.monster.EntitySlime>
<net.minecraft.entity.monster.EntitySnowman
Passive="true">
<AttackPower Probability="80">0</AttackPower>
<Evasion>5</Evasion>
</net.minecraft.entity.monster.EntitySnowman>
<net.minecraft.entity.monster.EntitySpider>
<AttackPower Probability="70">2</AttackPower>
<Evasion>25</Evasion>
<Conflicts>
<net.minecraft.entity.monster.EntityCaveSpider></net.minecraft.entity.monster.EntityCaveSpider>
</Conflicts>
</net.minecraft.entity.monster.EntitySpider>
<net.minecraft.entity.monster.EntityStray>
<AttackPower Probability="75" Variance="1">3</AttackPower>
<AttackEffect Probability="90">slowness</AttackEffect>
<Evasion>13</Evasion>
</net.minecraft.entity.monster.EntityStray>
<net.minecraft.entity.monster.EntityVex>
<AttackPower Probability="65">9</AttackPower>
<Evasion>30</Evasion>
</net.minecraft.entity.monster.EntityVex>
<net.minecraft.entity.monster.EntityVindicator>
<AttackPower Probability="70">13</AttackPower>
<Evasion>10</Evasion>
</net.minecraft.entity.monster.EntityVindicator>
<net.minecraft.entity.monster.EntityWitch>
<AttackPower Probability="75" Variance="1">5</AttackPower>
<Evasion>8</Evasion>
</net.minecraft.entity.monster.EntityWitch>
<net.minecraft.entity.monster.EntityWitherSkeleton>
<AttackPower Probability="70">8</AttackPower>
<AttackEffect Probability="90">wither</AttackEffect>
<Evasion>7</Evasion>
</net.minecraft.entity.monster.EntityWitherSkeleton>
<net.minecraft.entity.monster.EntityZombie>
<AttackPower Probability="70">3</AttackPower>
<Conflicts>
<net.minecraft.entity.monster.EntityHusk></net.minecraft.entity.monster.EntityHusk>
<net.minecraft.entity.monster.EntityZombieVillager></net.minecraft.entity.monster.EntityZombieVillager>
</Conflicts>
<Evasion>5</Evasion>
</net.minecraft.entity.monster.EntityZombie>
<net.minecraft.entity.monster.EntityZombieVillager>
<AttackPower Probability="70">3</AttackPower>
<Evasion>5</Evasion>
</net.minecraft.entity.monster.EntityZombieVillager>
</EntityStats>
</TurnBasedMinecraftConfig>