From 025e5d3c1ce3f8e9972f411edbb7cd9af8902c75 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 13 Oct 2022 13:32:10 +0000 Subject: [PATCH] Fix whitespace [skip actions] --- .../java/emu/grasscutter/Grasscutter.java | 2 +- .../emu/grasscutter/data/ResourceLoader.java | 2 +- .../data/excels/DailyDungeonData.java | 68 +-- .../emu/grasscutter/data/excels/ItemData.java | 2 +- .../grasscutter/database/DatabaseManager.java | 10 +- .../emu/grasscutter/game/home/GameHome.java | 10 +- .../grasscutter/game/home/HomeSceneItem.java | 16 +- .../grasscutter/game/inventory/GameItem.java | 508 +++++++++--------- .../grasscutter/game/player/PlayerCodex.java | 12 +- .../props/ItemUseAction/ItemUseAddEnergy.java | 2 +- .../game/systems/InventorySystem.java | 2 +- .../game/world/WorldDataSystem.java | 4 +- .../emu/grasscutter/scripts/ScriptLoader.java | 128 ++--- .../recv/HandlerEvtCreateGadgetNotify.java | 20 +- .../packet/send/PacketSceneTimeNotify.java | 16 +- .../java/emu/grasscutter/utils/FileUtils.java | 160 +++--- 16 files changed, 481 insertions(+), 481 deletions(-) diff --git a/src/main/java/emu/grasscutter/Grasscutter.java b/src/main/java/emu/grasscutter/Grasscutter.java index 7f62b9f6e..57f22d11f 100644 --- a/src/main/java/emu/grasscutter/Grasscutter.java +++ b/src/main/java/emu/grasscutter/Grasscutter.java @@ -246,7 +246,7 @@ public final class Grasscutter { public static Language getLanguage(String langCode) { return Language.getLanguage(langCode); } - + public static ServerRunMode getRunMode() { return Grasscutter.runModeOverride != null ? Grasscutter.runModeOverride : SERVER.runMode; } diff --git a/src/main/java/emu/grasscutter/data/ResourceLoader.java b/src/main/java/emu/grasscutter/data/ResourceLoader.java index 6fbd64697..a1f97d88f 100644 --- a/src/main/java/emu/grasscutter/data/ResourceLoader.java +++ b/src/main/java/emu/grasscutter/data/ResourceLoader.java @@ -176,7 +176,7 @@ public class ResourceLoader { GameData.proudSkillGroupLevels .computeIfAbsent(data.getProudSkillGroupId(), i -> new IntArraySet()) .add(data.getLevel())); - GameData.getAvatarSkillDataMap().forEach((id, data) -> + GameData.getAvatarSkillDataMap().forEach((id, data) -> GameData.avatarSkillLevels.put((int) id, GameData.proudSkillGroupLevels.get(data.getProudSkillGroupId()))); } diff --git a/src/main/java/emu/grasscutter/data/excels/DailyDungeonData.java b/src/main/java/emu/grasscutter/data/excels/DailyDungeonData.java index 9f36ce980..1cf6f0a8d 100644 --- a/src/main/java/emu/grasscutter/data/excels/DailyDungeonData.java +++ b/src/main/java/emu/grasscutter/data/excels/DailyDungeonData.java @@ -10,39 +10,39 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; @ResourceType(name = "DailyDungeonConfigData.json") public class DailyDungeonData extends GameResource { - private int id; - private int[] monday; - private int[] tuesday; - private int[] wednesday; - private int[] thursday; - private int[] friday; - private int[] saturday; - private int[] sunday; - - private static final int[] empty = new int[0]; - private final Int2ObjectMap map; - - public DailyDungeonData() { - this.map = new Int2ObjectOpenHashMap<>(); - } - - @Override - public int getId() { - return this.id; - } - - public int[] getDungeonsByDay(int day) { - return map.getOrDefault(day, empty); - } + private int id; + private int[] monday; + private int[] tuesday; + private int[] wednesday; + private int[] thursday; + private int[] friday; + private int[] saturday; + private int[] sunday; - @Override - public void onLoad() { - map.put(Calendar.MONDAY, monday); - map.put(Calendar.TUESDAY, tuesday); - map.put(Calendar.WEDNESDAY, wednesday); - map.put(Calendar.THURSDAY, thursday); - map.put(Calendar.FRIDAY, friday); - map.put(Calendar.SATURDAY, saturday); - map.put(Calendar.SUNDAY, sunday); - } + private static final int[] empty = new int[0]; + private final Int2ObjectMap map; + + public DailyDungeonData() { + this.map = new Int2ObjectOpenHashMap<>(); + } + + @Override + public int getId() { + return this.id; + } + + public int[] getDungeonsByDay(int day) { + return map.getOrDefault(day, empty); + } + + @Override + public void onLoad() { + map.put(Calendar.MONDAY, monday); + map.put(Calendar.TUESDAY, tuesday); + map.put(Calendar.WEDNESDAY, wednesday); + map.put(Calendar.THURSDAY, thursday); + map.put(Calendar.FRIDAY, friday); + map.put(Calendar.SATURDAY, saturday); + map.put(Calendar.SUNDAY, sunday); + } } diff --git a/src/main/java/emu/grasscutter/data/excels/ItemData.java b/src/main/java/emu/grasscutter/data/excels/ItemData.java index 3fe1a57b3..7293f8c17 100644 --- a/src/main/java/emu/grasscutter/data/excels/ItemData.java +++ b/src/main/java/emu/grasscutter/data/excels/ItemData.java @@ -137,7 +137,7 @@ public class ItemData extends GameResource { } } - + @Getter public static class WeaponProperty { private FightProperty propType; diff --git a/src/main/java/emu/grasscutter/database/DatabaseManager.java b/src/main/java/emu/grasscutter/database/DatabaseManager.java index 3ff4cdeb2..a674b5fa4 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseManager.java +++ b/src/main/java/emu/grasscutter/database/DatabaseManager.java @@ -50,10 +50,10 @@ public final class DatabaseManager { // Set mapper options. MapperOptions mapperOptions = MapperOptions.builder() .storeEmpties(true).storeNulls(false).build(); - + // Create data store. gameDatastore = Morphia.createDatastore(gameMongoClient, DATABASE.game.collection, mapperOptions); - + // Map classes. Class[] entities = new Reflections(Grasscutter.class.getPackageName()) .getTypesAnnotatedWith(Entity.class) @@ -71,15 +71,15 @@ public final class DatabaseManager { if (SERVER.runMode == ServerRunMode.GAME_ONLY) { MongoClient dispatchMongoClient = MongoClients.create(DATABASE.server.connectionUri); - + dispatchDatastore = Morphia.createDatastore(dispatchMongoClient, DATABASE.server.collection, mapperOptions); dispatchDatastore.getMapper().map(new Class[] {DatabaseCounter.class, Account.class}); - + // Ensure indexes for dispatch datastore ensureIndexes(dispatchDatastore); } } - + /** * Ensures the database indexes exist and rebuilds them if there is an error with them * @param datastore The datastore to ensure indexes on diff --git a/src/main/java/emu/grasscutter/game/home/GameHome.java b/src/main/java/emu/grasscutter/game/home/GameHome.java index 73ef64580..7fb306491 100644 --- a/src/main/java/emu/grasscutter/game/home/GameHome.java +++ b/src/main/java/emu/grasscutter/game/home/GameHome.java @@ -39,11 +39,11 @@ public class GameHome { ConcurrentHashMap sceneMap; Set unlockedHomeBgmList; - public void save(){ + public void save() { DatabaseHelper.saveHome(this); } - public static GameHome getByUid(Integer uid){ + public static GameHome getByUid(Integer uid) { var home = DatabaseHelper.getHomeByUid(uid); if (home == null) { home = GameHome.create(uid); @@ -51,7 +51,7 @@ public class GameHome { return home; } - public static GameHome create(Integer uid){ + public static GameHome create(Integer uid) { return GameHome.of() .ownerUid(uid) .level(1) @@ -62,7 +62,7 @@ public class GameHome { public HomeSceneItem getHomeSceneItem(int sceneId) { return sceneMap.computeIfAbsent(sceneId, e -> { var defaultItem = GameData.getHomeworldDefaultSaveData().get(sceneId); - if (defaultItem != null){ + if (defaultItem != null) { Grasscutter.getLogger().info("Set player {} home {} to initial setting", ownerUid, sceneId); return HomeSceneItem.parseFrom(defaultItem, sceneId); } @@ -87,7 +87,7 @@ public class GameHome { return this.player; } - public HomeWorldLevelData getLevelData(){ + public HomeWorldLevelData getLevelData() { return GameData.getHomeWorldLevelDataMap().get(level); } diff --git a/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java b/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java index e61cb91b4..a5512a937 100644 --- a/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java +++ b/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java @@ -42,10 +42,10 @@ public class HomeSceneItem { .build(); } - public void update(HomeSceneArrangementInfo arrangementInfo){ - for(var blockItem : arrangementInfo.getBlockArrangementInfoListList()){ + public void update(HomeSceneArrangementInfo arrangementInfo) { + for (var blockItem : arrangementInfo.getBlockArrangementInfoListList()) { var block = this.blockItems.get(blockItem.getBlockId()); - if(block == null){ + if (block == null) { Grasscutter.getLogger().warn("Could not found the Home Block {}", blockItem.getBlockId()); continue; } @@ -61,20 +61,20 @@ public class HomeSceneItem { this.tmpVersion = arrangementInfo.getTmpVersion(); } - public int getRoomSceneId(){ - if(mainHouse == null || mainHouse.getAsItem() == null){ + public int getRoomSceneId() { + if (mainHouse == null || mainHouse.getAsItem() == null) { return 0; } return mainHouse.getAsItem().getRoomSceneId(); } - public int calComfort(){ + public int calComfort() { return this.blockItems.values().stream() .mapToInt(HomeBlockItem::calComfort) .sum(); } - public HomeSceneArrangementInfo toProto(){ + public HomeSceneArrangementInfo toProto() { var proto = HomeSceneArrangementInfo.newBuilder(); blockItems.values().forEach(b -> proto.addBlockArrangementInfoList(b.toProto())); @@ -87,7 +87,7 @@ public class HomeSceneItem { .setUnk2700BJHAMKKECEI(homeBgmId) .setTmpVersion(tmpVersion); - if(mainHouse != null){ + if (mainHouse != null) { proto.setMainHouse(mainHouse.toProto()); } return proto.build(); diff --git a/src/main/java/emu/grasscutter/game/inventory/GameItem.java b/src/main/java/emu/grasscutter/game/inventory/GameItem.java index 93dd4622a..cf979b073 100644 --- a/src/main/java/emu/grasscutter/game/inventory/GameItem.java +++ b/src/main/java/emu/grasscutter/game/inventory/GameItem.java @@ -39,59 +39,59 @@ import lombok.Setter; @Entity(value = "items", useDiscriminator = false) public class GameItem { - @Id private ObjectId id; - @Indexed private int ownerId; - @Getter @Setter private int itemId; - @Getter @Setter private int count; - - @Transient @Getter private long guid; // Player unique id - @Transient @Getter @Setter private ItemData itemData; - - // Equips - @Getter @Setter private int level; - @Getter @Setter private int exp; - @Getter @Setter private int totalExp; - @Getter @Setter private int promoteLevel; - @Getter @Setter private boolean locked; - - // Weapon - @Getter private List affixes; - @Getter @Setter private int refinement = 0; - - // Relic - @Getter @Setter private int mainPropId; - @Getter private List appendPropIdList; - - @Getter @Setter private int equipCharacter; - @Transient @Getter @Setter private int weaponEntityId; - - public GameItem() { - // Morphia only - } - - public GameItem(int itemId) { - this(GameData.getItemDataMap().get(itemId)); - } - - public GameItem(int itemId, int count) { - this(GameData.getItemDataMap().get(itemId), count); - } + @Id private ObjectId id; + @Indexed private int ownerId; + @Getter @Setter private int itemId; + @Getter @Setter private int count; + + @Transient @Getter private long guid; // Player unique id + @Transient @Getter @Setter private ItemData itemData; + + // Equips + @Getter @Setter private int level; + @Getter @Setter private int exp; + @Getter @Setter private int totalExp; + @Getter @Setter private int promoteLevel; + @Getter @Setter private boolean locked; + + // Weapon + @Getter private List affixes; + @Getter @Setter private int refinement = 0; + + // Relic + @Getter @Setter private int mainPropId; + @Getter private List appendPropIdList; + + @Getter @Setter private int equipCharacter; + @Transient @Getter @Setter private int weaponEntityId; + + public GameItem() { + // Morphia only + } + + public GameItem(int itemId) { + this(GameData.getItemDataMap().get(itemId)); + } + + public GameItem(int itemId, int count) { + this(GameData.getItemDataMap().get(itemId), count); + } + + public GameItem(ItemParamData itemParamData) { + this(itemParamData.getId(), itemParamData.getCount()); + } + + public GameItem(ItemData data) { + this(data, 1); + } + + public GameItem(ItemData data, int count) { + this.itemId = data.getId(); + this.itemData = data; - public GameItem(ItemParamData itemParamData) { - this(itemParamData.getId(), itemParamData.getCount()); - } - - public GameItem(ItemData data) { - this(data, 1); - } - - public GameItem(ItemData data, int count) { - this.itemId = data.getId(); - this.itemData = data; - switch (data.getItemType()) { case ITEM_VIRTUAL: - this.count = count; + this.count = count; break; case ITEM_WEAPON: this.count = 1; @@ -114,72 +114,72 @@ public class GameItem { if (mainPropData != null) { this.mainPropId = mainPropData.getId(); } - // Create extra stats + // Create extra stats this.addAppendProps(data.getAppendPropNum()); break; default: this.count = Math.min(count, data.getStackLimit()); - } - } + } + } - public int getOwnerId() { - return ownerId; - } + public int getOwnerId() { + return ownerId; + } - public void setOwner(Player player) { - this.ownerId = player.getUid(); - this.guid = player.getNextGameGuid(); - } + public void setOwner(Player player) { + this.ownerId = player.getUid(); + this.guid = player.getNextGameGuid(); + } - public ObjectId getObjectId() { - return id; - } - - public ItemType getItemType() { - return this.itemData.getItemType(); - } + public ObjectId getObjectId() { + return id; + } - public static int getMinPromoteLevel(int level) { - if (level > 80) { - return 6; - } else if (level > 70) { - return 5; - } else if (level > 60) { - return 4; - } else if (level > 50) { - return 3; - } else if (level > 40) { - return 2; - } else if (level > 20) { - return 1; - } - return 0; - } + public ItemType getItemType() { + return this.itemData.getItemType(); + } + + public static int getMinPromoteLevel(int level) { + if (level > 80) { + return 6; + } else if (level > 70) { + return 5; + } else if (level > 60) { + return 4; + } else if (level > 50) { + return 3; + } else if (level > 40) { + return 2; + } else if (level > 20) { + return 1; + } + return 0; + } + + public int getEquipSlot() { + return this.getItemData().getEquipType().getValue(); + } + + public boolean isEquipped() { + return this.getEquipCharacter() > 0; + } + + public boolean isDestroyable() { + return !this.isLocked() && !this.isEquipped(); + } + + public void addAppendProp() { + if (this.appendPropIdList == null) { + this.appendPropIdList = new ArrayList<>(); + } + + if (this.appendPropIdList.size() < 4) { + this.addNewAppendProp(); + } else { + this.upgradeRandomAppendProp(); + } + } - public int getEquipSlot() { - return this.getItemData().getEquipType().getValue(); - } - - public boolean isEquipped() { - return this.getEquipCharacter() > 0; - } - - public boolean isDestroyable() { - return !this.isLocked() && !this.isEquipped(); - } - - public void addAppendProp() { - if (this.appendPropIdList == null) { - this.appendPropIdList = new ArrayList<>(); - } - - if (this.appendPropIdList.size() < 4) { - this.addNewAppendProp(); - } else { - this.upgradeRandomAppendProp(); - } - } - public void addAppendProps(int quantity) { int num = Math.max(quantity, 0); for (int i = 0; i < num; i++) { @@ -199,165 +199,165 @@ public class GameItem { return props; } - private void addNewAppendProp() { + private void addNewAppendProp() { List affixList = GameDepot.getRelicAffixList(this.itemData.getAppendPropDepotId()); - - if (affixList == null) { - return; - } - - // Build blacklist - Dont add same stat as main/sub stat + + if (affixList == null) { + return; + } + + // Build blacklist - Dont add same stat as main/sub stat Set blacklist = this.getAppendFightProperties(); - ReliquaryMainPropData mainPropData = GameData.getReliquaryMainPropDataMap().get(this.mainPropId); - if (mainPropData != null) { - blacklist.add(mainPropData.getFightProp()); - } - - // Build random list - WeightedList randomList = new WeightedList<>(); - for (ReliquaryAffixData affix : affixList) { - if (!blacklist.contains(affix.getFightProp())) { - randomList.add(affix.getWeight(), affix); - } - } - - if (randomList.size() == 0) { - return; - } + ReliquaryMainPropData mainPropData = GameData.getReliquaryMainPropDataMap().get(this.mainPropId); + if (mainPropData != null) { + blacklist.add(mainPropData.getFightProp()); + } - // Add random stat - ReliquaryAffixData affixData = randomList.next(); - this.appendPropIdList.add(affixData.getId()); - } - - private void upgradeRandomAppendProp() { + // Build random list + WeightedList randomList = new WeightedList<>(); + for (ReliquaryAffixData affix : affixList) { + if (!blacklist.contains(affix.getFightProp())) { + randomList.add(affix.getWeight(), affix); + } + } + + if (randomList.size() == 0) { + return; + } + + // Add random stat + ReliquaryAffixData affixData = randomList.next(); + this.appendPropIdList.add(affixData.getId()); + } + + private void upgradeRandomAppendProp() { List affixList = GameDepot.getRelicAffixList(this.itemData.getAppendPropDepotId()); - - if (affixList == null) { - return; - } - - // Build whitelist + + if (affixList == null) { + return; + } + + // Build whitelist Set whitelist = this.getAppendFightProperties(); - - // Build random list - WeightedList randomList = new WeightedList<>(); - for (ReliquaryAffixData affix : affixList) { - if (whitelist.contains(affix.getFightProp())) { - randomList.add(affix.getUpgradeWeight(), affix); - } - } - - // Add random stat - ReliquaryAffixData affixData = randomList.next(); - this.appendPropIdList.add(affixData.getId()); - } - @PostLoad - public void onLoad() { - if (this.itemData == null) { - this.itemData = GameData.getItemDataMap().get(getItemId()); - } - } - - public void save() { - if (this.count > 0 && this.ownerId > 0) { - DatabaseHelper.saveItem(this); - } else if (this.getObjectId() != null) { - DatabaseHelper.deleteItem(this); - } - } - - public SceneWeaponInfo createSceneWeaponInfo() { - SceneWeaponInfo.Builder weaponInfo = SceneWeaponInfo.newBuilder() - .setEntityId(this.getWeaponEntityId()) - .setItemId(this.getItemId()) - .setGuid(this.getGuid()) - .setLevel(this.getLevel()) - .setGadgetId(this.getItemData().getGadgetId()) - .setAbilityInfo(AbilitySyncStateInfo.newBuilder().setIsInited(getAffixes().size() > 0)); - - if (this.getAffixes() != null && this.getAffixes().size() > 0) { - for (int affix : this.getAffixes()) { - weaponInfo.putAffixMap(affix, this.getRefinement()); - } - } - - return weaponInfo.build(); - } - - public SceneReliquaryInfo createSceneReliquaryInfo() { - SceneReliquaryInfo relicInfo = SceneReliquaryInfo.newBuilder() - .setItemId(this.getItemId()) - .setGuid(this.getGuid()) - .setLevel(this.getLevel()) - .build(); - - return relicInfo; - } + // Build random list + WeightedList randomList = new WeightedList<>(); + for (ReliquaryAffixData affix : affixList) { + if (whitelist.contains(affix.getFightProp())) { + randomList.add(affix.getUpgradeWeight(), affix); + } + } - public Weapon toWeaponProto() { - Weapon.Builder weapon = Weapon.newBuilder() - .setLevel(this.getLevel()) - .setExp(this.getExp()) - .setPromoteLevel(this.getPromoteLevel()); + // Add random stat + ReliquaryAffixData affixData = randomList.next(); + this.appendPropIdList.add(affixData.getId()); + } - if (this.getAffixes() != null && this.getAffixes().size() > 0) { - for (int affix : this.getAffixes()) { - weapon.putAffixMap(affix, this.getRefinement()); - } - } + @PostLoad + public void onLoad() { + if (this.itemData == null) { + this.itemData = GameData.getItemDataMap().get(getItemId()); + } + } - return weapon.build(); - } + public void save() { + if (this.count > 0 && this.ownerId > 0) { + DatabaseHelper.saveItem(this); + } else if (this.getObjectId() != null) { + DatabaseHelper.deleteItem(this); + } + } - public Reliquary toReliquaryProto() { - Reliquary.Builder relic = Reliquary.newBuilder() - .setLevel(this.getLevel()) - .setExp(this.getExp()) - .setPromoteLevel(this.getPromoteLevel()) - .setMainPropId(this.getMainPropId()) - .addAllAppendPropIdList(this.getAppendPropIdList()); + public SceneWeaponInfo createSceneWeaponInfo() { + SceneWeaponInfo.Builder weaponInfo = SceneWeaponInfo.newBuilder() + .setEntityId(this.getWeaponEntityId()) + .setItemId(this.getItemId()) + .setGuid(this.getGuid()) + .setLevel(this.getLevel()) + .setGadgetId(this.getItemData().getGadgetId()) + .setAbilityInfo(AbilitySyncStateInfo.newBuilder().setIsInited(getAffixes().size() > 0)); - return relic.build(); - } + if (this.getAffixes() != null && this.getAffixes().size() > 0) { + for (int affix : this.getAffixes()) { + weaponInfo.putAffixMap(affix, this.getRefinement()); + } + } - public Item toProto() { - Item.Builder proto = Item.newBuilder() - .setGuid(this.getGuid()) - .setItemId(this.getItemId()); - - switch (getItemType()) { - case ITEM_WEAPON: - Weapon weapon = this.toWeaponProto(); - proto.setEquip(Equip.newBuilder().setWeapon(weapon).setIsLocked(this.isLocked()).build()); - break; - case ITEM_RELIQUARY: - Reliquary relic = this.toReliquaryProto(); - proto.setEquip(Equip.newBuilder().setReliquary(relic).setIsLocked(this.isLocked()).build()); - break; - case ITEM_FURNITURE: - Furniture furniture = Furniture.newBuilder() - .setCount(getCount()) - .build(); - proto.setFurniture(furniture); - break; - default: - Material material = Material.newBuilder() - .setCount(getCount()) - .build(); - proto.setMaterial(material); - break; - } - - return proto.build(); - } + return weaponInfo.build(); + } - public ItemHint toItemHintProto() { - return ItemHint.newBuilder().setItemId(getItemId()).setCount(getCount()).setIsNew(false).build(); - } + public SceneReliquaryInfo createSceneReliquaryInfo() { + SceneReliquaryInfo relicInfo = SceneReliquaryInfo.newBuilder() + .setItemId(this.getItemId()) + .setGuid(this.getGuid()) + .setLevel(this.getLevel()) + .build(); - public ItemParam toItemParam() { - return ItemParam.newBuilder().setItemId(this.getItemId()).setCount(this.getCount()).build(); - } + return relicInfo; + } + + public Weapon toWeaponProto() { + Weapon.Builder weapon = Weapon.newBuilder() + .setLevel(this.getLevel()) + .setExp(this.getExp()) + .setPromoteLevel(this.getPromoteLevel()); + + if (this.getAffixes() != null && this.getAffixes().size() > 0) { + for (int affix : this.getAffixes()) { + weapon.putAffixMap(affix, this.getRefinement()); + } + } + + return weapon.build(); + } + + public Reliquary toReliquaryProto() { + Reliquary.Builder relic = Reliquary.newBuilder() + .setLevel(this.getLevel()) + .setExp(this.getExp()) + .setPromoteLevel(this.getPromoteLevel()) + .setMainPropId(this.getMainPropId()) + .addAllAppendPropIdList(this.getAppendPropIdList()); + + return relic.build(); + } + + public Item toProto() { + Item.Builder proto = Item.newBuilder() + .setGuid(this.getGuid()) + .setItemId(this.getItemId()); + + switch (getItemType()) { + case ITEM_WEAPON: + Weapon weapon = this.toWeaponProto(); + proto.setEquip(Equip.newBuilder().setWeapon(weapon).setIsLocked(this.isLocked()).build()); + break; + case ITEM_RELIQUARY: + Reliquary relic = this.toReliquaryProto(); + proto.setEquip(Equip.newBuilder().setReliquary(relic).setIsLocked(this.isLocked()).build()); + break; + case ITEM_FURNITURE: + Furniture furniture = Furniture.newBuilder() + .setCount(getCount()) + .build(); + proto.setFurniture(furniture); + break; + default: + Material material = Material.newBuilder() + .setCount(getCount()) + .build(); + proto.setMaterial(material); + break; + } + + return proto.build(); + } + + public ItemHint toItemHintProto() { + return ItemHint.newBuilder().setItemId(getItemId()).setCount(getCount()).setIsNew(false).build(); + } + + public ItemParam toItemParam() { + return ItemParam.newBuilder().setItemId(this.getItemId()).setCount(this.getCount()).build(); + } } diff --git a/src/main/java/emu/grasscutter/game/player/PlayerCodex.java b/src/main/java/emu/grasscutter/game/player/PlayerCodex.java index 57809f9d3..28d3d3546 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerCodex.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerCodex.java @@ -27,7 +27,7 @@ public class PlayerCodex { @Getter private Set unlockedReliquary; @Getter private Set unlockedReliquarySuitCodex; - public PlayerCodex(){ + public PlayerCodex() { this.unlockedWeapon = new HashSet<>(); this.unlockedAnimal = new HashMap<>(); this.unlockedMaterial = new HashSet<>(); @@ -38,7 +38,7 @@ public class PlayerCodex { this.unlockedReliquarySuitCodex = new HashSet<>(); } - public PlayerCodex(Player player){ + public PlayerCodex(Player player) { this(); this.player = player; } @@ -48,7 +48,7 @@ public class PlayerCodex { this.fixReliquaries(); } - public void checkAddedItem(GameItem item){ + public void checkAddedItem(GameItem item) { val itemData = item.getItemData(); val itemId = item.getItemId(); switch (itemData.getItemType()) { @@ -85,7 +85,7 @@ public class PlayerCodex { } } - public void checkAnimal(GameEntity target, CodexAnimalData.CountType countType){ + public void checkAnimal(GameEntity target, CodexAnimalData.CountType countType) { if (target instanceof EntityMonster) { val monsterId = ((EntityMonster) target).getMonsterData().getId(); val codexAnimal = GameData.getCodexAnimalDataMap().get(monsterId); @@ -101,7 +101,7 @@ public class PlayerCodex { } } - public void checkUnlockedSuits(int reliquaryId){ + public void checkUnlockedSuits(int reliquaryId) { GameData.getCodexReliquaryArrayList().stream() .filter(x -> !this.getUnlockedReliquarySuitCodex().contains(x.getId())) .filter(x -> x.containsId(reliquaryId)) @@ -127,4 +127,4 @@ public class PlayerCodex { .forEach(x -> this.getUnlockedReliquarySuitCodex().add(x.getId())); this.player.save(); } -} \ No newline at end of file +} diff --git a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAddEnergy.java b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAddEnergy.java index e02c6feb3..6f3074205 100644 --- a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAddEnergy.java +++ b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAddEnergy.java @@ -27,7 +27,7 @@ public abstract class ItemUseAddEnergy extends ItemUseAction { var activeTeam = teamManager.getActiveTeam(); // On-field vs off-field multiplier. // The on-field character gets full amount, off-field characters get less depending on the team size. - final float offFieldRatio = switch(activeTeam.size()) { + final float offFieldRatio = switch (activeTeam.size()) { case 2 -> 0.8f; case 3 -> 0.7f; default -> 0.6f; diff --git a/src/main/java/emu/grasscutter/game/systems/InventorySystem.java b/src/main/java/emu/grasscutter/game/systems/InventorySystem.java index 5c2afa758..5a2d49530 100644 --- a/src/main/java/emu/grasscutter/game/systems/InventorySystem.java +++ b/src/main/java/emu/grasscutter/game/systems/InventorySystem.java @@ -570,7 +570,7 @@ public class InventorySystem extends BaseGameSystem { // Calc exp int expGain = 0; - + var data = GameData.getItemDataMap().get(itemId); if (data != null) { var actions = data.getItemUseActions(); diff --git a/src/main/java/emu/grasscutter/game/world/WorldDataSystem.java b/src/main/java/emu/grasscutter/game/world/WorldDataSystem.java index 32e7fb954..0df4c69cf 100644 --- a/src/main/java/emu/grasscutter/game/world/WorldDataSystem.java +++ b/src/main/java/emu/grasscutter/game/world/WorldDataSystem.java @@ -85,10 +85,10 @@ public class WorldDataSystem extends BaseGameSystem { return level; } private InvestigationMonsterOuterClass.InvestigationMonster getInvestigationMonster(Player player, InvestigationMonsterData imd) { - if(imd.getGroupIdList().isEmpty() || imd.getMonsterIdList().isEmpty()){ + if (imd.getGroupIdList().isEmpty() || imd.getMonsterIdList().isEmpty()) { return null; } - + var groupId = imd.getGroupIdList().get(0); var monsterId = imd.getMonsterIdList().get(0); var sceneId = imd.getCityData().getSceneId(); diff --git a/src/main/java/emu/grasscutter/scripts/ScriptLoader.java b/src/main/java/emu/grasscutter/scripts/ScriptLoader.java index 84e3e784c..54efe768f 100644 --- a/src/main/java/emu/grasscutter/scripts/ScriptLoader.java +++ b/src/main/java/emu/grasscutter/scripts/ScriptLoader.java @@ -30,28 +30,28 @@ import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; public class ScriptLoader { - private static ScriptEngineManager sm; + private static ScriptEngineManager sm; @Getter private static ScriptEngine engine; - private static ScriptEngineFactory factory; + private static ScriptEngineFactory factory; @Getter private static Serializer serializer; @Getter private static ScriptLib scriptLib; @Getter private static LuaValue scriptLibLua; - /** - * suggest GC to remove it if the memory is less - */ - private static Map> scriptsCache = new ConcurrentHashMap<>(); - /** - * sceneId - SceneMeta - */ - private static Map> sceneMetaCache = new ConcurrentHashMap<>(); + /** + * suggest GC to remove it if the memory is less + */ + private static Map> scriptsCache = new ConcurrentHashMap<>(); + /** + * sceneId - SceneMeta + */ + private static Map> sceneMetaCache = new ConcurrentHashMap<>(); - public synchronized static void init() throws Exception { - if (sm != null) { - throw new Exception("Script loader already initialized"); - } + public synchronized static void init() throws Exception { + if (sm != null) { + throw new Exception("Script loader already initialized"); + } - // Create script engine - sm = new ScriptEngineManager(); + // Create script engine + sm = new ScriptEngineManager(); engine = sm.getEngineByName("luaj"); factory = getEngine().getFactory(); @@ -60,61 +60,61 @@ public class ScriptLoader { // Set engine to replace require as a temporary fix to missing scripts LuajContext ctx = (LuajContext) engine.getContext(); - ctx.globals.set("require", new OneArgFunction() { - @Override - public LuaValue call(LuaValue arg0) { - return LuaValue.ZERO; - } - }); + ctx.globals.set("require", new OneArgFunction() { + @Override + public LuaValue call(LuaValue arg0) { + return LuaValue.ZERO; + } + }); - LuaTable table = new LuaTable(); - Arrays.stream(EntityType.values()).forEach(e -> table.set(e.name().toUpperCase(), e.getValue())); - ctx.globals.set("EntityType", table); + LuaTable table = new LuaTable(); + Arrays.stream(EntityType.values()).forEach(e -> table.set(e.name().toUpperCase(), e.getValue())); + ctx.globals.set("EntityType", table); LuaTable table1 = new LuaTable(); Arrays.stream(QuestState.values()).forEach(e -> table1.set(e.name().toUpperCase(), e.getValue())); ctx.globals.set("QuestState", table1); - ctx.globals.set("EventType", CoerceJavaToLua.coerce(new EventType())); // TODO - make static class to avoid instantiating a new class every scene - ctx.globals.set("GadgetState", CoerceJavaToLua.coerce(new ScriptGadgetState())); - ctx.globals.set("RegionShape", CoerceJavaToLua.coerce(new ScriptRegionShape())); + ctx.globals.set("EventType", CoerceJavaToLua.coerce(new EventType())); // TODO - make static class to avoid instantiating a new class every scene + ctx.globals.set("GadgetState", CoerceJavaToLua.coerce(new ScriptGadgetState())); + ctx.globals.set("RegionShape", CoerceJavaToLua.coerce(new ScriptRegionShape())); - scriptLib = new ScriptLib(); - scriptLibLua = CoerceJavaToLua.coerce(scriptLib); - ctx.globals.set("ScriptLib", scriptLibLua); - } + scriptLib = new ScriptLib(); + scriptLibLua = CoerceJavaToLua.coerce(scriptLib); + ctx.globals.set("ScriptLib", scriptLibLua); + } - public static Optional tryGet(SoftReference softReference){ - try{ - return Optional.ofNullable(softReference.get()); - }catch (NullPointerException npe){ - return Optional.empty(); - } - } + public static Optional tryGet(SoftReference softReference) { + try { + return Optional.ofNullable(softReference.get()); + }catch (NullPointerException npe) { + return Optional.empty(); + } + } - @Deprecated(forRemoval = true) - public static CompiledScript getScriptByPath(String path) { - var sc = tryGet(scriptsCache.get(path)); - if (sc.isPresent()) { - return sc.get(); - } + @Deprecated(forRemoval = true) + public static CompiledScript getScriptByPath(String path) { + var sc = tryGet(scriptsCache.get(path)); + if (sc.isPresent()) { + return sc.get(); + } - Grasscutter.getLogger().debug("Loading script " + path); + Grasscutter.getLogger().debug("Loading script " + path); - File file = new File(path); + File file = new File(path); - if (!file.exists()) return null; + if (!file.exists()) return null; - try (FileReader fr = new FileReader(file)) { - var script = ((Compilable) getEngine()).compile(fr); - scriptsCache.put(path, new SoftReference<>(script)); - return script; - } catch (Exception e) { - Grasscutter.getLogger().error("Loading script {} failed!", path, e); - return null; - } + try (FileReader fr = new FileReader(file)) { + var script = ((Compilable) getEngine()).compile(fr); + scriptsCache.put(path, new SoftReference<>(script)); + return script; + } catch (Exception e) { + Grasscutter.getLogger().error("Loading script {} failed!", path, e); + return null; + } - } + } public static CompiledScript getScript(String path) { var sc = tryGet(scriptsCache.get(path)); @@ -136,12 +136,12 @@ public class ScriptLoader { } } - public static SceneMeta getSceneMeta(int sceneId) { - return tryGet(sceneMetaCache.get(sceneId)).orElseGet(() -> { - var instance = SceneMeta.of(sceneId); - sceneMetaCache.put(sceneId, new SoftReference<>(instance)); - return instance; - }); - } + public static SceneMeta getSceneMeta(int sceneId) { + return tryGet(sceneMetaCache.get(sceneId)).orElseGet(() -> { + var instance = SceneMeta.of(sceneId); + sceneMetaCache.put(sceneId, new SoftReference<>(instance)); + return instance; + }); + } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtCreateGadgetNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtCreateGadgetNotify.java index 1c3c82323..4d7007e1e 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtCreateGadgetNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtCreateGadgetNotify.java @@ -11,18 +11,18 @@ import emu.grasscutter.server.game.GameSession; @Opcodes(PacketOpcodes.EvtCreateGadgetNotify) public class HandlerEvtCreateGadgetNotify extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - EvtCreateGadgetNotify notify = EvtCreateGadgetNotify.parseFrom(payload); + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + EvtCreateGadgetNotify notify = EvtCreateGadgetNotify.parseFrom(payload); - // Sanity check - dont add duplicate entities - if (session.getPlayer().getScene().getEntityById(notify.getEntityId()) != null) { - return; - } + // Sanity check - dont add duplicate entities + if (session.getPlayer().getScene().getEntityById(notify.getEntityId()) != null) { + return; + } - // Create entity and summon in world + // Create entity and summon in world var gadgetId = notify.getConfigId(); - EntityClientGadget gadget = switch (gadgetId) { + EntityClientGadget gadget = switch (gadgetId) { //Solar Isotoma. case EntitySolarIsotomaClientGadget.GADGET_ID -> new EntitySolarIsotomaClientGadget(session.getPlayer().getScene(), session.getPlayer(), notify); @@ -33,6 +33,6 @@ public class HandlerEvtCreateGadgetNotify extends PacketHandler { }; session.getPlayer().getScene().onPlayerCreateGadget(gadget); - } + } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneTimeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneTimeNotify.java index 6b2e413e8..b227d6c99 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneTimeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneTimeNotify.java @@ -7,14 +7,14 @@ import emu.grasscutter.net.proto.SceneTimeNotifyOuterClass.SceneTimeNotify; public class PacketSceneTimeNotify extends BasePacket { - public PacketSceneTimeNotify(Player player) { - super(PacketOpcodes.SceneTimeNotify); + public PacketSceneTimeNotify(Player player) { + super(PacketOpcodes.SceneTimeNotify); - SceneTimeNotify proto = SceneTimeNotify.newBuilder() - .setSceneId(player.getSceneId()) - .setSceneTime(player.getScene().getSceneTime()) - .build(); + SceneTimeNotify proto = SceneTimeNotify.newBuilder() + .setSceneId(player.getSceneId()) + .setSceneTime(player.getScene().getSceneTime()) + .build(); - this.setData(proto); - } + this.setData(proto); + } } diff --git a/src/main/java/emu/grasscutter/utils/FileUtils.java b/src/main/java/emu/grasscutter/utils/FileUtils.java index 1f4848241..377f3a5a9 100644 --- a/src/main/java/emu/grasscutter/utils/FileUtils.java +++ b/src/main/java/emu/grasscutter/utils/FileUtils.java @@ -111,93 +111,93 @@ public final class FileUtils { return SCRIPTS_PATH.resolve(path); } - public static void write(String dest, byte[] bytes) { - Path path = Path.of(dest); - - try { - Files.write(path, bytes); - } catch (IOException e) { - Grasscutter.getLogger().warn("Failed to write file: " + dest); - } - } - - public static byte[] read(String dest) { - return read(Path.of(dest)); - } + public static void write(String dest, byte[] bytes) { + Path path = Path.of(dest); - public static byte[] read(Path path) { - try { - return Files.readAllBytes(path); - } catch (IOException e) { - Grasscutter.getLogger().warn("Failed to read file: " + path); - } - - return new byte[0]; - } + try { + Files.write(path, bytes); + } catch (IOException e) { + Grasscutter.getLogger().warn("Failed to write file: " + dest); + } + } - public static InputStream readResourceAsStream(String resourcePath) { - return Grasscutter.class.getResourceAsStream(resourcePath); - } + public static byte[] read(String dest) { + return read(Path.of(dest)); + } - public static byte[] readResource(String resourcePath) { - try (InputStream is = Grasscutter.class.getResourceAsStream(resourcePath)) { - return is.readAllBytes(); - } catch (Exception exception) { - Grasscutter.getLogger().warn("Failed to read resource: " + resourcePath); - exception.printStackTrace(); - } + public static byte[] read(Path path) { + try { + return Files.readAllBytes(path); + } catch (IOException e) { + Grasscutter.getLogger().warn("Failed to read file: " + path); + } - return new byte[0]; - } - - public static byte[] read(File file) { - return read(file.getPath()); - } + return new byte[0]; + } - public static void copyResource(String resourcePath, String destination) { - try { - byte[] resource = FileUtils.readResource(resourcePath); - FileUtils.write(destination, resource); - } catch (Exception exception) { - Grasscutter.getLogger().warn("Failed to copy resource: " + resourcePath + "\n" + exception); - } - } - - public static String getFilenameWithoutPath(String fileName) { - if (fileName.indexOf(".") > 0) { - return fileName.substring(0, fileName.lastIndexOf(".")); - } else { - return fileName; - } - } + public static InputStream readResourceAsStream(String resourcePath) { + return Grasscutter.class.getResourceAsStream(resourcePath); + } - // From https://mkyong.com/java/java-read-a-file-from-resources-folder/ - public static List getPathsFromResource(String folder) throws URISyntaxException { - List result = null; + public static byte[] readResource(String resourcePath) { + try (InputStream is = Grasscutter.class.getResourceAsStream(resourcePath)) { + return is.readAllBytes(); + } catch (Exception exception) { + Grasscutter.getLogger().warn("Failed to read resource: " + resourcePath); + exception.printStackTrace(); + } - try { - // file walks JAR - result = Files.walk(JAR_FILE_SYSTEM.getPath(folder)) - .filter(Files::isRegularFile) - .collect(Collectors.toList()); - } catch (Exception e) { - // Eclipse puts resources in its bin folder - File f = new File(System.getProperty("user.dir") + folder); - - if (!f.exists() || f.listFiles().length == 0) { - return null; - } - - result = Arrays.stream(f.listFiles()).map(File::toPath).toList(); - } - - return result; - } + return new byte[0]; + } - @SuppressWarnings("ResultOfMethodCallIgnored") - public static String readToString(InputStream file) throws IOException { - byte[] content = file.readAllBytes(); + public static byte[] read(File file) { + return read(file.getPath()); + } - return new String(content, StandardCharsets.UTF_8); - } + public static void copyResource(String resourcePath, String destination) { + try { + byte[] resource = FileUtils.readResource(resourcePath); + FileUtils.write(destination, resource); + } catch (Exception exception) { + Grasscutter.getLogger().warn("Failed to copy resource: " + resourcePath + "\n" + exception); + } + } + + public static String getFilenameWithoutPath(String fileName) { + if (fileName.indexOf(".") > 0) { + return fileName.substring(0, fileName.lastIndexOf(".")); + } else { + return fileName; + } + } + + // From https://mkyong.com/java/java-read-a-file-from-resources-folder/ + public static List getPathsFromResource(String folder) throws URISyntaxException { + List result = null; + + try { + // file walks JAR + result = Files.walk(JAR_FILE_SYSTEM.getPath(folder)) + .filter(Files::isRegularFile) + .collect(Collectors.toList()); + } catch (Exception e) { + // Eclipse puts resources in its bin folder + File f = new File(System.getProperty("user.dir") + folder); + + if (!f.exists() || f.listFiles().length == 0) { + return null; + } + + result = Arrays.stream(f.listFiles()).map(File::toPath).toList(); + } + + return result; + } + + @SuppressWarnings("ResultOfMethodCallIgnored") + public static String readToString(InputStream file) throws IOException { + byte[] content = file.readAllBytes(); + + return new String(content, StandardCharsets.UTF_8); + } }