mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-13 12:54:36 +01:00
Implement attributing locking when reforging
This commit is contained in:
@@ -3,8 +3,8 @@ package emu.nebula.data.resources;
|
|||||||
import emu.nebula.data.BaseDef;
|
import emu.nebula.data.BaseDef;
|
||||||
import emu.nebula.data.GameData;
|
import emu.nebula.data.GameData;
|
||||||
import emu.nebula.data.ResourceType;
|
import emu.nebula.data.ResourceType;
|
||||||
|
import emu.nebula.util.CustomIntArray;
|
||||||
import emu.nebula.util.WeightedList;
|
import emu.nebula.util.WeightedList;
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntList;
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@@ -35,9 +35,10 @@ public class CharGemSlotControlDef extends BaseDef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IntList generateAttributes() {
|
public IntList generateAttributes() {
|
||||||
// Generate list of attributes
|
return this.generateAttributes(new CustomIntArray());
|
||||||
var list = new IntArrayList();
|
}
|
||||||
|
|
||||||
|
public IntList generateAttributes(CustomIntArray list) {
|
||||||
// Add unique attributes
|
// Add unique attributes
|
||||||
if (this.UniqueAttrGroupId > 0) {
|
if (this.UniqueAttrGroupId > 0) {
|
||||||
var group = GameData.getCharGemAttrGroupDataTable().get(this.UniqueAttrGroupId);
|
var group = GameData.getCharGemAttrGroupDataTable().get(this.UniqueAttrGroupId);
|
||||||
@@ -48,7 +49,7 @@ public class CharGemSlotControlDef extends BaseDef {
|
|||||||
list.add(attributeType.getRandomValue());
|
list.add(attributeType.getRandomValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list.size() >= 4) {
|
if (list.size() >= this.MaxAlterNum) {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,7 +67,7 @@ public class CharGemSlotControlDef extends BaseDef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add up to 4 attributes
|
// Add up to 4 attributes
|
||||||
while (list.size() < 4) {
|
while (list.getValueCount() < this.MaxAlterNum) {
|
||||||
var group = random.next();
|
var group = random.next();
|
||||||
var attributeType = group.getRandomAttributeType(list);
|
var attributeType = group.getRandomAttributeType(list);
|
||||||
list.add(attributeType.getRandomValue());
|
list.add(attributeType.getRandomValue());
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ import emu.nebula.proto.Public.UI32;
|
|||||||
import emu.nebula.proto.PublicStarTower.StarTowerChar;
|
import emu.nebula.proto.PublicStarTower.StarTowerChar;
|
||||||
import emu.nebula.proto.PublicStarTower.StarTowerCharGem;
|
import emu.nebula.proto.PublicStarTower.StarTowerCharGem;
|
||||||
import emu.nebula.util.Bitset;
|
import emu.nebula.util.Bitset;
|
||||||
|
import emu.nebula.util.CustomIntArray;
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import us.hebi.quickbuf.RepeatedInt;
|
import us.hebi.quickbuf.RepeatedInt;
|
||||||
|
|
||||||
@@ -558,6 +560,7 @@ public class Character implements GameDatabaseObject {
|
|||||||
return change;
|
return change;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public synchronized PlayerChangeInfo refreshGem(int slotId, int gemIndex, RepeatedInt lockedAttributes) {
|
public synchronized PlayerChangeInfo refreshGem(int slotId, int gemIndex, RepeatedInt lockedAttributes) {
|
||||||
// Get gem from slot
|
// Get gem from slot
|
||||||
var gem = this.getGemFromSlot(slotId, gemIndex);
|
var gem = this.getGemFromSlot(slotId, gemIndex);
|
||||||
@@ -572,20 +575,47 @@ public class Character implements GameDatabaseObject {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the player has the materials to craft the emblem
|
// Get locked attributes
|
||||||
if (!getPlayer().getInventory().hasItem(gemData.getRefreshCostTid(), gemControl.getRefreshCostQty())) {
|
if (lockedAttributes.length() > gemControl.getLockableNum()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate the materials we need
|
||||||
|
var materials = new ItemParamMap();
|
||||||
|
materials.add(gemData.getRefreshCostTid(), gemControl.getRefreshCostQty());
|
||||||
|
materials.add(gemControl.getLockItemTid(), gemControl.getLockItemQty() * lockedAttributes.length());
|
||||||
|
|
||||||
|
// Make sure the player has the materials to craft the emblem
|
||||||
|
if (!getPlayer().getInventory().hasItems(materials)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create base list of attributes
|
||||||
|
var list = new CustomIntArray();
|
||||||
|
|
||||||
|
// 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++) {
|
||||||
|
int attr = gem.getAttributes()[i];
|
||||||
|
|
||||||
|
if (locked.contains(attr)) {
|
||||||
|
list.add(i, attr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Generate attributes and create gem
|
// Generate attributes and create gem
|
||||||
var attributes = gemControl.generateAttributes();
|
var attributes = gemControl.generateAttributes(list);
|
||||||
gem.setNewAttributes(attributes);
|
gem.setNewAttributes(attributes);
|
||||||
|
|
||||||
// Save to database
|
// Save to database
|
||||||
this.save();
|
this.save();
|
||||||
|
|
||||||
// Consume materials
|
// Consume materials
|
||||||
var change = getPlayer().getInventory().removeItem(gemData.getRefreshCostTid(), gemControl.getRefreshCostQty());
|
var change = getPlayer().getInventory().removeItems(materials);
|
||||||
|
|
||||||
// Set change info extra info
|
// Set change info extra info
|
||||||
change.setExtraData(gem);
|
change.setExtraData(gem);
|
||||||
|
|||||||
46
src/main/java/emu/nebula/util/CustomIntArray.java
Normal file
46
src/main/java/emu/nebula/util/CustomIntArray.java
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package emu.nebula.util;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
|
|
||||||
|
public class CustomIntArray extends IntArrayList {
|
||||||
|
private static final long serialVersionUID = -3887905394107667439L;
|
||||||
|
|
||||||
|
public CustomIntArray() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int index, int value) {
|
||||||
|
while (index > this.size()) {
|
||||||
|
super.add(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.add(index, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean add(int value) {
|
||||||
|
for (int i = 0; i < this.size(); i++) {
|
||||||
|
if (this.getInt(i) == 0) {
|
||||||
|
this.set(i, value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.add(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the amount of non-zero values in this array
|
||||||
|
*/
|
||||||
|
public int getValueCount() {
|
||||||
|
int realSize = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < super.size(); i++) {
|
||||||
|
if (this.getInt(i) != 0) {
|
||||||
|
realSize++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return realSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user