mirror of
https://github.com/Melledy/Nebula.git
synced 2026-09-20 01:29:54 +02:00
Implement emblem tempering
This commit is contained in:
@@ -3,6 +3,7 @@ package emu.nebula.game.character;
|
||||
import dev.morphia.annotations.Entity;
|
||||
import emu.nebula.proto.Public.CharGem;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@@ -10,7 +11,9 @@ import lombok.Getter;
|
||||
public class CharacterGem {
|
||||
private boolean locked;
|
||||
private int[] attributes;
|
||||
private int[] overlock;
|
||||
private int[] alterAttributes;
|
||||
private int[] alterOverlock;
|
||||
|
||||
@Deprecated // Morphia only
|
||||
public CharacterGem() {
|
||||
@@ -19,7 +22,9 @@ public class CharacterGem {
|
||||
|
||||
public CharacterGem(IntList attributes) {
|
||||
this.attributes = attributes.toIntArray();
|
||||
this.overlock = new int[this.attributes.length];
|
||||
this.alterAttributes = new int[4];
|
||||
this.alterOverlock = new int[this.alterAttributes.length];
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
@@ -30,8 +35,18 @@ public class CharacterGem {
|
||||
this.attributes = attributes.toIntArray();
|
||||
}
|
||||
|
||||
public void setNewAttributes(IntList attributes) {
|
||||
public void setNewAttributes(IntList attributes, IntSet locked) {
|
||||
this.alterAttributes = attributes.toIntArray();
|
||||
this.alterOverlock = new int[this.getOverlock().length];
|
||||
|
||||
// Copy over locked attributes
|
||||
if (locked.size() > 0) {
|
||||
for (int i = 0; i < this.getOverlock().length; i++) {
|
||||
if (locked.contains(this.alterAttributes[i])) {
|
||||
this.getAlterOverlock()[i] = this.getOverlock()[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasAlterAttributes() {
|
||||
@@ -52,12 +67,40 @@ public class CharacterGem {
|
||||
|
||||
// Replace attributes
|
||||
this.attributes = this.alterAttributes;
|
||||
this.overlock = this.alterOverlock;
|
||||
this.alterAttributes = new int[4];
|
||||
this.alterOverlock = new int[this.alterAttributes.length];
|
||||
|
||||
// Success
|
||||
return true;
|
||||
}
|
||||
|
||||
public int[] getOverlock() {
|
||||
if (this.overlock == null) {
|
||||
this.overlock = new int[this.attributes.length];
|
||||
}
|
||||
|
||||
return this.overlock;
|
||||
}
|
||||
|
||||
public int[] getAlterOverlock() {
|
||||
if (this.alterOverlock == null) {
|
||||
this.alterOverlock = new int[this.attributes.length];
|
||||
}
|
||||
|
||||
return this.alterOverlock;
|
||||
}
|
||||
|
||||
public int getOverlockCount() {
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0; i < this.getOverlock().length; i++) {
|
||||
count += this.getOverlock()[i];
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
// Proto
|
||||
|
||||
public CharGem toProto() {
|
||||
@@ -65,8 +108,8 @@ public class CharacterGem {
|
||||
.setLock(this.isLocked())
|
||||
.addAllAttributes(this.getAttributes())
|
||||
.addAllAlterAttributes(this.getAlterAttributes())
|
||||
.addAllOverlockCount(new int[this.getAttributes().length])
|
||||
.addAllAlterOverlockCount(new int[this.getAlterAttributes().length]);
|
||||
.addAllOverlockCount(this.getOverlock())
|
||||
.addAllAlterOverlockCount(this.getAlterOverlock());
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
@@ -769,10 +769,10 @@ public class GameCharacter implements GameDatabaseObject {
|
||||
|
||||
// Create base list of attributes
|
||||
var list = new CustomIntArray();
|
||||
var locked = new IntOpenHashSet();
|
||||
|
||||
// Add locked attributes to list
|
||||
if (lockedAttributes.length() != 0) {
|
||||
var locked = new IntOpenHashSet();
|
||||
lockedAttributes.forEach(locked::add);
|
||||
|
||||
for (int i = 0; i < gem.getAttributes().length; i++) {
|
||||
@@ -786,7 +786,7 @@ public class GameCharacter implements GameDatabaseObject {
|
||||
|
||||
// Generate attributes and create gem
|
||||
var attributes = gemControl.generateAttributes(this, list);
|
||||
gem.setNewAttributes(attributes);
|
||||
gem.setNewAttributes(attributes, locked);
|
||||
|
||||
// Save to database
|
||||
this.save();
|
||||
@@ -818,6 +818,92 @@ public class GameCharacter implements GameDatabaseObject {
|
||||
return success;
|
||||
}
|
||||
|
||||
public PlayerChangeInfo overlockGem(int slotId, int gemIndex, int attrIndex) {
|
||||
// Get gem from slot
|
||||
var gem = this.getGemFromSlot(slotId, gemIndex);
|
||||
if (gem == null) return null;
|
||||
|
||||
// Sanity check attr index
|
||||
if (attrIndex < 0 || attrIndex >= gem.getAttributes().length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get total overlock count
|
||||
int count = gem.getOverlockCount();
|
||||
|
||||
if (count >= GameConstants.CHARACTER_MAX_OVERLOCK_COUNT) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get gem data
|
||||
var gemData = this.getData().getCharGemData(slotId);
|
||||
var gemControl = GameData.getCharGemSlotControlDataTable().get(slotId);
|
||||
|
||||
if (gemControl == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Calculate the materials we need
|
||||
var materials = new ItemParamMap();
|
||||
materials.add(gemData.getOverlockCostTid(), gemControl.getOverlockCostQty());
|
||||
materials.add(GameConstants.GOLD_ITEM_ID, gemControl.getOverlockDoraCostQty());
|
||||
|
||||
// Make sure the player has the materials to craft the emblem
|
||||
if (!getPlayer().getInventory().hasItems(materials)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get attribute
|
||||
int attrId = gem.getAttributes()[attrIndex];
|
||||
var attr = GameData.getCharGemAttrValueDataTable().get(attrId);
|
||||
|
||||
if (attr == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if we can upgrade
|
||||
if (gem.getOverlock()[attrIndex] >= attr.getOverlockCount()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Upgrade overlock
|
||||
gem.getOverlock()[attrIndex]++;
|
||||
|
||||
// Consume materials
|
||||
var change = getPlayer().getInventory().removeItems(materials);
|
||||
|
||||
// Save
|
||||
this.save();
|
||||
|
||||
// Success
|
||||
return change;
|
||||
}
|
||||
|
||||
public PlayerChangeInfo revertOverlockGem(int slotId, int gemIndex, int attrIndex) {
|
||||
// Get gem from slot
|
||||
var gem = this.getGemFromSlot(slotId, gemIndex);
|
||||
if (gem == null) return null;
|
||||
|
||||
// Sanity check attr index
|
||||
if (attrIndex < 0 || attrIndex >= gem.getAttributes().length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if we can revert
|
||||
if (gem.getOverlock()[attrIndex] <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Revert overlock
|
||||
gem.getOverlock()[attrIndex]--;
|
||||
|
||||
// Save
|
||||
this.save();
|
||||
|
||||
// Success
|
||||
return new PlayerChangeInfo();
|
||||
}
|
||||
|
||||
// Proto
|
||||
|
||||
public Char toProto() {
|
||||
@@ -892,7 +978,7 @@ public class GameCharacter implements GameDatabaseObject {
|
||||
|
||||
if (gem != null) {
|
||||
info.addAllAttributes(gem.getAttributes());
|
||||
info.addAllOverlockCount(new int[gem.getAttributes().length]);
|
||||
info.addAllOverlockCount(gem.getOverlock());
|
||||
} else {
|
||||
info.addAllAttributes(new int[4]);
|
||||
info.addAllOverlockCount(new int[4]);
|
||||
|
||||
Reference in New Issue
Block a user