Skip to content

Commit a0e2506

Browse files
Merge pull request #836 from LongPPPP/master
feat: pet ability handler system remake
2 parents 6245184 + 62f100c commit a0e2506

36 files changed

Lines changed: 1056 additions & 209 deletions

File tree

commons/src/generated/java/net/swofty/commons/skyblock/item/ItemType.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public enum ItemType {
262262

263263
BEE_MINION_SKIN(Material.PLAYER_HEAD, Rarity.COMMON),
264264

265-
BEE_PET(Material.PLAYER_HEAD, Rarity.EPIC),
265+
BEE_PET(Material.PLAYER_HEAD, Rarity.MYTHIC),
266266

267267
BEHEADED_HORROR(Material.PLAYER_HEAD, Rarity.EPIC),
268268

@@ -722,6 +722,8 @@ public enum ItemType {
722722

723723
CHICKEN_MINION(Material.PLAYER_HEAD, Rarity.COMMON),
724724

725+
CHICKEN_PET(Material.PLAYER_HEAD, Rarity.LEGENDARY),
726+
725727
CHILI_PEPPER(Material.PLAYER_HEAD, Rarity.UNCOMMON),
726728

727729
CHISELED_QUARTZ_BLOCK(Material.CHISELED_QUARTZ_BLOCK, Rarity.COMMON),
@@ -1846,6 +1848,8 @@ public enum ItemType {
18461848

18471849
GOLEM_SWORD(Material.IRON_SWORD, Rarity.RARE),
18481850

1851+
GRANDMA_WOLF_PET(Material.PLAYER_HEAD, Rarity.LEGENDARY),
1852+
18491853
GRANITE(Material.GRANITE, Rarity.COMMON),
18501854

18511855
GRANITE_SLAB(Material.GRANITE_SLAB, Rarity.COMMON),

commons/src/main/java/net/swofty/commons/skyblock/item/attribute/attributes/ItemAttributePetData.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public Integer getAsLevel(Rarity rarity) {
6767
case RARE -> getLevel(experience, RARE_XP_GOALS);
6868
case EPIC -> getLevel(experience, EPIC_XP_GOALS);
6969
case LEGENDARY -> getLevel(experience, LEGENDARY_XP_GOALS);
70+
case MYTHIC -> getLevel(experience, MYTHIC_XP_GOALS);
7071
default -> 0;
7172
};
7273
}
@@ -78,6 +79,7 @@ public double getAsExperience(Rarity rarity) {
7879
case RARE -> experience - RARE_XP_GOALS.get(getAsLevel(Rarity.RARE));
7980
case EPIC -> experience - EPIC_XP_GOALS.get(getAsLevel(Rarity.EPIC));
8081
case LEGENDARY -> experience - LEGENDARY_XP_GOALS.get(getAsLevel(Rarity.LEGENDARY));
82+
case MYTHIC -> experience - MYTHIC_XP_GOALS.get(getAsLevel(Rarity.MYTHIC));
8183
default -> 0;
8284
};
8385
}
@@ -89,6 +91,7 @@ public long getExperienceForLevel(int level, Rarity rarity) {
8991
case RARE -> RARE_XP_GOALS.get(level - 1);
9092
case EPIC -> EPIC_XP_GOALS.get(level - 1);
9193
case LEGENDARY -> LEGENDARY_XP_GOALS.get(level - 1);
94+
case MYTHIC -> MYTHIC_XP_GOALS.get(level - 1);
9295
default -> 0;
9396
};
9497
}
@@ -136,4 +139,6 @@ private Integer getLevel(double xp, List<Integer> goals) {
136139
1205530, 1302730, 1406930, 1518630, 1638330, 1766530, 1903730, 2050430, 2207130, 2374830, 2554530, 2747230, 2953930, 3175630, 3413330, 3668030, 3940730, 4232430,
137140
4544130, 4877830, 5235530, 5619230, 6030930, 6472630, 6949330, 7466030, 8027730, 8639430, 9306130, 10032830, 10824530, 11686230, 12622930, 13639630, 14741330,
138141
15933030, 17219730, 18606430, 20103130, 21719830, 23466530, 25353230);
142+
143+
protected static final List<Integer> MYTHIC_XP_GOALS = LEGENDARY_XP_GOALS;
139144
}

commons/src/main/java/net/swofty/commons/skyblock/statistics/ItemStatistic.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ public String getFullDisplayName() {
169169
return LegacyComponentSerializer.legacySection().serialize(getCompleteDisplayName());
170170
}
171171

172+
public String getLegacyDisplayColor() {
173+
return LegacyComponentSerializer.legacySection()
174+
.serialize(Component.text("|", displayColor)).replace("|", "");
175+
}
176+
172177
public Component getCompleteDisplayName() {
173178
return symbol.getSprite().appendSpace().append(Component.text(displayName)).color(displayColor);
174179
}

configuration/i18n/en_US/items.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ items.EVERBURNING_FLAME = Everburning Flame
434434
items.HEAT_CORE = Heat Core
435435
items.BEE_MINION_SKIN = Bee Minion Skin
436436
items.BEE_PET = Bee Pet
437+
items.CHICKEN_PET = Chicken Pet
438+
items.GRANDMA_WOLF_PET = Grandma Wolf Pet
437439
items.ALL_SKILLS_EXP_BOOST = All Skills Exp Boost
438440
items.MINING_EXP_BOOST_COMMON = Mining Exp Boost Common
439441
items.MINING_EXP_BOOST_RARE = Mining Exp Boost Rare

configuration/skyblock/items/pets.yml

Lines changed: 89 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
items:
22
- id: BEE_PET
33
material: player_head
4-
rarity: EPIC
4+
rarity: MYTHIC
55
components:
66
- id: PET
77
pet_name: Bee
@@ -35,31 +35,102 @@ items:
3535
item: ENCHANTED_GOLD_BLOCK
3636
amount: 9
3737
rest: null
38-
base_statistics:
39-
strength: 5.0
38+
base_statistics: {}
4039
per_level_statistics:
4140
common:
42-
speed: 1.0
43-
strength: 3.0
44-
intelligence: 5.0
41+
speed: 0.1
42+
strength: 0.25
43+
intelligence: 0.5
4544
uncommon:
46-
speed: 1.5
47-
strength: 4.0
48-
intelligence: 7.0
45+
speed: 0.1
46+
strength: 0.25
47+
intelligence: 0.5
4948
rare:
50-
speed: 2.0
51-
strength: 5.0
52-
intelligence: 10.0
49+
speed: 0.1
50+
strength: 0.25
51+
intelligence: 0.5
52+
mining_fortune: 0.2
53+
foraging_fortune: 0.2
54+
farming_fortune: 0.2
5355
epic:
54-
speed: 2.5
55-
strength: 6.0
56-
intelligence: 15.0
56+
speed: 0.1
57+
strength: 0.25
58+
intelligence: 0.5
59+
mining_fortune: 0.25
60+
foraging_fortune: 0.25
61+
farming_fortune: 0.25
5762
legendary:
58-
speed: 3.0
59-
strength: 7.0
60-
intelligence: 20.0
63+
speed: 0.1
64+
strength: 0.25
65+
intelligence: 0.5
66+
mining_fortune: 0.3
67+
foraging_fortune: 0.3
68+
farming_fortune: 0.3
69+
mythic:
70+
speed: 0.1
71+
strength: 0.25
72+
intelligence: 0.5
73+
mining_fortune: 0.4
74+
foraging_fortune: 0.4
75+
farming_fortune: 0.4
6176
particle: 3
6277
skill_category: FARMING
6378
skull_texture: 12724a9a4cdd68ba49415560e5be40b4a1c47cb5be1d66aedb52a30e62ef2d47
6479
handler_id: BEE
80+
- id: TRACKED_UNIQUE
81+
- id: CHICKEN_PET
82+
material: player_head
83+
rarity: LEGENDARY
84+
components:
85+
- id: PET
86+
pet_name: Chicken
87+
base_statistics: {}
88+
per_level_statistics:
89+
common:
90+
speed: 0.5
91+
farming_fortune: 0.5
92+
uncommon:
93+
speed: 0.5
94+
farming_fortune: 0.5
95+
rare:
96+
speed: 0.5
97+
farming_fortune: 0.5
98+
epic:
99+
speed: 0.5
100+
farming_fortune: 0.5
101+
legendary:
102+
speed: 0.5
103+
farming_fortune: 0.5
104+
particle: 3
105+
skill_category: FARMING
106+
skull_texture: 7f37d524c3eed171ce149887ea1dee4ed399904727d521865688ece3bac75e
107+
handler_id: CHICKEN
108+
- id: TRACKED_UNIQUE
109+
- id: GRANDMA_WOLF_PET
110+
material: player_head
111+
rarity: LEGENDARY
112+
components:
113+
- id: PET
114+
pet_name: Grandma Wolf
115+
base_statistics: {}
116+
per_level_statistics:
117+
common:
118+
strength: 0.25
119+
health: 1
120+
uncommon:
121+
strength: 0.25
122+
health: 1
123+
rare:
124+
strength: 0.25
125+
health: 1
126+
epic:
127+
strength: 0.25
128+
health: 1
129+
legendary:
130+
strength: 0.25
131+
health: 1
132+
particle: 3
133+
skill_category: COMBAT
134+
skull_texture: e897c5640ccfc68ffb65e331b7070ce5d14439ad2cd7d9612a6feb023eedac18
135+
handler_id: GRANDMA_WOLF
65136
- id: TRACKED_UNIQUE

type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/bestiary/BestiaryData.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ public int getTotalExtraXPPercentage(int tier) {
215215

216216
public List<String> getTotalBonuses(List<String> lore, String name, int tier) {
217217
lore.add("§a" + name + " §aBonuses");
218-
lore.add("§8+" + ItemStatistic.MAGIC_FIND.getDisplayColor() + getTotalMagicFind(tier) + " " + ItemStatistic.MAGIC_FIND.getFullDisplayName());
219-
lore.add("§8+" + ItemStatistic.STRENGTH.getDisplayColor() + getTotalStrength(tier) + " " + ItemStatistic.STRENGTH.getFullDisplayName());
218+
lore.add("§8+" + ItemStatistic.MAGIC_FIND.getLegacyDisplayColor() + getTotalMagicFind(tier) + " " + ItemStatistic.MAGIC_FIND.getFullDisplayName());
219+
lore.add("§8+" + ItemStatistic.STRENGTH.getLegacyDisplayColor() + getTotalStrength(tier) + " " + ItemStatistic.STRENGTH.getFullDisplayName());
220220
lore.add("§8+§6" + getTotalExtraCoinPercentage(tier) + "% §7coin gain");
221221

222222
int totalXp = getTotalExtraXPPercentage(tier);
@@ -231,8 +231,8 @@ public List<String> getTotalBonuses(List<String> lore, String name, int tier) {
231231

232232
public List<String> getNextBonuses(List<String> lore, String name, int tier) {
233233
lore.add("§7Tier " + StringUtility.getAsRomanNumeral(tier) + " Rewards");
234-
lore.add(" §8+" + ItemStatistic.MAGIC_FIND.getDisplayColor() + getMagicFind(tier) + " " + ItemStatistic.MAGIC_FIND.getFullDisplayName());
235-
lore.add(" §8+" + ItemStatistic.STRENGTH.getDisplayColor() + getStrength(tier) + " " + ItemStatistic.STRENGTH.getFullDisplayName());
234+
lore.add(" §8+" + ItemStatistic.MAGIC_FIND.getLegacyDisplayColor() + getMagicFind(tier) + " " + ItemStatistic.MAGIC_FIND.getFullDisplayName());
235+
lore.add(" §8+" + ItemStatistic.STRENGTH.getLegacyDisplayColor() + getStrength(tier) + " " + ItemStatistic.STRENGTH.getFullDisplayName());
236236
lore.add(" §8+§6" + getExtraCoinPercentage(tier) + "% §7coin gain");
237237

238238
int totalXp = getExtraXpPercentage(tier);

type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/commands/RecombobulateCommand.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public void registerUsage(MinestomCommand command) {
2020

2121
((SkyBlockPlayer) sender).updateItem(PlayerItemOrigin.MAIN_HAND, (item) -> {
2222
ItemAttributeHandler itemAttributeHandler = item.getAttributeHandler();
23+
if (itemAttributeHandler.isPet()) {
24+
sender.sendMessage("§cPets cannot be recombobulated!");
25+
return;
26+
}
2327
itemAttributeHandler.setRecombobulated(!itemAttributeHandler.isRecombobulated());
2428
sender.sendMessage("§aRecombobulated: §d" + itemAttributeHandler.isRecombobulated());
2529
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package net.swofty.type.skyblockgeneric.commands;
2+
3+
import net.minestom.server.command.builder.arguments.ArgumentWord;
4+
import net.minestom.server.command.builder.suggestion.SuggestionEntry;
5+
import net.swofty.commons.skyblock.item.Rarity;
6+
import net.swofty.type.generic.command.CommandParameters;
7+
import net.swofty.type.generic.command.HypixelCommand;
8+
import net.swofty.type.generic.user.categories.Rank;
9+
import net.swofty.type.skyblockgeneric.item.ItemAttributeHandler;
10+
import net.swofty.type.skyblockgeneric.item.updater.PlayerItemOrigin;
11+
import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer;
12+
13+
import java.util.Arrays;
14+
import java.util.List;
15+
import java.util.stream.Collectors;
16+
17+
@CommandParameters(labels = "setpetrarity",
18+
description = "Sets the rarity of the pet in your hand",
19+
usage = "/setpetrarity <rarity>",
20+
permission = Rank.STAFF,
21+
allowsConsole = false)
22+
public class SetPetRarityCommand extends HypixelCommand {
23+
private static final List<Rarity> PET_RARITIES = Arrays.stream(Rarity.values())
24+
.filter(rarity -> rarity.ordinal() <= Rarity.MYTHIC.ordinal())
25+
.toList();
26+
27+
@Override
28+
public void registerUsage(MinestomCommand command) {
29+
ArgumentWord rarityArgument = new ArgumentWord("rarity");
30+
rarityArgument.setSuggestionCallback((sender, context, suggestion) ->
31+
PET_RARITIES.forEach(rarity ->
32+
suggestion.addEntry(new SuggestionEntry(rarity.name()))));
33+
34+
command.addSyntax((sender, context) -> {
35+
if (!permissionCheck(sender)) return;
36+
37+
Rarity rarity = Rarity.getRarity(context.get(rarityArgument));
38+
if (rarity == null || !PET_RARITIES.contains(rarity)) {
39+
sender.sendMessage("§cInvalid rarity. Use " + PET_RARITIES.stream()
40+
.map(Enum::name).collect(Collectors.joining("/")) + ".");
41+
return;
42+
}
43+
SkyBlockPlayer player = (SkyBlockPlayer) sender;
44+
45+
player.updateItem(PlayerItemOrigin.MAIN_HAND, (item) -> {
46+
ItemAttributeHandler handler = item.getAttributeHandler();
47+
if (!handler.isPet()) {
48+
sender.sendMessage("§cThe item in your hand is not a pet.");
49+
return;
50+
}
51+
handler.setRarity(rarity);
52+
sender.sendMessage("§aSet rarity to " + rarity.getLegacyColor() + rarity.name() + "§a.");
53+
});
54+
}, rarityArgument);
55+
}
56+
}

type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/data/datapoints/DatapointPetData.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@
33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44
import lombok.Getter;
55
import net.swofty.commons.skyblock.item.ItemType;
6+
import net.swofty.commons.skyblock.item.Rarity;
67
import net.swofty.commons.skyblock.item.UnderstandableSkyBlockItem;
78
import net.swofty.commons.protocol.Serializer;
89
import net.swofty.commons.protocol.serializers.UnderstandableSkyBlockItemSerializer;
910
import net.swofty.type.skyblockgeneric.data.SkyBlockDatapoint;
1011
import net.swofty.type.skyblockgeneric.entity.PetEntityImpl;
1112
import net.swofty.type.skyblockgeneric.item.SkyBlockItem;
13+
import net.swofty.type.skyblockgeneric.item.components.PetComponent;
1214
import net.swofty.type.skyblockgeneric.item.components.SkullHeadComponent;
15+
import net.swofty.type.skyblockgeneric.item.handlers.pet.PetHandler;
16+
import net.swofty.type.skyblockgeneric.item.handlers.pet.abstr.AbilityRuntime;
17+
import net.swofty.type.skyblockgeneric.item.handlers.pet.abstr.PetAbility;
18+
import net.swofty.type.skyblockgeneric.item.handlers.pet.abstr.PetEvent;
1319
import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer;
1420
import org.jetbrains.annotations.Nullable;
1521
import org.json.JSONObject;
1622

1723
import java.util.HashMap;
24+
import java.util.List;
25+
import java.util.Map;
1826

1927
public class DatapointPetData extends SkyBlockDatapoint<DatapointPetData.UserPetData> {
2028
private static final Serializer serializer = new Serializer<UserPetData>() {
@@ -64,6 +72,8 @@ public DatapointPetData(String key) {
6472
public static class UserPetData {
6573
private HashMap<SkyBlockItem, Boolean> petsMap;
6674
private PetEntityImpl enabledPetEntityImpl = null;
75+
private transient List<PetAbility> cachedAbilities;
76+
private final transient Map<PetAbility, AbilityRuntime> abilityRuntimes = new HashMap<>();
6777

6878
public UserPetData() {
6979
this.petsMap = new HashMap<>();
@@ -79,13 +89,15 @@ public void addPet(SkyBlockItem pet) {
7989

8090
public void setEnabled(ItemType type, boolean enabled) {
8191
// Set all previous true pets to false
82-
petsMap.keySet().stream().filter(pet -> pet.getAttributeHandler().getPotentialType() == type).forEach(pet -> petsMap.put(pet, false));
92+
petsMap.keySet().forEach(pet -> petsMap.put(pet, false));
8393

8494
// Set the new pet to the new state
8595
petsMap.keySet().stream().filter(pet -> pet.getAttributeHandler().getPotentialType() == type).findFirst().ifPresent(pet -> petsMap.put(pet, enabled));
8696

8797
if (enabledPetEntityImpl != null)
8898
enabledPetEntityImpl.remove();
99+
100+
refreshCachedAbilities();
89101
}
90102

91103
public void updatePetEntityImpl(SkyBlockPlayer player) {
@@ -108,12 +120,45 @@ public void isEnabled(ItemType type) {
108120

109121
public void deselectCurrent() {
110122
petsMap.keySet().forEach(pet -> petsMap.put(pet, false));
123+
this.cachedAbilities = null;
111124
}
112125

113126
public @Nullable SkyBlockItem getEnabledPet() {
114127
return petsMap.keySet().stream().filter(petsMap::get).findFirst().orElse(null);
115128
}
116129

130+
public List<PetAbility> getCachedAbilities(SkyBlockItem pet) {
131+
if (cachedAbilities == null) {
132+
PetComponent component = pet.getComponent(PetComponent.class);
133+
cachedAbilities = PetHandler.valueOf(component.getHandlerId().toUpperCase()).getAbilities(pet);
134+
}
135+
return cachedAbilities;
136+
}
137+
138+
public AbilityRuntime getAbilityRuntime(PetAbility ability) {
139+
return abilityRuntimes.computeIfAbsent(ability, _ -> new AbilityRuntime());
140+
}
141+
142+
public <E extends PetEvent> E dispatch(E event) {
143+
SkyBlockItem pet = getEnabledPet();
144+
if (pet == null) return event;
145+
for (PetAbility ability : getCachedAbilities(pet)) {
146+
ability.onEvent(event);
147+
}
148+
return event;
149+
}
150+
151+
// TODO: need to be called by Tier Boost
152+
public void refreshCachedAbilities() {
153+
SkyBlockItem activePet = getEnabledPet();
154+
if (activePet != null) {
155+
PetComponent component = activePet.getComponent(PetComponent.class);
156+
this.cachedAbilities = PetHandler.valueOf(component.getHandlerId().toUpperCase()).getAbilities(activePet);
157+
} else {
158+
this.cachedAbilities = null;
159+
}
160+
}
161+
117162
public @Nullable SkyBlockItem getPet(ItemType type) {
118163
return petsMap.keySet().stream().filter(pet -> pet.getAttributeHandler().getPotentialType() == type).findFirst().orElse(null);
119164
}

0 commit comments

Comments
 (0)