Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NwCreature - Add ForceLevelUp #792

Closed
Closed
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
114 changes: 114 additions & 0 deletions NWN.Anvil/src/main/API/Events/Native/DamageEvents/DamageData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,120 @@ public T Sonic
set => source[11] = value;
}

public T Custom1
{
get => source[13];
set => source[13] = value;
}

public T Custom2
{
get => source[14];
set => source[14] = value;
}

public T Custom3
{
get => source[15];
set => source[15] = value;
}

public T Custom4
{
get => source[16];
set => source[16] = value;
}

public T Custom5
{
get => source[17];
set => source[17] = value;
}

public T Custom6
{
get => source[18];
set => source[18] = value;
}

public T Custom7
{
get => source[19];
set => source[19] = value;
}

public T Custom8
{
get => source[20];
set => source[20] = value;
}

public T Custom9
{
get => source[21];
set => source[21] = value;
}

public T Custom10
{
get => source[22];
set => source[22] = value;
}

public T Custom11
{
get => source[23];
set => source[23] = value;
}

public T Custom12
{
get => source[24];
set => source[24] = value;
}

public T Custom13
{
get => source[25];
set => source[25] = value;
}

public T Custom14
{
get => source[26];
set => source[26] = value;
}

public T Custom15
{
get => source[27];
set => source[27] = value;
}

public T Custom16
{
get => source[28];
set => source[28] = value;
}

public T Custom17
{
get => source[29];
set => source[29] = value;
}

public T Custom18
{
get => source[30];
set => source[30] = value;
}

public T Custom19
{
get => source[31];
set => source[31] = value;
}

public T GetDamageByType(DamageType damageType)
{
int index = BitOperations.Log2((uint)damageType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
using Anvil.API.Events;
using Anvil.Native;
using Anvil.Services;
using NWN.Core;

Check warning

Code scanning / InspectCode

Redundant using directive Warning

Using directive is not required by the code and can be safely removed
using NWN.Native.API;

namespace Anvil.API.Events
Expand All @@ -17,6 +19,8 @@
public bool PreventSpellCast { get; set; }

public NwSpell Spell { get; private init; } = null!;
public NwGameObject TargetObject { get; private init; } = null!;
public Vector3 TargetPosition { get; private init; }

NwObject IEvent.Context => Caster;

Expand All @@ -36,12 +40,16 @@
{
CNWSCreature creature = CNWSCreature.FromPointer(pCreature);

NwGameObject oTarget = ((uint)creature.m_pExecutingAIAction.m_pParameter[5]).ToNwObject<NwGameObject>()!;

OnSpellBroadcast eventData = ProcessEvent(EventCallbackType.Before, new OnSpellBroadcast
{
Caster = creature.ToNwObject<NwCreature>()!,
Spell = NwSpell.FromSpellId((int)nSpellId)!,
ClassIndex = nMultiClass,
Feat = NwFeat.FromFeatId(nFeat)!,
TargetObject = oTarget,
TargetPosition = oTarget is not null ? oTarget.Position : new Vector3(BitConverter.Int32BitsToSingle((int)creature.m_pExecutingAIAction.m_pParameter[6]), BitConverter.Int32BitsToSingle((int)creature.m_pExecutingAIAction.m_pParameter[7]), BitConverter.Int32BitsToSingle((int)creature.m_pExecutingAIAction.m_pParameter[8])),

Check warning

Code scanning / InspectCode

Expression is always true according to nullable reference types' annotations Warning

Expression is always true according to nullable reference types' annotations

Check notice

Code scanning / InspectCode

Merge conditional ?: expression into conditional access Note

Merge conditional expression
});

if (!eventData.PreventSpellCast)
Expand Down
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 @@
{
AreaOfEffect.AddToArea(area, x, y, z, true.ToInt());
}
/// <summary>

Check warning

Code scanning / InspectCode

Incorrect blank lines: Blank lines are missing elsewhere Warning

Blank lines are missing, expected minimum 1 instead of 0
/// 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);
}
}

}
}
27 changes: 27 additions & 0 deletions NWN.Anvil/src/main/API/Objects/NwCreature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,33 @@
await WaitForObjectContext();
NWScript.ActionCounterSpell(counterSpellTarget);
}
/// <summary>

Check warning

Code scanning / InspectCode

Incorrect blank lines: Blank lines are missing elsewhere Warning

Blank lines are missing, expected minimum 1 instead of 0
/// Forces a PC to level up without the level up GUI.
/// </summary>
/// <param name="nClass">The class to level up.</param>
/// <param name="nHitDie">The hit points gained during this level up.</param>
/// <param name="nAbilityGain">The abilty to increase : 6 = no increase.</param>
/// <param name="bEpic">Is this an epic level.</param>
/// <param name="nSkillPointsRemaining">Number of skill points to give</param>
/// <param name="nDomain1">Sets a cleric domain for the class (255 = no domain)</param>
/// <param name="nDomain2">Sets the second cleric domain for the class (255 = no domain)</param>
/// <param name="nSchool">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(byte nClass, byte nHitDie, byte nAbilityGain = 6, int bEpic = 0, ushort nSkillPointsRemaining = 0, byte nDomain1 = 255, byte nDomain2 = 255, byte nSchool = 255, int addStatsToList = 1)
{
CNWLevelStats stats = new()

Check notice

Code scanning / InspectCode

Use preferred style of 'new' expression when created type is evident Note

Missing type specification
{
m_nClass = nClass,
m_nHitDie = nHitDie,
m_nAbilityGain = nAbilityGain,
m_bEpic = bEpic,
m_nSkillPointsRemaining = nSkillPointsRemaining,
};

Creature.m_pStats.LevelUp(stats, nDomain1, nDomain2, nSchool, addStatsToList);
GC.SuppressFinalize(stats);
}


/// <summary>
/// Instructs this creature to equip the specified item into the given inventory slot.<br/>
Expand Down
Loading