From 1ecc3f43905d4d29f409d86654aa113bc948b2af Mon Sep 17 00:00:00 2001 From: AnimeGitB Date: Mon, 17 Oct 2022 16:13:28 +1030 Subject: [PATCH] Remove constellation charge and talent level bonuses from db --- .../java/emu/grasscutter/data/GameData.java | 4 ++ .../emu/grasscutter/data/ResourceLoader.java | 5 +++ .../emu/grasscutter/game/avatar/Avatar.java | 42 +++++++------------ .../grasscutter/game/entity/EntityAvatar.java | 31 +++++++------- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/main/java/emu/grasscutter/data/GameData.java b/src/main/java/emu/grasscutter/data/GameData.java index ea9114572..bcaacb3e0 100644 --- a/src/main/java/emu/grasscutter/data/GameData.java +++ b/src/main/java/emu/grasscutter/data/GameData.java @@ -12,6 +12,8 @@ import emu.grasscutter.data.binout.*; import emu.grasscutter.game.quest.QuestEncryptionKey; import emu.grasscutter.utils.Utils; import emu.grasscutter.data.excels.*; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; @@ -124,6 +126,7 @@ public class GameData { private static Map> fetters = new HashMap<>(); private static Map> shopGoods = new HashMap<>(); protected static Int2ObjectMap proudSkillGroupLevels = new Int2ObjectOpenHashMap<>(); + protected static Int2IntMap proudSkillGroupMaxLevels = new Int2IntOpenHashMap(); protected static Int2ObjectMap avatarSkillLevels = new Int2ObjectOpenHashMap<>(); // Getters with wrong names, remove later @@ -141,6 +144,7 @@ public class GameData { public static AbilityData getAbilityData(String abilityName) {return abilityDataMap.get(abilityName);} public static IntSet getAvatarSkillLevels(int avatarSkillId) {return avatarSkillLevels.get(avatarSkillId);} public static IntSet getProudSkillGroupLevels(int proudSkillGroupId) {return proudSkillGroupLevels.get(proudSkillGroupId);} + public static int getProudSkillGroupMaxLevel(int proudSkillGroupId) {return proudSkillGroupMaxLevels.getOrDefault(proudSkillGroupId, 0);} // Multi-keyed getters public static AvatarPromoteData getAvatarPromoteData(int promoteId, int promoteLevel) { diff --git a/src/main/java/emu/grasscutter/data/ResourceLoader.java b/src/main/java/emu/grasscutter/data/ResourceLoader.java index a1f97d88f..b44a2efac 100644 --- a/src/main/java/emu/grasscutter/data/ResourceLoader.java +++ b/src/main/java/emu/grasscutter/data/ResourceLoader.java @@ -172,12 +172,17 @@ public class ResourceLoader { } private static void cacheTalentLevelSets() { + // All known levels, keyed by proudSkillGroupId GameData.getProudSkillDataMap().forEach((id, data) -> GameData.proudSkillGroupLevels .computeIfAbsent(data.getProudSkillGroupId(), i -> new IntArraySet()) .add(data.getLevel())); + // All known levels, keyed by avatarSkillId GameData.getAvatarSkillDataMap().forEach((id, data) -> GameData.avatarSkillLevels.put((int) id, GameData.proudSkillGroupLevels.get(data.getProudSkillGroupId()))); + // Maximum known levels, keyed by proudSkillGroupId + GameData.proudSkillGroupLevels.forEach((id, set) -> + GameData.proudSkillGroupMaxLevels.put((int) id, set.intStream().max().getAsInt())); } private static void loadAbilityEmbryos() { diff --git a/src/main/java/emu/grasscutter/game/avatar/Avatar.java b/src/main/java/emu/grasscutter/game/avatar/Avatar.java index abdbf5c85..d0d56b53d 100644 --- a/src/main/java/emu/grasscutter/game/avatar/Avatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/Avatar.java @@ -3,7 +3,6 @@ package emu.grasscutter.game.avatar; import static emu.grasscutter.config.Configuration.GAME_OPTIONS; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -60,6 +59,7 @@ import emu.grasscutter.net.proto.ShowEquipOuterClass.ShowEquip; import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.ProtoHelper; import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2IntArrayMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; @@ -95,9 +95,9 @@ public class Avatar { private List fetters; - private Map skillLevelMap; // Talent levels - private Map skillExtraChargeMap; // Charges - private Map proudSkillBonusMap; // Talent bonus levels (from const) + private Map skillLevelMap = new Int2IntArrayMap(7); // Talent levels + @Transient @Getter private Map skillExtraChargeMap = new Int2IntArrayMap(2); // Charges + @Transient private Map proudSkillBonusMap = new Int2IntArrayMap(2); // Talent bonus levels (from const) @Getter private int skillDepotId; private Set talentIdList; // Constellation id list @Getter private Set proudSkillList; // Character passives @@ -118,7 +118,6 @@ public class Avatar { this.fightProp = new Int2FloatOpenHashMap(); this.fightPropOverrides = new Int2FloatOpenHashMap(); this.extraAbilityEmbryos = new HashSet<>(); - this.proudSkillBonusMap = new HashMap<>(); this.fetters = new ArrayList<>(); // TODO Move to avatar } @@ -136,8 +135,6 @@ public class Avatar { this.bornTime = (int) (System.currentTimeMillis() / 1000); this.flyCloak = 140001; - this.skillLevelMap = new HashMap<>(); - this.skillExtraChargeMap = new HashMap<>(); this.talentIdList = new HashSet<>(); this.proudSkillList = new HashSet<>(); @@ -247,13 +244,6 @@ public class Avatar { this.recalcStats(); } - private Map getSkillExtraChargeMap() { - if (skillExtraChargeMap == null) { - skillExtraChargeMap = new HashMap<>(); - } - return skillExtraChargeMap; - } - public void setFetterList(List fetterList) { this.fetters = fetterList; } @@ -315,18 +305,16 @@ public class Avatar { // Returns a copy of the skill bonus levels for the current skillDepot, capped to avoid invalid levels. public Map getProudSkillBonusMap() { - var map = new Int2IntOpenHashMap(); + var map = new Int2IntArrayMap(); this.skillDepot.getSkillsAndEnergySkill().forEach(skillId -> { val skillData = GameData.getAvatarSkillDataMap().get(skillId); if (skillData == null) return; int proudSkillGroupId = skillData.getProudSkillGroupId(); int bonus = this.proudSkillBonusMap.getOrDefault(proudSkillGroupId, 0); - val validLevels = GameData.getProudSkillGroupLevels(proudSkillGroupId); - if (validLevels != null && validLevels.size() > 0) { - int maxLevel = validLevels.intStream().max().getAsInt(); - int maxBonus = maxLevel - this.skillLevelMap.getOrDefault(skillId, 0); - if (maxBonus < bonus) - bonus = maxBonus; + int maxLevel = GameData.getProudSkillGroupMaxLevel(proudSkillGroupId); + int curLevel = this.skillLevelMap.getOrDefault(skillId, 0); + if (maxLevel > 0) { + bonus = Math.min(bonus, maxLevel - curLevel); } map.put(proudSkillGroupId, bonus); }); @@ -678,8 +666,8 @@ public class Avatar { public void recalcConstellations() { // Clear first - this.getProudSkillBonusMap().clear(); - this.getSkillExtraChargeMap().clear(); + this.proudSkillBonusMap.clear(); + this.skillExtraChargeMap.clear(); // Sanity checks if (this.data == null || this.skillDepot == null) { @@ -732,7 +720,7 @@ public class Avatar { } // Add to bonus list - this.addProudSkillLevelBonus(skillId, 3); + this.addProudSkillLevelBonus(skillData.getProudSkillGroupId(), 3); return true; } @@ -834,9 +822,9 @@ public class Avatar { } public boolean sendSkillExtraChargeMap() { - var map = this.getSkillExtraChargeMap(); + val map = this.getSkillExtraChargeMap(); if (map.isEmpty()) return false; - this.getPlayer().sendPacket(new PacketAvatarSkillInfoNotify(this.guid, new Int2IntOpenHashMap(map))); + this.getPlayer().sendPacket(new PacketAvatarSkillInfoNotify(this.guid, new Int2IntArrayMap(map))); // TODO: Remove this allocation when updating interfaces to FastUtils later return true; } @@ -891,7 +879,7 @@ public class Avatar { .setCoreProudSkillLevel(this.getCoreProudSkillLevel()) .putAllSkillLevelMap(this.getSkillLevelMap()) .addAllInherentProudSkillList(this.getProudSkillList()) - .putAllProudSkillExtraLevelMap(getProudSkillBonusMap()) + .putAllProudSkillExtraLevelMap(this.getProudSkillBonusMap()) .setAvatarType(1) .setBornTime(this.getBornTime()) .setFetterInfo(avatarFetter) diff --git a/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java b/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java index ee9573911..7c04f4a4f 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java @@ -39,6 +39,7 @@ import emu.grasscutter.utils.ProtoHelper; import emu.grasscutter.utils.Utils; import it.unimi.dsi.fastutil.ints.Int2FloatMap; import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap; +import lombok.val; public class EntityAvatar extends GameEntity { private final Avatar avatar; @@ -193,21 +194,23 @@ public class EntityAvatar extends GameEntity { } public SceneAvatarInfo getSceneAvatarInfo() { + val avatar = this.getAvatar(); + val player = this.getPlayer(); SceneAvatarInfo.Builder avatarInfo = SceneAvatarInfo.newBuilder() - .setUid(this.getPlayer().getUid()) - .setAvatarId(this.getAvatar().getAvatarId()) - .setGuid(this.getAvatar().getGuid()) - .setPeerId(this.getPlayer().getPeerId()) - .addAllTalentIdList(this.getAvatar().getTalentIdList()) - .setCoreProudSkillLevel(this.getAvatar().getCoreProudSkillLevel()) - .putAllSkillLevelMap(this.getAvatar().getSkillLevelMap()) - .setSkillDepotId(this.getAvatar().getSkillDepotId()) - .addAllInherentProudSkillList(this.getAvatar().getProudSkillList()) - .putAllProudSkillExtraLevelMap(this.getAvatar().getProudSkillBonusMap()) - .addAllTeamResonanceList(this.getAvatar().getPlayer().getTeamManager().getTeamResonances()) - .setWearingFlycloakId(this.getAvatar().getFlyCloak()) - .setCostumeId(this.getAvatar().getCostume()) - .setBornTime(this.getAvatar().getBornTime()); + .setUid(player.getUid()) + .setAvatarId(avatar.getAvatarId()) + .setGuid(avatar.getGuid()) + .setPeerId(player.getPeerId()) + .addAllTalentIdList(avatar.getTalentIdList()) + .setCoreProudSkillLevel(avatar.getCoreProudSkillLevel()) + .putAllSkillLevelMap(avatar.getSkillLevelMap()) + .setSkillDepotId(avatar.getSkillDepotId()) + .addAllInherentProudSkillList(avatar.getProudSkillList()) + .putAllProudSkillExtraLevelMap(avatar.getProudSkillBonusMap()) + .addAllTeamResonanceList(player.getTeamManager().getTeamResonances()) + .setWearingFlycloakId(avatar.getFlyCloak()) + .setCostumeId(avatar.getCostume()) + .setBornTime(avatar.getBornTime()); for (GameItem item : avatar.getEquips().values()) { if (item.getItemData().getEquipType() == EquipType.EQUIP_WEAPON) {