Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft : Capture the flag #44

Open
wants to merge 25 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d1d3c67
Début du jeu CTF
orwenn22 Sep 12, 2023
d55bc11
CTF : amélioration code
orwenn22 Sep 13, 2023
847be56
CTF : ramener drapeau adverse à sa base
orwenn22 Sep 13, 2023
d778031
CTF : scoreboard avec les scores
orwenn22 Sep 13, 2023
dfaae9a
CTF : retirer commentaire TODO
orwenn22 Sep 13, 2023
b42becd
CTF : rendre le jeu gagnable
orwenn22 Sep 14, 2023
0b642b7
CTF : effet de glow
orwenn22 Sep 14, 2023
2aeb53d
CTF : drop le drapeau au sol
orwenn22 Sep 14, 2023
1338ead
CTF : cercles autour des spawns de drapeaux
orwenn22 Sep 15, 2023
9d16ab1
CTF : renommer teams en français
orwenn22 Sep 15, 2023
a60fda6
CTF:Ne pas drop le drapeau si joueur meurt dans le vide
orwenn22 Sep 16, 2023
ab41249
CTF : 8 joueurs max dans la game
orwenn22 Sep 17, 2023
5905c6e
CTF : amélioration check si le joueur casse son propre drapeau
orwenn22 Sep 17, 2023
a6a7ab4
CTF : ajouter killzone
orwenn22 Oct 1, 2023
a3f9f41
CTF : suivre la position des drapeaux
orwenn22 Oct 1, 2023
f1d5223
CTF: toujours drop le drapeau sur un block solide
orwenn22 Nov 9, 2023
ac3a4cf
CTF: amélioration drop drapeau
orwenn22 Nov 9, 2023
0c50291
CTF : utiliser TeamWin pour définir les vainqueurs
orwenn22 Dec 14, 2023
2401c97
Merge remote-tracking branch 'origin/dev' into CTF
orwenn22 Dec 14, 2023
39bde86
CTF : typo belowBock -> belowBlock
orwenn22 Dec 15, 2023
8183c2c
CTF : game_points -> gamePoint
orwenn22 Dec 15, 2023
211a8ef
CTF : belowBlock
orwenn22 Dec 15, 2023
4459613
CTF : ne pas utiliser le snake case dans initFlags
orwenn22 Dec 15, 2023
585eb48
CTF : Ne pas hardcoder les positions dans l'inventaire
orwenn22 Jan 5, 2024
e550b48
CTF : Gérer les particules dans une classe séparé
orwenn22 Jan 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions games/ctf/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription

plugins {
`java-library`
id("net.minecrell.plugin-yml.bukkit") version "0.5.2" // Generates plugin.yml
}

dependencies {
implementation(project(":core"))

compileOnly("io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT")

compileOnly("fr.efreicraft:ECATUP:latest.integration")
}

bukkit {
load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD
name = "LudosCTF"
main = "fr.efreicraft.ludos.games.ctf.Main"
apiVersion = "1.19"
authors = listOf("Ewenn BAUDET")
prefix = "CTF"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package fr.efreicraft.ludos.games.ctf;

import fr.efreicraft.ludos.core.Core;
import fr.efreicraft.ludos.core.players.LudosPlayer;
import fr.efreicraft.ludos.core.utils.MessageUtils;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerDropItemEvent;

public record EventListener(GameLogic ctfLogic) implements Listener {
JiveOff marked this conversation as resolved.
Show resolved Hide resolved
@EventHandler
public void onPlayerDrop(PlayerDropItemEvent event) {
event.setCancelled(true);
}

@EventHandler
public void onPlayerBreakBlock(BlockBreakEvent event) {
LudosPlayer ludos_player = Core.get().getPlayerManager().getPlayer(event.getPlayer());

String team_to_check = ""; //on doit vérifier si le joueur n'appartient pas à cette team avant de casser le drapeau
JiveOff marked this conversation as resolved.
Show resolved Hide resolved

switch (event.getBlock().getBlockData().getMaterial()) {
case RED_BANNER -> team_to_check = "RED";
case BLUE_BANNER -> team_to_check = "BLUE";
default -> {
event.setCancelled(true);
return;
}
}

//Vérifier si le joueur n'essaie pas de casser le drapeau de sa propre équipe
if(Core.get().getTeamManager().getTeam(team_to_check).getPlayers().contains(ludos_player)) {
ludos_player.sendMessage(
MessageUtils.ChatPrefix.GAME,
"Tu ne peux pas récupérer ton propre drapeau !"
);
event.setCancelled(true);
return;
}

ludos_player.sendMessage(
MessageUtils.ChatPrefix.GAME,
"Tu as récupéré le drapeau adverse !"
);

//TODO : stocker les joueurs possédants les drapeaux dans GameLogic


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package fr.efreicraft.ludos.games.ctf;

import fr.efreicraft.ludos.core.players.LudosPlayer;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

public class GameLogic {
public Location redLocation;
public Location blueLocation;

public int scoreTeamRed;
public int scoreTeamBlue;
JiveOff marked this conversation as resolved.
Show resolved Hide resolved

public GameLogic() {
redLocation = null;
blueLocation = null;

scoreTeamRed = 0;
scoreTeamBlue = 0;
}
JiveOff marked this conversation as resolved.
Show resolved Hide resolved

//Faire apparaître les drapeaux sur la map, et stocker leurs positions
public void initFlags(Location red_location, Location blue_location) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Généralement, on essaye de privilégier un seul casing pour les arguments de méthodes, il faut donc éviter le snake case occasionnel.

redLocation = red_location;
blueLocation = blue_location;

redLocation.getWorld().setBlockData(redLocation, Material.RED_BANNER.createBlockData());
blueLocation.getWorld().setBlockData(blueLocation, Material.BLUE_BANNER.createBlockData());
}

public void preparePlayerToSpawn(LudosPlayer player) {
player.entity().setGameMode(GameMode.SURVIVAL);
player.entity().getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD));
//TODO : ajouter + d'équipement ici ?
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package fr.efreicraft.ludos.games.ctf;


import fr.efreicraft.ludos.core.Core;
import fr.efreicraft.ludos.core.games.annotations.GameMetadata;
import fr.efreicraft.ludos.core.games.annotations.GameRules;
import fr.efreicraft.ludos.core.games.interfaces.Game;
import fr.efreicraft.ludos.core.maps.points.GamePoint;
import fr.efreicraft.ludos.core.players.LudosPlayer;
import fr.efreicraft.ludos.core.teams.DefaultTeamRecordBuilder;
import fr.efreicraft.ludos.core.teams.TeamRecord;
import fr.efreicraft.ludos.core.utils.ColorUtils;
import org.bukkit.*;

import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;

@GameMetadata(
name = "CTF",
description = "TODO !",
authors = {"orwenn"},
color = "&f",
rules = @GameRules(
minPlayers = 2,
maxPlayers = 2
)
)
public class LudosGame extends Game {

private final GameLogic gameLogic;

public LudosGame() {
super();
gameLogic = new GameLogic();
this.setEventListener(new EventListener(gameLogic));
}

@Override
public void preMapParse(World world) {
// Nothing to do here
}

@Override
public void beginGame() {
super.beginGame();

}

@Override
public void postMapParse() {
Map<String, ArrayList<GamePoint>> game_points = Core.get().getMapManager().getCurrentMap().getGamePoints();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas de snake case


gameLogic.initFlags(
game_points.get("RED_FLAG").get(0).getLocation(),
game_points.get("BLUE_FLAG").get(0).getLocation()
);
}

@Override
public void setupScoreboard(LudosPlayer player) {
// No scoreboard for now
}

@Override
public EnumMap<Material, String> getGamePointsMaterials() {
EnumMap<Material, String> gamePointsMaterials = new EnumMap<>(Material.class);
gamePointsMaterials.put(Material.RED_CONCRETE, "RED_FLAG");
gamePointsMaterials.put(Material.BLUE_CONCRETE, "BLUE_FLAG");
return gamePointsMaterials;
}

@Override
public Map<String, TeamRecord> getTeamRecords() {
HashMap<String, TeamRecord> teams = new HashMap<>();
teams.put("RED", new TeamRecord(
"Red",
1,
true,
true,
new ColorUtils.TeamColorSet(ColorUtils.TeamColors.RED),
player -> true,
this.gameLogic::preparePlayerToSpawn
));
teams.put("BLUE", new TeamRecord(
"Blue",
2,
true,
true,
new ColorUtils.TeamColorSet(ColorUtils.TeamColors.BLUE),
player -> true,
this.gameLogic::preparePlayerToSpawn
));
teams.putAll(DefaultTeamRecordBuilder.DefaultTeamRecords.ONLY_SPECTATOR.getTeamRecords());
return teams;
}
}
16 changes: 16 additions & 0 deletions games/ctf/src/main/java/fr/efreicraft/ludos/games/ctf/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fr.efreicraft.ludos.games.ctf;

import fr.efreicraft.ludos.core.games.interfaces.Game;
import fr.efreicraft.ludos.core.games.interfaces.GamePlugin;

public class Main extends GamePlugin {

public Main() {
super();
}

@Override
public Class<? extends Game> getGameClass() {
return LudosGame.class;
}
}
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ include (
"games:arena",
"games:spleef",
"games:rush",
"games:sumo"
"games:sumo",
"games:ctf"
)

if (System.getenv("NEXUS_REPOSITORY") == null) {
Expand Down