Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Undercova/Holocore
Browse files Browse the repository at this point in the history
  • Loading branch information
Undercova committed May 5, 2024
2 parents 25095f5 + e2f09b1 commit 919dcce
Show file tree
Hide file tree
Showing 14 changed files with 1,776 additions and 168 deletions.
1,653 changes: 1,653 additions & 0 deletions serverdata/crafting/schematic_group.sdb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2024 /// 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. *
Expand Down Expand Up @@ -51,8 +51,6 @@ public SWGNameGenerator() {

@NotNull
public String generateRaceName(@NotNull Race race) {
if (!nameFilter.isLoaded())
nameFilter.load();
return generateName("race_" + race.getSpecies());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2024 /// 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. *
Expand All @@ -24,21 +24,46 @@
* 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.utilities;

public class MathUtils {

// http://en.wikipedia.org/wiki/Julian_day#Converting_Julian_or_Gregorian_calendar_date_to_Julian_Day_Number
public static int julianDay(int year, int month, int day) {
int a = (14 - month) / 12;
int y = year + 4800 - a;
int m = month + 12 * a - 3;
return day + Math.floorDiv(153 * m + 2, 5) + (365 * y) + Math.floorDiv(y, 4) - Math.floorDiv(y, 100) + Math.floorDiv(y, 400) - 32045;
package com.projectswg.holocore.resources.support.data.server_info.loader

import com.projectswg.holocore.resources.support.data.server_info.SdbLoader
import java.io.File

class SchematicGroupLoader : DataLoader() {

private val schematicGroupMap = mutableMapOf<String, MutableCollection<String>>()

/**
* Returns a collection of all schematic names in the given group
* Example: getSchematicsInGroup("craftDroidDamageRepairA") returns a collection of ["object/draft_schematic/droid/droid_damage_repair_kit_a.iff"]
*/
fun getSchematicsInGroup(groupId: String): Collection<String> {
return schematicGroupMap.getOrElse(groupId) { emptyList() }
}

override fun load() {
val set = SdbLoader.load(File("serverdata/crafting/schematic_group.sdb"))

set.use {
while (set.next()) {
val groupid = set.getText("groupid")
val schematicname = set.getText("schematicname")

if (groupid != "end") {
ensureSchematicGroupExists(groupid)
appendSchematicToGroup(groupid, schematicname)
}
}
}
}

// Used for calculating born dates
public static int numberDaysSince(int y1, int m1, int d1, int y2, int m2, int d2) {
return julianDay(y1, m1, d1) - julianDay(y2, m2, d2);

private fun appendSchematicToGroup(groupid: String, schematicname: String) {
schematicGroupMap[groupid]?.add(schematicname)
}

private fun ensureSchematicGroupExists(groupid: String) {
if (!schematicGroupMap.containsKey(groupid)) {
schematicGroupMap[groupid] = mutableListOf()
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2024 /// 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. *
Expand Down Expand Up @@ -112,6 +112,7 @@ object ServerData {
val planetChatRooms by SoftDataLoaderDelegate(::PlanetChatRoomLoader)
val staticCityPoints by SoftDataLoaderDelegate(::StaticCityPointLoader)
val npcEquipment by SoftDataLoaderDelegate(::NpcEquipmentLoader)
val schematicGroups by SoftDataLoaderDelegate(::SchematicGroupLoader)

private class WeakDataLoaderDelegate<T: DataLoader>(loaderCreator: () -> T): DataLoaderDelegate<T>(::WeakReference, loaderCreator)
private class SoftDataLoaderDelegate<T: DataLoader>(loaderCreator: () -> T): DataLoaderDelegate<T>(::SoftReference, loaderCreator)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2024 /// 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. *
Expand Down Expand Up @@ -74,14 +74,12 @@ class StaticItemLoader internal constructor() : DataLoader() {

val armorInfo: ArmorItemInfo?
val consumableInfo: ConsumableItemInfo?
val costumeInfo: CostumeItemInfo?
val crystalInfo: CrystalItemInfo?
val grantInfo: GrantItemInfo?
val genericInfo: GenericItemInfo?
val itemInfo: GenericItemInfo?
val objectInfo: ObjectItemInfo?
val schematicInfo: SchematicItemInfo?
val storytellerInfo: StorytellerItemInfo?
val weaponInfo: WeaponItemInfo?
val wearableInfo: WearableItemInfo?

Expand All @@ -90,14 +88,12 @@ class StaticItemLoader internal constructor() : DataLoader() {

this.armorInfo = if ("armor" == type) ArmorItemInfo(set, colorArray) else null
this.consumableInfo = if ("consumable" == type) ConsumableItemInfo(set) else null
this.costumeInfo = if ("costume" == type) CostumeItemInfo(set) else null
this.crystalInfo = if ("crystal" == type) CrystalItemInfo(set, colorArray) else null
this.grantInfo = if ("grant" == type) GrantItemInfo(set) else null
this.genericInfo = if ("generic" == type) GenericItemInfo(set, colorArray) else null
this.itemInfo = if ("item" == type) GenericItemInfo(set, colorArray) else null
this.objectInfo = if ("object" == type) ObjectItemInfo(set, colorArray) else null
this.schematicInfo = if ("schematic" == type) SchematicItemInfo(set) else null
this.storytellerInfo = if ("storyteller" == type) StorytellerItemInfo(set) else null
this.weaponInfo = if ("weapon" == type) WeaponItemInfo(set) else null
this.wearableInfo = if ("wearable" == type) WearableItemInfo(set, colorArray) else null
}
Expand Down Expand Up @@ -148,12 +144,6 @@ class StaticItemLoader internal constructor() : DataLoader() {

}

class CostumeItemInfo(set: SdbResultSet) {

val buffName: String = set.getText("buff_name")

}

class CrystalItemInfo(set: SdbResultSet, colorArray: SdbIntegerColumnArraySet) {
val color: IntArray = Arrays.copyOfRange(colorArray.getArray(set), 0, 5)
get() = field.clone()
Expand Down Expand Up @@ -208,9 +198,6 @@ class StaticItemLoader internal constructor() : DataLoader() {

}

@Suppress("UNUSED_PARAMETER")
class StorytellerItemInfo(set: SdbResultSet)

class WeaponItemInfo(set: SdbResultSet) {

val minDamage: Int = set.getInt("min_damage").toInt()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2024 /// 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. *
Expand Down Expand Up @@ -27,12 +27,10 @@
package com.projectswg.holocore.resources.support.global.player;

import com.projectswg.common.network.packets.SWGPacket;
import com.projectswg.holocore.ProjectSWG;
import com.projectswg.holocore.intents.support.global.network.OutboundPacketIntent;
import com.projectswg.holocore.resources.support.objects.swg.SWGObject;
import com.projectswg.holocore.resources.support.objects.swg.creature.CreatureObject;
import com.projectswg.holocore.resources.support.objects.swg.player.PlayerObject;
import me.joshlarson.jlcommon.control.Intent;
import me.joshlarson.jlcommon.control.IntentChain;
import org.jetbrains.annotations.NotNull;

Expand All @@ -44,7 +42,6 @@
public class Player implements Comparable<Player> {

private final long networkId;
private final IntentChain intentChain;
private final AtomicReference<CreatureObject> creatureObject;
private final AtomicReference<InetSocketAddress> address;
private final Consumer<SWGPacket> packetSender;
Expand All @@ -59,7 +56,6 @@ public class Player implements Comparable<Player> {
public Player(long networkId, InetSocketAddress address, Consumer<SWGPacket> packetSender) {
this.networkId = networkId;
this.address = new AtomicReference<>(address);
this.intentChain = new IntentChain();
this.creatureObject = new AtomicReference<>(null);
this.packetSender = packetSender;
}
Expand Down Expand Up @@ -149,11 +145,7 @@ public String getCharacterChatName() {
public AccessLevel getAccessLevel() {
return accessLevel;
}

public String getGalaxyName() {
return ProjectSWG.INSTANCE.getGalaxy().getName();
}


public CreatureObject getCreatureObject() {
return creatureObject.get();
}
Expand All @@ -171,12 +163,7 @@ public PlayerObject getPlayerObject() {
public double getTimeSinceLastPacket() {
return (System.nanoTime()-lastInboundMessage)/1E6;
}

public boolean isBaselinesSent(SWGObject obj) {
CreatureObject creature = getCreatureObject();
return creature == null || creature.isBaselinesSent(obj);
}


public void sendPacket(SWGPacket packet) {
packetSender.accept(packet);
IntentChain.broadcastChain(new OutboundPacketIntent(this, packet));
Expand Down Expand Up @@ -230,14 +217,6 @@ public void sendPacket(SWGPacket packet1, SWGPacket packet2, SWGPacket packet3,
);
}

public void broadcast(Intent intent) {
CreatureObject creatureObject = getCreatureObject();
if (creatureObject != null)
creatureObject.broadcast(intent);
else
intentChain.broadcastAfter(intent);
}

@Override
public String toString() {
CreatureObject creatureObject = getCreatureObject();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2024 /// 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. *
Expand Down Expand Up @@ -57,14 +57,12 @@ object StaticItemCreator {
applyAttributes(obj, info.wearableInfo)
applyAttributes(obj, info.weaponInfo)
applyAttributes(obj, info.consumableInfo)
applyAttributes(obj, info.costumeInfo)
applyAttributes(obj, info.crystalInfo)
applyAttributes(obj, info.grantInfo)
applyAttributes(obj, info.genericInfo)
applyAttributes(obj, info.itemInfo)
applyAttributes(obj, info.objectInfo)
applyAttributes(obj, info.schematicInfo)
applyAttributes(obj, info.storytellerInfo)
}

private fun applyAttributes(obj: TangibleObject, info: StaticItemLoader.ArmorItemInfo?) {
Expand Down Expand Up @@ -155,12 +153,6 @@ object StaticItemCreator {

applyItemValue(info.value, obj)
}

@Suppress("UNUSED_PARAMETER")
private fun applyAttributes(obj: TangibleObject, info: StaticItemLoader.CostumeItemInfo?) {
// if (info == null)
// return;
}

private fun applyAttributes(obj: TangibleObject, info: StaticItemLoader.CrystalItemInfo?) {
if (info == null)
Expand Down Expand Up @@ -229,13 +221,7 @@ object StaticItemCreator {
// if (info == null)
// return;
}

@Suppress("UNUSED_PARAMETER")
private fun applyAttributes(obj: TangibleObject, info: StaticItemLoader.StorytellerItemInfo?) {
// if (info == null)
// return;
}


private fun applySkillMods(obj: TangibleObject, skillMods: Map<String, Int>) {
for ((key, value) in skillMods) {
obj.adjustSkillmod(key, value, 0)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2024 /// 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. *
Expand Down Expand Up @@ -35,7 +35,6 @@ import com.projectswg.common.network.packets.swg.zone.baselines.Baseline.Baselin
import com.projectswg.holocore.resources.support.global.network.BaselineBuilder
import com.projectswg.holocore.resources.support.global.player.AccessLevel
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.intangible.IntangibleObject
import com.projectswg.holocore.resources.support.objects.swg.waypoint.WaypointObject
import java.time.Instant
Expand All @@ -45,7 +44,6 @@ 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) {

Expand Down Expand Up @@ -147,10 +145,6 @@ class PlayerObject(objectId: Long) : IntangibleObject(objectId, BaselineType.PLA
play3.bornDate = BORN_DATE_START.until(LocalDate.ofInstant(time, BORN_DATE_ZONE), ChronoUnit.DAYS).toInt()
}

fun setBornDate(year: Int, month: Int, day: Int) {
play3.setBornDate(year, month, day)
}

fun setAdminTag(accessLevel: AccessLevel) {
when (accessLevel) {
AccessLevel.PLAYER -> play6.adminTag = 0.toByte()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ internal class PlayerObjectOwnerNP(private val obj: PlayerObject) : MongoPersist
bb.addInt(maxMeds) // 15
bb.addObject(groupWaypoints) // 16
bb.addInt(jediState) // 17
bb.incrementOperandCount(19)
bb.incrementOperandCount(18)
}

fun parseBaseline9(buffer: NetBuffer) {
Expand Down Expand Up @@ -223,6 +223,7 @@ internal class PlayerObjectOwnerNP(private val obj: PlayerObject) : MongoPersist
craftingStage = data.getInteger("craftingStage", craftingStage)
nearbyCraftStation = data.getLong("nearbyCraftStation", nearbyCraftStation)
draftSchematics.putAll(data.getMap("draftSchematics", Long::class.java, Int::class.java))
draftSchematics.resetUpdateCount() // If we don't do this, the client will display 0 draft schematics after a server reboot for all players
craftingComponentBioLink = data.getLong("craftingComponentBioLink", craftingComponentBioLink)
experimentPoints = data.getInteger("experimentPoints", experimentPoints)
expModified = data.getInteger("expModified", expModified)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2024 /// 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. *
Expand Down Expand Up @@ -34,9 +34,6 @@ 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.*

/**
* PLAY 3
Expand All @@ -58,10 +55,6 @@ internal class PlayerObjectShared(private val obj: PlayerObject) : MongoPersista
this.playTime += playTime
}

fun setBornDate(year: Int, month: Int, day: Int) {
bornDate = MathUtils.numberDaysSince(year, month, day, 2000, 12, 31)
}

fun createBaseline3(bb: BaselineBuilder) {
bb.addObject(_flags) // 5
bb.addObject(_profileFlags) // 6
Expand Down
Loading

0 comments on commit 919dcce

Please sign in to comment.