Skip to content
Snippets Groups Projects
Commit 85f44ebd authored by AnimeGitB's avatar AnimeGitB
Browse files

Refactor out some EntrySets

parent b5f356ce
Branches
Tags
No related merge requests found
Showing
with 59 additions and 136 deletions
...@@ -467,37 +467,31 @@ public class Avatar { ...@@ -467,37 +467,31 @@ public class Avatar {
} }
// Set stuff // Set stuff
for (Int2IntOpenHashMap.Entry e : setMap.int2IntEntrySet()) { setMap.forEach((setId, amount) -> {
ReliquarySetData setData = GameData.getReliquarySetDataMap().get(e.getIntKey()); ReliquarySetData setData = GameData.getReliquarySetDataMap().get((int) setId);
if (setData == null) { if (setData == null) return;
continue;
}
// Calculate how many items are from the set // Calculate how many items are from the set
int amount = e.getIntValue();
// Add affix data from set bonus // Add affix data from set bonus
for (int setIndex = 0; setIndex < setData.getSetNeedNum().length; setIndex++) { val setNeedNum = setData.getSetNeedNum();
if (amount >= setData.getSetNeedNum()[setIndex]) { for (int setIndex = 0; setIndex < setNeedNum.length; setIndex++) {
int affixId = (setData.getEquipAffixId() * 10) + setIndex; if (amount < setNeedNum[setIndex]) break;
EquipAffixData affix = GameData.getEquipAffixDataMap().get(affixId); int affixId = (setData.getEquipAffixId() * 10) + setIndex;
if (affix == null) { EquipAffixData affix = GameData.getEquipAffixDataMap().get(affixId);
continue; if (affix == null) {
} continue;
}
// Add properties from this affix to our avatar
for (FightPropData prop : affix.getAddProps()) {
this.addFightProperty(prop.getProp(), prop.getValue());
}
// Add any skill strings from this affix // Add properties from this affix to our avatar
this.addToExtraAbilityEmbryos(affix.getOpenConfig(), true); for (FightPropData prop : affix.getAddProps()) {
} else { this.addFightProperty(prop.getProp(), prop.getValue());
break;
} }
// Add any skill strings from this affix
this.addToExtraAbilityEmbryos(affix.getOpenConfig(), true);
} }
} });
// Weapon // Weapon
GameItem weapon = this.getWeapon(); GameItem weapon = this.getWeapon();
......
...@@ -247,13 +247,7 @@ public class EntityAvatar extends GameEntity { ...@@ -247,13 +247,7 @@ public class EntityAvatar extends GameEntity {
entityInfo.setMotionInfo(this.getMotionInfo()); entityInfo.setMotionInfo(this.getMotionInfo());
} }
for (Int2FloatMap.Entry entry : getFightProperties().int2FloatEntrySet()) { this.addAllFightPropsToEntityInfo(entityInfo);
if (entry.getIntKey() == 0) {
continue;
}
FightPropPair fightProp = FightPropPair.newBuilder().setPropType(entry.getIntKey()).setPropValue(entry.getFloatValue()).build();
entityInfo.addFightPropList(fightProp);
}
PropPair pair = PropPair.newBuilder() PropPair pair = PropPair.newBuilder()
.setType(PlayerProperty.PROP_LEVEL.getId()) .setType(PlayerProperty.PROP_LEVEL.getId())
......
...@@ -217,7 +217,7 @@ public class EntityGadget extends EntityBaseGadget { ...@@ -217,7 +217,7 @@ public class EntityGadget extends EntityBaseGadget {
// We do not use the getter to null check because the getter will create a fight prop map if it is null // We do not use the getter to null check because the getter will create a fight prop map if it is null
if (this.fightProp != null) { if (this.fightProp != null) {
this.addAllFightPropsToEntityInfo(entityInfo); addAllFightPropsToEntityInfo(entityInfo);
} }
SceneGadgetInfo.Builder gadgetInfo = SceneGadgetInfo.newBuilder() SceneGadgetInfo.Builder gadgetInfo = SceneGadgetInfo.newBuilder()
......
...@@ -255,13 +255,7 @@ public class EntityMonster extends GameEntity { ...@@ -255,13 +255,7 @@ public class EntityMonster extends GameEntity {
.setEntityAuthorityInfo(authority) .setEntityAuthorityInfo(authority)
.setLifeState(this.getLifeState().getValue()); .setLifeState(this.getLifeState().getValue());
for (Int2FloatMap.Entry entry : getFightProperties().int2FloatEntrySet()) { this.addAllFightPropsToEntityInfo(entityInfo);
if (entry.getIntKey() == 0) {
continue;
}
FightPropPair fightProp = FightPropPair.newBuilder().setPropType(entry.getIntKey()).setPropValue(entry.getFloatValue()).build();
entityInfo.addFightPropList(fightProp);
}
PropPair pair = PropPair.newBuilder() PropPair pair = PropPair.newBuilder()
.setType(PlayerProperty.PROP_LEVEL.getId()) .setType(PlayerProperty.PROP_LEVEL.getId())
......
...@@ -122,14 +122,7 @@ public class EntityVehicle extends EntityBaseGadget { ...@@ -122,14 +122,7 @@ public class EntityVehicle extends EntityBaseGadget {
.setPropValue(ProtoHelper.newPropValue(PlayerProperty.PROP_LEVEL, 47)) .setPropValue(ProtoHelper.newPropValue(PlayerProperty.PROP_LEVEL, 47))
.build(); .build();
for (Int2FloatMap.Entry entry : getFightProperties().int2FloatEntrySet()) { this.addAllFightPropsToEntityInfo(entityInfo);
if (entry.getIntKey() == 0) {
continue;
}
FightPropPair fightProp = FightPropPair.newBuilder().setPropType(entry.getIntKey()).setPropValue(entry.getFloatValue()).build();
entityInfo.addFightPropList(fightProp);
}
entityInfo.addPropList(pair); entityInfo.addPropList(pair);
return entityInfo.build(); return entityInfo.build();
......
...@@ -113,13 +113,10 @@ public abstract class GameEntity { ...@@ -113,13 +113,10 @@ public abstract class GameEntity {
} }
public void addAllFightPropsToEntityInfo(SceneEntityInfo.Builder entityInfo) { public void addAllFightPropsToEntityInfo(SceneEntityInfo.Builder entityInfo) {
for (Int2FloatMap.Entry entry : this.getFightProperties().int2FloatEntrySet()) { this.getFightProperties().forEach((key, value) -> {
if (entry.getIntKey() == 0) { if (key == 0) return;
continue; entityInfo.addFightPropList(FightPropPair.newBuilder().setPropType(key).setPropValue(value).build());
} });
FightPropPair fightProp = FightPropPair.newBuilder().setPropType(entry.getIntKey()).setPropValue(entry.getFloatValue()).build();
entityInfo.addFightPropList(fightProp);
}
} }
protected MotionInfo getMotionInfo() { protected MotionInfo getMotionInfo() {
......
...@@ -93,14 +93,7 @@ public class EntityPlatform extends EntityBaseGadget { ...@@ -93,14 +93,7 @@ public class EntityPlatform extends EntityBaseGadget {
.setGadget(gadgetInfo) .setGadget(gadgetInfo)
.setLifeState(1); .setLifeState(1);
for (Int2FloatMap.Entry entry : getFightProperties().int2FloatEntrySet()) { this.addAllFightPropsToEntityInfo(entityInfo);
if (entry.getIntKey() == 0) {
continue;
}
FightPropPairOuterClass.FightPropPair fightProp = FightPropPairOuterClass.FightPropPair.newBuilder().setPropType(entry.getIntKey()).setPropValue(entry.getFloatValue()).build();
entityInfo.addFightPropList(fightProp);
}
return entityInfo.build(); return entityInfo.build();
} }
......
...@@ -89,16 +89,7 @@ public class EntitySolarIsotomaElevatorPlatform extends EntityPlatform { ...@@ -89,16 +89,7 @@ public class EntitySolarIsotomaElevatorPlatform extends EntityPlatform {
Grasscutter.getLogger().warn("Why gadget owner doesn't exist?"); Grasscutter.getLogger().warn("Why gadget owner doesn't exist?");
} }
for (var entry : getFightProperties().int2FloatEntrySet()) { this.addAllFightPropsToEntityInfo(info);
if (entry.getIntKey() == 0) {
continue;
}
var fightProp = FightPropPairOuterClass.FightPropPair.newBuilder()
.setPropType(entry.getIntKey())
.setPropValue(entry.getFloatValue())
.build();
info.addFightPropList(fightProp);
}
info.setLifeState(1) info.setLifeState(1)
.setGadget(gadget) .setGadget(gadget)
......
...@@ -172,16 +172,11 @@ public class CookingManager extends BasePlayerManager { ...@@ -172,16 +172,11 @@ public class CookingManager extends BasePlayerManager {
// Construct CookRecipeData protos. // Construct CookRecipeData protos.
List<CookRecipeDataOuterClass.CookRecipeData> data = new ArrayList<>(); List<CookRecipeDataOuterClass.CookRecipeData> data = new ArrayList<>();
for (var recipe : unlockedRecipes.entrySet()) { unlockedRecipes.forEach((recipeId, proficiency) ->
int recipeId = recipe.getKey(); data.add(CookRecipeDataOuterClass.CookRecipeData.newBuilder()
int proficiency = recipe.getValue();
CookRecipeDataOuterClass.CookRecipeData proto = CookRecipeDataOuterClass.CookRecipeData.newBuilder()
.setRecipeId(recipeId) .setRecipeId(recipeId)
.setProficiency(proficiency) .setProficiency(proficiency)
.build(); .build()));
data.add(proto);
}
// Send packet. // Send packet.
this.player.sendPacket(new PacketCookDataNotify(data)); this.player.sendPacket(new PacketCookDataNotify(data));
......
...@@ -304,9 +304,8 @@ public class StaminaManager extends BasePlayerManager { ...@@ -304,9 +304,8 @@ public class StaminaManager extends BasePlayerManager {
session.send(new PacketVehicleStaminaNotify(vehicleId, ((float) newStamina) / 100)); session.send(new PacketVehicleStaminaNotify(vehicleId, ((float) newStamina) / 100));
} }
// notify updated // notify updated
for (Map.Entry<String, AfterUpdateStaminaListener> listener : afterUpdateStaminaListeners.entrySet()) { int s = newStamina;
listener.getValue().onAfterUpdateStamina(reason, newStamina, isCharacterStamina); afterUpdateStaminaListeners.forEach((k, v) -> v.onAfterUpdateStamina(reason, s, isCharacterStamina));
}
return newStamina; return newStamina;
} }
......
...@@ -36,6 +36,7 @@ import emu.grasscutter.server.game.BaseGameSystem; ...@@ -36,6 +36,7 @@ import emu.grasscutter.server.game.BaseGameSystem;
import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
import it.unimi.dsi.fastutil.ints.Int2FloatArrayMap;
import it.unimi.dsi.fastutil.ints.Int2IntArrayMap; import it.unimi.dsi.fastutil.ints.Int2IntArrayMap;
import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
...@@ -634,7 +635,7 @@ public class InventorySystem extends BaseGameSystem { ...@@ -634,7 +635,7 @@ public class InventorySystem extends BaseGameSystem {
Map<Integer, Float> oldPropMap = avatar.getFightProperties(); Map<Integer, Float> oldPropMap = avatar.getFightProperties();
if (oldLevel != level) { if (oldLevel != level) {
// Deep copy if level has changed // Deep copy if level has changed
oldPropMap = avatar.getFightProperties().int2FloatEntrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); oldPropMap = new Int2FloatArrayMap(avatar.getFightProperties());
} }
// Done // Done
...@@ -696,7 +697,8 @@ public class InventorySystem extends BaseGameSystem { ...@@ -696,7 +697,8 @@ public class InventorySystem extends BaseGameSystem {
public void destroyMaterial(Player player, List<MaterialInfo> list) { public void destroyMaterial(Player player, List<MaterialInfo> list) {
// Return materials // Return materials
Int2IntOpenHashMap returnMaterialMap = new Int2IntOpenHashMap(); val returnMaterialMap = new Int2IntOpenHashMap();
val inventory = player.getInventory();
for (MaterialInfo info : list) { for (MaterialInfo info : list) {
// Sanity check // Sanity check
...@@ -704,28 +706,27 @@ public class InventorySystem extends BaseGameSystem { ...@@ -704,28 +706,27 @@ public class InventorySystem extends BaseGameSystem {
continue; continue;
} }
GameItem item = player.getInventory().getItemByGuid(info.getGuid()); GameItem item = inventory.getItemByGuid(info.getGuid());
if (item == null || !item.isDestroyable()) { if (item == null || !item.isDestroyable()) {
continue; continue;
} }
// Remove // Remove
int removeAmount = Math.min(info.getCount(), item.getCount()); int removeAmount = Math.min(info.getCount(), item.getCount());
player.getInventory().removeItem(item, removeAmount); inventory.removeItem(item, removeAmount);
// Delete material return items // Delete material return items
if (item.getItemData().getDestroyReturnMaterial().length > 0) { val data = item.getItemData();
for (int i = 0; i < item.getItemData().getDestroyReturnMaterial().length; i++) { if (data.getDestroyReturnMaterial().length > 0) {
returnMaterialMap.addTo(item.getItemData().getDestroyReturnMaterial()[i], item.getItemData().getDestroyReturnMaterialCount()[i]); for (int i = 0; i < data.getDestroyReturnMaterial().length; i++) {
returnMaterialMap.addTo(data.getDestroyReturnMaterial()[i], data.getDestroyReturnMaterialCount()[i]);
} }
} }
} }
// Give back items // Give back items
if (returnMaterialMap.size() > 0) { if (returnMaterialMap.size() > 0) {
for (Int2IntMap.Entry e : returnMaterialMap.int2IntEntrySet()) { returnMaterialMap.forEach((id, count) -> inventory.addItem(new GameItem(id, count)));
player.getInventory().addItem(new GameItem(e.getIntKey(), e.getIntValue()));
}
} }
// Packets // Packets
......
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import java.util.Map.Entry;
import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.player.TeamInfo;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.AvatarDataNotifyOuterClass.AvatarDataNotify; import emu.grasscutter.net.proto.AvatarDataNotifyOuterClass.AvatarDataNotify;
import emu.grasscutter.net.proto.AvatarTeamOuterClass.AvatarTeam;
public class PacketAvatarDataNotify extends BasePacket { public class PacketAvatarDataNotify extends BasePacket {
...@@ -21,21 +17,14 @@ public class PacketAvatarDataNotify extends BasePacket { ...@@ -21,21 +17,14 @@ public class PacketAvatarDataNotify extends BasePacket {
.addAllOwnedFlycloakList(player.getFlyCloakList()) .addAllOwnedFlycloakList(player.getFlyCloakList())
.addAllOwnedCostumeList(player.getCostumeList()); .addAllOwnedCostumeList(player.getCostumeList());
for (Avatar avatar : player.getAvatars()) { player.getAvatars().forEach(avatar -> proto.addAvatarList(avatar.toProto()));
proto.addAvatarList(avatar.toProto());
}
// Add the id list for custom teams. player.getTeamManager().getTeams().forEach((id, teamInfo) -> {
for (int id : player.getTeamManager().getTeams().keySet()) { proto.putAvatarTeamMap(id, teamInfo.toProto(player));
if (id > 4) { if (id > 4) { // Add the id list for custom teams.
proto.addCustomTeamIds(id); proto.addCustomTeamIds(id);
} }
} });
for (Entry<Integer, TeamInfo> entry : player.getTeamManager().getTeams().entrySet()) {
TeamInfo teamInfo = entry.getValue();
proto.putAvatarTeamMap(entry.getKey(), teamInfo.toProto(player));
}
// Set main character // Set main character
Avatar mainCharacter = player.getAvatars().getAvatarById(player.getMainCharacterId()); Avatar mainCharacter = player.getAvatars().getAvatarById(player.getMainCharacterId());
......
...@@ -12,7 +12,7 @@ public class PacketAvatarExpeditionAllDataRsp extends BasePacket { ...@@ -12,7 +12,7 @@ public class PacketAvatarExpeditionAllDataRsp extends BasePacket {
public PacketAvatarExpeditionAllDataRsp(Map<Long, ExpeditionInfo> expeditionInfo, int expeditionCountLimit) { public PacketAvatarExpeditionAllDataRsp(Map<Long, ExpeditionInfo> expeditionInfo, int expeditionCountLimit) {
super(PacketOpcodes.AvatarExpeditionAllDataRsp); super(PacketOpcodes.AvatarExpeditionAllDataRsp);
List<Integer> openExpeditionList = new ArrayList<>(List.of(306,305,304,303,302,301,206,105,204,104,203,103,202,101,102,201,106,205,401,402,403,404,405,406)); var openExpeditionList = List.of(306,305,304,303,302,301,206,105,204,104,203,103,202,101,102,201,106,205,401,402,403,404,405,406);
this.setData(AvatarExpeditionAllDataRsp.newBuilder() this.setData(AvatarExpeditionAllDataRsp.newBuilder()
.addAllOpenExpeditionList(openExpeditionList) .addAllOpenExpeditionList(openExpeditionList)
......
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import java.util.Map.Entry;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.player.TeamInfo;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.AvatarTeamOuterClass.AvatarTeam;
import emu.grasscutter.net.proto.AvatarTeamUpdateNotifyOuterClass.AvatarTeamUpdateNotify; import emu.grasscutter.net.proto.AvatarTeamUpdateNotifyOuterClass.AvatarTeamUpdateNotify;
public class PacketAvatarTeamUpdateNotify extends BasePacket { public class PacketAvatarTeamUpdateNotify extends BasePacket {
...@@ -17,10 +12,7 @@ public class PacketAvatarTeamUpdateNotify extends BasePacket { ...@@ -17,10 +12,7 @@ public class PacketAvatarTeamUpdateNotify extends BasePacket {
AvatarTeamUpdateNotify.Builder proto = AvatarTeamUpdateNotify.newBuilder(); AvatarTeamUpdateNotify.Builder proto = AvatarTeamUpdateNotify.newBuilder();
for (Entry<Integer, TeamInfo> entry : player.getTeamManager().getTeams().entrySet()) { player.getTeamManager().getTeams().forEach((id, teamInfo) -> proto.putAvatarTeamMap(id, teamInfo.toProto(player)));
TeamInfo teamInfo = entry.getValue();
proto.putAvatarTeamMap(entry.getKey(), teamInfo.toProto(player));
}
this.setData(proto); this.setData(proto);
} }
......
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import java.util.Map.Entry;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.player.TeamInfo;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.AvatarTeamOuterClass.AvatarTeam;
import emu.grasscutter.net.proto.CustomTeamListNotifyOuterClass.CustomTeamListNotify; import emu.grasscutter.net.proto.CustomTeamListNotifyOuterClass.CustomTeamListNotify;
public class PacketCustomTeamListNotify extends BasePacket { public class PacketCustomTeamListNotify extends BasePacket {
...@@ -24,10 +19,7 @@ public class PacketCustomTeamListNotify extends BasePacket { ...@@ -24,10 +19,7 @@ public class PacketCustomTeamListNotify extends BasePacket {
} }
// Add the avatar lists for all the teams the player has. // Add the avatar lists for all the teams the player has.
for (Entry<Integer, TeamInfo> entry : player.getTeamManager().getTeams().entrySet()) { player.getTeamManager().getTeams().forEach((id, teamInfo) -> proto.putAvatarTeamMap(id, teamInfo.toProto(player)));
TeamInfo teamInfo = entry.getValue();
proto.putAvatarTeamMap(entry.getKey(), teamInfo.toProto(player));
}
this.setData(proto); this.setData(proto);
} }
......
...@@ -4,19 +4,18 @@ import emu.grasscutter.net.packet.BasePacket; ...@@ -4,19 +4,18 @@ import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.DestroyMaterialRspOuterClass.DestroyMaterialRsp; import emu.grasscutter.net.proto.DestroyMaterialRspOuterClass.DestroyMaterialRsp;
import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
public class PacketDestroyMaterialRsp extends BasePacket { public class PacketDestroyMaterialRsp extends BasePacket {
public PacketDestroyMaterialRsp(Int2IntOpenHashMap returnMaterialMap) { public PacketDestroyMaterialRsp(Int2IntMap returnMaterialMap) {
super(PacketOpcodes.DestroyMaterialRsp); super(PacketOpcodes.DestroyMaterialRsp);
DestroyMaterialRsp.Builder proto = DestroyMaterialRsp.newBuilder(); var proto = DestroyMaterialRsp.newBuilder();
for (Int2IntMap.Entry e : returnMaterialMap.int2IntEntrySet()) { returnMaterialMap.forEach((id, count) -> {
proto.addItemIdList(e.getIntKey()); proto.addItemIdList(id);
proto.addItemCountList(e.getIntValue()); proto.addItemCountList(count);
} });
this.setData(proto); this.setData(proto);
} }
......
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