mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-17 09:25:06 +01:00
Refactor avatar skilldepot and constellation/talent changing
Ensures Traveler retains talent levels and constellations on inactive elements when switching elements. Relevant for any other skillDepot-changing activities like Windtrace too, though keeping those in the db might not be as useful. Refactor avatar talent upgrade and access Refactor skillExtraCharges
This commit is contained in:
@@ -19,50 +19,49 @@ import emu.grasscutter.server.packet.send.PacketAvatarSkillDepotChangeNotify;
|
||||
|
||||
@Opcodes(PacketOpcodes.AvatarChangeElementTypeReq)
|
||||
public class HandlerAvatarChangeElementTypeReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||
AvatarChangeElementTypeReq req = AvatarChangeElementTypeReq.parseFrom(payload);
|
||||
|
||||
WorldAreaData area = GameData.getWorldAreaDataMap().get(req.getAreaId());
|
||||
|
||||
if (area == null || area.getElementType() == null || area.getElementType().getDepotValue() <= 0) {
|
||||
session.send(new PacketAvatarChangeElementTypeRsp(Retcode.RET_SVR_ERROR_VALUE));
|
||||
return;
|
||||
}
|
||||
|
||||
// Get current avatar, should be one of the main characters
|
||||
EntityAvatar mainCharacterEntity = session.getPlayer().getTeamManager().getCurrentAvatarEntity();
|
||||
|
||||
int intialSkillDepotId = 0;
|
||||
if (mainCharacterEntity.getAvatar().getAvatarId() == GameConstants.MAIN_CHARACTER_MALE) {
|
||||
intialSkillDepotId = 500;
|
||||
} else if (mainCharacterEntity.getAvatar().getAvatarId() == GameConstants.MAIN_CHARACTER_FEMALE) {
|
||||
intialSkillDepotId = 700;
|
||||
} else {
|
||||
session.send(new PacketAvatarChangeElementTypeRsp(Retcode.RET_SVR_ERROR_VALUE));
|
||||
return;
|
||||
}
|
||||
intialSkillDepotId += area.getElementType().getDepotValue();
|
||||
|
||||
// Sanity checks for skill depots
|
||||
Avatar mainCharacter = mainCharacterEntity.getAvatar();
|
||||
AvatarSkillDepotData skillDepot = GameData.getAvatarSkillDepotDataMap().get(intialSkillDepotId);
|
||||
if (skillDepot == null || skillDepot.getId() == mainCharacter.getSkillDepotId()) {
|
||||
session.send(new PacketAvatarChangeElementTypeRsp(Retcode.RET_SVR_ERROR_VALUE));
|
||||
return;
|
||||
}
|
||||
|
||||
// Success
|
||||
session.send(new PacketAvatarChangeElementTypeRsp());
|
||||
|
||||
// Set skill depot
|
||||
mainCharacter.setSkillDepotData(skillDepot);
|
||||
|
||||
// Ability change packet
|
||||
session.send(new PacketAvatarSkillDepotChangeNotify(mainCharacter));
|
||||
session.send(new PacketAbilityChangeNotify(mainCharacterEntity));
|
||||
session.send(new PacketAvatarFightPropNotify(mainCharacter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||
AvatarChangeElementTypeReq req = AvatarChangeElementTypeReq.parseFrom(payload);
|
||||
|
||||
WorldAreaData area = GameData.getWorldAreaDataMap().get(req.getAreaId());
|
||||
|
||||
if (area == null || area.getElementType() == null || area.getElementType().getDepotValue() <= 0) {
|
||||
session.send(new PacketAvatarChangeElementTypeRsp(Retcode.RET_SVR_ERROR_VALUE));
|
||||
return;
|
||||
}
|
||||
|
||||
// Get current avatar, should be one of the main characters
|
||||
EntityAvatar mainCharacterEntity = session.getPlayer().getTeamManager().getCurrentAvatarEntity();
|
||||
Avatar mainCharacter = mainCharacterEntity.getAvatar();
|
||||
|
||||
int skillDepotId = area.getElementType().getDepotValue();
|
||||
switch (mainCharacter.getAvatarId()) {
|
||||
case GameConstants.MAIN_CHARACTER_MALE -> skillDepotId += 500;
|
||||
case GameConstants.MAIN_CHARACTER_FEMALE -> skillDepotId += 700;
|
||||
default -> {
|
||||
session.send(new PacketAvatarChangeElementTypeRsp(Retcode.RET_SVR_ERROR_VALUE));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Sanity checks for skill depots
|
||||
AvatarSkillDepotData skillDepot = GameData.getAvatarSkillDepotDataMap().get(skillDepotId);
|
||||
if (skillDepot == null || skillDepot.getId() == mainCharacter.getSkillDepotId()) {
|
||||
session.send(new PacketAvatarChangeElementTypeRsp(Retcode.RET_SVR_ERROR_VALUE));
|
||||
return;
|
||||
}
|
||||
|
||||
// Set skill depot
|
||||
mainCharacter.setSkillDepotData(skillDepot);
|
||||
|
||||
// Success
|
||||
session.send(new PacketAvatarChangeElementTypeRsp());
|
||||
|
||||
// Ability change packet
|
||||
session.send(new PacketAvatarSkillDepotChangeNotify(mainCharacter));
|
||||
session.send(new PacketAbilityChangeNotify(mainCharacterEntity));
|
||||
session.send(new PacketAvatarFightPropNotify(mainCharacter));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ public class HandlerAvatarSkillUpgradeReq extends PacketHandler {
|
||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||
AvatarSkillUpgradeReq req = AvatarSkillUpgradeReq.parseFrom(payload);
|
||||
|
||||
// Sanity checks
|
||||
var avatar = session.getPlayer().getAvatars().getAvatarByGuid(req.getAvatarGuid());
|
||||
if (avatar == null) return;
|
||||
// Level up avatar talent
|
||||
session.getServer().getInventorySystem().upgradeAvatarSkill(session.getPlayer(), req.getAvatarGuid(), req.getAvatarSkillId());
|
||||
avatar.upgradeSkill(req.getAvatarSkillId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,9 @@ public class HandlerUnlockAvatarTalentReq extends PacketHandler {
|
||||
UnlockAvatarTalentReq req = UnlockAvatarTalentReq.parseFrom(payload);
|
||||
|
||||
// Unlock avatar const
|
||||
session.getServer().getInventorySystem().unlockAvatarConstellation(session.getPlayer(), req.getAvatarGuid());
|
||||
var avatar = session.getPlayer().getAvatars().getAvatarByGuid(req.getAvatarGuid());
|
||||
if (avatar == null) return;
|
||||
avatar.unlockConstellation(req.getTalentId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
package emu.grasscutter.server.packet.send;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import emu.grasscutter.game.avatar.Avatar;
|
||||
import emu.grasscutter.net.packet.BasePacket;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.AvatarSkillInfoNotifyOuterClass.AvatarSkillInfoNotify;
|
||||
import emu.grasscutter.net.proto.AvatarSkillInfoOuterClass.AvatarSkillInfo;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
|
||||
public class PacketAvatarSkillInfoNotify extends BasePacket {
|
||||
|
||||
public PacketAvatarSkillInfoNotify(Avatar avatar) {
|
||||
super(PacketOpcodes.AvatarSkillInfoNotify);
|
||||
public PacketAvatarSkillInfoNotify(long avatarGuid, Int2IntMap skillExtraChargeMap) {
|
||||
super(PacketOpcodes.AvatarSkillInfoNotify);
|
||||
|
||||
AvatarSkillInfoNotify.Builder proto = AvatarSkillInfoNotify.newBuilder()
|
||||
.setGuid(avatar.getGuid());
|
||||
|
||||
for (Entry<Integer, Integer> entry : avatar.getSkillExtraChargeMap().entrySet()) {
|
||||
proto.putSkillMap(entry.getKey(), AvatarSkillInfo.newBuilder().setMaxChargeCount(entry.getValue()).build());
|
||||
}
|
||||
|
||||
this.setData(proto);
|
||||
}
|
||||
var proto = AvatarSkillInfoNotify.newBuilder().setGuid(avatarGuid);
|
||||
|
||||
skillExtraChargeMap.forEach((skillId, count) ->
|
||||
proto.putSkillMap(skillId, AvatarSkillInfo.newBuilder().setMaxChargeCount(count).build()));
|
||||
|
||||
this.setData(proto);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user