Commit 7b591a2d authored by xtaodada's avatar xtaodada Committed by Melledy
Browse files

implement shopMail giftPackage function


Co-authored-by: default avatarKinesis <CCasusensa@users.noreply.github.com>
parent 73fc9fe4
......@@ -62,6 +62,7 @@ public class GameData {
private static final Int2ObjectMap<FetterData> fetterDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<FetterCharacterCardData> fetterCharacterCardDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<RewardData> rewardDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<RewardBoxData> rewardBoxDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<WorldLevelData> worldLevelDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<DailyDungeonData> dailyDungeonDataMap = new Int2ObjectOpenHashMap<>();
private static final Int2ObjectMap<DungeonData> dungeonDataMap = new Int2ObjectOpenHashMap<>();
......@@ -263,6 +264,10 @@ public class GameData {
return rewardDataMap;
}
public static Int2ObjectMap<RewardBoxData> getRewardBoxDataMap() {
return rewardBoxDataMap;
}
public static Map<Integer, List<Integer>> getFetterDataEntries() {
if (fetters.isEmpty()) {
fetterDataMap.forEach((k, v) -> {
......
package emu.grasscutter.data.common;
public class RewardBoxItemData {
private int Id;
private String Count;
public int getItemId() {
return Id;
}
public void setItemId(int itemId) {
Id = itemId;
}
public String getItemCount() {
return Count;
}
public void setItemCount(String itemCount) {
Count = itemCount;
}
}
package emu.grasscutter.data.def;
import java.util.List;
import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.ResourceType;
import emu.grasscutter.data.common.RewardBoxItemData;
@ResourceType(name = "RewardPreviewExcelConfigData.json")
public class RewardBoxData extends GameResource {
public int Id;
public List<RewardBoxItemData> PreviewItems;
@Override
public int getId() {
return Id;
}
public List<RewardBoxItemData> getRewardBoxItemList() {
return PreviewItems;
}
@Override
public void onLoad() {
}
}
......@@ -30,6 +30,7 @@ public class ShopGoodsData extends GameResource {
private transient ShopInfo.ShopRefreshType RefreshTypeEnum;
private int RefreshParam;
private int ShowId;
@Override
public void onLoad() {
......@@ -105,4 +106,8 @@ public class ShopGoodsData extends GameResource {
public int getRefreshParam() {
return RefreshParam;
}
public int getShowId() {
return ShowId;
}
}
......@@ -58,6 +58,9 @@ public class GameItem {
// Relic
private int mainPropId;
private List<Integer> appendPropIdList;
// shopMailBox
private int rewardBoxId;
private int equipCharacter;
@Transient private int weaponEntityId;
......@@ -90,7 +93,7 @@ public class GameItem {
// Equip data
if (getItemType() == ItemType.ITEM_WEAPON) {
this.level = this.count > 1 ? this.count : 1;
this.level = Math.max(this.count, 1);
this.affixes = new ArrayList<>(2);
if (getItemData().getSkillAffix() != null) {
for (int skillAffix : getItemData().getSkillAffix()) {
......@@ -248,6 +251,14 @@ public class GameItem {
this.mainPropId = mainPropId;
}
public int getRewardBoxId() {
return rewardBoxId;
}
public void setRewardBoxId(int rewardBoxId) {
this.rewardBoxId = rewardBoxId;
}
public List<Integer> getAppendPropIdList() {
return appendPropIdList;
}
......
......@@ -7,11 +7,13 @@ import java.util.stream.Collectors;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.data.common.RewardBoxItemData;
import emu.grasscutter.data.custom.OpenConfigEntry;
import emu.grasscutter.data.custom.OpenConfigEntry.SkillPointModifier;
import emu.grasscutter.data.def.AvatarPromoteData;
import emu.grasscutter.data.def.AvatarSkillData;
import emu.grasscutter.data.def.AvatarSkillDepotData;
import emu.grasscutter.data.def.RewardBoxData;
import emu.grasscutter.data.def.WeaponPromoteData;
import emu.grasscutter.data.def.AvatarSkillDepotData.InherentProudSkillOpens;
import emu.grasscutter.data.def.AvatarTalentData;
......@@ -21,6 +23,7 @@ import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.inventory.ItemType;
import emu.grasscutter.game.inventory.MaterialType;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam;
import emu.grasscutter.net.proto.MaterialInfoOuterClass.MaterialInfo;
import emu.grasscutter.server.game.GameServer;
......@@ -897,6 +900,26 @@ public class InventoryManager {
player.sendPacket(new PacketDestroyMaterialRsp(returnMaterialMap));
}
private boolean handleRewardBox(Player player, GameItem useItem) {
List<RewardBoxData> rewardBoxDataList = GameData.getRewardBoxDataMap().values().stream().filter(x -> x.getId() == useItem.getRewardBoxId()).collect(Collectors.toList());
if (rewardBoxDataList.isEmpty()) {
return false;
}
List<GameItem> rewardItemList = new ArrayList<>();
for (RewardBoxItemData itemData : rewardBoxDataList.get(0).getRewardBoxItemList()) {
if (itemData.getItemId() == 0) {
continue;
}
String[] split = itemData.getItemCount().split(";");
int itemCount = Integer.parseInt(split[(int) (Math.random()* split.length)]);
rewardItemList.add(new GameItem(itemData.getItemId(), itemCount));
}
if (!rewardItemList.isEmpty()) {
player.getInventory().addItems(rewardItemList, ActionReason.Shop);
}
return true;
}
public GameItem useItem(Player player, long targetGuid, long itemGuid, int count) {
Avatar target = player.getAvatars().getAvatarByGuid(targetGuid);
GameItem useItem = player.getInventory().getItemByGuid(itemGuid);
......@@ -918,6 +941,11 @@ public class InventoryManager {
used = player.getTeamManager().reviveAvatar(target) ? 1 : 0;
}
break;
case MATERIAL_CHEST:
if (useItem.getRewardBoxId() > 0) {
used = handleRewardBox(player, useItem) ? 1 : 0;
}
break;
default:
break;
}
......
......@@ -13,6 +13,7 @@ public class ShopInfo {
private List<ItemParamData> costItemList;
private int boughtNum = 0;
private int buyLimit = 0;
private int showId = 0;
private int beginTime = 0;
private int endTime = 1924992000;
private int minLevel = 0;
......@@ -51,6 +52,7 @@ public class ShopInfo {
this.mcoin = sgd.getCostMcoin();
this.hcoin = sgd.getCostHcoin();
this.buyLimit = sgd.getBuyLimit();
this.showId = sgd.getShowId();
this.minLevel = sgd.getMinPlayerLevel();
this.maxLevel = sgd.getMaxPlayerLevel();
......@@ -180,6 +182,14 @@ public class ShopInfo {
this.maxLevel = maxLevel;
}
public int getShowId() {
return showId;
}
public void setShowId(int showId) {
this.showId = showId;
}
public ShopRefreshType getShopRefreshType() {
if (refreshType == null)
return ShopRefreshType.NONE;
......
......@@ -4,7 +4,6 @@ import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.game.shop.ShopInfo;
import emu.grasscutter.game.shop.ShopLimit;
import emu.grasscutter.game.shop.ShopManager;
......@@ -19,7 +18,6 @@ import emu.grasscutter.server.packet.send.PacketBuyGoodsRsp;
import emu.grasscutter.server.packet.send.PacketStoreItemChangeNotify;
import emu.grasscutter.utils.Utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
......@@ -92,6 +90,9 @@ public class HandlerBuyGoodsReq extends PacketHandler {
session.getPlayer().addShopLimit(sg.getGoodsId(), buyGoodsReq.getBoughtNum(), ShopManager.getShopNextRefreshTime(sg));
GameItem item = new GameItem(GameData.getItemDataMap().get(sg.getGoodsItem().getId()));
item.setCount(buyGoodsReq.getBoughtNum() * sg.getGoodsItem().getCount());
if (sg.getShowId() > 0) {
item.setRewardBoxId(sg.getShowId());
}
session.getPlayer().getInventory().addItem(item, ActionReason.Shop, true); // fix: not notify when got virtual item from shop
session.send(new PacketBuyGoodsRsp(buyGoodsReq.getShopType(), session.getPlayer().getGoodsLimit(sg.getGoodsId()).getHasBoughtInPeriod(), buyGoodsReq.getGoodsListList().stream().filter(x -> x.getGoodsId() == goodsId).findFirst().get()));
}
......
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