mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-12 20:34:36 +01:00
Implement monolith shop discounts and improvements
This commit is contained in:
@@ -458,14 +458,18 @@ public class StarTowerGame {
|
||||
* Creates a potential selector for a random character
|
||||
*/
|
||||
public StarTowerBaseCase createPotentialSelector() {
|
||||
int charId = this.getRandomCharId();
|
||||
return this.createPotentialSelector(charId);
|
||||
return this.createPotentialSelector(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a potential selector for the specified character
|
||||
*/
|
||||
public StarTowerBaseCase createPotentialSelector(int charId) {
|
||||
// Check character id
|
||||
if (charId <= 0) {
|
||||
charId = this.getRandomCharId();
|
||||
}
|
||||
|
||||
// Get character potentials
|
||||
var data = GameData.getCharPotentialDataTable().get(charId);
|
||||
if (data == null) {
|
||||
@@ -498,14 +502,10 @@ public class StarTowerGame {
|
||||
}
|
||||
|
||||
// Get random potential id
|
||||
int index = ThreadLocalRandom.current().nextInt(0, potentials.size());
|
||||
int potentialId = potentials.getInt(index);
|
||||
int potentialId = Utils.randomElement(potentials, true);
|
||||
|
||||
// Add to selector
|
||||
selector.add(potentialId);
|
||||
|
||||
// Remove potential id from the selector
|
||||
potentials.removeInt(index);
|
||||
}
|
||||
|
||||
// Sanity check
|
||||
|
||||
@@ -10,18 +10,29 @@ public class StarTowerShopGoods {
|
||||
private int goodsId;
|
||||
private int price;
|
||||
private int discount;
|
||||
private int count;
|
||||
private int charPos;
|
||||
private boolean sold;
|
||||
|
||||
public StarTowerShopGoods(int type, int goodsId, int price) {
|
||||
this.type = type;
|
||||
this.goodsId = goodsId;
|
||||
this.price = price;
|
||||
this.count = 1;
|
||||
}
|
||||
|
||||
public void markAsSold() {
|
||||
this.sold = true;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public void setCharPos(int charPos) {
|
||||
this.charPos = charPos;
|
||||
}
|
||||
|
||||
public boolean hasDiscount() {
|
||||
return this.getDiscount() > 0;
|
||||
}
|
||||
@@ -37,4 +48,13 @@ public class StarTowerShopGoods {
|
||||
public int getDisplayPrice() {
|
||||
return this.price;
|
||||
}
|
||||
|
||||
public int getCharId(StarTowerGame game) {
|
||||
if (this.getCharPos() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int index = this.getCharPos() - 1;
|
||||
return game.getCharIds().getInt(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import emu.nebula.GameConstants;
|
||||
import emu.nebula.game.player.PlayerChangeInfo;
|
||||
import emu.nebula.game.tower.StarTowerShopGoods;
|
||||
import emu.nebula.proto.PublicStarTower.HawkerCaseData;
|
||||
import emu.nebula.proto.PublicStarTower.HawkerGoods;
|
||||
@@ -37,9 +38,38 @@ public class StarTowerHawkerCase extends StarTowerBaseCase {
|
||||
// Clear goods
|
||||
this.getGoods().clear();
|
||||
|
||||
// Caclulate amount of potentials/sub notes to sell
|
||||
int total = getModifiers().getShopGoodsCount();
|
||||
|
||||
int minPotentials = Math.max(total / 2, 2);
|
||||
int maxPotentials = Math.max(total - 1, minPotentials);
|
||||
int potentials = Utils.randomRange(minPotentials, maxPotentials);
|
||||
int subNotes = total - potentials;
|
||||
|
||||
// Add goods
|
||||
for (int i = 0; i < getModifiers().getShopGoodsCount(); i++) {
|
||||
this.addGoods(new StarTowerShopGoods(1, 1, 200));
|
||||
for (int i = 0; i < potentials; i++) {
|
||||
// Create potential selector shop item
|
||||
var goods = new StarTowerShopGoods(1, 102, 200);
|
||||
|
||||
// Add character specific potentials
|
||||
if (Utils.generateRandomDouble() < .2) {
|
||||
goods.setCharPos(1);
|
||||
}
|
||||
|
||||
// Add to goods map
|
||||
this.addGoods(goods);
|
||||
}
|
||||
for (int i = 0; i < subNotes; i++) {
|
||||
// Randomize sub note
|
||||
int id = Utils.randomElement(this.getGame().getSubNoteDropList());
|
||||
int count = Utils.randomRange(3, 10);
|
||||
|
||||
// Create sub note shop item
|
||||
var goods = new StarTowerShopGoods(2, id, 15 * count);
|
||||
goods.setCount(count);
|
||||
|
||||
// Add to goods map
|
||||
this.addGoods(goods);
|
||||
}
|
||||
|
||||
// Apply discounts based on star tower talents
|
||||
@@ -121,6 +151,9 @@ public class StarTowerHawkerCase extends StarTowerBaseCase {
|
||||
// Create new goods
|
||||
this.initGoods();
|
||||
|
||||
// Consume reroll count
|
||||
this.getGame().getModifiers().consumeShopReroll();
|
||||
|
||||
// Set in proto
|
||||
rsp.getMutableSelectResp()
|
||||
.setHawkerCase(this.toHawkerCaseProto());
|
||||
@@ -130,9 +163,6 @@ public class StarTowerHawkerCase extends StarTowerBaseCase {
|
||||
|
||||
// Set change info
|
||||
rsp.setChange(change.toProto());
|
||||
|
||||
// Consume reroll count
|
||||
this.getGame().getModifiers().consumeShopReroll();
|
||||
}
|
||||
|
||||
private void buy(int sid, StarTowerInteractResp rsp) {
|
||||
@@ -153,11 +183,21 @@ public class StarTowerHawkerCase extends StarTowerBaseCase {
|
||||
// Mark goods as sold
|
||||
goods.markAsSold();
|
||||
|
||||
// Add case
|
||||
this.getGame().addCase(rsp.getMutableCases(), this.getGame().createPotentialSelector());
|
||||
// Create change info
|
||||
var change = new PlayerChangeInfo();
|
||||
|
||||
// Add goods
|
||||
if (goods.getType() == 1) {
|
||||
// Potential selector
|
||||
int charId = goods.getCharId(this.getGame());
|
||||
this.getGame().addCase(rsp.getMutableCases(), this.getGame().createPotentialSelector(charId));
|
||||
} else {
|
||||
// Sub notes
|
||||
this.getGame().addItem(goods.getGoodsId(), goods.getCount(), change);
|
||||
}
|
||||
|
||||
// Remove coins
|
||||
var change = this.getGame().addItem(GameConstants.STAR_TOWER_COIN_ITEM_ID, -price);
|
||||
this.getGame().addItem(GameConstants.STAR_TOWER_COIN_ITEM_ID, -price, change);
|
||||
|
||||
// Set change info
|
||||
rsp.setChange(change.toProto());
|
||||
@@ -179,10 +219,10 @@ public class StarTowerHawkerCase extends StarTowerBaseCase {
|
||||
var goods = entry.getValue();
|
||||
|
||||
var info = HawkerGoods.newInstance()
|
||||
.setIdx(goods.getGoodsId())
|
||||
.setIdx(1)
|
||||
.setSid(sid)
|
||||
.setType(goods.getType())
|
||||
.setGoodsId(102) // ?
|
||||
.setGoodsId(goods.getGoodsId())
|
||||
.setPrice(goods.getDisplayPrice())
|
||||
.setTag(1);
|
||||
|
||||
@@ -190,6 +230,10 @@ public class StarTowerHawkerCase extends StarTowerBaseCase {
|
||||
info.setDiscount(goods.getPrice());
|
||||
}
|
||||
|
||||
if (goods.getCharPos() > 0) {
|
||||
info.setCharPos(goods.getCharPos());
|
||||
}
|
||||
|
||||
hawker.addList(info);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user