Skip to content

Commit 254d3cc

Browse files
committed
Implement emblem tempering
1 parent d4e89e6 commit 254d3cc

9 files changed

Lines changed: 212 additions & 7 deletions

File tree

src/main/java/emu/nebula/GameConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class GameConstants {
3131
public static final int CHARACTER_MAX_GEMS_PER_SLOT = 4;
3232
public static final int CHARACTER_MAX_GEM_PRESETS = 3;
3333
public static final int CHARACTER_MAX_GEM_SLOTS = 3;
34+
public static final int CHARACTER_MAX_OVERLOCK_COUNT = 2;
3435

3536
public static final int CHARACTER_TAG_VANGUARD = 101;
3637
public static final int CHARACTER_TAG_VERSATILE = 102;

src/main/java/emu/nebula/data/resources/CharGemAttrValueDef.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class CharGemAttrValueDef extends BaseDef {
1313
private int TypeId;
1414
private int AttrType;
1515
private int AttrTypeFirstSubtype;
16+
private int OverlockCount;
1617
private int Rarity;
1718

1819
@Override

src/main/java/emu/nebula/data/resources/CharGemDef.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class CharGemDef extends BaseDef {
1010
private int Id;
1111
private int GenerateCostTid;
1212
private int RefreshCostTid;
13+
private int OverlockCostTid;
1314
private int Type;
1415

1516
@Override

src/main/java/emu/nebula/data/resources/CharGemSlotControlDef.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class CharGemSlotControlDef extends BaseDef {
2121

2222
private int GeneratenCostQty;
2323
private int RefreshCostQty;
24+
private int OverlockCostQty;
25+
private int OverlockDoraCostQty;
2426

2527
private int LockableNum;
2628
private int LockItemTid;

src/main/java/emu/nebula/game/character/CharacterGem.java

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
import dev.morphia.annotations.Entity;
44
import emu.nebula.proto.Public.CharGem;
55
import it.unimi.dsi.fastutil.ints.IntList;
6+
import it.unimi.dsi.fastutil.ints.IntSet;
67
import lombok.Getter;
78

89
@Getter
910
@Entity(useDiscriminator = false)
1011
public class CharacterGem {
1112
private boolean locked;
1213
private int[] attributes;
14+
private int[] overlock;
1315
private int[] alterAttributes;
16+
private int[] alterOverlock;
1417

1518
@Deprecated // Morphia only
1619
public CharacterGem() {
@@ -19,7 +22,9 @@ public CharacterGem() {
1922

2023
public CharacterGem(IntList attributes) {
2124
this.attributes = attributes.toIntArray();
25+
this.overlock = new int[this.attributes.length];
2226
this.alterAttributes = new int[4];
27+
this.alterOverlock = new int[this.alterAttributes.length];
2328
}
2429

2530
public void setLocked(boolean locked) {
@@ -30,8 +35,18 @@ public void setAttributes(IntList attributes) {
3035
this.attributes = attributes.toIntArray();
3136
}
3237

33-
public void setNewAttributes(IntList attributes) {
38+
public void setNewAttributes(IntList attributes, IntSet locked) {
3439
this.alterAttributes = attributes.toIntArray();
40+
this.alterOverlock = new int[this.getOverlock().length];
41+
42+
// Copy over locked attributes
43+
if (locked.size() > 0) {
44+
for (int i = 0; i < this.getOverlock().length; i++) {
45+
if (locked.contains(this.alterAttributes[i])) {
46+
this.getAlterOverlock()[i] = this.getOverlock()[i];
47+
}
48+
}
49+
}
3550
}
3651

3752
public boolean hasAlterAttributes() {
@@ -52,21 +67,49 @@ public boolean replaceAttributes() {
5267

5368
// Replace attributes
5469
this.attributes = this.alterAttributes;
70+
this.overlock = this.alterOverlock;
5571
this.alterAttributes = new int[4];
72+
this.alterOverlock = new int[this.alterAttributes.length];
5673

5774
// Success
5875
return true;
5976
}
6077

78+
public int[] getOverlock() {
79+
if (this.overlock == null) {
80+
this.overlock = new int[this.attributes.length];
81+
}
82+
83+
return this.overlock;
84+
}
85+
86+
public int[] getAlterOverlock() {
87+
if (this.alterOverlock == null) {
88+
this.alterOverlock = new int[this.attributes.length];
89+
}
90+
91+
return this.alterOverlock;
92+
}
93+
94+
public int getOverlockCount() {
95+
int count = 0;
96+
97+
for (int i = 0; i < this.getOverlock().length; i++) {
98+
count += this.getOverlock()[i];
99+
}
100+
101+
return count;
102+
}
103+
61104
// Proto
62105

63106
public CharGem toProto() {
64107
var proto = CharGem.newInstance()
65108
.setLock(this.isLocked())
66109
.addAllAttributes(this.getAttributes())
67110
.addAllAlterAttributes(this.getAlterAttributes())
68-
.addAllOverlockCount(new int[this.getAttributes().length])
69-
.addAllAlterOverlockCount(new int[this.getAlterAttributes().length]);
111+
.addAllOverlockCount(this.getOverlock())
112+
.addAllAlterOverlockCount(this.getAlterOverlock());
70113

71114
return proto;
72115
}

src/main/java/emu/nebula/game/character/GameCharacter.java

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -769,10 +769,10 @@ public synchronized PlayerChangeInfo refreshGem(int slotId, int gemIndex, Repeat
769769

770770
// Create base list of attributes
771771
var list = new CustomIntArray();
772+
var locked = new IntOpenHashSet();
772773

773774
// Add locked attributes to list
774775
if (lockedAttributes.length() != 0) {
775-
var locked = new IntOpenHashSet();
776776
lockedAttributes.forEach(locked::add);
777777

778778
for (int i = 0; i < gem.getAttributes().length; i++) {
@@ -786,7 +786,7 @@ public synchronized PlayerChangeInfo refreshGem(int slotId, int gemIndex, Repeat
786786

787787
// Generate attributes and create gem
788788
var attributes = gemControl.generateAttributes(this, list);
789-
gem.setNewAttributes(attributes);
789+
gem.setNewAttributes(attributes, locked);
790790

791791
// Save to database
792792
this.save();
@@ -818,6 +818,92 @@ public boolean replaceGemAttributes(int slotId, int gemIndex) {
818818
return success;
819819
}
820820

821+
public PlayerChangeInfo overlockGem(int slotId, int gemIndex, int attrIndex) {
822+
// Get gem from slot
823+
var gem = this.getGemFromSlot(slotId, gemIndex);
824+
if (gem == null) return null;
825+
826+
// Sanity check attr index
827+
if (attrIndex < 0 || attrIndex >= gem.getAttributes().length) {
828+
return null;
829+
}
830+
831+
// Get total overlock count
832+
int count = gem.getOverlockCount();
833+
834+
if (count >= GameConstants.CHARACTER_MAX_OVERLOCK_COUNT) {
835+
return null;
836+
}
837+
838+
// Get gem data
839+
var gemData = this.getData().getCharGemData(slotId);
840+
var gemControl = GameData.getCharGemSlotControlDataTable().get(slotId);
841+
842+
if (gemControl == null) {
843+
return null;
844+
}
845+
846+
// Calculate the materials we need
847+
var materials = new ItemParamMap();
848+
materials.add(gemData.getOverlockCostTid(), gemControl.getOverlockCostQty());
849+
materials.add(GameConstants.GOLD_ITEM_ID, gemControl.getOverlockDoraCostQty());
850+
851+
// Make sure the player has the materials to craft the emblem
852+
if (!getPlayer().getInventory().hasItems(materials)) {
853+
return null;
854+
}
855+
856+
// Get attribute
857+
int attrId = gem.getAttributes()[attrIndex];
858+
var attr = GameData.getCharGemAttrValueDataTable().get(attrId);
859+
860+
if (attr == null) {
861+
return null;
862+
}
863+
864+
// Check if we can upgrade
865+
if (gem.getOverlock()[attrIndex] >= attr.getOverlockCount()) {
866+
return null;
867+
}
868+
869+
// Upgrade overlock
870+
gem.getOverlock()[attrIndex]++;
871+
872+
// Consume materials
873+
var change = getPlayer().getInventory().removeItems(materials);
874+
875+
// Save
876+
this.save();
877+
878+
// Success
879+
return change;
880+
}
881+
882+
public PlayerChangeInfo revertOverlockGem(int slotId, int gemIndex, int attrIndex) {
883+
// Get gem from slot
884+
var gem = this.getGemFromSlot(slotId, gemIndex);
885+
if (gem == null) return null;
886+
887+
// Sanity check attr index
888+
if (attrIndex < 0 || attrIndex >= gem.getAttributes().length) {
889+
return null;
890+
}
891+
892+
// Check if we can revert
893+
if (gem.getOverlock()[attrIndex] <= 0) {
894+
return null;
895+
}
896+
897+
// Revert overlock
898+
gem.getOverlock()[attrIndex]--;
899+
900+
// Save
901+
this.save();
902+
903+
// Success
904+
return new PlayerChangeInfo();
905+
}
906+
821907
// Proto
822908

823909
public Char toProto() {
@@ -892,7 +978,7 @@ public StarTowerChar toStarTowerProto() {
892978

893979
if (gem != null) {
894980
info.addAllAttributes(gem.getAttributes());
895-
info.addAllOverlockCount(new int[gem.getAttributes().length]);
981+
info.addAllOverlockCount(gem.getOverlock());
896982
} else {
897983
info.addAllAttributes(new int[4]);
898984
info.addAllOverlockCount(new int[4]);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package emu.nebula.server.handlers;
2+
3+
import emu.nebula.net.NetHandler;
4+
import emu.nebula.net.NetMsgId;
5+
import emu.nebula.proto.CharGemUseOverlock.CharGemOverlockReq;
6+
import emu.nebula.net.HandlerId;
7+
import emu.nebula.net.GameSession;
8+
9+
@HandlerId(NetMsgId.char_gem_overlock_req)
10+
public class HandlerCharGemOverlockReq extends NetHandler {
11+
12+
@Override
13+
public byte[] handle(GameSession session, byte[] message) throws Exception {
14+
// Parse req
15+
var req = CharGemOverlockReq.parseFrom(message);
16+
17+
// Get character
18+
var character = session.getPlayer().getCharacters().getCharacterById(req.getCharId());
19+
20+
if (character == null) {
21+
return session.encodeMsg(NetMsgId.char_gem_overlock_failed_ack);
22+
}
23+
24+
// Overlock gem
25+
var change = character.overlockGem(req.getSlotId(), req.getGemIndex(), req.getAttrIndex());
26+
27+
if (change == null) {
28+
return session.encodeMsg(NetMsgId.char_gem_overlock_failed_ack);
29+
}
30+
31+
// Encode and send
32+
return session.encodeMsg(NetMsgId.char_gem_overlock_succeed_ack, change.toProto());
33+
}
34+
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package emu.nebula.server.handlers;
2+
3+
import emu.nebula.net.NetHandler;
4+
import emu.nebula.net.NetMsgId;
5+
import emu.nebula.proto.CharGemUseOverlockRevert.CharGemOverlockRevertReq;
6+
import emu.nebula.net.HandlerId;
7+
import emu.nebula.net.GameSession;
8+
9+
@HandlerId(NetMsgId.char_gem_overlock_revert_req)
10+
public class HandlerCharGemOverlockRevertReq extends NetHandler {
11+
12+
@Override
13+
public byte[] handle(GameSession session, byte[] message) throws Exception {
14+
// Parse req
15+
var req = CharGemOverlockRevertReq.parseFrom(message);
16+
17+
// Get character
18+
var character = session.getPlayer().getCharacters().getCharacterById(req.getCharId());
19+
20+
if (character == null) {
21+
return session.encodeMsg(NetMsgId.char_gem_overlock_revert_failed_ack);
22+
}
23+
24+
// Overlock gem
25+
var change = character.revertOverlockGem(req.getSlotId(), req.getGemIndex(), req.getAttrIndex());
26+
27+
if (change == null) {
28+
return session.encodeMsg(NetMsgId.char_gem_overlock_revert_failed_ack);
29+
}
30+
31+
// Encode and send
32+
return session.encodeMsg(NetMsgId.char_gem_overlock_revert_succeed_ack, change.toProto());
33+
}
34+
35+
}

src/main/java/emu/nebula/server/handlers/HandlerCharGemRefreshReq.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public byte[] handle(GameSession session, byte[] message) throws Exception {
3939
// Build response
4040
var rsp = CharGemRefreshResp.newInstance()
4141
.setChangeInfo(change.toProto())
42-
.addAllAttributes(gem.getAlterAttributes());
42+
.addAllAttributes(gem.getAlterAttributes())
43+
.addAllOverlockCount(gem.getAlterOverlock());
4344

4445
// Encode and send
4546
return session.encodeMsg(NetMsgId.char_gem_refresh_succeed_ack, rsp);

0 commit comments

Comments
 (0)