Anvil
Anvil.API.TwoDimArrayEntry Class Reference

2da row data. More...

Public Member Functions

bool? GetBool (int columnIndex)
 Gets the specified boolean value. More...
 
bool? GetBool (string columnName)
 Gets the specified boolean value. More...
 
T? GetEnum< T > (int columnIndex)
 Gets the specified enum value. More...
 
T? GetEnum< T > (string columnName)
 Gets the specified enum value. More...
 
float? GetFloat (int columnIndex)
 Gets the specified float value. More...
 
float? GetFloat (string columnName)
 Gets the specified float value. More...
 
int? GetInt (int columnIndex)
 Gets the specified int value. More...
 
int? GetInt (string columnName)
 Gets the specified int value. More...
 
string? GetString (int columnIndex)
 Gets the specified string value. More...
 
string? GetString (string columnName)
 Gets the specified string value. More...
 
StrRefGetStrRef (int columnIndex)
 Gets the specified StrRef value. More...
 
StrRefGetStrRef (string columnName)
 Gets the specified StrRef value. More...
 
TwoDimArray< T >? GetTable< T > (int columnIndex)
 Interprets the specified value as a table index, and returns the associated table entry. More...
 
TwoDimArray< T >? GetTable< T > (string columnName)
 Interprets the specified value as a table index, and returns the associated table entry. More...
 
T? GetTableEntry< T > (int columnIndex, TwoDimArray< T > table)
 Interprets the specified value as a table index, and returns the associated table entry. More...
 
T? GetTableEntry< T > (string columnName, TwoDimArray< T > table)
 Interprets the specified value as a table index, and returns the associated table entry. More...
 
Vector3? GetVector3 (int columnIndexX, int columnIndexY, int columnIndexZ)
 Gets the specified Vector3 value. More...
 
Vector3? GetVector3 (string columnNameX, string columnNameY, string columnNameZ)
 Gets the specified Vector3 value. More...
 

Properties

int ColumnCount [get]
 Gets the number of columns in this row. More...
 
string[] Columns [get]
 Gets the column labels/names for this row. More...
 

Detailed Description

2da row data.

Examples

/*
* Define a implementation to deserialize "xptable.2da", and use this class to determine how much XP is remaining until the next level.
*/
using System.Linq;
using Anvil.API;
namespace NWN.Anvil.Samples
{
// This is the deserialization class for this specific type of 2da.
// We can implement our own helper functions here that operate on the 2da data, and cache it.
public sealed class ExpTableEntry : ITwoDimArrayEntry
{
public int Level { get; private set; }
public int XP { get; private set; }
// RowIndex is already populated externally, and we do not need to assign it in InterpretEntry.
public int RowIndex { get; init; }
// InterpretEntry is where we populate our entry properties (Level & XP) with the correct data.
public void InterpretEntry(TwoDimArrayEntry entry)
{
Level = entry.GetInt("Level").GetValueOrDefault(0);
XP = entry.GetInt("XP").GetValueOrDefault(0);
}
}
[ServiceBinding(typeof(XPReportService))]
public class XPReportService
{
// The TwoDimArray is created here.
// ExpTableEntry (the type above) is passed in as a type parameter to be used to create our row data from exptable.2da.
private readonly TwoDimArray<ExpTableEntry> expTable = NwGameTables.GetTable<ExpTableEntry>("exptable.2da")!;
public XPReportService()
{
NwModule.Instance.OnClientEnter += OnClientEnter;
}
private void OnClientEnter(ModuleEvents.OnClientEnter onClientEnter)
{
NwPlayer player = onClientEnter.Player;
NwCreature? creature = player.ControlledCreature;
if (creature == null)
{
return;
}
int nextLevel = GetLevelFromXp(creature.Xp) + 1;
if (nextLevel > MaxLevel)
{
return;
}
player.SendServerMessage($"Next level up: {GetXpForLevel(nextLevel) - creature.Xp}");
}
public int MaxLevel => expTable[^1].Level;
public int GetXpForLevel(int level)
{
return expTable.First(entry => entry.Level == level).XP;
}
public int GetLevelFromXp(int xp)
{
int level = 1;
foreach (ExpTableEntry entry in expTable.Rows)
{
if (entry.XP > xp)
{
break;
}
level = entry.Level;
}
return level;
}
}
}

Member Function Documentation

◆ GetBool() [1/2]

bool? Anvil.API.TwoDimArrayEntry.GetBool ( int  columnIndex)
inline

Gets the specified boolean value.

Parameters
columnIndexThe index of the column to query.
Returns
The associated value. null if no value is set.

◆ GetBool() [2/2]

bool? Anvil.API.TwoDimArrayEntry.GetBool ( string  columnName)
inline

Gets the specified boolean value.

Parameters
columnNameThe name/label of the column to query.
Returns
The associated value. null if no value is set.

◆ GetEnum< T >() [1/2]

T? Anvil.API.TwoDimArrayEntry.GetEnum< T > ( int  columnIndex)
inline

Gets the specified enum value.

Parameters
columnIndexThe index of the column to query.
Returns
The associated value. null if no value is set.
Type Constraints
T :struct 
T :Enum 

◆ GetEnum< T >() [2/2]

T? Anvil.API.TwoDimArrayEntry.GetEnum< T > ( string  columnName)
inline

Gets the specified enum value.

Parameters
columnNameThe name/label of the column to query.
Returns
The associated value. null if no value is set.
Type Constraints
T :struct 
T :Enum 

◆ GetFloat() [1/2]

float? Anvil.API.TwoDimArrayEntry.GetFloat ( int  columnIndex)
inline

Gets the specified float value.

Parameters
columnIndexThe index of the column to query.
Returns
The associated value. null if no value is set.

◆ GetFloat() [2/2]

float? Anvil.API.TwoDimArrayEntry.GetFloat ( string  columnName)
inline

Gets the specified float value.

Parameters
columnNameThe name/label of the column to query.
Returns
The associated value. null if no value is set.

◆ GetInt() [1/2]

int? Anvil.API.TwoDimArrayEntry.GetInt ( int  columnIndex)
inline

Gets the specified int value.

Parameters
columnIndexThe index of the column to query.
Returns
The associated value. null if no value is set.

◆ GetInt() [2/2]

int? Anvil.API.TwoDimArrayEntry.GetInt ( string  columnName)
inline

Gets the specified int value.

Parameters
columnNameThe name/label of the column to query.
Returns
The associated value. null if no value is set.

◆ GetString() [1/2]

string? Anvil.API.TwoDimArrayEntry.GetString ( int  columnIndex)
inline

Gets the specified string value.

Parameters
columnIndexThe index of the column to query.
Returns
The associated value. null if no value is set.

◆ GetString() [2/2]

string? Anvil.API.TwoDimArrayEntry.GetString ( string  columnName)
inline

Gets the specified string value.

Parameters
columnNameThe name/label of the column to query.
Returns
The associated value. null if no value is set.

◆ GetStrRef() [1/2]

StrRef? Anvil.API.TwoDimArrayEntry.GetStrRef ( int  columnIndex)
inline

Gets the specified StrRef value.

Parameters
columnIndexThe index of the column to query.
Returns
The associated value. null if no value is set.

◆ GetStrRef() [2/2]

StrRef? Anvil.API.TwoDimArrayEntry.GetStrRef ( string  columnName)
inline

Gets the specified StrRef value.

Parameters
columnNameThe name/label of the column to query.
Returns
The associated value. null if no value is set.

◆ GetTable< T >() [1/2]

TwoDimArray<T>? Anvil.API.TwoDimArrayEntry.GetTable< T > ( int  columnIndex)
inline

Interprets the specified value as a table index, and returns the associated table entry.

Parameters
columnIndexThe index of the column to query.
Template Parameters
TThe type of table entry.
Returns
The associated value, otherwise the default array entry value (typically null)
Type Constraints
T :class 
T :ITwoDimArrayEntry 
T :new() 

◆ GetTable< T >() [2/2]

TwoDimArray<T>? Anvil.API.TwoDimArrayEntry.GetTable< T > ( string  columnName)
inline

Interprets the specified value as a table index, and returns the associated table entry.

Parameters
columnNameThe name/label of the column to query.
Template Parameters
TThe type of table entry.
Returns
The associated value, otherwise the default array entry value (typically null)
Type Constraints
T :class 
T :ITwoDimArrayEntry 
T :new() 

◆ GetTableEntry< T >() [1/2]

T? Anvil.API.TwoDimArrayEntry.GetTableEntry< T > ( int  columnIndex,
TwoDimArray< T >  table 
)
inline

Interprets the specified value as a table index, and returns the associated table entry.

Parameters
columnIndexThe index of the column to query.
tableThe table that should be used to resolve the value.
Template Parameters
TThe type of table entry.
Returns
The associated value, otherwise the default array entry value (typically null)
Type Constraints
T :class 
T :ITwoDimArrayEntry 
T :new() 

◆ GetTableEntry< T >() [2/2]

T? Anvil.API.TwoDimArrayEntry.GetTableEntry< T > ( string  columnName,
TwoDimArray< T >  table 
)
inline

Interprets the specified value as a table index, and returns the associated table entry.

Parameters
columnNameThe name/label of the column to query.
tableThe table that should be used to resolve the value.
Template Parameters
TThe type of table entry.
Returns
The associated value, otherwise the default array entry value (typically null)
Type Constraints
T :class 
T :ITwoDimArrayEntry 
T :new() 

◆ GetVector3() [1/2]

Vector3? Anvil.API.TwoDimArrayEntry.GetVector3 ( int  columnIndexX,
int  columnIndexY,
int  columnIndexZ 
)
inline

Gets the specified Vector3 value.

Parameters
columnIndexXThe index of the column containing the x component of the vector.
columnIndexYThe index of the column containing the y component of the vector.
columnIndexZThe index of the column containing the z component of the vector.
Returns
The associated value. null if no value is set.

◆ GetVector3() [2/2]

Vector3? Anvil.API.TwoDimArrayEntry.GetVector3 ( string  columnNameX,
string  columnNameY,
string  columnNameZ 
)
inline

Gets the specified Vector3 value.

Parameters
columnNameXThe name/label of the column containing the x component of the vector.
columnNameYThe name/label of the column containing the y component of the vector.
columnNameZThe name/label of the column containing the z component of the vector.
Returns
The associated value. null if no value is set.

Property Documentation

◆ ColumnCount

int Anvil.API.TwoDimArrayEntry.ColumnCount
get

Gets the number of columns in this row.

◆ Columns

string [] Anvil.API.TwoDimArrayEntry.Columns
get

Gets the column labels/names for this row.


The documentation for this class was generated from the following file: