Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,31 @@
***********************************************************************************/
package com.projectswg.holocore.resources.support.data.server_info.loader.npc

import com.projectswg.common.data.swgfile.ClientFactory
import com.projectswg.holocore.resources.support.data.server_info.SdbLoader
import com.projectswg.holocore.resources.support.data.server_info.loader.*
import com.projectswg.holocore.resources.support.objects.swg.weapon.WeaponType
import java.io.File
import java.io.IOException
import java.util.function.Consumer

class NpcWeaponLoader : DataLoader() {
private val weapons: MutableMap<String, List<String>> = HashMap()
private val weaponTypes: MutableMap<String, WeaponType> = HashMap()

fun getWeapons(weaponId: String): List<String>? {
return weapons[weaponId]
}

/**
* Gets the type of the specified weapon. Returns `null` if no weapon with that IFF is found
* @param weaponIff the weapon IFF
* @return the type of the specified weapon, or `null` on error
*/
fun getWeaponType(weaponIff: String?): WeaponType? {
return weaponTypes[ClientFactory.formatToSharedFile(weaponIff)]
}

fun forEach(c: Consumer<List<String>>?) {
weapons.values.forEach(c)
}
Expand All @@ -47,7 +59,13 @@ class NpcWeaponLoader : DataLoader() {
override fun load() {
SdbLoader.load(File("serverdata/npc/npc_weapon.sdb")).use { set ->
while (set.next()) {
weapons[set.getText("weapon_id")] = listOf(*set.getText("weapons").split(";".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray())
val templates = set.getText("weapons").split(";".toRegex()).dropLastWhile { it.isEmpty() }
weapons[set.getText("weapon_id")] = templates

val weaponType = WeaponType.valueOf(set.getText("weapon_type"))
for (template in templates) {
weaponTypes[ClientFactory.formatToSharedFile(template)] = weaponType
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ package com.projectswg.holocore.resources.support.npc.spawn
import com.projectswg.common.data.encodables.tangible.PvpFlag
import com.projectswg.common.data.encodables.tangible.PvpStatus
import com.projectswg.common.data.location.Location
import com.projectswg.common.data.objects.GameObjectType
import com.projectswg.holocore.intents.gameplay.gcw.UpdateFactionIntent
import com.projectswg.holocore.intents.gameplay.gcw.UpdateFactionStatusIntent
import com.projectswg.holocore.intents.support.objects.ObjectCreatedIntent
import com.projectswg.holocore.resources.support.data.server_info.loader.DataLoader.Companion.npcStats
import com.projectswg.holocore.resources.support.data.server_info.loader.DataLoader.Companion.npcWeaponRanges
import com.projectswg.holocore.resources.support.data.server_info.loader.DataLoader.Companion.npcWeapons
import com.projectswg.holocore.resources.support.data.server_info.loader.DataLoader.Companion.terrains
import com.projectswg.holocore.resources.support.data.server_info.loader.ServerData.npcEquipment
import com.projectswg.holocore.resources.support.data.server_info.loader.combat.FactionLoader.Faction
Expand Down Expand Up @@ -249,15 +249,16 @@ object NPCCreator {
private fun createWeapon(detailNpcStat: DetailNpcStatInfo, template: String): WeaponObject? {
try {
val weapon = ObjectCreator.createObjectFromTemplate(template) as WeaponObject
val weaponType = getWeaponType(weapon.gameObjectType)

weapon.minDamage = (detailNpcStat.damagePerSecond * 2 * 0.90).toInt()
weapon.maxDamage = detailNpcStat.damagePerSecond * 2
val range = npcWeaponRanges().getWeaponRange(template)
if (range == -1) Log.w("Failed to load weapon range for: %s", template)
weapon.minRange = range.toFloat()
weapon.maxRange = range.toFloat()
weapon.type = weaponType
val weaponType = npcWeapons().getWeaponType(template)
if (weaponType == null) Log.w("Failed to load weapon type for: %s", template)
weapon.type = weaponType ?: WeaponType.UNARMED
// TODO set damage type, since all NPC weapons shouldn't deal kinetic damage
return weapon
} catch (e: ObjectCreationException) {
Expand All @@ -266,27 +267,4 @@ object NPCCreator {
}
}

/**
* Somewhat accurate way of determining a WeaponType based on a GameObjectType.
* Problem is that GOT_WEAPON_RANGED_RIFLE can be both a rifle and a heavy weapon, but we assume it's a rifle since NPCs don't use heavy weapons.
*
* @param weaponObjectType to determine a WeaponType based on
* @return `WeaponType` that was determined from the given `weaponObjectType` param
*/
private fun getWeaponType(weaponObjectType: GameObjectType): WeaponType {
return when (weaponObjectType) {
GameObjectType.GOT_WEAPON_HEAVY_MINE -> WeaponType.HEAVY
GameObjectType.GOT_WEAPON_HEAVY_MISC -> WeaponType.HEAVY
GameObjectType.GOT_WEAPON_HEAVY_SPECIAL -> WeaponType.HEAVY
GameObjectType.GOT_WEAPON_MELEE_1H -> WeaponType.ONE_HANDED_MELEE
GameObjectType.GOT_WEAPON_MELEE_2H -> WeaponType.TWO_HANDED_MELEE
GameObjectType.GOT_WEAPON_MELEE_MISC -> WeaponType.ONE_HANDED_MELEE
GameObjectType.GOT_WEAPON_MELEE_POLEARM -> WeaponType.POLEARM_MELEE
GameObjectType.GOT_WEAPON_RANGED_CARBINE -> WeaponType.CARBINE
GameObjectType.GOT_WEAPON_RANGED_PISTOL -> WeaponType.PISTOL
GameObjectType.GOT_WEAPON_RANGED_RIFLE -> WeaponType.RIFLE
GameObjectType.GOT_WEAPON_RANGED_THROWN -> WeaponType.THROWN
else -> WeaponType.UNARMED
}
}
}
Loading