mirror of
https://github.com/Melledy/Nebula.git
synced 2026-11-04 21:36:51 +01:00
Implement presets
This commit is contained in:
1 parent
87c5dff006
commit
a8c64e5a78
12 files changed
+459
-9
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.PotentialPreselectionDelete.PotentialPreselectionDeleteReq;
|
||||
import emu.nebula.net.HandlerId;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import emu.nebula.game.tower.StarTowerPotentialPreset;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@HandlerId(NetMsgId.potential_preselection_delete_req)
|
||||
public class HandlerPotentialPreselectionDeleteReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Parse request
|
||||
var req = PotentialPreselectionDeleteReq.parseFrom(message);
|
||||
|
||||
// Get list of presets
|
||||
var presets = new HashSet<StarTowerPotentialPreset>();
|
||||
|
||||
// Get preset
|
||||
for (long id : req.getIds()) {
|
||||
var preset = session.getPlayer().getStarTowerManager().getPresetById(id);
|
||||
|
||||
if (preset == null) {
|
||||
return session.encodeMsg(NetMsgId.potential_preselection_delete_failed_ack);
|
||||
}
|
||||
|
||||
presets.add(preset);
|
||||
}
|
||||
|
||||
// Delete presets
|
||||
for (var preset : presets) {
|
||||
session.getPlayer().getStarTowerManager().deletePreset(preset);
|
||||
}
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.potential_preselection_delete_succeed_ack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.PotentialPreselectionImport.PotentialPreselectionImportReq;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@HandlerId(NetMsgId.potential_preselection_import_req)
|
||||
public class HandlerPotentialPreselectionImportReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Parse request
|
||||
var req = PotentialPreselectionImportReq.parseFrom(message);
|
||||
|
||||
// Import preset
|
||||
var preset = session.getPlayer().getStarTowerManager().importPreset(
|
||||
req.getName(),
|
||||
req.getPreference(),
|
||||
req.getCharPotentials()
|
||||
);
|
||||
|
||||
// Check if there was an error with importing the preset
|
||||
if (preset == null) {
|
||||
return session.encodeMsg(NetMsgId.potential_preselection_import_failed_ack);
|
||||
}
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.potential_preselection_import_succeed_ack, preset.toProto());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,12 @@ public class HandlerPotentialPreselectionListReq extends NetHandler {
|
||||
// Create base response
|
||||
var rsp = PotentialPreselectionList.newInstance();
|
||||
|
||||
// Add potential presets
|
||||
var presets = session.getPlayer().getStarTowerManager().getPresets().values();
|
||||
for (var preset : presets) {
|
||||
rsp.addList(preset.toProto());
|
||||
}
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.potential_preselection_list_succeed_ack, rsp);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.PotentialPreselectionNameSet.PotentialPreselectionNameSetReq;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@HandlerId(NetMsgId.potential_preselection_name_set_req)
|
||||
public class HandlerPotentialPreselectionNameSetReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Parse request
|
||||
var req = PotentialPreselectionNameSetReq.parseFrom(message);
|
||||
|
||||
// Get preset
|
||||
var preset = session.getPlayer().getStarTowerManager().getPresetById(req.getId());
|
||||
|
||||
if (preset == null) {
|
||||
return session.encodeMsg(NetMsgId.potential_preselection_name_set_failed_ack);
|
||||
}
|
||||
|
||||
// Update name
|
||||
preset.setName(req.getName());
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.potential_preselection_name_set_succeed_ack);
|
||||
}
|
||||
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.PotentialPreselectionPreferenceSet.PotentialPreselectionPreferenceSetReq;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import emu.nebula.game.tower.StarTowerPotentialPreset;
|
||||
|
||||
@HandlerId(NetMsgId.potential_preselection_preference_set_req)
|
||||
public class HandlerPotentialPreselectionPreferenceSetReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Parse request
|
||||
var req = PotentialPreselectionPreferenceSetReq.parseFrom(message);
|
||||
|
||||
// Get list of presets
|
||||
var checkInPresets = new HashSet<StarTowerPotentialPreset>();
|
||||
var checkOutPresets = new HashSet<StarTowerPotentialPreset>();
|
||||
|
||||
// Get check-in presets
|
||||
for (long id : req.getCheckInIds()) {
|
||||
var preset = session.getPlayer().getStarTowerManager().getPresetById(id);
|
||||
|
||||
if (preset == null) {
|
||||
return session.encodeMsg(NetMsgId.potential_preselection_preference_set_failed_ack);
|
||||
}
|
||||
|
||||
checkInPresets.add(preset);
|
||||
}
|
||||
|
||||
// Get check-out presets
|
||||
for (long id : req.getCheckOutIds()) {
|
||||
var preset = session.getPlayer().getStarTowerManager().getPresetById(id);
|
||||
|
||||
if (preset == null) {
|
||||
return session.encodeMsg(NetMsgId.potential_preselection_preference_set_failed_ack);
|
||||
}
|
||||
|
||||
checkOutPresets.add(preset);
|
||||
}
|
||||
|
||||
// Set preference to true for check-in presets
|
||||
for (var preset : checkInPresets) {
|
||||
preset.setPreference(true);
|
||||
}
|
||||
|
||||
// Set preference to false for check-out presets
|
||||
for (var preset : checkOutPresets) {
|
||||
preset.setPreference(false);
|
||||
}
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.potential_preselection_preference_set_succeed_ack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.PotentialPreselectionUpdate.PotentialPreselectionUpdateReq;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@HandlerId(NetMsgId.potential_preselection_update_req)
|
||||
public class HandlerPotentialPreselectionUpdateReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Parse request
|
||||
var req = PotentialPreselectionUpdateReq.parseFrom(message);
|
||||
|
||||
// Get preset
|
||||
var preset = session.getPlayer().getStarTowerManager().getPresetById(req.getId());
|
||||
|
||||
if (preset == null) {
|
||||
return session.encodeMsg(NetMsgId.potential_preselection_update_failed_ack);
|
||||
}
|
||||
|
||||
// Update potentials
|
||||
preset.updatePotentials(req.getCharPotentials());
|
||||
preset.save();
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.potential_preselection_update_succeed_ack, preset.toProto());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user