Version 1.3, Fixes, improvements
Changed turn-based-battle start behavior to also start when a hostile mob targets a player or entity in battle. Added config option to revert to old-style battle starting behavior. (Since config version updated, older config will be moved and the new config will take its place.) Changed mob attack target in Battle to whatever they were targeting (via a call to "getAttackTarget()").
This commit is contained in:
parent
6e7cd0177a
commit
115fa02753
7 changed files with 148 additions and 18 deletions
|
@ -10,7 +10,7 @@ buildscript {
|
|||
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
|
||||
|
||||
version = "1.2"
|
||||
version = "1.3"
|
||||
group = "com.seodisparate.TurnBasedMinecraft" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = "TurnBasedMinecraft"
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Queue;
|
|||
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage;
|
||||
|
||||
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class AttackEventHandler
|
||||
|
@ -83,4 +84,20 @@ public class AttackEventHandler
|
|||
TurnBasedMinecraftMod.proxy.setAttackingDamage((int) event.getAmount());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void entityTargeted(LivingSetAttackTargetEvent event)
|
||||
{
|
||||
if(event.getEntity().world.isRemote || TurnBasedMinecraftMod.proxy.getConfig().isOldBattleBehaviorEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if(event.getEntity() != null
|
||||
&& event.getTarget() != null
|
||||
&& !TurnBasedMinecraftMod.proxy.getConfig().getBattleIgnoringPlayers().contains(event.getEntity().getEntityId())
|
||||
&& !TurnBasedMinecraftMod.proxy.getConfig().getBattleIgnoringPlayers().contains(event.getTarget().getEntityId()))
|
||||
{
|
||||
TurnBasedMinecraftMod.proxy.getBattleManager().checkTargeted(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleInfo;
|
|||
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
@ -885,27 +886,35 @@ public class Battle
|
|||
}
|
||||
else
|
||||
{
|
||||
if(next.isSideA)
|
||||
EntityLivingBase attackTarget = ((EntityLiving)next.entity).getAttackTarget();
|
||||
if(attackTarget != null && hasCombatant(attackTarget.getEntityId()))
|
||||
{
|
||||
int randomTargetIndex = (int)(Math.random() * sideB.size());
|
||||
for(Combatant c : sideB.values())
|
||||
{
|
||||
if(randomTargetIndex-- == 0)
|
||||
{
|
||||
target = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
target = getCombatantByID(attackTarget.getEntityId());
|
||||
}
|
||||
else
|
||||
{
|
||||
int randomTargetIndex = (int)(Math.random() * sideA.size());
|
||||
for(Combatant c : sideA.values())
|
||||
if(next.isSideA)
|
||||
{
|
||||
if(randomTargetIndex-- == 0)
|
||||
int randomTargetIndex = (int)(Math.random() * sideB.size());
|
||||
for(Combatant c : sideB.values())
|
||||
{
|
||||
target = c;
|
||||
break;
|
||||
if(randomTargetIndex-- == 0)
|
||||
{
|
||||
target = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int randomTargetIndex = (int)(Math.random() * sideA.size());
|
||||
for(Combatant c : sideA.values())
|
||||
{
|
||||
if(randomTargetIndex-- == 0)
|
||||
{
|
||||
target = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.apache.logging.log4j.Logger;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
|
||||
|
||||
public class BattleManager
|
||||
{
|
||||
|
@ -155,6 +156,89 @@ public class BattleManager
|
|||
return true;
|
||||
}
|
||||
|
||||
public void checkTargeted(LivingSetAttackTargetEvent event)
|
||||
{
|
||||
EntityInfo attackerInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getEntity());
|
||||
EntityInfo targetedInfo = event.getTarget() instanceof EntityPlayer ? null : TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getTarget());
|
||||
if((event.getTarget() instanceof EntityPlayer && ((EntityPlayer)event.getTarget()).isCreative())
|
||||
|| attackerInfo == null
|
||||
|| attackerInfo.ignoreBattle
|
||||
|| TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType(attackerInfo.category)
|
||||
|| (targetedInfo != null
|
||||
&& (targetedInfo.ignoreBattle
|
||||
|| TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType(targetedInfo.category))))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Entity inBattle = null;
|
||||
Entity notInBattle = null;
|
||||
Battle battle = null;
|
||||
|
||||
for(Battle b : battleMap.values())
|
||||
{
|
||||
if(b.hasCombatant(event.getEntity().getEntityId()))
|
||||
{
|
||||
if(inBattle != null)
|
||||
{
|
||||
// both entities already in battle
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
inBattle = event.getEntity();
|
||||
notInBattle = event.getTarget();
|
||||
battle = b;
|
||||
}
|
||||
}
|
||||
if(b.hasCombatant(event.getTarget().getEntityId()))
|
||||
{
|
||||
if(inBattle != null)
|
||||
{
|
||||
// both entities already in battle
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
inBattle = event.getTarget();
|
||||
notInBattle = event.getEntity();
|
||||
battle = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(battle == null)
|
||||
{
|
||||
// neither in battle
|
||||
if(event.getEntity() instanceof EntityPlayer || event.getTarget() instanceof EntityPlayer)
|
||||
{
|
||||
// at least one is a player, create battle
|
||||
Collection<Entity> sideA = new ArrayList<Entity>(1);
|
||||
Collection<Entity> sideB = new ArrayList<Entity>(1);
|
||||
sideA.add(event.getEntity());
|
||||
sideB.add(event.getTarget());
|
||||
createBattle(sideA, sideB);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// add entity to battle
|
||||
if(battle.getSize() >= TurnBasedMinecraftMod.proxy.getConfig().getMaxInBattle())
|
||||
{
|
||||
// battle max reached, cannot add to battle
|
||||
return;
|
||||
}
|
||||
else if(battle.hasCombatantInSideA(inBattle.getEntityId()))
|
||||
{
|
||||
battle.addCombatantToSideB(notInBattle);
|
||||
}
|
||||
else
|
||||
{
|
||||
battle.addCombatantToSideA(notInBattle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Battle createBattle(Collection<Entity> sideA, Collection<Entity> sideB)
|
||||
{
|
||||
while(battleMap.containsKey(IDCounter))
|
||||
|
|
|
@ -48,6 +48,7 @@ public class Config
|
|||
private Set<Integer> battleIgnoringPlayers = null;
|
||||
private boolean onlyOPsSelfDisableTB = true;
|
||||
private boolean battleDisabledForAll = false;
|
||||
private boolean oldBattleBehaviorEnabled = false;
|
||||
|
||||
public Config(Logger logger)
|
||||
{
|
||||
|
@ -174,6 +175,17 @@ public class Config
|
|||
{
|
||||
continue;
|
||||
}
|
||||
else if(xmlReader.getLocalName().equals("OldBattleBehavior"))
|
||||
{
|
||||
if(xmlReader.getElementText().toLowerCase().equals("false"))
|
||||
{
|
||||
oldBattleBehaviorEnabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
oldBattleBehaviorEnabled = true;
|
||||
}
|
||||
}
|
||||
else if(xmlReader.getLocalName().equals("WhoCanDisableTurnBasedForSelf"))
|
||||
{
|
||||
if(xmlReader.getElementText().toLowerCase().equals("any"))
|
||||
|
@ -617,4 +629,9 @@ public class Config
|
|||
{
|
||||
return battleDisabledForAll;
|
||||
}
|
||||
|
||||
public boolean isOldBattleBehaviorEnabled()
|
||||
{
|
||||
return oldBattleBehaviorEnabled;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class TurnBasedMinecraftMod
|
|||
{
|
||||
public static final String MODID = "com.seodisparate.turnbasedminecraft";
|
||||
public static final String NAME = "Turn Based Minecraft Mod";
|
||||
public static final String VERSION = "1.2";
|
||||
public static final String VERSION = "1.3";
|
||||
public static final String CONFIG_FILENAME = "TBM_Config.xml";
|
||||
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
|
||||
public static final String CONFIG_FILE_PATH = CONFIG_DIRECTORY + CONFIG_FILENAME;
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
<TurnBasedMinecraftConfig>
|
||||
<!-- If the mod has a newer version config, it will rename the existing config and place the new config -->
|
||||
<Version>4</Version>
|
||||
<Version>5</Version>
|
||||
<!-- If not "false", uses old battle behavior where battles only start on attack/hit. Otherwise, battles can
|
||||
start when a hostile mob targets a player or another entity in battle. -->
|
||||
<OldBattleBehavior>false</OldBattleBehavior>
|
||||
<!-- Determines who can disable turn-based-battle for themselves via command. Must be "op" or "any". If neither, defaults to "op"-->
|
||||
<WhoCanDisableTurnBasedForSelf>op</WhoCanDisableTurnBasedForSelf>
|
||||
<!-- If there are "MaxInBattle" amount of entities in battle, other entities cannot join until combatants leave battle. -->
|
||||
|
|
Loading…
Reference in a new issue