forked from SteamWar/SteamWar
Add glyph flight for enchant particles and blend team links
Entries with the enchant particle get a Glyph flight setting: float down as usual, fly into the player or fly out of them, the latter two unlocked by the WarGear Season placement and participation. Team link lines now start in the drawing player's particle and blend into the partner's along the way.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 SteamWar.de-Serverteam
|
||||
* 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
|
||||
@@ -16,7 +16,6 @@
|
||||
* 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.elements.touch;
|
||||
|
||||
import de.steamwar.lobby.particle.BodyMotion;
|
||||
@@ -31,21 +30,27 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
// A line of particles between nearby players who show the same reward. Each pair is drawn by only one of them.
|
||||
// A line of particles between nearby players who show the same link. It starts in one player's particle and blends
|
||||
// into the other's towards them. Each pair is drawn by only one of them.
|
||||
public class TeamLink extends DelegatingParticleElement {
|
||||
|
||||
public static final double RANGE = 8;
|
||||
private static final double CHEST = 1.2;
|
||||
// Spreads the blend evenly along the line, so it does not flicker from tick to tick
|
||||
private static final double GOLDEN_RATIO = 0.6180339887;
|
||||
|
||||
// Per reward, who showed it in which tick
|
||||
private static final Map<String, Map<Player, Long>> SHOWING = new HashMap<>();
|
||||
private record Showing(long tick, ParticleElement particle) {
|
||||
}
|
||||
|
||||
private final String reward;
|
||||
// Per link, who showed it in which tick with which particle
|
||||
private static final Map<String, Map<Player, Showing>> SHOWING = new HashMap<>();
|
||||
|
||||
private final String link;
|
||||
private final double spacing;
|
||||
|
||||
public TeamLink(String reward, ParticleElement particleElement, double spacing) {
|
||||
public TeamLink(String link, ParticleElement particleElement, double spacing) {
|
||||
super(particleElement);
|
||||
this.reward = reward;
|
||||
this.link = link;
|
||||
this.spacing = spacing;
|
||||
}
|
||||
|
||||
@@ -53,14 +58,14 @@ public class TeamLink extends DelegatingParticleElement {
|
||||
public void tick(ParticleTickData particleTickData) {
|
||||
Player player = particleTickData.getPlayer();
|
||||
long now = BodyMotion.currentTick();
|
||||
Map<Player, Long> showing = SHOWING.computeIfAbsent(reward, key -> new WeakHashMap<>());
|
||||
showing.put(player, now);
|
||||
Map<Player, Showing> showing = SHOWING.computeIfAbsent(link, key -> new WeakHashMap<>());
|
||||
showing.put(player, new Showing(now, particleElement));
|
||||
|
||||
Location from = player.getLocation().add(0, CHEST, 0);
|
||||
for (Map.Entry<Player, Long> other : showing.entrySet()) {
|
||||
for (Map.Entry<Player, Showing> other : showing.entrySet()) {
|
||||
Player partner = other.getKey();
|
||||
// Still showing it, and drawn by the player with the smaller id only
|
||||
if (partner == player || other.getValue() < now - 1 || player.getUniqueId().compareTo(partner.getUniqueId()) > 0) continue;
|
||||
if (partner == player || other.getValue().tick() < now - 1 || player.getUniqueId().compareTo(partner.getUniqueId()) > 0) continue;
|
||||
Location to = partner.getLocation().add(0, CHEST, 0);
|
||||
if (to.getWorld() != from.getWorld() || to.distanceSquared(from) > RANGE * RANGE) continue;
|
||||
|
||||
@@ -68,7 +73,9 @@ public class TeamLink extends DelegatingParticleElement {
|
||||
int points = (int) Math.ceil(step.length() / spacing);
|
||||
step.multiply(1.0 / points);
|
||||
for (int i = 1; i < points; i++) {
|
||||
particleElement.tick(particleTickData.withLocation(from.clone().add(step.clone().multiply(i))));
|
||||
double towardsPartner = (double) i / points;
|
||||
ParticleElement particle = (i * GOLDEN_RATIO) % 1 < towardsPartner ? other.getValue().particle() : particleElement;
|
||||
particle.tick(particleTickData.withLocation(from.clone().add(step.clone().multiply(i))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user