mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-16 14:24:57 +01:00
Implement tutorial levels
This commit is contained in:
36
src/main/java/emu/nebula/game/tutorial/TutorialLevelLog.java
Normal file
36
src/main/java/emu/nebula/game/tutorial/TutorialLevelLog.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package emu.nebula.game.tutorial;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import emu.nebula.proto.Public.TutorialLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Entity(useDiscriminator = false)
|
||||
public class TutorialLevelLog {
|
||||
private int id;
|
||||
private boolean claimed;
|
||||
|
||||
@Deprecated // Morphia only
|
||||
public TutorialLevelLog() {
|
||||
|
||||
}
|
||||
|
||||
public TutorialLevelLog(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setClaimed(boolean value) {
|
||||
this.claimed = value;
|
||||
}
|
||||
|
||||
// Proto
|
||||
|
||||
public TutorialLevel toProto() {
|
||||
var proto = TutorialLevel.newInstance()
|
||||
.setLevelId(this.getId())
|
||||
.setPassed(true)
|
||||
.setRewardReceived(this.isClaimed());
|
||||
|
||||
return proto;
|
||||
}
|
||||
}
|
||||
63
src/main/java/emu/nebula/game/tutorial/TutorialModule.java
Normal file
63
src/main/java/emu/nebula/game/tutorial/TutorialModule.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package emu.nebula.game.tutorial;
|
||||
|
||||
import emu.nebula.Nebula;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.game.GameContext;
|
||||
import emu.nebula.game.GameContextModule;
|
||||
import emu.nebula.game.player.Player;
|
||||
import emu.nebula.game.player.PlayerChangeInfo;
|
||||
|
||||
public class TutorialModule extends GameContextModule {
|
||||
|
||||
public TutorialModule(GameContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public boolean settle(Player player, int id) {
|
||||
// Check if the tutorial was completed
|
||||
if (player.getProgress().getTutorialLog().containsKey(id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get data
|
||||
var data = GameData.getTutorialLevelDataTable().get(id);
|
||||
if (data == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create log
|
||||
var log = new TutorialLevelLog(id);
|
||||
|
||||
// Add to progress tutorial map
|
||||
player.getProgress().getTutorialLog().put(id, log);
|
||||
|
||||
// Save to database
|
||||
Nebula.getGameDatabase().update(player.getProgress(), player.getUid(), "tutorialLog." + log.getId(), log);
|
||||
|
||||
// Success
|
||||
return true;
|
||||
}
|
||||
|
||||
public PlayerChangeInfo recvReward(Player player, int id) {
|
||||
// Get tutorial log
|
||||
var log = player.getProgress().getTutorialLog().get(id);
|
||||
if (log == null || log.isClaimed()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get data
|
||||
var data = GameData.getTutorialLevelDataTable().get(id);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set claim state
|
||||
log.setClaimed(true);
|
||||
|
||||
// Save to database
|
||||
Nebula.getGameDatabase().update(player.getProgress(), player.getUid(), "tutorialLog." + log.getId(), log);
|
||||
|
||||
// Add reward item
|
||||
return player.getInventory().addItem(data.getItem1(), data.getQty1());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user