forked from SteamWar/SteamWar
The Touch setting is gone. Its unique mechanics become reward designs that use the entry's particle: Burst (on jumping, landing or sneaking, as a puff or a ring), Footprints, Team link, Shimmer and Heartbeat. Each is unlocked by any of the rewards that had it, and Burst's triggers are locked separately. The wing beat becomes the Beat on jump wing motion, unlocked by WarGear Season 2022. December snow and the glyphs are dropped: the first is a plain particle with a condition, the second only works with enchanting glyphs.
280 lines
11 KiB
Java
280 lines
11 KiB
Java
/*
|
|
* This file is a part of the SteamWar software.
|
|
*
|
|
* Copyright (C) 2025 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.lobby.particle;
|
|
|
|
import de.steamwar.lobby.LobbySystem;
|
|
import de.steamwar.lobby.special.easter.EggDifficulty;
|
|
import de.steamwar.lobby.special.easter.EggHunt;
|
|
import de.steamwar.sql.Event;
|
|
import de.steamwar.sql.SteamwarUser;
|
|
import de.steamwar.sql.Team;
|
|
import de.steamwar.sql.UserPerm;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.Set;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import java.util.stream.Collectors;
|
|
|
|
public interface ParticleRequirement {
|
|
|
|
String getRequirementName(Player player);
|
|
|
|
// Whether the player meets this requirement
|
|
boolean matches(UnlockContext context);
|
|
|
|
// Administrators pass every requirement; lore still names the regular requirement
|
|
default boolean test(UnlockContext context) {
|
|
return context.getUser().hasPerm(UserPerm.ADMINISTRATION) || matches(context);
|
|
}
|
|
|
|
ParticleRequirement SERVER_TEAM = new ParticleRequirement() {
|
|
@Override
|
|
public String getRequirementName(Player player) {
|
|
return LobbySystem.getMessage().parse("PARTICLE_UNLOCKED_BY_SERVER_TEAM", player);
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(UnlockContext context) {
|
|
return context.getUser().hasPerm(UserPerm.TEAM);
|
|
}
|
|
};
|
|
|
|
ParticleRequirement NO_REQUIRMENT = new ParticleRequirement() {
|
|
@Override
|
|
public String getRequirementName(Player player) {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(UnlockContext context) {
|
|
return true;
|
|
}
|
|
};
|
|
|
|
// Does not also pass for the server team
|
|
ParticleRequirement TEAM_MEMBER = new ParticleRequirement() {
|
|
@Override
|
|
public String getRequirementName(Player player) {
|
|
return LobbySystem.getMessage().parse("PARTICLE_UNLOCKED_BY_TEAM", player);
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(UnlockContext context) {
|
|
return context.getUser().getTeam() != 0;
|
|
}
|
|
};
|
|
ParticleRequirement EVENT_PARTICIPATION = new ParticleRequirement() {
|
|
@Override
|
|
public String getRequirementName(Player player) {
|
|
return LobbySystem.getMessage().parse("PARTICLE_UNLOCKED_BY_EVENT", player);
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(UnlockContext context) {
|
|
return !context.getEvents().isEmpty();
|
|
}
|
|
}.or(SERVER_TEAM);
|
|
ParticleRequirement EGG_HUNT_EASY = _easterEggHuntDifficulty(EggDifficulty.EASY);
|
|
ParticleRequirement EGG_HUNT_MEDIUM = _easterEggHuntDifficulty(EggDifficulty.MEDIUM);
|
|
ParticleRequirement EGG_HUNT_HARD = _easterEggHuntDifficulty(EggDifficulty.HARD);
|
|
ParticleRequirement EGG_HUNT_EXTREME = _easterEggHuntDifficulty(EggDifficulty.EXTREME);
|
|
ParticleRequirement EGG_HUNT_ADVANCED = _easterEggHuntDifficulty(EggDifficulty.ADVANCED);
|
|
ParticleRequirement EGG_HUNT_FOUND_HALF = new ParticleRequirement() {
|
|
@Override
|
|
public String getRequirementName(Player player) {
|
|
return LobbySystem.getMessage().parse("PARTICLE_UNLOCKED_BY_EASTER_EGG_HUNT_HALF", player);
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(UnlockContext context) {
|
|
String eggHuntConfig = context.getEggHuntConfig();
|
|
if (eggHuntConfig == null) return false;
|
|
int count = 0;
|
|
for (int i = 0; i < eggHuntConfig.length(); i++) {
|
|
if (eggHuntConfig.charAt(i) == '1') {
|
|
count++;
|
|
}
|
|
}
|
|
return count >= EggHunt.getEggList().size() / 2;
|
|
}
|
|
};
|
|
|
|
static ParticleRequirement specificTeam(int teamId) {
|
|
if (teamId == 0) return NO_REQUIRMENT;
|
|
String teamKuerzel = Team.byId(teamId).getTeamKuerzel();
|
|
return new ParticleRequirement() {
|
|
@Override
|
|
public String getRequirementName(Player player) {
|
|
return LobbySystem.getMessage().parse("PARTICLE_UNLOCKED_BY_SPECIFIC_TEAM", player, teamKuerzel);
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(UnlockContext context) {
|
|
return context.getUser().getTeam() == teamId;
|
|
}
|
|
}.or(SERVER_TEAM);
|
|
}
|
|
|
|
static ParticleRequirement eventParticipation(int eventId) {
|
|
String eventName = Event.byId(eventId).getEventName();
|
|
return new ParticleRequirement() {
|
|
@Override
|
|
public String getRequirementName(Player player) {
|
|
return LobbySystem.getMessage().parse("PARTICLE_UNLOCKED_BY_EVENT_PARTICIPATION", player, eventName);
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(UnlockContext context) {
|
|
return context.getEvents().contains(eventId);
|
|
}
|
|
}.or(SERVER_TEAM);
|
|
}
|
|
|
|
static ParticleRequirement eventPlacement(int eventId, int... placementTeams) {
|
|
String eventName = Event.byId(eventId).getEventName();
|
|
Set<Integer> teams = new HashSet<>();
|
|
for (int i : placementTeams) teams.add(i);
|
|
return new ParticleRequirement() {
|
|
@Override
|
|
public String getRequirementName(Player player) {
|
|
return LobbySystem.getMessage().parse("PARTICLE_UNLOCKED_BY_EVENT_PLACEMENT", player, eventName);
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(UnlockContext context) {
|
|
if (!teams.contains(context.getUser().getTeam())) return false;
|
|
return context.getEvents().contains(eventId);
|
|
}
|
|
}.or(SERVER_TEAM);
|
|
}
|
|
|
|
static ParticleRequirement _easterEggHuntDifficulty(EggDifficulty difficulty) {
|
|
AtomicInteger count = new AtomicInteger();
|
|
List<Integer> eggs = EggHunt.getEggList()
|
|
.stream()
|
|
.map(egg -> {
|
|
int id = count.getAndIncrement();
|
|
if (egg.getDifficulty() == difficulty) {
|
|
return id;
|
|
} else {
|
|
return null;
|
|
}
|
|
})
|
|
.filter(Objects::nonNull)
|
|
.collect(Collectors.toList());
|
|
|
|
return new ParticleRequirement() {
|
|
@Override
|
|
public String getRequirementName(Player player) {
|
|
return LobbySystem.getMessage().parse("PARTICLE_UNLOCKED_BY_EASTER_EGG_HUNT_DIFFICULTY", player, LobbySystem.getMessage().parse(difficulty.getMessage(), player));
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(UnlockContext context) {
|
|
String eggHuntConfig = context.getEggHuntConfig();
|
|
if (eggHuntConfig == null) return false;
|
|
return eggs.stream().allMatch(id -> eggHuntConfig.length() > id && eggHuntConfig.charAt(id) == '1');
|
|
}
|
|
};
|
|
}
|
|
|
|
static ParticleRequirement specificPlayer(int userId) {
|
|
String userName = SteamwarUser.byId(userId).getUserName();
|
|
return new ParticleRequirement() {
|
|
@Override
|
|
public String getRequirementName(Player player) {
|
|
return LobbySystem.getMessage().parse("PARTICLE_UNLOCKED_BY_SPECIFIC_USER", player, userName);
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(UnlockContext context) {
|
|
return context.getUser().getId() == userId;
|
|
}
|
|
}.or(SERVER_TEAM);
|
|
}
|
|
|
|
static ParticleRequirement easterEventSpecificPlayer(int userId) {
|
|
String userName = SteamwarUser.byId(userId).getUserName();
|
|
return new ParticleRequirement() {
|
|
@Override
|
|
public String getRequirementName(Player player) {
|
|
return LobbySystem.getMessage().parse("PARTICLE_UNLOCKED_BY_SPECIFIC_USER_EASTER", player, userName);
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(UnlockContext context) {
|
|
return context.getUser().getId() == userId;
|
|
}
|
|
}.or(SERVER_TEAM);
|
|
}
|
|
|
|
static ParticleRequirement easterEventSpecificTeam(int teamId) {
|
|
if (teamId == 0) return NO_REQUIRMENT;
|
|
String teamKuerzel = Team.byId(teamId).getTeamKuerzel();
|
|
return new ParticleRequirement() {
|
|
@Override
|
|
public String getRequirementName(Player player) {
|
|
return LobbySystem.getMessage().parse("PARTICLE_UNLOCKED_BY_SPECIFIC_TEAM_EASTER", player, teamKuerzel);
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(UnlockContext context) {
|
|
return context.getUser().getTeam() == teamId;
|
|
}
|
|
}.or(SERVER_TEAM);
|
|
}
|
|
|
|
// Met by meeting any of the requirements; the lore lists them one per line
|
|
static ParticleRequirement anyOf(ParticleRequirement... requirements) {
|
|
return new ParticleRequirement() {
|
|
@Override
|
|
public String getRequirementName(Player player) {
|
|
return java.util.Arrays.stream(requirements).map(requirement -> requirement.getRequirementName(player)).filter(Objects::nonNull).collect(Collectors.joining("\n"));
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(UnlockContext context) {
|
|
for (ParticleRequirement requirement : requirements) {
|
|
if (requirement.test(context)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
};
|
|
}
|
|
|
|
// The alternative is checked first, as it is usually the cheap server team check
|
|
default ParticleRequirement or(ParticleRequirement particleRequirement) {
|
|
return new ParticleRequirement() {
|
|
@Override
|
|
public String getRequirementName(Player player) {
|
|
return ParticleRequirement.this.getRequirementName(player);
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(UnlockContext context) {
|
|
return particleRequirement.test(context) || ParticleRequirement.this.test(context);
|
|
}
|
|
};
|
|
}
|
|
}
|