Fixed value parsing from item definitions

This commit is contained in:
Ceikry 2022-10-03 07:26:34 +00:00 committed by Ryan
parent 30f43e1a18
commit 39cf1f60ca
5 changed files with 14694 additions and 33 deletions

View file

@ -81,7 +81,7 @@ public class ItemDefinition extends Definition<Item> {
/** /**
* The item value. * The item value.
*/ */
private int value; private int value = 1;
/** /**
* If item is members only. * If item is members only.
@ -358,14 +358,9 @@ public class ItemDefinition extends Definition<Item> {
} else if (opcode == 11) { } else if (opcode == 11) {
def.stackable = true; def.stackable = true;
} else if (opcode == 12) { } else if (opcode == 12) {
def.value = buffer.getInt(); def.value = ((buffer.get() & 0xFF) << 24) + ((buffer.get() & 0xFF) << 16) + ((buffer.get() & 0xFF) << 8) + (buffer.get() & 0xFF);
if (def.value == 0) {
def.value = 1;
}
} else if (opcode == 16) { } else if (opcode == 16) {
def.membersOnly = true; def.membersOnly = true;
} else if (opcode == 18) {
buffer.getShort();
} else if (opcode == 23) { } else if (opcode == 23) {
def.maleWornModelId1 = buffer.getShort() & 0xFFFF; def.maleWornModelId1 = buffer.getShort() & 0xFFFF;
// buffer.get(); // buffer.get();
@ -446,15 +441,6 @@ public class ItemDefinition extends Definition<Item> {
def.lendId = buffer.getShort() & 0xFFFF; def.lendId = buffer.getShort() & 0xFFFF;
} else if (opcode == 122) { } else if (opcode == 122) {
def.lendTemplateId = buffer.getShort() & 0xFFFF; def.lendTemplateId = buffer.getShort() & 0xFFFF;
} else if (opcode == 124) {
if (def.unknownArray3 == null) {
def.unknownArray3 = new int[11][];
}
int slot = buffer.get();
def.unknownArray3[slot] = new int[6];
for (int i = 0; i < 6; i++) {
def.unknownArray3[slot][i] = buffer.getShort();
}
} else if (opcode == 125) { } else if (opcode == 125) {
buffer.get(); buffer.get();
buffer.get(); buffer.get();
@ -475,18 +461,6 @@ public class ItemDefinition extends Definition<Item> {
} else if (opcode == 130) { } else if (opcode == 130) {
buffer.get(); buffer.get();
buffer.getShort(); buffer.getShort();
} else if (opcode == 132) {
int length = buffer.get() & 0xFF;
def.unknownArray2 = new int[length];
for (int index = 0; index < length; index++) {
def.unknownArray2[index] = buffer.getShort() & 0xFFFF;
}
} else if (opcode == 134) {
buffer.get();
} else if (opcode == 139) {
def.recolourId = buffer.getShort() & 0xFFFF;
} else if (opcode == 140) {
def.recolourTemplateId = buffer.getShort() & 0xFFFF;
} else if (opcode == 249) { } else if (opcode == 249) {
int length = buffer.get() & 0xFF; int length = buffer.get() & 0xFF;
if (def.clientScriptData == null) { if (def.clientScriptData == null) {
@ -923,9 +897,6 @@ public class ItemDefinition extends Definition<Item> {
* @return The value. * @return The value.
*/ */
public int getValue() { public int getValue() {
if (value == 0) {
return 1;
}
return value; return value;
} }

View file

@ -233,7 +233,6 @@ class ItemConfigParser {
when (it.key.toString()) { when (it.key.toString()) {
//Special cases //Special cases
"defence_anim" -> configs.put(it.key.toString(), Animation(it.value.toString().toInt(), Animator.Priority.HIGH)) "defence_anim" -> configs.put(it.key.toString(), Animation(it.value.toString().toInt(), Animator.Priority.HIGH))
"shop_price" -> {def.value = (it.value.toString().toInt()); configs.put(it.key.toString(),it.value.toString().toInt())}
"requirements" -> { configs.put(it.key.toString(),requirements) "requirements" -> { configs.put(it.key.toString(),requirements)
it.value.toString() it.value.toString()
.split("-") .split("-")

View file

@ -18,6 +18,8 @@ import rs09.game.system.config.ServerConfigParser
import rs09.game.world.GameWorld import rs09.game.world.GameWorld
import rs09.game.world.repository.Repository import rs09.game.world.repository.Repository
import rs09.game.world.update.UpdateSequence import rs09.game.world.update.UpdateSequence
import java.io.File
import java.net.URI
import java.nio.ByteBuffer import java.nio.ByteBuffer
object TestUtils { object TestUtils {
@ -60,6 +62,10 @@ object TestUtils {
} }
} }
fun loadFile(path: String) : URI? {
return this::class.java.getResource(path)?.toURI()
}
fun advanceTicks(amount: Int, skipPulseUpdates: Boolean = true) { fun advanceTicks(amount: Int, skipPulseUpdates: Boolean = true) {
SystemLogger.logInfo(this::class.java, "Advancing ticks by $amount.") SystemLogger.logInfo(this::class.java, "Advancing ticks by $amount.")
for(i in 0 until amount) { for(i in 0 until amount) {

View file

@ -0,0 +1,27 @@
package core.cache
import TestUtils
import api.itemDefinition
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import java.io.File
class ItemDefTests {
val knownGood = HashMap<Int,Int>()
init {
TestUtils.preTestSetup()
}
@Test fun itemDefsShouldHaveExpectedValues() {
File(TestUtils.loadFile("530_cache_item_values_from_client.csv")).useLines { lines ->
lines.forEach {
val toks = it.split(",")
knownGood[toks[0].toIntOrNull() ?: return@forEach] = toks[toks.size - 1].toInt()
}
}
for ((id, expectedValue) in knownGood) {
val def = itemDefinition(id)
Assertions.assertEquals(expectedValue, def.value, "Value of ${def.name} (${def.isUnnoted}) does not match known good values!")
}
}
}

File diff suppressed because it is too large Load diff