Skip to content

Commit

Permalink
Added generic helper for loot tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
Musashi1584 committed Aug 13, 2017
1 parent 5e173c0 commit c961aa6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
10 changes: 5 additions & 5 deletions X2CommunityHighlander.XCOM_sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# XCOM ModBuddy Solution File, Format Version 11.00
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{5DAE07AF-E217-45C1-8DE7-FF99D6011E8A}") = "X2CommunityHighlander", "X2CommunityHighlander\X2CommunityHighlander.x2proj", "{6671DE85-5595-469A-9B54-28A003DEFE77}"
Project("{5DAE07AF-E217-45C1-8DE7-FF99D6011E8A}") = "X2CommunityHighlander", "X2CommunityHighlander\X2CommunityHighlander.x2proj", "{2B0DCA36-C993-41FB-8A29-C4670602A0B5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|XCOM 2 = Debug|XCOM 2
Default|XCOM 2 = Default|XCOM 2
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6671DE85-5595-469A-9B54-28A003DEFE77}.Debug|XCOM 2.ActiveCfg = Debug|XCOM 2
{6671DE85-5595-469A-9B54-28A003DEFE77}.Debug|XCOM 2.Build.0 = Debug|XCOM 2
{6671DE85-5595-469A-9B54-28A003DEFE77}.Default|XCOM 2.ActiveCfg = Debug|XCOM 2
{6671DE85-5595-469A-9B54-28A003DEFE77}.Default|XCOM 2.Build.0 = Debug|XCOM 2
{2B0DCA36-C993-41FB-8A29-C4670602A0B5}.Debug|XCOM 2.ActiveCfg = Debug|XCOM 2
{2B0DCA36-C993-41FB-8A29-C4670602A0B5}.Debug|XCOM 2.Build.0 = Debug|XCOM 2
{2B0DCA36-C993-41FB-8A29-C4670602A0B5}.Default|XCOM 2.ActiveCfg = Debug|XCOM 2
{2B0DCA36-C993-41FB-8A29-C4670602A0B5}.Default|XCOM 2.Build.0 = Debug|XCOM 2
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
41 changes: 41 additions & 0 deletions X2CommunityHighlander/Src/XComGame/Classes/LootTableHelper.uc
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);
}
}
3 changes: 3 additions & 0 deletions X2CommunityHighlander/X2CommunityHighlander.x2proj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<Content Include="Src\XComGame\Classes\Helpers_LW.uc">
<SubType>Content</SubType>
</Content>
<Content Include="Src\XComGame\Classes\LootTableHelper.uc">
<SubType>Content</SubType>
</Content>
<Content Include="Src\XComGame\Classes\LWUtilities_Ranks.uc">
<SubType>Content</SubType>
</Content>
Expand Down

0 comments on commit c961aa6

Please sign in to comment.