Implement monolith shop refresh

This commit is contained in:
Melledy
2025-12-03 22:23:41 -08:00
parent c8a7db75aa
commit 357d12779b
6 changed files with 134 additions and 35 deletions

View File

@@ -440,7 +440,7 @@ public class StarTowerGame {
// Create shop npc if this is the last room
if (this.isOnFinalFloor()) {
// Create hawker case (shop)
cases.add(new StarTowerHawkerCase(this));
cases.add(new StarTowerHawkerCase());
// Create strengthen machine
if (this.getModifiers().isEnableEndStrengthen()) {
cases.add(new StarTowerStrengthenMachineCase());

View File

@@ -19,6 +19,12 @@ public class StarTowerModifiers {
// Bonus max potential level
private int bonusMaxPotentialLevel;
// Shop
private int shopGoodsCount;
private int shopRerollCount;
private int shopRerollPrice;
public StarTowerModifiers(StarTowerGame game) {
this.game = game;
@@ -41,6 +47,28 @@ public class StarTowerModifiers {
} else if (this.hasGrowthNode(20601)) {
this.bonusMaxPotentialLevel = 4;
}
// Shop
if (this.hasGrowthNode(20702)) {
this.shopGoodsCount = 8;
} else if (this.hasGrowthNode(20402)) {
this.shopGoodsCount = 6;
} else if (this.hasGrowthNode(10402)) {
this.shopGoodsCount = 4;
} else {
this.shopGoodsCount = 2;
}
if (this.hasGrowthNode(20902)) {
this.shopRerollCount++;
}
if (this.hasGrowthNode(30601)) {
this.shopRerollCount++;
}
if (this.shopRerollCount > 0) {
this.shopRerollPrice = 100;
}
}
public boolean hasGrowthNode(int nodeId) {
@@ -64,4 +92,8 @@ public class StarTowerModifiers {
public void setFreeStrengthen(boolean b) {
this.freeStrengthen = b;
}
public void consumeShopReroll() {
this.shopRerollCount = Math.max(this.shopRerollCount - 1, 0);
}
}

View File

@@ -27,13 +27,18 @@ public abstract class StarTowerBaseCase {
public StarTowerModifiers getModifiers() {
return this.getGame().getModifiers();
}
public abstract CaseType getType();
public void register(StarTowerBaseRoom room) {
this.game = room.getGame();
this.id = room.getNextCaseId();
this.onRegister();
}
public abstract CaseType getType();
public void onRegister() {
}
public abstract StarTowerInteractResp interact(StarTowerInteractReq req, StarTowerInteractResp rsp);

View File

@@ -4,8 +4,8 @@ import java.util.HashMap;
import java.util.Map;
import emu.nebula.GameConstants;
import emu.nebula.game.tower.StarTowerGame;
import emu.nebula.game.tower.StarTowerShopGoods;
import emu.nebula.proto.PublicStarTower.HawkerCaseData;
import emu.nebula.proto.PublicStarTower.HawkerGoods;
import emu.nebula.proto.PublicStarTower.StarTowerRoomCase;
import emu.nebula.proto.StarTowerInteract.StarTowerInteractReq;
@@ -19,23 +19,29 @@ public class StarTowerHawkerCase extends StarTowerBaseCase {
public StarTowerHawkerCase() {
this.goods = new HashMap<>();
}
public StarTowerHawkerCase(StarTowerGame game) {
this();
// Create shop goods
for (int i = 0; i < 6; i++) {
this.addGoods(new StarTowerShopGoods(1, 1, 200));
}
// TODO apply discounts based on star tower talents
}
@Override
public CaseType getType() {
return CaseType.Hawker;
}
@Override
public void onRegister() {
this.initGoods();
}
public void initGoods() {
// Clear goods
this.getGoods().clear();
// Add goods
for (int i = 0; i < getModifiers().getShopGoodsCount(); i++) {
this.addGoods(new StarTowerShopGoods(1, 1, 200));
}
// TODO apply discounts based on star tower talents
}
public void addGoods(StarTowerShopGoods goods) {
this.getGoods().put(getGoods().size() + 1, goods);
}
@@ -45,16 +51,65 @@ public class StarTowerHawkerCase extends StarTowerBaseCase {
// Set nil resp
rsp.getMutableNilResp();
// Get goods
var goods = this.getGoods().get(req.getHawkerReq().getSid());
if (goods == null) {
return rsp;
// Get hawker req
var hawker = req.getHawkerReq();
if (hawker.hasReRoll()) {
// Refresh shop items
this.refresh(rsp);
} else if (hawker.hasSid()) {
// Buy shop items
this.buy(hawker.getSid(), rsp);
}
// Success
return rsp;
}
private void refresh(StarTowerInteractResp rsp) {
// Check if we can refresh
if (this.getModifiers().getShopRerollCount() <= 0) {
return;
}
// Make sure we have enough currency
int coin = this.getGame().getRes().get(GameConstants.STAR_TOWER_COIN_ITEM_ID);
if (coin < goods.getPrice() || goods.isSold()) {
return rsp;
int coin = this.getGame().getResCount(GameConstants.STAR_TOWER_COIN_ITEM_ID);
int price = this.getModifiers().getShopRerollPrice();
if (coin < price) {
return;
}
// Create new goods
this.initGoods();
// Set in proto
rsp.getMutableSelectResp()
.setHawkerCase(this.toHawkerCaseProto());
// Remove coins
var change = this.getGame().addItem(GameConstants.STAR_TOWER_COIN_ITEM_ID, -price);
// Set change info
rsp.setChange(change.toProto());
// Consume reroll count
this.getGame().getModifiers().consumeShopReroll();
}
private void buy(int sid, StarTowerInteractResp rsp) {
// Get goods
var goods = this.getGoods().get(sid);
if (goods == null) {
return;
}
// Make sure we have enough currency
int coin = this.getGame().getResCount(GameConstants.STAR_TOWER_COIN_ITEM_ID);
int price = goods.getPrice();
if (coin < price || goods.isSold()) {
return;
}
// Mark goods as sold
@@ -63,21 +118,23 @@ public class StarTowerHawkerCase extends StarTowerBaseCase {
// Add case
this.getGame().addCase(rsp.getMutableCases(), this.getGame().createPotentialSelector());
// Remove items
var change = this.getGame().addItem(GameConstants.STAR_TOWER_COIN_ITEM_ID, -goods.getPrice());
// Remove coins
var change = this.getGame().addItem(GameConstants.STAR_TOWER_COIN_ITEM_ID, -price);
// Set change info
rsp.setChange(change.toProto());
// Success
return rsp;
}
// Proto
@Override
public void encodeProto(StarTowerRoomCase proto) {
var hawker = proto.getMutableHawkerCase();
private HawkerCaseData toHawkerCaseProto() {
var hawker = HawkerCaseData.newInstance();
if (this.getModifiers().getShopRerollCount() > 0) {
hawker.setCanReRoll(true);
hawker.setReRollTimes(this.getModifiers().getShopRerollCount());
hawker.setReRollPrice(this.getModifiers().getShopRerollPrice());
}
for (var entry : this.getGoods().entrySet()) {
var sid = entry.getKey();
@@ -93,5 +150,12 @@ public class StarTowerHawkerCase extends StarTowerBaseCase {
hawker.addList(info);
}
return hawker;
}
@Override
public void encodeProto(StarTowerRoomCase proto) {
proto.setHawkerCase(this.toHawkerCaseProto());
}
}

View File

@@ -1,10 +1,10 @@
package emu.nebula.game.tower.cases;
import emu.nebula.GameConstants;
import emu.nebula.game.tower.room.StarTowerBaseRoom;
import emu.nebula.proto.PublicStarTower.StarTowerRoomCase;
import emu.nebula.proto.StarTowerInteract.StarTowerInteractReq;
import emu.nebula.proto.StarTowerInteract.StarTowerInteractResp;
import lombok.Getter;
@Getter
@@ -14,10 +14,8 @@ public class StarTowerStrengthenMachineCase extends StarTowerBaseCase {
private int times;
@Override
public void register(StarTowerBaseRoom room) {
super.register(room);
// Also set strengthen price
public void onRegister() {
// Set strengthen price
this.free = this.getModifiers().isFreeStrengthen();
this.discount = this.getModifiers().getStrengthenDiscount();
}

View File

@@ -17,7 +17,7 @@ public class StarTowerHawkerRoom extends StarTowerBaseRoom {
@Override
public void onEnter() {
// Create hawker case (shop)
this.addCase(new StarTowerHawkerCase(this.getGame()));
this.addCase(new StarTowerHawkerCase());
// Create strengthen machine
if (this.getModifiers().isEnableShopStrengthen()) {