From e6149f5bf0ef0d25ebdcc5250cec8ee38e2f9701 Mon Sep 17 00:00:00 2001 From: Ziggy Date: Fri, 28 Jul 2023 18:32:18 +0200 Subject: [PATCH] Grant draft schematics from skills --- .../objects/swg/player/PlayerObject.kt | 4 ++ .../objects/swg/player/PlayerObjectOwnerNP.kt | 12 +++- .../player/experience/skills/SkillService.kt | 56 ++++++++++++++++++- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/projectswg/holocore/resources/support/objects/swg/player/PlayerObject.kt b/src/main/java/com/projectswg/holocore/resources/support/objects/swg/player/PlayerObject.kt index 013dc19ca..3e6e0abaa 100644 --- a/src/main/java/com/projectswg/holocore/resources/support/objects/swg/player/PlayerObject.kt +++ b/src/main/java/com/projectswg/holocore/resources/support/objects/swg/player/PlayerObject.kt @@ -270,6 +270,10 @@ class PlayerObject(objectId: Long) : IntangibleObject(objectId, BaselineType.PLA fun setDraftSchematic(serverCrc: Int, clientCrc: Int, counter: Int) { play9.setDraftSchematic(serverCrc, clientCrc, counter) } + + fun revokeDraftSchematic(serverCrc: Int, clientCrc: Int) { + play9.revokeDraftSchematic(serverCrc, clientCrc) + } var craftingComponentBioLink by play9::craftingComponentBioLink var experimentPoints by play9::experimentPoints diff --git a/src/main/java/com/projectswg/holocore/resources/support/objects/swg/player/PlayerObjectOwnerNP.kt b/src/main/java/com/projectswg/holocore/resources/support/objects/swg/player/PlayerObjectOwnerNP.kt index 679c2e84d..6414f2777 100644 --- a/src/main/java/com/projectswg/holocore/resources/support/objects/swg/player/PlayerObjectOwnerNP.kt +++ b/src/main/java/com/projectswg/holocore/resources/support/objects/swg/player/PlayerObjectOwnerNP.kt @@ -70,10 +70,20 @@ internal class PlayerObjectOwnerNP(private val obj: PlayerObject) : MongoPersist } fun setDraftSchematic(serverCrc: Int, clientCrc: Int, counter: Int) { - val combinedCrc = serverCrc.toLong() shl 32 and -0x100000000L or (clientCrc.toLong() and 0x00000000FFFFFFFFL) + val combinedCrc = combinedCrc(serverCrc, clientCrc) draftSchematics[combinedCrc] = counter draftSchematics.sendDeltaMessage(obj) } + + fun revokeDraftSchematic(serverCrc: Int, clientCrc: Int) { + val combinedCrc = combinedCrc(serverCrc, clientCrc) + draftSchematics.remove(combinedCrc) + draftSchematics.sendDeltaMessage(obj) + } + + private fun combinedCrc(serverCrc: Int, clientCrc: Int): Long { + return serverCrc.toLong() shl 32 and -0x100000000L or (clientCrc.toLong() and 0x00000000FFFFFFFFL) + } fun getFriendsList(): List { return Collections.unmodifiableList(friendsList) diff --git a/src/main/java/com/projectswg/holocore/services/gameplay/player/experience/skills/SkillService.kt b/src/main/java/com/projectswg/holocore/services/gameplay/player/experience/skills/SkillService.kt index e2101eb17..7bb19345e 100644 --- a/src/main/java/com/projectswg/holocore/services/gameplay/player/experience/skills/SkillService.kt +++ b/src/main/java/com/projectswg/holocore/services/gameplay/player/experience/skills/SkillService.kt @@ -26,6 +26,8 @@ ***********************************************************************************/ package com.projectswg.holocore.services.gameplay.player.experience.skills +import com.projectswg.common.data.CRC +import com.projectswg.common.data.swgfile.ClientFactory import com.projectswg.holocore.intents.gameplay.player.badge.GrantBadgeIntent import com.projectswg.holocore.intents.gameplay.player.badge.SetTitleIntent import com.projectswg.holocore.intents.gameplay.player.experience.skills.GrantSkillIntent @@ -34,6 +36,7 @@ import com.projectswg.holocore.intents.gameplay.player.experience.skills.Surrend import com.projectswg.holocore.resources.support.data.server_info.StandardLog import com.projectswg.holocore.resources.support.data.server_info.loader.DataLoader.Companion.badges import com.projectswg.holocore.resources.support.data.server_info.loader.DataLoader.Companion.skills +import com.projectswg.holocore.resources.support.data.server_info.loader.ServerData.schematicGroups import com.projectswg.holocore.resources.support.data.server_info.loader.SkillLoader.SkillInfo import com.projectswg.holocore.resources.support.objects.swg.creature.CreatureObject import com.projectswg.holocore.services.gameplay.player.experience.* @@ -178,7 +181,10 @@ class SkillService : Service() { target.removeSkill(surrenderedSkill) target.removeCommands(*skillInfo.commands) skillInfo.skillMods.forEach { (skillModName: String, skillModValue: Int) -> SkillModIntent(skillModName, 0, -skillModValue, target).broadcast() } - + val schematicGroups = skillInfo.schematicsGranted + for (schematicGroup in schematicGroups) { + revokeSchematicGroup(target, schematicGroup) + } val newCombatLevel = getCombatLevel(target) val levelChanged = oldCombatLevel != newCombatLevel @@ -248,9 +254,57 @@ class SkillService : Service() { target.addCommand(*skill.commands) skill.skillMods.forEach { (skillModName, skillModValue) -> SkillModIntent(skillModName, skillModValue, 0, target).broadcast() } + + val schematicGroups = skill.schematicsGranted + for (schematicGroup in schematicGroups) { + grantSchematicGroup(target, schematicGroup) + } + GrantSkillIntent(GrantSkillIntent.IntentType.GIVEN, skill.name, target, false).broadcast() } + private fun grantSchematicGroup(target: CreatureObject, schematicGroup: String) { + val schematicGroupLoader = schematicGroups + val schematicsInGroup = schematicGroupLoader.getSchematicsInGroup(schematicGroup) + + for (schematicInGroup in schematicsInGroup) { + grantSchematic(target, schematicInGroup) + } + } + + private fun grantSchematic(target: CreatureObject, schematicInGroup: String) { + val schematicInGroupShared = ClientFactory.formatToSharedFile(schematicInGroup) + val serverCrc = getDraftSchematicServerCrc(schematicInGroupShared) + val clientCrc = getDraftSchematicClientCrc(schematicInGroupShared) + target.playerObject.setDraftSchematic(serverCrc, clientCrc, 1) + } + + private fun revokeSchematicGroup(target: CreatureObject, schematicGroup: String) { + val schematicGroupLoader = schematicGroups + val schematicsInGroup = schematicGroupLoader.getSchematicsInGroup(schematicGroup) + + for (schematicInGroup in schematicsInGroup) { + revokeSchematic(target, schematicInGroup) + } + } + + private fun revokeSchematic(target: CreatureObject, schematicInGroup: String) { + val schematicInGroupShared = ClientFactory.formatToSharedFile(schematicInGroup) + val serverCrc = getDraftSchematicServerCrc(schematicInGroupShared) + val clientCrc = getDraftSchematicClientCrc(schematicInGroupShared) + target.playerObject.revokeDraftSchematic(serverCrc, clientCrc) + } + + private fun getDraftSchematicServerCrc(schematicInGroupShared: String): Int { + return CRC.getCrc(schematicInGroupShared) + } + + private fun getDraftSchematicClientCrc(schematicInGroupShared: String): Int { + val templateWithoutPrefix = schematicInGroupShared.replace("object/draft_schematic/", "") + return CRC.getCrc(templateWithoutPrefix) + } + + private fun skillPointsSpent(creature: CreatureObject): Int { return creature.skills .mapNotNull { skills().getSkillByName(it) }