import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MobEntity;
+import net.minecraft.entity.monster.CreeperEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.*;
import net.minecraft.util.DamageSource;
import net.minecraft.util.RegistryKey;
-import net.minecraft.world.DimensionType;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.PacketDistributor;
DEFEND(2),
FLEE(3),
USE_ITEM(4),
- SWITCH_ITEM(5);
+ SWITCH_ITEM(5),
+ CREEPER_WAIT(6),
+ CREEPER_EXPLODE(7);
private int value;
private static Map<Integer, Decision> map = new HashMap<Integer, Decision>();
{
enforceFreezePositions();
}
+ defuseCreepers();
switch(state)
{
case DECISION:
// picking decision for sideA non-players
if(!(c.entity instanceof PlayerEntity) && c.decision == Decision.UNDECIDED && c.entityInfo != null)
{
+ if(c.entity instanceof CreeperEntity) {
+ if(c.creeperTurns++ < 2) {
+ c.decision = Decision.CREEPER_WAIT;
+ } else {
+ c.decision = Decision.CREEPER_EXPLODE;
+ }
+ continue;
+ }
int percentage = random.nextInt(100);
if(percentage < c.entityInfo.decisionAttack)
{
{
if(!(c.entity instanceof PlayerEntity) && c.decision == Decision.UNDECIDED && c.entityInfo != null)
{
+ if(c.entity instanceof CreeperEntity) {
+ if(c.creeperTurns++ < 2) {
+ c.decision = Decision.CREEPER_WAIT;
+ } else {
+ c.decision = Decision.CREEPER_EXPLODE;
+ }
+ continue;
+ }
int percentage = random.nextInt(100);
if(percentage < c.entityInfo.decisionAttack)
{
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getEntityId(), 0, PacketBattleMessage.UsedItemAction.USED_INVALID.getValue(), targetItemStack.getDisplayName().getString());
}
break;
- case SWITCH_ITEM:
+ case SWITCH_ITEM: {
debugLog += " switch item";
- if(next.itemToUse < 0 || next.itemToUse > 8)
- {
+ if (next.itemToUse < 0 || next.itemToUse > 8) {
sendMessageToAllPlayers(PacketBattleMessage.MessageType.SWITCHED_ITEM, next.entity.getEntityId(), 0, 0);
break;
}
final Entity nextEntity = next.entity;
final int nextItemToUse = next.itemToUse;
- ((PlayerEntity)nextEntity).inventory.currentItem = nextItemToUse;
+ ((PlayerEntity) nextEntity).inventory.currentItem = nextItemToUse;
sendMessageToAllPlayers(PacketBattleMessage.MessageType.SWITCHED_ITEM, next.entity.getEntityId(), 0, 1);
+ }
+ break;
+ case CREEPER_WAIT:
+ debugLog += " creeper wait";
+ if(next.creeperTurns < 2) {
+ sendMessageToAllPlayers(PacketBattleMessage.MessageType.CREEPER_WAIT, next.entity.getEntityId(), 0, 0);
+ } else {
+ sendMessageToAllPlayers(PacketBattleMessage.MessageType.CREEPER_WAIT_FINAL, next.entity.getEntityId(), 0, 0);
+ }
+ break;
+ case CREEPER_EXPLODE: {
+ debugLog += " creeper explode";
+ sendMessageToAllPlayers(PacketBattleMessage.MessageType.CREEPER_EXPLODE, next.entity.getEntityId(), 0, 0);
+ final Entity nextEntity = next.entity;
+ final EntityInfo nextEntityInfo = next.entityInfo;
+ for (Combatant c : sideA.values()) {
+ if (c.entity.getEntityId() != next.entity.getEntityId()) {
+ int hitChance = next.entityInfo.attackProbability;
+ if (c.entity instanceof PlayerEntity) {
+ hitChance = hitChance * (100 - TurnBasedMinecraftMod.proxy.getConfig().getPlayerEvasion()) / 100;
+ } else {
+ hitChance = hitChance * (100 - c.entityInfo.evasion) / 100;
+ }
+ if (hitChance < TurnBasedMinecraftMod.proxy.getConfig().getMinimumHitPercentage()) {
+ hitChance = TurnBasedMinecraftMod.proxy.getConfig().getMinimumHitPercentage();
+ }
+ if (random.nextInt(100) < hitChance) {
+ final Entity targetEntity = c.entity;
+ final EntityInfo targetEntityInfo = c.entityInfo;
+ int damageAmount = nextEntityInfo.attackPower;
+ if (nextEntityInfo.attackVariance > 0) {
+ damageAmount += random.nextInt(nextEntityInfo.attackVariance * 2 + 1) - nextEntityInfo.attackVariance;
+ }
+ if (damageAmount < 0) {
+ damageAmount = 0;
+ }
+ final int finalDamageAmount = damageAmount;
+ final boolean attackEffectTriggered;
+ if (nextEntityInfo.attackEffect != EntityInfo.Effect.UNKNOWN && nextEntityInfo.attackEffectProbability > 0) {
+ if (random.nextInt(100) < nextEntityInfo.attackEffectProbability) {
+ attackEffectTriggered = true;
+ } else {
+ attackEffectTriggered = false;
+ }
+ } else {
+ attackEffectTriggered = false;
+ }
+
+ TurnBasedMinecraftMod.proxy.setAttackingEntity(nextEntity);
+ targetEntity.attackEntityFrom(DamageSource.causeMobDamage((LivingEntity) nextEntity), finalDamageAmount);
+ TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
+ sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getEntityId(), targetEntity.getEntityId(), finalDamageAmount);
+ if(attackEffectTriggered) {
+ nextEntityInfo.attackEffect.applyEffectToEntity((LivingEntity)targetEntity);
+ sendMessageToAllPlayers(PacketBattleMessage.MessageType.WAS_AFFECTED, nextEntity.getEntityId(), targetEntity.getEntityId(), 0, nextEntityInfo.attackEffect.getAffectedString());
+ }
+ }
+ }
+ }
+ for(Combatant c : sideB.values()) {
+ if (c.entity.getEntityId() != next.entity.getEntityId()) {
+ int hitChance = next.entityInfo.attackProbability;
+ if (c.entity instanceof PlayerEntity) {
+ hitChance = hitChance * (100 - TurnBasedMinecraftMod.proxy.getConfig().getPlayerEvasion()) / 100;
+ } else {
+ hitChance = hitChance * (100 - c.entityInfo.evasion) / 100;
+ }
+ if (hitChance < TurnBasedMinecraftMod.proxy.getConfig().getMinimumHitPercentage()) {
+ hitChance = TurnBasedMinecraftMod.proxy.getConfig().getMinimumHitPercentage();
+ }
+ if (random.nextInt(100) < hitChance) {
+ final Entity targetEntity = c.entity;
+ final EntityInfo targetEntityInfo = c.entityInfo;
+ int damageAmount = nextEntityInfo.attackPower;
+ if (nextEntityInfo.attackVariance > 0) {
+ damageAmount += random.nextInt(nextEntityInfo.attackVariance * 2 + 1) - nextEntityInfo.attackVariance;
+ }
+ if (damageAmount < 0) {
+ damageAmount = 0;
+ }
+ final int finalDamageAmount = damageAmount;
+ final boolean attackEffectTriggered;
+ if (nextEntityInfo.attackEffect != EntityInfo.Effect.UNKNOWN && nextEntityInfo.attackEffectProbability > 0) {
+ if (random.nextInt(100) < nextEntityInfo.attackEffectProbability) {
+ attackEffectTriggered = true;
+ } else {
+ attackEffectTriggered = false;
+ }
+ } else {
+ attackEffectTriggered = false;
+ }
+
+ TurnBasedMinecraftMod.proxy.setAttackingEntity(nextEntity);
+ targetEntity.attackEntityFrom(DamageSource.causeMobDamage((LivingEntity) nextEntity), finalDamageAmount);
+ TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
+ sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getEntityId(), targetEntity.getEntityId(), finalDamageAmount);
+ if(attackEffectTriggered) {
+ nextEntityInfo.attackEffect.applyEffectToEntity((LivingEntity)targetEntity);
+ sendMessageToAllPlayers(PacketBattleMessage.MessageType.WAS_AFFECTED, nextEntity.getEntityId(), targetEntity.getEntityId(), 0, nextEntityInfo.attackEffect.getAffectedString());
+ }
+ }
+ }
+ }
+ ((CreeperEntity)nextEntity).setCreeperState(1000000);
+ }
break;
}
}
debugLog = "Update end";
return battleEnded;
} // update(final long dt)
+
+ private void defuseCreepers() {
+ for(Combatant c : sideA.values()) {
+ if(c.entity instanceof CreeperEntity) {
+ if(c.creeperTurns <= 2) {
+ ((CreeperEntity)c.entity).setCreeperState(-10);
+ } else {
+ ((CreeperEntity)c.entity).setCreeperState(1000000);
+ }
+ }
+ }
+ for(Combatant c : sideB.values()) {
+ if(c.entity instanceof CreeperEntity) {
+ if(c.creeperTurns <= 2) {
+ ((CreeperEntity)c.entity).setCreeperState(-10);
+ } else {
+ ((CreeperEntity) c.entity).setCreeperState(1000000);
+ }
+ }
+ }
+ }
}
import net.minecraft.entity.Entity;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.RegistryKey;
-import net.minecraft.util.ResourceLocation;
-import net.minecraft.world.DimensionType;
+import net.minecraft.util.text.Color;
+import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkEvent;
BECAME_CREATIVE(15),
FIRED_ARROW(16),
ARROW_HIT(17),
- BOW_NO_AMMO(18);
+ BOW_NO_AMMO(18),
+ CREEPER_WAIT(19),
+ CREEPER_WAIT_FINAL(20),
+ CREEPER_EXPLODE(21);
private int value;
private static Map<Integer, MessageType> map = new HashMap<Integer, MessageType>();
case BOW_NO_AMMO:
TurnBasedMinecraftMod.proxy.displayString(from + " tried to use their bow but ran out of ammo!");
break;
+ case CREEPER_WAIT: {
+ StringTextComponent prefix = new StringTextComponent("TBM: ");
+ prefix.func_230530_a_(prefix.getStyle().func_240718_a_(Color.func_240743_a_(0xFF00FF00)).func_240713_a_(true));
+ StringTextComponent message = new StringTextComponent(from + " is charging up!");
+ message.func_230530_a_(message.getStyle().func_240718_a_(Color.func_240743_a_(0xFFFFFF00)));
+ prefix.getSiblings().add(message);
+ TurnBasedMinecraftMod.proxy.displayTextComponent(prefix);
+ }
+ break;
+ case CREEPER_WAIT_FINAL: {
+ StringTextComponent prefix = new StringTextComponent("TBM: ");
+ prefix.func_230530_a_(prefix.getStyle().func_240718_a_(Color.func_240743_a_(0xFF00FF00)).func_240713_a_(true));
+ StringTextComponent message = new StringTextComponent(from + " is about to explode!");
+ message.func_230530_a_(message.getStyle().func_240718_a_(Color.func_240743_a_(0xFFFF5050)));
+ prefix.getSiblings().add(message);
+ TurnBasedMinecraftMod.proxy.displayTextComponent(prefix);
+ }
+ break;
+ case CREEPER_EXPLODE: {
+ StringTextComponent prefix = new StringTextComponent("TBM: ");
+ prefix.func_230530_a_(prefix.getStyle().func_240718_a_(Color.func_240743_a_(0xFF00FF00)).func_240713_a_(true));
+ StringTextComponent message = new StringTextComponent(from + " exploded!");
+ message.func_230530_a_(message.getStyle().func_240718_a_(Color.func_240743_a_(0xFFFF0000)));
+ prefix.getSiblings().add(message);
+ TurnBasedMinecraftMod.proxy.displayTextComponent(prefix);
+ }
+ break;
}
});
ctx.get().setPacketHandled(true);