From 0db017dfa40f1b668280fb1a9415173929f6c9ec Mon Sep 17 00:00:00 2001 From: xmplay <81370285+xmplay@users.noreply.github.com> Date: Fri, 22 Apr 2022 09:52:33 +0200 Subject: [PATCH 01/27] fix typos and grammar in README.md --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 853c37ae3..1bff62df9 100644 --- a/README.md +++ b/README.md @@ -10,20 +10,20 @@ A WIP server reimplementation for *some anime game* 2.3-2.6 * Inventory features (recieving items/characters, upgrading items/characters, etc) * Gacha system * Friends list -* Co-op *partially* work +* Co-op *partially* works # Quick setup guide ### Note -* If you update from an older version, delete `config.json` for regeneration +* If you updated from an older version, delete `config.json` to regenerate it. ### Prerequisites -* JDK-8u202 ([mirror link](https://mirrors.huaweicloud.com/java/jdk/8u202-b08/) since Oracle required an account to download old builds) +* JDK-8u202 ([mirror link](https://mirrors.huaweicloud.com/java/jdk/8u202-b08/) since Oracle requires an account to download old builds) * Mongodb (recommended 4.0+) * Proxy daemon: mitmproxy (mitmdump, recommended), Fiddler Classic, etc. ### Starting up Grasscutter server (Assuming you are on Windows) -1. Setup compile environment `gradlew.bat` +1. Setup the compile environment with `gradlew.bat` 2. Compile Grasscutter with `gradlew jar` -3. Create a folder named `resources` in your Grasscutter directory, bring your `BinOutput` and `ExcelBinOutput` folders into it *(Check the wiki for more details how to get those.)* +3. Create a folder named `resources` in your Grasscutter directory, move your `BinOutput` and `ExcelBinOutput` folders there *(Check the wiki for more details on how to get those.)* 4. Run Grasscutter with `java -jar grasscutter.jar`. Make sure mongodb service is running as well. ### Connecting with the client @@ -37,7 +37,7 @@ A WIP server reimplementation for *some anime game* 2.3-2.6 2. Set network proxy to `127.0.0.1:8080` or the proxy port you specified. 4. *yoink* -* or you can use `run.cmd` to start Server & Proxy daemon with one click +* or you can use `run.cmd` to start the Server & Proxy daemon with one click # Grasscutter commands There is a dummy user named "Server" in every player's friends list that you can message to use commands. Commands also work in other chat rooms, such as private/team chats. @@ -54,26 +54,26 @@ There is a dummy user named "Server" in every player's friends list that you can `killall` -`setworldlevel [level]` - Relog to see effects properly +`setworldlevel [level]` - Changes your world level, relog to see effects properly `godmode` - Prevents you from taking damage -`resetconst` - Resets the constellation level on your current active character, will need to relog after using the command to see any changes. +`resetconst` - Resets the constellation level on your currently selected character, will need to relog after using the command to see any changes. -`setstats [stats] [amount]` - Changes the current character's specified stat. +`setstats [stats] [amount]` - Changes the currently selected character's specified stat. -`clearartifacts` - Deletes all unequipped and unlocked level 0 artifacts, **including yellow rarity ones** from your inventory +`clearartifacts` - Deletes all unequipped and unlocked level 0 artifacts, **including 5* rarity ones** from your inventory -`pos` - Gets your current coordinate. +`pos` - Gets your current coordinates. `weather [weather id] [climate id]` - Changes the current weather. *More commands will be updated in the [wiki](https://github.com/Melledy/Grasscutter/wiki/).* ### Bonus -When you want to teleport to somewhere, use the ingame marking function on Map, click Confirm. You will see your character falling from a very high destination, exact location that you marked. +When you want to teleport somewhere, use the in-game marking function on the Map, click Confirm. You will see your character falling from a very high spot at the exact location you marked. # Quick Troubleshooting * If compiling wasn't successful, please check your JDK installation (must be JDK 8 and validated JDK's bin PATH variable) -* My client doesn't connect, doesn't login, 4206, etc... - Mostly your proxy daemon setup is *the issue*, if using Fiddler make sure it running on another port except 8888 +* My client doesn't connect, doesn't login, 4206, etc... - Mostly your proxy daemon setup is *the issue*, if you're using Fiddler make sure it's running on a port other than 8888 * Startup sequence: Mongodb > Grasscutter > Proxy daemon (mitmdump, fiddler, etc.) > Client From 13ebc4f4fcd5e57dba98c87155cfa52b3478303c Mon Sep 17 00:00:00 2001 From: xmplay <81370285+xmplay@users.noreply.github.com> Date: Fri, 22 Apr 2022 09:55:44 +0200 Subject: [PATCH 02/27] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1bff62df9..b5538b012 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ There is a dummy user named "Server" in every player's friends list that you can `setstats [stats] [amount]` - Changes the currently selected character's specified stat. -`clearartifacts` - Deletes all unequipped and unlocked level 0 artifacts, **including 5* rarity ones** from your inventory +`clearartifacts` - Deletes all unequipped and unlocked level 0 artifacts, **including 5-star rarity ones** from your inventory `pos` - Gets your current coordinates. From 159b10af7214695a2927c1945d183806b9f0c8fe Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Fri, 22 Apr 2022 22:27:40 +0800 Subject: [PATCH 03/27] AvatarFetterLevel --- .../emu/grasscutter/data/GenshinData.java | 10 ++++++++ .../data/def/AvatarFetterLevelData.java | 23 +++++++++++++++++ .../game/avatar/GenshinAvatar.java | 23 +++++++++++++++-- .../game/managers/InventoryManager.java | 25 +++++++++++++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/main/java/emu/grasscutter/data/def/AvatarFetterLevelData.java diff --git a/src/main/java/emu/grasscutter/data/GenshinData.java b/src/main/java/emu/grasscutter/data/GenshinData.java index 7e14b1b46..155ebb60c 100644 --- a/src/main/java/emu/grasscutter/data/GenshinData.java +++ b/src/main/java/emu/grasscutter/data/GenshinData.java @@ -31,6 +31,7 @@ public class GenshinData { private static final Int2ObjectMap avatarSkillDepotDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap avatarSkillDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap avatarCurveDataMap = new Int2ObjectLinkedOpenHashMap<>(); + private static final Int2ObjectMap avatarFetterLevelDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap avatarPromoteDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap avatarTalentDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap proudSkillDataMap = new Int2ObjectOpenHashMap<>(); @@ -114,6 +115,10 @@ public class GenshinData { return playerLevelDataMap; } + public static Int2ObjectMap getAvatarFetterLevelDataMap() { + return avatarFetterLevelDataMap; + } + public static Int2ObjectMap getAvatarLevelDataMap() { return avatarLevelDataMap; } @@ -175,6 +180,11 @@ public class GenshinData { AvatarLevelData levelData = avatarLevelDataMap.get(level); return levelData != null ? levelData.getExp() : 0; } + + public static int getAvatarFetterLevelExpRequired(int level) { + AvatarFetterLevelData levelData = avatarFetterLevelDataMap.get(level); + return levelData != null ? levelData.getExp() : 0; + } public static Int2ObjectMap getProudSkillDataMap() { return proudSkillDataMap; diff --git a/src/main/java/emu/grasscutter/data/def/AvatarFetterLevelData.java b/src/main/java/emu/grasscutter/data/def/AvatarFetterLevelData.java new file mode 100644 index 000000000..8dd93eea5 --- /dev/null +++ b/src/main/java/emu/grasscutter/data/def/AvatarFetterLevelData.java @@ -0,0 +1,23 @@ +package emu.grasscutter.data.def; + +import emu.grasscutter.data.GenshinResource; +import emu.grasscutter.data.ResourceType; + +@ResourceType(name = "AvatarFettersLevelExcelConfigData.json") +public class AvatarFetterLevelData extends GenshinResource { + private int FetterLevel; + private int NeedExp; + + @Override + public int getId() { + return this.FetterLevel; + } + + public int getLevel() { + return FetterLevel; + } + + public int getExp() { + return NeedExp; + } +} diff --git a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java index 6906d3896..d4e998d46 100644 --- a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java @@ -89,6 +89,9 @@ public class GenshinAvatar { private int flyCloak; private int costume; private int bornTime; + + private int fetterLevel = 1; + private int fetterExp; public GenshinAvatar() { // Morhpia only! @@ -281,6 +284,22 @@ public class GenshinAvatar { return fetters; } + public int getFetterLevel() { + return fetterLevel; + } + + public void setFetterLevel(int fetterLevel) { + this.fetterLevel = fetterLevel; + } + + public int getFetterExp() { + return fetterExp; + } + + public void setFetterExp(int fetterExp) { + this.fetterExp = fetterExp; + } + public float getCurrentHp() { return currentHp; } @@ -702,8 +721,8 @@ public class GenshinAvatar { public AvatarInfo toProto() { AvatarFetterInfo.Builder avatarFetter = AvatarFetterInfo.newBuilder() - .setExpLevel(10) - .setExpNumber(6325); // Highest Level + .setExpLevel(this.getFetterLevel()) + .setExpNumber(this.getFetterExp()); if (this.getFetterList() != null) { for (int i = 0; i < this.getFetterList().size(); i++) { diff --git a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java index 532155db1..96ab032b8 100644 --- a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java +++ b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java @@ -711,6 +711,31 @@ public class InventoryManager { player.sendPacket(new PacketAvatarUpgradeRsp(avatar, oldLevel, oldPropMap)); } + public void upgradeAvatarFetterLevel(GenshinPlayer player, GenshinAvatar avatar, int expGain) { + // May work. Not test. + int maxLevel = GenshinData.getAvatarFetterLevelDataMap().get(GenshinData.getAvatarFetterLevelDataMap().size() - 1).getLevel(); + int level = avatar.getFetterLevel(); + int exp = avatar.getFetterExp(); + int reqExp = GenshinData.getAvatarFetterLevelExpRequired(level); + + while (expGain > 0 && reqExp > 0 && level < maxLevel) { + int toGain = Math.min(expGain, reqExp - exp); + exp += toGain; + expGain -= toGain; + if (exp >= reqExp) { + exp = 0; + level += 1; + reqExp = GenshinData.getAvatarFetterLevelExpRequired(level); + } + } + + avatar.setFetterLevel(level); + avatar.setFetterExp(exp); + avatar.save(); + + player.sendPacket(new PacketAvatarPropNotify(avatar)); + } + public void upgradeAvatarSkill(GenshinPlayer player, long guid, int skillId) { // Sanity checks GenshinAvatar avatar = player.getAvatars().getAvatarByGuid(guid); From eb709046608e3bec95e289c22280a41a8188746c Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Fri, 22 Apr 2022 23:46:24 +0800 Subject: [PATCH 04/27] setfetterlevel command --- .../commands/SetFetterLevelCommand.java | 41 +++++++++++++++++++ .../game/managers/InventoryManager.java | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java diff --git a/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java b/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java new file mode 100644 index 000000000..60a7e4796 --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java @@ -0,0 +1,41 @@ +package emu.grasscutter.command.commands; + +import java.util.List; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.entity.EntityAvatar; + +@Command(label = "setfetterlevel", usage = "setfetterlevel ", + description = "Sets your fetter level for your current active character", + aliases = {"setfetterlvl"}, permission = "player.setfetterlevel") +public final class SetFetterLevelCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + if (args.size() < 1) { + CommandHandler.sendMessage(sender, "Usage: setfetterlevel "); + return; + } + + try { + int fetterLevel = Integer.parseInt(args.get(0)); + if (fetterLevel < 0 || fetterLevel > 10) { + CommandHandler.sendMessage(sender, "Fetter level must be between 0 and 10."); + return; + } + EntityAvatar avatar = sender.getTeamManager().getCurrentAvatarEntity(); + avatar.getAvatar().setFetterLevel(fetterLevel); + CommandHandler.sendMessage(sender, "Fetter level set to " + fetterLevel); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(null, "Invalid fetter level."); + } + } + +} diff --git a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java index 96ab032b8..4ea9e6bc1 100644 --- a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java +++ b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java @@ -713,7 +713,7 @@ public class InventoryManager { public void upgradeAvatarFetterLevel(GenshinPlayer player, GenshinAvatar avatar, int expGain) { // May work. Not test. - int maxLevel = GenshinData.getAvatarFetterLevelDataMap().get(GenshinData.getAvatarFetterLevelDataMap().size() - 1).getLevel(); + int maxLevel = 10; // Keep it until I think of a more "elegant" way int level = avatar.getFetterLevel(); int exp = avatar.getFetterExp(); int reqExp = GenshinData.getAvatarFetterLevelExpRequired(level); From 48db64469236418a000ea0e30d624f5d3e32aa09 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sat, 23 Apr 2022 01:36:48 +0800 Subject: [PATCH 05/27] command fix --- .../commands/SetFetterLevelCommand.java | 13 +++++-- .../send/PacketAvatarFetterDataNotify.java | 38 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java diff --git a/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java b/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java index 60a7e4796..74847a49a 100644 --- a/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java @@ -4,8 +4,10 @@ import java.util.List; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.data.GenshinData; import emu.grasscutter.game.GenshinPlayer; -import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.game.avatar.GenshinAvatar; +import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify; @Command(label = "setfetterlevel", usage = "setfetterlevel ", description = "Sets your fetter level for your current active character", @@ -30,8 +32,13 @@ public final class SetFetterLevelCommand implements CommandHandler { CommandHandler.sendMessage(sender, "Fetter level must be between 0 and 10."); return; } - EntityAvatar avatar = sender.getTeamManager().getCurrentAvatarEntity(); - avatar.getAvatar().setFetterLevel(fetterLevel); + GenshinAvatar avatar = sender.getTeamManager().getCurrentAvatarEntity().getAvatar(); + + avatar.setFetterLevel(fetterLevel); + avatar.setFetterExp(GenshinData.getAvatarFetterLevelDataMap().get(fetterLevel).getExp()); + avatar.save(); + + sender.sendPacket(new PacketAvatarFetterDataNotify(avatar)); CommandHandler.sendMessage(sender, "Fetter level set to " + fetterLevel); } catch (NumberFormatException ignored) { CommandHandler.sendMessage(null, "Invalid fetter level."); diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java new file mode 100644 index 000000000..86cea0e02 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java @@ -0,0 +1,38 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.GenshinAvatar; +import emu.grasscutter.game.props.FetterState; +import emu.grasscutter.net.packet.GenshinPacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarFetterDataNotifyOuterClass.AvatarFetterDataNotify; +import emu.grasscutter.net.proto.AvatarFetterInfoOuterClass.AvatarFetterInfo; +import emu.grasscutter.net.proto.FetterDataOuterClass.FetterData; + +public class PacketAvatarFetterDataNotify extends GenshinPacket { + + public PacketAvatarFetterDataNotify(GenshinAvatar avatar) { + super(PacketOpcodes.AvatarFetterDataNotify); + + AvatarFetterInfo.Builder avatarFetter = AvatarFetterInfo.newBuilder() + .setExpLevel(avatar.getFetterLevel()) + .setExpNumber(avatar.getFetterExp()); + + if (avatar.getFetterList() != null) { + for (int i = 0; i < avatar.getFetterList().size(); i++) { + avatarFetter.addFetterList( + FetterData.newBuilder() + .setFetterId(avatar.getFetterList().get(i)) + .setFetterState(FetterState.FINISH.getValue()) + ); + } + } + + AvatarFetterInfo avatarFetterInfo = avatarFetter.build(); + + AvatarFetterDataNotify proto = AvatarFetterDataNotify.newBuilder() + .putFetterInfoMap(avatar.getGuid(), avatarFetterInfo) + .build(); + + this.setData(proto); + } +} From a52eaf9bbcaccdc794085e4f65e694a63c5cd048 Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Fri, 22 Apr 2022 23:19:58 +0200 Subject: [PATCH 06/27] Use count for level for equips --- .../grasscutter/command/commands/GiveCommand.java | 13 ++++++------- .../emu/grasscutter/game/inventory/GenshinItem.java | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/GiveCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveCommand.java index a533130bc..c427d9d89 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveCommand.java @@ -91,17 +91,16 @@ public final class GiveCommand implements CommandHandler { this.item(targetPlayer, itemData, amount); - CommandHandler.sendMessage(sender, String.format("Given %s of %s to %s.", amount, item, target)); + if (!itemData.isEquip()) CommandHandler.sendMessage(sender, String.format("Given %s of %s to %s.", amount, item, target)); + else CommandHandler.sendMessage(sender, String.format("Given %s with level %s to %s", item, amount, target)); } private void item(GenshinPlayer player, ItemData itemData, int amount) { if (itemData.isEquip()) { - List items = new LinkedList<>(); - for (int i = 0; i < amount; i++) { - items.add(new GenshinItem(itemData)); - } - player.getInventory().addItems(items); - player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop)); + GenshinItem item = new GenshinItem(itemData); + item.setLevel(amount); + player.getInventory().addItem(item); + player.sendPacket(new PacketItemAddHintNotify(item, ActionReason.SubfieldDrop)); } else { GenshinItem genshinItem = new GenshinItem(itemData); genshinItem.setCount(amount); diff --git a/src/main/java/emu/grasscutter/game/inventory/GenshinItem.java b/src/main/java/emu/grasscutter/game/inventory/GenshinItem.java index 0b0db49c4..fccc49307 100644 --- a/src/main/java/emu/grasscutter/game/inventory/GenshinItem.java +++ b/src/main/java/emu/grasscutter/game/inventory/GenshinItem.java @@ -90,7 +90,7 @@ public class GenshinItem { // Equip data if (getItemType() == ItemType.ITEM_WEAPON) { - this.level = 1; + this.level = this.count > 1 ? this.count : 1; this.affixes = new ArrayList<>(2); if (getItemData().getSkillAffix() != null) { for (int skillAffix : getItemData().getSkillAffix()) { From 7ccecda07c5d0a1ee5e965a82aae731fd99637ca Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sat, 23 Apr 2022 06:08:37 +0800 Subject: [PATCH 07/27] AvatarFetterLevelReward --- .../emu/grasscutter/data/GenshinData.java | 5 +++ .../emu/grasscutter/data/def/AvatarData.java | 9 +++++ .../data/def/FetterCharacterCardData.java | 24 +++++++++++++ .../game/avatar/GenshinAvatar.java | 11 ++++++ .../HandlerAvatarFetterLevelRewardReq.java | 32 +++++++++++++++++ .../PacketAvatarFetterLevelRewardRsp.java | 35 +++++++++++++++++++ 6 files changed, 116 insertions(+) create mode 100644 src/main/java/emu/grasscutter/data/def/FetterCharacterCardData.java create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterLevelRewardRsp.java diff --git a/src/main/java/emu/grasscutter/data/GenshinData.java b/src/main/java/emu/grasscutter/data/GenshinData.java index 155ebb60c..98f235c1e 100644 --- a/src/main/java/emu/grasscutter/data/GenshinData.java +++ b/src/main/java/emu/grasscutter/data/GenshinData.java @@ -58,6 +58,7 @@ public class GenshinData { private static final Int2ObjectMap sceneDataMap = new Int2ObjectLinkedOpenHashMap<>(); private static final Int2ObjectMap fetterDataMap = new Int2ObjectOpenHashMap<>(); + private static final Int2ObjectMap fetterCharacterCardDataMap = new Int2ObjectOpenHashMap<>(); // Cache private static Map> fetters = new HashMap<>(); @@ -119,6 +120,10 @@ public class GenshinData { return avatarFetterLevelDataMap; } + public static Int2ObjectMap getFetterCharacterCardDataMap() { + return fetterCharacterCardDataMap; + } + public static Int2ObjectMap getAvatarLevelDataMap() { return avatarLevelDataMap; } diff --git a/src/main/java/emu/grasscutter/data/def/AvatarData.java b/src/main/java/emu/grasscutter/data/def/AvatarData.java index 8097e04a7..a714344ae 100644 --- a/src/main/java/emu/grasscutter/data/def/AvatarData.java +++ b/src/main/java/emu/grasscutter/data/def/AvatarData.java @@ -57,6 +57,7 @@ public class AvatarData extends GenshinResource { private IntList abilities; private List fetters; + private int nameCardRewardId; @Override public int getId(){ @@ -199,12 +200,20 @@ public class AvatarData extends GenshinResource { return fetters; } + public int getNameCardRewardId() { + return nameCardRewardId; + } + @Override public void onLoad() { this.skillDepot = GenshinData.getAvatarSkillDepotDataMap().get(this.SkillDepotId); // Get fetters from GenshinData this.fetters = GenshinData.getFetterDataEntries().get(this.Id); + + if (GenshinData.getFetterCharacterCardDataMap().get(this.Id) != null) { + this.nameCardRewardId = GenshinData.getFetterCharacterCardDataMap().get(this.Id).getRewardId(); + } int size = GenshinData.getAvatarCurveDataMap().size(); this.hpGrowthCurve = new float[size]; diff --git a/src/main/java/emu/grasscutter/data/def/FetterCharacterCardData.java b/src/main/java/emu/grasscutter/data/def/FetterCharacterCardData.java new file mode 100644 index 000000000..2bf96ad8e --- /dev/null +++ b/src/main/java/emu/grasscutter/data/def/FetterCharacterCardData.java @@ -0,0 +1,24 @@ +package emu.grasscutter.data.def; + +import emu.grasscutter.data.GenshinResource; +import emu.grasscutter.data.ResourceType; +import emu.grasscutter.data.ResourceType.LoadPriority; + +@ResourceType(name = "FetterCharacterCardExcelConfigData.json", loadPriority = LoadPriority.HIGHEST) +public class FetterCharacterCardData extends GenshinResource { + private int AvatarId; + private int RewardId; + + @Override + public int getId() { + return AvatarId; + } + + public int getRewardId() { + return RewardId; + } + + @Override + public void onLoad() { + } +} diff --git a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java index d4e998d46..5ad553f9c 100644 --- a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java @@ -92,6 +92,8 @@ public class GenshinAvatar { private int fetterLevel = 1; private int fetterExp; + + private int nameCardRewardId; public GenshinAvatar() { // Morhpia only! @@ -110,6 +112,7 @@ public class GenshinAvatar { public GenshinAvatar(AvatarData data) { this(); this.avatarId = data.getId(); + this.nameCardRewardId = data.getNameCardRewardId(); this.data = data; this.bornTime = (int) (System.currentTimeMillis() / 1000); this.flyCloak = 140001; @@ -172,6 +175,14 @@ public class GenshinAvatar { this.satiation = satiation; } + public int getNameCardRewardId() { + return nameCardRewardId; + } + + public void setNameCardRewardId(int nameCardRewardId) { + this.nameCardRewardId = nameCardRewardId; + } + public int getSatiationPenalty() { return satiationPenalty; } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java new file mode 100644 index 000000000..d3431d535 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java @@ -0,0 +1,32 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarFetterLevelRewardReqOuterClass.AvatarFetterLevelRewardReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketAvatarFetterLevelRewardRsp; +import emu.grasscutter.net.packet.PacketHandler; + +@Opcodes(PacketOpcodes.AvatarFetterLevelRewardReq) +public class HandlerAvatarFetterLevelRewardReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AvatarFetterLevelRewardReq req = AvatarFetterLevelRewardReq.parseFrom(payload); + if (req.getFetterLevel() < 10) { + // You don't have a full level of fetter level, why do you want to get a divorce certificate? + session.send(new PacketAvatarFetterLevelRewardRsp(req.getAvatarGuid(), req.getFetterLevel())); + } else { + long avatarGuid = req.getAvatarGuid(); + + int rewardId = session + .getPlayer() + .getAvatars() + .getAvatarByGuid(avatarGuid) + .getNameCardRewardId(); + + // Here need to send the packets, I am not at all clear ah! + + session.send(new PacketAvatarFetterLevelRewardRsp(avatarGuid, req.getFetterLevel(), rewardId)); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterLevelRewardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterLevelRewardRsp.java new file mode 100644 index 000000000..e9d4895ff --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterLevelRewardRsp.java @@ -0,0 +1,35 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.GenshinPacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarFetterLevelRewardRspOuterClass.AvatarFetterLevelRewardRsp; + +public class PacketAvatarFetterLevelRewardRsp extends GenshinPacket { + + public PacketAvatarFetterLevelRewardRsp(long guid, int fetterLevel, int rewardId) { + super(PacketOpcodes.AvatarFetterLevelRewardRsp); + + AvatarFetterLevelRewardRsp proto = AvatarFetterLevelRewardRsp.newBuilder() + .setAvatarGuid(guid) + .setFetterLevel(fetterLevel) + .setRetcode(0) + .setRewardId(rewardId) + .build(); + + this.setData(proto); + } + + public PacketAvatarFetterLevelRewardRsp(long guid, int fetterLevel) { + super(PacketOpcodes.AvatarFetterLevelRewardRsp); + + AvatarFetterLevelRewardRsp proto = AvatarFetterLevelRewardRsp.newBuilder() + .setAvatarGuid(guid) + .setFetterLevel(fetterLevel) + .setRetcode(1) + .setRewardId(0) + .build(); + + this.setData(proto); + } + +} From 5ea5ea238c7ec7aba834e79fc96ab43c7cc6f669 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sat, 23 Apr 2022 10:51:22 +0800 Subject: [PATCH 08/27] OpenCond for unlocking judgment --- .../grasscutter/data/common/OpenCondData.java | 24 +++++++++++++++++++ .../emu/grasscutter/data/def/FetterData.java | 8 +++++++ 2 files changed, 32 insertions(+) create mode 100644 src/main/java/emu/grasscutter/data/common/OpenCondData.java diff --git a/src/main/java/emu/grasscutter/data/common/OpenCondData.java b/src/main/java/emu/grasscutter/data/common/OpenCondData.java new file mode 100644 index 000000000..9e7b62b11 --- /dev/null +++ b/src/main/java/emu/grasscutter/data/common/OpenCondData.java @@ -0,0 +1,24 @@ +package emu.grasscutter.data.common; + +import java.util.List; + +public class OpenCondData { + private String CondType; + private List ParamList; + + public String getCondType() { + return CondType; + } + + public void setCondType(String condType) { + CondType = condType; + } + + public List getParamList() { + return ParamList; + } + + public void setParamList(List paramList) { + ParamList = paramList; + } +} diff --git a/src/main/java/emu/grasscutter/data/def/FetterData.java b/src/main/java/emu/grasscutter/data/def/FetterData.java index d17c940d1..dc88fd795 100644 --- a/src/main/java/emu/grasscutter/data/def/FetterData.java +++ b/src/main/java/emu/grasscutter/data/def/FetterData.java @@ -1,13 +1,17 @@ package emu.grasscutter.data.def; +import java.util.List; + import emu.grasscutter.data.GenshinResource; import emu.grasscutter.data.ResourceType; import emu.grasscutter.data.ResourceType.LoadPriority; +import emu.grasscutter.data.common.OpenCondData; @ResourceType(name = {"FetterInfoExcelConfigData.json", "FettersExcelConfigData.json", "FetterStoryExcelConfigData.json"}, loadPriority = LoadPriority.HIGHEST) public class FetterData extends GenshinResource { private int AvatarId; private int FetterId; + private List OpenCond; @Override public int getId() { @@ -18,6 +22,10 @@ public class FetterData extends GenshinResource { return AvatarId; } + public List getOpenConds() { + return OpenCond; + } + @Override public void onLoad() { } From 3707ee54776bef5d33376f6d566ed45a70ffe28c Mon Sep 17 00:00:00 2001 From: fumbling <104180076+fumbling644o@users.noreply.github.com> Date: Fri, 22 Apr 2022 22:02:13 -0400 Subject: [PATCH 09/27] Make gradlew executable --- gradlew | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 gradlew diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 From d1d8378e15cf0d094d3ab6c2979216078cb3715e Mon Sep 17 00:00:00 2001 From: fumbling <104180076+fumbling644o@users.noreply.github.com> Date: Fri, 22 Apr 2022 22:02:41 -0400 Subject: [PATCH 10/27] Workflow: Use Ubuntu and add PR triggers --- .github/workflows/build.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8457bf7ac..26a075ccc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,9 +3,14 @@ on: push: branches: - "stable" + pull_request: + types: + - opened + - synchronize + - reopened jobs: Build-Server-Jar: - runs-on: windows-latest + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 @@ -15,10 +20,9 @@ jobs: distribution: temurin java-version: '8' - name: Run Gradle - run: .\gradlew.bat && .\gradlew jar + run: ./gradlew && ./gradlew jar - name: Upload build uses: actions/upload-artifact@v3 with: name: Grasscutter path: grasscutter.jar - From 220f252f0fb9a4ba51572690a5a028dd666a9779 Mon Sep 17 00:00:00 2001 From: fumbling <104180076+fumbling644o@users.noreply.github.com> Date: Fri, 22 Apr 2022 22:40:19 -0400 Subject: [PATCH 11/27] Workflow: Switch from Temurin 8 to 16 --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 26a075ccc..cc0193c1a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ jobs: uses: actions/setup-java@v3 with: distribution: temurin - java-version: '8' + java-version: '16' - name: Run Gradle run: ./gradlew && ./gradlew jar - name: Upload build From c77aa3ff79a274ac4cef12caf31da2309909f21a Mon Sep 17 00:00:00 2001 From: WangYneos Date: Sat, 23 Apr 2022 12:02:10 +0800 Subject: [PATCH 12/27] make mitmproxy ignore non Genshin hosts --- README.md | 2 +- start.cmd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 853c37ae3..a08da974b 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ A WIP server reimplementation for *some anime game* 2.3-2.6 ### Connecting with the client ½. Create an account using *server console command* below 1. Run a proxy daemon: (choose either one) - - mitmdump: `mitmdump -s proxy.py -k` + - mitmdump: `mitmdump -s proxy.py -k`--allow-hosts ".*\.yuanshen\.com|.*\.mihoyo\.com|.*\.hoyoverse\.com" - Fiddler Classic: Run Fiddler Classic, turn on `Decrypt https traffic` in setting and change the default port there (Tools -> Options -> Connections) to anything other than `8888`, and load [this script](https://github.lunatic.moe/fiddlerscript). - [Hosts file](https://github.com/Melledy/Grasscutter/wiki/Running#traffic-route-map) 2. Trust CA certificate: diff --git a/start.cmd b/start.cmd index 8c89f359e..48de450d1 100644 --- a/start.cmd +++ b/start.cmd @@ -75,7 +75,7 @@ for /f "tokens=2*" %%a in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVe @rem TODO: External proxy when ORIG_PROXY_ENABLE == 0x1 echo set ws = createobject("wscript.shell") > "%temp%\proxy.vbs" echo ws.currentdirectory = "%MITMDUMP_PATH%" >> "%temp%\proxy.vbs" -echo ws.run "cmd /c mitmdump.exe -s "^&chr(34)^&"%PROXY_SCRIPT_NAME%"^&chr(34)^&" -k",0 >> "%temp%\proxy.vbs" +echo ws.run "cmd /c mitmdump.exe -s "^&chr(34)^&"%PROXY_SCRIPT_NAME%"^&chr(34)^&" -k --allow-hosts \".*\.yuanshen\.com|.*\.mihoyo\.com|.*\.hoyoverse\.com\"",0 >> "%temp%\proxy.vbs" "%temp%\proxy.vbs" del /f /q "%temp%\proxy.vbs" >nul 2>nul From ae00eb69d67fd5b7561410f77f6426f0599fa8a3 Mon Sep 17 00:00:00 2001 From: WangYneos <42824603+WangYneos@users.noreply.github.com> Date: Sat, 23 Apr 2022 12:07:23 +0800 Subject: [PATCH 13/27] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a08da974b..370dc3c99 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ A WIP server reimplementation for *some anime game* 2.3-2.6 ### Connecting with the client ½. Create an account using *server console command* below 1. Run a proxy daemon: (choose either one) - - mitmdump: `mitmdump -s proxy.py -k`--allow-hosts ".*\.yuanshen\.com|.*\.mihoyo\.com|.*\.hoyoverse\.com" + - mitmdump: `mitmdump -s proxy.py -k --allow-hosts ".*\.yuanshen\.com|.*\.mihoyo\.com|.*\.hoyoverse\.com"` - Fiddler Classic: Run Fiddler Classic, turn on `Decrypt https traffic` in setting and change the default port there (Tools -> Options -> Connections) to anything other than `8888`, and load [this script](https://github.lunatic.moe/fiddlerscript). - [Hosts file](https://github.com/Melledy/Grasscutter/wiki/Running#traffic-route-map) 2. Trust CA certificate: From 22e5ca5545039df239bd0d6bb495c107fc206745 Mon Sep 17 00:00:00 2001 From: WangYneos <42824603+WangYneos@users.noreply.github.com> Date: Sat, 23 Apr 2022 13:57:48 +0800 Subject: [PATCH 14/27] Update start.cmd --- start.cmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/start.cmd b/start.cmd index 48de450d1..59ff78160 100644 --- a/start.cmd +++ b/start.cmd @@ -75,7 +75,7 @@ for /f "tokens=2*" %%a in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVe @rem TODO: External proxy when ORIG_PROXY_ENABLE == 0x1 echo set ws = createobject("wscript.shell") > "%temp%\proxy.vbs" echo ws.currentdirectory = "%MITMDUMP_PATH%" >> "%temp%\proxy.vbs" -echo ws.run "cmd /c mitmdump.exe -s "^&chr(34)^&"%PROXY_SCRIPT_NAME%"^&chr(34)^&" -k --allow-hosts \".*\.yuanshen\.com|.*\.mihoyo\.com|.*\.hoyoverse\.com\"",0 >> "%temp%\proxy.vbs" +echo ws.run "cmd /c mitmdump.exe -s "^&chr(34)^&"%PROXY_SCRIPT_NAME%"^&chr(34)^&" -k --allow-hosts ^&chr(34)^&.*\.yuanshen\.com|.*\.mihoyo\.com|.*\.hoyoverse\.com^&chr(34)^&",0 >> "%temp%\proxy.vbs" "%temp%\proxy.vbs" del /f /q "%temp%\proxy.vbs" >nul 2>nul @@ -157,4 +157,4 @@ call :LOG [INFO] See you again :) goto :EOF :LOG -echo [%time:~0,8%] %* \ No newline at end of file +echo [%time:~0,8%] %* From 39e590dfb85988aa7c6e3cdad72f1a90edf238bd Mon Sep 17 00:00:00 2001 From: WangYneos Date: Sat, 23 Apr 2022 14:28:14 +0800 Subject: [PATCH 15/27] Fix Syntax --- start.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.cmd b/start.cmd index 59ff78160..c9dcc606f 100644 --- a/start.cmd +++ b/start.cmd @@ -75,7 +75,7 @@ for /f "tokens=2*" %%a in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVe @rem TODO: External proxy when ORIG_PROXY_ENABLE == 0x1 echo set ws = createobject("wscript.shell") > "%temp%\proxy.vbs" echo ws.currentdirectory = "%MITMDUMP_PATH%" >> "%temp%\proxy.vbs" -echo ws.run "cmd /c mitmdump.exe -s "^&chr(34)^&"%PROXY_SCRIPT_NAME%"^&chr(34)^&" -k --allow-hosts ^&chr(34)^&.*\.yuanshen\.com|.*\.mihoyo\.com|.*\.hoyoverse\.com^&chr(34)^&",0 >> "%temp%\proxy.vbs" +echo ws.run "cmd /c mitmdump.exe -s "^&chr(34)^&"%PROXY_SCRIPT_NAME%"^&chr(34)^&" -k --allow-hosts "^&chr(34)^&".*\.yuanshen\.com|.*\.mihoyo\.com|.*\.hoyoverse\.com"^&chr(34),0 >> "%temp%\proxy.vbs" "%temp%\proxy.vbs" del /f /q "%temp%\proxy.vbs" >nul 2>nul From 3bc249f0426fda483a32f634c001f7d686ec3a8d Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sat, 23 Apr 2022 21:03:29 +0800 Subject: [PATCH 16/27] Try to give name card --- .../data/common/RewardItemData.java | 22 +++++++++++++++ .../emu/grasscutter/data/def/RewardData.java | 27 +++++++++++++++++++ .../game/avatar/GenshinAvatar.java | 1 + .../HandlerAvatarFetterLevelRewardReq.java | 21 +++++++++++++-- 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 src/main/java/emu/grasscutter/data/common/RewardItemData.java create mode 100644 src/main/java/emu/grasscutter/data/def/RewardData.java diff --git a/src/main/java/emu/grasscutter/data/common/RewardItemData.java b/src/main/java/emu/grasscutter/data/common/RewardItemData.java new file mode 100644 index 000000000..024b89f7f --- /dev/null +++ b/src/main/java/emu/grasscutter/data/common/RewardItemData.java @@ -0,0 +1,22 @@ +package emu.grasscutter.data.common; + +public class RewardItemData { + private int ItemId; + private int ItemCount; + + public int getItemId() { + return ItemId; + } + + public void setItemId(int itemId) { + ItemId = itemId; + } + + public int getItemCount() { + return ItemCount; + } + + public void setItemCount(int itemCount) { + ItemCount = itemCount; + } +} diff --git a/src/main/java/emu/grasscutter/data/def/RewardData.java b/src/main/java/emu/grasscutter/data/def/RewardData.java new file mode 100644 index 000000000..46c39ac10 --- /dev/null +++ b/src/main/java/emu/grasscutter/data/def/RewardData.java @@ -0,0 +1,27 @@ +package emu.grasscutter.data.def; + +import java.util.List; + +import emu.grasscutter.data.GenshinResource; +import emu.grasscutter.data.ResourceType; +import emu.grasscutter.data.common.RewardItemData; + +@ResourceType(name = "RewardExcelConfigData.json") +public class RewardData extends GenshinResource { + public int RewardId; + public List RewardItemList; + + @Override + public int getId() { + return RewardId; + } + + public List getRewardItemList() { + return RewardItemList; + } + + @Override + public void onLoad() { + + } +} diff --git a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java index 254258300..45b5c09ec 100644 --- a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java @@ -433,6 +433,7 @@ public class GenshinAvatar { // Fetters this.setFetterList(data.getFetters()); + this.setNameCardRewardId(data.getNameCardRewardId()); // Get hp percent, set to 100% if none float hpPercent = this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) <= 0 ? 1f : this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) / this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP); diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java index d3431d535..2269f8606 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java @@ -1,10 +1,17 @@ package emu.grasscutter.server.packet.recv; +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.GenshinData; +import emu.grasscutter.data.def.RewardData; +import emu.grasscutter.game.inventory.GenshinItem; +import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.AvatarFetterLevelRewardReqOuterClass.AvatarFetterLevelRewardReq; import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.packet.send.PacketAvatarFetterLevelRewardRsp; +import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; +import emu.grasscutter.server.packet.send.PacketUnlockNameCardNotify; import emu.grasscutter.net.packet.PacketHandler; @Opcodes(PacketOpcodes.AvatarFetterLevelRewardReq) @@ -23,9 +30,19 @@ public class HandlerAvatarFetterLevelRewardReq extends PacketHandler { .getAvatars() .getAvatarByGuid(avatarGuid) .getNameCardRewardId(); - - // Here need to send the packets, I am not at all clear ah! + RewardData card = GenshinData.getRewardDataMap().get(rewardId); + int cardId = card.getRewardItemList().get(0).getItemId(); + + if (session.getPlayer().getNameCardList().contains(cardId)) { + // Already got divorce certificate. + session.send(new PacketAvatarFetterLevelRewardRsp(req.getAvatarGuid(), req.getFetterLevel())); + return; + } + + GenshinItem item = new GenshinItem(cardId); + session.getPlayer().sendPacket(new PacketItemAddHintNotify(item, ActionReason.FetterLevelReward)); + session.send(new PacketUnlockNameCardNotify(cardId)); session.send(new PacketAvatarFetterLevelRewardRsp(avatarGuid, req.getFetterLevel(), rewardId)); } } From 57e363725134ca02df03db40e24f5c6185e48e96 Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Sat, 23 Apr 2022 16:11:45 +0200 Subject: [PATCH 17/27] Add promoteLevel and count --- .../command/commands/GiveCommand.java | 80 ++++++++++++++----- 1 file changed, 62 insertions(+), 18 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/GiveCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveCommand.java index c427d9d89..2ecdac1f5 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveCommand.java @@ -13,16 +13,15 @@ import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; import java.util.LinkedList; import java.util.List; -@Command(label = "give", usage = "give [player] [amount]", - description = "Gives an item to you or the specified player", aliases = {"g", "item", "giveitem"}, permission = "player.give") +@Command(label = "give", usage = "give [player] [amount] [level]", description = "Gives an item to you or the specified player", aliases = { + "g", "item", "giveitem" }, permission = "player.give") public final class GiveCommand implements CommandHandler { @Override public void execute(GenshinPlayer sender, List args) { - int target, item, amount = 1; - + int target, item, lvl, amount = 1; if (sender == null && args.size() < 2) { - CommandHandler.sendMessage(null, "Usage: give [amount]"); + CommandHandler.sendMessage(null, "Usage: give [amount] [level]"); return; } @@ -34,6 +33,7 @@ public final class GiveCommand implements CommandHandler { try { item = Integer.parseInt(args.get(0)); target = sender.getUid(); + lvl = 1; } catch (NumberFormatException ignored) { // TODO: Parse from item name using GM Handbook. CommandHandler.sendMessage(sender, "Invalid item id."); @@ -43,6 +43,7 @@ public final class GiveCommand implements CommandHandler { case 2: // [amount] | [player] try { target = Integer.parseInt(args.get(0)); + lvl = 1; if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) { target = sender.getUid(); @@ -57,17 +58,39 @@ public final class GiveCommand implements CommandHandler { return; } break; - case 3: // [player] [amount] + case 3: // [player] [amount] | [amount] [level] + try { + target = Integer.parseInt(args.get(0)); + + if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) { + target = sender.getUid(); + item = Integer.parseInt(args.get(0)); + amount = Integer.parseInt(args.get(1)); + lvl = Integer.parseInt(args.get(2)); + } else { + item = Integer.parseInt(args.get(1)); + amount = Integer.parseInt(args.get(2)); + lvl = 1; + } + + } catch (NumberFormatException ignored) { + // TODO: Parse from item name using GM Handbook. + CommandHandler.sendMessage(sender, "Invalid item or player ID."); + return; + } + break; + case 4: // [player] [amount] [level] try { target = Integer.parseInt(args.get(0)); if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { CommandHandler.sendMessage(sender, "Invalid player ID."); return; + } else { + item = Integer.parseInt(args.get(1)); + amount = Integer.parseInt(args.get(2)); + lvl = Integer.parseInt(args.get(3)); } - - item = Integer.parseInt(args.get(1)); - amount = Integer.parseInt(args.get(2)); } catch (NumberFormatException ignored) { // TODO: Parse from item name using GM Handbook. CommandHandler.sendMessage(sender, "Invalid item or player ID."); @@ -89,18 +112,40 @@ public final class GiveCommand implements CommandHandler { return; } - this.item(targetPlayer, itemData, amount); + this.item(targetPlayer, itemData, amount, lvl); - if (!itemData.isEquip()) CommandHandler.sendMessage(sender, String.format("Given %s of %s to %s.", amount, item, target)); - else CommandHandler.sendMessage(sender, String.format("Given %s with level %s to %s", item, amount, target)); + if (!itemData.isEquip()) + CommandHandler.sendMessage(sender, String.format("Given %s of %s to %s.", amount, item, target)); + else + CommandHandler.sendMessage(sender, + String.format("Given %s with level %s %s times to %s", item, lvl, amount, target)); } - private void item(GenshinPlayer player, ItemData itemData, int amount) { + private void item(GenshinPlayer player, ItemData itemData, int amount, int lvl) { if (itemData.isEquip()) { - GenshinItem item = new GenshinItem(itemData); - item.setLevel(amount); - player.getInventory().addItem(item); - player.sendPacket(new PacketItemAddHintNotify(item, ActionReason.SubfieldDrop)); + List items = new LinkedList<>(); + for (int i = 0; i < amount; i++) { + GenshinItem item = new GenshinItem(itemData); + item.setCount(amount); + item.setLevel(lvl); + item.setPromoteLevel(0); + if (lvl > 20) { // 20/40 + item.setPromoteLevel(1); + } else if (lvl > 40) { // 40/50 + item.setPromoteLevel(2); + } else if (lvl > 50) { // 50/60 + item.setPromoteLevel(3); + } else if (lvl > 60) { // 60/70 + item.setPromoteLevel(4); + } else if (lvl > 70) { // 70/80 + item.setPromoteLevel(5); + } else if (lvl > 80) { // 80/90 + item.setPromoteLevel(6); + } + items.add(item); + } + player.getInventory().addItems(items); + player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop)); } else { GenshinItem genshinItem = new GenshinItem(itemData); genshinItem.setCount(amount); @@ -109,4 +154,3 @@ public final class GiveCommand implements CommandHandler { } } } - From ad1c3f9a3b4de30a3978e67e684b2919a5615cf6 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sat, 23 Apr 2022 22:16:59 +0800 Subject: [PATCH 18/27] Will --- .../packet/recv/HandlerAvatarFetterLevelRewardReq.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java index 2269f8606..d93b157df 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java @@ -36,13 +36,14 @@ public class HandlerAvatarFetterLevelRewardReq extends PacketHandler { if (session.getPlayer().getNameCardList().contains(cardId)) { // Already got divorce certificate. - session.send(new PacketAvatarFetterLevelRewardRsp(req.getAvatarGuid(), req.getFetterLevel())); + session.getPlayer().sendPacket(new PacketAvatarFetterLevelRewardRsp(req.getAvatarGuid(), req.getFetterLevel())); return; } GenshinItem item = new GenshinItem(cardId); + session.getPlayer().getInventory().addItem(item); session.getPlayer().sendPacket(new PacketItemAddHintNotify(item, ActionReason.FetterLevelReward)); - session.send(new PacketUnlockNameCardNotify(cardId)); + session.getPlayer().sendPacket(new PacketUnlockNameCardNotify(cardId)); session.send(new PacketAvatarFetterLevelRewardRsp(avatarGuid, req.getFetterLevel(), rewardId)); } } From 3baef42aac418ec5d79891836ece4e893389876c Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sat, 23 Apr 2022 23:48:06 +0800 Subject: [PATCH 19/27] Name Card Done!!!!!!!!!!! --- .../java/emu/grasscutter/data/GenshinData.java | 5 +++++ .../emu/grasscutter/data/def/AvatarData.java | 9 +++++++++ .../grasscutter/game/avatar/GenshinAvatar.java | 18 ++++++++++++++++++ .../HandlerAvatarFetterLevelRewardReq.java | 13 ++++++++----- .../send/PacketAvatarFetterDataNotify.java | 7 +++++++ 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/main/java/emu/grasscutter/data/GenshinData.java b/src/main/java/emu/grasscutter/data/GenshinData.java index 98f235c1e..3b3d351da 100644 --- a/src/main/java/emu/grasscutter/data/GenshinData.java +++ b/src/main/java/emu/grasscutter/data/GenshinData.java @@ -59,6 +59,7 @@ public class GenshinData { private static final Int2ObjectMap sceneDataMap = new Int2ObjectLinkedOpenHashMap<>(); private static final Int2ObjectMap fetterDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap fetterCharacterCardDataMap = new Int2ObjectOpenHashMap<>(); + private static final Int2ObjectMap rewardDataMap = new Int2ObjectOpenHashMap<>(); // Cache private static Map> fetters = new HashMap<>(); @@ -243,6 +244,10 @@ public class GenshinData { return sceneDataMap; } + public static Int2ObjectMap getRewardDataMap() { + return rewardDataMap; + } + public static Map> getFetterDataEntries() { if (fetters.isEmpty()) { fetterDataMap.forEach((k, v) -> { diff --git a/src/main/java/emu/grasscutter/data/def/AvatarData.java b/src/main/java/emu/grasscutter/data/def/AvatarData.java index a714344ae..3beb21eec 100644 --- a/src/main/java/emu/grasscutter/data/def/AvatarData.java +++ b/src/main/java/emu/grasscutter/data/def/AvatarData.java @@ -58,6 +58,7 @@ public class AvatarData extends GenshinResource { private List fetters; private int nameCardRewardId; + private int nameCardId; @Override public int getId(){ @@ -204,6 +205,10 @@ public class AvatarData extends GenshinResource { return nameCardRewardId; } + public int getNameCardId() { + return nameCardId; + } + @Override public void onLoad() { this.skillDepot = GenshinData.getAvatarSkillDepotDataMap().get(this.SkillDepotId); @@ -214,6 +219,10 @@ public class AvatarData extends GenshinResource { if (GenshinData.getFetterCharacterCardDataMap().get(this.Id) != null) { this.nameCardRewardId = GenshinData.getFetterCharacterCardDataMap().get(this.Id).getRewardId(); } + + if (GenshinData.getRewardDataMap().get(this.nameCardRewardId) != null) { + this.nameCardId = GenshinData.getRewardDataMap().get(this.nameCardRewardId).getRewardItemList().get(0).getItemId(); + } int size = GenshinData.getAvatarCurveDataMap().size(); this.hpGrowthCurve = new float[size]; diff --git a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java index 45b5c09ec..ab2f67a43 100644 --- a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java @@ -94,6 +94,7 @@ public class GenshinAvatar { private int fetterExp; private int nameCardRewardId; + private int nameCardId; public GenshinAvatar() { // Morhpia only! @@ -113,6 +114,7 @@ public class GenshinAvatar { this(); this.avatarId = data.getId(); this.nameCardRewardId = data.getNameCardRewardId(); + this.nameCardId = data.getNameCardId(); this.data = data; this.bornTime = (int) (System.currentTimeMillis() / 1000); this.flyCloak = 140001; @@ -311,6 +313,14 @@ public class GenshinAvatar { this.fetterExp = fetterExp; } + public int getNameCardId() { + return nameCardId; + } + + public void setNameCardId(int nameCardId) { + this.nameCardId = nameCardId; + } + public float getCurrentHp() { return currentHp; } @@ -434,6 +444,7 @@ public class GenshinAvatar { // Fetters this.setFetterList(data.getFetters()); this.setNameCardRewardId(data.getNameCardRewardId()); + this.setNameCardId(data.getNameCardId()); // Get hp percent, set to 100% if none float hpPercent = this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) <= 0 ? 1f : this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) / this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP); @@ -746,6 +757,13 @@ public class GenshinAvatar { } } + int rewardId = this.getNameCardRewardId(); + int cardId = this.getNameCardId(); + + if (this.getPlayer().getNameCardList().contains(cardId)) { + avatarFetter.addRewardedFetterLevelList(rewardId); + } + AvatarInfo.Builder avatarInfo = AvatarInfo.newBuilder() .setAvatarId(this.getAvatarId()) .setGuid(this.getGuid()) diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java index d93b157df..51192f620 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java @@ -1,14 +1,15 @@ package emu.grasscutter.server.packet.recv; -import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GenshinData; import emu.grasscutter.data.def.RewardData; +import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.inventory.GenshinItem; import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.AvatarFetterLevelRewardReqOuterClass.AvatarFetterLevelRewardReq; import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify; import emu.grasscutter.server.packet.send.PacketAvatarFetterLevelRewardRsp; import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; import emu.grasscutter.server.packet.send.PacketUnlockNameCardNotify; @@ -25,18 +26,19 @@ public class HandlerAvatarFetterLevelRewardReq extends PacketHandler { } else { long avatarGuid = req.getAvatarGuid(); - int rewardId = session + GenshinAvatar avatar = session .getPlayer() .getAvatars() - .getAvatarByGuid(avatarGuid) - .getNameCardRewardId(); + .getAvatarByGuid(avatarGuid); + + int rewardId = avatar.getNameCardRewardId(); RewardData card = GenshinData.getRewardDataMap().get(rewardId); int cardId = card.getRewardItemList().get(0).getItemId(); if (session.getPlayer().getNameCardList().contains(cardId)) { // Already got divorce certificate. - session.getPlayer().sendPacket(new PacketAvatarFetterLevelRewardRsp(req.getAvatarGuid(), req.getFetterLevel())); + session.getPlayer().sendPacket(new PacketAvatarFetterLevelRewardRsp(req.getAvatarGuid(), req.getFetterLevel(), rewardId)); return; } @@ -45,6 +47,7 @@ public class HandlerAvatarFetterLevelRewardReq extends PacketHandler { session.getPlayer().sendPacket(new PacketItemAddHintNotify(item, ActionReason.FetterLevelReward)); session.getPlayer().sendPacket(new PacketUnlockNameCardNotify(cardId)); session.send(new PacketAvatarFetterLevelRewardRsp(avatarGuid, req.getFetterLevel(), rewardId)); + session.send(new PacketAvatarFetterDataNotify(avatar)); } } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java index 86cea0e02..6be12e603 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java @@ -26,6 +26,13 @@ public class PacketAvatarFetterDataNotify extends GenshinPacket { ); } } + + int rewardId = avatar.getNameCardRewardId(); + int cardId = avatar.getNameCardId(); + + if (avatar.getPlayer().getNameCardList().contains(cardId)) { + avatarFetter.addRewardedFetterLevelList(rewardId); + } AvatarFetterInfo avatarFetterInfo = avatarFetter.build(); From 2dd8932144c8808af5c6aa288ed0a7e8d0e6e30b Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sun, 24 Apr 2022 03:10:07 +0800 Subject: [PATCH 20/27] Add Teleport command --- .../command/commands/PositionCommand.java | 3 +- .../command/commands/TelePortCommand.java | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/main/java/emu/grasscutter/command/commands/TelePortCommand.java diff --git a/src/main/java/emu/grasscutter/command/commands/PositionCommand.java b/src/main/java/emu/grasscutter/command/commands/PositionCommand.java index 639301c7f..8bdf3c754 100644 --- a/src/main/java/emu/grasscutter/command/commands/PositionCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/PositionCommand.java @@ -17,6 +17,7 @@ public final class PositionCommand implements CommandHandler { return; } - sender.dropMessage(String.format("Coord: %.3f, %.3f, %.3f", sender.getPos().getX(), sender.getPos().getY(), sender.getPos().getZ())); + sender.dropMessage(String.format("Coord: %.3f, %.3f, %.3f\nScene id: %d", + sender.getPos().getX(), sender.getPos().getY(), sender.getPos().getZ(), sender.getSceneId())); } } diff --git a/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java b/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java new file mode 100644 index 000000000..1a9e4f87a --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java @@ -0,0 +1,43 @@ +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.utils.Position; + +import java.util.List; + +@Command(label = "teleport", usage = "teleport ", aliases = {"tp"}, + description = "Change the player's position.", permission = "player.teleport") +public class TelePortCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + if (args.size() < 3){ + CommandHandler.sendMessage(sender, "Usage: /tp [scene id]"); + return; + } + + try { + float x = Float.parseFloat(args.get(0)); + float y = Float.parseFloat(args.get(1)); + float z = Float.parseFloat(args.get(2)); + int sceneId = sender.getSceneId(); + if (args.size() == 4){ + sceneId = Integer.parseInt(args.get(3)); + } + Position target = new Position(x, y, z); + boolean result = sender.getWorld().transferPlayerToScene(sender, sceneId, target); + if (!result) { + CommandHandler.sendMessage(sender, "Invalid position."); + } + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid position."); + } + } +} From 6dae4d43fe4eb207ffefdcd7fc74152096e25688 Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Sat, 23 Apr 2022 22:33:52 +0200 Subject: [PATCH 21/27] Add level parameter to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 853c37ae3..e6049370b 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ There is a dummy user named "Server" in every player's friends list that you can `spawn [monster id] [level] [amount]` -`give [item id] [amount]` +`give [item id] [amount] [level]` `givechar [avatar id] [level]` From 9e523da18eebf9eedddbbbf6ad8f9ec67c3e2bd8 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sun, 24 Apr 2022 05:20:59 +0800 Subject: [PATCH 22/27] tp with relative coordinates --- .../command/commands/TelePortCommand.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java b/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java index 1a9e4f87a..84848afa5 100644 --- a/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java @@ -24,9 +24,36 @@ public class TelePortCommand implements CommandHandler { } try { - float x = Float.parseFloat(args.get(0)); - float y = Float.parseFloat(args.get(1)); - float z = Float.parseFloat(args.get(2)); + float x = 0f; + float y = 0f; + float z = 0f; + if (args.get(0).contains("~")) { + if (args.get(0).equals("~")) { + x = sender.getPos().getX(); + } else { + x = Float.parseFloat(args.get(0).replace("~", "")) + sender.getPos().getX(); + } + } else { + x = Float.parseFloat(args.get(0)); + } + if (args.get(1).contains("~")) { + if (args.get(1).equals("~")) { + y = sender.getPos().getY(); + } else { + y = Float.parseFloat(args.get(1).replace("~", "")) + sender.getPos().getY(); + } + } else { + y = Float.parseFloat(args.get(1)); + } + if (args.get(2).contains("~")) { + if (args.get(2).equals("~")) { + z = sender.getPos().getZ(); + } else { + z = Float.parseFloat(args.get(2).replace("~", "")) + sender.getPos().getZ(); + } + } else { + z = Float.parseFloat(args.get(2)); + } int sceneId = sender.getSceneId(); if (args.size() == 4){ sceneId = Integer.parseInt(args.get(3)); From 7792c5c73fe9c163ae2dfcb265648d302319d22b Mon Sep 17 00:00:00 2001 From: Miyucchi Date: Sun, 24 Apr 2022 00:10:26 +0200 Subject: [PATCH 23/27] Fix counter --- src/main/java/emu/grasscutter/database/DatabaseManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/database/DatabaseManager.java b/src/main/java/emu/grasscutter/database/DatabaseManager.java index 9d64f9258..6df2ca9f0 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseManager.java +++ b/src/main/java/emu/grasscutter/database/DatabaseManager.java @@ -101,7 +101,7 @@ public final class DatabaseManager { } public static synchronized int getNextId(Class c) { - DatabaseCounter counter = getDatastore().find(DatabaseCounter.class).filter(Filters.eq("_id", c.getName())).first(); + DatabaseCounter counter = getDatastore().find(DatabaseCounter.class).filter(Filters.eq("_id", c.getSimpleName())).first(); if (counter == null) { counter = new DatabaseCounter(c.getSimpleName()); } From 031be2e3d13338d130dcb7118b8c391047598461 Mon Sep 17 00:00:00 2001 From: lunaticwhat Date: Sun, 24 Apr 2022 06:00:27 +0700 Subject: [PATCH 24/27] gitignore'd protos --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9df6d0071..4699d31c7 100644 --- a/.gitignore +++ b/.gitignore @@ -50,8 +50,7 @@ resources/* logs/* data/AbilityEmbryos.json data/OpenConfig.json -proto/auto/ -proto/protoc.exe +proto/* GM Handbook.txt config.json mitmdump.exe From b2840b17401950bd5c08ab48dfb9da71a35622dd Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:25:13 +0800 Subject: [PATCH 25/27] Player level reward --- .../recv/HandlerTakePlayerLevelRewardReq.java | 43 +++++++++++++++++++ .../send/PacketTakePlayerLevelRewardRsp.java | 26 +++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketTakePlayerLevelRewardRsp.java diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java new file mode 100644 index 000000000..d3f50acee --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java @@ -0,0 +1,43 @@ +package emu.grasscutter.server.packet.recv; + +import java.util.LinkedList; +import java.util.List; + +import emu.grasscutter.data.GenshinData; +import emu.grasscutter.data.common.RewardItemData; +import emu.grasscutter.game.inventory.GenshinItem; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TakePlayerLevelRewardReqOuterClass.TakePlayerLevelRewardReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; +import emu.grasscutter.server.packet.send.PacketTakePlayerLevelRewardRsp; + +@Opcodes(PacketOpcodes.TakePlayerLevelRewardReq) +public class HandlerTakePlayerLevelRewardReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + TakePlayerLevelRewardReq req = TakePlayerLevelRewardReq.parseFrom(payload); + + int level = req.getLevel(); + int rewardId = GenshinData.getPlayerLevelDataMap().get(level).getRewardId(); + + if (rewardId != 0) { + List rewardItems = GenshinData.getRewardDataMap().get(rewardId).getRewardItemList(); + List items = new LinkedList<>(); + for (RewardItemData rewardItem : rewardItems) { + if (rewardItem != null) { + if (rewardItem.getItemId() != 0) { + items.add(new GenshinItem(rewardItem.getItemId(), rewardItem.getItemCount())); + } + } + } + session.getPlayer().getInventory().addItems(items); + session.getPlayer().sendPacket(new PacketItemAddHintNotify(items, ActionReason.PlayerUpgradeReward)); + } + + session.send(new PacketTakePlayerLevelRewardRsp(level, rewardId)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTakePlayerLevelRewardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTakePlayerLevelRewardRsp.java new file mode 100644 index 000000000..5a50d0806 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTakePlayerLevelRewardRsp.java @@ -0,0 +1,26 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.GenshinPacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TakePlayerLevelRewardRspOuterClass.TakePlayerLevelRewardRsp; + +public class PacketTakePlayerLevelRewardRsp extends GenshinPacket { + + public PacketTakePlayerLevelRewardRsp(int level, int rewardId) { + super(PacketOpcodes.TakePlayerLevelRewardRsp); + + int retcode = 0; + + if (rewardId == 0) { + retcode = 1; + } + + TakePlayerLevelRewardRsp proto = TakePlayerLevelRewardRsp.newBuilder() + .setLevel(level) + .setRewardId(rewardId) + .setRetcode(retcode) + .build(); + + this.setData(proto); + } +} From 2f5ae6c784a9cf79ff922a15b4eed5e798b8c5f6 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sun, 24 Apr 2022 11:40:10 +0800 Subject: [PATCH 26/27] GodMode command supports playerId --- .../command/commands/GodModeCommand.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/GodModeCommand.java b/src/main/java/emu/grasscutter/command/commands/GodModeCommand.java index e5635dc9f..0b4139ac1 100644 --- a/src/main/java/emu/grasscutter/command/commands/GodModeCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GodModeCommand.java @@ -1,5 +1,6 @@ package emu.grasscutter.command.commands; +import emu.grasscutter.Grasscutter; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; import emu.grasscutter.game.GenshinPlayer; @@ -16,7 +17,29 @@ public final class GodModeCommand implements CommandHandler { CommandHandler.sendMessage(null, "Run this command in-game."); return; // TODO: toggle player's godmode statue from console or other players } - sender.setGodmode(!sender.inGodmode()); - sender.dropMessage("Godmode is now " + (sender.inGodmode() ? "enabled" : "disabled") + "."); + + int target; + if (args.size() == 1) { + try { + target = Integer.parseInt(args.get(0)); + if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { + target = sender.getUid(); + } + } catch (NumberFormatException e) { + CommandHandler.sendMessage(sender, "Invalid player id."); + return; + } + } else { + target = sender.getUid(); + } + GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); + if (targetPlayer == null) { + CommandHandler.sendMessage(sender, "Player not found."); + return; + } + + targetPlayer.setGodmode(!targetPlayer.inGodmode()); + sender.dropMessage("Godmode is now " + (targetPlayer.inGodmode() ? "enabled" : "disabled") + + "for " + targetPlayer.getNickname() + " ."); } } From 56a1ab64abf8b3ca3693090d11ef46c7cca6ea35 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sun, 24 Apr 2022 13:22:26 +0800 Subject: [PATCH 27/27] Player Level Reward Update Notify Support! --- .../emu/grasscutter/game/GenshinPlayer.java | 12 ++++++++++ .../recv/HandlerTakePlayerLevelRewardReq.java | 5 +++++ .../PacketPlayerLevelRewardUpdateNotify.java | 22 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLevelRewardUpdateNotify.java diff --git a/src/main/java/emu/grasscutter/game/GenshinPlayer.java b/src/main/java/emu/grasscutter/game/GenshinPlayer.java index cdef5852e..271a6f014 100644 --- a/src/main/java/emu/grasscutter/game/GenshinPlayer.java +++ b/src/main/java/emu/grasscutter/game/GenshinPlayer.java @@ -52,6 +52,7 @@ import emu.grasscutter.server.packet.send.PacketPlayerPropNotify; import emu.grasscutter.server.packet.send.PacketPlayerStoreNotify; import emu.grasscutter.server.packet.send.PacketPrivateChatNotify; import emu.grasscutter.server.packet.send.PacketScenePlayerLocationNotify; +import emu.grasscutter.server.packet.send.PacketPlayerLevelRewardUpdateNotify; import emu.grasscutter.server.packet.send.PacketSetNameCardRsp; import emu.grasscutter.server.packet.send.PacketStoreWeightLimitNotify; import emu.grasscutter.server.packet.send.PacketUnlockNameCardNotify; @@ -96,6 +97,7 @@ public class GenshinPlayer { private MpSettingType mpSetting = MpSettingType.MpSettingEnterAfterApply; private boolean showAvatar; private ArrayList shownAvatars; + private Set rewardedLevels; private int sceneId; private int regionId; @@ -143,6 +145,7 @@ public class GenshinPlayer { this.clientAbilityInitFinishHandler = new InvokeHandler(PacketClientAbilityInitFinishNotify.class); this.birthday = new PlayerBirthday(); + this.rewardedLevels = new HashSet<>(); } // On player creation @@ -656,6 +659,14 @@ public class GenshinPlayer { this.updateProfile(); } + public Set getRewardedLevels() { + return rewardedLevels; + } + + public void setRewardedLevels(Set rewardedLevels) { + this.rewardedLevels = rewardedLevels; + } + public SocialDetail.Builder getSocialDetail() { SocialDetail.Builder social = SocialDetail.newBuilder() .setUid(this.getUid()) @@ -773,6 +784,7 @@ public class GenshinPlayer { session.send(new PacketAvatarDataNotify(this)); session.send(new PacketPlayerEnterSceneNotify(this)); // Enter game world + session.send(new PacketPlayerLevelRewardUpdateNotify(rewardedLevels)); session.send(new PacketOpenStateUpdateNotify()); // First notify packets sent diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java index d3f50acee..a81da7758 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java @@ -2,7 +2,9 @@ package emu.grasscutter.server.packet.recv; import java.util.LinkedList; import java.util.List; +import java.util.Set; +import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GenshinData; import emu.grasscutter.data.common.RewardItemData; import emu.grasscutter.game.inventory.GenshinItem; @@ -36,6 +38,9 @@ public class HandlerTakePlayerLevelRewardReq extends PacketHandler { } session.getPlayer().getInventory().addItems(items); session.getPlayer().sendPacket(new PacketItemAddHintNotify(items, ActionReason.PlayerUpgradeReward)); + Set rewardedLevels = session.getPlayer().getRewardedLevels(); + rewardedLevels.add(level); + session.getPlayer().setRewardedLevels(rewardedLevels); } session.send(new PacketTakePlayerLevelRewardRsp(level, rewardId)); diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLevelRewardUpdateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLevelRewardUpdateNotify.java new file mode 100644 index 000000000..6a20e288b --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLevelRewardUpdateNotify.java @@ -0,0 +1,22 @@ +package emu.grasscutter.server.packet.send; + +import java.util.Set; + +import emu.grasscutter.net.packet.GenshinPacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerLevelRewardUpdateNotifyOuterClass.PlayerLevelRewardUpdateNotify; + +public class PacketPlayerLevelRewardUpdateNotify extends GenshinPacket { + + public PacketPlayerLevelRewardUpdateNotify(Set rewardedLevels) { + super(PacketOpcodes.PlayerLevelRewardUpdateNotify); + + PlayerLevelRewardUpdateNotify.Builder proto = PlayerLevelRewardUpdateNotify.newBuilder(); + + for (Integer level : rewardedLevels) { + proto.addLevelList(level); + } + + this.setData(proto.build()); + } +}