Skip to content

Commit 98af791

Browse files
committed
feat(faction): add C_Reputation.GetFactionDataByID
Keys the modern FactionData table by faction ID instead of by displayed-list position. Reuses the shared ReadFactionData chain and table builder, so it needs no new engine work. Unlike GetFactionInfoByID this is not limited to the player's reputation list: an unencountered faction fills cleanly with currentStanding 0 and atWarWith false, so any real faction's name, description and thresholds are readable.
1 parent 6228827 commit 98af791

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ reference in **[docs/API.md](docs/API.md)**.
6666
| [EquipmentSet](docs/API.md#equipmentset) | `C_EquipmentSet.CanUseEquipmentSets`, `C_EquipmentSet.ClearIgnoredSlotsForSave`, `C_EquipmentSet.CreateEquipmentSet`, `C_EquipmentSet.DeleteEquipmentSet`, `C_EquipmentSet.EquipmentSetContainsLockedItems`, `C_EquipmentSet.GetEquipmentSetID`, `C_EquipmentSet.GetEquipmentSetIDs`, `C_EquipmentSet.GetEquipmentSetInfo`, `C_EquipmentSet.GetIgnoredSlots`, `C_EquipmentSet.GetItemIDs`, `C_EquipmentSet.GetItemLocations`, `C_EquipmentSet.GetNumEquipmentSets`, `C_EquipmentSet.IgnoreSlotForSave`, `C_EquipmentSet.IsSlotIgnoredForSave`, `C_EquipmentSet.ModifyEquipmentSet`, `C_EquipmentSet.SaveEquipmentSet`, `C_EquipmentSet.UnignoreSlotForSave`, `C_EquipmentSet.UseEquipmentSet` |
6767
| [Events](docs/API.md#events) | `C_EventUtils.IsEventValid`, `GetFramesRegisteredForEvent` |
6868
| [Expansion](docs/API.md#expansion) | `ClassicExpansionAtLeast`, `ClassicExpansionAtMost`, `GetClassicExpansionLevel` |
69-
| [Faction](docs/API.md#faction) | `C_Reputation.GetFactionDataByIndex`, `C_Reputation.GetFactionStandings`, `C_Reputation.GetLastStandingChange`, `C_Reputation.GetWatchedFactionData`, `C_Reputation.SetWatchedFactionByID`, `GetFactionIDByIndex`, `GetFactionInfoByID`, `GetFactionParentID` |
69+
| [Faction](docs/API.md#faction) | `C_Reputation.GetFactionDataByID`, `C_Reputation.GetFactionDataByIndex`, `C_Reputation.GetFactionStandings`, `C_Reputation.GetLastStandingChange`, `C_Reputation.GetWatchedFactionData`, `C_Reputation.SetWatchedFactionByID`, `GetFactionIDByIndex`, `GetFactionInfoByID`, `GetFactionParentID` |
7070
| [Focus](docs/API.md#focus) | `ClearFocus`, `FocusUnit` |
7171
| [Frame](docs/API.md#frame) | `region:SetPoint("point")` (one-arg form), `region:SetSize`, `region:GetSize`, `region:IsMouseOver`, `region:GetRect`, `region:IsDragging`, `GetMouseFoci`, `frame:SetShown`, `fontstring:GetStringHeight`, `fontstring:GetUnboundedStringWidth`, `fontstring:GetWrappedWidth`, `fontstring:GetNumLines`, `fontstring:GetLineHeight`, `fontstring:IsTruncated`, `fontstring:SetMaxLines`, `fontstring:GetMaxLines`, `fontstring:SetFormattedText`, `texture:SetRotation`, `texture:GetRotation`, `texture:SetVertexOffset`, `texture:GetVertexOffset`, `texture:SetColorTexture`, `texture:SetMask`, `frame:CreateMaskTexture`, `texture:AddMaskTexture`, `texture:RemoveMaskTexture`, `texture:GetNumMaskTextures`, `texture:GetMaskTexture`, `fontstring:SetRotation`, `fontstring:GetRotation`, `editBox:SetCursorPosition`, `editBox:GetCursorPosition`, `editBox:GetUTF8CursorPosition`, `editBox:ClearHighlightText`, `editBox:HasFocus`, `editBox:HasText`, `editBox:SetHighlightColor`, `editBox:GetHighlightColor`, `editBox:ClearHistory`, `frame:SetResizeBounds`, `frame:HookScript`, `frame:IsEventRegistered`, `frame:GetEffectiveAlpha`, `frame:SetAttribute`, `frame:SetAttributeNoHandler`, `frame:ClearAttribute`, `frame:GetAttribute`, `OnAttributeChanged` (script), `SetModernScriptArgs`, `GetModernScriptArgs`, `PreClick` (script), `PostClick` (script), `GetClickFrame` |
7272
| [FriendList](docs/API.md#friendlist) | `C_FriendList.GetFriendInfo`, `C_FriendList.GetFriendInfoByIndex`, `C_FriendList.GetNumFriends`, `C_FriendList.GetNumOnlineFriends`, `C_FriendList.GetNumWhoResults`, `C_FriendList.GetWhoInfo`, `C_FriendList.IsFriend`, `C_FriendList.IsIgnored`, `C_FriendList.IsIgnoredByGuid`, `C_FriendList.IsWhoQueryPending`, `C_FriendList.SendWhoQueryByName`, `C_FriendList.SetFriendNotes`, `C_FriendList.SetFriendNotesByIndex` |

docs/API.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ build instructions.
158158
- [`GetFactionParentID(factionID)`](#getfactionparentidfactionid)
159159
- [`C_Reputation.GetFactionStandings()`](#c_reputationgetfactionstandings)
160160
- [`C_Reputation.GetWatchedFactionData()`](#c_reputationgetwatchedfactiondata)
161+
- [`C_Reputation.GetFactionDataByID(factionID)`](#c_reputationgetfactiondatabyidfactionid)
161162
- [`C_Reputation.GetFactionDataByIndex(factionSortIndex)`](#c_reputationgetfactiondatabyindexfactionsortindex)
162163
- [`C_Reputation.SetWatchedFactionByID(factionID)`](#c_reputationsetwatchedfactionbyidfactionid)
163164
- [`C_Reputation.GetLastStandingChange()`](#c_reputationgetlaststandingchange)
@@ -3861,6 +3862,27 @@ Implementation reads the watched `RepListID` from the player's
38613862
`ReadFactionData` chain (Faction.dbc lookup, reaction band, rep slot
38623863
flags, header/collapsed checks).
38633864

3865+
### `C_Reputation.GetFactionDataByID(factionID)`
3866+
3867+
Returns a `FactionData` table for a faction by ID, or `nil` when the ID
3868+
has no `Faction.dbc` record.
3869+
3870+
The table has the same shape as
3871+
[`C_Reputation.GetFactionDataByIndex`](#c_reputationgetfactiondatabyindexfactionsortindex)
3872+
— see that section for the full field list.
3873+
3874+
The faction does not have to be in the player's reputation list. One the
3875+
character has never encountered fills cleanly, with `currentStanding` `0`
3876+
and `atWarWith` `false`, so you can read any faction's name, description,
3877+
and standing thresholds without walking the displayed list.
3878+
3879+
```lua
3880+
local d = C_Reputation.GetFactionDataByID(69) -- Darnassus
3881+
if d then
3882+
print(d.name, d.currentStanding, d.nextReactionThreshold)
3883+
end
3884+
```
3885+
38643886
### `C_Reputation.GetFactionDataByIndex(factionSortIndex)`
38653887

38663888
Returns a `FactionData` table for the faction at the given 1-based

src/faction/Info.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,30 @@ static int __fastcall Script_C_Reputation_GetWatchedFactionData(void *L) {
407407
return 1;
408408
}
409409

410+
// `C_Reputation.GetFactionDataByID(factionID)` — modern table-shaped
411+
// accessor keyed by faction ID rather than by displayed-list position.
412+
// Returns nil when the ID has no `Faction.dbc` record.
413+
//
414+
// Unlike the index form, this doesn't need the faction to be in the
415+
// player's displayed reputation list: `ReadFactionData` fills an
416+
// unencountered faction cleanly (currentStanding 0, not at war), so a
417+
// lookup works for any real faction.
418+
static int __fastcall Script_C_Reputation_GetFactionDataByID(void *L) {
419+
if (!Game::Lua::IsNumber(L, 1)) {
420+
Game::Lua::Error(L, "Usage: C_Reputation.GetFactionDataByID(factionID)");
421+
return 0;
422+
}
423+
const int factionID = static_cast<int>(Game::Lua::ToNumber(L, 1));
424+
425+
FactionData d;
426+
if (!ReadFactionData(factionID, &d))
427+
return 0; // nil — no such faction
428+
429+
Game::Lua::SetTop(L, 0);
430+
PushFactionDataTable(L, d);
431+
return 1;
432+
}
433+
410434
// `C_Reputation.GetFactionDataByIndex(factionSortIndex)` — modern
411435
// table-shaped accessor over the displayed reputation list. 1-based
412436
// index covering the same range as vanilla's `GetFactionInfo(index)`
@@ -479,6 +503,8 @@ static void RegisterLuaFunctions() {
479503
&Script_C_Reputation_GetWatchedFactionData);
480504
Game::Lua::RegisterTableFunction("C_Reputation", "GetFactionStandings",
481505
&Script_C_Reputation_GetFactionStandings);
506+
Game::Lua::RegisterTableFunction("C_Reputation", "GetFactionDataByID",
507+
&Script_C_Reputation_GetFactionDataByID);
482508
Game::Lua::RegisterTableFunction("C_Reputation", "GetFactionDataByIndex",
483509
&Script_C_Reputation_GetFactionDataByIndex);
484510
}

0 commit comments

Comments
 (0)