mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-09 16:45:44 -07:00
Cleaned up legacy save code
This commit is contained in:
parent
acc6c182a5
commit
c03947e0b0
23 changed files with 53 additions and 708 deletions
|
|
@ -20,7 +20,6 @@ import core.game.world.GameWorld;
|
|||
import org.rs09.consts.Sounds;
|
||||
|
||||
import java.awt.*;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static core.api.ContentAPIKt.*;
|
||||
import static core.api.regionspec.RegionSpecificationKt.fillWith;
|
||||
|
|
@ -99,36 +98,6 @@ public final class HouseManager {
|
|||
}
|
||||
|
||||
|
||||
public void save(ByteBuffer buffer) {
|
||||
buffer.put((byte) location.ordinal());
|
||||
buffer.put((byte) style.ordinal());
|
||||
if (hasServant()) {
|
||||
servant.save(buffer);
|
||||
} else {
|
||||
buffer.put((byte) -1);
|
||||
}
|
||||
for (int z = 0; z < 4; z++) {
|
||||
for (int x = 0; x < 8; x++) {
|
||||
for (int y = 0; y < 8; y++) {
|
||||
Room room = rooms[z][x][y];
|
||||
if (room != null) {
|
||||
buffer.put((byte) z).put((byte) x).put((byte) y);
|
||||
buffer.put((byte) room.getProperties().ordinal());
|
||||
buffer.put((byte) room.getRotation().toInteger());
|
||||
for (int i = 0; i < room.getHotspots().length; i++) {
|
||||
if (room.getHotspots()[i].getDecorationIndex() > -1) {
|
||||
buffer.put((byte) i);
|
||||
buffer.put((byte) room.getHotspots()[i].getDecorationIndex());
|
||||
}
|
||||
}
|
||||
buffer.put((byte) -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
buffer.put((byte) -1);//Eof
|
||||
}
|
||||
|
||||
public void parse(JSONObject data){
|
||||
location = HouseLocation.values()[Integer.parseInt( data.get("location").toString())];
|
||||
style = HousingStyle.values()[Integer.parseInt( data.get("style").toString())];
|
||||
|
|
@ -155,28 +124,6 @@ public final class HouseManager {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void parse(ByteBuffer buffer) {
|
||||
location = HouseLocation.values()[buffer.get() & 0xFF];
|
||||
style = HousingStyle.values()[buffer.get() & 0xFF];
|
||||
servant = Servant.parse(buffer);
|
||||
int z = 0;
|
||||
while ((z = buffer.get()) != -1) {
|
||||
if (z == 3) {
|
||||
hasDungeon = true;
|
||||
}
|
||||
int x = buffer.get();
|
||||
int y = buffer.get();
|
||||
Room room = rooms[z][x][y] = new Room(RoomProperties.values()[buffer.get() & 0xFF]);
|
||||
room.configure(style);
|
||||
room.setRotation(Direction.get(buffer.get() & 0xFF));
|
||||
int spot = 0;
|
||||
while ((spot = buffer.get()) != -1) {
|
||||
room.getHotspots()[spot].setDecorationIndex(buffer.get() & 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares for entering the player's house.
|
||||
* @param player
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ import core.game.node.entity.npc.NPC;
|
|||
import core.game.node.item.Item;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Represents a player's servant.
|
||||
* @author Emperor
|
||||
|
|
@ -44,26 +42,9 @@ public final class Servant extends NPC {
|
|||
}
|
||||
|
||||
/**
|
||||
* Saves the servant details.
|
||||
* @param buffer The buffer to write on.
|
||||
*/
|
||||
public void save(ByteBuffer buffer) {
|
||||
buffer.put((byte) type.ordinal());
|
||||
buffer.putShort((byte) uses);
|
||||
if (item == null) {
|
||||
buffer.putShort((short) -1);
|
||||
} else {
|
||||
buffer.putShort((short) item.getId());
|
||||
buffer.putInt(item.getAmount());
|
||||
}
|
||||
buffer.put((byte) (greet ? 1 : 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the servant from the buffer.
|
||||
* Parses the servant from the save file.
|
||||
* @return The servant.
|
||||
*/
|
||||
|
||||
public static Servant parse(JSONObject data){
|
||||
int type = Integer.parseInt( data.get("type").toString());
|
||||
Servant servant = new Servant(ServantType.values()[type]);
|
||||
|
|
@ -77,21 +58,6 @@ public final class Servant extends NPC {
|
|||
return servant;
|
||||
}
|
||||
|
||||
public static Servant parse(ByteBuffer buffer) {
|
||||
int type = buffer.get();
|
||||
if (type == -1) {
|
||||
return null;
|
||||
}
|
||||
Servant servant = new Servant(ServantType.values()[type]);
|
||||
servant.uses = buffer.getShort() & 0xFFFF;
|
||||
int itemId = buffer.getShort() & 0xFFFF;
|
||||
if ((short) itemId != -1) {
|
||||
servant.item = new Item(itemId, buffer.getInt());
|
||||
}
|
||||
servant.greet = buffer.get() == 1;
|
||||
return servant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item value.
|
||||
* @return The item.
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import core.game.node.entity.player.Player
|
|||
import core.game.node.entity.player.link.diary.DiaryType
|
||||
import core.game.node.entity.skill.Skills
|
||||
import content.data.skill.SkillingTool
|
||||
import content.global.activity.shootingstar.StarBonus
|
||||
import content.global.skill.skillcapeperks.SkillcapePerks
|
||||
import core.game.node.item.ChanceItem
|
||||
import core.game.node.scenery.Scenery
|
||||
|
|
@ -224,7 +225,7 @@ class MiningSkillPulse(private val player: Player, private val node: Node) : Pul
|
|||
}
|
||||
|
||||
// If player has mining boost from Shooting Star, roll chance at extra ore
|
||||
if (player.hasActiveState("shooting-star")) {
|
||||
if (hasTimerActive<StarBonus>(player)) {
|
||||
if (RandomFunction.getRandom(5) == 3) {
|
||||
sendMessage(player, "...you manage to mine a second ore thanks to the Star Sprite.")
|
||||
amount += 1
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package core.cache.def.impl;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import core.ServerConstants;
|
||||
import core.cache.Cache;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package core.cache.def.impl;
|
||||
|
||||
import core.ServerConstants;
|
||||
import content.global.skill.summoning.familiar.BurdenBeast;
|
||||
import core.api.EquipmentSlot;
|
||||
import core.cache.Cache;
|
||||
import core.cache.def.Definition;
|
||||
|
|
@ -12,17 +12,12 @@ import core.game.node.entity.skill.Skills;
|
|||
import core.game.node.item.Item;
|
||||
import core.game.node.item.ItemPlugin;
|
||||
import core.game.world.GameWorld;
|
||||
import core.net.packet.PacketRepository;
|
||||
import core.net.packet.out.WeightUpdate;
|
||||
import core.plugin.Plugin;
|
||||
import core.tools.Log;
|
||||
import core.tools.StringUtils;
|
||||
import core.tools.SystemLogger;
|
||||
import core.game.system.config.ItemConfigParser;
|
||||
import org.rs09.consts.Items;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
|
@ -33,7 +28,6 @@ import static core.api.ContentAPIKt.log;
|
|||
|
||||
/**
|
||||
* Represents an item's definitions.
|
||||
* @author Jagex
|
||||
* @author Emperor
|
||||
*/
|
||||
public class ItemDefinition extends Definition<Item> {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package core.cache.def.impl;
|
|||
|
||||
import core.cache.Cache;
|
||||
import core.tools.Log;
|
||||
import core.tools.SystemLogger;
|
||||
import core.game.world.GameWorld;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import core.game.interaction.OptionHandler;
|
|||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.scenery.Scenery;
|
||||
import core.tools.Log;
|
||||
import core.tools.SystemLogger;
|
||||
import core.game.world.GameWorld;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import org.json.simple.JSONArray;
|
|||
import org.json.simple.JSONObject;
|
||||
import org.rs09.consts.Items;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
|
@ -560,30 +559,6 @@ public class Container {
|
|||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the container data from the byte buffer.
|
||||
*
|
||||
* @param buffer The byte buffer.
|
||||
* @return The total value of all items (G.E price > Store price > High
|
||||
* alchemy price).
|
||||
*/
|
||||
public int parse(ByteBuffer buffer) {
|
||||
int slot;
|
||||
int total = 0;
|
||||
while ((slot = buffer.getShort()) != -1) {
|
||||
int id = buffer.getShort() & 0xFFFF;
|
||||
int amount = buffer.getInt();
|
||||
int charge = buffer.getInt();
|
||||
if (id >= ItemDefinition.getDefinitions().size() || slot >= items.length || slot < 0) {
|
||||
continue;
|
||||
}
|
||||
Item item = items[slot] = new Item(id, amount, charge);
|
||||
item.setIndex(slot);
|
||||
total += item.getValue();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public void parse(JSONArray itemArray){
|
||||
AtomicInteger total = new AtomicInteger(0);
|
||||
itemArray.forEach(item -> {
|
||||
|
|
@ -601,30 +576,6 @@ public class Container {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the item data on the byte buffer.
|
||||
*
|
||||
* @param buffer The byte buffer.
|
||||
* @return The total value of all items (G.E price > Store price > High
|
||||
* alchemy price).
|
||||
*/
|
||||
public long save(ByteBuffer buffer) {
|
||||
long totalValue = 0;
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
Item item = items[i];
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
buffer.putShort((short) i);
|
||||
buffer.putShort((short) item.getId());
|
||||
buffer.putInt(item.getAmount());
|
||||
buffer.putInt(item.getCharge());
|
||||
totalValue += item.getValue();
|
||||
}
|
||||
buffer.putShort((short) -1);
|
||||
return totalValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the container to this container.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -166,26 +166,6 @@ public final class BankContainer extends Container {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long save(ByteBuffer buffer) {
|
||||
buffer.putInt(lastAmountX);
|
||||
buffer.put((byte) tabStartSlot.length);
|
||||
for (int j : tabStartSlot) {
|
||||
buffer.putShort((short) j);
|
||||
}
|
||||
return super.save(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int parse(ByteBuffer buffer) {
|
||||
lastAmountX = buffer.getInt();
|
||||
int length = buffer.get() & 0xFF;
|
||||
for (int i = 0; i < length; i++) {
|
||||
tabStartSlot[i] = buffer.getShort();
|
||||
}
|
||||
return super.parse(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the bank.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -71,8 +71,6 @@ import core.game.node.entity.combat.CombatSwingHandler;
|
|||
import content.global.handlers.item.equipment.EquipmentDegrader;
|
||||
import core.game.node.entity.combat.graves.Grave;
|
||||
import core.game.node.entity.combat.graves.GraveController;
|
||||
import core.game.node.entity.state.State;
|
||||
import core.game.node.entity.state.StateRepository;
|
||||
import core.game.world.GameWorld;
|
||||
import core.game.world.repository.Repository;
|
||||
import core.game.world.update.MapChunkRenderer;
|
||||
|
|
@ -123,10 +121,9 @@ public class Player extends Entity {
|
|||
|
||||
public VarpManager varpManager = new VarpManager(this);
|
||||
|
||||
public HashMap<Integer, Integer> varpMap = new HashMap<>();
|
||||
public HashMap<Integer, Boolean> saveVarp = new HashMap<>();
|
||||
public HashMap<Integer, Integer> varpMap = new HashMap<>();
|
||||
|
||||
public HashMap<String,State> states = new HashMap<>();
|
||||
public HashMap<Integer, Boolean> saveVarp = new HashMap<>();
|
||||
|
||||
public HashMap<String,Function1<Player, Unit>> logoutListeners = new HashMap<>();
|
||||
|
||||
|
|
@ -500,21 +497,21 @@ public class Player extends Entity {
|
|||
if (i == null) break;
|
||||
totalWealth += (long) i.getDefinition().getValue() * i.getAmount();
|
||||
}
|
||||
GrandExchangeRecords ge = GrandExchangeRecords.getInstance(this);
|
||||
for (int i=0; i<6; i++) {
|
||||
GrandExchangeOffer offer = ge.getOffer(i);
|
||||
if (offer != null) {
|
||||
totalWealth += offer.cacheValue();
|
||||
}
|
||||
}
|
||||
GrandExchangeRecords ge = GrandExchangeRecords.getInstance(this);
|
||||
for (int i=0; i<6; i++) {
|
||||
GrandExchangeOffer offer = ge.getOffer(i);
|
||||
if (offer != null) {
|
||||
totalWealth += offer.cacheValue();
|
||||
}
|
||||
}
|
||||
|
||||
// This can lead to a false positive of up to 3 * 187.5k, but only for 3 ticks while a cannon is being constructed
|
||||
if (this.getAttribute("dmc", null) != null) {
|
||||
totalWealth += ItemDefinition.forId(Items.CANNON_BASE_6).getValue();
|
||||
totalWealth += ItemDefinition.forId(Items.CANNON_STAND_8).getValue();
|
||||
totalWealth += ItemDefinition.forId(Items.CANNON_BARRELS_10).getValue();
|
||||
totalWealth += ItemDefinition.forId(Items.CANNON_FURNACE_12).getValue();
|
||||
}
|
||||
// This can lead to a false positive of up to 3 * 187.5k, but only for 3 ticks while a cannon is being constructed
|
||||
if (this.getAttribute("dmc", null) != null) {
|
||||
totalWealth += ItemDefinition.forId(Items.CANNON_BASE_6).getValue();
|
||||
totalWealth += ItemDefinition.forId(Items.CANNON_STAND_8).getValue();
|
||||
totalWealth += ItemDefinition.forId(Items.CANNON_BARRELS_10).getValue();
|
||||
totalWealth += ItemDefinition.forId(Items.CANNON_FURNACE_12).getValue();
|
||||
}
|
||||
|
||||
long diff = previousWealth == -1 ? 0L : totalWealth - previousWealth;
|
||||
setAttribute("/save:last-wealth", totalWealth);
|
||||
|
|
@ -557,15 +554,15 @@ public class Player extends Entity {
|
|||
return this.getIndex() | 0x8000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttack (Entity e) {
|
||||
if (e instanceof Player) {
|
||||
Player p = (Player) e;
|
||||
if (skullManager.isWildernessDisabled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onAttack (Entity e) {
|
||||
if (e instanceof Player) {
|
||||
Player p = (Player) e;
|
||||
if (skullManager.isWildernessDisabled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CombatSwingHandler getSwingHandler(boolean swing) {
|
||||
|
|
@ -594,7 +591,7 @@ public class Player extends Entity {
|
|||
|
||||
@Override
|
||||
public void commenceDeath(Entity killer) {
|
||||
if (!isPlaying()) return;
|
||||
if (!isPlaying()) return;
|
||||
super.commenceDeath(killer);
|
||||
if (prayer.get(PrayerType.RETRIBUTION)) {
|
||||
prayer.startRetribution(killer);
|
||||
|
|
@ -747,18 +744,18 @@ public class Player extends Entity {
|
|||
if (entity instanceof NPC && !((NPC) entity).getDefinition().hasAction("attack") && !((NPC) entity).isIgnoreAttackRestrictions(this)) {
|
||||
return false;
|
||||
}
|
||||
if (entity instanceof Player) {
|
||||
Player p = (Player) entity;
|
||||
if (p.getSkullManager().isWilderness() && skullManager.isWilderness()) {
|
||||
if (!GameWorld.getSettings().getWild_pvp_enabled())
|
||||
return false;
|
||||
if (p.getSkullManager().hasWildernessProtection())
|
||||
return false;
|
||||
if (skullManager.hasWildernessProtection())
|
||||
return false;
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
if (entity instanceof Player) {
|
||||
Player p = (Player) entity;
|
||||
if (p.getSkullManager().isWilderness() && skullManager.isWilderness()) {
|
||||
if (!GameWorld.getSettings().getWild_pvp_enabled())
|
||||
return false;
|
||||
if (p.getSkullManager().hasWildernessProtection())
|
||||
return false;
|
||||
if (skullManager.hasWildernessProtection())
|
||||
return false;
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
return super.isAttackable(entity, style, message);
|
||||
}
|
||||
|
||||
|
|
@ -1346,7 +1343,6 @@ public class Player extends Entity {
|
|||
return "Player [name=" + name + ", getRights()=" + getRights() + "]";
|
||||
}
|
||||
|
||||
|
||||
public String getCustomState() {
|
||||
return customState;
|
||||
}
|
||||
|
|
@ -1372,37 +1368,15 @@ public class Player extends Entity {
|
|||
this.archeryTotal = archeryTotal;
|
||||
}
|
||||
|
||||
public boolean hasActiveState(String key){
|
||||
State state = states.get(key);
|
||||
if(state != null && state.getPulse() != null){
|
||||
return true;
|
||||
public void updateAppearance() {
|
||||
getUpdateMasks().register(EntityFlag.Appearance, this);
|
||||
}
|
||||
|
||||
public void incrementInvalidPacketCount() {
|
||||
invalidPacketCount++;
|
||||
if (invalidPacketCount >= 5) {
|
||||
clear();
|
||||
log(this.getClass(), Log.ERR, "Disconnecting " + getName() + " for having a high rate of invalid packets. Potential packet bot misbehaving, or simply really bad connection.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public State registerState(String key){
|
||||
return StateRepository.forKey(key, this);
|
||||
}
|
||||
|
||||
public void clearState(String key){
|
||||
State state = states.get(key);
|
||||
if(state == null) return;
|
||||
Pulse pulse = state.getPulse();
|
||||
if(pulse != null) {
|
||||
pulse.stop();
|
||||
}
|
||||
states.remove(key);
|
||||
}
|
||||
|
||||
public void updateAppearance() {
|
||||
getUpdateMasks().register(EntityFlag.Appearance, this);
|
||||
}
|
||||
|
||||
public void incrementInvalidPacketCount() {
|
||||
invalidPacketCount++;
|
||||
if (invalidPacketCount >= 5) {
|
||||
clear();
|
||||
log(this.getClass(), Log.ERR, "Disconnecting " + getName() + " for having a high rate of invalid packets. Potential packet bot misbehaving, or simply really bad connection.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ class PlayerSaveParser(val player: Player) {
|
|||
parseAppearance()
|
||||
parseGrave()
|
||||
parseVarps()
|
||||
parseStates()
|
||||
parseSpellbook()
|
||||
parseSavedData()
|
||||
parseAutocastSpell()
|
||||
|
|
@ -174,22 +173,6 @@ class PlayerSaveParser(val player: Player) {
|
|||
player.bankPinManager.parse(bpData)
|
||||
}
|
||||
|
||||
fun parseStates() {
|
||||
player.states.clear()
|
||||
if (saveFile!!.containsKey("states")) {
|
||||
val states: JSONArray = saveFile!!["states"] as JSONArray
|
||||
for (state in states) {
|
||||
val s = state as JSONObject
|
||||
val stateId = s["stateKey"].toString()
|
||||
if(player.states[stateId] != null) continue
|
||||
val stateClass = player.registerState(stateId)
|
||||
stateClass?.parse(s)
|
||||
stateClass?.init()
|
||||
player.states.put(stateId,stateClass)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun parseFamiliars() {
|
||||
val familiarData = saveFile!!["familiarManager"] as JSONObject
|
||||
player.familiarManager.parse(familiarData)
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ class PlayerSaver (val player: Player){
|
|||
savePlayerMonitor(saveFile)
|
||||
saveMusicPlayer(saveFile)
|
||||
saveFamiliarManager(saveFile)
|
||||
saveStateManager(saveFile)
|
||||
saveBankPinData(saveFile)
|
||||
saveHouseData(saveFile)
|
||||
saveAchievementData(saveFile)
|
||||
|
|
@ -262,19 +261,6 @@ class PlayerSaver (val player: Player){
|
|||
root.put("bankPinManager",bankPinManager)
|
||||
}
|
||||
|
||||
fun saveStateManager(root: JSONObject){
|
||||
val states = JSONArray()
|
||||
player.states.forEach{key,clazz ->
|
||||
if(clazz != null && clazz.pulse != null) {
|
||||
val stateObj = JSONObject()
|
||||
stateObj.put("stateKey", key)
|
||||
clazz.save(stateObj)
|
||||
states.add(stateObj)
|
||||
}
|
||||
}
|
||||
root.put("states",states)
|
||||
}
|
||||
|
||||
fun saveFamiliarManager(root: JSONObject){
|
||||
val familiarManager = JSONObject()
|
||||
val petDetails = JSONObject()
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import core.game.node.item.Item;
|
|||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
|
@ -97,19 +96,6 @@ public final class QuestData {
|
|||
witchsExperimentStage = Integer.parseInt( data.get("witchsExperimentStage").toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the desert treasure node.
|
||||
* @param buffer The buffer.
|
||||
*/
|
||||
private final void saveDesertTreasureNode(ByteBuffer buffer) {
|
||||
buffer.put((byte) 8);
|
||||
for (int i = 0; i < desertTreasure.length; i++) {
|
||||
Item item = desertTreasure[i];
|
||||
buffer.putShort((short) item.getId());
|
||||
buffer.put((byte) item.getAmount());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the draynorLever.
|
||||
* @return The draynorLever.
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ package core.game.node.entity.player.link;
|
|||
|
||||
import core.game.node.entity.player.Player;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Represents a managing class of saved data related to ingame interactions,
|
||||
* such as questing data, npc talking data, etc.
|
||||
|
|
@ -39,45 +37,6 @@ public class SavedData {
|
|||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to save an activity var that isn't valued at default.
|
||||
* @param buffer the buffer.
|
||||
* @param var the variable to save.
|
||||
*/
|
||||
public static final void save(final ByteBuffer buffer, final Object var, final int index) {
|
||||
if (var instanceof Integer ? (int) var != 0 : var instanceof Double ? (double) var != 0.0 : var instanceof Byte ? (byte) var != 0 : var instanceof Short ? (short) var != 0 : var instanceof Long ? (long) var != 0L : var instanceof Boolean ? (boolean) var != false : var != null) {
|
||||
buffer.put((byte) index);
|
||||
if (var instanceof Integer) {
|
||||
buffer.putInt((int) var);
|
||||
} else if (var instanceof Byte) {
|
||||
buffer.put((byte) var);
|
||||
} else if (var instanceof Short) {
|
||||
buffer.putShort((short) var);
|
||||
} else if (var instanceof Long) {
|
||||
buffer.putLong((long) var);
|
||||
} else if (var instanceof Boolean) {
|
||||
buffer.put((byte) 1);
|
||||
} else if (var instanceof Double) {
|
||||
buffer.putDouble((double) var);
|
||||
} else if (var instanceof double[]) {
|
||||
double[] doubleArray = ((double[]) var);
|
||||
for (int i = 0; i < doubleArray.length; i++) {
|
||||
buffer.putDouble(doubleArray[i]);
|
||||
}
|
||||
} else if (var instanceof boolean[]) {
|
||||
boolean[] booleanArray = ((boolean[]) var);
|
||||
for (int i = 0; i < booleanArray.length; i++) {
|
||||
buffer.put((byte) (booleanArray[i] ? 1 : 0));
|
||||
}
|
||||
} else if (var instanceof int[]) {
|
||||
int[] intArray = ((int[]) var);
|
||||
for (int i = 0; i < intArray.length; i++) {
|
||||
buffer.putInt(intArray[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the boolean value.
|
||||
* @param value the value.
|
||||
|
|
@ -87,15 +46,6 @@ public class SavedData {
|
|||
return value == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the boolean value.
|
||||
* @param buffer the buffer.
|
||||
* @return the value.
|
||||
*/
|
||||
public static boolean getBoolean(ByteBuffer buffer) {
|
||||
return getBoolean(buffer.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the activityData.
|
||||
* @return The activityData.
|
||||
|
|
|
|||
|
|
@ -4,12 +4,8 @@ import core.game.system.config.ItemConfigParser;
|
|||
import org.json.simple.JSONObject;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.item.Item;
|
||||
import core.game.system.task.Pulse;
|
||||
import core.game.world.GameWorld;
|
||||
import core.net.packet.IoBuffer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static core.api.ContentAPIKt.*;
|
||||
|
||||
|
||||
|
|
@ -199,61 +195,9 @@ public final class Settings {
|
|||
}
|
||||
|
||||
/**
|
||||
* Writes the settings on the byte buffer.
|
||||
* @param buffer The byte buffer.
|
||||
* Parses the settings from the save file.
|
||||
* @param settingsData The JSON object.
|
||||
*/
|
||||
public void save(ByteBuffer buffer) {
|
||||
buffer.put((byte) 1).put((byte) brightness).put((byte) musicVolume).put((byte) soundEffectVolume).put((byte) areaSoundVolume).put((byte) (singleMouseButton ? 1 : 0)).put((byte) (disableChatEffects ? 1 : 0)).put((byte) (splitPrivateChat ? 1 : 0)).put((byte) (acceptAid ? 1 : 0)).put((byte) (runToggled ? 1 : 0)).put((byte) publicChatSetting).put((byte) privateChatSetting).put((byte) clanChatSetting).put((byte) tradeSetting).put((byte) assistSetting).put(((byte) runEnergy));
|
||||
if (!player.getProperties().isRetaliating()) {
|
||||
buffer.put((byte) 2);
|
||||
}
|
||||
if (specialEnergy != 100) {
|
||||
buffer.put((byte) 3).put((byte) specialEnergy);
|
||||
}
|
||||
if (attackStyleIndex != 0) {
|
||||
buffer.put((byte) 4).put((byte) attackStyleIndex);
|
||||
}
|
||||
buffer.put((byte) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the settings from the byte buffer.
|
||||
* @param buffer The byte buffer.
|
||||
*/
|
||||
public void parse(ByteBuffer buffer) {
|
||||
int opcode;
|
||||
while ((opcode = buffer.get() & 0xFF) != 0) {
|
||||
switch (opcode) {
|
||||
case 1:
|
||||
brightness = buffer.get();
|
||||
musicVolume = buffer.get();
|
||||
soundEffectVolume = buffer.get();
|
||||
areaSoundVolume = buffer.get();
|
||||
singleMouseButton = buffer.get() == 1;
|
||||
disableChatEffects = buffer.get() == 1;
|
||||
splitPrivateChat = buffer.get() == 1;
|
||||
acceptAid = buffer.get() == 1;
|
||||
runToggled = buffer.get() == 1;
|
||||
publicChatSetting = buffer.get();
|
||||
privateChatSetting = buffer.get();
|
||||
clanChatSetting = buffer.get();
|
||||
tradeSetting = buffer.get();
|
||||
assistSetting = buffer.get();
|
||||
runEnergy = buffer.get();
|
||||
break;
|
||||
case 2:
|
||||
player.getProperties().setRetaliating(false);
|
||||
break;
|
||||
case 3:
|
||||
specialEnergy = buffer.get() & 0xFF;
|
||||
break;
|
||||
case 4:
|
||||
attackStyleIndex = buffer.get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void parse(JSONObject settingsData){
|
||||
brightness = Integer.parseInt( settingsData.get("brightness").toString());
|
||||
musicVolume = Integer.parseInt( settingsData.get("musicVolume").toString());
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import core.plugin.CorePluginTypes.XPGainPlugins;
|
|||
import org.rs09.consts.Items;
|
||||
import org.rs09.consts.Sounds;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static core.api.ContentAPIKt.getWorldTicks;
|
||||
|
|
@ -413,30 +412,6 @@ public final class Skills {
|
|||
updateCombatLevel();
|
||||
}
|
||||
|
||||
public void parseExpRate(ByteBuffer buffer) {
|
||||
experienceMultiplier = buffer.getDouble();
|
||||
if(GameWorld.getSettings().getDefault_xp_rate() != experienceMultiplier){
|
||||
experienceMultiplier = GameWorld.getSettings().getDefault_xp_rate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the skill data on the buffer.
|
||||
* @param buffer The byte buffer.
|
||||
*/
|
||||
public void save(ByteBuffer buffer) {
|
||||
for (int i = 0; i < 24; i++) {
|
||||
buffer.putInt((int) (experience[i] * 10));
|
||||
buffer.put((byte) dynamicLevels[i]);
|
||||
buffer.put((byte) staticLevels[i]);
|
||||
}
|
||||
buffer.putInt((int) experienceGained);
|
||||
}
|
||||
|
||||
public void saveExpRate(ByteBuffer buffer) {
|
||||
buffer.putDouble(experienceMultiplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes all the skill levels.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
package core.game.node.entity.state
|
||||
|
||||
annotation class PlayerState(val key: String)
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package core.game.node.entity.state
|
||||
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.system.task.Pulse
|
||||
import org.json.simple.JSONObject
|
||||
import core.game.world.GameWorld.Pulser
|
||||
|
||||
/**
|
||||
* A class representing a state that the player or some associated thing can be in.
|
||||
* @param player The player the state is for
|
||||
* @author Ceikry
|
||||
*/
|
||||
abstract class State(val player: Player? = null) {
|
||||
var pulse: Pulse? = null
|
||||
|
||||
/**
|
||||
* Saves any additional data the state might need to the player's save.
|
||||
*/
|
||||
abstract fun save(root: JSONObject)
|
||||
|
||||
/**
|
||||
* Parses any additional saved data the state might have.
|
||||
*/
|
||||
abstract fun parse(_data: JSONObject)
|
||||
|
||||
/**
|
||||
* Returns a new instance of the class constructed for the player.
|
||||
*/
|
||||
abstract fun newInstance(player: Player? = null) : State
|
||||
|
||||
/**
|
||||
* Method used to define the pulse the state uses.
|
||||
* Called during the init method of the state, which is done during save parsing and done
|
||||
* manually when first creating a state.
|
||||
*/
|
||||
abstract fun createPulse()
|
||||
fun init() {
|
||||
createPulse()
|
||||
pulse ?: return
|
||||
Pulser.submit(pulse!!)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
package core.game.node.entity.state;
|
||||
|
||||
import core.game.node.entity.Entity;
|
||||
import core.game.system.task.Pulse;
|
||||
import core.game.world.GameWorld;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Represents a state pulse.
|
||||
* @author Emperor
|
||||
*/
|
||||
public abstract class StatePulse extends Pulse {
|
||||
|
||||
/**
|
||||
* The entity.
|
||||
*/
|
||||
protected final Entity entity;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code StatePulse} {@code Object}.
|
||||
* @param entity The entity.
|
||||
* @param ticks The amount of ticks.
|
||||
*/
|
||||
public StatePulse(Entity entity, int ticks) {
|
||||
super(ticks, entity);
|
||||
super.stop();
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if data has to be saved.
|
||||
* @return {@code True} if so.
|
||||
*/
|
||||
public abstract boolean isSaveRequired();
|
||||
|
||||
/**
|
||||
* Saves the state data.
|
||||
* @param buffer The buffer.
|
||||
*/
|
||||
public abstract void save(ByteBuffer buffer);
|
||||
|
||||
/**
|
||||
* Parses the state data.
|
||||
* @param entity The entity.
|
||||
* @param buffer The buffer.
|
||||
* @return The state pulse created.
|
||||
*/
|
||||
public abstract StatePulse parse(Entity entity, ByteBuffer buffer);
|
||||
|
||||
/**
|
||||
* Creates a new instance of this state pulse.
|
||||
* @param entity The entity.
|
||||
* @param args The arguments.
|
||||
* @return The state pulse.
|
||||
*/
|
||||
public abstract StatePulse create(Entity entity, Object... args);
|
||||
|
||||
/**
|
||||
* Checks if this pulse can be ran for the given entity.
|
||||
* @param entity The entity.
|
||||
* @return {@code True} if so.
|
||||
*/
|
||||
public boolean canRun(Entity entity) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the pulse gets manually removed.
|
||||
*/
|
||||
public void remove() {
|
||||
/*
|
||||
* empty.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the pulse.
|
||||
*/
|
||||
public void run() {
|
||||
if (isRunning()) {
|
||||
return;
|
||||
}
|
||||
restart();
|
||||
start();
|
||||
GameWorld.getPulser().submit(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
package core.game.node.entity.state
|
||||
|
||||
import core.api.StartupListener
|
||||
import core.game.node.entity.player.Player
|
||||
import io.github.classgraph.ClassGraph
|
||||
|
||||
class StateRepository : StartupListener{
|
||||
override fun startup() {
|
||||
loadStateClasses()
|
||||
}
|
||||
|
||||
companion object {
|
||||
val states = HashMap<String, State>()
|
||||
|
||||
fun loadStateClasses()
|
||||
{
|
||||
val result = ClassGraph().enableClassInfo().enableAnnotationInfo().acceptPackages("content").scan()
|
||||
result.getClassesWithAnnotation("core.game.node.entity.state.PlayerState").forEach{
|
||||
val key = it.getAnnotationInfo("core.game.node.entity.state.PlayerState").parameterValues[0].value as String
|
||||
val clazz = it.loadClass().newInstance()
|
||||
if(clazz is State) {
|
||||
states.put(key, clazz)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun forKey(key: String, player: Player): State?{
|
||||
val state = states[key]
|
||||
if(player.hasActiveState(key)){
|
||||
return states[key]
|
||||
}
|
||||
if(state != null){
|
||||
val clazz = state.newInstance(player)
|
||||
player.states[key] = clazz
|
||||
return clazz
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
package core.game.node.entity.state.impl;
|
||||
|
||||
import core.game.node.entity.Entity;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.entity.state.StatePulse;
|
||||
import core.game.world.GameWorld;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* The pulse used for fire resistant.
|
||||
* @author Vexia
|
||||
*/
|
||||
public class FireResistantPulse extends StatePulse {
|
||||
|
||||
/**
|
||||
* The time to finish.
|
||||
*/
|
||||
private static int END_TIME = GameWorld.getSettings().isDevMode() ? 30 : 600;
|
||||
|
||||
/**
|
||||
* The current tick.
|
||||
*/
|
||||
private int currentTick;
|
||||
|
||||
/**
|
||||
* If the potion is an extended antifire.
|
||||
*/
|
||||
private boolean extended;
|
||||
|
||||
/**
|
||||
* Constructs a new {@Code FireResistantPulse} {@Code Object}
|
||||
* @param entity the entity.
|
||||
* @param ticks the ticks.
|
||||
*/
|
||||
public FireResistantPulse(Entity entity, int ticks, int currentTick, boolean extended) {
|
||||
super(entity, ticks);
|
||||
this.extended = extended;
|
||||
this.currentTick = currentTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaveRequired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(ByteBuffer buffer) {
|
||||
buffer.putInt(currentTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatePulse parse(Entity entity, ByteBuffer buffer) {
|
||||
return new FireResistantPulse(entity, 1, buffer.getInt(), extended);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatePulse create(Entity entity, Object... args) {
|
||||
return new FireResistantPulse(entity, 1, 0, (boolean) args[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pulse() {
|
||||
if(extended && currentTick == 0 && END_TIME < 1200){
|
||||
END_TIME += 600;
|
||||
}
|
||||
if (entity instanceof Player) {
|
||||
if (currentTick == (END_TIME - 25)) {
|
||||
entity.asPlayer().getPacketDispatch().sendMessage("<col=7f007f>Your resistance to dragonfire is about to run out.");
|
||||
} else if (currentTick == (END_TIME - 1)) {
|
||||
entity.asPlayer().getPacketDispatch().sendMessage("<col=7f007f>Your resistance to dragonfire has run out.");
|
||||
}
|
||||
}
|
||||
return ++currentTick >= END_TIME;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,12 +1,10 @@
|
|||
package core.game.system.communication;
|
||||
|
||||
import core.cache.misc.buffer.ByteBufferUtils;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.tools.Log;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import proto.management.PrivateMessage;
|
||||
import core.auth.UserAccountInfo;
|
||||
import core.tools.SystemLogger;
|
||||
import core.game.system.mysql.SQLTable;
|
||||
import core.game.system.task.Pulse;
|
||||
import core.game.world.GameWorld;
|
||||
|
|
@ -19,7 +17,6 @@ import core.net.packet.out.ContactPackets;
|
|||
import core.tools.StringUtils;
|
||||
import core.worker.ManagementEvents;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
|
@ -215,27 +212,6 @@ public final class CommunicationInfo {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Roar temp
|
||||
* @param buffer
|
||||
*/
|
||||
public void parsePrevious(ByteBuffer buffer) {
|
||||
int size = buffer.get() & 0xFF;
|
||||
for (int i = 0; i < size; i++) {
|
||||
String name = ByteBufferUtils.getString(buffer);
|
||||
Contact contact = new Contact(name);
|
||||
contact.setRank(ClanRank.FRIEND);
|
||||
contacts.put(name, contact);
|
||||
}
|
||||
size = buffer.get() & 0xFF;
|
||||
for (int i = 0; i < size; i++) {
|
||||
blocked.add(ByteBufferUtils.getString(buffer));
|
||||
}
|
||||
if (buffer.get() == 1) {
|
||||
ByteBufferUtils.getString(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the target.
|
||||
* @param player The player sending the message.
|
||||
|
|
|
|||
|
|
@ -10,12 +10,10 @@ import org.json.simple.JSONObject
|
|||
import org.json.simple.parser.JSONParser
|
||||
import core.ServerConstants
|
||||
import core.api.log
|
||||
import core.tools.SystemLogger
|
||||
import core.game.world.GameWorld
|
||||
import core.game.world.repository.Repository
|
||||
import core.tools.Log
|
||||
import java.io.*
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
class GroundSpawnLoader {
|
||||
val parser = JSONParser()
|
||||
|
|
@ -65,17 +63,6 @@ class GroundSpawnLoader {
|
|||
return "GroundSpawn [name=" + getName() + ", respawnRate=" + respawnRate + ", loc=" + getLocation() + "]"
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to save this ground item to a byte buffer.
|
||||
* @param buffer the buffer.
|
||||
*/
|
||||
fun save(buffer: ByteBuffer) {
|
||||
buffer.putInt(respawnRate)
|
||||
buffer.putShort(id.toShort())
|
||||
buffer.putInt(amount)
|
||||
buffer.putShort((getLocation().x and 0xFFFF).toShort()).putShort((getLocation().y and 0xFFFF).toShort()).put(getLocation().z.toByte())
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to initialize this spawn.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue