Commit eb64b25f authored by Melledy's avatar Melledy
Browse files

Implement quest rewards

parent 2628227e
package emu.grasscutter.data.common;
import com.google.gson.annotations.SerializedName;
public class ItemParamData {
@SerializedName(value="Id", alternate={"ItemId"})
private int Id;
@SerializedName(value="Count", alternate={"ItemCount"})
private int Count;
public ItemParamData() {}
......@@ -14,7 +19,15 @@ public class ItemParamData {
return Id;
}
public int getItemId() {
return Id;
}
public int getCount() {
return Count;
}
public int getItemCount() {
return Count;
}
}
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;
}
}
......@@ -4,24 +4,24 @@ import java.util.List;
import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.ResourceType;
import emu.grasscutter.data.common.RewardItemData;
import emu.grasscutter.data.common.ItemParamData;
@ResourceType(name = "RewardExcelConfigData.json")
public class RewardData extends GameResource {
public int RewardId;
public List<RewardItemData> RewardItemList;
public List<ItemParamData> RewardItemList;
@Override
public int getId() {
return RewardId;
}
public List<RewardItemData> getRewardItemList() {
public List<ItemParamData> getRewardItemList() {
return RewardItemList;
}
@Override
public void onLoad() {
RewardItemList = RewardItemList.stream().filter(i -> i.getId() > 0).toList();
}
}
......@@ -150,6 +150,14 @@ public class Inventory implements Iterable<GameItem> {
addItems(items.stream().map(param -> new GameItem(param.getItemId(), param.getCount())).toList(), null);
}
public void addItemParamDatas(Collection<ItemParamData> items) {
addItemParamDatas(items, null);
}
public void addItemParamDatas(Collection<ItemParamData> items, ActionReason reason) {
addItems(items.stream().map(param -> new GameItem(param.getItemId(), param.getCount())).toList(), reason);
}
private synchronized GameItem putItem(GameItem item) {
// Dont add items that dont have a valid item definition.
if (item.getItemData() == null) {
......
......@@ -11,8 +11,11 @@ import dev.morphia.annotations.Id;
import dev.morphia.annotations.Indexed;
import dev.morphia.annotations.Transient;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.custom.MainQuestData;
import emu.grasscutter.data.def.RewardData;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.quest.enums.ParentQuestState;
import emu.grasscutter.game.quest.enums.QuestState;
import emu.grasscutter.net.proto.ChildQuestOuterClass.ChildQuest;
......@@ -91,9 +94,23 @@ public class GameMainQuest {
public void finish() {
this.isFinished = true;
this.state = ParentQuestState.PARENT_QUEST_STATE_FINISHED;
this.getOwner().getSession().send(new PacketFinishedParentQuestUpdateNotify(this));
this.getOwner().getSession().send(new PacketCodexDataUpdateNotify(this));
this.save();
// Add rewards
MainQuestData mainQuestData = GameData.getMainQuestDataMap().get(this.getParentQuestId());
for (int rewardId : mainQuestData.getRewardIdList()) {
RewardData rewardData = GameData.getRewardDataMap().get(rewardId);
if (rewardData == null) {
continue;
}
getOwner().getInventory().addItemParamDatas(rewardData.getRewardItemList(), ActionReason.QuestReward);
}
}
public void save() {
......
......@@ -6,7 +6,8 @@ import java.util.Set;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.RewardItemData;
import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.net.packet.Opcodes;
......@@ -27,17 +28,8 @@ public class HandlerTakePlayerLevelRewardReq extends PacketHandler {
int rewardId = GameData.getPlayerLevelDataMap().get(level).getRewardId();
if (rewardId != 0) {
List<RewardItemData> rewardItems = GameData.getRewardDataMap().get(rewardId).getRewardItemList();
List<GameItem> items = new LinkedList<>();
for (RewardItemData rewardItem : rewardItems) {
if (rewardItem != null) {
if (rewardItem.getItemId() != 0) {
items.add(new GameItem(rewardItem.getItemId(), rewardItem.getItemCount()));
}
}
}
session.getPlayer().getInventory().addItems(items);
session.getPlayer().sendPacket(new PacketItemAddHintNotify(items, ActionReason.PlayerUpgradeReward));
List<ItemParamData> rewardItems = GameData.getRewardDataMap().get(rewardId).getRewardItemList();
session.getPlayer().getInventory().addItemParamDatas(rewardItems, ActionReason.PlayerUpgradeReward);
Set<Integer> rewardedLevels = session.getPlayer().getRewardedLevels();
rewardedLevels.add(level);
session.getPlayer().setRewardedLevels(rewardedLevels);
......
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