|
bool? | GetBool (int rowIndex, int columnIndex) |
| Gets the specified boolean value. More...
|
|
bool? | GetBool (int rowIndex, string columnName) |
| Gets the specified boolean value. More...
|
|
int | GetColumnIndex (string columnName) |
| Gets the index of the column with the specified name/label. More...
|
|
T? | GetEnum< T > (int rowIndex, int columnIndex) |
| Gets the specified enum value value. More...
|
|
T? | GetEnum< T > (int rowIndex, string columnName) |
| Gets the specified StrRef value. More...
|
|
IEnumerator< T > | GetEnumerator () |
|
float? | GetFloat (int rowIndex, int columnIndex) |
| Gets the specified float value. More...
|
|
float? | GetFloat (int rowIndex, string columnName) |
| Gets the specified float value. More...
|
|
int? | GetInt (int rowIndex, int columnIndex) |
| Gets the specified int value. More...
|
|
int? | GetInt (int rowIndex, string columnName) |
| Gets the specified int value. More...
|
|
T | GetRow (int rowIndex) |
| Gets the row at the specified index. More...
|
|
string? | GetString (int rowIndex, int columnIndex) |
| Gets the specified string value. More...
|
|
string? | GetString (int rowIndex, string columnName) |
| Gets the specified string value. More...
|
|
StrRef? | GetStrRef (int rowIndex, int columnIndex) |
| Gets the specified StrRef value. More...
|
|
StrRef? | GetStrRef (int rowIndex, string columnName) |
| Gets the specified StrRef value. More...
|
|
TwoDimArray< T >? | GetTable< T > (int rowIndex, int columnIndex) |
| Interprets the specified value as a table name, and returns the associated table. More...
|
|
TwoDimArray< T >? | GetTable< T > (int rowIndex, string columnName) |
| Interprets the specified value as a table name, and returns the associated table. More...
|
|
T? | GetTableEntry< T > (int rowIndex, int columnIndex, TwoDimArray< T > table) |
| Interprets the specified value as a table index, and returns the associated table entry. More...
|
|
T? | GetTableEntry< T > (int rowIndex, string columnName, TwoDimArray< T > table) |
| Interprets the specified value as a table index, and returns the associated table entry. More...
|
|
Vector3? | GetVector3 (int rowIndex, int columnIndexX, int columnIndexY, int columnIndexZ) |
| Gets the specified Vector3 value. More...
|
|
Vector3? | GetVector3 (int rowIndex, string columnNameX, string columnNameY, string columnNameZ) |
| Gets the specified Vector3 value. More...
|
|
A two dimensional array data resource.
A two dimensional array resource, with a decoded row type.
Examples
using System.Linq;
namespace NWN.Anvil.Samples
{
public sealed class ExpTableEntry : ITwoDimArrayEntry
{
public int Level { get; private set; }
public int XP { get; private set; }
public int RowIndex { get; init; }
public void InterpretEntry(TwoDimArrayEntry entry)
{
Level = entry.GetInt("Level").GetValueOrDefault(0);
XP = entry.GetInt("XP").GetValueOrDefault(0);
}
}
[ServiceBinding(typeof(XPReportService))]
public class XPReportService
{
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;
}
}
}
- Template Parameters
-
T | The row/entry type to decode the array. |