mirror of
https://github.com/Melledy/Nebula.git
synced 2026-09-19 17:19:58 +02:00
Implement monolith shop
This commit is contained in:
@@ -14,6 +14,7 @@ public class GameConstants {
|
|||||||
|
|
||||||
public static final int GOLD_ITEM_ID = 1;
|
public static final int GOLD_ITEM_ID = 1;
|
||||||
public static final int ENERGY_BUY_ITEM_ID = 2;
|
public static final int ENERGY_BUY_ITEM_ID = 2;
|
||||||
|
public static final int STAR_TOWER_GOLD_ITEM_ID = 11;
|
||||||
public static final int EXP_ITEM_ID = 21;
|
public static final int EXP_ITEM_ID = 21;
|
||||||
|
|
||||||
public static final int MAX_ENERGY = 240;
|
public static final int MAX_ENERGY = 240;
|
||||||
|
|||||||
@@ -104,12 +104,12 @@ public class StarTowerCase {
|
|||||||
var hawker = proto.getMutableHawkerCase();
|
var hawker = proto.getMutableHawkerCase();
|
||||||
|
|
||||||
for (var entry : getGoodsList().entrySet()) {
|
for (var entry : getGoodsList().entrySet()) {
|
||||||
var id = entry.getKey();
|
var sid = entry.getKey();
|
||||||
var goods = entry.getValue();
|
var goods = entry.getValue();
|
||||||
|
|
||||||
var info = HawkerGoods.newInstance()
|
var info = HawkerGoods.newInstance()
|
||||||
.setIdx(goods.getGoodsId())
|
.setIdx(goods.getGoodsId())
|
||||||
.setSid(id)
|
.setSid(sid)
|
||||||
.setType(goods.getType())
|
.setType(goods.getType())
|
||||||
.setGoodsId(102) // ?
|
.setGoodsId(102) // ?
|
||||||
.setPrice(goods.getPrice())
|
.setPrice(goods.getPrice())
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import dev.morphia.annotations.Entity;
|
import dev.morphia.annotations.Entity;
|
||||||
|
|
||||||
|
import emu.nebula.GameConstants;
|
||||||
import emu.nebula.data.GameData;
|
import emu.nebula.data.GameData;
|
||||||
import emu.nebula.data.resources.PotentialDef;
|
import emu.nebula.data.resources.PotentialDef;
|
||||||
import emu.nebula.data.resources.StarTowerDef;
|
import emu.nebula.data.resources.StarTowerDef;
|
||||||
@@ -19,11 +21,12 @@ import emu.nebula.proto.StarTowerInteract.StarTowerInteractResp;
|
|||||||
import emu.nebula.util.Snowflake;
|
import emu.nebula.util.Snowflake;
|
||||||
import emu.nebula.util.Utils;
|
import emu.nebula.util.Utils;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
import us.hebi.quickbuf.RepeatedMessage;
|
import us.hebi.quickbuf.RepeatedMessage;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@@ -55,7 +58,7 @@ public class StarTowerGame {
|
|||||||
private int battleCount;
|
private int battleCount;
|
||||||
private List<StarTowerChar> chars;
|
private List<StarTowerChar> chars;
|
||||||
private List<StarTowerDisc> discs;
|
private List<StarTowerDisc> discs;
|
||||||
private IntSet charIds;
|
private IntList charIds;
|
||||||
|
|
||||||
// Case
|
// Case
|
||||||
private int lastCaseId = 0;
|
private int lastCaseId = 0;
|
||||||
@@ -102,7 +105,7 @@ public class StarTowerGame {
|
|||||||
this.charHp = -1;
|
this.charHp = -1;
|
||||||
this.chars = new ArrayList<>();
|
this.chars = new ArrayList<>();
|
||||||
this.discs = new ArrayList<>();
|
this.discs = new ArrayList<>();
|
||||||
this.charIds = new IntOpenHashSet();
|
this.charIds = new IntArrayList();
|
||||||
|
|
||||||
this.cases = new ArrayList<>();
|
this.cases = new ArrayList<>();
|
||||||
|
|
||||||
@@ -169,6 +172,10 @@ public class StarTowerGame {
|
|||||||
return this.build;
|
return this.build;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getRandomCharId() {
|
||||||
|
return Utils.randomElement(this.getCharIds());
|
||||||
|
}
|
||||||
|
|
||||||
public StarTowerStageDef getStageData(int stage, int floor) {
|
public StarTowerStageDef getStageData(int stage, int floor) {
|
||||||
var stageId = (this.getId() * 10000) + (stage * 100) + floor;
|
var stageId = (this.getId() * 10000) + (stage * 100) + floor;
|
||||||
return GameData.getStarTowerStageDataTable().get(stageId);
|
return GameData.getStarTowerStageDataTable().get(stageId);
|
||||||
@@ -299,6 +306,17 @@ public class StarTowerGame {
|
|||||||
// Add to new infos
|
// Add to new infos
|
||||||
this.getNewInfos().add(id, count);
|
this.getNewInfos().add(id, count);
|
||||||
}
|
}
|
||||||
|
case Res -> {
|
||||||
|
// Add to res
|
||||||
|
this.getRes().add(id, count);
|
||||||
|
|
||||||
|
// Add change
|
||||||
|
var info = TowerResInfo.newInstance()
|
||||||
|
.setTid(id)
|
||||||
|
.setQty(count);
|
||||||
|
|
||||||
|
change.add(info);
|
||||||
|
}
|
||||||
default -> {
|
default -> {
|
||||||
// Ignored
|
// Ignored
|
||||||
}
|
}
|
||||||
@@ -394,8 +412,13 @@ public class StarTowerGame {
|
|||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public StarTowerInteractResp onBattleEnd(StarTowerInteractReq req, StarTowerInteractResp rsp) {
|
public StarTowerInteractResp onBattleEnd(StarTowerInteractReq req, StarTowerInteractResp rsp) {
|
||||||
|
// Parse battle end
|
||||||
var proto = req.getBattleEndReq();
|
var proto = req.getBattleEndReq();
|
||||||
|
|
||||||
|
// Init change
|
||||||
|
var change = new PlayerChangeInfo();
|
||||||
|
|
||||||
|
// Handle victory/defeat
|
||||||
if (proto.hasVictory()) {
|
if (proto.hasVictory()) {
|
||||||
// Add team level
|
// Add team level
|
||||||
this.teamLevel++;
|
this.teamLevel++;
|
||||||
@@ -409,6 +432,16 @@ public class StarTowerGame {
|
|||||||
.setLv(this.getTeamLevel())
|
.setLv(this.getTeamLevel())
|
||||||
.setBattleTime(this.getBattleTime());
|
.setBattleTime(this.getBattleTime());
|
||||||
|
|
||||||
|
// Add money
|
||||||
|
// TODO calculate properly
|
||||||
|
int money = Utils.randomRange(5, 15) * 10;
|
||||||
|
|
||||||
|
if (this.getRoomType() == StarTowerRoomType.BossRoom.getValue()) {
|
||||||
|
money += 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.addItem(GameConstants.STAR_TOWER_GOLD_ITEM_ID, money, change);
|
||||||
|
|
||||||
// Create potential selector
|
// Create potential selector
|
||||||
int charId = this.getChars().get(battleCount % this.getCharIds().size()).getId();
|
int charId = this.getChars().get(battleCount % this.getCharIds().size()).getId();
|
||||||
var potentialCase = this.createPotentialSelector(charId);
|
var potentialCase = this.createPotentialSelector(charId);
|
||||||
@@ -419,12 +452,8 @@ public class StarTowerGame {
|
|||||||
// Add sub note skills
|
// Add sub note skills
|
||||||
var battleCase = this.getBattleCase();
|
var battleCase = this.getBattleCase();
|
||||||
if (battleCase != null) {
|
if (battleCase != null) {
|
||||||
var change = new PlayerChangeInfo();
|
|
||||||
int subNoteSkills = battleCase.getSubNoteSkillNum();
|
int subNoteSkills = battleCase.getSubNoteSkillNum();
|
||||||
|
|
||||||
this.addRandomSubNoteSkills(subNoteSkills, change);
|
this.addRandomSubNoteSkills(subNoteSkills, change);
|
||||||
|
|
||||||
rsp.setChange(change.toProto());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Handle defeat
|
// Handle defeat
|
||||||
@@ -434,6 +463,9 @@ public class StarTowerGame {
|
|||||||
// Increment battle count
|
// Increment battle count
|
||||||
this.battleCount++;
|
this.battleCount++;
|
||||||
|
|
||||||
|
// Set change
|
||||||
|
rsp.setChange(change.toProto());
|
||||||
|
|
||||||
return rsp;
|
return rsp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,6 +559,7 @@ public class StarTowerGame {
|
|||||||
} else if (this.roomType == StarTowerRoomType.ShopRoom.getValue()) {
|
} else if (this.roomType == StarTowerRoomType.ShopRoom.getValue()) {
|
||||||
var hawkerCase = new StarTowerCase(CaseType.Hawker);
|
var hawkerCase = new StarTowerCase(CaseType.Hawker);
|
||||||
|
|
||||||
|
// TODO
|
||||||
hawkerCase.addGoods(new StarTowerShopGoods(1, 1, 200));
|
hawkerCase.addGoods(new StarTowerShopGoods(1, 1, 200));
|
||||||
hawkerCase.addGoods(new StarTowerShopGoods(1, 1, 200));
|
hawkerCase.addGoods(new StarTowerShopGoods(1, 1, 200));
|
||||||
hawkerCase.addGoods(new StarTowerShopGoods(1, 1, 200));
|
hawkerCase.addGoods(new StarTowerShopGoods(1, 1, 200));
|
||||||
@@ -550,6 +583,38 @@ public class StarTowerGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StarTowerInteractResp onHawkerReq(StarTowerInteractReq req, StarTowerInteractResp rsp) {
|
private StarTowerInteractResp onHawkerReq(StarTowerInteractReq req, StarTowerInteractResp rsp) {
|
||||||
|
// Set this proto
|
||||||
|
rsp.getMutableNilResp();
|
||||||
|
|
||||||
|
// Get hawker case
|
||||||
|
var shop = this.getHawkerCase();
|
||||||
|
if (shop == null || shop.getGoodsList() == null) {
|
||||||
|
return rsp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get goods
|
||||||
|
var goods = shop.getGoodsList().get(req.getHawkerReq().getSid());
|
||||||
|
|
||||||
|
// Make sure we have enough currency
|
||||||
|
if (this.getRes().get(GameConstants.STAR_TOWER_GOLD_ITEM_ID) < goods.getPrice() || goods.isSold()) {
|
||||||
|
return rsp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark goods as sold
|
||||||
|
goods.markAsSold();
|
||||||
|
|
||||||
|
// Add case
|
||||||
|
int charId = this.getRandomCharId();
|
||||||
|
var potentialCase = this.createPotentialSelector(charId);
|
||||||
|
this.addCase(rsp.getMutableCases(), potentialCase);
|
||||||
|
|
||||||
|
// Remove items
|
||||||
|
var change = this.addItem(GameConstants.STAR_TOWER_GOLD_ITEM_ID, -goods.getPrice(), null);
|
||||||
|
|
||||||
|
// Set change info
|
||||||
|
rsp.setChange(change.toProto());
|
||||||
|
|
||||||
|
// Success
|
||||||
return rsp;
|
return rsp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,5 +16,9 @@ public class StarTowerShopGoods {
|
|||||||
this.goodsId = goodsId;
|
this.goodsId = goodsId;
|
||||||
this.price = price;
|
this.price = price;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void markAsSold() {
|
||||||
|
this.sold = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user