mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-02 17:00:19 +01:00
Recoded floor / finish system
This commit is contained in:
parent
4f4fa877cf
commit
a01e18b0c7
@ -181,6 +181,7 @@ public enum DMessages implements Messages {
|
|||||||
PLAYER_DEATH("Player_Death", "&4&v1 &6died and has &4&v2 &6lives left."),
|
PLAYER_DEATH("Player_Death", "&4&v1 &6died and has &4&v2 &6lives left."),
|
||||||
PLAYER_DEATH_KICK("Player_DeathKick", "&2&v1 &6lost his last life and was kicked."),
|
PLAYER_DEATH_KICK("Player_DeathKick", "&2&v1 &6lost his last life and was kicked."),
|
||||||
PLAYER_FINISHED_DUNGEON("Player_FinishedDungeon", "&6You successfully finished the dungeon!"),
|
PLAYER_FINISHED_DUNGEON("Player_FinishedDungeon", "&6You successfully finished the dungeon!"),
|
||||||
|
PLAYER_FINISHED_FLOOR("Player_Finished_Floor", "&6You successfully finished the floor."),
|
||||||
PLAYER_INVITED("Player_Invited", "&4&v1&6 invited you to the group &4&v2&6."),
|
PLAYER_INVITED("Player_Invited", "&4&v1&6 invited you to the group &4&v2&6."),
|
||||||
PLAYER_UNINVITED("Player_Uninvited", "&4&v1&6 took back your invitation to the group &4&v2&6."),
|
PLAYER_UNINVITED("Player_Uninvited", "&4&v1&6 took back your invitation to the group &4&v2&6."),
|
||||||
PLAYER_JOIN_GROUP("Player_JoinGroup", "&6You successfully joined the group!"),
|
PLAYER_JOIN_GROUP("Player_JoinGroup", "&6You successfully joined the group!"),
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.dre2n.dungeonsxl.event.dgroup;
|
package io.github.dre2n.dungeonsxl.event.dgroup;
|
||||||
|
|
||||||
|
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
||||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@ -28,8 +29,26 @@ public class DGroupFinishDungeonEvent extends DGroupEvent implements Cancellable
|
|||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
public DGroupFinishDungeonEvent(DGroup dGroup) {
|
private Dungeon dungeon;
|
||||||
|
|
||||||
|
public DGroupFinishDungeonEvent(Dungeon dungeon, DGroup dGroup) {
|
||||||
super(dGroup);
|
super(dGroup);
|
||||||
|
this.dungeon = dungeon;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the dungeon
|
||||||
|
*/
|
||||||
|
public Dungeon getDungeon() {
|
||||||
|
return dungeon;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param dungeon
|
||||||
|
* the dungeon to set
|
||||||
|
*/
|
||||||
|
public void setDisbander(Dungeon dungeon) {
|
||||||
|
this.dungeon = dungeon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,6 +18,7 @@ package io.github.dre2n.dungeonsxl.event.dgroup;
|
|||||||
|
|
||||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||||
import io.github.dre2n.dungeonsxl.world.DGameWorld;
|
import io.github.dre2n.dungeonsxl.world.DGameWorld;
|
||||||
|
import io.github.dre2n.dungeonsxl.world.DResourceWorld;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
@ -30,9 +31,9 @@ public class DGroupFinishFloorEvent extends DGroupEvent implements Cancellable {
|
|||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
private DGameWorld finished;
|
private DGameWorld finished;
|
||||||
private String next;
|
private DResourceWorld next;
|
||||||
|
|
||||||
public DGroupFinishFloorEvent(DGroup dGroup, DGameWorld finished, String next) {
|
public DGroupFinishFloorEvent(DGroup dGroup, DGameWorld finished, DResourceWorld next) {
|
||||||
super(dGroup);
|
super(dGroup);
|
||||||
this.finished = finished;
|
this.finished = finished;
|
||||||
this.next = next;
|
this.next = next;
|
||||||
@ -56,15 +57,15 @@ public class DGroupFinishFloorEvent extends DGroupEvent implements Cancellable {
|
|||||||
/**
|
/**
|
||||||
* @return the next
|
* @return the next
|
||||||
*/
|
*/
|
||||||
public String getNext() {
|
public DResourceWorld getNext() {
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param next
|
* @param next
|
||||||
* the name of the DGameWorld to set
|
* the resource to set
|
||||||
*/
|
*/
|
||||||
public void setNext(String next) {
|
public void setNext(DResourceWorld next) {
|
||||||
this.next = next;
|
this.next = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,30 +28,13 @@ public class DGamePlayerFinishEvent extends DGamePlayerEvent implements Cancella
|
|||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
private boolean first;
|
|
||||||
private boolean hasToWait;
|
private boolean hasToWait;
|
||||||
|
|
||||||
public DGamePlayerFinishEvent(DGamePlayer dPlayer, boolean first, boolean hasToWait) {
|
public DGamePlayerFinishEvent(DGamePlayer dPlayer, boolean hasToWait) {
|
||||||
super(dPlayer);
|
super(dPlayer);
|
||||||
this.first = first;
|
|
||||||
this.hasToWait = hasToWait;
|
this.hasToWait = hasToWait;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the first
|
|
||||||
*/
|
|
||||||
public boolean isFirst() {
|
|
||||||
return first;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param first
|
|
||||||
* the first to set
|
|
||||||
*/
|
|
||||||
public void setFirst(boolean first) {
|
|
||||||
this.first = first;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the hasToWait
|
* @return the hasToWait
|
||||||
*/
|
*/
|
||||||
|
@ -95,6 +95,7 @@ public class Game {
|
|||||||
tutorial = false;
|
tutorial = false;
|
||||||
started = false;
|
started = false;
|
||||||
world = resource.instantiateAsGameWorld();
|
world = resource.instantiateAsGameWorld();
|
||||||
|
world.setType(DGameWorld.Type.START_FLOOR);
|
||||||
|
|
||||||
dGroups.add(dGroup);
|
dGroups.add(dGroup);
|
||||||
dGroup.setGameWorld(world);
|
dGroup.setGameWorld(world);
|
||||||
|
@ -16,14 +16,10 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.dre2n.dungeonsxl.player;
|
package io.github.dre2n.dungeonsxl.player;
|
||||||
|
|
||||||
import io.github.dre2n.commons.util.NumberUtil;
|
|
||||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||||
import io.github.dre2n.commons.util.playerutil.PlayerUtil;
|
import io.github.dre2n.commons.util.playerutil.PlayerUtil;
|
||||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||||
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
|
|
||||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishDungeonEvent;
|
|
||||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupRewardEvent;
|
|
||||||
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent;
|
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent;
|
||||||
import io.github.dre2n.dungeonsxl.event.dplayer.instance.DInstancePlayerUpdateEvent;
|
import io.github.dre2n.dungeonsxl.event.dplayer.instance.DInstancePlayerUpdateEvent;
|
||||||
import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerDeathEvent;
|
import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerDeathEvent;
|
||||||
@ -737,79 +733,34 @@ public class DGamePlayer extends DInstancePlayer {
|
|||||||
* the name of the next floor
|
* the name of the next floor
|
||||||
*/
|
*/
|
||||||
public void finishFloor(DResourceWorld specifiedFloor) {
|
public void finishFloor(DResourceWorld specifiedFloor) {
|
||||||
MessageUtil.sendMessage(getPlayer(), DMessages.PLAYER_FINISHED_DUNGEON.getMessage());
|
if (!dGroup.getDungeon().isMultiFloor()) {
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageUtil.sendMessage(getPlayer(), DMessages.PLAYER_FINISHED_FLOOR.getMessage());
|
||||||
finished = true;
|
finished = true;
|
||||||
|
|
||||||
|
boolean hasToWait = false;
|
||||||
if (getDGroup() == null) {
|
if (getDGroup() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dGroup.isPlaying()) {
|
if (!dGroup.isPlaying()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dGroup.setNextFloor(specifiedFloor);
|
dGroup.setNextFloor(specifiedFloor);
|
||||||
|
if (dGroup.isFinished()) {
|
||||||
for (Player player : dGroup.getPlayers()) {
|
dGroup.finishFloor(specifiedFloor);
|
||||||
DGamePlayer dPlayer = getByPlayer(player);
|
} else {
|
||||||
if (!dPlayer.finished) {
|
MessageUtil.sendMessage(player, DMessages.PLAYER_WAIT_FOR_OTHER_PLAYERS.getMessage());
|
||||||
MessageUtil.sendMessage(this.getPlayer(), DMessages.PLAYER_WAIT_FOR_OTHER_PLAYERS.getMessage());
|
hasToWait = true;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean invalid = !dGroup.getDungeon().isMultiFloor();
|
DGamePlayerFinishEvent dPlayerFinishEvent = new DGamePlayerFinishEvent(this, hasToWait);
|
||||||
|
plugin.getServer().getPluginManager().callEvent(dPlayerFinishEvent);
|
||||||
for (Player player : dGroup.getPlayers()) {
|
if (dPlayerFinishEvent.isCancelled()) {
|
||||||
DGamePlayer dPlayer = getByPlayer(player);
|
finished = false;
|
||||||
|
|
||||||
if (invalid) {
|
|
||||||
dPlayer.finish(false);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
dPlayer.finished = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (invalid) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DungeonConfig dConfig = dGroup.getDungeon().getConfig();
|
|
||||||
int random = NumberUtil.generateRandomInt(0, dConfig.getFloors().size());
|
|
||||||
DResourceWorld newFloor = dGroup.getUnplayedFloors().get(random);
|
|
||||||
if (dConfig.getFloorCount() == dGroup.getFloorCount() - 1) {
|
|
||||||
newFloor = dConfig.getEndFloor();
|
|
||||||
|
|
||||||
} else if (specifiedFloor != null) {
|
|
||||||
newFloor = specifiedFloor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*DGroupFinishFloorEvent event = new DGroupFinishFloorEvent(dGroup, dGroup.getGameWorld(), newFloor);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
Game game = dGroup.getGameWorld().getGame();
|
|
||||||
|
|
||||||
dGroup.removeUnplayedFloor(dGroup.getGameWorld().getResource(), false);
|
|
||||||
|
|
||||||
DGameWorld gameWorld = null;
|
|
||||||
if (newFloor != null) {
|
|
||||||
gameWorld = newFloor.instantiateAsGameWorld();
|
|
||||||
}
|
|
||||||
dGroup.setGameWorld(gameWorld);
|
|
||||||
|
|
||||||
for (Player player : dGroup.getPlayers()) {
|
|
||||||
DGamePlayer dPlayer = getByPlayer(player);
|
|
||||||
dPlayer.setWorld(gameWorld.getWorld());
|
|
||||||
dPlayer.setCheckpoint(dGroup.getGameWorld().getStartLocation(dGroup));
|
|
||||||
if (dPlayer.getWolf() != null) {
|
|
||||||
dPlayer.getWolf().teleport(dPlayer.getCheckpoint());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dGroup.startGame(game);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -829,60 +780,23 @@ public class DGamePlayer extends DInstancePlayer {
|
|||||||
}
|
}
|
||||||
finished = true;
|
finished = true;
|
||||||
|
|
||||||
if (getDGroup() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dGroup.isPlaying()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean first = true;
|
|
||||||
boolean hasToWait = false;
|
boolean hasToWait = false;
|
||||||
|
if (!getDGroup().isPlaying()) {
|
||||||
for (Player player : dGroup.getPlayers()) {
|
return;
|
||||||
DGamePlayer dPlayer = getByPlayer(player);
|
}
|
||||||
if (!dPlayer.finished) {
|
if (dGroup.isFinished()) {
|
||||||
if (message) {
|
dGroup.finish();
|
||||||
MessageUtil.sendMessage(this.getPlayer(), DMessages.PLAYER_WAIT_FOR_OTHER_PLAYERS.getMessage());
|
} else {
|
||||||
}
|
if (message) {
|
||||||
hasToWait = true;
|
MessageUtil.sendMessage(this.getPlayer(), DMessages.PLAYER_WAIT_FOR_OTHER_PLAYERS.getMessage());
|
||||||
|
|
||||||
} else if (dPlayer != this) {
|
|
||||||
first = false;
|
|
||||||
}
|
}
|
||||||
|
hasToWait = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DGamePlayerFinishEvent dPlayerFinishEvent = new DGamePlayerFinishEvent(this, first, hasToWait);
|
DGamePlayerFinishEvent dPlayerFinishEvent = new DGamePlayerFinishEvent(this, hasToWait);
|
||||||
|
plugin.getServer().getPluginManager().callEvent(dPlayerFinishEvent);
|
||||||
if (dPlayerFinishEvent.isCancelled()) {
|
if (dPlayerFinishEvent.isCancelled()) {
|
||||||
finished = false;
|
finished = false;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasToWait) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DGroupFinishDungeonEvent dGroupFinishDungeonEvent = new DGroupFinishDungeonEvent(dGroup);
|
|
||||||
|
|
||||||
if (dGroupFinishDungeonEvent.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Game.getByDGroup(dGroup).resetWaveKills();
|
|
||||||
|
|
||||||
DGroupRewardEvent dGroupRewardEvent = new DGroupRewardEvent(dGroup);
|
|
||||||
plugin.getServer().getPluginManager().callEvent(dGroupRewardEvent);
|
|
||||||
for (Player player : dGroup.getPlayers()) {
|
|
||||||
DGamePlayer dPlayer = getByPlayer(player);
|
|
||||||
dPlayer.leave(false);
|
|
||||||
|
|
||||||
if (!dGroupRewardEvent.isCancelled()) {
|
|
||||||
for (Reward reward : dGroup.getRewards()) {
|
|
||||||
reward.giveTo(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,11 +16,16 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.dre2n.dungeonsxl.player;
|
package io.github.dre2n.dungeonsxl.player;
|
||||||
|
|
||||||
|
import io.github.dre2n.commons.util.NumberUtil;
|
||||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||||
|
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
|
||||||
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
||||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupDisbandEvent;
|
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupDisbandEvent;
|
||||||
|
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishDungeonEvent;
|
||||||
|
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishFloorEvent;
|
||||||
|
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupRewardEvent;
|
||||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupStartFloorEvent;
|
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupStartFloorEvent;
|
||||||
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerJoinDGroupEvent;
|
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerJoinDGroupEvent;
|
||||||
import io.github.dre2n.dungeonsxl.event.requirement.RequirementDemandEvent;
|
import io.github.dre2n.dungeonsxl.event.requirement.RequirementDemandEvent;
|
||||||
@ -117,7 +122,7 @@ public class DGroup {
|
|||||||
dungeon = plugin.getDungeons().getByName(identifier);
|
dungeon = plugin.getDungeons().getByName(identifier);
|
||||||
if (multiFloor && dungeon != null) {
|
if (multiFloor && dungeon != null) {
|
||||||
// Real dungeon
|
// Real dungeon
|
||||||
unplayedFloors = dungeon.getConfig().getFloors();
|
unplayedFloors = new ArrayList<>(dungeon.getConfig().getFloors());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Artificial dungeon
|
// Artificial dungeon
|
||||||
@ -155,7 +160,7 @@ public class DGroup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dungeon = dungeon;
|
setDungeon(dungeon);
|
||||||
playing = false;
|
playing = false;
|
||||||
floorCount = 0;
|
floorCount = 0;
|
||||||
}
|
}
|
||||||
@ -407,11 +412,16 @@ public class DGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Sets up all dungeon-related fields.
|
||||||
|
*
|
||||||
* @param dungeon
|
* @param dungeon
|
||||||
* the dungeon to set
|
* the dungeon to set
|
||||||
*/
|
*/
|
||||||
public void setDungeon(Dungeon dungeon) {
|
public void setDungeon(Dungeon dungeon) {
|
||||||
this.dungeon = dungeon;
|
this.dungeon = dungeon;
|
||||||
|
if (dungeon.isMultiFloor()) {
|
||||||
|
unplayedFloors = new ArrayList<>(dungeon.getConfig().getFloors());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -644,7 +654,92 @@ public class DGroup {
|
|||||||
this.lives = lives;
|
this.lives = lives;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if all players are finished
|
||||||
|
*/
|
||||||
|
public boolean isFinished() {
|
||||||
|
for (DGamePlayer dPlayer : getDGamePlayers()) {
|
||||||
|
if (!dPlayer.isFinished()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* Actions */
|
/* Actions */
|
||||||
|
/**
|
||||||
|
* The group finishs the dungeon.
|
||||||
|
*/
|
||||||
|
public void finish() {
|
||||||
|
DGroupFinishDungeonEvent dGroupFinishDungeonEvent = new DGroupFinishDungeonEvent(dungeon, this);
|
||||||
|
plugin.getServer().getPluginManager().callEvent(dGroupFinishDungeonEvent);
|
||||||
|
if (dGroupFinishDungeonEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game.getByDGroup(this).resetWaveKills();
|
||||||
|
DGroupRewardEvent dGroupRewardEvent = new DGroupRewardEvent(this);
|
||||||
|
plugin.getServer().getPluginManager().callEvent(dGroupRewardEvent);
|
||||||
|
for (DGamePlayer player : getDGamePlayers()) {
|
||||||
|
player.leave(false);
|
||||||
|
if (!dGroupRewardEvent.isCancelled()) {
|
||||||
|
for (Reward reward : rewards) {
|
||||||
|
reward.giveTo(player.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The group finishs the current floor.
|
||||||
|
*
|
||||||
|
* @param specifiedFloor
|
||||||
|
* the name of the next floor
|
||||||
|
*/
|
||||||
|
public void finishFloor(DResourceWorld specifiedFloor) {
|
||||||
|
DungeonConfig dConfig = dungeon.getConfig();
|
||||||
|
int floorsLeft = getUnplayedFloors().size();
|
||||||
|
DResourceWorld newFloor = null;
|
||||||
|
DGameWorld.Type type = null;
|
||||||
|
if (gameWorld.getType() == DGameWorld.Type.END_FLOOR) {
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
} else if (specifiedFloor != null) {
|
||||||
|
newFloor = specifiedFloor;
|
||||||
|
type = DGameWorld.Type.DEFAULT;
|
||||||
|
} else if (floorsLeft > 0) {
|
||||||
|
int random = NumberUtil.generateRandomInt(0, floorsLeft);
|
||||||
|
newFloor = getUnplayedFloors().get(random);
|
||||||
|
type = DGameWorld.Type.DEFAULT;
|
||||||
|
} else {
|
||||||
|
newFloor = dConfig.getEndFloor();
|
||||||
|
type = DGameWorld.Type.END_FLOOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
DGroupFinishFloorEvent event = new DGroupFinishFloorEvent(this, gameWorld, newFloor);
|
||||||
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game game = gameWorld.getGame();
|
||||||
|
removeUnplayedFloor(gameWorld.getResource(), false);
|
||||||
|
DGameWorld gameWorld = newFloor.instantiateAsGameWorld();
|
||||||
|
gameWorld.setType(type);
|
||||||
|
this.gameWorld = gameWorld;
|
||||||
|
game.setWorld(gameWorld);
|
||||||
|
|
||||||
|
for (DGamePlayer player : getDGamePlayers()) {
|
||||||
|
player.setWorld(gameWorld.getWorld());
|
||||||
|
player.setCheckpoint(gameWorld.getStartLocation(this));
|
||||||
|
if (player.getWolf() != null) {
|
||||||
|
player.getWolf().teleport(player.getCheckpoint());
|
||||||
|
}
|
||||||
|
player.setFinished(false);
|
||||||
|
}
|
||||||
|
startGame(game);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the group from the List
|
* Remove the group from the List
|
||||||
*/
|
*/
|
||||||
@ -810,23 +905,6 @@ public class DGroup {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean finishIfMembersFinished() {
|
|
||||||
boolean finish = true;
|
|
||||||
|
|
||||||
for (DGamePlayer dPlayer : getDGamePlayers()) {
|
|
||||||
if (!dPlayer.isFinished()) {
|
|
||||||
finish = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (finish && getDGamePlayers().size() > 0) {
|
|
||||||
getDGamePlayers().get(0).finishFloor(nextFloor);
|
|
||||||
}
|
|
||||||
|
|
||||||
return finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to all players in the group
|
* Send a message to all players in the group
|
||||||
*/
|
*/
|
||||||
|
@ -73,9 +73,17 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
*/
|
*/
|
||||||
public class DGameWorld extends DInstanceWorld {
|
public class DGameWorld extends DInstanceWorld {
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
START_FLOOR,
|
||||||
|
END_FLOOR,
|
||||||
|
DEFAULT
|
||||||
|
}
|
||||||
|
|
||||||
Game game;
|
Game game;
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
|
private Type type = Type.DEFAULT;
|
||||||
|
|
||||||
private boolean isPlaying = false;
|
private boolean isPlaying = false;
|
||||||
|
|
||||||
// TO DO: Which lists actually need to be CopyOnWriteArrayLists?
|
// TO DO: Which lists actually need to be CopyOnWriteArrayLists?
|
||||||
@ -119,6 +127,22 @@ public class DGameWorld extends DInstanceWorld {
|
|||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
* the type of the floor
|
||||||
|
*/
|
||||||
|
public Type getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param type
|
||||||
|
* the type to set
|
||||||
|
*/
|
||||||
|
public void setType(Type type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the isPlaying
|
* @return the isPlaying
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user