mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-12 12:24:35 +01:00
Implement mass limit break
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package emu.nebula.game.character;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import emu.nebula.Nebula;
|
||||
@@ -10,6 +11,7 @@ import emu.nebula.game.player.PlayerManager;
|
||||
import emu.nebula.proto.Public.HandbookInfo;
|
||||
import emu.nebula.util.Bitset;
|
||||
import emu.nebula.game.player.Player;
|
||||
import emu.nebula.game.player.PlayerChangeInfo;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import lombok.Getter;
|
||||
@@ -164,6 +166,45 @@ public class CharacterStorage extends PlayerManager {
|
||||
return handbook;
|
||||
}
|
||||
|
||||
public PlayerChangeInfo limitBreakAllDiscs() {
|
||||
// Create variables
|
||||
var change = new PlayerChangeInfo();
|
||||
var modifiedDiscs = new ArrayList<GameDisc>();
|
||||
|
||||
// Try to limit all discs
|
||||
for (var disc : this.getDiscCollection()) {
|
||||
// Skip if at max stars
|
||||
if (disc.getStar() >= 5) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get transform id
|
||||
var transformId = disc.getData().getTransformItemId();
|
||||
var transformCount = this.getPlayer().getInventory().getItemCount(transformId);
|
||||
|
||||
if (transformCount <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try to limit break
|
||||
var discChange = disc.limitBreak(transformCount);
|
||||
|
||||
// Check if limit break was successful
|
||||
if (discChange == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Merge any changes from the disc limit break to this one
|
||||
change.add(discChange);
|
||||
|
||||
// Add to changed discs
|
||||
modifiedDiscs.add(disc);
|
||||
}
|
||||
|
||||
// Success
|
||||
return change.setExtraData(modifiedDiscs);
|
||||
}
|
||||
|
||||
// Database
|
||||
|
||||
public void loadFromDatabase() {
|
||||
|
||||
@@ -237,11 +237,14 @@ public class GameDisc implements GameDatabaseObject {
|
||||
// Remove items
|
||||
var change = this.getPlayer().getInventory().removeItems(materials, null);
|
||||
|
||||
// Add phase level
|
||||
this.star = Math.max(this.star + count, 4);
|
||||
// Add star
|
||||
int old = this.star;
|
||||
this.star = Math.max(this.star + count, 5);
|
||||
|
||||
// Save to database
|
||||
this.save();
|
||||
// Save to database if star count changed
|
||||
if (this.star != old) {
|
||||
this.save();
|
||||
}
|
||||
|
||||
// Success
|
||||
return change.setSuccess(true);
|
||||
|
||||
@@ -7,15 +7,12 @@ import emu.nebula.GameConstants;
|
||||
import emu.nebula.proto.AnyOuterClass.Any;
|
||||
import emu.nebula.proto.Public.ChangeInfo;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import us.hebi.quickbuf.ProtoMessage;
|
||||
|
||||
@Getter
|
||||
public class PlayerChangeInfo {
|
||||
private boolean success;
|
||||
private List<Any> list;
|
||||
|
||||
@Setter
|
||||
private Object extraData;
|
||||
|
||||
public PlayerChangeInfo() {
|
||||
@@ -30,6 +27,11 @@ public class PlayerChangeInfo {
|
||||
public boolean isEmpty() {
|
||||
return this.list == null || this.list.isEmpty();
|
||||
}
|
||||
|
||||
public PlayerChangeInfo setExtraData(Object extraData) {
|
||||
this.extraData = extraData;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void add(ProtoMessage<?> proto) {
|
||||
var any = Any.newInstance()
|
||||
@@ -39,6 +41,10 @@ public class PlayerChangeInfo {
|
||||
this.list.add(any);
|
||||
}
|
||||
|
||||
public void add(PlayerChangeInfo otherChange) {
|
||||
this.getList().addAll(otherChange.getList());
|
||||
}
|
||||
|
||||
// Proto
|
||||
|
||||
public ChangeInfo toProto() {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.DiscAllLimitBreak.DiscAllLimitBreakResp;
|
||||
import emu.nebula.proto.DiscAllLimitBreak.DiscLimitBreakChange;
|
||||
import emu.nebula.net.HandlerId;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import emu.nebula.game.character.GameDisc;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@HandlerId(NetMsgId.disc_all_limit_break_req)
|
||||
public class HandlerDiscAllLimitBreakReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Limit break all discs
|
||||
var change = session.getPlayer().getCharacters().limitBreakAllDiscs();
|
||||
|
||||
if (change == null) {
|
||||
return session.encodeMsg(NetMsgId.disc_all_limit_break_failed_ack);
|
||||
}
|
||||
|
||||
// Get changed discs
|
||||
@SuppressWarnings("unchecked")
|
||||
var discs = (List<GameDisc>) change.getExtraData();
|
||||
|
||||
// Build response
|
||||
var rsp = DiscAllLimitBreakResp.newInstance()
|
||||
.setChange(change.toProto());
|
||||
|
||||
for (var disc : discs) {
|
||||
var info = DiscLimitBreakChange.newInstance()
|
||||
.setId(disc.getDiscId())
|
||||
.setStar(disc.getStar());
|
||||
|
||||
rsp.addLimitBreaks(info);
|
||||
}
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.disc_all_limit_break_succeed_ack, rsp);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user