Raid Phase Framework

This commit is contained in:
Aubri Seebauer committed 2023-04-02 21:50:44 -04:00
1 parent 168851ec63
commit 2cb609acc6
5 files changed
+193 -53

No files matched your search

+1
View File
@@ -5,3 +5,4 @@
.project .project
/.idea/ /.idea/
/.vscode/ /.vscode/
AlathraWar.iml
+3
View File
@@ -0,0 +1,3 @@
MaxID: 0
Raids:
@@ -1,9 +1,13 @@
package me.ShermansWorld.AlathraWar; package me.ShermansWorld.AlathraWar;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.exceptions.TownyException; import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock; import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.WorldCoord;
import me.ShermansWorld.AlathraWar.commands.RaidCommands; import me.ShermansWorld.AlathraWar.commands.RaidCommands;
import me.ShermansWorld.AlathraWar.data.RaidPhase;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -58,12 +62,12 @@ public class Raid {
private boolean side1AreRaiders; private boolean side1AreRaiders;
private boolean side2AreRaiders; private boolean side2AreRaiders;
private int id; private int id;
private int raiderPoints; private int raidScore;
private int defenderPoints;
private int MAXRAIDTICKS; private int MAXRAIDTICKS;
private Player owner; private Player owner;
private int raidTicks; private int raidTicks;
private TownBlock homeBlock; private TownBlock homeBlock;
private RaidPhase phase;
private Location townSpawn; private Location townSpawn;
int[] bukkitId; int[] bukkitId;
public ArrayList<String> raiderPlayers; public ArrayList<String> raiderPlayers;
@@ -72,7 +76,7 @@ public class Raid {
// Constructs raid for staging phase // Constructs raid for staging phase
public Raid(final int id, final War war, final Town town, final String raiders, final String defenders, public Raid(final int id, final War war, final Town town, final String raiders, final String defenders,
final boolean side1AreRaiders, final boolean side2AreRaiders) { final boolean side1AreRaiders, final boolean side2AreRaiders) {
/*
this.raidTicks = 0; this.raidTicks = 0;
this.bukkitId = new int[1]; this.bukkitId = new int[1];
this.raiderPlayers = new ArrayList<String>(); this.raiderPlayers = new ArrayList<String>();
@@ -81,11 +85,31 @@ public class Raid {
this.town = town; this.town = town;
this.raiders = raiders; this.raiders = raiders;
this.id = id; this.id = id;
*/
} }
public void start() { public void start() {
//start
this.phase = RaidPhase.START;
this.raidScore = Main.siegeData.getConfig().getInt("Raids." + String.valueOf(this.id) + ".raidscore");
this.side1AreRaiders = Main.siegeData.getConfig()
.getBoolean("Raids." + String.valueOf(this.id) + ".side1areraiders");
this.side2AreRaiders = Main.siegeData.getConfig()
.getBoolean("Raids." + String.valueOf(this.id) + ".side2areraiders");
this.MAXRAIDTICKS = 72000;
this.raidTicks = Main.siegeData.getConfig().getInt("Raids." + String.valueOf(this.id) + ".raidticks");
this.owner = Bukkit.getPlayer(Main.siegeData.getConfig().getString("Raids." + String.valueOf(this.id) + ".owner"));
if (this.side1AreRaiders) {
this.raiderPlayers = this.war.getSide1Players();
this.defenderPlayers = this.war.getSide2Players();
} else {
this.raiderPlayers = this.war.getSide2Players();
this.defenderPlayers = this.war.getSide1Players();
}
// Sets homeBlock and spawn for town. (So no mid-raid changes.) // Sets homeBlock and spawn for town. (So no mid-raid changes.)
try { try {
homeBlock = town.getHomeBlock(); homeBlock = town.getHomeBlock();
@@ -96,65 +120,136 @@ public class Raid {
// Creates 10 second looping function for Raid // Creates 10 second looping function for Raid
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) Main.getInstance(), this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) Main.getInstance(),
(Runnable) new Runnable() { (Runnable) new Runnable() {
int homeBlockControl = 0; int homeBlockControl = 0;
@Override @Override
public void run() { public void run() {
if (homeBlock != null) { if (homeBlock != null) {
town.setHomeBlock(homeBlock); town.setHomeBlock(homeBlock);
town.setSpawn(townSpawn); town.setSpawn(townSpawn);
} }
if (Raid.this.side1AreRaiders) { if (Raid.this.side1AreRaiders) {
Raid.this.raiderPlayers = Raid.this.war.getSide1Players(); Raid.this.raiderPlayers = Raid.this.war.getSide1Players();
Raid.this.defenderPlayers = Raid.this.war.getSide2Players(); Raid.this.defenderPlayers = Raid.this.war.getSide2Players();
} else {
Raid.this.raiderPlayers = Raid.this.war.getSide2Players();
Raid.this.defenderPlayers = Raid.this.war.getSide1Players();
}
if (Raid.this.raidTicks >= Raid.this.MAXRAIDTICKS) {
Bukkit.getServer().getScheduler().cancelTask(Raid.this.bukkitId[0]);
//TODO: fix raid scoring
if (Raid.this.raidScore > 750) {
Raid.this.raidersWin(Raid.this.owner);
} else { } else {
Raid.this.raiderPlayers = Raid.this.war.getSide2Players(); Raid.this.defendersWin();
Raid.this.defenderPlayers = Raid.this.war.getSide1Players();
} }
if (Raid.this.raidTicks >= Raid.this.MAXRAIDTICKS) { } else {
Bukkit.getServer().getScheduler().cancelTask(Raid.this.bukkitId[0]); final Raid this$0 = Raid.this;
if (Raid.this.raiderPoints > Raid.this.defenderPoints) { Raid.access$7(this$0, this$0.raidTicks + 200);
Raid.this.raidersWin(Raid.this.owner); Main.raidData.getConfig().set("Raids." + String.valueOf(Raid.this.id) + ".raidticks",
} else { (Object) Raid.this.raidTicks);
Raid.this.defendersWin(); Main.raidData.saveConfig();
//check and start travel phase
if (Raid.this.raidTicks >= RaidPhase.TRAVEL.startTick && Raid.this.phase != RaidPhase.TRAVEL) {
startTravel();
}
//check and start combat phase
if (Raid.this.raidTicks >= RaidPhase.COMBAT.startTick && Raid.this.phase != RaidPhase.COMBAT) {
startCombat();
}
//Raid start phase behavior
if (Raid.this.phase == RaidPhase.START) {
//update
if (Raid.this.raidTicks % 6000 == 0) {
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid of "
+ Raid.this.town.getName() + " will begin in " + (RaidPhase.TRAVEL.startTick / 20 / 60) + " minutes!");
Bukkit.broadcastMessage(
"The Raiders are gathering at " + TownyAPI.getInstance().getTownName(Raid.this.owner.getLocation()) + " before making the journey over!");
} }
} else {
final Raid this$0 = Raid.this;
Raid.access$7(this$0, this$0.raidTicks + 200);
Main.raidData.getConfig().set("Raids." + String.valueOf(Raid.this.id) + ".raidticks",
(Object) Raid.this.raidTicks);
Main.raidData.saveConfig();
}
//Raid Travel phase behavior
else if (Raid.this.phase == RaidPhase.TRAVEL) {
//Check if a player has arrived at the town (in it) and if so start combat
for(String player : raiderPlayers) {
WorldCoord playercoord = WorldCoord.parseWorldCoord(Bukkit.getPlayer(player));
if(Raid.this.town.hasTownBlock(playercoord)) {
startCombat();
}
}
}
//Raid combat phase behavior
else if (Raid.this.phase == RaidPhase.COMBAT) {
//Report
if (Raid.this.raidTicks % 6000 == 0) { if (Raid.this.raidTicks % 6000 == 0) {
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "Report on the raid of " Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "Report on the raid of "
+ Raid.this.town.getName() + ":"); + Raid.this.town.getName() + ":");
Bukkit.broadcastMessage( Bukkit.broadcastMessage(
"Raider Points - " + String.valueOf(Raid.this.raiderPoints)); "Raid Score - " + String.valueOf(Raid.this.raidScore));
Bukkit.broadcastMessage(
"Defender Points - " + String.valueOf(Raid.this.defenderPoints));
} }
} }
} }
}, 0L, 200L); }
}, 0L, 200L);
} }
// End of raid // End of raid
public void stop() { public void stop() {
Bukkit.getScheduler().cancelTask(this.bukkitId[0]); Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
RaidCommands.raids.remove(this); //im not making this rn -Aubri RaidCommands.raids.remove(this);
Main.raidData.getConfig().set("Raids." + String.valueOf(this.id), (Object) null); Main.raidData.getConfig().set("Raids." + String.valueOf(this.id), (Object) null);
Main.raidData.saveConfig(); Main.raidData.saveConfig();
} }
/**
* Begin the Gather phase of the raid
*/
private void startGather() {
Raid.this.phase = RaidPhase.GATHER;
}
/**
* Begin the Travel phase of the raid
*/
private void startTravel() {
Raid.this.phase = RaidPhase.TRAVEL;
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The Raiders of "
+ (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2())
+ " are coming to raid "
+ Raid.this.town.getName() + "!");
//in the case were not at that stage already, if this happens we have an issue
Raid.this.raidTicks = RaidPhase.TRAVEL.startTick;
}
/**
* Begin the combat phase of the raid
*/
private void startCombat() {
Raid.this.phase = RaidPhase.COMBAT;
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The Raiders of "
+ (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2())
+ " have arrived at "
+ Raid.this.town.getName() + " and the fighting has begun!");
//in the case were not at that stage already
Raid.this.raidTicks = RaidPhase.COMBAT.startTick;
}
/** /**
* Need to add call to KillsListener (defined seperate from Siege) * Need to add call to KillsListener (defined seperate from Siege)
*/ */
public void raiderKilled() { public void raiderKilled() {
//award negative score
//tp to town spawn
} }
/** /**
@@ -162,24 +257,28 @@ public class Raid {
*/ */
public void defenderKilled() { public void defenderKilled() {
//award positive score
} }
public void raidersWin(final Player owner) { public void raidersWin(final Player owner) {
stop();
} }
public void defendersWin() { public void defendersWin() {
stop();
} }
public void addPointsToRaiders(final int points) { public void addPointsToRaidScore(final int points) {
this.raiderPoints += points; this.raidScore += points;
} }
public void addPointsToDefenders(final int points) { public void subtractPointsFromRaidScore(final int points) {
this.defenderPoints += points; this.raidScore -= points;
} }
public int getID() { public int getID() {
return this.id; return this.id;
} }
@@ -220,20 +319,12 @@ public class Raid {
this.raiders = defenders; this.raiders = defenders;
} }
public int getRaiderPoints() { public int getRaidScore() {
return this.raiderPoints; return this.raidScore;
} }
public void raiderPoints(final int raiderPoints) { public void setRaidScore(final int raidScore) {
this.raiderPoints = raiderPoints; this.raidScore = raidScore;
}
public int getDefenderPoints() {
return this.defenderPoints;
}
public void defenderPoints(final int defenderPoints) {
this.defenderPoints = this.raiderPoints;
} }
public boolean getSide1AreRaiders() { public boolean getSide1AreRaiders() {
@@ -49,9 +49,8 @@ public class RaidCommands implements CommandExecutor
p.sendMessage("Town: " + raid.getTown().getName()); p.sendMessage("Town: " + raid.getTown().getName());
p.sendMessage("Raiders: " + raid.getRaiders()); p.sendMessage("Raiders: " + raid.getRaiders());
p.sendMessage("Defenders: " + raid.getDefenders()); p.sendMessage("Defenders: " + raid.getDefenders());
p.sendMessage("Raider Points: " + String.valueOf(raid.getRaiderPoints())); p.sendMessage("Raid Score: " + String.valueOf(raid.getRaidScore()));
p.sendMessage("Defender Points: " + String.valueOf(raid.getDefenderPoints())); p.sendMessage("Time Left: " + String.valueOf((72000 - Main.raidData.getConfig().getInt("Raids." + String.valueOf(String.valueOf(raid.getID()) + ".raidticks"))) / 1200) + " minutes");
p.sendMessage("Time Left: " + String.valueOf((108000 - Main.raidData.getConfig().getInt("Raids." + String.valueOf(String.valueOf(raid.getID()) + ".raidticks"))) / 1200) + " minutes");
p.sendMessage("-=-=-=-=-=-=-=-=-=-=-=-"); p.sendMessage("-=-=-=-=-=-=-=-=-=-=-=-");
} }
} else if (args[0].equalsIgnoreCase("help")) { } else if (args[0].equalsIgnoreCase("help")) {
@@ -0,0 +1,46 @@
package me.ShermansWorld.AlathraWar.data;
public enum RaidPhase {
START(0, 0),
GATHER(1, 1),
TRAVEL(2, 18000),
COMBAT(3, 24000);
//Start phase starts when the command to start a raid is ran, it allows the raiders to join, and for people to get geared up
//after 15 minutes travel phase begins, where the raiders start travelling and moving to the new town.
//no killing can occur during these two phases.
//Once at least one player has stepped into the defending town, or 5 min have passed during the travel phase,
//the combat begins and lasts 40 minutes.
public final int id;
public final int startTick;
private RaidPhase(int id, int startTick) {
this.id = id;
this.startTick = startTick;
}
/**
* Grabs the phase by name, ignores case
* @param name
* @return
*/
public static RaidPhase getByName(String name) {
for(RaidPhase p : RaidPhase.values()) {
if(p.name().equalsIgnoreCase(name)) return p;
}
return null;
}
/**
* Grabs phase by id number for easy storage reading
* @param id
* @return
*/
public static RaidPhase getByID(int id) {
for(RaidPhase p : RaidPhase.values()) {
if(p.id == id) return p;
}
return null;
}
}