Skip to content

Commit

Permalink
Allow adding constellations to playerless avatars
Browse files Browse the repository at this point in the history
  • Loading branch information
Birdulon committed Aug 21, 2022
1 parent c517b8a commit d9f85ba
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/emu/grasscutter/game/avatar/Avatar.java
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@ public void addToExtraAbilityEmbryos(String openConfig, boolean forceAdd) {

public void calcConstellation(OpenConfigEntry entry, boolean notifyClient) {
if (entry == null) return;
if (this.getPlayer() == null)
notifyClient = false;

// Check if new constellation adds +3 to a skill level
if (this.calcConstellationExtraLevels(entry) && notifyClient) {
Expand Down Expand Up @@ -754,18 +756,21 @@ public boolean unlockConstellation(int talentId, boolean skipPayment) {
// Get talent
AvatarTalentData talentData = GameData.getAvatarTalentDataMap().get(talentId);
if (talentData == null) return false;
var player = this.getPlayer();

// Pay constellation item if possible
if (!skipPayment && !this.getPlayer().getInventory().payItem(talentData.getMainCostItemId(), 1)) {
if (!skipPayment && (player != null) && !player.getInventory().payItem(talentData.getMainCostItemId(), 1)) {
return false;
}

// Apply + recalc
this.talentIdList.add(talentData.getId());

// Packet
this.getPlayer().sendPacket(new PacketAvatarUnlockTalentNotify(this, talentId));
this.getPlayer().sendPacket(new PacketUnlockAvatarTalentRsp(this, talentId));
if (player != null) {
player.sendPacket(new PacketAvatarUnlockTalentNotify(this, talentId));
player.sendPacket(new PacketUnlockAvatarTalentRsp(this, talentId));
}

// Proud skill bonus map (Extra skills)
this.calcConstellation(GameData.getOpenConfigEntries().get(talentData.getOpenConfig()), true);
Expand Down

0 comments on commit d9f85ba

Please sign in to comment.