mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-13 12:54:36 +01:00
Implement resident shop
This commit is contained in:
@@ -18,6 +18,7 @@ import lombok.Getter;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class GameData {
|
||||
// Characters
|
||||
@Getter private static DataTable<CharacterDef> CharacterDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<CharacterAdvanceDef> CharacterAdvanceDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<CharacterSkillUpgradeDef> CharacterSkillUpgradeDataTable = new DataTable<>();
|
||||
@@ -27,12 +28,14 @@ public class GameData {
|
||||
@Getter private static DataTable<TalentGroupDef> TalentGroupDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<TalentDef> TalentDataTable = new DataTable<>();
|
||||
|
||||
// Discs
|
||||
@Getter private static DataTable<DiscDef> DiscDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<DiscStrengthenDef> DiscStrengthenDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<DiscItemExpDef> DiscItemExpDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<DiscPromoteDef> DiscPromoteDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<DiscPromoteLimitDef> DiscPromoteLimitDataTable = new DataTable<>();
|
||||
|
||||
// Items
|
||||
@Getter private static DataTable<ItemDef> ItemDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<ProductionDef> ProductionDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<PlayerHeadDef> PlayerHeadDataTable = new DataTable<>();
|
||||
@@ -43,9 +46,14 @@ public class GameData {
|
||||
@Getter private static DataTable<MallShopDef> MallShopDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<MallGemDef> MallGemDataTable = new DataTable<>();
|
||||
|
||||
@Getter private static DataTable<ResidentShopDef> ResidentShopDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<ResidentGoodsDef> ResidentGoodsDataTable = new DataTable<>();
|
||||
|
||||
// Dictionary
|
||||
@Getter private static DataTable<DictionaryTabDef> DictionaryTabDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<DictionaryEntryDef> DictionaryEntryDataTable = new DataTable<>();
|
||||
|
||||
// Instances
|
||||
@Getter private static DataTable<DailyInstanceDef> DailyInstanceDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<DailyInstanceRewardGroupDef> DailyInstanceRewardGroupDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<RegionBossLevelDef> RegionBossLevelDataTable = new DataTable<>();
|
||||
@@ -62,9 +70,11 @@ public class GameData {
|
||||
@Getter private static DataTable<StoryDef> StoryDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<StorySetSectionDef> StorySetSectionDataTable = new DataTable<>();
|
||||
|
||||
// Daily quests
|
||||
@Getter private static DataTable<DailyQuestDef> DailyQuestDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<DailyQuestActiveDef> DailyQuestActiveDataTable = new DataTable<>();
|
||||
|
||||
// Star tower
|
||||
@Getter private static DataTable<StarTowerDef> StarTowerDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<StarTowerStageDef> StarTowerStageDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<PotentialDef> PotentialDataTable = new DataTable<>();
|
||||
|
||||
@@ -2,11 +2,10 @@ package emu.nebula.data.resources;
|
||||
|
||||
import emu.nebula.data.BaseDef;
|
||||
import emu.nebula.data.ResourceType;
|
||||
import emu.nebula.data.ResourceType.LoadPriority;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@ResourceType(name = "Handbook.json", loadPriority = LoadPriority.LOW)
|
||||
@ResourceType(name = "Handbook.json")
|
||||
public class HandbookDef extends BaseDef {
|
||||
private int Id;
|
||||
private int Index;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package emu.nebula.data.resources;
|
||||
|
||||
import emu.nebula.data.BaseDef;
|
||||
import emu.nebula.data.ResourceType;
|
||||
import emu.nebula.game.inventory.ItemParamMap;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@ResourceType(name = "ResidentGoods.json")
|
||||
public class ResidentGoodsDef extends BaseDef {
|
||||
private int Id;
|
||||
private int ShopId;
|
||||
private int MaximumLimit;
|
||||
|
||||
private int ItemId;
|
||||
private int ItemQuantity;
|
||||
|
||||
private int CurrencyItemId;
|
||||
private int Price;
|
||||
|
||||
private transient ItemParamMap products;
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return Id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
this.products = new ItemParamMap();
|
||||
|
||||
if (this.ItemId > 0) {
|
||||
this.products.add(this.ItemId, this.ItemQuantity);
|
||||
}
|
||||
}
|
||||
}
|
||||
16
src/main/java/emu/nebula/data/resources/ResidentShopDef.java
Normal file
16
src/main/java/emu/nebula/data/resources/ResidentShopDef.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package emu.nebula.data.resources;
|
||||
|
||||
import emu.nebula.data.BaseDef;
|
||||
import emu.nebula.data.ResourceType;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@ResourceType(name = "ResidentShop.json")
|
||||
public class ResidentShopDef extends BaseDef {
|
||||
private int Id;
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return Id;
|
||||
}
|
||||
}
|
||||
@@ -594,6 +594,11 @@ public class Inventory extends PlayerManager implements GameDatabaseObject {
|
||||
change = new PlayerChangeInfo();
|
||||
}
|
||||
|
||||
// Sanity check
|
||||
if (buyCount <= 0) {
|
||||
return change;
|
||||
}
|
||||
|
||||
// Make sure we have the currency
|
||||
int cost = buyCount * currencyCount;
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.Public.ResidentShop;
|
||||
import emu.nebula.proto.ResidentShopGet.ResidentShopGetResp;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@HandlerId(NetMsgId.resident_shop_get_req)
|
||||
public class HandlerResidentShopGetReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Build response
|
||||
var rsp = ResidentShopGetResp.newInstance();
|
||||
|
||||
for (var data : GameData.getResidentShopDataTable()) {
|
||||
var proto = ResidentShop.newInstance()
|
||||
.setId(data.getId())
|
||||
.setRefreshTime(Long.MAX_VALUE);
|
||||
|
||||
rsp.addShops(proto);
|
||||
}
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.resident_shop_get_succeed_ack, rsp);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.ResidentShopPurchase.ResidentShopPurchaseReq;
|
||||
import emu.nebula.proto.ResidentShopPurchase.ResidentShopPurchaseResp;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@HandlerId(NetMsgId.resident_shop_purchase_req)
|
||||
public class HandlerResidentShopPurchaseReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Parse request
|
||||
var req = ResidentShopPurchaseReq.parseFrom(message);
|
||||
|
||||
// Get goods
|
||||
var data = GameData.getResidentGoodsDataTable().get(req.getGoodsId());
|
||||
if (data == null) {
|
||||
return session.encodeMsg(NetMsgId.resident_shop_purchase_failed_ack);
|
||||
}
|
||||
|
||||
// Buy
|
||||
var change = session.getPlayer().getInventory().buyItem(
|
||||
data.getCurrencyItemId(),
|
||||
data.getPrice(),
|
||||
data.getProducts(),
|
||||
req.getNumber()
|
||||
);
|
||||
|
||||
// Build response
|
||||
var rsp = ResidentShopPurchaseResp.newInstance()
|
||||
.setChange(change.toProto())
|
||||
.setPurchasedNumber(0); // Prevent avaliable item count from decreasing
|
||||
|
||||
rsp.getMutableShop()
|
||||
.setId(data.getShopId())
|
||||
.setRefreshTime(Long.MAX_VALUE);
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.resident_shop_purchase_succeed_ack, rsp);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user