Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
a9453aa859
Commit
d7b63841a1
@ -21,6 +21,7 @@ package de.steamwar.fightsystem;
|
|||||||
|
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.fightsystem.ai.LixfelAI;
|
||||||
import de.steamwar.fightsystem.commands.*;
|
import de.steamwar.fightsystem.commands.*;
|
||||||
import de.steamwar.fightsystem.countdown.*;
|
import de.steamwar.fightsystem.countdown.*;
|
||||||
import de.steamwar.fightsystem.event.HellsBells;
|
import de.steamwar.fightsystem.event.HellsBells;
|
||||||
@ -105,7 +106,7 @@ public class FightSystem extends JavaPlugin {
|
|||||||
techHider = new TechHiderWrapper();
|
techHider = new TechHiderWrapper();
|
||||||
new FightWorld();
|
new FightWorld();
|
||||||
new FightUI();
|
new FightUI();
|
||||||
new FightStatistics();
|
//new FightStatistics();
|
||||||
new BungeeFightInfo();
|
new BungeeFightInfo();
|
||||||
|
|
||||||
new WinconditionAllDead();
|
new WinconditionAllDead();
|
||||||
@ -163,6 +164,8 @@ public class FightSystem extends JavaPlugin {
|
|||||||
}else if(Config.mode == ArenaMode.PREPARE) {
|
}else if(Config.mode == ArenaMode.PREPARE) {
|
||||||
Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID));
|
Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new LixfelAI(Fight.getBlueTeam());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
127
FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java
Normale Datei
127
FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java
Normale Datei
@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.fightsystem.ai;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.sql.SchematicNode;
|
||||||
|
import de.steamwar.sql.SteamwarUser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Villager;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public abstract class AI {
|
||||||
|
|
||||||
|
private static final Map<UUID, AI> ais = new HashMap<>();
|
||||||
|
|
||||||
|
public static AI getAI(UUID uuid) {
|
||||||
|
return ais.get(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final FightTeam team;
|
||||||
|
private final LivingEntity entity;
|
||||||
|
private final BukkitTask task;
|
||||||
|
private int cooldown;
|
||||||
|
|
||||||
|
private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.entity.CraftEntity", "getHandle");
|
||||||
|
private static final Reflection.FieldAccessor<UUID> entityUUID = Reflection.getField("{nms.world.entity}.Entity", UUID.class, 0);
|
||||||
|
protected AI(FightTeam team, SteamwarUser user) {
|
||||||
|
this.team = team;
|
||||||
|
|
||||||
|
entity = Config.world.spawn(Config.SpecSpawn, Villager.class, entity -> entityUUID.set(getHandle.invoke(entity), user.getUUID()));
|
||||||
|
entity.setCustomName(user.getUserName());
|
||||||
|
entity.setAI(false);
|
||||||
|
|
||||||
|
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::run, 1, 1);
|
||||||
|
ais.put(user.getUUID(), this);
|
||||||
|
team.addMember(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract SchematicNode chooseSchematic();
|
||||||
|
|
||||||
|
public boolean acceptJoinRequest(Player player, FightTeam team) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void plan();
|
||||||
|
|
||||||
|
public void cleanup() {
|
||||||
|
ais.remove(entity.getUniqueId());
|
||||||
|
task.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LivingEntity getEntity() {
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setReady() {
|
||||||
|
if(FightState.getFightState() != FightState.POST_SCHEM_SETUP)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(team.getLeader().getEntity() != entity)
|
||||||
|
return;
|
||||||
|
|
||||||
|
team.setReady(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Material getBlock(Vector pos) {
|
||||||
|
//TODO position translation
|
||||||
|
cooldown++;
|
||||||
|
return pos.toLocation(Config.world).getBlock().getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setTNT(Vector pos) {
|
||||||
|
//TODO position translation
|
||||||
|
//TODO Check position
|
||||||
|
//TODO Check AIR is there
|
||||||
|
cooldown++;
|
||||||
|
pos.toLocation(Config.world).getBlock().setType(Material.TNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void move(Vector pos) {
|
||||||
|
//TODO position translation
|
||||||
|
//TODO Check position
|
||||||
|
//TODO falling check
|
||||||
|
//TODO pathfinding
|
||||||
|
cooldown += 5;
|
||||||
|
entity.teleport(pos.toLocation(Config.world));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void run() {
|
||||||
|
if(cooldown > 0)
|
||||||
|
cooldown--;
|
||||||
|
|
||||||
|
if(cooldown > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
plan();
|
||||||
|
}
|
||||||
|
}
|
@ -19,27 +19,28 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.ai;
|
package de.steamwar.fightsystem.ai;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
|
import de.steamwar.sql.SchematicNode;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.entity.Villager;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class AIPlayer {
|
public class LixfelAI extends AI {
|
||||||
private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.entity.CraftEntity", "getHandle");
|
public LixfelAI(FightTeam team) {
|
||||||
private static final Reflection.FieldAccessor<UUID> entityUUID = Reflection.getField("{nms.world.entity}.Entity", UUID.class, 0);
|
super(team, SteamwarUser.get("public"));
|
||||||
|
|
||||||
private final LivingEntity player;
|
|
||||||
|
|
||||||
public AIPlayer(SteamwarUser user) {
|
|
||||||
player = Config.world.spawn(Config.SpecSpawn, Villager.class, entity -> entityUUID.set(getHandle.invoke(entity), user.getUUID()));
|
|
||||||
player.setCustomName(user.getUserName());
|
|
||||||
player.setAI(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LivingEntity getEntity() {
|
@Override
|
||||||
return player;
|
public SchematicNode chooseSchematic() {
|
||||||
|
List<SchematicNode> publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB());
|
||||||
|
return publics.get(new Random().nextInt(publics.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void plan() {
|
||||||
|
setReady();
|
||||||
|
getEntity().setAI(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.fightsystem.fight;
|
package de.steamwar.fightsystem.fight;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.ai.AI;
|
||||||
import de.steamwar.fightsystem.countdown.EnternCountdown;
|
import de.steamwar.fightsystem.countdown.EnternCountdown;
|
||||||
import de.steamwar.sql.PersonalKit;
|
import de.steamwar.sql.PersonalKit;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
@ -62,6 +63,7 @@ public class FightPlayer {
|
|||||||
public void setOut() {
|
public void setOut() {
|
||||||
isOut = true;
|
isOut = true;
|
||||||
stopEnternCountdown();
|
stopEnternCountdown();
|
||||||
|
ifAI(AI::cleanup);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startEnternCountdown() {
|
public void startEnternCountdown() {
|
||||||
@ -83,6 +85,11 @@ public class FightPlayer {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ifAI(Consumer<AI> function) {
|
||||||
|
if(!(entity instanceof Player))
|
||||||
|
function.accept(AI.getAI(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
public void ifPlayer(Consumer<Player> function) {
|
public void ifPlayer(Consumer<Player> function) {
|
||||||
if(entity instanceof Player)
|
if(entity instanceof Player)
|
||||||
function.accept((Player) entity);
|
function.accept((Player) entity);
|
||||||
|
@ -372,6 +372,8 @@ public class FightTeam {
|
|||||||
if(FightState.getFightState() == FightState.PRE_LEADER_SETUP && !Fight.getOpposite(this).isLeaderless()){
|
if(FightState.getFightState() == FightState.PRE_LEADER_SETUP && !Fight.getOpposite(this).isLeaderless()){
|
||||||
FightState.setFightState(FightState.PRE_SCHEM_SETUP);
|
FightState.setFightState(FightState.PRE_SCHEM_SETUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
leader.ifAI(ai -> setSchem(ai.chooseSchematic()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<FightPlayer> getPlayers() {
|
public Collection<FightPlayer> getPlayers() {
|
||||||
|
@ -63,6 +63,8 @@ public class JoinRequest {
|
|||||||
this.player = player;
|
this.player = player;
|
||||||
this.team = team;
|
this.team = team;
|
||||||
this.waitOnApproval = new HashSet<>(FightState.ingame() ? Fight.teams() : Collections.singleton(team));
|
this.waitOnApproval = new HashSet<>(FightState.ingame() ? Fight.teams() : Collections.singleton(team));
|
||||||
|
|
||||||
|
activeRequests.put(player, this);
|
||||||
for(FightTeam t : waitOnApproval) {
|
for(FightTeam t : waitOnApproval) {
|
||||||
FightPlayer leader = t.getLeader();
|
FightPlayer leader = t.getLeader();
|
||||||
if(leader == null)
|
if(leader == null)
|
||||||
@ -72,9 +74,12 @@ public class JoinRequest {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
leader.ifPlayer(leaderPlayer -> FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_NOTIFICATION", leaderPlayer, "REQUESTS", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/requests"), player.getName(), team.getColoredName()));
|
leader.ifPlayer(leaderPlayer -> FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_NOTIFICATION", leaderPlayer, "REQUESTS", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/requests"), player.getName(), team.getColoredName()));
|
||||||
|
leader.ifAI(ai -> {
|
||||||
|
if(ai.acceptJoinRequest(player, team))
|
||||||
|
accept(t);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
activeRequests.put(player, this);
|
|
||||||
FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_CONFIRMATION", player, ChatMessageType.ACTION_BAR);
|
FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_CONFIRMATION", player, ChatMessageType.ACTION_BAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,14 +20,10 @@
|
|||||||
package de.steamwar.fightsystem.listener;
|
package de.steamwar.fightsystem.listener;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.ArenaMode;
|
import de.steamwar.fightsystem.ArenaMode;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import de.steamwar.fightsystem.ai.AIPlayer;
|
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -47,15 +43,7 @@ public class NormalJoin implements Listener {
|
|||||||
|
|
||||||
FightTeam team = Fight.teams().stream().filter(t -> player.getUniqueId().equals(t.getDesignatedLeader())).findAny( // Player is designated leader of a team
|
FightTeam team = Fight.teams().stream().filter(t -> player.getUniqueId().equals(t.getDesignatedLeader())).findAny( // Player is designated leader of a team
|
||||||
).orElse(Fight.teams().stream().filter(t -> t.canbeLeader(player)).findAny().orElse(null)); // Else search empty team
|
).orElse(Fight.teams().stream().filter(t -> t.canbeLeader(player)).findAny().orElse(null)); // Else search empty team
|
||||||
if(team != null) {
|
if(team != null)
|
||||||
team.addMember(player);
|
team.addMember(player);
|
||||||
FightTeam aiTeam = Fight.getOpposite(team);
|
|
||||||
AIPlayer aiPlayer = new AIPlayer(SteamwarUser.get(0));
|
|
||||||
aiTeam.addMember(aiPlayer.getEntity());
|
|
||||||
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
|
|
||||||
FightState.setFightState(FightState.POST_SCHEM_SETUP);
|
|
||||||
aiTeam.setReady(true);
|
|
||||||
}, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren