mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 05:44:36 +01:00
Add basic handling of shops
This commit is contained in:
@@ -28,6 +28,7 @@ public class GameData {
|
||||
@Getter private static Int2ObjectMap<MapEntranceExcel> mapEntranceExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
@Getter private static Int2ObjectMap<HeroExcel> heroExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
@Getter private static Int2ObjectMap<ChallengeExcel> challengeExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
@Getter private static Int2ObjectMap<ShopExcel> shopExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
private static Int2ObjectMap<AvatarPromotionExcel> avatarPromotionExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
private static Int2ObjectMap<AvatarSkillTreeExcel> avatarSkillTreeExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
26
src/main/java/emu/lunarcore/data/excel/ShopExcel.java
Normal file
26
src/main/java/emu/lunarcore/data/excel/ShopExcel.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package emu.lunarcore.data.excel;
|
||||
|
||||
import emu.lunarcore.data.GameResource;
|
||||
import emu.lunarcore.data.ResourceType;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@ResourceType(name = {"ShopConfig.json"})
|
||||
public class ShopExcel extends GameResource {
|
||||
private int ShopID;
|
||||
private int ShopType;
|
||||
|
||||
private transient Int2ObjectMap<ShopGoodsExcel> goods;
|
||||
|
||||
public ShopExcel() {
|
||||
this.goods = new Int2ObjectOpenHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return ShopID;
|
||||
}
|
||||
|
||||
}
|
||||
41
src/main/java/emu/lunarcore/data/excel/ShopGoodsExcel.java
Normal file
41
src/main/java/emu/lunarcore/data/excel/ShopGoodsExcel.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package emu.lunarcore.data.excel;
|
||||
|
||||
import emu.lunarcore.data.GameData;
|
||||
import emu.lunarcore.data.GameResource;
|
||||
import emu.lunarcore.data.ResourceType;
|
||||
import emu.lunarcore.data.ResourceType.LoadPriority;
|
||||
import emu.lunarcore.proto.GoodsOuterClass.Goods;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@ResourceType(name = {"ShopGoodsConfig.json"}, loadPriority = LoadPriority.LOW)
|
||||
public class ShopGoodsExcel extends GameResource {
|
||||
private int GoodsID;
|
||||
private int ItemID;
|
||||
private int ItemCount;
|
||||
private int ShopID;
|
||||
private int[] CurrencyList;
|
||||
private int[] CurrencyCostList;
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return GoodsID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
ShopExcel shop = GameData.getShopExcelMap().get(this.ShopID);
|
||||
if (shop == null) return;
|
||||
|
||||
shop.getGoods().put(this.GoodsID, this);
|
||||
}
|
||||
|
||||
public Goods toProto() {
|
||||
var proto = Goods.newInstance()
|
||||
.setGoodsId(this.getGoodsID())
|
||||
.setItemId(this.getItemID())
|
||||
.setEndTime(Integer.MAX_VALUE);
|
||||
|
||||
return proto;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package emu.lunarcore.server.packet.recv;
|
||||
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.Opcodes;
|
||||
import emu.lunarcore.server.packet.PacketHandler;
|
||||
|
||||
@Opcodes(CmdId.BuyGoodsCsReq)
|
||||
public class HandlerBuyGoodsCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
|
||||
session.send(CmdId.BuyGoodsScRsp);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.data.GameData;
|
||||
import emu.lunarcore.data.excel.ShopExcel;
|
||||
import emu.lunarcore.proto.GetShopListScRspOuterClass.GetShopListScRsp;
|
||||
import emu.lunarcore.proto.ShopOuterClass.Shop;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
@@ -8,10 +11,27 @@ public class PacketGetShopListScRsp extends BasePacket {
|
||||
|
||||
public PacketGetShopListScRsp(int shopType) {
|
||||
super(CmdId.GetShopListScRsp);
|
||||
|
||||
|
||||
var data = GetShopListScRsp.newInstance()
|
||||
.setShopType(shopType);
|
||||
|
||||
for (ShopExcel shopExcel : GameData.getShopExcelMap().values()) {
|
||||
if (shopExcel.getShopType() != shopType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Shop shop = Shop.newInstance()
|
||||
.setShopId(shopExcel.getId())
|
||||
.setCityLevel(1)
|
||||
.setEndTime(Integer.MAX_VALUE);
|
||||
|
||||
for (var goodsExcel : shopExcel.getGoods().values()) {
|
||||
shop.addGoodsList(goodsExcel.toProto());
|
||||
}
|
||||
|
||||
data.addShopList(shop);
|
||||
}
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user