Skip to content

Commit b6197c2

Browse files
committed
fix(combat): switch to melonlogger, typecast safely, update xml docs
Closes KaBooMa#83
1 parent a8c0dfa commit b6197c2

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

S1API/Entities/Behaviour/CombatBehaviour.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using UnityEngine;
1414
using MelonLoader;
1515
using S1API.Entities.Equippables;
16+
using S1API.Internal.Utils;
1617
using Object = UnityEngine.Object;
1718

1819
namespace S1API.Entities.Behaviour;
@@ -22,6 +23,8 @@ namespace S1API.Entities.Behaviour;
2223
/// </summary>
2324
public class CombatBehaviour
2425
{
26+
private static readonly Logging.Log Logger = new("CombatBehaviour");
27+
2528
/// <summary>
2629
/// INTERNAL: NPC reference
2730
/// </summary>
@@ -57,8 +60,13 @@ public float GiveUpTime
5760
/// <summary>
5861
/// Gets or sets the default weapon asset path for the NPC's combat behaviour.
5962
/// This property allows you to specify the weapon that the NPC will use by default.
60-
/// <see cref="Weapon"/> for convenience when setting this property.
63+
/// Use <see cref="Weapon"/> or <see cref="AvatarEquippablePaths"/> for convenience when setting this property.
64+
/// Set to an empty string to clear the default weapon.
6165
/// </summary>
66+
/// <remarks>
67+
/// Using type-safe <see cref="SetDefaultWeapon(Equippable)"/>
68+
/// or <see cref="SetDefaultWeapon(EquippableBuilder)"/> is generally preferred and advised.
69+
/// </remarks>
6270
public string DefaultWeaponAssetPath
6371
{
6472
get
@@ -74,21 +82,27 @@ public string DefaultWeaponAssetPath
7482
return;
7583
}
7684

77-
var go = Resources.Load(value) as GameObject;
78-
if (go == null)
85+
var go = Resources.Load(value);
86+
if (!CrossType.Is<GameObject>(go, out var gameObject) || gameObject == null)
7987
{
80-
Debug.LogError("Could not find weapon at path: " + value);
88+
Logger.Error("Could not find weapon at path: " + value);
8189
return;
8290
}
8391

84-
var equippable = Object.Instantiate(go).GetComponent<AvatarEquippable>();
92+
var equippable = Object.Instantiate(gameObject).GetComponent<AvatarEquippable>();
8593
if (equippable == null)
8694
{
87-
Debug.LogError("Could not get AvatarEquippable from weapon at path: " + value);
95+
Logger.Error("Could not get AvatarEquippable from weapon at path: " + value);
96+
return;
97+
}
98+
99+
if (!CrossType.Is<AvatarWeapon>(equippable, out var avatarWeapon))
100+
{
101+
Logger.Error("AvatarEquippable at path is not an AvatarWeapon: " + value);
88102
return;
89103
}
90104

91-
NPC.S1NPC.Behaviour.CombatBehaviour.DefaultWeapon = equippable as AvatarWeapon;
105+
NPC.S1NPC.Behaviour.CombatBehaviour.DefaultWeapon = avatarWeapon;
92106
}
93107
}
94108

0 commit comments

Comments
 (0)