mirror of
https://github.com/Melledy/Nebula.git
synced 2026-09-19 17:19:58 +02:00
Implement mass limit break
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package emu.nebula.game.character;
|
package emu.nebula.game.character;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import emu.nebula.Nebula;
|
import emu.nebula.Nebula;
|
||||||
@@ -10,6 +11,7 @@ import emu.nebula.game.player.PlayerManager;
|
|||||||
import emu.nebula.proto.Public.HandbookInfo;
|
import emu.nebula.proto.Public.HandbookInfo;
|
||||||
import emu.nebula.util.Bitset;
|
import emu.nebula.util.Bitset;
|
||||||
import emu.nebula.game.player.Player;
|
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.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -164,6 +166,45 @@ public class CharacterStorage extends PlayerManager {
|
|||||||
return handbook;
|
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
|
// Database
|
||||||
|
|
||||||
public void loadFromDatabase() {
|
public void loadFromDatabase() {
|
||||||
|
|||||||
@@ -237,11 +237,14 @@ public class GameDisc implements GameDatabaseObject {
|
|||||||
// Remove items
|
// Remove items
|
||||||
var change = this.getPlayer().getInventory().removeItems(materials, null);
|
var change = this.getPlayer().getInventory().removeItems(materials, null);
|
||||||
|
|
||||||
// Add phase level
|
// Add star
|
||||||
this.star = Math.max(this.star + count, 4);
|
int old = this.star;
|
||||||
|
this.star = Math.max(this.star + count, 5);
|
||||||
|
|
||||||
// Save to database
|
// Save to database if star count changed
|
||||||
|
if (this.star != old) {
|
||||||
this.save();
|
this.save();
|
||||||
|
}
|
||||||
|
|
||||||
// Success
|
// Success
|
||||||
return change.setSuccess(true);
|
return change.setSuccess(true);
|
||||||
|
|||||||
@@ -7,15 +7,12 @@ import emu.nebula.GameConstants;
|
|||||||
import emu.nebula.proto.AnyOuterClass.Any;
|
import emu.nebula.proto.AnyOuterClass.Any;
|
||||||
import emu.nebula.proto.Public.ChangeInfo;
|
import emu.nebula.proto.Public.ChangeInfo;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
|
||||||
import us.hebi.quickbuf.ProtoMessage;
|
import us.hebi.quickbuf.ProtoMessage;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class PlayerChangeInfo {
|
public class PlayerChangeInfo {
|
||||||
private boolean success;
|
private boolean success;
|
||||||
private List<Any> list;
|
private List<Any> list;
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Object extraData;
|
private Object extraData;
|
||||||
|
|
||||||
public PlayerChangeInfo() {
|
public PlayerChangeInfo() {
|
||||||
@@ -31,6 +28,11 @@ public class PlayerChangeInfo {
|
|||||||
return this.list == null || this.list.isEmpty();
|
return this.list == null || this.list.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlayerChangeInfo setExtraData(Object extraData) {
|
||||||
|
this.extraData = extraData;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public void add(ProtoMessage<?> proto) {
|
public void add(ProtoMessage<?> proto) {
|
||||||
var any = Any.newInstance()
|
var any = Any.newInstance()
|
||||||
.setTypeUrl(GameConstants.PROTO_BASE_TYPE_URL + proto.getClass().getSimpleName())
|
.setTypeUrl(GameConstants.PROTO_BASE_TYPE_URL + proto.getClass().getSimpleName())
|
||||||
@@ -39,6 +41,10 @@ public class PlayerChangeInfo {
|
|||||||
this.list.add(any);
|
this.list.add(any);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void add(PlayerChangeInfo otherChange) {
|
||||||
|
this.getList().addAll(otherChange.getList());
|
||||||
|
}
|
||||||
|
|
||||||
// Proto
|
// Proto
|
||||||
|
|
||||||
public ChangeInfo toProto() {
|
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