From 3075e2d6c09907f1c4df9eba1cd9fc6de175c7ea Mon Sep 17 00:00:00 2001 From: Chimerik <47835020+Chimerik@users.noreply.github.com> Date: Tue, 21 Jan 2025 00:06:33 +0100 Subject: [PATCH] NwCreature - Associates (#795) * 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 Co-authored-by: Jhett Black <10942655+jhett12321@users.noreply.github.com> --- .../src/main/API/Objects/NwAreaOfEffect.cs | 12 ++ NWN.Anvil/src/main/API/Objects/NwCreature.cs | 110 ++++++++++++++++-- 2 files changed, 114 insertions(+), 8 deletions(-) diff --git a/NWN.Anvil/src/main/API/Objects/NwAreaOfEffect.cs b/NWN.Anvil/src/main/API/Objects/NwAreaOfEffect.cs index 99eae71d8..5bc22407d 100644 --- a/NWN.Anvil/src/main/API/Objects/NwAreaOfEffect.cs +++ b/NWN.Anvil/src/main/API/Objects/NwAreaOfEffect.cs @@ -104,5 +104,17 @@ private protected override void AddToArea(CNWSArea area, float x, float y, float { AreaOfEffect.AddToArea(area, x, y, z, true.ToInt()); } + + /// + /// Set the radius of this area of effect. + /// + /// The new radius of the area of effect. + public void SetRadius(float radius) + { + if (radius > 0 && AreaOfEffect.m_nShape == 0) + { + AreaOfEffect.SetShape(0, radius); + } + } } } diff --git a/NWN.Anvil/src/main/API/Objects/NwCreature.cs b/NWN.Anvil/src/main/API/Objects/NwCreature.cs index 0e3ab9db6..878c812d0 100644 --- a/NWN.Anvil/src/main/API/Objects/NwCreature.cs +++ b/NWN.Anvil/src/main/API/Objects/NwCreature.cs @@ -92,14 +92,22 @@ public bool AlwaysWalk } /// - /// Gets this creature's animal companion name. + /// Gets or sets this creature's animal companion name. /// - public string AnimalCompanionName => NWScript.GetAnimalCompanionName(this); + public string AnimalCompanionName + { + get => NWScript.GetAnimalCompanionName(this); + set => Creature.m_pStats.m_sAnimalCompanionName = value.ToExoString(); + } /// - /// Gets this creature's animal companion creature type. + /// Gets or sets this creature's animal companion creature type. /// - public AnimalCompanionCreatureType AnimalCompanionType => (AnimalCompanionCreatureType)NWScript.GetAnimalCompanionCreatureType(this); + public AnimalCompanionCreatureType AnimalCompanionType + { + get => (AnimalCompanionCreatureType)NWScript.GetAnimalCompanionCreatureType(this); + set => Creature.m_pStats.m_nAnimalCompanionCreatureType = (int)value; + } /// /// Gets or sets the appearance of this creature. @@ -355,14 +363,22 @@ public NwFaction Faction } /// - /// Gets this creature's familiar name. + /// Gets or sets this creature's familiar name. /// - public string FamiliarName => NWScript.GetFamiliarName(this); + public string FamiliarName + { + get => NWScript.GetFamiliarName(this); + set => Creature.m_pStats.m_sFamiliarName = value.ToExoString(); + } /// - /// Gets the type of familiar that this creature can summon. + /// Gets or sets the type of familiar that this creature can summon. /// - public FamiliarCreatureType FamiliarType => (FamiliarCreatureType)NWScript.GetFamiliarCreatureType(this); + public FamiliarCreatureType FamiliarType + { + get => (FamiliarCreatureType)NWScript.GetFamiliarCreatureType(this); + set => Creature.m_pStats.m_nFamiliarCreatureType = (int)value; + } /// /// Gets the number of feats known by this creature. @@ -1004,6 +1020,35 @@ public async Task ActionCounterspell(NwGameObject counterSpellTarget) NWScript.ActionCounterSpell(counterSpellTarget); } + /// + /// Forces a PC to level up without the level up GUI. + /// + /// The class to level up. + /// The hit points gained during this level up. + /// The abilty to increase : 6 = no increase. + /// Is this an epic level. + /// Number of skill points to give + /// Sets a cleric domain for the class (255 = no domain) + /// Sets the second cleric domain for the class (255 = no domain) + /// Sets the wizard school for the class (255 = no school) + /// Adds the new stats to the character sheet + 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); + } + /// /// Instructs this creature to equip the specified item into the given inventory slot.
/// Note: If the creature already has an item equipped in the slot specified, it will be unequipped automatically @@ -2647,6 +2692,26 @@ public void SummonAnimalCompanion() NWScript.SummonAnimalCompanion(this); } + /// + /// Forces this creature to summon a familiar event if it does not meet the base game requirements + /// + /// The blueprint resource reference of the creature. + public void SummonAnimalCompanion(string resRef) + { + Creature.SummonAssociate(new CResRef(resRef), Creature.m_pStats.m_sAnimalCompanionName, (ushort)AssociateType.AnimalCompanion); + Creature.m_bSummonedAnimalCompanion = 1; + } + + /// + /// Forces this creature to unsummon their animal companion.
+ /// Does nothing if this creature has no animal companion summoned. + ///
+ public void UnsummonAnimalCompanion() + { + GetAssociate(AssociateType.AnimalCompanion)?.Creature.UnsummonMyself(); + Creature.m_bSummonedAnimalCompanion = 0; + } + /// /// Instructs this creature to summon their familiar (wizard/sorcerer).
/// Does nothing if this creature has no familiar available. @@ -2656,6 +2721,35 @@ public void SummonFamiliar() NWScript.SummonFamiliar(this); } + /// + /// Forces this creature to summon a familiar event if it does not meet the base game requirements + /// + /// The blueprint resource reference of the creature. + public void SummonFamiliar(string resRef) + { + Creature.SummonAssociate(new CResRef(resRef), Creature.m_pStats.m_sFamiliarName, (ushort)AssociateType.Familiar); + Creature.m_bSummonedFamiliar = 1; + } + + /// + /// Forces this creature to unsummon their familiar.
+ /// Does nothing if this creature has no familiar summoned. + ///
+ public void UnsummonFamiliar() + { + GetAssociate(AssociateType.Familiar)?.Creature.UnsummonMyself(); + Creature.m_bSummonedFamiliar = 0; + } + + /// + /// Forces this creature to unsummon itself.
+ /// Does nothing if this creature is not a summon. + ///
+ public void Unsummon() + { + Creature.UnsummonMyself(); + } + /// /// Takes gold away from this creature. ///