Skip to content

Commit

Permalink
X2CommunityCore#275 Moves loot helper methods to X2LootTable and adds…
Browse files Browse the repository at this point in the history
… remove helper methods
  • Loading branch information
Musashi1584 committed Aug 14, 2017
1 parent 8d26c08 commit 8704811
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 48 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", "{BC03F5F5-F2DA-40ED-BC11-78049036FC68}"
Project("{5DAE07AF-E217-45C1-8DE7-FF99D6011E8A}") = "X2CommunityHighlander", "X2CommunityHighlander\X2CommunityHighlander.x2proj", "{7AD29FBC-D864-4EAF-B8E6-2D3E5CECE537}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|XCOM 2 = Debug|XCOM 2
Default|XCOM 2 = Default|XCOM 2
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BC03F5F5-F2DA-40ED-BC11-78049036FC68}.Debug|XCOM 2.ActiveCfg = Debug|XCOM 2
{BC03F5F5-F2DA-40ED-BC11-78049036FC68}.Debug|XCOM 2.Build.0 = Debug|XCOM 2
{BC03F5F5-F2DA-40ED-BC11-78049036FC68}.Default|XCOM 2.ActiveCfg = Debug|XCOM 2
{BC03F5F5-F2DA-40ED-BC11-78049036FC68}.Default|XCOM 2.Build.0 = Debug|XCOM 2
{7AD29FBC-D864-4EAF-B8E6-2D3E5CECE537}.Debug|XCOM 2.ActiveCfg = Debug|XCOM 2
{7AD29FBC-D864-4EAF-B8E6-2D3E5CECE537}.Debug|XCOM 2.Build.0 = Debug|XCOM 2
{7AD29FBC-D864-4EAF-B8E6-2D3E5CECE537}.Default|XCOM 2.ActiveCfg = Debug|XCOM 2
{7AD29FBC-D864-4EAF-B8E6-2D3E5CECE537}.Default|XCOM 2.Build.0 = Debug|XCOM 2
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
40 changes: 0 additions & 40 deletions X2CommunityHighlander/Src/XComGame/Classes/LootTableHelper.uc

This file was deleted.

106 changes: 106 additions & 0 deletions X2CommunityHighlander/Src/XComGame/Classes/X2LootTable.uc
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,109 @@ var private native Map_Mirror LootTablesMap{TMap<FName, INT>}; //
native function InitLootTables(bool bValidateItemNames=true); // validates loot tables and sets up LootTablesMap
native function RollForLootTable(const out name LootTableName, out array<name> RolledLoot);

// Start Issue #275 - Add a loot table interface
// static function are for use in the DLCInfo OnPostTemplatesCreated event
public function AddEntryAndReload(name TableName, LootTableEntry AddTableEntry)
{
AddEntry(TableName, AddTableEntry);
InitLootTables();
}

public function RemoveEntryAndReload(name TableName, LootTableEntry TableEntry)
{
RemoveEntry(TableName, TableEntry);
InitLootTables();
}

public function AddLootTableAndReload(LootTable AddLootTable)
{
local LootTableEntry Loot;
foreach AddLootTable.Loots(Loot)
{
AddEntry(AddLootTable.TableName, Loot);
}
InitLootTables();
}

public function RemoveLootTableAndReload(LootTable LootTable)
{
RemoveLootTable(LootTable);
InitLootTables();
}

public static function AddLootTable(LootTable AddLootTable)
{
local LootTableEntry Loot;
foreach AddLootTable.Loots(Loot)
{
AddEntry(AddLootTable.TableName, Loot);
}
}

public static function RemoveLootTable(LootTable RemoveLootTable)
{
local X2LootTable LootTable;

LootTable = X2LootTable(class'Engine'.static.FindClassDefaultObject(string(default.Class.Name)));
LootTable.LootTables.RemoveItem(RemoveLootTable);
}

public static function AddEntryToLootTable(name TableName, LootTableEntry AddTableEntry)
{
AddEntry(TableName, AddTableEntry);
}

private static function RemoveEntry(name TableName, LootTableEntry TableEntry)
{
local X2LootTable LootTable;
local int Index;

LootTable = X2LootTable(class'Engine'.static.FindClassDefaultObject(string(default.Class.Name)));

Index = LootTable.LootTables.Find('TableName', TableName);

if (Index != INDEX_NONE)
{
LootTable.LootTables[Index].Loots.RemoveItem(TableEntry);
}
}

// When the sum of chances is greater 100% after adding an entry, recalculate chances to 100% total
private static function AddEntry(name TableName, LootTableEntry AddTableEntry)
{
local X2LootTable LootTable;
local LootTableEntry TableEntry;
local int Index, OldChance, NewChance, SumChances, TableEntryIndex;

LootTable = X2LootTable(class'Engine'.static.FindClassDefaultObject(string(default.Class.Name)));
`LOG(string(default.Class.Name) @ LootTable);

Index = LootTable.LootTables.Find('TableName', TableName);

if (Index != INDEX_NONE)
{
// Add the new table entry
LootTable.LootTables[Index].Loots.AddItem(AddTableEntry);

// Recalculate the chances
foreach LootTable.LootTables[Index].Loots(TableEntry)
{
if (TableEntry.RollGroup == AddTableEntry.RollGroup)
SumChances += TableEntry.Chance;
}

if (SumChances > 100)
{
for (TableEntryIndex = 0; TableEntryIndex < LootTable.LootTables[Index].Loots.Length; TableEntryIndex++)
{
if (LootTable.LootTables[Index].Loots[TableEntryIndex].RollGroup == AddTableEntry.RollGroup)
{
OldChance = LootTable.LootTables[Index].Loots[TableEntryIndex].Chance;
NewChance = Round(100 / SumChances * OldChance);
LootTable.LootTables[Index].Loots[TableEntryIndex].Chance = NewChance;
}
}
}
}
}
// End Issue #275
3 changes: 0 additions & 3 deletions X2CommunityHighlander/X2CommunityHighlander.x2proj
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
<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 8704811

Please sign in to comment.