2019-11-25 06:29:25 +00:00
|
|
|
package com.burnedkirby.TurnBasedMinecraft.common;
|
2018-08-28 06:13:14 +00:00
|
|
|
|
2019-11-25 06:29:25 +00:00
|
|
|
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleInfo;
|
|
|
|
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleMessage;
|
2022-05-17 05:47:42 +00:00
|
|
|
import net.minecraft.resources.ResourceKey;
|
|
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
|
|
import net.minecraft.world.damagesource.DamageSource;
|
2022-06-08 10:22:45 +00:00
|
|
|
import net.minecraft.world.effect.MobEffects;
|
2022-05-17 05:47:42 +00:00
|
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
|
|
import net.minecraft.world.entity.Mob;
|
|
|
|
import net.minecraft.world.entity.monster.Creeper;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.item.*;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
import net.minecraftforge.network.PacketDistributor;
|
2018-08-29 06:09:44 +00:00
|
|
|
|
2022-05-17 05:47:42 +00:00
|
|
|
import java.util.*;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
2018-08-28 06:13:14 +00:00
|
|
|
|
|
|
|
public class Battle
|
|
|
|
{
|
2018-08-29 06:09:44 +00:00
|
|
|
private final int id;
|
|
|
|
private Map<Integer, Combatant> sideA;
|
|
|
|
private Map<Integer, Combatant> sideB;
|
2018-09-04 06:21:49 +00:00
|
|
|
private Map<Integer, Combatant> players;
|
|
|
|
private PriorityQueue<Combatant> turnOrderQueue;
|
2018-09-27 07:44:28 +00:00
|
|
|
private Queue<Combatant> sideAEntryQueue;
|
|
|
|
private Queue<Combatant> sideBEntryQueue;
|
2018-08-28 06:13:14 +00:00
|
|
|
|
2018-08-29 06:09:44 +00:00
|
|
|
private State state;
|
2018-09-04 06:21:49 +00:00
|
|
|
private AtomicInteger playerCount;
|
|
|
|
private AtomicInteger undecidedCount;
|
2018-09-10 05:59:56 +00:00
|
|
|
private long lastInstant;
|
|
|
|
private long timer;
|
2018-08-29 06:09:44 +00:00
|
|
|
|
2018-09-06 08:08:36 +00:00
|
|
|
private boolean isServer;
|
|
|
|
private boolean battleEnded;
|
|
|
|
|
2018-10-17 09:28:47 +00:00
|
|
|
private BattleManager battleManager;
|
2018-10-27 08:34:02 +00:00
|
|
|
|
|
|
|
private Random random;
|
2018-10-17 09:28:47 +00:00
|
|
|
|
2018-10-19 08:18:02 +00:00
|
|
|
public String debugLog; // TODO remove after freeze bug has been found
|
2019-11-29 04:47:39 +00:00
|
|
|
|
2022-05-17 05:47:42 +00:00
|
|
|
private ResourceKey<Level> dimension;
|
2018-10-19 08:18:02 +00:00
|
|
|
|
2018-08-29 06:09:44 +00:00
|
|
|
public enum State
|
|
|
|
{
|
2018-09-10 05:59:56 +00:00
|
|
|
DECISION(0),
|
|
|
|
ACTION(1),
|
|
|
|
DECISION_PLAYER_READY(2);
|
|
|
|
|
|
|
|
private int value;
|
|
|
|
private static Map<Integer, State> map = new HashMap<Integer, State>();
|
|
|
|
|
2018-10-24 08:20:04 +00:00
|
|
|
State(int value)
|
2018-09-10 05:59:56 +00:00
|
|
|
{
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getValue()
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
{
|
|
|
|
for(State state : State.values())
|
|
|
|
{
|
|
|
|
map.put(state.value, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static State valueOf(int stateType)
|
|
|
|
{
|
|
|
|
return map.get(stateType);
|
|
|
|
}
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum Decision
|
|
|
|
{
|
|
|
|
UNDECIDED(0),
|
|
|
|
ATTACK(1),
|
|
|
|
DEFEND(2),
|
|
|
|
FLEE(3),
|
2018-09-11 06:15:31 +00:00
|
|
|
USE_ITEM(4),
|
2020-11-18 06:52:54 +00:00
|
|
|
SWITCH_ITEM(5),
|
|
|
|
CREEPER_WAIT(6),
|
|
|
|
CREEPER_EXPLODE(7);
|
2018-08-29 06:09:44 +00:00
|
|
|
|
|
|
|
private int value;
|
|
|
|
private static Map<Integer, Decision> map = new HashMap<Integer, Decision>();
|
|
|
|
|
2018-10-24 08:20:04 +00:00
|
|
|
Decision(int value)
|
2018-08-29 06:09:44 +00:00
|
|
|
{
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getValue()
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
{
|
|
|
|
for(Decision decision : Decision.values())
|
|
|
|
{
|
|
|
|
map.put(decision.value, decision);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Decision valueOf(int decisionType)
|
|
|
|
{
|
|
|
|
return map.get(decisionType);
|
|
|
|
}
|
|
|
|
}
|
2018-08-28 06:13:14 +00:00
|
|
|
|
2022-05-17 05:47:42 +00:00
|
|
|
public Battle(BattleManager battleManager, int id, Collection<Entity> sideA, Collection<Entity> sideB, boolean isServer, ResourceKey<Level> dimension)
|
2018-08-28 06:13:14 +00:00
|
|
|
{
|
2018-10-17 09:28:47 +00:00
|
|
|
this.battleManager = battleManager;
|
2018-09-06 08:08:36 +00:00
|
|
|
this.isServer = isServer;
|
2018-08-28 06:13:14 +00:00
|
|
|
this.id = id;
|
2018-10-26 09:10:09 +00:00
|
|
|
this.sideA = new ConcurrentHashMap<Integer, Combatant>();
|
|
|
|
this.sideB = new ConcurrentHashMap<Integer, Combatant>();
|
|
|
|
players = new ConcurrentHashMap<Integer, Combatant>();
|
2018-09-04 06:21:49 +00:00
|
|
|
turnOrderQueue = new PriorityQueue<Combatant>(new Combatant.CombatantComparator());
|
2018-09-27 07:44:28 +00:00
|
|
|
sideAEntryQueue = new ArrayDeque<Combatant>();
|
|
|
|
sideBEntryQueue = new ArrayDeque<Combatant>();
|
2018-09-04 06:21:49 +00:00
|
|
|
playerCount = new AtomicInteger(0);
|
|
|
|
undecidedCount = new AtomicInteger(0);
|
2018-10-27 08:34:02 +00:00
|
|
|
random = new Random();
|
2019-11-29 04:47:39 +00:00
|
|
|
this.dimension = dimension;
|
2018-08-29 06:09:44 +00:00
|
|
|
if(sideA != null)
|
2018-08-28 06:13:14 +00:00
|
|
|
{
|
2018-08-29 06:09:44 +00:00
|
|
|
for(Entity e : sideA)
|
|
|
|
{
|
2019-11-28 07:32:34 +00:00
|
|
|
EntityInfo entityInfo;
|
|
|
|
try {
|
2021-05-21 05:44:31 +00:00
|
|
|
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomName().getString());
|
2019-11-28 07:32:34 +00:00
|
|
|
} catch(NullPointerException exception) {
|
|
|
|
entityInfo = null;
|
|
|
|
}
|
2018-10-26 04:35:20 +00:00
|
|
|
if(entityInfo == null)
|
|
|
|
{
|
|
|
|
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
|
|
|
|
}
|
|
|
|
|
2022-05-17 05:47:42 +00:00
|
|
|
if(entityInfo == null && !(e instanceof Player) && TurnBasedMinecraftMod.proxy.isServerRunning())
|
2018-09-04 06:21:49 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Combatant newCombatant = new Combatant(e, entityInfo);
|
2018-09-05 06:54:06 +00:00
|
|
|
newCombatant.isSideA = true;
|
2018-09-17 06:49:10 +00:00
|
|
|
newCombatant.battleID = getId();
|
2021-05-21 05:44:31 +00:00
|
|
|
this.sideA.put(e.getId(), newCombatant);
|
2022-05-17 05:47:42 +00:00
|
|
|
if(e instanceof Player)
|
2018-08-29 06:09:44 +00:00
|
|
|
{
|
2018-09-04 06:21:49 +00:00
|
|
|
newCombatant.recalcSpeedOnCompare = true;
|
|
|
|
playerCount.incrementAndGet();
|
2021-05-21 05:44:31 +00:00
|
|
|
players.put(e.getId(), newCombatant);
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
2018-09-28 08:45:32 +00:00
|
|
|
if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
|
2018-09-18 06:56:06 +00:00
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
newCombatant.x = e.getX();
|
|
|
|
newCombatant.z = e.getZ();
|
2022-05-17 05:47:42 +00:00
|
|
|
newCombatant.yaw = e.getXRot();
|
|
|
|
newCombatant.pitch = e.getYRot();
|
2018-09-18 06:56:06 +00:00
|
|
|
}
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|
2018-08-29 06:09:44 +00:00
|
|
|
if(sideB != null)
|
2018-08-28 06:13:14 +00:00
|
|
|
{
|
2018-08-29 06:09:44 +00:00
|
|
|
for(Entity e : sideB)
|
|
|
|
{
|
2019-11-28 07:32:34 +00:00
|
|
|
EntityInfo entityInfo;
|
|
|
|
try {
|
2021-05-21 05:44:31 +00:00
|
|
|
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomName().getString());
|
2019-11-28 07:32:34 +00:00
|
|
|
} catch(NullPointerException exception) {
|
|
|
|
entityInfo = null;
|
|
|
|
}
|
2018-10-26 04:35:20 +00:00
|
|
|
if(entityInfo == null)
|
|
|
|
{
|
|
|
|
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
|
|
|
|
}
|
|
|
|
|
2022-05-17 05:47:42 +00:00
|
|
|
if(entityInfo == null && !(e instanceof Player) && TurnBasedMinecraftMod.proxy.isServerRunning())
|
2018-09-04 06:21:49 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Combatant newCombatant = new Combatant(e, entityInfo);
|
2018-09-05 06:54:06 +00:00
|
|
|
newCombatant.isSideA = false;
|
2018-09-17 06:49:10 +00:00
|
|
|
newCombatant.battleID = getId();
|
2021-05-21 05:44:31 +00:00
|
|
|
this.sideB.put(e.getId(), newCombatant);
|
2022-05-17 05:47:42 +00:00
|
|
|
if(e instanceof Player)
|
2018-08-29 06:09:44 +00:00
|
|
|
{
|
2018-09-04 06:21:49 +00:00
|
|
|
newCombatant.recalcSpeedOnCompare = true;
|
|
|
|
playerCount.incrementAndGet();
|
2021-05-21 05:44:31 +00:00
|
|
|
players.put(e.getId(), newCombatant);
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
2018-09-28 08:45:32 +00:00
|
|
|
if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
|
2018-09-18 06:56:06 +00:00
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
newCombatant.x = e.getX();
|
|
|
|
newCombatant.z = e.getZ();
|
2022-05-17 05:47:42 +00:00
|
|
|
newCombatant.yaw = e.getXRot();
|
|
|
|
newCombatant.pitch = e.getYRot();
|
2018-09-18 06:56:06 +00:00
|
|
|
}
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|
|
|
|
|
2018-10-18 04:43:26 +00:00
|
|
|
if(isServer)
|
2018-09-06 08:08:36 +00:00
|
|
|
{
|
2018-10-18 04:43:26 +00:00
|
|
|
for(Combatant c : this.sideA.values())
|
2018-09-14 05:14:10 +00:00
|
|
|
{
|
2018-10-18 04:43:26 +00:00
|
|
|
if(c.entityInfo != null)
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, c.entity.getId(), 0, id, c.entityInfo.category);
|
2018-10-18 04:43:26 +00:00
|
|
|
}
|
2022-05-17 05:47:42 +00:00
|
|
|
else if(c.entity instanceof Player)
|
2018-10-18 04:43:26 +00:00
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, c.entity.getId(), 0, id, "player");
|
2018-10-18 04:43:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, c.entity.getId(), 0, id);
|
2018-10-18 04:43:26 +00:00
|
|
|
}
|
2018-09-27 09:09:40 +00:00
|
|
|
}
|
2018-10-18 04:43:26 +00:00
|
|
|
for(Combatant c : this.sideB.values())
|
2018-09-14 05:14:10 +00:00
|
|
|
{
|
2018-10-18 04:43:26 +00:00
|
|
|
if(c.entityInfo != null)
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, c.entity.getId(), 0, id, c.entityInfo.category);
|
2018-10-18 04:43:26 +00:00
|
|
|
}
|
2022-05-17 05:47:42 +00:00
|
|
|
else if(c.entity instanceof Player)
|
2018-10-18 04:43:26 +00:00
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, c.entity.getId(), 0, id, "player");
|
2018-10-18 04:43:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, c.entity.getId(), 0, id);
|
2018-10-18 04:43:26 +00:00
|
|
|
}
|
2018-09-14 05:14:10 +00:00
|
|
|
}
|
2018-09-06 08:08:36 +00:00
|
|
|
}
|
|
|
|
|
2018-09-10 05:59:56 +00:00
|
|
|
lastInstant = System.nanoTime();
|
2018-08-29 06:09:44 +00:00
|
|
|
state = State.DECISION;
|
2018-09-04 06:21:49 +00:00
|
|
|
undecidedCount.set(playerCount.get());
|
2018-09-28 08:45:32 +00:00
|
|
|
timer = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
|
2018-09-06 08:08:36 +00:00
|
|
|
battleEnded = false;
|
|
|
|
|
|
|
|
notifyPlayersBattleInfo();
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getId()
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2018-09-06 08:08:36 +00:00
|
|
|
public Entity getCombatantEntity(int entityID)
|
|
|
|
{
|
|
|
|
Combatant c = sideA.get(entityID);
|
|
|
|
if(c != null)
|
|
|
|
{
|
|
|
|
return c.entity;
|
|
|
|
}
|
|
|
|
c = sideB.get(entityID);
|
|
|
|
if(c != null)
|
|
|
|
{
|
|
|
|
return c.entity;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-08-28 06:13:14 +00:00
|
|
|
public boolean hasCombatant(int entityID)
|
|
|
|
{
|
2019-11-29 04:59:41 +00:00
|
|
|
for(Combatant c : sideAEntryQueue)
|
2018-10-18 05:47:40 +00:00
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
if(c.entity.getId() == entityID)
|
2018-10-18 05:47:40 +00:00
|
|
|
{
|
2019-11-29 04:59:41 +00:00
|
|
|
return true;
|
2018-10-18 05:47:40 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-29 04:59:41 +00:00
|
|
|
for(Combatant c : sideBEntryQueue)
|
2018-10-18 05:47:40 +00:00
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
if(c.entity.getId() == entityID)
|
2018-10-18 05:47:40 +00:00
|
|
|
{
|
2019-11-29 04:59:41 +00:00
|
|
|
return true;
|
2018-10-18 05:47:40 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-28 06:13:14 +00:00
|
|
|
return sideA.containsKey(entityID) || sideB.containsKey(entityID);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasCombatantInSideA(int entityID)
|
|
|
|
{
|
2019-11-29 04:59:41 +00:00
|
|
|
for(Combatant c : sideAEntryQueue)
|
2018-10-18 05:47:40 +00:00
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
if(c.entity.getId() == entityID)
|
2018-10-18 05:47:40 +00:00
|
|
|
{
|
2019-11-29 04:59:41 +00:00
|
|
|
return true;
|
2018-10-18 05:47:40 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-28 06:13:14 +00:00
|
|
|
return sideA.containsKey(entityID);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addCombatantToSideA(Entity e)
|
|
|
|
{
|
2019-11-28 07:32:34 +00:00
|
|
|
EntityInfo entityInfo;
|
|
|
|
try {
|
2021-05-21 05:44:31 +00:00
|
|
|
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomName().getString());
|
2019-11-28 07:32:34 +00:00
|
|
|
} catch(NullPointerException exception) {
|
|
|
|
entityInfo = null;
|
|
|
|
}
|
2018-10-26 04:35:20 +00:00
|
|
|
if(entityInfo == null)
|
|
|
|
{
|
|
|
|
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
|
|
|
|
}
|
|
|
|
|
2022-05-17 05:47:42 +00:00
|
|
|
if(entityInfo == null && !(e instanceof Player) && TurnBasedMinecraftMod.proxy.isServerRunning())
|
2018-09-04 06:21:49 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Combatant newCombatant = new Combatant(e, entityInfo);
|
2018-09-05 06:54:06 +00:00
|
|
|
newCombatant.isSideA = true;
|
2018-09-17 06:49:10 +00:00
|
|
|
newCombatant.battleID = getId();
|
2018-09-27 07:44:28 +00:00
|
|
|
if(isServer)
|
|
|
|
{
|
2019-11-29 04:59:41 +00:00
|
|
|
sideAEntryQueue.add(newCombatant);
|
2018-09-27 07:44:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sideA.put(e.getId(), newCombatant);
|
2018-09-27 07:44:28 +00:00
|
|
|
}
|
2022-05-17 05:47:42 +00:00
|
|
|
if(e instanceof Player)
|
2018-08-29 06:09:44 +00:00
|
|
|
{
|
2018-09-04 06:21:49 +00:00
|
|
|
newCombatant.recalcSpeedOnCompare = true;
|
|
|
|
playerCount.incrementAndGet();
|
2021-05-21 05:44:31 +00:00
|
|
|
players.put(e.getId(), newCombatant);
|
2018-08-29 06:09:44 +00:00
|
|
|
if(state == State.DECISION)
|
|
|
|
{
|
2018-09-04 06:21:49 +00:00
|
|
|
undecidedCount.incrementAndGet();
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-28 08:45:32 +00:00
|
|
|
if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
|
2018-09-18 06:56:06 +00:00
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
newCombatant.x = e.getX();
|
|
|
|
newCombatant.z = e.getZ();
|
2022-05-17 05:47:42 +00:00
|
|
|
newCombatant.yaw = e.getXRot();
|
|
|
|
newCombatant.pitch = e.getYRot();
|
2018-09-18 06:56:06 +00:00
|
|
|
}
|
2018-10-18 04:43:26 +00:00
|
|
|
if(isServer)
|
2018-09-14 05:14:10 +00:00
|
|
|
{
|
2018-10-18 04:43:26 +00:00
|
|
|
if(newCombatant.entityInfo != null)
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, newCombatant.entity.getId(), 0, id, newCombatant.entityInfo.category);
|
2018-10-18 04:43:26 +00:00
|
|
|
}
|
2022-05-17 05:47:42 +00:00
|
|
|
else if(newCombatant.entity instanceof Player)
|
2018-10-18 04:43:26 +00:00
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, newCombatant.entity.getId(), 0, id, "player");
|
2018-10-18 04:43:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, newCombatant.entity.getId(), 0, id);
|
2018-10-18 04:43:26 +00:00
|
|
|
}
|
2018-09-14 05:14:10 +00:00
|
|
|
}
|
2018-09-06 08:08:36 +00:00
|
|
|
notifyPlayersBattleInfo();
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addCombatantToSideB(Entity e)
|
|
|
|
{
|
2019-11-28 07:32:34 +00:00
|
|
|
EntityInfo entityInfo;
|
|
|
|
try {
|
2021-05-21 05:44:31 +00:00
|
|
|
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomName().getString());
|
2019-11-28 07:32:34 +00:00
|
|
|
} catch(NullPointerException exception) {
|
|
|
|
entityInfo = null;
|
|
|
|
}
|
2018-10-26 04:35:20 +00:00
|
|
|
if(entityInfo == null)
|
|
|
|
{
|
|
|
|
entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e);
|
|
|
|
}
|
|
|
|
|
2022-05-17 05:47:42 +00:00
|
|
|
if(entityInfo == null && !(e instanceof Player) && TurnBasedMinecraftMod.proxy.isServerRunning())
|
2018-09-04 06:21:49 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Combatant newCombatant = new Combatant(e, entityInfo);
|
2018-09-05 06:54:06 +00:00
|
|
|
newCombatant.isSideA = false;
|
2018-09-17 06:49:10 +00:00
|
|
|
newCombatant.battleID = getId();
|
2018-09-27 07:44:28 +00:00
|
|
|
if(isServer)
|
|
|
|
{
|
2019-11-29 04:59:41 +00:00
|
|
|
sideBEntryQueue.add(newCombatant);
|
2018-09-27 07:44:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sideB.put(e.getId(), newCombatant);
|
2018-09-27 07:44:28 +00:00
|
|
|
}
|
2022-05-17 05:47:42 +00:00
|
|
|
if(e instanceof Player)
|
2018-08-29 06:09:44 +00:00
|
|
|
{
|
2018-09-04 06:21:49 +00:00
|
|
|
newCombatant.recalcSpeedOnCompare = true;
|
|
|
|
playerCount.incrementAndGet();
|
2021-05-21 05:44:31 +00:00
|
|
|
players.put(e.getId(), newCombatant);
|
2018-08-29 06:09:44 +00:00
|
|
|
if(state == State.DECISION)
|
|
|
|
{
|
2018-09-04 06:21:49 +00:00
|
|
|
undecidedCount.incrementAndGet();
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-28 08:45:32 +00:00
|
|
|
if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
|
2018-09-18 06:56:06 +00:00
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
newCombatant.x = e.getX();
|
|
|
|
newCombatant.z = e.getZ();
|
2022-05-17 05:47:42 +00:00
|
|
|
newCombatant.yaw = e.getXRot();
|
|
|
|
newCombatant.pitch = e.getYRot();
|
2018-09-18 06:56:06 +00:00
|
|
|
}
|
2018-10-18 04:43:26 +00:00
|
|
|
if(isServer)
|
2018-09-14 05:14:10 +00:00
|
|
|
{
|
2018-10-18 04:43:26 +00:00
|
|
|
if(newCombatant.entityInfo != null)
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, newCombatant.entity.getId(), 0, id, newCombatant.entityInfo.category);
|
2018-10-18 04:43:26 +00:00
|
|
|
}
|
2022-05-17 05:47:42 +00:00
|
|
|
else if(newCombatant.entity instanceof Player)
|
2018-10-18 04:43:26 +00:00
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, newCombatant.entity.getId(), 0, id, "player");
|
2018-10-18 04:43:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ENTERED, newCombatant.entity.getId(), 0, id);
|
2018-10-18 04:43:26 +00:00
|
|
|
}
|
2018-09-14 05:14:10 +00:00
|
|
|
}
|
2018-09-06 08:08:36 +00:00
|
|
|
notifyPlayersBattleInfo();
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void clearCombatants()
|
|
|
|
{
|
|
|
|
sideA.clear();
|
|
|
|
sideB.clear();
|
2018-09-27 09:09:40 +00:00
|
|
|
sideAEntryQueue.clear();
|
|
|
|
sideBEntryQueue.clear();
|
2018-08-30 07:15:20 +00:00
|
|
|
players.clear();
|
2018-09-04 06:21:49 +00:00
|
|
|
playerCount.set(0);
|
|
|
|
undecidedCount.set(0);
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Collection<Combatant> getSideA()
|
|
|
|
{
|
|
|
|
return sideA.values();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Collection<Combatant> getSideB()
|
|
|
|
{
|
|
|
|
return sideB.values();
|
|
|
|
}
|
|
|
|
|
2018-09-11 06:15:31 +00:00
|
|
|
public Set<Map.Entry<Integer, Combatant>> getSideAEntrySet()
|
|
|
|
{
|
|
|
|
return sideA.entrySet();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Set<Map.Entry<Integer, Combatant>> getSideBEntrySet()
|
|
|
|
{
|
|
|
|
return sideB.entrySet();
|
|
|
|
}
|
|
|
|
|
2018-08-29 06:09:44 +00:00
|
|
|
public Collection<Integer> getSideAIDs()
|
|
|
|
{
|
|
|
|
Collection<Integer> sideAIDs = new ArrayList<Integer>(sideA.size());
|
|
|
|
for(Combatant combatant : sideA.values())
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sideAIDs.add(combatant.entity.getId());
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
|
|
|
return sideAIDs;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Collection<Integer> getSideBIDs()
|
|
|
|
{
|
|
|
|
Collection<Integer> sideBIDs = new ArrayList<Integer>(sideB.size());
|
|
|
|
for(Combatant combatant : sideB.values())
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sideBIDs.add(combatant.entity.getId());
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
|
|
|
return sideBIDs;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Combatant getCombatantByID(int entityID)
|
|
|
|
{
|
|
|
|
Combatant combatant = sideA.get(entityID);
|
|
|
|
if(combatant == null)
|
|
|
|
{
|
|
|
|
combatant = sideB.get(entityID);
|
|
|
|
}
|
|
|
|
return combatant;
|
|
|
|
}
|
|
|
|
|
2018-09-05 06:54:06 +00:00
|
|
|
public void setDecision(int entityID, Decision decision, int targetIDOrItemID)
|
2018-08-29 06:09:44 +00:00
|
|
|
{
|
|
|
|
if(state != State.DECISION)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-09-04 06:21:49 +00:00
|
|
|
Combatant combatant = players.get(entityID);
|
2018-09-05 06:54:06 +00:00
|
|
|
if(combatant == null || combatant.decision != Decision.UNDECIDED)
|
2018-08-29 06:09:44 +00:00
|
|
|
{
|
2018-09-04 06:21:49 +00:00
|
|
|
return;
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
2018-09-04 06:21:49 +00:00
|
|
|
combatant.decision = decision;
|
2018-09-05 06:54:06 +00:00
|
|
|
if(decision == Decision.ATTACK)
|
|
|
|
{
|
|
|
|
combatant.targetEntityID = targetIDOrItemID;
|
|
|
|
}
|
2018-09-11 06:15:31 +00:00
|
|
|
else if(decision == Decision.USE_ITEM || decision == Decision.SWITCH_ITEM)
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
|
|
|
combatant.itemToUse = targetIDOrItemID;
|
|
|
|
}
|
2018-09-04 06:21:49 +00:00
|
|
|
undecidedCount.decrementAndGet();
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public State getState()
|
|
|
|
{
|
|
|
|
return state;
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|
|
|
|
|
2018-09-10 05:59:56 +00:00
|
|
|
public void setState(State state)
|
|
|
|
{
|
|
|
|
this.state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getTimerSeconds()
|
|
|
|
{
|
|
|
|
return timer / 1000000000;
|
|
|
|
}
|
|
|
|
|
2018-09-14 03:44:45 +00:00
|
|
|
public int getSize()
|
|
|
|
{
|
2018-10-27 04:58:19 +00:00
|
|
|
int size = sideA.size() + sideB.size();
|
2019-11-29 04:59:41 +00:00
|
|
|
size += sideAEntryQueue.size();
|
|
|
|
size += sideBEntryQueue.size();
|
2018-10-27 04:58:19 +00:00
|
|
|
return size;
|
2018-09-14 03:44:45 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 08:08:36 +00:00
|
|
|
protected void notifyPlayersBattleInfo()
|
2018-08-30 07:15:20 +00:00
|
|
|
{
|
2018-09-06 08:08:36 +00:00
|
|
|
if(!isServer)
|
2018-08-30 07:15:20 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-09-10 05:59:56 +00:00
|
|
|
PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer);
|
2018-09-04 06:21:49 +00:00
|
|
|
for(Combatant p : players.values())
|
2018-08-30 07:15:20 +00:00
|
|
|
{
|
2022-05-17 05:47:42 +00:00
|
|
|
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer)p.entity), infoPacket);
|
2018-08-30 07:15:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-17 06:49:10 +00:00
|
|
|
protected void sendMessageToAllPlayers(PacketBattleMessage.MessageType type, int from, int to, int amount)
|
2018-08-28 06:13:14 +00:00
|
|
|
{
|
2018-10-27 04:58:19 +00:00
|
|
|
sendMessageToAllPlayers(type, from, to, amount, new String());
|
2018-09-06 08:08:36 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 06:49:10 +00:00
|
|
|
protected void sendMessageToAllPlayers(PacketBattleMessage.MessageType type, int from, int to, int amount, String custom)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
|
|
|
if(!isServer)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-11-29 04:47:39 +00:00
|
|
|
PacketBattleMessage packet = new PacketBattleMessage(type, from, to, dimension, amount, custom);
|
2018-09-07 07:41:22 +00:00
|
|
|
for(Combatant p : players.values())
|
|
|
|
{
|
2019-10-28 02:49:28 +00:00
|
|
|
if(p.entity.isAlive())
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
2022-05-17 05:47:42 +00:00
|
|
|
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) p.entity), packet);
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if at least one combatant was removed
|
|
|
|
*/
|
|
|
|
private boolean healthCheck()
|
|
|
|
{
|
2018-10-18 04:34:57 +00:00
|
|
|
boolean didRemove = false;
|
|
|
|
for(Iterator<Map.Entry<Integer, Combatant>> iter = sideA.entrySet().iterator(); iter.hasNext();)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
2018-10-18 04:34:57 +00:00
|
|
|
Map.Entry<Integer, Combatant> entry = iter.next();
|
2019-10-28 02:49:28 +00:00
|
|
|
if(!entry.getValue().entity.isAlive())
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
2018-10-18 04:34:57 +00:00
|
|
|
iter.remove();
|
|
|
|
players.remove(entry.getKey());
|
|
|
|
removeCombatantPostRemove(entry.getValue());
|
|
|
|
didRemove = true;
|
2018-10-26 09:10:09 +00:00
|
|
|
String category = null;
|
2018-10-18 04:34:57 +00:00
|
|
|
if(entry.getValue().entityInfo != null)
|
2018-09-27 09:09:40 +00:00
|
|
|
{
|
2018-10-18 04:34:57 +00:00
|
|
|
category = entry.getValue().entityInfo.category;
|
2018-09-27 09:09:40 +00:00
|
|
|
}
|
2022-05-17 05:47:42 +00:00
|
|
|
else if(entry.getValue().entity instanceof Player)
|
2018-09-27 09:09:40 +00:00
|
|
|
{
|
|
|
|
category = "player";
|
|
|
|
}
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DIED, entry.getValue().entity.getId(), 0, 0, category);
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-18 04:34:57 +00:00
|
|
|
for(Iterator<Map.Entry<Integer, Combatant>> iter = sideB.entrySet().iterator(); iter.hasNext();)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
2018-10-18 04:34:57 +00:00
|
|
|
Map.Entry<Integer, Combatant> entry = iter.next();
|
2019-10-28 02:49:28 +00:00
|
|
|
if(!entry.getValue().entity.isAlive())
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
2018-10-18 04:34:57 +00:00
|
|
|
iter.remove();
|
|
|
|
players.remove(entry.getKey());
|
|
|
|
removeCombatantPostRemove(entry.getValue());
|
|
|
|
didRemove = true;
|
2018-10-26 09:10:09 +00:00
|
|
|
String category = null;
|
2018-10-18 04:34:57 +00:00
|
|
|
if(entry.getValue().entityInfo != null)
|
2018-09-27 09:09:40 +00:00
|
|
|
{
|
2018-10-18 04:34:57 +00:00
|
|
|
category = entry.getValue().entityInfo.category;
|
2018-09-27 09:09:40 +00:00
|
|
|
}
|
2022-05-17 05:47:42 +00:00
|
|
|
else if(entry.getValue().entity instanceof Player)
|
2018-09-27 09:09:40 +00:00
|
|
|
{
|
|
|
|
category = "player";
|
|
|
|
}
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DIED, entry.getValue().entity.getId(), 0, 0, category);
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(players.isEmpty() || sideA.isEmpty() || sideB.isEmpty())
|
|
|
|
{
|
|
|
|
battleEnded = true;
|
|
|
|
}
|
|
|
|
else if(didRemove)
|
|
|
|
{
|
2018-09-19 06:00:38 +00:00
|
|
|
resetUndecidedCount();
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return didRemove;
|
|
|
|
}
|
|
|
|
|
2018-09-27 09:09:40 +00:00
|
|
|
/**
|
|
|
|
* @return true if at least one combatant was removed
|
|
|
|
*/
|
2018-09-19 06:00:38 +00:00
|
|
|
private boolean isCreativeCheck()
|
2018-09-14 03:44:45 +00:00
|
|
|
{
|
2018-10-18 04:34:57 +00:00
|
|
|
boolean didRemove = false;
|
|
|
|
for(Iterator<Map.Entry<Integer, Combatant>> iter = players.entrySet().iterator(); iter.hasNext();)
|
2018-09-14 03:44:45 +00:00
|
|
|
{
|
2018-10-18 04:34:57 +00:00
|
|
|
Map.Entry<Integer, Combatant> entry = iter.next();
|
2022-05-17 05:47:42 +00:00
|
|
|
if(entry.getValue().entity != null && ((Player)entry.getValue().entity).isCreative())
|
2018-09-14 03:44:45 +00:00
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.BECAME_CREATIVE, entry.getValue().entity.getId(), 0, 0);
|
2018-10-18 04:34:57 +00:00
|
|
|
iter.remove();
|
|
|
|
sideA.remove(entry.getKey());
|
|
|
|
sideB.remove(entry.getKey());
|
|
|
|
playerCount.decrementAndGet();
|
|
|
|
removeCombatantPostRemove(entry.getValue());
|
|
|
|
didRemove = true;
|
2018-09-14 03:44:45 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-19 06:00:38 +00:00
|
|
|
if(didRemove)
|
|
|
|
{
|
|
|
|
resetUndecidedCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
return didRemove;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void resetUndecidedCount()
|
|
|
|
{
|
|
|
|
if(state == State.DECISION)
|
|
|
|
{
|
|
|
|
undecidedCount.set(0);
|
|
|
|
for(Combatant p : players.values())
|
|
|
|
{
|
|
|
|
if(p.decision == Decision.UNDECIDED)
|
|
|
|
{
|
|
|
|
undecidedCount.incrementAndGet();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-14 03:44:45 +00:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:56:06 +00:00
|
|
|
private void enforceFreezePositions()
|
|
|
|
{
|
|
|
|
for(Combatant c : sideA.values())
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
c.entity.setPos(c.x, c.entity.getY(), c.z);
|
|
|
|
c.entity.setYBodyRot(c.yaw);
|
|
|
|
c.entity.setYHeadRot(c.pitch);
|
2018-09-18 06:56:06 +00:00
|
|
|
}
|
|
|
|
for(Combatant c : sideB.values())
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
c.entity.setPos(c.x, c.entity.getY(), c.z);
|
|
|
|
c.entity.setYBodyRot(c.yaw);
|
|
|
|
c.entity.setYHeadRot(c.pitch);
|
2018-09-18 06:56:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-17 09:28:47 +00:00
|
|
|
private void removeCombatant(Combatant c)
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sideA.remove(c.entity.getId());
|
|
|
|
sideB.remove(c.entity.getId());
|
|
|
|
if(players.remove(c.entity.getId()) != null)
|
2018-10-17 09:28:47 +00:00
|
|
|
{
|
|
|
|
playerCount.decrementAndGet();
|
2018-10-18 04:34:57 +00:00
|
|
|
}
|
|
|
|
removeCombatantPostRemove(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void removeCombatantPostRemove(Combatant c)
|
|
|
|
{
|
2022-05-17 05:47:42 +00:00
|
|
|
if(c.entity instanceof Player)
|
2018-10-18 04:34:57 +00:00
|
|
|
{
|
2022-05-17 05:47:42 +00:00
|
|
|
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) c.entity), new PacketBattleMessage(PacketBattleMessage.MessageType.ENDED, 0, 0, dimension, 0));
|
2018-10-17 09:28:47 +00:00
|
|
|
}
|
|
|
|
battleManager.addRecentlyLeftBattle(c);
|
|
|
|
}
|
2019-11-29 04:47:39 +00:00
|
|
|
|
|
|
|
public void forceRemoveCombatant(EntityIDDimPair e) {
|
|
|
|
sideA.remove(e.id);
|
|
|
|
sideB.remove(e.id);
|
|
|
|
if(players.remove(e.id) != null) {
|
|
|
|
playerCount.decrementAndGet();
|
|
|
|
}
|
|
|
|
for(Iterator<Combatant> iter = sideAEntryQueue.iterator(); iter.hasNext();) {
|
|
|
|
Combatant c = iter.next();
|
2021-05-21 05:44:31 +00:00
|
|
|
if(c.entity.getId() == e.id) {
|
2019-11-29 04:47:39 +00:00
|
|
|
iter.remove();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(Iterator<Combatant> iter = sideBEntryQueue.iterator(); iter.hasNext();) {
|
|
|
|
Combatant c = iter.next();
|
2021-05-21 05:44:31 +00:00
|
|
|
if(c.entity.getId() == e.id) {
|
2019-11-29 04:47:39 +00:00
|
|
|
iter.remove();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-29 05:46:45 +00:00
|
|
|
|
|
|
|
private void setDecisionState()
|
|
|
|
{
|
|
|
|
for(Combatant c : sideA.values())
|
|
|
|
{
|
|
|
|
c.decision = Decision.UNDECIDED;
|
|
|
|
}
|
|
|
|
for(Combatant c : sideB.values())
|
|
|
|
{
|
|
|
|
c.decision = Decision.UNDECIDED;
|
|
|
|
}
|
|
|
|
state = State.DECISION;
|
|
|
|
undecidedCount.set(players.size());
|
|
|
|
}
|
|
|
|
|
2018-09-10 05:59:56 +00:00
|
|
|
/**
|
|
|
|
* @return True if battle has ended
|
|
|
|
*/
|
|
|
|
public boolean update()
|
|
|
|
{
|
2018-09-27 07:44:28 +00:00
|
|
|
if(!isServer)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(battleEnded)
|
2018-09-10 05:59:56 +00:00
|
|
|
{
|
2018-10-17 09:28:47 +00:00
|
|
|
Collection<Combatant> combatants = new ArrayList<Combatant>();
|
|
|
|
combatants.addAll(sideA.values());
|
|
|
|
combatants.addAll(sideB.values());
|
|
|
|
for(Combatant c : combatants)
|
|
|
|
{
|
|
|
|
removeCombatant(c);
|
|
|
|
}
|
2018-09-10 05:59:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
long nextInstant = System.nanoTime();
|
|
|
|
long dt = nextInstant - lastInstant;
|
|
|
|
lastInstant = nextInstant;
|
2018-10-29 05:46:45 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return update(dt);
|
|
|
|
} catch (Throwable t)
|
|
|
|
{
|
|
|
|
TurnBasedMinecraftMod.logger.error("Update: ", t);
|
|
|
|
setDecisionState();
|
|
|
|
boolean changed = false;
|
|
|
|
if(healthCheck())
|
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
if(isCreativeCheck())
|
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_END, 0, 0, 1);
|
|
|
|
if(changed)
|
|
|
|
{
|
|
|
|
notifyPlayersBattleInfo();
|
|
|
|
}
|
|
|
|
return battleEnded;
|
|
|
|
}
|
2018-09-10 05:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean update(final long dt)
|
2018-09-06 08:08:36 +00:00
|
|
|
{
|
|
|
|
if(battleEnded)
|
|
|
|
{
|
2018-10-17 09:28:47 +00:00
|
|
|
Collection<Combatant> combatants = new ArrayList<Combatant>();
|
|
|
|
combatants.addAll(sideA.values());
|
|
|
|
combatants.addAll(sideB.values());
|
|
|
|
for(Combatant c : combatants)
|
|
|
|
{
|
|
|
|
removeCombatant(c);
|
|
|
|
}
|
2018-09-06 08:08:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-09-27 09:09:40 +00:00
|
|
|
boolean combatantsChanged = false;
|
2019-11-29 04:59:41 +00:00
|
|
|
for(Combatant c = sideAEntryQueue.poll(); c != null; c = sideAEntryQueue.poll())
|
2018-09-27 07:44:28 +00:00
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sideA.put(c.entity.getId(), c);
|
2019-11-29 04:59:41 +00:00
|
|
|
combatantsChanged = true;
|
2018-09-27 07:44:28 +00:00
|
|
|
}
|
2019-11-29 04:59:41 +00:00
|
|
|
for(Combatant c = sideBEntryQueue.poll(); c != null; c = sideBEntryQueue.poll())
|
2018-09-27 07:44:28 +00:00
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sideB.put(c.entity.getId(), c);
|
2019-11-29 04:59:41 +00:00
|
|
|
combatantsChanged = true;
|
2018-09-27 07:44:28 +00:00
|
|
|
}
|
2018-09-28 08:45:32 +00:00
|
|
|
if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
|
2018-09-18 06:56:06 +00:00
|
|
|
{
|
|
|
|
enforceFreezePositions();
|
|
|
|
}
|
2020-11-18 06:52:54 +00:00
|
|
|
defuseCreepers();
|
2018-08-29 06:09:44 +00:00
|
|
|
switch(state)
|
|
|
|
{
|
|
|
|
case DECISION:
|
2018-09-10 05:59:56 +00:00
|
|
|
timer -= dt;
|
|
|
|
if(timer <= 0 || undecidedCount.get() <= 0)
|
2018-08-29 06:09:44 +00:00
|
|
|
{
|
2018-09-06 08:08:36 +00:00
|
|
|
for(Combatant c : sideA.values())
|
|
|
|
{
|
|
|
|
// picking decision for sideA non-players
|
2022-05-17 05:47:42 +00:00
|
|
|
if(!(c.entity instanceof Player) && c.decision == Decision.UNDECIDED && c.entityInfo != null)
|
2018-09-06 08:08:36 +00:00
|
|
|
{
|
2022-05-17 05:47:42 +00:00
|
|
|
if(c.entity instanceof Creeper) {
|
2020-11-18 07:16:18 +00:00
|
|
|
if(c.creeperTurns++ < TurnBasedMinecraftMod.proxy.getConfig().getCreeperExplodeTurn()) {
|
2020-11-18 06:52:54 +00:00
|
|
|
c.decision = Decision.CREEPER_WAIT;
|
|
|
|
} else {
|
|
|
|
c.decision = Decision.CREEPER_EXPLODE;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2018-10-27 08:34:02 +00:00
|
|
|
int percentage = random.nextInt(100);
|
2018-09-06 08:08:36 +00:00
|
|
|
if(percentage < c.entityInfo.decisionAttack)
|
|
|
|
{
|
|
|
|
c.decision = Decision.ATTACK;
|
|
|
|
}
|
|
|
|
else if(percentage - c.entityInfo.decisionAttack < c.entityInfo.decisionDefend)
|
|
|
|
{
|
|
|
|
c.decision = Decision.DEFEND;
|
|
|
|
}
|
|
|
|
else if(percentage - c.entityInfo.decisionAttack - c.entityInfo.decisionDefend < c.entityInfo.decisionFlee)
|
|
|
|
{
|
|
|
|
c.decision = Decision.FLEE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(Combatant c : sideB.values())
|
|
|
|
{
|
2022-05-17 05:47:42 +00:00
|
|
|
if(!(c.entity instanceof Player) && c.decision == Decision.UNDECIDED && c.entityInfo != null)
|
2018-09-06 08:08:36 +00:00
|
|
|
{
|
2022-05-17 05:47:42 +00:00
|
|
|
if(c.entity instanceof Creeper) {
|
2020-11-18 07:16:18 +00:00
|
|
|
if(c.creeperTurns++ < TurnBasedMinecraftMod.proxy.getConfig().getCreeperExplodeTurn()) {
|
2020-11-18 06:52:54 +00:00
|
|
|
c.decision = Decision.CREEPER_WAIT;
|
|
|
|
} else {
|
|
|
|
c.decision = Decision.CREEPER_EXPLODE;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2018-10-27 08:34:02 +00:00
|
|
|
int percentage = random.nextInt(100);
|
2018-09-06 08:08:36 +00:00
|
|
|
if(percentage < c.entityInfo.decisionAttack)
|
|
|
|
{
|
|
|
|
c.decision = Decision.ATTACK;
|
|
|
|
}
|
|
|
|
else if(percentage - c.entityInfo.decisionAttack < c.entityInfo.decisionDefend)
|
|
|
|
{
|
|
|
|
c.decision = Decision.DEFEND;
|
|
|
|
}
|
|
|
|
else if(percentage - c.entityInfo.decisionAttack - c.entityInfo.decisionDefend < c.entityInfo.decisionFlee)
|
|
|
|
{
|
|
|
|
c.decision = Decision.FLEE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-05 06:54:06 +00:00
|
|
|
state = State.ACTION;
|
2018-09-28 08:45:32 +00:00
|
|
|
timer = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
|
2018-09-10 05:59:56 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_BEGIN, 0, 0, 0);
|
2018-09-04 06:21:49 +00:00
|
|
|
turnOrderQueue.clear();
|
|
|
|
for(Combatant c : sideA.values())
|
|
|
|
{
|
|
|
|
turnOrderQueue.add(c);
|
|
|
|
}
|
|
|
|
for(Combatant c : sideB.values())
|
|
|
|
{
|
|
|
|
turnOrderQueue.add(c);
|
|
|
|
}
|
2018-10-18 05:47:40 +00:00
|
|
|
return update(0);
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
2018-09-07 07:41:22 +00:00
|
|
|
else
|
|
|
|
{
|
2018-09-27 09:09:40 +00:00
|
|
|
if(healthCheck())
|
|
|
|
{
|
|
|
|
combatantsChanged = true;
|
|
|
|
}
|
|
|
|
if(isCreativeCheck())
|
|
|
|
{
|
|
|
|
combatantsChanged = true;
|
|
|
|
}
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
2018-08-29 06:09:44 +00:00
|
|
|
break;
|
2018-09-05 06:54:06 +00:00
|
|
|
case ACTION:
|
2018-09-04 06:21:49 +00:00
|
|
|
{
|
2018-09-18 06:56:06 +00:00
|
|
|
for(Combatant next = turnOrderQueue.poll(); next != null; next = turnOrderQueue.poll())
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2019-10-28 02:49:28 +00:00
|
|
|
if(!next.entity.isAlive())
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2018-09-07 07:41:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-10-28 02:49:28 +00:00
|
|
|
|
2021-05-21 05:44:31 +00:00
|
|
|
debugLog = next.entity.getDisplayName().getString();
|
2019-10-28 02:49:28 +00:00
|
|
|
|
2018-09-13 05:52:48 +00:00
|
|
|
next.remainingDefenses = 0;
|
2018-10-29 05:46:45 +00:00
|
|
|
|
|
|
|
Decision decision = next.decision;
|
|
|
|
next.decision = Decision.UNDECIDED;
|
2018-09-13 05:52:48 +00:00
|
|
|
|
2018-10-29 05:46:45 +00:00
|
|
|
switch(decision)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
|
|
|
case UNDECIDED:
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " undecided";
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DID_NOTHING, next.entity.getId(), 0, 0);
|
2018-09-07 07:41:22 +00:00
|
|
|
break;
|
|
|
|
case ATTACK:
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " attack";
|
2018-09-07 07:41:22 +00:00
|
|
|
Combatant target = null;
|
2022-05-17 05:47:42 +00:00
|
|
|
if(next.entity instanceof Player)
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " as player";
|
2018-10-18 07:26:09 +00:00
|
|
|
target = sideA.get(next.targetEntityID);
|
|
|
|
if(target == null)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
|
|
|
target = sideB.get(next.targetEntityID);
|
|
|
|
}
|
2019-10-28 02:49:28 +00:00
|
|
|
if(target == null || !target.entity.isAlive() || target == next)
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2018-10-18 07:26:09 +00:00
|
|
|
continue;
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
2022-05-17 05:47:42 +00:00
|
|
|
ItemStack heldItemStack = ((Player)next.entity).getMainHandItem();
|
2019-10-28 02:49:28 +00:00
|
|
|
if(heldItemStack.getItem() instanceof BowItem)
|
2018-09-17 06:49:10 +00:00
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " with bow";
|
2022-05-17 05:47:42 +00:00
|
|
|
if(Utility.doesPlayerHaveArrows((Player)next.entity))
|
2018-09-17 06:49:10 +00:00
|
|
|
{
|
|
|
|
final Entity nextEntity = next.entity;
|
|
|
|
final Entity targetEntity = target.entity;
|
2021-05-21 05:44:31 +00:00
|
|
|
final float yawDirection = Utility.yawDirection(next.entity.getX(), next.entity.getZ(), target.entity.getX(), target.entity.getZ());
|
|
|
|
final float pitchDirection = Utility.pitchDirection(next.entity.getX(), next.entity.getY(), next.entity.getZ(), target.entity.getX(), target.entity.getY(), target.entity.getZ());
|
2019-10-28 02:49:28 +00:00
|
|
|
final int randomTimeLeft = random.nextInt(heldItemStack.getItem().getUseDuration(heldItemStack) / 3);
|
2018-09-28 08:45:32 +00:00
|
|
|
if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
|
2018-09-18 06:56:06 +00:00
|
|
|
{
|
|
|
|
next.yaw = yawDirection;
|
|
|
|
next.pitch = pitchDirection;
|
|
|
|
}
|
2019-10-28 02:49:28 +00:00
|
|
|
// have player look at attack target
|
2022-05-17 05:47:42 +00:00
|
|
|
((ServerPlayer)nextEntity).connection.teleport(nextEntity.getX(), nextEntity.getY(), nextEntity.getZ(), yawDirection, pitchDirection);
|
2019-10-28 02:49:28 +00:00
|
|
|
BowItem itemBow = (BowItem)heldItemStack.getItem();
|
2019-11-29 04:59:41 +00:00
|
|
|
TurnBasedMinecraftMod.proxy.getAttackerViaBowSet().add(new AttackerViaBow(nextEntity, getId()));
|
2022-05-17 05:47:42 +00:00
|
|
|
itemBow.releaseUsing(((Player)nextEntity).getMainHandItem(), nextEntity.level, (LivingEntity) nextEntity, randomTimeLeft);
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.FIRED_ARROW, nextEntity.getId(), targetEntity.getId(), 0);
|
2018-09-17 06:49:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.BOW_NO_AMMO, next.entity.getId(), 0, 0);
|
2018-09-17 06:49:10 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " without bow";
|
2018-09-28 08:45:32 +00:00
|
|
|
int hitChance = TurnBasedMinecraftMod.proxy.getConfig().getPlayerAttackProbability();
|
2022-05-17 05:47:42 +00:00
|
|
|
if(target.entity instanceof Player)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
2018-10-24 08:20:04 +00:00
|
|
|
hitChance = hitChance * (100 - TurnBasedMinecraftMod.proxy.getConfig().getPlayerEvasion()) / 100;
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-24 08:20:04 +00:00
|
|
|
hitChance = hitChance * (100 - target.entityInfo.evasion) / 100;
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
2018-09-28 08:45:32 +00:00
|
|
|
if(hitChance < TurnBasedMinecraftMod.proxy.getConfig().getMinimumHitPercentage())
|
2018-09-13 05:12:04 +00:00
|
|
|
{
|
2018-09-28 08:45:32 +00:00
|
|
|
hitChance = TurnBasedMinecraftMod.proxy.getConfig().getMinimumHitPercentage();
|
2018-09-13 05:12:04 +00:00
|
|
|
}
|
2018-10-27 08:34:02 +00:00
|
|
|
if(random.nextInt(100) < hitChance)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
|
|
|
if(target.remainingDefenses <= 0)
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " hit success";
|
2018-09-07 07:41:22 +00:00
|
|
|
// attack
|
2018-09-12 05:43:59 +00:00
|
|
|
final Entity nextEntity = next.entity;
|
|
|
|
final Entity targetEntity = target.entity;
|
2018-09-17 04:27:13 +00:00
|
|
|
final EntityInfo targetEntityInfo = target.entityInfo;
|
2021-05-21 05:44:31 +00:00
|
|
|
final float yawDirection = Utility.yawDirection(next.entity.getX(), next.entity.getZ(), target.entity.getX(), target.entity.getZ());
|
|
|
|
final float pitchDirection = Utility.pitchDirection(next.entity.getX(), next.entity.getY(), next.entity.getZ(), target.entity.getX(), target.entity.getY(), target.entity.getZ());
|
2018-10-27 08:34:02 +00:00
|
|
|
final boolean defenseDamageTriggered;
|
2022-05-17 05:47:42 +00:00
|
|
|
if(!(targetEntity instanceof Player) && targetEntityInfo.defenseDamage > 0 && targetEntityInfo.defenseDamageProbability > 0)
|
2018-10-27 08:34:02 +00:00
|
|
|
{
|
|
|
|
if(random.nextInt(100) < targetEntityInfo.defenseDamageProbability)
|
|
|
|
{
|
|
|
|
defenseDamageTriggered = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
defenseDamageTriggered = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
defenseDamageTriggered = false;
|
|
|
|
}
|
2018-09-28 08:45:32 +00:00
|
|
|
if(TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled())
|
2018-09-18 06:56:06 +00:00
|
|
|
{
|
|
|
|
next.yaw = yawDirection;
|
|
|
|
next.pitch = pitchDirection;
|
|
|
|
}
|
2019-10-28 02:49:28 +00:00
|
|
|
// have player look at attack target
|
2022-05-17 05:47:42 +00:00
|
|
|
((ServerPlayer)nextEntity).connection.teleport(nextEntity.getX(), nextEntity.getY(), nextEntity.getZ(), yawDirection, pitchDirection);
|
2019-10-28 02:49:28 +00:00
|
|
|
TurnBasedMinecraftMod.proxy.setAttackingEntity(nextEntity);
|
|
|
|
TurnBasedMinecraftMod.proxy.setAttackingDamage(0);
|
2022-05-17 05:47:42 +00:00
|
|
|
((Player)nextEntity).attack(targetEntity);
|
2019-10-28 02:49:28 +00:00
|
|
|
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getId(), targetEntity.getId(), TurnBasedMinecraftMod.proxy.getAttackingDamage());
|
2019-10-28 02:49:28 +00:00
|
|
|
if(defenseDamageTriggered)
|
|
|
|
{
|
|
|
|
// defense damage
|
2021-05-21 05:44:31 +00:00
|
|
|
DamageSource defenseDamageSource = DamageSource.mobAttack((LivingEntity) targetEntity);
|
2019-10-28 02:49:28 +00:00
|
|
|
TurnBasedMinecraftMod.proxy.setAttackingEntity(targetEntity);
|
2021-05-21 05:44:31 +00:00
|
|
|
nextEntity.hurt(defenseDamageSource, targetEntityInfo.defenseDamage);
|
2018-09-28 08:45:32 +00:00
|
|
|
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENSE_DAMAGE, targetEntity.getId(), nextEntity.getId(), targetEntityInfo.defenseDamage);
|
2019-10-28 02:49:28 +00:00
|
|
|
}
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
2018-09-07 07:41:22 +00:00
|
|
|
else
|
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " hit blocked";
|
2018-09-07 07:41:22 +00:00
|
|
|
// blocked
|
|
|
|
--target.remainingDefenses;
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFEND, target.entity.getId(), next.entity.getId(), 0);
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " hit missed";
|
2018-09-07 07:41:22 +00:00
|
|
|
// miss
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.MISS, next.entity.getId(), target.entity.getId(), 0);
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " as mob";
|
2022-05-17 05:47:42 +00:00
|
|
|
LivingEntity attackTarget = ((Mob)next.entity).getTarget();
|
2021-05-21 05:44:31 +00:00
|
|
|
if(attackTarget != null && hasCombatant(attackTarget.getId()))
|
2018-10-17 08:15:23 +00:00
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " to targeted";
|
2021-05-21 05:44:31 +00:00
|
|
|
target = getCombatantByID(attackTarget.getId());
|
2018-10-17 08:15:23 +00:00
|
|
|
}
|
|
|
|
else
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " to random other side";
|
2018-10-17 08:15:23 +00:00
|
|
|
if(next.isSideA)
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2018-10-29 05:46:45 +00:00
|
|
|
if(sideB.size() > 0)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
2018-10-29 05:46:45 +00:00
|
|
|
int randomTargetIndex = random.nextInt(sideB.size());
|
|
|
|
for(Combatant c : sideB.values())
|
2018-10-17 08:15:23 +00:00
|
|
|
{
|
2018-10-29 05:46:45 +00:00
|
|
|
if(randomTargetIndex-- == 0)
|
|
|
|
{
|
|
|
|
target = c;
|
|
|
|
break;
|
|
|
|
}
|
2018-10-17 08:15:23 +00:00
|
|
|
}
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
2018-10-17 08:15:23 +00:00
|
|
|
else
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2018-10-29 05:46:45 +00:00
|
|
|
if(sideA.size() > 0)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
2018-10-29 05:46:45 +00:00
|
|
|
int randomTargetIndex = random.nextInt(sideA.size());
|
|
|
|
for(Combatant c : sideA.values())
|
2018-10-17 08:15:23 +00:00
|
|
|
{
|
2018-10-29 05:46:45 +00:00
|
|
|
if(randomTargetIndex-- == 0)
|
|
|
|
{
|
|
|
|
target = c;
|
|
|
|
break;
|
|
|
|
}
|
2018-10-17 08:15:23 +00:00
|
|
|
}
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-28 02:49:28 +00:00
|
|
|
if(target == null || !target.entity.isAlive() || target == next)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int hitChance = next.entityInfo.attackProbability;
|
2022-05-17 05:47:42 +00:00
|
|
|
if(target.entity instanceof Player)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
2018-10-24 08:20:04 +00:00
|
|
|
hitChance = hitChance * (100 - TurnBasedMinecraftMod.proxy.getConfig().getPlayerEvasion()) / 100;
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-24 08:20:04 +00:00
|
|
|
hitChance = hitChance * (100 - target.entityInfo.evasion) / 100;
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
2018-09-28 08:45:32 +00:00
|
|
|
if(hitChance < TurnBasedMinecraftMod.proxy.getConfig().getMinimumHitPercentage())
|
2018-09-13 05:12:04 +00:00
|
|
|
{
|
2018-09-28 08:45:32 +00:00
|
|
|
hitChance = TurnBasedMinecraftMod.proxy.getConfig().getMinimumHitPercentage();
|
2018-09-13 05:12:04 +00:00
|
|
|
}
|
2018-10-27 08:34:02 +00:00
|
|
|
if(random.nextInt(100) < hitChance)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
|
|
|
if(target.remainingDefenses <= 0)
|
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " hit success";
|
2021-05-21 05:44:31 +00:00
|
|
|
DamageSource damageSource = DamageSource.mobAttack((LivingEntity)next.entity);
|
2018-09-07 07:41:22 +00:00
|
|
|
int damageAmount = next.entityInfo.attackPower;
|
|
|
|
if(next.entityInfo.attackVariance > 0)
|
|
|
|
{
|
2018-10-27 08:34:02 +00:00
|
|
|
damageAmount += random.nextInt(next.entityInfo.attackVariance * 2 + 1) - next.entityInfo.attackVariance;
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
2018-10-24 08:20:04 +00:00
|
|
|
if(damageAmount < 0)
|
|
|
|
{
|
|
|
|
damageAmount = 0;
|
|
|
|
}
|
2018-09-07 07:41:22 +00:00
|
|
|
// attack
|
2018-09-17 04:27:13 +00:00
|
|
|
final Entity nextEntity = next.entity;
|
|
|
|
final EntityInfo nextEntityInfo = next.entityInfo;
|
|
|
|
final Entity targetEntity = target.entity;
|
|
|
|
final EntityInfo targetEntityInfo = target.entityInfo;
|
|
|
|
final int finalDamageAmount = damageAmount;
|
2018-10-27 07:53:04 +00:00
|
|
|
final boolean defenseDamageTriggered;
|
|
|
|
final boolean attackEffectTriggered;
|
|
|
|
|
2022-05-17 05:47:42 +00:00
|
|
|
if(!(targetEntity instanceof Player) && targetEntityInfo.defenseDamage > 0 && targetEntityInfo.defenseDamageProbability > 0)
|
2018-10-27 07:53:04 +00:00
|
|
|
{
|
2018-10-27 08:34:02 +00:00
|
|
|
if(random.nextInt(100) < targetEntityInfo.defenseDamageProbability)
|
2018-10-27 07:53:04 +00:00
|
|
|
{
|
|
|
|
defenseDamageTriggered = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
defenseDamageTriggered = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
defenseDamageTriggered = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(nextEntityInfo.attackEffect != EntityInfo.Effect.UNKNOWN && nextEntityInfo.attackEffectProbability > 0)
|
|
|
|
{
|
2018-10-27 08:34:02 +00:00
|
|
|
if(random.nextInt(100) < nextEntityInfo.attackEffectProbability)
|
2018-10-27 07:53:04 +00:00
|
|
|
{
|
|
|
|
attackEffectTriggered = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attackEffectTriggered = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attackEffectTriggered = false;
|
|
|
|
}
|
|
|
|
|
2019-10-28 02:49:28 +00:00
|
|
|
TurnBasedMinecraftMod.proxy.setAttackingEntity(nextEntity);
|
2021-05-21 05:44:31 +00:00
|
|
|
targetEntity.hurt(damageSource, finalDamageAmount);
|
2019-10-28 02:49:28 +00:00
|
|
|
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getId(), targetEntity.getId(), finalDamageAmount);
|
2019-10-28 02:49:28 +00:00
|
|
|
if(defenseDamageTriggered)
|
|
|
|
{
|
|
|
|
// defense damage
|
2021-05-21 05:44:31 +00:00
|
|
|
DamageSource defenseDamageSource = DamageSource.mobAttack((LivingEntity)targetEntity);
|
2019-10-28 02:49:28 +00:00
|
|
|
TurnBasedMinecraftMod.proxy.setAttackingEntity(targetEntity);
|
2021-05-21 05:44:31 +00:00
|
|
|
nextEntity.hurt(defenseDamageSource, targetEntityInfo.defenseDamage);
|
2018-09-28 08:45:32 +00:00
|
|
|
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENSE_DAMAGE, targetEntity.getId(), nextEntity.getId(), targetEntityInfo.defenseDamage);
|
2019-10-28 02:49:28 +00:00
|
|
|
}
|
|
|
|
// attack effect
|
|
|
|
if(attackEffectTriggered)
|
|
|
|
{
|
|
|
|
nextEntityInfo.attackEffect.applyEffectToEntity((LivingEntity)targetEntity);
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.WAS_AFFECTED, nextEntity.getId(), targetEntity.getId(), 0, nextEntityInfo.attackEffect.getAffectedString());
|
2019-10-28 02:49:28 +00:00
|
|
|
}
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " hit blocked";
|
2018-09-07 07:41:22 +00:00
|
|
|
// blocked
|
|
|
|
--target.remainingDefenses;
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFEND, target.entity.getId(), next.entity.getId(), 0);
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " hit missed";
|
2018-09-07 07:41:22 +00:00
|
|
|
// miss
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.MISS, next.entity.getId(), target.entity.getId(), 0);
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
2018-09-07 07:41:22 +00:00
|
|
|
break;
|
|
|
|
case DEFEND:
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " defend";
|
2018-09-28 08:45:32 +00:00
|
|
|
next.remainingDefenses = TurnBasedMinecraftMod.proxy.getConfig().getDefenseDuration();
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENDING, next.entity.getId(), 0, 0);
|
2018-09-07 07:41:22 +00:00
|
|
|
break;
|
|
|
|
case FLEE:
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " flee";
|
2018-09-07 07:41:22 +00:00
|
|
|
int fastestEnemySpeed = 0;
|
|
|
|
if(next.isSideA)
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2018-09-07 07:41:22 +00:00
|
|
|
for(Combatant c : sideB.values())
|
|
|
|
{
|
2022-05-17 05:47:42 +00:00
|
|
|
if(c.entity instanceof Player)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
2022-06-08 10:22:45 +00:00
|
|
|
int playerSpeed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSpeed();
|
|
|
|
if (((Player) c.entity).hasEffect(MobEffects.MOVEMENT_SPEED)) {
|
|
|
|
playerSpeed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerHasteSpeed();
|
|
|
|
} else if (((Player) c.entity).hasEffect(MobEffects.MOVEMENT_SLOWDOWN)) {
|
|
|
|
playerSpeed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSlowSpeed();
|
|
|
|
}
|
|
|
|
if(playerSpeed > fastestEnemySpeed)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
2018-09-28 08:45:32 +00:00
|
|
|
fastestEnemySpeed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSpeed();
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(c.entityInfo.speed > fastestEnemySpeed)
|
|
|
|
{
|
|
|
|
fastestEnemySpeed = c.entityInfo.speed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-07 07:41:22 +00:00
|
|
|
for(Combatant c : sideA.values())
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2022-05-17 05:47:42 +00:00
|
|
|
if(c.entity instanceof Player)
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2022-06-08 10:22:45 +00:00
|
|
|
int playerSpeed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSpeed();
|
|
|
|
if (((Player) c.entity).hasEffect(MobEffects.MOVEMENT_SPEED)) {
|
|
|
|
playerSpeed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerHasteSpeed();
|
|
|
|
} else if (((Player) c.entity).hasEffect(MobEffects.MOVEMENT_SLOWDOWN)) {
|
|
|
|
playerSpeed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSlowSpeed();
|
|
|
|
}
|
|
|
|
if(playerSpeed > fastestEnemySpeed)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
2018-09-28 08:45:32 +00:00
|
|
|
fastestEnemySpeed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSpeed();
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
2018-09-07 07:41:22 +00:00
|
|
|
else
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2018-09-07 07:41:22 +00:00
|
|
|
if(c.entityInfo.speed > fastestEnemySpeed)
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2018-09-07 07:41:22 +00:00
|
|
|
fastestEnemySpeed = c.entityInfo.speed;
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
|
|
|
int fleeProbability = 0;
|
2022-05-17 05:47:42 +00:00
|
|
|
if(next.entity instanceof Player)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
2022-06-08 10:22:45 +00:00
|
|
|
int playerSpeed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSpeed();
|
|
|
|
if (((Player) next.entity).hasEffect(MobEffects.MOVEMENT_SPEED)) {
|
|
|
|
playerSpeed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerHasteSpeed();
|
|
|
|
} else if (((Player) next.entity).hasEffect(MobEffects.MOVEMENT_SLOWDOWN)) {
|
|
|
|
playerSpeed = TurnBasedMinecraftMod.proxy.getConfig().getPlayerSlowSpeed();
|
|
|
|
}
|
|
|
|
if(fastestEnemySpeed >= playerSpeed)
|
2018-09-07 07:41:22 +00:00
|
|
|
{
|
2018-09-28 08:45:32 +00:00
|
|
|
fleeProbability = TurnBasedMinecraftMod.proxy.getConfig().getFleeBadProbability();
|
2018-09-07 07:41:22 +00:00
|
|
|
}
|
2018-09-05 06:54:06 +00:00
|
|
|
else
|
|
|
|
{
|
2018-09-28 08:45:32 +00:00
|
|
|
fleeProbability = TurnBasedMinecraftMod.proxy.getConfig().getFleeGoodProbability();
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-07 07:41:22 +00:00
|
|
|
if(fastestEnemySpeed >= next.entityInfo.speed)
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2018-09-28 08:45:32 +00:00
|
|
|
fleeProbability = TurnBasedMinecraftMod.proxy.getConfig().getFleeBadProbability();
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-28 08:45:32 +00:00
|
|
|
fleeProbability = TurnBasedMinecraftMod.proxy.getConfig().getFleeGoodProbability();
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-27 08:34:02 +00:00
|
|
|
if(random.nextInt(100) < fleeProbability)
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " success";
|
2018-09-07 07:41:22 +00:00
|
|
|
// flee success
|
2018-09-27 09:09:40 +00:00
|
|
|
combatantsChanged = true;
|
|
|
|
String fleeingCategory = new String();
|
|
|
|
if(next.entityInfo != null)
|
|
|
|
{
|
|
|
|
fleeingCategory = next.entityInfo.category;
|
|
|
|
}
|
2022-05-17 05:47:42 +00:00
|
|
|
else if(next.entity instanceof Player)
|
2018-09-27 09:09:40 +00:00
|
|
|
{
|
|
|
|
fleeingCategory = "player";
|
|
|
|
}
|
2018-10-17 09:28:47 +00:00
|
|
|
removeCombatant(next);
|
2021-05-23 06:38:04 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.FLEE, next.entity.getId(), 0, 1, fleeingCategory);
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " fail";
|
2018-09-07 07:41:22 +00:00
|
|
|
// flee fail
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.FLEE, next.entity.getId(), 0, 0);
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
2018-09-07 07:41:22 +00:00
|
|
|
break;
|
|
|
|
case USE_ITEM:
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " use item";
|
2018-09-11 07:39:46 +00:00
|
|
|
if(next.itemToUse < 0 || next.itemToUse > 8)
|
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " invalid";
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_INVALID.getValue());
|
2018-09-11 07:39:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-05-17 05:47:42 +00:00
|
|
|
ItemStack targetItemStack = ((Player) next.entity).getInventory().getItem(next.itemToUse);
|
2018-09-07 07:41:22 +00:00
|
|
|
Item targetItem = targetItemStack.getItem();
|
|
|
|
if(targetItem == null)
|
2018-09-05 06:54:06 +00:00
|
|
|
{
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " null";
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_NOTHING.getValue());
|
2018-09-07 07:41:22 +00:00
|
|
|
break;
|
2022-05-17 05:47:42 +00:00
|
|
|
} else if(targetItem.isEdible()) {
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " food";
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_FOOD.getValue(), targetItemStack.getDisplayName().getString());
|
2018-09-17 04:27:13 +00:00
|
|
|
final Entity nextEntity = next.entity;
|
2018-10-19 08:18:02 +00:00
|
|
|
final int nextItemToUse = next.itemToUse;
|
2022-05-17 05:47:42 +00:00
|
|
|
((Player) nextEntity).getInventory().setItem(nextItemToUse, targetItem.finishUsingItem(targetItemStack, nextEntity.level, (LivingEntity)nextEntity));
|
2021-05-23 04:22:18 +00:00
|
|
|
} else {
|
|
|
|
// then check vanilla foods
|
2022-05-17 05:47:42 +00:00
|
|
|
if (targetItem.getItemCategory() == CreativeModeTab.TAB_FOOD && targetItem.isEdible()) {
|
2021-05-23 04:22:18 +00:00
|
|
|
debugLog += " food";
|
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_FOOD.getValue(), targetItemStack.getDisplayName().getString());
|
|
|
|
final Entity nextEntity = next.entity;
|
|
|
|
final int nextItemToUse = next.itemToUse;
|
2022-05-17 05:47:42 +00:00
|
|
|
((Player) nextEntity).getInventory().setItem(nextItemToUse, targetItem.finishUsingItem(targetItemStack, nextEntity.level, (LivingEntity) nextEntity));
|
2021-05-23 04:22:18 +00:00
|
|
|
} else if (targetItem instanceof PotionItem) {
|
|
|
|
debugLog += " potion";
|
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_POTION.getValue(), targetItemStack.getDisplayName().getString());
|
|
|
|
final Entity nextEntity = next.entity;
|
|
|
|
final int nextItemToUse = next.itemToUse;
|
2022-05-17 05:47:42 +00:00
|
|
|
((Player) nextEntity).getInventory().setItem(nextItemToUse, targetItem.finishUsingItem(targetItemStack, nextEntity.level, (LivingEntity) nextEntity));
|
2021-05-23 04:22:18 +00:00
|
|
|
} else {
|
|
|
|
debugLog += " non-consumable";
|
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_INVALID.getValue(), targetItemStack.getDisplayName().getString());
|
|
|
|
}
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
2018-09-07 07:41:22 +00:00
|
|
|
break;
|
2020-11-18 06:52:54 +00:00
|
|
|
case SWITCH_ITEM: {
|
2018-10-19 08:18:02 +00:00
|
|
|
debugLog += " switch item";
|
2020-11-18 06:52:54 +00:00
|
|
|
if (next.itemToUse < 0 || next.itemToUse > 8) {
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.SWITCHED_ITEM, next.entity.getId(), 0, 0);
|
2018-09-11 07:39:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-09-17 04:27:13 +00:00
|
|
|
final Entity nextEntity = next.entity;
|
|
|
|
final int nextItemToUse = next.itemToUse;
|
2022-05-17 05:47:42 +00:00
|
|
|
((Player) nextEntity).getInventory().selected = nextItemToUse;
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.SWITCHED_ITEM, next.entity.getId(), 0, 1);
|
2020-11-18 06:52:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CREEPER_WAIT:
|
|
|
|
debugLog += " creeper wait";
|
2020-11-18 07:16:18 +00:00
|
|
|
if(next.creeperTurns < TurnBasedMinecraftMod.proxy.getConfig().getCreeperExplodeTurn()) {
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.CREEPER_WAIT, next.entity.getId(), 0, 0);
|
2020-11-18 06:52:54 +00:00
|
|
|
} else {
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.CREEPER_WAIT_FINAL, next.entity.getId(), 0, 0);
|
2020-11-18 06:52:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CREEPER_EXPLODE: {
|
|
|
|
debugLog += " creeper explode";
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.CREEPER_EXPLODE, next.entity.getId(), 0, 0);
|
2020-11-18 06:52:54 +00:00
|
|
|
final Entity nextEntity = next.entity;
|
|
|
|
final EntityInfo nextEntityInfo = next.entityInfo;
|
|
|
|
for (Combatant c : sideA.values()) {
|
2021-05-21 05:44:31 +00:00
|
|
|
if (c.entity.getId() != next.entity.getId()) {
|
2020-11-18 06:52:54 +00:00
|
|
|
int hitChance = next.entityInfo.attackProbability;
|
2022-05-17 05:47:42 +00:00
|
|
|
if (c.entity instanceof Player) {
|
2020-11-18 06:52:54 +00:00
|
|
|
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);
|
2021-05-21 05:44:31 +00:00
|
|
|
targetEntity.hurt(DamageSource.mobAttack((LivingEntity) nextEntity), finalDamageAmount);
|
2020-11-18 06:52:54 +00:00
|
|
|
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getId(), targetEntity.getId(), finalDamageAmount);
|
2020-11-18 06:52:54 +00:00
|
|
|
if(attackEffectTriggered) {
|
|
|
|
nextEntityInfo.attackEffect.applyEffectToEntity((LivingEntity)targetEntity);
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.WAS_AFFECTED, nextEntity.getId(), targetEntity.getId(), 0, nextEntityInfo.attackEffect.getAffectedString());
|
2020-11-18 06:52:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(Combatant c : sideB.values()) {
|
2021-05-21 05:44:31 +00:00
|
|
|
if (c.entity.getId() != next.entity.getId()) {
|
2020-11-18 06:52:54 +00:00
|
|
|
int hitChance = next.entityInfo.attackProbability;
|
2022-05-17 05:47:42 +00:00
|
|
|
if (c.entity instanceof Player) {
|
2020-11-18 06:52:54 +00:00
|
|
|
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);
|
2021-05-21 05:44:31 +00:00
|
|
|
targetEntity.hurt(DamageSource.mobAttack((LivingEntity) nextEntity), finalDamageAmount);
|
2020-11-18 06:52:54 +00:00
|
|
|
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getId(), targetEntity.getId(), finalDamageAmount);
|
2020-11-18 06:52:54 +00:00
|
|
|
if(attackEffectTriggered) {
|
|
|
|
nextEntityInfo.attackEffect.applyEffectToEntity((LivingEntity)targetEntity);
|
2021-05-21 05:44:31 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.WAS_AFFECTED, nextEntity.getId(), targetEntity.getId(), 0, nextEntityInfo.attackEffect.getAffectedString());
|
2020-11-18 06:52:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-17 05:47:42 +00:00
|
|
|
((Creeper)nextEntity).setSwellDir(1000000);
|
2020-11-18 06:52:54 +00:00
|
|
|
}
|
2018-09-11 06:15:31 +00:00
|
|
|
break;
|
2018-09-05 06:54:06 +00:00
|
|
|
}
|
2018-09-06 08:08:36 +00:00
|
|
|
}
|
2018-10-26 09:10:09 +00:00
|
|
|
debugLog = "Actions almost end";
|
2018-10-29 05:46:45 +00:00
|
|
|
setDecisionState();
|
2018-09-27 09:09:40 +00:00
|
|
|
if(healthCheck())
|
|
|
|
{
|
|
|
|
combatantsChanged = true;
|
|
|
|
}
|
|
|
|
if(isCreativeCheck())
|
|
|
|
{
|
|
|
|
combatantsChanged = true;
|
|
|
|
}
|
2018-10-26 09:10:09 +00:00
|
|
|
debugLog += ", adding task";
|
2019-10-28 02:49:28 +00:00
|
|
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_END, 0, 0, 0);
|
2018-10-26 09:10:09 +00:00
|
|
|
debugLog = "Actions end";
|
2018-09-07 07:41:22 +00:00
|
|
|
break;
|
|
|
|
} // case ACTION
|
2018-09-10 05:59:56 +00:00
|
|
|
default:
|
|
|
|
state = State.DECISION;
|
|
|
|
break;
|
2018-09-07 07:41:22 +00:00
|
|
|
} // switch(state)
|
2018-10-26 09:10:09 +00:00
|
|
|
debugLog = "Update almost end";
|
2018-09-27 09:09:40 +00:00
|
|
|
if(combatantsChanged)
|
|
|
|
{
|
|
|
|
notifyPlayersBattleInfo();
|
|
|
|
}
|
2018-10-17 09:28:47 +00:00
|
|
|
if(battleEnded)
|
|
|
|
{
|
|
|
|
Collection<Combatant> combatants = new ArrayList<Combatant>();
|
|
|
|
combatants.addAll(sideA.values());
|
|
|
|
combatants.addAll(sideB.values());
|
|
|
|
for(Combatant c : combatants)
|
|
|
|
{
|
|
|
|
removeCombatant(c);
|
|
|
|
}
|
|
|
|
}
|
2018-10-26 09:10:09 +00:00
|
|
|
debugLog = "Update end";
|
2018-09-06 08:08:36 +00:00
|
|
|
return battleEnded;
|
2018-09-10 05:59:56 +00:00
|
|
|
} // update(final long dt)
|
2020-11-18 06:52:54 +00:00
|
|
|
|
|
|
|
private void defuseCreepers() {
|
|
|
|
for(Combatant c : sideA.values()) {
|
2022-05-17 05:47:42 +00:00
|
|
|
if(c.entity instanceof Creeper) {
|
2020-11-18 07:16:18 +00:00
|
|
|
if(c.creeperTurns <= TurnBasedMinecraftMod.proxy.getConfig().getCreeperExplodeTurn()) {
|
2022-05-17 05:47:42 +00:00
|
|
|
((Creeper)c.entity).setSwellDir(-10);
|
2020-11-18 06:52:54 +00:00
|
|
|
} else {
|
2022-05-17 05:47:42 +00:00
|
|
|
((Creeper)c.entity).setSwellDir(1000000);
|
2020-11-18 06:52:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(Combatant c : sideB.values()) {
|
2022-05-17 05:47:42 +00:00
|
|
|
if(c.entity instanceof Creeper) {
|
2020-11-18 07:16:18 +00:00
|
|
|
if(c.creeperTurns <= TurnBasedMinecraftMod.proxy.getConfig().getCreeperExplodeTurn()) {
|
2022-05-17 05:47:42 +00:00
|
|
|
((Creeper)c.entity).setSwellDir(-10);
|
2020-11-18 06:52:54 +00:00
|
|
|
} else {
|
2022-05-17 05:47:42 +00:00
|
|
|
((Creeper) c.entity).setSwellDir(1000000);
|
2020-11-18 06:52:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|