Commit 85f44ebd authored by AnimeGitB's avatar AnimeGitB
Browse files

Refactor out some EntrySets

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