Skip to content

Commit

Permalink
NwCreature - Associates (#795)
Browse files Browse the repository at this point in the history
* Add Custom damage types to DamageData

* OnSpellBroadcast - Add Target & position parameters

OnSpellBroadcast - Add Target & position parameters

* NwAreaOfEffect - Add SetRadius

NwAreaOfEffect - Add SetRadius

* NwAreaOfEffect - SetRadius add comments

* NwCreature - Add ForceLevelUp

* NwCreature - Add Get/Set for companion and familiars types and names

* NwCreature - Add Setters for familiar and companions types and names

NwCreature - Add Setters for familiar and companions types and names

* OnSpellBroadcast - Warning fixes

* OnSpellBroadcast - Typo fixes

* NwCreature - Add associates methods

* DamageData remove old implementation

* Fix typo

* Fix declaration of new expression

* Fixes to fit Anvil design!

* Parenthesis removal

* Removed Whitespace

* Adding a method to force a creature to unsummon itself

* Update NwCreature.cs

* Update NwCreature.cs

---------

Co-authored-by: Chim <[email protected]>
Co-authored-by: Jhett Black <[email protected]>
  • Loading branch information
3 people authored Jan 20, 2025
1 parent 9e9831e commit 3075e2d
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 8 deletions.
12 changes: 12 additions & 0 deletions NWN.Anvil/src/main/API/Objects/NwAreaOfEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,17 @@ private protected override void AddToArea(CNWSArea area, float x, float y, float
{
AreaOfEffect.AddToArea(area, x, y, z, true.ToInt());
}

/// <summary>
/// Set the radius of this area of effect.
/// </summary>
/// <param name="radius">The new radius of the area of effect.</param>
public void SetRadius(float radius)
{
if (radius > 0 && AreaOfEffect.m_nShape == 0)
{
AreaOfEffect.SetShape(0, radius);
}
}
}
}
110 changes: 102 additions & 8 deletions NWN.Anvil/src/main/API/Objects/NwCreature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,22 @@ public bool AlwaysWalk
}

/// <summary>
/// Gets this creature's animal companion name.
/// Gets or sets this creature's animal companion name.
/// </summary>
public string AnimalCompanionName => NWScript.GetAnimalCompanionName(this);
public string AnimalCompanionName
{
get => NWScript.GetAnimalCompanionName(this);
set => Creature.m_pStats.m_sAnimalCompanionName = value.ToExoString();
}

/// <summary>
/// Gets this creature's animal companion creature type.
/// Gets or sets this creature's animal companion creature type.
/// </summary>
public AnimalCompanionCreatureType AnimalCompanionType => (AnimalCompanionCreatureType)NWScript.GetAnimalCompanionCreatureType(this);
public AnimalCompanionCreatureType AnimalCompanionType
{
get => (AnimalCompanionCreatureType)NWScript.GetAnimalCompanionCreatureType(this);
set => Creature.m_pStats.m_nAnimalCompanionCreatureType = (int)value;
}

/// <summary>
/// Gets or sets the appearance of this creature.
Expand Down Expand Up @@ -355,14 +363,22 @@ public NwFaction Faction
}

/// <summary>
/// Gets this creature's familiar name.
/// Gets or sets this creature's familiar name.
/// </summary>
public string FamiliarName => NWScript.GetFamiliarName(this);
public string FamiliarName
{
get => NWScript.GetFamiliarName(this);
set => Creature.m_pStats.m_sFamiliarName = value.ToExoString();
}

/// <summary>
/// Gets the type of familiar that this creature can summon.
/// Gets or sets the type of familiar that this creature can summon.
/// </summary>
public FamiliarCreatureType FamiliarType => (FamiliarCreatureType)NWScript.GetFamiliarCreatureType(this);
public FamiliarCreatureType FamiliarType
{
get => (FamiliarCreatureType)NWScript.GetFamiliarCreatureType(this);
set => Creature.m_pStats.m_nFamiliarCreatureType = (int)value;
}

/// <summary>
/// Gets the number of feats known by this creature.
Expand Down Expand Up @@ -1004,6 +1020,35 @@ public async Task ActionCounterspell(NwGameObject counterSpellTarget)
NWScript.ActionCounterSpell(counterSpellTarget);
}

/// <summary>
/// Forces a PC to level up without the level up GUI.
/// </summary>
/// <param name="classType">The class to level up.</param>
/// <param name="hitDie">The hit points gained during this level up.</param>
/// <param name="abilityGain">The abilty to increase : 6 = no increase.</param>
/// <param name="epic">Is this an epic level.</param>
/// <param name="skillPointsRemaining">Number of skill points to give</param>
/// <param name="domain1">Sets a cleric domain for the class (255 = no domain)</param>
/// <param name="domain2">Sets the second cleric domain for the class (255 = no domain)</param>
/// <param name="school">Sets the wizard school for the class (255 = no school)</param>
/// <param name="addStatsToList">Adds the new stats to the character sheet</param>
public void ForceLevelUp(NwClass classType, byte hitDie, Ability? abilityGain = default, bool epic = false, ushort skillPointsRemaining = 0, NwDomain? domain1 = default, NwDomain? domain2 = default, SpellSchool school = SpellSchool.Unknown, bool addStatsToList = true)
{
abilityGain ??= (Ability)6;

CNWLevelStats stats = new CNWLevelStats()
{
m_nClass = classType.Id,
m_nHitDie = hitDie,
m_nAbilityGain = (byte)abilityGain,
m_bEpic = epic.ToInt(),
m_nSkillPointsRemaining = skillPointsRemaining,
};

Creature.m_pStats.LevelUp(stats, domain1?.Id ?? 255, domain2?.Id ?? 255, unchecked((byte)school), addStatsToList.ToInt());
GC.SuppressFinalize(stats);
}

/// <summary>
/// Instructs this creature to equip the specified item into the given inventory slot.<br/>
/// Note: If the creature already has an item equipped in the slot specified, it will be unequipped automatically
Expand Down Expand Up @@ -2647,6 +2692,26 @@ public void SummonAnimalCompanion()
NWScript.SummonAnimalCompanion(this);
}

/// <summary>
/// Forces this creature to summon a familiar event if it does not meet the base game requirements
/// </summary>
/// <param name="resRef">The blueprint resource reference of the creature.</param>
public void SummonAnimalCompanion(string resRef)
{
Creature.SummonAssociate(new CResRef(resRef), Creature.m_pStats.m_sAnimalCompanionName, (ushort)AssociateType.AnimalCompanion);
Creature.m_bSummonedAnimalCompanion = 1;
}

/// <summary>
/// Forces this creature to unsummon their animal companion.<br/>
/// Does nothing if this creature has no animal companion summoned.
/// </summary>
public void UnsummonAnimalCompanion()
{
GetAssociate(AssociateType.AnimalCompanion)?.Creature.UnsummonMyself();
Creature.m_bSummonedAnimalCompanion = 0;
}

/// <summary>
/// Instructs this creature to summon their familiar (wizard/sorcerer).<br/>
/// Does nothing if this creature has no familiar available.
Expand All @@ -2656,6 +2721,35 @@ public void SummonFamiliar()
NWScript.SummonFamiliar(this);
}

/// <summary>
/// Forces this creature to summon a familiar event if it does not meet the base game requirements
/// </summary>
/// <param name="resRef">The blueprint resource reference of the creature.</param>
public void SummonFamiliar(string resRef)
{
Creature.SummonAssociate(new CResRef(resRef), Creature.m_pStats.m_sFamiliarName, (ushort)AssociateType.Familiar);
Creature.m_bSummonedFamiliar = 1;
}

/// <summary>
/// Forces this creature to unsummon their familiar.<br/>
/// Does nothing if this creature has no familiar summoned.
/// </summary>
public void UnsummonFamiliar()
{
GetAssociate(AssociateType.Familiar)?.Creature.UnsummonMyself();
Creature.m_bSummonedFamiliar = 0;
}

/// <summary>
/// Forces this creature to unsummon itself.<br/>
/// Does nothing if this creature is not a summon.
/// </summary>
public void Unsummon()
{
Creature.UnsummonMyself();
}

/// <summary>
/// Takes gold away from this creature.
/// </summary>
Expand Down

0 comments on commit 3075e2d

Please sign in to comment.