Skip to content

Commit a64d3ca

Browse files
committed
ref game modifier
1 parent 4fa517c commit a64d3ca

File tree

15 files changed

+327
-125
lines changed

15 files changed

+327
-125
lines changed

src/main/java/com/github/elic0de/hungergames/animation/Animation.java renamed to src/main/java/com/github/elic0de/battleroyale/animation/Animation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.elic0de.hungergames.animation;
1+
package com.github.elic0de.battleroyale.animation;
22

33
import lombok.Getter;
44
import lombok.NonNull;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.github.elic0de.battleroyale.animation;
2+
3+
import com.github.elic0de.battleroyale.BattleRoyale;
4+
import com.github.elic0de.battleroyale.animation.text.ZoomInAnimation;
5+
import com.github.elic0de.battleroyale.animation.text.ZoomOutAnimation;
6+
import com.github.elic0de.battleroyale.modifier.modifiers.GameModifier;
7+
import org.bukkit.Bukkit;
8+
import org.bukkit.ChatColor;
9+
import org.bukkit.Sound;
10+
import org.bukkit.entity.Player;
11+
import org.bukkit.scheduler.BukkitRunnable;
12+
13+
import java.util.Collection;
14+
import java.util.List;
15+
16+
public class Test {
17+
18+
// todo
19+
public void animation(Collection<GameModifier> gameModifiers) {
20+
Bukkit.getOnlinePlayers().forEach(player -> new BukkitRunnable() {
21+
int frame = 0;
22+
float pitch = 1.0f;
23+
24+
@Override
25+
public void run() {
26+
player.sendTitle(ChatColor.translateAlternateColorCodes('&', new ZoomOutAnimation().animate("ゲームモディファイアー", frame)), "ピックされました!", 0, 70, 0);
27+
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1f, Math.min(2.0f, pitch));
28+
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_HARP, 1f, Math.min(2.0f, pitch));
29+
30+
frame++;
31+
pitch += .1;
32+
if (frame == 15) {
33+
cancel();
34+
startSlotAnimationTitle(player, gameModifiers);
35+
}
36+
}
37+
}.runTaskTimer(BattleRoyale.getInstance(), 0L, 2));
38+
}
39+
40+
// todo
41+
public void startSlotAnimationTitle(Player player, Collection<GameModifier> modifiers) {
42+
List<String> symbols = modifiers.stream().map(modifier ->
43+
String.format(modifier.getColor() + "%s,%s,%s", modifier.getColor(), modifier.getSymbol(), modifier.getColor() + modifier.getName())).toList();
44+
45+
new BukkitRunnable() {
46+
int frameIn = 0;
47+
int frameIndex = 0;
48+
int cycles = 10;
49+
50+
@Override
51+
public void run() {
52+
final String[] frame = symbols.get(frameIndex).split(",");
53+
final String color = frame[0];
54+
final String title = frame[1];
55+
final String subtitle = frame[2];
56+
final GameModifier pickedModifier = BattleRoyale.getInstance().getGame().getModifierManager().getCurrentMission();
57+
58+
if (cycles <= 5) {
59+
60+
player.sendTitle(String.format(pickedModifier.getColor() + "[%s]", pickedModifier.getSymbol()), pickedModifier.getColor() + pickedModifier.getName(), 0, 20, 0);
61+
62+
63+
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1f, 2);
64+
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1f, 1);
65+
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1f, .5f);
66+
} else {
67+
player.sendTitle(color + new ZoomInAnimation().animate(title, frameIn), subtitle, 0, 20, 0);
68+
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_HARP, 1f, 2f);
69+
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_HARP, 1f, .5f);
70+
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1f, 1);
71+
}
72+
frameIn++;
73+
frameIndex++;
74+
if (frameIndex >= symbols.size()) {
75+
frameIndex = 0;
76+
cycles--;
77+
78+
if (cycles <= 0) {
79+
cancel();
80+
pickedModifier.modify();
81+
}
82+
}
83+
}
84+
}.runTaskTimer(BattleRoyale.getInstance(), 0L, 2L);
85+
}
86+
}

src/main/java/com/github/elic0de/hungergames/animation/TextAnimation.java renamed to src/main/java/com/github/elic0de/battleroyale/animation/TextAnimation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.elic0de.hungergames.animation;
1+
package com.github.elic0de.battleroyale.animation;
22

33
import lombok.NonNull;
44

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.github.elic0de.battleroyale.animation.text;
2+
3+
import com.github.elic0de.battleroyale.animation.TextAnimation;
4+
import lombok.NonNull;
5+
6+
public class ZoomInAnimation extends TextAnimation {
7+
8+
public ZoomInAnimation() {
9+
super("zooIn", 1, 40);
10+
}
11+
12+
@Override
13+
public String animate(@NonNull String text, long step, String... args) {
14+
int currentStep = getCurrentStep(step, 10);
15+
int spaceCount = Math.max(0, 10 - currentStep);
16+
// 空白を作成
17+
18+
String space = " ".repeat(spaceCount);
19+
String SQUARE_BRACKET_END = "]";
20+
String SQUARE_BRACKET_START = "[";
21+
return SQUARE_BRACKET_START + space + text + space + SQUARE_BRACKET_END;
22+
}
23+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.github.elic0de.battleroyale.animation.text;
2+
3+
import com.github.elic0de.battleroyale.animation.TextAnimation;
4+
import lombok.NonNull;
5+
import org.bukkit.ChatColor;
6+
7+
public class ZoomOutAnimation extends TextAnimation {
8+
9+
public ZoomOutAnimation() {
10+
super("zoomOut", 1, 40);
11+
}
12+
13+
@Override
14+
public String animate(@NonNull String text, long step, String... args) {
15+
String stripped = ChatColor.stripColor(text);
16+
int length = stripped.length();
17+
int currentStep = getCurrentStep(step, length);
18+
int spaceCount = Math.min(15, currentStep);
19+
ChatColor color = currentStep % 2 == 0 ? ChatColor.RED : ChatColor.GOLD;
20+
21+
// 空白を作成
22+
String space = " ".repeat(Math.max(0, spaceCount));
23+
24+
String SQUARE_BRACKET_END = "]";
25+
String SQUARE_BRACKET_START = "[";
26+
String spacedText = SQUARE_BRACKET_START + space + text + space + SQUARE_BRACKET_END;
27+
return color + spacedText;
28+
}
29+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.github.elic0de.battleroyale.event;
2+
3+
import com.github.elic0de.battleroyale.user.GameUser;
4+
import org.bukkit.event.HandlerList;
5+
import org.bukkit.event.player.PlayerEvent;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
public class GamePlayerKillEvent extends PlayerEvent {
9+
10+
private final GameUser killer;
11+
private final GameUser vitim;
12+
private static final HandlerList handlers = new HandlerList();
13+
14+
public GamePlayerKillEvent(@NotNull GameUser killer, @NotNull GameUser vitim) {
15+
super(killer.getPlayer());
16+
this.killer = killer;
17+
this.vitim = vitim;
18+
}
19+
20+
public GameUser getKiller() {
21+
return killer;
22+
}
23+
24+
public GameUser getVitim() {
25+
return vitim;
26+
}
27+
28+
@NotNull
29+
@Override
30+
public HandlerList getHandlers() {
31+
return handlers;
32+
}
33+
34+
public static HandlerList getHandlerList(){
35+
return handlers;
36+
}
37+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.github.elic0de.battleroyale.modifier.modifiers;
2+
3+
import com.github.elic0de.eliccommon.util.ItemBuilder;
4+
import org.bukkit.ChatColor;
5+
import org.bukkit.Material;
6+
import org.bukkit.event.EventHandler;
7+
import org.bukkit.event.block.BlockBreakEvent;
8+
9+
import java.util.Arrays;
10+
import java.util.Random;
11+
12+
public class FlowerPower extends GameModifier {
13+
14+
public FlowerPower() {
15+
super("❁", "Flower Power", "花を壊した時にランダムなアイテムがドロップする。", ChatColor.YELLOW);
16+
}
17+
18+
@EventHandler
19+
private void on(BlockBreakEvent event) {
20+
if (getPlugin().getGame().getModifierManager().getCurrentMission() != this) return;
21+
if (event.getBlock().getType() != Material.POPPY) return;
22+
23+
event.setDropItems(false);
24+
Arrays.stream(Material.values()).skip(new Random().nextInt(Material.values().length)).findAny().ifPresent(material ->
25+
event.getBlock().getWorld().dropItemNaturally(event.getBlock().getLocation(), ItemBuilder.of(material).build()));
26+
}
27+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.github.elic0de.battleroyale.modifier.modifiers;
2+
3+
import com.github.elic0de.battleroyale.BattleRoyale;
4+
import lombok.Getter;
5+
import org.bukkit.Bukkit;
6+
import org.bukkit.ChatColor;
7+
import org.bukkit.event.Listener;
8+
9+
@Getter
10+
public class GameModifier implements Listener {
11+
12+
private final BattleRoyale plugin = BattleRoyale.getInstance();
13+
14+
private final String symbol;
15+
private final String name;
16+
private final String description;
17+
private final ChatColor color;
18+
19+
protected GameModifier(String symbol, String name, String description, ChatColor color) {
20+
this.symbol = symbol;
21+
this.name = name;
22+
this.description = description;
23+
this.color = color;
24+
Bukkit.getPluginManager().registerEvents(this, BattleRoyale.getInstance());
25+
}
26+
27+
public void modify() {
28+
29+
}
30+
31+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.github.elic0de.battleroyale.modifier.modifiers;
2+
3+
import com.github.elic0de.battleroyale.event.GamePlayerKillEvent;
4+
import org.bukkit.ChatColor;
5+
import org.bukkit.event.EventHandler;
6+
7+
public class HealthOnKill extends GameModifier {
8+
9+
public HealthOnKill() {
10+
super("❁", "Health On Kill", "敵を倒すと最大HPが増加する。", ChatColor.YELLOW);
11+
}
12+
13+
@EventHandler
14+
private void on(GamePlayerKillEvent event) {
15+
if (getPlugin().getGame().getModifierManager().getCurrentMission() != this) return;
16+
event.getKiller().getPlayer().setHealth(20);
17+
}
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.github.elic0de.battleroyale.modifier.modifiers;
2+
3+
import com.github.elic0de.battleroyale.event.GamePlayerKillEvent;
4+
import org.bukkit.ChatColor;
5+
import org.bukkit.event.EventHandler;
6+
import org.bukkit.potion.PotionEffect;
7+
import org.bukkit.potion.PotionEffectType;
8+
9+
public class MagicPower extends GameModifier {
10+
11+
public MagicPower() {
12+
super("☣", "Magic Power", "敵を倒した時、またはアシストでランダムな良いポーション効果が付与される。", ChatColor.GREEN);
13+
}
14+
15+
@EventHandler
16+
private void on(GamePlayerKillEvent event) {
17+
if (getPlugin().getGame().getModifierManager().getCurrentMission() != this) return;
18+
event.getKiller().getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 20, 2));
19+
}
20+
}

0 commit comments

Comments
 (0)