From 5b5237ef2f7d263a5e67ee3b5ee0dd35ccc7ecdb Mon Sep 17 00:00:00 2001 From: Ziggy Date: Thu, 17 Oct 2019 18:53:34 +0200 Subject: [PATCH] #191: GameObjectType based WeaponType determination is now only run for NPC weapons --- .../support/npc/spawn/NPCCreator.java | 30 +++++++++++++++++++ .../objects/swg/weapon/WeaponObject.java | 15 +--------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/projectswg/holocore/resources/support/npc/spawn/NPCCreator.java b/src/main/java/com/projectswg/holocore/resources/support/npc/spawn/NPCCreator.java index 047688725..d4b3952bc 100644 --- a/src/main/java/com/projectswg/holocore/resources/support/npc/spawn/NPCCreator.java +++ b/src/main/java/com/projectswg/holocore/resources/support/npc/spawn/NPCCreator.java @@ -30,6 +30,7 @@ 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.location.Location.LocationBuilder; +import com.projectswg.common.data.objects.GameObjectType; import com.projectswg.holocore.intents.gameplay.gcw.faction.FactionIntent; import com.projectswg.holocore.intents.support.objects.swg.ObjectCreatedIntent; import com.projectswg.holocore.resources.support.data.server_info.loader.DataLoader; @@ -46,6 +47,7 @@ import com.projectswg.holocore.resources.support.objects.swg.custom.AIObject; import com.projectswg.holocore.resources.support.objects.swg.tangible.OptionFlag; import com.projectswg.holocore.resources.support.objects.swg.tangible.TangibleObject; import com.projectswg.holocore.resources.support.objects.swg.weapon.WeaponObject; +import com.projectswg.holocore.resources.support.objects.swg.weapon.WeaponType; import me.joshlarson.jlcommon.control.IntentChain; import me.joshlarson.jlcommon.log.Log; import me.joshlarson.jlcommon.utilities.Arguments; @@ -206,6 +208,8 @@ public class NPCCreator { private static WeaponObject createWeapon(DetailNpcStatInfo detailNpcStat, String template) { try { WeaponObject weapon = (WeaponObject) ObjectCreator.createObjectFromTemplate(template); + WeaponType weaponType = getWeaponType(weapon.getGameObjectType()); + weapon.setMinDamage((int) (detailNpcStat.getDamagePerSecond() * 2 * 0.90)); weapon.setMaxDamage(detailNpcStat.getDamagePerSecond() * 2); int range = DataLoader.Companion.npcWeaponRanges().getWeaponRange(template); @@ -213,6 +217,8 @@ public class NPCCreator { Log.w("Failed to load weapon range for: %s", template); weapon.setMinRange(range); weapon.setMaxRange(range); + weapon.setType(weaponType); + // TODO set damage type, since all NPC weapons shouldn't deal kinetic damage return weapon; } catch (ObjectCreationException e) { Log.w("Weapon template does not exist: %s", template); @@ -220,4 +226,28 @@ public class 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 {@code WeaponType} that was determined from the given {@code weaponObjectType} param + */ + private static WeaponType getWeaponType(GameObjectType weaponObjectType) { + switch (weaponObjectType) { + case GOT_WEAPON_HEAVY_MINE: return WeaponType.HEAVY; + case GOT_WEAPON_HEAVY_MISC: return WeaponType.HEAVY; + case GOT_WEAPON_HEAVY_SPECIAL: return WeaponType.HEAVY; + case GOT_WEAPON_MELEE_1H: return WeaponType.ONE_HANDED_MELEE; + case GOT_WEAPON_MELEE_2H: return WeaponType.TWO_HANDED_MELEE; + case GOT_WEAPON_MELEE_MISC: return WeaponType.ONE_HANDED_MELEE; + case GOT_WEAPON_MELEE_POLEARM: return WeaponType.POLEARM_MELEE; + case GOT_WEAPON_RANGED_CARBINE: return WeaponType.CARBINE; + case GOT_WEAPON_RANGED_PISTOL: return WeaponType.PISTOL; + case GOT_WEAPON_RANGED_RIFLE: return WeaponType.RIFLE; + case GOT_WEAPON_RANGED_THROWN: return WeaponType.THROWN; + } + return WeaponType.UNARMED; + } + } diff --git a/src/main/java/com/projectswg/holocore/resources/support/objects/swg/weapon/WeaponObject.java b/src/main/java/com/projectswg/holocore/resources/support/objects/swg/weapon/WeaponObject.java index a547a78cb..ceb064f5a 100644 --- a/src/main/java/com/projectswg/holocore/resources/support/objects/swg/weapon/WeaponObject.java +++ b/src/main/java/com/projectswg/holocore/resources/support/objects/swg/weapon/WeaponObject.java @@ -112,20 +112,7 @@ public class WeaponObject extends TangibleObject { } public WeaponType getType() { - switch (getGameObjectType()) { - case GOT_WEAPON_HEAVY_MINE: return WeaponType.HEAVY; - case GOT_WEAPON_HEAVY_MISC: return WeaponType.HEAVY; - case GOT_WEAPON_HEAVY_SPECIAL: return WeaponType.HEAVY; - case GOT_WEAPON_MELEE_1H: return WeaponType.ONE_HANDED_MELEE; - case GOT_WEAPON_MELEE_2H: return WeaponType.TWO_HANDED_MELEE; - case GOT_WEAPON_MELEE_MISC: return WeaponType.ONE_HANDED_MELEE; - case GOT_WEAPON_MELEE_POLEARM: return WeaponType.POLEARM_MELEE; - case GOT_WEAPON_RANGED_CARBINE: return WeaponType.CARBINE; - case GOT_WEAPON_RANGED_PISTOL: return WeaponType.PISTOL; - case GOT_WEAPON_RANGED_RIFLE: return WeaponType.RIFLE; - case GOT_WEAPON_RANGED_THROWN: return WeaponType.THROWN; - } - return WeaponType.UNARMED; + return type; } public void setType(WeaponType type) {