mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-16 08:56:04 +01:00
implement npc shop
This commit is contained in:
@@ -109,6 +109,16 @@ public class Inventory implements Iterable<GameItem> {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean addItem(GameItem item, ActionReason reason, boolean forceNotify) {
|
||||
boolean result = addItem(item);
|
||||
|
||||
if (reason != null && (forceNotify || result)) {
|
||||
getPlayer().sendPacket(new PacketItemAddHintNotify(item, reason));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void addItems(Collection<GameItem> items) {
|
||||
this.addItems(items, null);
|
||||
|
||||
@@ -25,6 +25,7 @@ import emu.grasscutter.game.inventory.Inventory;
|
||||
import emu.grasscutter.game.mail.Mail;
|
||||
import emu.grasscutter.game.props.ActionReason;
|
||||
import emu.grasscutter.game.props.PlayerProperty;
|
||||
import emu.grasscutter.game.shop.ShopLimit;
|
||||
import emu.grasscutter.game.world.Scene;
|
||||
import emu.grasscutter.game.world.World;
|
||||
import emu.grasscutter.net.packet.BasePacket;
|
||||
@@ -84,6 +85,7 @@ public class Player {
|
||||
private ArrayList<AvatarProfileData> shownAvatars;
|
||||
private Set<Integer> rewardedLevels;
|
||||
private ArrayList<Mail> mail;
|
||||
private ArrayList<ShopLimit> shopLimit;
|
||||
|
||||
private int sceneId;
|
||||
private int regionId;
|
||||
@@ -141,6 +143,8 @@ public class Player {
|
||||
this.birthday = new PlayerBirthday();
|
||||
this.rewardedLevels = new HashSet<>();
|
||||
this.moonCardGetTimes = new HashSet<>();
|
||||
|
||||
this.shopLimit = new ArrayList<>();
|
||||
}
|
||||
|
||||
// On player creation
|
||||
@@ -592,6 +596,35 @@ public class Player {
|
||||
session.send(new PacketCardProductRewardNotify(getMoonCardRemainDays()));
|
||||
}
|
||||
|
||||
public List<ShopLimit> getShopLimit() {
|
||||
return shopLimit;
|
||||
}
|
||||
|
||||
public int getGoodsLimitNum(int goodsId) {
|
||||
for (ShopLimit sl : getShopLimit()) {
|
||||
if (sl.getShopGoodId() == goodsId)
|
||||
return sl.getHasBought();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void addShopLimit(int goodsId, int boughtCount) {
|
||||
boolean found = false;
|
||||
for (ShopLimit sl : getShopLimit()) {
|
||||
if (sl.getShopGoodId() == goodsId){
|
||||
sl.setHasBought(sl.getHasBought() + boughtCount);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
ShopLimit sl = new ShopLimit();
|
||||
sl.setShopGoodId(goodsId);
|
||||
sl.setHasBought(boughtCount);
|
||||
shopLimit.add(sl);
|
||||
}
|
||||
this.save();
|
||||
}
|
||||
|
||||
public boolean inGodmode() {
|
||||
return godmode;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,162 @@
|
||||
package emu.grasscutter.game.shop;
|
||||
|
||||
public class ShopInfo {
|
||||
import emu.grasscutter.data.common.ItemParamData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ShopInfo {
|
||||
public int shopId = 1004;
|
||||
public int goodsId = 0;
|
||||
public ItemParamData goodsItem;
|
||||
public int scoin = 0;
|
||||
public List<ItemParamData> costItemList;
|
||||
public int boughtNum = 0;
|
||||
public int buyLimit = 0;
|
||||
public int beginTime = 0;
|
||||
public int endTime = 1924992000;
|
||||
public int nextRefreshTime = 1924992000;
|
||||
public int minLevel = 0;
|
||||
public int maxLevel = 61;
|
||||
public List<Integer> preGoodsIdList = new ArrayList<>();
|
||||
public int mcoin = 0;
|
||||
public int hcoin = 0;
|
||||
public int disableType = 0;
|
||||
public int secondarySheetId = 0;
|
||||
|
||||
public int getHcoin() {
|
||||
return hcoin;
|
||||
}
|
||||
|
||||
public void setHcoin(int hcoin) {
|
||||
this.hcoin = hcoin;
|
||||
}
|
||||
|
||||
public List<Integer> getPreGoodsIdList() {
|
||||
return preGoodsIdList;
|
||||
}
|
||||
|
||||
public void setPreGoodsIdList(List<Integer> preGoodsIdList) {
|
||||
this.preGoodsIdList = preGoodsIdList;
|
||||
}
|
||||
|
||||
public int getMcoin() {
|
||||
return mcoin;
|
||||
}
|
||||
|
||||
public void setMcoin(int mcoin) {
|
||||
this.mcoin = mcoin;
|
||||
}
|
||||
|
||||
public int getDisableType() {
|
||||
return disableType;
|
||||
}
|
||||
|
||||
public void setDisableType(int disableType) {
|
||||
this.disableType = disableType;
|
||||
}
|
||||
|
||||
public int getSecondarySheetId() {
|
||||
return secondarySheetId;
|
||||
}
|
||||
|
||||
public void setSecondarySheetId(int secondarySheetId) {
|
||||
this.secondarySheetId = secondarySheetId;
|
||||
}
|
||||
|
||||
public int getShopId() {
|
||||
return shopId;
|
||||
}
|
||||
|
||||
public void setShopId(int shopId) {
|
||||
this.shopId = shopId;
|
||||
}
|
||||
|
||||
public int getGoodsId() {
|
||||
return goodsId;
|
||||
}
|
||||
|
||||
public void setGoodsId(int goodsId) {
|
||||
this.goodsId = goodsId;
|
||||
}
|
||||
|
||||
public ItemParamData getGoodsItem() {
|
||||
return goodsItem;
|
||||
}
|
||||
|
||||
public void setGoodsItem(ItemParamData goodsItem) {
|
||||
this.goodsItem = goodsItem;
|
||||
}
|
||||
|
||||
public int getScoin() {
|
||||
return scoin;
|
||||
}
|
||||
|
||||
public void setScoin(int scoin) {
|
||||
this.scoin = scoin;
|
||||
}
|
||||
|
||||
public List<ItemParamData> getCostItemList() {
|
||||
return costItemList;
|
||||
}
|
||||
|
||||
public void setCostItemList(List<ItemParamData> costItemList) {
|
||||
this.costItemList = costItemList;
|
||||
}
|
||||
|
||||
public int getBoughtNum() {
|
||||
return boughtNum;
|
||||
}
|
||||
|
||||
public void setBoughtNum(int boughtNum) {
|
||||
this.boughtNum = boughtNum;
|
||||
}
|
||||
|
||||
public int getBuyLimit() {
|
||||
return buyLimit;
|
||||
}
|
||||
|
||||
public void setBuyLimit(int buyLimit) {
|
||||
this.buyLimit = buyLimit;
|
||||
}
|
||||
|
||||
public int getBeginTime() {
|
||||
return beginTime;
|
||||
}
|
||||
|
||||
public void setBeginTime(int beginTime) {
|
||||
this.beginTime = beginTime;
|
||||
}
|
||||
|
||||
public int getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(int endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public int getNextRefreshTime() {
|
||||
return nextRefreshTime;
|
||||
}
|
||||
|
||||
public void setNextRefreshTime(int nextRefreshTime) {
|
||||
this.nextRefreshTime = nextRefreshTime;
|
||||
}
|
||||
|
||||
public int getMinLevel() {
|
||||
return minLevel;
|
||||
}
|
||||
|
||||
public void setMinLevel(int minLevel) {
|
||||
this.minLevel = minLevel;
|
||||
}
|
||||
|
||||
public int getMaxLevel() {
|
||||
return maxLevel;
|
||||
}
|
||||
|
||||
public void setMaxLevel(int maxLevel) {
|
||||
this.maxLevel = maxLevel;
|
||||
}
|
||||
}
|
||||
|
||||
25
src/main/java/emu/grasscutter/game/shop/ShopLimit.java
Normal file
25
src/main/java/emu/grasscutter/game/shop/ShopLimit.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package emu.grasscutter.game.shop;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
|
||||
@Entity
|
||||
public class ShopLimit {
|
||||
public int getShopGoodId() {
|
||||
return shopGoodId;
|
||||
}
|
||||
|
||||
public void setShopGoodId(int shopGoodId) {
|
||||
this.shopGoodId = shopGoodId;
|
||||
}
|
||||
|
||||
public int getHasBought() {
|
||||
return hasBought;
|
||||
}
|
||||
|
||||
public void setHasBought(int hasBought) {
|
||||
this.hasBought = hasBought;
|
||||
}
|
||||
|
||||
private int shopGoodId;
|
||||
private int hasBought;
|
||||
}
|
||||
@@ -1,12 +1,50 @@
|
||||
package emu.grasscutter.game.shop;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.server.game.GameServer;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ShopManager {
|
||||
private final GameServer server;
|
||||
|
||||
public Int2ObjectMap<List<ShopInfo>> getShopData() {
|
||||
return shopData;
|
||||
}
|
||||
|
||||
private final Int2ObjectMap<List<ShopInfo>> shopData;
|
||||
|
||||
public ShopManager(GameServer server) {
|
||||
this.server = server;
|
||||
this.shopData = new Int2ObjectOpenHashMap<>();
|
||||
this.load();
|
||||
}
|
||||
|
||||
public synchronized void load() {
|
||||
try (FileReader fileReader = new FileReader(Grasscutter.getConfig().DATA_FOLDER + "Shop.json")) {
|
||||
getShopData().clear();
|
||||
List<ShopInfo> banners = Grasscutter.getGsonFactory().fromJson(fileReader, TypeToken.getParameterized(Collection.class, ShopInfo.class).getType());
|
||||
if(banners.size() > 0) {
|
||||
for (ShopInfo shopInfo : banners) {
|
||||
if (!getShopData().containsKey(shopInfo.getShopId()))
|
||||
getShopData().put(shopInfo.getShopId(), new ArrayList<>());
|
||||
getShopData().get(shopInfo.getShopId()).add(shopInfo);
|
||||
Grasscutter.getLogger().info(String.format("Shop add: id [%d], data [%d*%d]", shopInfo.getShopId(), shopInfo.getGoodsItem().getId(), shopInfo.getGoodsItem().getCount()));
|
||||
}
|
||||
Grasscutter.getLogger().info("Shop data successfully loaded.");
|
||||
} else {
|
||||
Grasscutter.getLogger().error("Unable to load shop data. Shop data size is 0.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public GameServer getServer() {
|
||||
|
||||
Reference in New Issue
Block a user