mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-23 18:54:37 +01:00
Implement basic stamina system (Everyone disliked that)
This commit is contained in:
@@ -18,6 +18,7 @@ public class GameConstants {
|
||||
public static final int MATERIAL_HCOIN_ID = 1; // Material id for jades. DO NOT CHANGE
|
||||
public static final int MATERIAL_COIN_ID = 2; // Material id for credits. DO NOT CHANGE
|
||||
public static final int MAX_STAMINA = 240;
|
||||
public static final int MAX_STAMINA_RESERVE = 2400;
|
||||
public static final int MAX_AVATARS_IN_TEAM = 4;
|
||||
public static final int DEFAULT_TEAMS = 6;
|
||||
public static final int MAX_MP = 5; // Client doesnt like more than 5
|
||||
|
||||
@@ -33,6 +33,7 @@ public class Battle {
|
||||
private final List<GameItem> drops;
|
||||
private final long timestamp;
|
||||
|
||||
@Setter private int staminaCost;
|
||||
@Setter private int levelOverride;
|
||||
@Setter private int roundsLimit;
|
||||
|
||||
|
||||
@@ -160,7 +160,11 @@ public class BattleService extends BaseGameService {
|
||||
// Get waves
|
||||
wave = Math.min(Math.max(1, wave), cocoonExcel.getMaxWave());
|
||||
|
||||
// TODO sanity check stamina
|
||||
// Sanity check stamina
|
||||
int cost = cocoonExcel.getStaminaCost() * wave;
|
||||
if (player.getStamina() < cost) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get stages from cocoon
|
||||
List<StageExcel> stages = new ArrayList<>();
|
||||
@@ -181,6 +185,8 @@ public class BattleService extends BaseGameService {
|
||||
|
||||
// Build battle from cocoon data
|
||||
Battle battle = new Battle(player, player.getLineupManager().getCurrentLineup(), stages);
|
||||
battle.setStaminaCost(cost);
|
||||
|
||||
player.setBattle(battle);
|
||||
|
||||
// Send packet
|
||||
@@ -212,6 +218,10 @@ public class BattleService extends BaseGameService {
|
||||
}
|
||||
// Drops
|
||||
getServer().getDropService().calculateDrops(battle);
|
||||
// Spend stamina
|
||||
if (battle.getStaminaCost() > 0) {
|
||||
player.spendStamina(battle.getStaminaCost());
|
||||
}
|
||||
}
|
||||
case BATTLE_END_LOSE -> {
|
||||
// Set avatar hp to 20% if the player's party is downed
|
||||
|
||||
@@ -44,10 +44,7 @@ import emu.lunarcore.server.game.GameServer;
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.SessionState;
|
||||
import emu.lunarcore.server.packet.send.PacketEnterSceneByServerScNotify;
|
||||
import emu.lunarcore.server.packet.send.PacketPlayerSyncScNotify;
|
||||
import emu.lunarcore.server.packet.send.PacketSceneEntityMoveScNotify;
|
||||
import emu.lunarcore.server.packet.send.PacketSyncRogueVirtualItemInfoScNotify;
|
||||
import emu.lunarcore.server.packet.send.*;
|
||||
import emu.lunarcore.util.Position;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
@@ -69,11 +66,13 @@ public class Player {
|
||||
private int level;
|
||||
private int exp;
|
||||
private int worldLevel;
|
||||
private int stamina;
|
||||
private int scoin; // Credits
|
||||
private int hcoin; // Jade
|
||||
private int mcoin; // Crystals
|
||||
private int talentPoints;
|
||||
private int talentPoints; // Rogue talent points
|
||||
|
||||
private int stamina;
|
||||
private long nextStaminaRecover;
|
||||
|
||||
private transient Battle battle;
|
||||
private transient Scene scene;
|
||||
@@ -307,11 +306,6 @@ public class Player {
|
||||
this.sendPacket(new PacketSyncRogueVirtualItemInfoScNotify(this));
|
||||
}
|
||||
|
||||
public void addStamina(int amount) {
|
||||
this.stamina = Math.min(this.stamina + amount, GameConstants.MAX_STAMINA);
|
||||
this.sendPacket(new PacketPlayerSyncScNotify(this));
|
||||
}
|
||||
|
||||
public void addExp(int amount) {
|
||||
// Required exp
|
||||
int reqExp = GameData.getPlayerExpRequired(level + 1);
|
||||
@@ -363,6 +357,42 @@ public class Player {
|
||||
this.battle = battle;
|
||||
}
|
||||
|
||||
public void addStamina(int amount) {
|
||||
this.stamina = Math.min(this.stamina + amount, GameConstants.MAX_STAMINA);
|
||||
this.sendPacket(new PacketStaminaInfoScNotify(this));
|
||||
}
|
||||
|
||||
public void spendStamina(int amount) {
|
||||
this.stamina = Math.max(this.stamina - amount, 0);
|
||||
this.sendPacket(new PacketStaminaInfoScNotify(this));
|
||||
}
|
||||
|
||||
private void updateStamina() {
|
||||
// Get current timestamp
|
||||
long time = System.currentTimeMillis();
|
||||
boolean hasChanged = false;
|
||||
|
||||
// Check if we can add stamina
|
||||
while (time >= this.nextStaminaRecover) {
|
||||
// Add stamina
|
||||
if (this.stamina < GameConstants.MAX_STAMINA) {
|
||||
this.stamina += 1;
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
// Calculate next stamina recover time
|
||||
if (this.stamina >= GameConstants.MAX_STAMINA) {
|
||||
this.nextStaminaRecover = time;
|
||||
}
|
||||
this.nextStaminaRecover += 5 * 60 * 1000;
|
||||
}
|
||||
|
||||
// Send packet
|
||||
if (hasChanged && this.hasLoggedIn()) {
|
||||
this.getSession().send(new PacketStaminaInfoScNotify(this));
|
||||
}
|
||||
}
|
||||
|
||||
public EntityProp interactWithProp(int propEntityId) {
|
||||
// Sanity
|
||||
if (this.getScene() == null) return null;
|
||||
@@ -532,7 +562,7 @@ public class Player {
|
||||
}
|
||||
|
||||
public void onTick() {
|
||||
|
||||
this.updateStamina();
|
||||
}
|
||||
|
||||
// Database
|
||||
@@ -561,6 +591,9 @@ public class Player {
|
||||
// Post database load
|
||||
this.getAvatars().setupHeroPaths();
|
||||
|
||||
// Update stamina
|
||||
this.updateStamina();
|
||||
|
||||
// Check instances
|
||||
if (this.getChallengeInstance() != null && !this.getChallengeInstance().validate(this)) {
|
||||
// Delete instance if it failed to validate (example: missing an excel)
|
||||
|
||||
@@ -6,6 +6,7 @@ import emu.lunarcore.server.packet.Opcodes;
|
||||
import emu.lunarcore.server.packet.PacketHandler;
|
||||
import emu.lunarcore.server.packet.SessionState;
|
||||
import emu.lunarcore.server.packet.send.PacketPlayerLoginScRsp;
|
||||
import emu.lunarcore.server.packet.send.PacketStaminaInfoScNotify;
|
||||
|
||||
@Opcodes(CmdId.PlayerLoginCsReq)
|
||||
public class HandlerPlayerLoginCsReq extends PacketHandler {
|
||||
@@ -15,8 +16,9 @@ public class HandlerPlayerLoginCsReq extends PacketHandler {
|
||||
// Set session flag
|
||||
session.setState(SessionState.ACTIVE);
|
||||
|
||||
// Send
|
||||
// Send packets
|
||||
session.send(new PacketPlayerLoginScRsp(session));
|
||||
session.send(new PacketStaminaInfoScNotify(session.getPlayer()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class PacketGetBasicInfoScRsp extends BasePacket {
|
||||
|
||||
var data = GetBasicInfoScRsp.newInstance()
|
||||
.setCurDay(1)
|
||||
.setNextRecoverTime(0)
|
||||
.setNextRecoverTime(session.getPlayer().getNextStaminaRecover() / 1000)
|
||||
.setGameplayBirthday(session.getPlayer().getBirthday())
|
||||
.setPlayerSettingInfo(PlayerSettingInfo.newInstance());
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.proto.StaminaInfoScNotifyOuterClass.StaminaInfoScNotify;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketStaminaInfoScNotify extends BasePacket {
|
||||
|
||||
public PacketStaminaInfoScNotify(Player player) {
|
||||
super(CmdId.StaminaInfoScNotify);
|
||||
|
||||
var data = StaminaInfoScNotify.newInstance()
|
||||
.setNextRecoverTime(player.getNextStaminaRecover() / 1000)
|
||||
.setStamina(player.getStamina());
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user