forked from X2CommunityCore/X2CommunityHighlander
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added generic helper for loot tables.
- Loading branch information
1 parent
5e173c0
commit c961aa6
Showing
3 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
X2CommunityHighlander/Src/XComGame/Classes/LootTableHelper.uc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
class LootTableHelper extends Object; | ||
|
||
static function AddEntryToLootTable(name TableName, LootTableEntry AddTableEntry) | ||
{ | ||
local X2LootTable LootTableCDO; | ||
local LootTableEntry TableEntry; | ||
local int Index, TableEntryIndex; | ||
local array<int> SumChances; | ||
local int NewSumChances, OldChance; | ||
|
||
LootTableCDO = X2LootTable (class'Engine'.static.FindClassDefaultObject("X2LootTable")); | ||
|
||
Index = LootTableCDO.default.LootTables.Find('TableName', TableName); | ||
|
||
if (Index != INDEX_NONE) | ||
{ | ||
foreach LootTableCDO.default.LootTables[Index].Loots(TableEntry) | ||
{ | ||
SumChances[TableEntry.RollGroup] += TableEntry.Chance; | ||
} | ||
|
||
// Recalculate the chances | ||
NewSumChances = SumChances[AddTableEntry.RollGroup] + AddTableEntry.Chance; | ||
if (NewSumChances > 0) | ||
{ | ||
for (TableEntryIndex = 0; TableEntryIndex < LootTableCDO.default.LootTables[Index].Loots.Length; TableEntryIndex++) | ||
{ | ||
if (LootTableCDO.default.LootTables[Index].Loots[TableEntryIndex].RollGroup == AddTableEntry.RollGroup) | ||
{ | ||
OldChance = LootTableCDO.default.LootTables[Index].Loots[TableEntryIndex].Chance; | ||
LootTableCDO.default.LootTables[Index].Loots[TableEntryIndex].Chance = Round(100 / NewSumChances * OldChance); | ||
|
||
} | ||
} | ||
AddTableEntry.Chance = Round(100 / NewSumChances * AddTableEntry.Chance); | ||
} | ||
|
||
// Add the new table entry | ||
LootTableCDO.default.LootTables[Index].Loots.AddItem(AddTableEntry); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters