Merge pull request #1259 from Josh-Larson/convert-objects-to-kotlin

Convert SWG Objects to kotlin (part 2)
This commit is contained in:
Josh
2023-05-28 18:22:36 -05:00
committed by GitHub
14 changed files with 412 additions and 387 deletions
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
@@ -24,36 +24,30 @@
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.gameplay.player;
package com.projectswg.holocore.resources.gameplay.player
import com.projectswg.common.data.encodables.tangible.Posture;
import com.projectswg.holocore.resources.support.global.player.Player;
import com.projectswg.holocore.resources.support.global.player.PlayerFlags;
import com.projectswg.holocore.resources.support.objects.swg.SWGObject;
import com.projectswg.holocore.resources.support.objects.swg.cell.CellObject;
import com.projectswg.holocore.resources.support.objects.swg.creature.CreatureObject;
import com.projectswg.holocore.resources.support.objects.swg.player.PlayerObject;
import com.projectswg.common.data.encodables.tangible.Posture
import com.projectswg.holocore.resources.support.global.player.Player
import com.projectswg.holocore.resources.support.global.player.PlayerFlags
import com.projectswg.holocore.resources.support.objects.swg.cell.CellObject
import java.util.function.Predicate
import java.util.function.Predicate;
class ActivePlayerPredicate : Predicate<Player> {
override fun test(player: Player): Boolean {
val creatureObject = player.creatureObject
val playerObject = creatureObject.playerObject
public class ActivePlayerPredicate implements Predicate<Player> {
@Override
public boolean test(Player player) {
CreatureObject creatureObject = player.getCreatureObject();
PlayerObject playerObject = creatureObject.getPlayerObject();
boolean afk = playerObject.isFlagSet(PlayerFlags.AFK);
boolean offline = playerObject.isFlagSet(PlayerFlags.LD);
boolean incapacitated = creatureObject.getPosture() == Posture.INCAPACITATED;
boolean dead = creatureObject.getPosture() == Posture.DEAD;
boolean cloaked = !creatureObject.isVisible();
boolean privateCell = false; // Player might be inside a private building
SWGObject parent = creatureObject.getParent();
if (parent instanceof CellObject) {
privateCell = !((CellObject) parent).isPublic();
val afk = playerObject.flags[PlayerFlags.AFK]
val offline = playerObject.flags[PlayerFlags.LD]
val incapacitated = creatureObject.posture == Posture.INCAPACITATED
val dead = creatureObject.posture == Posture.DEAD
val cloaked = !creatureObject.isVisible
var privateCell = false // Player might be inside a private building
val parent = creatureObject.parent
if (parent is CellObject) {
privateCell = !parent.isPublic
}
return !afk && !offline && !incapacitated && !dead && !cloaked && !privateCell;
return !afk && !offline && !incapacitated && !dead && !cloaked && !privateCell
}
}
}
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
@@ -24,65 +24,69 @@
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.support.data.collections;
package com.projectswg.holocore.resources.support.data.collections
import com.projectswg.common.encoding.Encodable;
import com.projectswg.common.network.NetBuffer;
import com.projectswg.holocore.resources.support.objects.swg.SWGObject;
import com.projectswg.common.encoding.Encodable
import com.projectswg.common.network.NetBuffer
import com.projectswg.holocore.resources.support.objects.swg.SWGObject
import java.util.BitSet
import java.util.BitSet;
class SWGBitSet(private var view: Int, private var updateType: Int) : BitSet(128), Encodable {
public class SWGBitSet extends BitSet implements Encodable {
private static final long serialVersionUID = 1L;
private int view;
private int updateType;
public SWGBitSet() {
super(128);
fun wrapper(obj: SWGObject): SWGBitSetWrapper {
return SWGBitSetWrapper(obj)
}
public SWGBitSet(int view, int updateType) {
super(128); // Seems to be the default size for the bitmask sets in SWGPackets
this.view = view;
this.updateType = updateType;
}
@Override
public byte[] encode() {
byte[] bytes = toByteArray();
NetBuffer buffer = NetBuffer.allocate(8 + bytes.length);
buffer.addInt(bytes.length);
buffer.addInt(super.length());
buffer.addRawArray(bytes);
return buffer.array();
}
@Override
public void decode(NetBuffer data) {
int len = data.getInt();
data.getInt();
byte [] bytes = data.getArray(len);
clear();
or(BitSet.valueOf(bytes));
}
@Override
public int getLength() {
return 8 + (super.length()+7) / 8;
}
public void read(byte[] bytes) {
clear();
override fun encode(): ByteArray {
val bytes = toByteArray()
val buffer = NetBuffer.allocate(8 + bytes.size)
buffer.addInt(bytes.size)
buffer.addInt(super.length())
buffer.addRawArray(bytes)
return buffer.array()
}
override fun decode(data: NetBuffer) {
val len = data.int
data.int
val bytes = data.getArray(len)
clear()
or(valueOf(bytes))
}
override val length: Int
get() = 8 + (super.length() + 7) / 8
fun read(bytes: ByteArray?) {
clear()
if (bytes != null) {
xor(valueOf(bytes));
xor(valueOf(bytes))
}
}
public void sendDeltaMessage(SWGObject target) {
target.sendDelta(view, updateType, encode());
fun sendDeltaMessage(target: SWGObject) {
target.sendDelta(view, updateType, encode())
}
}
inner class SWGBitSetWrapper(private val obj: SWGObject) {
val flags: BitSet
get() = this@SWGBitSet.clone() as BitSet
fun get(): BitSet {
return this@SWGBitSet.clone() as BitSet
}
fun add(flags: BitSet) {
this@SWGBitSet.or(flags)
this@SWGBitSet.sendDeltaMessage(obj)
}
fun set(flags: BitSet) {
this@SWGBitSet.clear()
this@SWGBitSet.or(flags)
this@SWGBitSet.sendDeltaMessage(obj)
}
}
}
@@ -1,106 +0,0 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.support.data.collections;
import com.projectswg.common.encoding.Encodable;
import com.projectswg.common.network.NetBuffer;
import com.projectswg.holocore.resources.support.objects.swg.SWGObject;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.BitSet;
public class SWGFlag extends BitSet implements Encodable {
private final int view;
private final int updateType;
/**
* Creates a new {@link SWGFlag} for the defined baseline with the given view and update. Note
* that this is an extension of {@link BitSet}
*
* @param view The baseline number this BitSet resides in
* @param updateType The update variable used for sending a delta, it's the operand count that
* this BitSet resides at within the baseline
*/
public SWGFlag(int view, int updateType) {
super(128); // Seems to be the default size for the bitmask sets in SWGPackets
this.view = view;
this.updateType = updateType;
}
@Override
public byte @NotNull [] encode() {
byte [] encoded = toByteArray();
int resultingInts = (encoded.length + 3) / 4; // rounds up
NetBuffer buffer = NetBuffer.allocate(4 + resultingInts * 4);
buffer.addInt(resultingInts);
buffer.addRawArray(encoded);
return buffer.array();
}
@Override
public void decode(NetBuffer data) {
int len = data.getInt();
byte [] encoded = data.getArray(len * 4);
clear();
xor(BitSet.valueOf(encoded));
}
@Override
public int getLength() {
return 4 + (int) Math.ceil(super.size()/32.0);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof SWGFlag))
return super.equals(o);
return Arrays.equals(toList(), ((SWGFlag) o).toList());
}
@Override
public int hashCode() {
return Arrays.hashCode(toList());
}
public void sendDeltaMessage(SWGObject target) {
target.sendDelta(view, updateType, encode());
}
public int[] toList() {
int[] integers = new int[(int) Math.ceil(size()/32.0)];
for (int i = nextSetBit(0); i >= 0; i = nextSetBit(i+1)) {
integers[i / 32] |= (1 << (i % 32));
}
return integers;
}
}
@@ -0,0 +1,133 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.support.data.collections
import com.projectswg.common.encoding.Encodable
import com.projectswg.common.network.NetBuffer
import com.projectswg.holocore.resources.support.objects.swg.SWGObject
import java.util.*
import kotlin.math.ceil
/**
* Creates a new [SWGFlag] for the defined baseline with the given view and update. Note
* that this is an extension of [BitSet]
*
* @param view The baseline number this BitSet resides in
* @param updateType The update variable used for sending a delta, it's the operand count that
* this BitSet resides at within the baseline
*/
class SWGFlag(private val view: Int, private val updateType: Int) : BitSet(128), Encodable {
fun wrapper(obj: SWGObject): SWGFlagWrapper<Int> {
return wrapper(obj) { it }
}
fun <T> wrapper(obj: SWGObject, converter: (T) -> Int): SWGFlagWrapper<T> {
return SWGFlagWrapper(obj, converter)
}
override fun encode(): ByteArray {
val encoded = toByteArray()
val resultingInts = (encoded.size + 3) / 4 // rounds up
val buffer = NetBuffer.allocate(4 + resultingInts * 4)
buffer.addInt(resultingInts)
buffer.addRawArray(encoded)
return buffer.array()
}
override fun decode(data: NetBuffer) {
val len = data.int
val encoded = data.getArray(len * 4)
clear()
xor(valueOf(encoded))
}
override val length: Int
get() = 4 + ceil(super.size() / 32.0).toInt()
override fun equals(other: Any?): Boolean {
return if (other !is SWGFlag) super.equals(other) else toList().contentEquals(other.toList())
}
override fun hashCode(): Int {
return toList().contentHashCode()
}
fun sendDeltaMessage(target: SWGObject) {
target.sendDelta(view, updateType, encode())
}
fun toList(): IntArray {
val integers = IntArray(ceil(size() / 32.0).toInt())
var i = nextSetBit(0)
while (i >= 0) {
integers[i / 32] = integers[i / 32] or (1 shl i % 32)
i = nextSetBit(i + 1)
}
return integers
}
inner class SWGFlagWrapper<T>(private val obj: SWGObject, private val converter: (T) -> Int) {
val flags: BitSet
get() = this@SWGFlag.clone() as BitSet
operator fun get(flag: T): Boolean {
return this@SWGFlag[converter(flag)]
}
fun set(flag: T) {
this@SWGFlag.set(converter(flag))
this@SWGFlag.sendDeltaMessage(obj)
}
fun clear(flag: T) {
this@SWGFlag.clear(converter(flag))
this@SWGFlag.sendDeltaMessage(obj)
}
fun toggle(flag: T) {
this@SWGFlag.flip(converter(flag))
this@SWGFlag.sendDeltaMessage(obj)
}
fun set(flags: BitSet) {
this@SWGFlag.or(flags)
this@SWGFlag.sendDeltaMessage(obj)
}
fun clear(flags: BitSet) {
this@SWGFlag.andNot(flags)
this@SWGFlag.sendDeltaMessage(obj)
}
fun toggle(flags: BitSet) {
this@SWGFlag.xor(flags)
this@SWGFlag.sendDeltaMessage(obj)
}
}
}
@@ -1,3 +1,30 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.support.global.commands.callbacks.flags;
import com.projectswg.holocore.resources.support.global.commands.ICmdCallback;
@@ -10,7 +37,7 @@ public final class CmdToggleAwayFromKeyboard implements ICmdCallback {
@Override
public void execute(@NotNull Player player, SWGObject target, @NotNull String args) {
player.getPlayerObject().toggleFlag(PlayerFlags.AFK);
player.getPlayerObject().getFlags().toggle(PlayerFlags.AFK);
}
}
@@ -1,3 +1,29 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.support.global.commands.callbacks.flags;
import com.projectswg.holocore.resources.support.global.commands.ICmdCallback;
@@ -10,7 +36,7 @@ public final class CmdToggleDisplayingFactionRank implements ICmdCallback {
@Override
public void execute(@NotNull Player player, SWGObject target, @NotNull String args) {
player.getPlayerObject().toggleFlag(PlayerFlags.FACTIONRANK);
player.getPlayerObject().getFlags().toggle(PlayerFlags.FACTIONRANK);
}
}
@@ -1,3 +1,30 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.support.global.commands.callbacks.flags;
import com.projectswg.holocore.resources.support.global.commands.ICmdCallback;
@@ -10,7 +37,7 @@ public final class CmdToggleHelper implements ICmdCallback {
@Override
public void execute(@NotNull Player player, SWGObject target, @NotNull String args) {
player.getPlayerObject().toggleFlag(PlayerFlags.HELPER);
player.getPlayerObject().getFlags().toggle(PlayerFlags.HELPER);
}
}
@@ -1,3 +1,30 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.support.global.commands.callbacks.flags;
import com.projectswg.holocore.resources.support.global.commands.ICmdCallback;
@@ -10,7 +37,7 @@ public final class CmdToggleLookingForGroup implements ICmdCallback {
@Override
public void execute(@NotNull Player player, SWGObject target, @NotNull String args) {
player.getPlayerObject().toggleFlag(PlayerFlags.LFG);
player.getPlayerObject().getFlags().toggle(PlayerFlags.LFG);
}
}
@@ -1,3 +1,30 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.support.global.commands.callbacks.flags;
import com.projectswg.holocore.resources.support.global.commands.ICmdCallback;
@@ -10,7 +37,7 @@ public final class CmdToggleRolePlay implements ICmdCallback {
@Override
public void execute(@NotNull Player player, SWGObject target, @NotNull String args) {
player.getPlayerObject().toggleFlag(PlayerFlags.ROLEPLAYER);
player.getPlayerObject().getFlags().toggle(PlayerFlags.ROLEPLAYER);
}
}
@@ -45,6 +45,7 @@ import java.time.ZonedDateTime
import java.time.temporal.ChronoUnit
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import kotlin.math.max
class PlayerObject(objectId: Long) : IntangibleObject(objectId, BaselineType.PLAY) {
@@ -74,7 +75,7 @@ class PlayerObject(objectId: Long) : IntangibleObject(objectId, BaselineType.PLA
fun adjustFactionPoints(faction: String, adjustment: Int): Int {
val oldValue = factionPoints.getOrDefault(faction, 0)
val value = oldValue + adjustment
val cappedValue = Math.min(Math.max(value, -5000), 5000)
val cappedValue = value.coerceAtLeast(-5000).coerceAtMost(5000)
val delta = cappedValue - oldValue
if (delta != 0) {
factionPoints[faction] = value
@@ -119,63 +120,8 @@ class PlayerObject(objectId: Long) : IntangibleObject(objectId, BaselineType.PLA
removeMail(m.id)
}
val flagsList: BitSet
get() = play3.getFlagsList()
fun setFlag(flag: PlayerFlags) {
play3.setFlag(flag.flag)
}
fun clearFlag(flag: PlayerFlags) {
play3.clearFlag(flag.flag)
}
fun toggleFlag(flag: PlayerFlags) {
play3.toggleFlag(flag.flag)
}
fun setFlags(flags: Set<PlayerFlags>) {
play3.setFlags(PlayerFlags.bitsetFromFlags(flags))
}
fun clearFlags(flags: Set<PlayerFlags>) {
play3.clearFlags(PlayerFlags.bitsetFromFlags(flags))
}
fun toggleFlags(flags: Set<PlayerFlags>) {
play3.toggleFlags(PlayerFlags.bitsetFromFlags(flags))
}
fun isFlagSet(flag: PlayerFlags): Boolean {
return play3.isFlagSet(flag.flag)
}
val profileFlags: BitSet
get() = play3.getProfileFlags()
fun setProfileFlag(flag: PlayerFlags) {
play3.setProfileFlag(flag.flag)
}
fun clearProfileFlag(flag: PlayerFlags) {
play3.clearProfileFlag(flag.flag)
}
fun toggleProfileFlag(flag: PlayerFlags) {
play3.toggleProfileFlag(flag.flag)
}
fun setProfileFlags(flags: Set<PlayerFlags>) {
play3.setProfileFlags(PlayerFlags.bitsetFromFlags(flags))
}
fun clearProfileFlags(flags: Set<PlayerFlags>) {
play3.clearProfileFlags(PlayerFlags.bitsetFromFlags(flags))
}
fun toggleProfileFlags(flags: Set<PlayerFlags>) {
play3.toggleProfileFlags(PlayerFlags.bitsetFromFlags(flags))
}
val flags by play3::flags
val profileFlags by play3::profileFlags
var title by play3::title
val playTime by play3::playTime
@@ -250,27 +196,11 @@ class PlayerObject(objectId: Long) : IntangibleObject(objectId, BaselineType.PLA
get() = play8.getWaypoints()
var forcePower by play8::forcePower
var maxForcePower by play8::maxForcePower
var completedQuests: BitSet
get() = play8.getCompletedQuests()
set(completedQuests) {
play8.setCompletedQuests(completedQuests)
}
fun addCompletedQuests(completedQuests: BitSet) {
play8.addCompletedQuests(completedQuests)
}
var activeQuests: BitSet
get() = play8.getActiveQuests()
set(activeQuests) {
play8.setActiveQuests(activeQuests)
}
fun addActiveQuests(activeQuests: BitSet) {
play8.addActiveQuests(activeQuests)
}
val completedQuests by play8::completedQuests
val activeQuests by play8::activeQuests
var activeQuest by play8::activeQuest
val quests: Map<CRC, Quest>
get() = play8.getQuests()
@@ -46,8 +46,10 @@ import java.util.stream.Collectors
internal class PlayerObjectOwner(private val obj: PlayerObject) : MongoPersistable {
private val experience = SWGMap<String, Int>(8, 0, StringType.ASCII)
private val waypoints = SWGMap<Long, WaypointObject>(8, 1)
private val completedQuests = SWGBitSet(8, 4)
private val activeQuests = SWGBitSet(8, 5)
private val _completedQuests = SWGBitSet(8, 4)
val completedQuests = _completedQuests.wrapper(obj)
private val _activeQuests = SWGBitSet(8, 5)
val activeQuests = _activeQuests.wrapper(obj)
private val quests = SWGMap<CRC, Quest>(8, 7)
var forcePower by IndirectBaselineDelegate(obj = obj, value = 100, page = 8, update = 2)
@@ -102,32 +104,6 @@ internal class PlayerObjectOwner(private val obj: PlayerObject) : MongoPersistab
synchronized(waypoints) { if (waypoints.remove(objId) != null) waypoints.sendDeltaMessage(obj) }
}
fun getCompletedQuests(): BitSet {
return completedQuests.clone() as BitSet
}
fun addCompletedQuests(completedQuests: BitSet) {
this.completedQuests.or(completedQuests)
}
fun setCompletedQuests(completedQuests: BitSet) {
this.completedQuests.clear()
this.completedQuests.or(completedQuests)
}
fun getActiveQuests(): BitSet {
return activeQuests.clone() as BitSet
}
fun addActiveQuests(activeQuests: BitSet) {
this.activeQuests.or(activeQuests)
}
fun setActiveQuests(activeQuests: BitSet) {
this.activeQuests.clear()
this.activeQuests.or(activeQuests)
}
fun getQuests(): Map<CRC, Quest> {
return Collections.unmodifiableMap(quests)
}
@@ -137,8 +113,8 @@ internal class PlayerObjectOwner(private val obj: PlayerObject) : MongoPersistab
bb.addObject(waypoints) // 1
bb.addInt(forcePower) // 2
bb.addInt(maxForcePower) // 3
bb.addObject(completedQuests) // 4
bb.addObject(activeQuests) // 5
bb.addObject(_completedQuests) // 4
bb.addObject(_activeQuests) // 5
bb.addInt(activeQuest) // 6
bb.addObject(quests) // 7
bb.incrementOperandCount(8)
@@ -149,8 +125,8 @@ internal class PlayerObjectOwner(private val obj: PlayerObject) : MongoPersistab
data.putArray("waypoints", waypoints.values.stream().map { obj: WaypointObject -> obj.oob }.collect(Collectors.toList()))
data.putInteger("forcePower", forcePower)
data.putInteger("maxForcePower", maxForcePower)
data.putByteArray("completedQuests", completedQuests.toByteArray())
data.putByteArray("activeQuests", activeQuests.toByteArray())
data.putByteArray("completedQuests", _completedQuests.toByteArray())
data.putByteArray("activeQuests", _activeQuests.toByteArray())
data.putInteger("activeQuest", activeQuest)
data.putMap("quests", quests)
}
@@ -164,8 +140,8 @@ internal class PlayerObjectOwner(private val obj: PlayerObject) : MongoPersistab
.forEach(Consumer { obj: WaypointObject -> waypoints[obj.objectId] = obj })
forcePower = data.getInteger("forcePower", forcePower)
maxForcePower = data.getInteger("maxForcePower", maxForcePower)
completedQuests.read(data.getByteArray("completedQuests"))
activeQuests.read(data.getByteArray("activeQuests"))
_completedQuests.read(data.getByteArray("completedQuests"))
_activeQuests.read(data.getByteArray("activeQuests"))
activeQuest = data.getInteger("activeQuest", activeQuest)
quests.putAll(data.getMap("quests", CRC::class.java, Quest::class.java))
}
@@ -32,7 +32,9 @@ import com.projectswg.common.encoding.StringType
import com.projectswg.common.network.NetBuffer
import com.projectswg.holocore.resources.support.data.collections.SWGFlag
import com.projectswg.holocore.resources.support.global.network.BaselineBuilder
import com.projectswg.holocore.resources.support.global.player.PlayerFlags
import com.projectswg.holocore.resources.support.objects.swg.IndirectBaselineDelegate
import com.projectswg.holocore.resources.support.objects.swg.SWGObject
import com.projectswg.holocore.utilities.MathUtils
import java.util.*
@@ -41,86 +43,17 @@ import java.util.*
*/
internal class PlayerObjectShared(private val obj: PlayerObject) : MongoPersistable {
private val flagsList = SWGFlag(3, 5)
private val profileFlags = SWGFlag(3, 6)
private val _flags = SWGFlag(3, 5)
val flags = _flags.wrapper(obj) { it: PlayerFlags -> it.flag }
private val _profileFlags = SWGFlag(3, 6)
val profileFlags = _profileFlags.wrapper(obj) { it: PlayerFlags -> it.flag }
var title by IndirectBaselineDelegate(obj = obj, value = "", page = 3, update = 7, stringType = StringType.ASCII)
var bornDate by IndirectBaselineDelegate(obj = obj, value = 0, page = 3, update = 8)
var playTime by IndirectBaselineDelegate(obj = obj, value = 0, page = 3, update = 9)
var professionIcon by IndirectBaselineDelegate(obj = obj, value = 0, page = 3, update = 10)
fun getFlagsList(): BitSet {
return flagsList.clone() as BitSet
}
fun setFlag(flag: Int) {
flagsList.set(flag)
flagsList.sendDeltaMessage(obj)
}
fun clearFlag(flag: Int) {
flagsList.clear(flag)
flagsList.sendDeltaMessage(obj)
}
fun toggleFlag(flag: Int) {
flagsList.flip(flag)
flagsList.sendDeltaMessage(obj)
}
fun setFlags(flags: BitSet) {
flagsList.or(flags)
flagsList.sendDeltaMessage(obj)
}
fun clearFlags(flags: BitSet) {
flagsList.andNot(flags)
flagsList.sendDeltaMessage(obj)
}
fun toggleFlags(flags: BitSet) {
flagsList.xor(flags)
flagsList.sendDeltaMessage(obj)
}
fun isFlagSet(flag: Int): Boolean {
return flagsList[flag]
}
fun getProfileFlags(): BitSet {
return profileFlags.clone() as BitSet
}
fun setProfileFlag(flag: Int) {
profileFlags.set(flag)
profileFlags.sendDeltaMessage(obj)
}
fun clearProfileFlag(flag: Int) {
profileFlags.clear(flag)
profileFlags.sendDeltaMessage(obj)
}
fun toggleProfileFlag(flag: Int) {
profileFlags.flip(flag)
profileFlags.sendDeltaMessage(obj)
}
fun setProfileFlags(flags: BitSet) {
profileFlags.or(flags)
profileFlags.sendDeltaMessage(obj)
}
fun clearProfileFlags(flags: BitSet) {
profileFlags.andNot(flags)
profileFlags.sendDeltaMessage(obj)
}
fun toggleProfileFlags(flags: BitSet) {
profileFlags.xor(flags)
profileFlags.sendDeltaMessage(obj)
}
fun incrementPlayTime(playTime: Int) {
this.playTime += playTime
}
@@ -130,8 +63,8 @@ internal class PlayerObjectShared(private val obj: PlayerObject) : MongoPersista
}
fun createBaseline3(bb: BaselineBuilder) {
bb.addObject(flagsList) // 5
bb.addObject(profileFlags) // 6
bb.addObject(_flags) // 5
bb.addObject(_profileFlags) // 6
bb.addAscii(title) // 7
bb.addInt(bornDate) // 8
bb.addInt(playTime) // 9
@@ -140,8 +73,8 @@ internal class PlayerObjectShared(private val obj: PlayerObject) : MongoPersista
}
fun parseBaseline3(buffer: NetBuffer) {
flagsList.decode(buffer) // 5
profileFlags.decode(buffer) // 6
_flags.decode(buffer) // 5
_profileFlags.decode(buffer) // 6
title = buffer.ascii // 7
bornDate = buffer.int // 8
playTime = buffer.int // 9
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
@@ -127,14 +127,14 @@ public class ConnectionService extends Service {
PlayerObject player = p.getPlayerObject();
if (player == null)
return;
player.setFlag(PlayerFlags.LD);
player.getFlags().set(PlayerFlags.LD);
}
private void clearPlayerFlag(Player p) {
PlayerObject player = p.getPlayerObject();
if (player == null)
return;
player.clearFlag(PlayerFlags.LD);
player.getFlags().clear(PlayerFlags.LD);
}
private void zoneIn(Player p) {
@@ -1,3 +1,30 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.gameplay.player;
import com.projectswg.common.data.encodables.tangible.Posture;
@@ -35,7 +62,7 @@ public class TestActivePlayerPredicate {
@Test
public void testAfk() {
playerObject.setFlag(PlayerFlags.AFK);
playerObject.getFlags().set(PlayerFlags.AFK);
boolean actual = predicate.test(player);
@@ -44,7 +71,7 @@ public class TestActivePlayerPredicate {
@Test
public void testOffline() {
playerObject.setFlag(PlayerFlags.LD);
playerObject.getFlags().set(PlayerFlags.LD);
boolean actual = predicate.test(player);