Commit 12501944 authored by Melledy's avatar Melledy
Browse files

Fix weapon skills (and artifact sets) not working when you equip them

parent 8a890609
...@@ -13,6 +13,7 @@ import dev.morphia.annotations.Indexed; ...@@ -13,6 +13,7 @@ import dev.morphia.annotations.Indexed;
import dev.morphia.annotations.PostLoad; import dev.morphia.annotations.PostLoad;
import dev.morphia.annotations.PrePersist; import dev.morphia.annotations.PrePersist;
import dev.morphia.annotations.Transient; import dev.morphia.annotations.Transient;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GenshinData; import emu.grasscutter.data.GenshinData;
import emu.grasscutter.data.common.FightPropData; import emu.grasscutter.data.common.FightPropData;
import emu.grasscutter.data.custom.OpenConfigEntry; import emu.grasscutter.data.custom.OpenConfigEntry;
...@@ -42,6 +43,7 @@ import emu.grasscutter.game.props.FightProperty; ...@@ -42,6 +43,7 @@ import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.net.proto.AvatarFetterInfoOuterClass.AvatarFetterInfo; import emu.grasscutter.net.proto.AvatarFetterInfoOuterClass.AvatarFetterInfo;
import emu.grasscutter.net.proto.AvatarInfoOuterClass.AvatarInfo; import emu.grasscutter.net.proto.AvatarInfoOuterClass.AvatarInfo;
import emu.grasscutter.server.packet.send.PacketAbilityChangeNotify;
import emu.grasscutter.server.packet.send.PacketAvatarEquipChangeNotify; import emu.grasscutter.server.packet.send.PacketAvatarEquipChangeNotify;
import emu.grasscutter.server.packet.send.PacketAvatarFightPropNotify; import emu.grasscutter.server.packet.send.PacketAvatarFightPropNotify;
import emu.grasscutter.utils.ProtoHelper; import emu.grasscutter.utils.ProtoHelper;
...@@ -69,7 +71,7 @@ public class GenshinAvatar { ...@@ -69,7 +71,7 @@ public class GenshinAvatar {
@Transient private final Int2ObjectMap<GenshinItem> equips; @Transient private final Int2ObjectMap<GenshinItem> equips;
@Transient private final Int2FloatOpenHashMap fightProp; @Transient private final Int2FloatOpenHashMap fightProp;
@Transient private final Set<String> bonusAbilityList; @Transient private Set<String> extraAbilityEmbryos;
private Map<Integer, Integer> skillLevelMap; // Talent levels private Map<Integer, Integer> skillLevelMap; // Talent levels
private Map<Integer, Integer> proudSkillBonusMap; // Talent bonus levels (from const) private Map<Integer, Integer> proudSkillBonusMap; // Talent bonus levels (from const)
...@@ -86,7 +88,7 @@ public class GenshinAvatar { ...@@ -86,7 +88,7 @@ public class GenshinAvatar {
// Morhpia only! // Morhpia only!
this.equips = new Int2ObjectOpenHashMap<>(); this.equips = new Int2ObjectOpenHashMap<>();
this.fightProp = new Int2FloatOpenHashMap(); this.fightProp = new Int2FloatOpenHashMap();
this.bonusAbilityList = new HashSet<>(); this.extraAbilityEmbryos = new HashSet<>();
this.proudSkillBonusMap = new HashMap<>(); // TODO Move to genshin avatar this.proudSkillBonusMap = new HashMap<>(); // TODO Move to genshin avatar
} }
...@@ -260,8 +262,8 @@ public class GenshinAvatar { ...@@ -260,8 +262,8 @@ public class GenshinAvatar {
return proudSkillBonusMap; return proudSkillBonusMap;
} }
public Set<String> getBonusAbilityList() { public Set<String> getExtraAbilityEmbryos() {
return bonusAbilityList; return extraAbilityEmbryos;
} }
public float getCurrentHp() { public float getCurrentHp() {
...@@ -347,14 +349,14 @@ public class GenshinAvatar { ...@@ -347,14 +349,14 @@ public class GenshinAvatar {
item.setEquipCharacter(this.getAvatarId()); item.setEquipCharacter(this.getAvatarId());
item.save(); item.save();
if (this.getPlayer().hasSentAvatarDataNotify()) {
this.getPlayer().sendPacket(new PacketAvatarEquipChangeNotify(this, item));
}
if (shouldRecalc) { if (shouldRecalc) {
this.recalcStats(); this.recalcStats();
} }
if (this.getPlayer().hasSentAvatarDataNotify()) {
this.getPlayer().sendPacket(new PacketAvatarEquipChangeNotify(this, item));
}
return true; return true;
} }
...@@ -371,11 +373,18 @@ public class GenshinAvatar { ...@@ -371,11 +373,18 @@ public class GenshinAvatar {
} }
public void recalcStats() { public void recalcStats() {
recalcStats(false);
}
public void recalcStats(boolean forceSendAbilityChange) {
// Setup // Setup
AvatarData data = this.getAvatarData(); AvatarData data = this.getAvatarData();
AvatarPromoteData promoteData = GenshinData.getAvatarPromoteData(data.getAvatarPromoteId(), this.getPromoteLevel()); AvatarPromoteData promoteData = GenshinData.getAvatarPromoteData(data.getAvatarPromoteId(), this.getPromoteLevel());
Int2IntOpenHashMap setMap = new Int2IntOpenHashMap(); Int2IntOpenHashMap setMap = new Int2IntOpenHashMap();
this.getBonusAbilityList().clear();
// Extra ability embryos
Set<String> prevExtraAbilityEmbryos = this.getExtraAbilityEmbryos();
this.extraAbilityEmbryos = new HashSet<>();
// Get hp percent, set to 100% if none // Get hp percent, set to 100% if none
float hpPercent = this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) <= 0 ? 1f : this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) / this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP); float hpPercent = this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) <= 0 ? 1f : this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) / this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
...@@ -458,7 +467,7 @@ public class GenshinAvatar { ...@@ -458,7 +467,7 @@ public class GenshinAvatar {
} }
// Add any skill strings from this affix // Add any skill strings from this affix
this.addToAbilityList(affix.getOpenConfig(), true); this.addToExtraAbilityEmbryos(affix.getOpenConfig(), true);
} else { } else {
break; break;
} }
...@@ -505,7 +514,7 @@ public class GenshinAvatar { ...@@ -505,7 +514,7 @@ public class GenshinAvatar {
} }
// Add any skill strings from this affix // Add any skill strings from this affix
this.addToAbilityList(affix.getOpenConfig(), true); this.addToExtraAbilityEmbryos(affix.getOpenConfig(), true);
} }
} }
} }
...@@ -538,7 +547,7 @@ public class GenshinAvatar { ...@@ -538,7 +547,7 @@ public class GenshinAvatar {
} }
// Add any skill strings from this proud skill // Add any skill strings from this proud skill
this.addToAbilityList(proudSkillData.getOpenConfig(), true); this.addToExtraAbilityEmbryos(proudSkillData.getOpenConfig(), true);
} }
// Constellations // Constellations
...@@ -550,7 +559,7 @@ public class GenshinAvatar { ...@@ -550,7 +559,7 @@ public class GenshinAvatar {
} }
// Add any skill strings from this constellation // Add any skill strings from this constellation
this.addToAbilityList(avatarTalentData.getOpenConfig(), false); this.addToExtraAbilityEmbryos(avatarTalentData.getOpenConfig(), false);
} }
} }
...@@ -573,11 +582,17 @@ public class GenshinAvatar { ...@@ -573,11 +582,17 @@ public class GenshinAvatar {
// Packet // Packet
if (getPlayer() != null && getPlayer().hasSentAvatarDataNotify()) { if (getPlayer() != null && getPlayer().hasSentAvatarDataNotify()) {
// Update stats for client
getPlayer().sendPacket(new PacketAvatarFightPropNotify(this)); getPlayer().sendPacket(new PacketAvatarFightPropNotify(this));
// Update client abilities
EntityAvatar entity = this.getAsEntity();
if (entity != null && (!this.getExtraAbilityEmbryos().equals(prevExtraAbilityEmbryos) || forceSendAbilityChange)) {
getPlayer().sendPacket(new PacketAbilityChangeNotify(entity));
}
} }
} }
public void addToAbilityList(String openConfig, boolean forceAdd) { public void addToExtraAbilityEmbryos(String openConfig, boolean forceAdd) {
if (openConfig == null || openConfig.length() == 0) { if (openConfig == null || openConfig.length() == 0) {
return; return;
} }
...@@ -586,14 +601,14 @@ public class GenshinAvatar { ...@@ -586,14 +601,14 @@ public class GenshinAvatar {
if (entry == null) { if (entry == null) {
if (forceAdd) { if (forceAdd) {
// Add config string to ability skill list anyways // Add config string to ability skill list anyways
this.getBonusAbilityList().add(openConfig); this.getExtraAbilityEmbryos().add(openConfig);
} }
return; return;
} }
if (entry.getAddAbilities() != null) { if (entry.getAddAbilities() != null) {
for (String ability : entry.getAddAbilities()) { for (String ability : entry.getAddAbilities()) {
this.getBonusAbilityList().add(ability); this.getExtraAbilityEmbryos().add(ability);
} }
} }
} }
......
...@@ -223,8 +223,8 @@ public class EntityAvatar extends GenshinEntity { ...@@ -223,8 +223,8 @@ public class EntityAvatar extends GenshinEntity {
} }
} }
// Add equip abilities // Add equip abilities
if (this.getAvatar().getBonusAbilityList().size() > 0) { if (this.getAvatar().getExtraAbilityEmbryos().size() > 0) {
for (String skill : this.getAvatar().getBonusAbilityList()) { for (String skill : this.getAvatar().getExtraAbilityEmbryos()) {
AbilityEmbryo emb = AbilityEmbryo.newBuilder() AbilityEmbryo emb = AbilityEmbryo.newBuilder()
.setAbilityId(++embryoId) .setAbilityId(++embryoId)
.setAbilityNameHash(Utils.abilityHash(skill)) .setAbilityNameHash(Utils.abilityHash(skill))
......
...@@ -589,7 +589,6 @@ public class InventoryManager { ...@@ -589,7 +589,6 @@ public class InventoryManager {
// Update proud skills // Update proud skills
AvatarSkillDepotData skillDepot = GenshinData.getAvatarSkillDepotDataMap().get(avatar.getSkillDepotId()); AvatarSkillDepotData skillDepot = GenshinData.getAvatarSkillDepotDataMap().get(avatar.getSkillDepotId());
boolean hasAddedProudSkill = false;
if (skillDepot != null && skillDepot.getInherentProudSkillOpens() != null) { if (skillDepot != null && skillDepot.getInherentProudSkillOpens() != null) {
for (InherentProudSkillOpens openData : skillDepot.getInherentProudSkillOpens()) { for (InherentProudSkillOpens openData : skillDepot.getInherentProudSkillOpens()) {
...@@ -599,7 +598,6 @@ public class InventoryManager { ...@@ -599,7 +598,6 @@ public class InventoryManager {
if (openData.getNeedAvatarPromoteLevel() == avatar.getPromoteLevel()) { if (openData.getNeedAvatarPromoteLevel() == avatar.getPromoteLevel()) {
int proudSkillId = (openData.getProudSkillGroupId() * 100) + 1; int proudSkillId = (openData.getProudSkillGroupId() * 100) + 1;
if (GenshinData.getProudSkillDataMap().containsKey(proudSkillId)) { if (GenshinData.getProudSkillDataMap().containsKey(proudSkillId)) {
hasAddedProudSkill = true;
avatar.getProudSkillList().add(proudSkillId); avatar.getProudSkillList().add(proudSkillId);
player.sendPacket(new PacketProudSkillChangeNotify(avatar)); player.sendPacket(new PacketProudSkillChangeNotify(avatar));
} }
...@@ -607,20 +605,13 @@ public class InventoryManager { ...@@ -607,20 +605,13 @@ public class InventoryManager {
} }
} }
// Racalc stats and save avatar
avatar.recalcStats();
avatar.save();
// Resend ability embryos if proud skill has been added
if (hasAddedProudSkill && avatar.getAsEntity() != null) {
player.sendPacket(new PacketAbilityChangeNotify(avatar.getAsEntity()));
}
// TODO Send entity prop update packet to world
// Packets // Packets
player.sendPacket(new PacketAvatarPropNotify(avatar)); player.sendPacket(new PacketAvatarPropNotify(avatar));
player.sendPacket(new PacketAvatarPromoteRsp(avatar)); player.sendPacket(new PacketAvatarPromoteRsp(avatar));
// TODO Send entity prop update packet to world
avatar.recalcStats(true);
avatar.save();
} }
public void upgradeAvatar(GenshinPlayer player, long guid, int itemId, int count) { public void upgradeAvatar(GenshinPlayer player, long guid, int itemId, int count) {
...@@ -827,25 +818,20 @@ public class InventoryManager { ...@@ -827,25 +818,20 @@ public class InventoryManager {
// Apply + recalc // Apply + recalc
avatar.getTalentIdList().add(talentData.getId()); avatar.getTalentIdList().add(talentData.getId());
avatar.setCoreProudSkillLevel(currentTalentLevel + 1); avatar.setCoreProudSkillLevel(currentTalentLevel + 1);
avatar.recalcStats();
// Packet // Packet
player.sendPacket(new PacketAvatarUnlockTalentNotify(avatar, nextTalentId)); player.sendPacket(new PacketAvatarUnlockTalentNotify(avatar, nextTalentId));
player.sendPacket(new PacketUnlockAvatarTalentRsp(avatar, nextTalentId)); player.sendPacket(new PacketUnlockAvatarTalentRsp(avatar, nextTalentId));
// Proud skill bonus map // Proud skill bonus map (Extra skills)
OpenConfigEntry entry = GenshinData.getOpenConfigEntries().get(talentData.getOpenConfig()); OpenConfigEntry entry = GenshinData.getOpenConfigEntries().get(talentData.getOpenConfig());
if (entry != null && entry.getExtraTalentIndex() > 0) { if (entry != null && entry.getExtraTalentIndex() > 0) {
avatar.recalcProudSkillBonusMap(); avatar.recalcProudSkillBonusMap();
player.sendPacket(new PacketProudSkillExtraLevelNotify(avatar, entry.getExtraTalentIndex())); player.sendPacket(new PacketProudSkillExtraLevelNotify(avatar, entry.getExtraTalentIndex()));
} }
// Resend ability embryos // Recalc + save avatar
if (avatar.getAsEntity() != null) { avatar.recalcStats(true);
player.sendPacket(new PacketAbilityChangeNotify(avatar.getAsEntity()));
}
// Save avatar
avatar.save(); avatar.save();
} }
......
...@@ -8,8 +8,8 @@ import emu.grasscutter.net.proto.AbilityChangeNotifyOuterClass.AbilityChangeNoti ...@@ -8,8 +8,8 @@ import emu.grasscutter.net.proto.AbilityChangeNotifyOuterClass.AbilityChangeNoti
public class PacketAbilityChangeNotify extends GenshinPacket { public class PacketAbilityChangeNotify extends GenshinPacket {
public PacketAbilityChangeNotify(EntityAvatar entity) { public PacketAbilityChangeNotify(EntityAvatar entity) {
super(PacketOpcodes.AbilityChangeNotify); super(PacketOpcodes.AbilityChangeNotify, true);
AbilityChangeNotify proto = AbilityChangeNotify.newBuilder() AbilityChangeNotify proto = AbilityChangeNotify.newBuilder()
.setEntityId(entity.getId()) .setEntityId(entity.getId())
.setAbilityControlBlock(entity.getAbilityControlBlock()) .setAbilityControlBlock(entity.getAbilityControlBlock())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment