Commit a957b8c5 authored by GanyusLeftHorn's avatar GanyusLeftHorn Committed by Melledy
Browse files

Notify client of unlocked recipies on login.

parent 8484a535
package emu.grasscutter.game.managers;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import emu.grasscutter.data.GameData;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.proto.CookRecipeDataOuterClass;
import emu.grasscutter.server.packet.send.PacketCookDataNotify;
public class CookingManager {
private static Set<Integer> defaultUnlockedRecipies;
private final Player player;
public CookingManager(Player player) {
this.player = player;
}
public static void initialize() {
// Initialize the set of recipies that are unlocked by default.
defaultUnlockedRecipies = new HashSet<>();
for (var recipe : GameData.getCookRecipeDataMap().values()) {
if (recipe.isDefaultUnlocked()) {
defaultUnlockedRecipies.add(recipe.getId());
}
}
}
/********************
* Perform cooking.
********************/
/********************
* Notify unlocked recipies.
********************/
private void addDefaultUnlocked() {
// Get recipies that are already unlocked.
var unlockedRecipies = this.player.getUnlockedRecipies();
// Get recipies that should be unlocked by default but aren't.
var additionalRecipies = new HashSet<>(defaultUnlockedRecipies);
additionalRecipies.removeAll(unlockedRecipies.keySet());
// Add them to the player.
for (int id : additionalRecipies) {
unlockedRecipies.put(id, 0);
}
}
public void sendCookDataNofity() {
// Default unlocked recipies to player if they don't have them yet.
this.addDefaultUnlocked();
// Get unlocked recipies.
var unlockedRecipies = this.player.getUnlockedRecipies();
// Construct CookRecipeData protos.
List<CookRecipeDataOuterClass.CookRecipeData> data = new ArrayList<>();
for (var recipe : unlockedRecipies.entrySet()) {
int recipeId = recipe.getKey();
int proficiency = recipe.getValue();
CookRecipeDataOuterClass.CookRecipeData proto = CookRecipeDataOuterClass.CookRecipeData.newBuilder()
.setRecipeId(recipeId)
.setProficiency(proficiency)
.build();
data.add(proto);
}
// Send packet.
this.player.sendPacket(new PacketCookDataNotify(data));
}
}
......@@ -30,6 +30,7 @@ import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.inventory.Inventory;
import emu.grasscutter.game.mail.Mail;
import emu.grasscutter.game.mail.MailHandler;
import emu.grasscutter.game.managers.CookingManager;
import emu.grasscutter.game.managers.FurnitureManager;
import emu.grasscutter.game.managers.InsectCaptureManager;
import emu.grasscutter.game.managers.ResinManager;
......@@ -113,6 +114,7 @@ public class Player {
private Set<Integer> unlockedFurniture;
private Set<Integer> unlockedFurnitureSuite;
private List<ActiveForgeData> activeForges;
private Map<Integer, Integer> unlockedRecipies;
private Integer widgetId;
......@@ -184,6 +186,8 @@ public class Player {
@Transient private GameHome home;
@Transient private FurnitureManager furnitureManager;
@Transient private BattlePassManager battlePassManager;
@Transient private CookingManager cookingManager;
// @Transient private
@Getter @Transient private ActivityManager activityManager;
@Transient private CollectionManager collectionManager;
......@@ -228,6 +232,7 @@ public class Player {
this.unlockedFurniture = new HashSet<>();
this.unlockedFurnitureSuite = new HashSet<>();
this.activeForges = new ArrayList<>();
this.unlockedRecipies = new HashMap<>();
this.setSceneId(3);
this.setRegionId(1);
......@@ -254,6 +259,7 @@ public class Player {
this.resinManager = new ResinManager(this);
this.forgingManager = new ForgingManager(this);
this.furnitureManager = new FurnitureManager(this);
this.cookingManager = new CookingManager(this);
}
// On player creation
......@@ -288,6 +294,7 @@ public class Player {
this.deforestationManager = new DeforestationManager(this);
this.forgingManager = new ForgingManager(this);
this.furnitureManager = new FurnitureManager(this);
this.cookingManager = new CookingManager(this);
}
public int getUid() {
......@@ -666,6 +673,10 @@ public class Player {
return this.activeForges;
}
public Map<Integer, Integer> getUnlockedRecipies() {
return this.unlockedRecipies;
}
public MpSettingType getMpSetting() {
return MpSettingType.MP_SETTING_TYPE_ENTER_AFTER_APPLY; // TEMP
}
......@@ -1298,6 +1309,10 @@ public class Player {
return battlePassManager;
}
public CookingManager getCookingManager() {
return cookingManager;
}
public void loadBattlePassManager() {
if (this.battlePassManager != null) return;
this.battlePassManager = DatabaseHelper.loadBattlePass(this);
......@@ -1506,6 +1521,7 @@ public class Player {
session.send(new PacketCombineDataNotify(this.unlockedCombines));
this.forgingManager.sendForgeDataNotify();
this.resinManager.onPlayerLogin();
this.cookingManager.sendCookDataNofity();
getTodayMoonCard(); // The timer works at 0:0, some users log in after that, use this method to check if they have received a reward today or not. If not, send the reward.
// Battle Pass trigger
......
......@@ -12,6 +12,7 @@ import emu.grasscutter.game.dungeons.DungeonManager;
import emu.grasscutter.game.dungeons.challenge.DungeonChallenge;
import emu.grasscutter.game.expedition.ExpeditionManager;
import emu.grasscutter.game.gacha.GachaManager;
import emu.grasscutter.game.managers.CookingManager;
import emu.grasscutter.game.managers.InventoryManager;
import emu.grasscutter.game.managers.MultiplayerManager;
import emu.grasscutter.game.managers.chat.ChatManager;
......@@ -88,6 +89,7 @@ public final class GameServer extends KcpServer {
DungeonChallenge.initialize();
EnergyManager.initialize();
StaminaManager.initialize();
CookingManager.initialize();
this.address = address;
this.packetHandler = new GameServerPacketHandler(PacketHandler.class);
......
package emu.grasscutter.server.packet.send;
import java.util.List;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.CookDataNotifyOuterClass.CookDataNotify;
import emu.grasscutter.net.proto.CookRecipeDataOuterClass.CookRecipeData;
public class PacketCookDataNotify extends BasePacket {
public PacketCookDataNotify(List<CookRecipeData> recipies) {
super(PacketOpcodes.CookDataNotify);
CookDataNotify proto = CookDataNotify.newBuilder()
.addAllRecipeDataList(recipies)
.build();
this.setData(proto);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment