Raid Death behavior

This commit is contained in:
Aubri Seebauer committed 2023-04-03 15:23:42 -04:00
1 parent e65bae6f67
commit d6e5518c1e
4 files changed
+184 -24

No files matched your search

@@ -10,6 +10,7 @@ import me.ShermansWorld.AlathraWar.data.RaidPhase;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
@@ -30,19 +31,20 @@ and raided players may run out of the town, forfeiting the cost of the raid.
The raid is split into two phases:
- STAGING PHASE
- Raiders collect at raiding town, joining raid through command
- Defenders are given time to get to the town.
v/ Raiders collect at raiding town, joining raid through command
v/ Defenders are given time to get to the town. (travel is announced way in ahead)
- COMBAT PHASE
- Raiders go to town
v/ Raiders go to town
- Combat occurs
- Decides outcome of raid
TODO LIST:
- No teleporting by raiders
- Points management
- Both sides gain points for kills
- Raiders gain points for
- Raiders on death are teleported to their town spawn.
v/ Points management
v/ Raider death is negative score
v/ Defender death is positive score
- TODO Raiders gain points for
v/ Raiders on death are teleported to their town spawn.
*/
/**
@@ -62,7 +64,6 @@ public class Raid {
private boolean side2AreRaiders;
private int id;
private int raidScore;
private int MAXRAIDTICKS;
private Player owner;
private int raidTicks;
private TownBlock homeBlockRaided;
@@ -102,7 +103,6 @@ public class Raid {
.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"));
@@ -145,8 +145,9 @@ public class Raid {
Raid.this.raiderPlayers = Raid.this.war.getSide2Players();
Raid.this.defenderPlayers = Raid.this.war.getSide1Players();
}
if (Raid.this.raidTicks >= Raid.this.MAXRAIDTICKS) {
if (Raid.this.raidTicks >= RaidPhase.END.startTick) {
Bukkit.getServer().getScheduler().cancelTask(Raid.this.bukkitId[0]);
Raid.this.phase = RaidPhase.END;
//TODO: fix raid scoring
if (Raid.this.raidScore > 750) {
Raid.this.raidersWin(Raid.this.owner);
@@ -221,6 +222,7 @@ public class Raid {
// End of raid
public void stop() {
this.phase = RaidPhase.END;
Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
RaidCommands.raids.remove(this);
Main.raidData.getConfig().set("Raids." + String.valueOf(this.id), (Object) null);
@@ -263,28 +265,132 @@ public class Raid {
/**
* Need to add call to KillsListener (defined seperate from Siege)
*/
public void raiderKilled() {
public void raiderKilledInCombat(PlayerDeathEvent event) {
//award negative score
this.subtractPointsFromRaidScore(20);
for (final String playerName : this.getActiveRaiders()) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed! -40 Raid Score");
}
catch (NullPointerException ex3) {}
}
for (final String playerName : this.getDefenderPlayers()) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed! -20 Raid Score");
}
catch (NullPointerException ex4) {}
}
//tp to town spawn
//tp to gather town spawn
final Player killed = event.getEntity();
if(this.getActiveRaiders().contains(killed.getName())) {
try {
killed.teleport(this.getGatherTown().getSpawn());
killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died raiding and have been teleported back to the gather point.");
} catch (TownyException e) {
throw new RuntimeException(e);
}
}
}
/**
* Need to add call to KillsListener (defined seperate from Siege)
*/
public void defenderKilled() {
public void defenderKilledInCombat(PlayerDeathEvent event) {
this.addPointsToRaidScore(20);
for (final String playerName : this.getActiveRaiders()) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! +20 Raid Score");
}
catch (NullPointerException ex5) {}
}
for (final String playerName : this.getDefenderPlayers()) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! +20 Raid Score");
}
catch (NullPointerException ex6) {}
}
//award positive score
//tp to raid town spawn
final Player killed = event.getEntity();
if(this.getActiveRaiders().contains(killed.getName())) {
try {
killed.teleport(this.getGatherTown().getSpawn());
killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died raiding and have been teleported back to your town's spawn.");
} catch (TownyException e) {
throw new RuntimeException(e);
}
}
}
/**
* Need to add call to KillsListener (defined seperate from Siege)
*/
public void raiderKilledOutofCombat(PlayerDeathEvent event) {
//award negative score
for (final String playerName : this.getActiveRaiders()) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed before combat, no points awarded and death treated normally.");
}
catch (NullPointerException ex3) {}
}
for (final String playerName : this.getDefenderPlayers()) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed before combat, no points awarded and death treated normally.");
}
catch (NullPointerException ex4) {}
}
//tp to gather town spawn
final Player killed = event.getEntity();
if(this.getActiveRaiders().contains(killed.getName())) {
try {
killed.teleport(this.getGatherTown().getSpawn());
killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died before raiding and have been teleported back to the gather point.");
} catch (TownyException e) {
throw new RuntimeException(e);
}
}
}
/**
* Need to add call to KillsListener (defined seperate from Siege)
*/
public void defenderKilledOutofCombat(PlayerDeathEvent event) {
for (final String playerName : this.getActiveRaiders()) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed before combat, no points awarded and death treated normally.");
}
catch (NullPointerException ex5) {}
}
for (final String playerName : this.getDefenderPlayers()) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed before combat, no points awarded and death treated normally.");
}
catch (NullPointerException ex6) {}
}
//tp to raid town spawn
final Player killed = event.getEntity();
if(this.getActiveRaiders().contains(killed.getName())) {
try {
killed.teleport(this.getGatherTown().getSpawn());
killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died before being raided and have been teleported back to your town's spawn.");
} catch (TownyException e) {
throw new RuntimeException(e);
}
}
}
public void raidersWin(final Player owner) {
//TODO
stop();
}
public void defendersWin() {
//TODO
stop();
}
@@ -292,12 +292,15 @@ public class RaidCommands implements CommandExecutor
//if we find the raid
if(raidFound) {
if(raid.getPhase() == RaidPhase.GATHER) {
//check if gather phase
if(raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START) {
if(raid.getGatherTown().hasTownBlock(WorldCoord.parseWorldCoord(p))) {
raid.addActiveRaider(p.getName());
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
}
} else {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot join the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
}
}
}
@@ -4,7 +4,8 @@ public enum RaidPhase {
START(0, 0),
GATHER(1, 1),
TRAVEL(2, 18000),
COMBAT(3, 24000);
COMBAT(3, 24000),
END(4, 72000);
//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.
@@ -1,5 +1,8 @@
package me.ShermansWorld.AlathraWar.listeners;
import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.commands.RaidCommands;
import me.ShermansWorld.AlathraWar.data.RaidPhase;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Inventory;
import org.bukkit.command.CommandSender;
@@ -36,15 +39,16 @@ public final class KillsListener implements Listener
town = WorldCoord.parseWorldCoord((Entity)killed).getTownBlock().getTown();
}
catch (NotRegisteredException ex2) {}
boolean playerCloseToHomeBlock = false;
boolean playerCloseToHomeBlockSiege = false;
boolean playerCloseToHomeBlockRaid = false;
try {
for (final Siege siege : SiegeCommands.sieges) {
final int homeBlockXCoord = siege.getTown().getHomeBlock().getCoord().getX() * 16;
final int homeBlockZCoord = siege.getTown().getHomeBlock().getCoord().getZ() * 16;
if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoord) <= 300 && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoord) <= 300) {
playerCloseToHomeBlock = true;
playerCloseToHomeBlockSiege = true;
}
if (siege.getAttackerPlayers().contains(killer.getName()) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlock)) {
if (siege.getAttackerPlayers().contains(killer.getName()) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlockSiege)) {
if (siege.getDefenderPlayers().contains(killed.getName())) {
siege.addPointsToAttackers(20);
for (final String playerName : siege.getAttackerPlayers()) {
@@ -63,7 +67,7 @@ public final class KillsListener implements Listener
this.siegeKill(killed, event);
return;
}
if (siege.getDefenderPlayers().contains(killer.getName()) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlock)) {
if (siege.getDefenderPlayers().contains(killer.getName()) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlockSiege)) {
if (siege.getAttackerPlayers().contains(killed.getName())) {
siege.addPointsToDefenders(20);
for (final String playerName : siege.getAttackerPlayers()) {
@@ -82,16 +86,62 @@ public final class KillsListener implements Listener
this.siegeKill(killed, event);
return;
}
if ( (town != null && town.equals(siege.getTown()) || playerCloseToHomeBlock) ) {
if ( (town != null && town.equals(siege.getTown()) || playerCloseToHomeBlockSiege) ) {
this.siegeKill(killed, event);
}
}
//Raid logic
for (final Raid raid : RaidCommands.raids) {
final int homeBlockXCoordRaided = raid.getRaidedTown().getHomeBlock().getCoord().getX() * 16;
final int homeBlockZCoordRaided = raid.getRaidedTown().getHomeBlock().getCoord().getZ() * 16;
// final int homeBlockXCoordGather = raid.getGatherTown().getHomeBlock().getCoord().getX() * 16;
// final int homeBlockZCoordGather = raid.getGatherTown().getHomeBlock().getCoord().getZ() * 16;
if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoordRaided) <= 300 && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoordRaided) <= 300) {
playerCloseToHomeBlockRaid = true;
}
if (raid.getActiveRaiders().contains(killer.getName()) && ((town != null && town.equals(raid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
if(raid.getPhase() == RaidPhase.COMBAT) {
if (raid.getDefenderPlayers().contains(killed.getName())) {
raid.defenderKilledInCombat(event);
}
this.siegeKill(killed, event);
return;
} else {
raid.defenderKilledOutofCombat(event);
}
}
if (raid.getDefenderPlayers().contains(killer.getName()) && ((town != null && town.equals(raid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
if(raid.getPhase() == RaidPhase.COMBAT) {
if (raid.getActiveRaiders().contains(killed.getName())) {
raid.raiderKilledInCombat(event);
}
this.siegeKill(killed, event);
return;
} else {
raid.raiderKilledOutofCombat(event);
}
}
if ( (town != null && town.equals(raid.getRaidedTown()) || playerCloseToHomeBlockRaid) ) {
this.siegeKill(killed, event);
}
}
}
catch (NullPointerException | TownyException ex7) {
}
}
/**
* Damage all gear held by the player, and then send them to spawn
* They don't lose items from death.
* @param killed
* @param event
*/
private void siegeKill(final Player killed, final PlayerDeathEvent event) {
final Inventory inv = (Inventory)killed.getInventory();
for (int i = 0; i < inv.getSize(); ++i) {