mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-15 08:25:21 +01:00
Refactor out some EntrySets
This commit is contained in:
@@ -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;
|
||||
val setNeedNum = setData.getSetNeedNum();
|
||||
for (int setIndex = 0; setIndex < setNeedNum.length; setIndex++) {
|
||||
if (amount < setNeedNum[setIndex]) break;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
// Add any skill strings from this affix
|
||||
this.addToExtraAbilityEmbryos(affix.getOpenConfig(), true);
|
||||
} else {
|
||||
break;
|
||||
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());
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user