mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-13 12:54:36 +01:00
Implement monolith shop refresh
This commit is contained in:
@@ -440,7 +440,7 @@ public class StarTowerGame {
|
|||||||
// Create shop npc if this is the last room
|
// Create shop npc if this is the last room
|
||||||
if (this.isOnFinalFloor()) {
|
if (this.isOnFinalFloor()) {
|
||||||
// Create hawker case (shop)
|
// Create hawker case (shop)
|
||||||
cases.add(new StarTowerHawkerCase(this));
|
cases.add(new StarTowerHawkerCase());
|
||||||
// Create strengthen machine
|
// Create strengthen machine
|
||||||
if (this.getModifiers().isEnableEndStrengthen()) {
|
if (this.getModifiers().isEnableEndStrengthen()) {
|
||||||
cases.add(new StarTowerStrengthenMachineCase());
|
cases.add(new StarTowerStrengthenMachineCase());
|
||||||
|
|||||||
@@ -19,6 +19,12 @@ public class StarTowerModifiers {
|
|||||||
// Bonus max potential level
|
// Bonus max potential level
|
||||||
private int bonusMaxPotentialLevel;
|
private int bonusMaxPotentialLevel;
|
||||||
|
|
||||||
|
// Shop
|
||||||
|
private int shopGoodsCount;
|
||||||
|
|
||||||
|
private int shopRerollCount;
|
||||||
|
private int shopRerollPrice;
|
||||||
|
|
||||||
public StarTowerModifiers(StarTowerGame game) {
|
public StarTowerModifiers(StarTowerGame game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
@@ -41,6 +47,28 @@ public class StarTowerModifiers {
|
|||||||
} else if (this.hasGrowthNode(20601)) {
|
} else if (this.hasGrowthNode(20601)) {
|
||||||
this.bonusMaxPotentialLevel = 4;
|
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) {
|
public boolean hasGrowthNode(int nodeId) {
|
||||||
@@ -64,4 +92,8 @@ public class StarTowerModifiers {
|
|||||||
public void setFreeStrengthen(boolean b) {
|
public void setFreeStrengthen(boolean b) {
|
||||||
this.freeStrengthen = b;
|
this.freeStrengthen = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void consumeShopReroll() {
|
||||||
|
this.shopRerollCount = Math.max(this.shopRerollCount - 1, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,13 +27,18 @@ public abstract class StarTowerBaseCase {
|
|||||||
public StarTowerModifiers getModifiers() {
|
public StarTowerModifiers getModifiers() {
|
||||||
return this.getGame().getModifiers();
|
return this.getGame().getModifiers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract CaseType getType();
|
||||||
|
|
||||||
public void register(StarTowerBaseRoom room) {
|
public void register(StarTowerBaseRoom room) {
|
||||||
this.game = room.getGame();
|
this.game = room.getGame();
|
||||||
this.id = room.getNextCaseId();
|
this.id = room.getNextCaseId();
|
||||||
|
this.onRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract CaseType getType();
|
public void onRegister() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public abstract StarTowerInteractResp interact(StarTowerInteractReq req, StarTowerInteractResp rsp);
|
public abstract StarTowerInteractResp interact(StarTowerInteractReq req, StarTowerInteractResp rsp);
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import emu.nebula.GameConstants;
|
import emu.nebula.GameConstants;
|
||||||
import emu.nebula.game.tower.StarTowerGame;
|
|
||||||
import emu.nebula.game.tower.StarTowerShopGoods;
|
import emu.nebula.game.tower.StarTowerShopGoods;
|
||||||
|
import emu.nebula.proto.PublicStarTower.HawkerCaseData;
|
||||||
import emu.nebula.proto.PublicStarTower.HawkerGoods;
|
import emu.nebula.proto.PublicStarTower.HawkerGoods;
|
||||||
import emu.nebula.proto.PublicStarTower.StarTowerRoomCase;
|
import emu.nebula.proto.PublicStarTower.StarTowerRoomCase;
|
||||||
import emu.nebula.proto.StarTowerInteract.StarTowerInteractReq;
|
import emu.nebula.proto.StarTowerInteract.StarTowerInteractReq;
|
||||||
@@ -19,23 +19,29 @@ public class StarTowerHawkerCase extends StarTowerBaseCase {
|
|||||||
public StarTowerHawkerCase() {
|
public StarTowerHawkerCase() {
|
||||||
this.goods = new HashMap<>();
|
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
|
@Override
|
||||||
public CaseType getType() {
|
public CaseType getType() {
|
||||||
return CaseType.Hawker;
|
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) {
|
public void addGoods(StarTowerShopGoods goods) {
|
||||||
this.getGoods().put(getGoods().size() + 1, goods);
|
this.getGoods().put(getGoods().size() + 1, goods);
|
||||||
}
|
}
|
||||||
@@ -45,16 +51,65 @@ public class StarTowerHawkerCase extends StarTowerBaseCase {
|
|||||||
// Set nil resp
|
// Set nil resp
|
||||||
rsp.getMutableNilResp();
|
rsp.getMutableNilResp();
|
||||||
|
|
||||||
// Get goods
|
// Get hawker req
|
||||||
var goods = this.getGoods().get(req.getHawkerReq().getSid());
|
var hawker = req.getHawkerReq();
|
||||||
if (goods == null) {
|
|
||||||
return rsp;
|
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
|
// Make sure we have enough currency
|
||||||
int coin = this.getGame().getRes().get(GameConstants.STAR_TOWER_COIN_ITEM_ID);
|
int coin = this.getGame().getResCount(GameConstants.STAR_TOWER_COIN_ITEM_ID);
|
||||||
if (coin < goods.getPrice() || goods.isSold()) {
|
int price = this.getModifiers().getShopRerollPrice();
|
||||||
return rsp;
|
|
||||||
|
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
|
// Mark goods as sold
|
||||||
@@ -63,21 +118,23 @@ public class StarTowerHawkerCase extends StarTowerBaseCase {
|
|||||||
// Add case
|
// Add case
|
||||||
this.getGame().addCase(rsp.getMutableCases(), this.getGame().createPotentialSelector());
|
this.getGame().addCase(rsp.getMutableCases(), this.getGame().createPotentialSelector());
|
||||||
|
|
||||||
// Remove items
|
// Remove coins
|
||||||
var change = this.getGame().addItem(GameConstants.STAR_TOWER_COIN_ITEM_ID, -goods.getPrice());
|
var change = this.getGame().addItem(GameConstants.STAR_TOWER_COIN_ITEM_ID, -price);
|
||||||
|
|
||||||
// Set change info
|
// Set change info
|
||||||
rsp.setChange(change.toProto());
|
rsp.setChange(change.toProto());
|
||||||
|
|
||||||
// Success
|
|
||||||
return rsp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proto
|
// Proto
|
||||||
|
|
||||||
@Override
|
private HawkerCaseData toHawkerCaseProto() {
|
||||||
public void encodeProto(StarTowerRoomCase proto) {
|
var hawker = HawkerCaseData.newInstance();
|
||||||
var hawker = proto.getMutableHawkerCase();
|
|
||||||
|
if (this.getModifiers().getShopRerollCount() > 0) {
|
||||||
|
hawker.setCanReRoll(true);
|
||||||
|
hawker.setReRollTimes(this.getModifiers().getShopRerollCount());
|
||||||
|
hawker.setReRollPrice(this.getModifiers().getShopRerollPrice());
|
||||||
|
}
|
||||||
|
|
||||||
for (var entry : this.getGoods().entrySet()) {
|
for (var entry : this.getGoods().entrySet()) {
|
||||||
var sid = entry.getKey();
|
var sid = entry.getKey();
|
||||||
@@ -93,5 +150,12 @@ public class StarTowerHawkerCase extends StarTowerBaseCase {
|
|||||||
|
|
||||||
hawker.addList(info);
|
hawker.addList(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return hawker;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void encodeProto(StarTowerRoomCase proto) {
|
||||||
|
proto.setHawkerCase(this.toHawkerCaseProto());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package emu.nebula.game.tower.cases;
|
package emu.nebula.game.tower.cases;
|
||||||
|
|
||||||
import emu.nebula.GameConstants;
|
import emu.nebula.GameConstants;
|
||||||
import emu.nebula.game.tower.room.StarTowerBaseRoom;
|
|
||||||
import emu.nebula.proto.PublicStarTower.StarTowerRoomCase;
|
import emu.nebula.proto.PublicStarTower.StarTowerRoomCase;
|
||||||
import emu.nebula.proto.StarTowerInteract.StarTowerInteractReq;
|
import emu.nebula.proto.StarTowerInteract.StarTowerInteractReq;
|
||||||
import emu.nebula.proto.StarTowerInteract.StarTowerInteractResp;
|
import emu.nebula.proto.StarTowerInteract.StarTowerInteractResp;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@@ -14,10 +14,8 @@ public class StarTowerStrengthenMachineCase extends StarTowerBaseCase {
|
|||||||
private int times;
|
private int times;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register(StarTowerBaseRoom room) {
|
public void onRegister() {
|
||||||
super.register(room);
|
// Set strengthen price
|
||||||
|
|
||||||
// Also set strengthen price
|
|
||||||
this.free = this.getModifiers().isFreeStrengthen();
|
this.free = this.getModifiers().isFreeStrengthen();
|
||||||
this.discount = this.getModifiers().getStrengthenDiscount();
|
this.discount = this.getModifiers().getStrengthenDiscount();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class StarTowerHawkerRoom extends StarTowerBaseRoom {
|
|||||||
@Override
|
@Override
|
||||||
public void onEnter() {
|
public void onEnter() {
|
||||||
// Create hawker case (shop)
|
// Create hawker case (shop)
|
||||||
this.addCase(new StarTowerHawkerCase(this.getGame()));
|
this.addCase(new StarTowerHawkerCase());
|
||||||
|
|
||||||
// Create strengthen machine
|
// Create strengthen machine
|
||||||
if (this.getModifiers().isEnableShopStrengthen()) {
|
if (this.getModifiers().isEnableShopStrengthen()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user