Skip to content

Commit

Permalink
Issue X2CommunityCore#275 Provide a loot helper class
Browse files Browse the repository at this point in the history
  • Loading branch information
Musashi1584 committed Aug 13, 2017
1 parent c961aa6 commit 4a3cd92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 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", "{2B0DCA36-C993-41FB-8A29-C4670602A0B5}"
Project("{5DAE07AF-E217-45C1-8DE7-FF99D6011E8A}") = "X2CommunityHighlander", "X2CommunityHighlander\X2CommunityHighlander.x2proj", "{831439B0-C5B9-453D-8742-5BFA39F4B691}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|XCOM 2 = Debug|XCOM 2
Default|XCOM 2 = Default|XCOM 2
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{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
{831439B0-C5B9-453D-8742-5BFA39F4B691}.Debug|XCOM 2.ActiveCfg = Debug|XCOM 2
{831439B0-C5B9-453D-8742-5BFA39F4B691}.Debug|XCOM 2.Build.0 = Debug|XCOM 2
{831439B0-C5B9-453D-8742-5BFA39F4B691}.Default|XCOM 2.ActiveCfg = Debug|XCOM 2
{831439B0-C5B9-453D-8742-5BFA39F4B691}.Default|XCOM 2.Build.0 = Debug|XCOM 2
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
27 changes: 13 additions & 14 deletions X2CommunityHighlander/Src/XComGame/Classes/LootTableHelper.uc
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,39 @@ class LootTableHelper extends Object;

static function AddEntryToLootTable(name TableName, LootTableEntry AddTableEntry)
{
local X2LootTable LootTableCDO;
local X2LootTableManager LootManager;
local LootTableEntry TableEntry;
local int Index, TableEntryIndex;
local array<int> SumChances;
local int NewSumChances, OldChance;
local int NewSumChances, OldChance, SumChances;

LootTableCDO = X2LootTable (class'Engine'.static.FindClassDefaultObject("X2LootTable"));
LootManager = X2LootTableManager(class'Engine'.static.FindClassDefaultObject("X2LootTableManager"));

Index = LootTableCDO.default.LootTables.Find('TableName', TableName);
Index = LootManager.default.LootTables.Find('TableName', TableName);

if (Index != INDEX_NONE)
{
foreach LootTableCDO.default.LootTables[Index].Loots(TableEntry)
foreach LootManager.default.LootTables[Index].Loots(TableEntry)
{
SumChances[TableEntry.RollGroup] += TableEntry.Chance;
if (TableEntry.RollGroup == AddTableEntry.RollGroup)
SumChances += TableEntry.Chance;
}

// Recalculate the chances
NewSumChances = SumChances[AddTableEntry.RollGroup] + AddTableEntry.Chance;
NewSumChances = SumChances + AddTableEntry.Chance;
if (NewSumChances > 0)
{
for (TableEntryIndex = 0; TableEntryIndex < LootTableCDO.default.LootTables[Index].Loots.Length; TableEntryIndex++)
for (TableEntryIndex = 0; TableEntryIndex < LootManager.default.LootTables[Index].Loots.Length; TableEntryIndex++)
{
if (LootTableCDO.default.LootTables[Index].Loots[TableEntryIndex].RollGroup == AddTableEntry.RollGroup)
if (LootManager.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);

OldChance = LootManager.default.LootTables[Index].Loots[TableEntryIndex].Chance;
LootManager.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);
LootManager.default.LootTables[Index].Loots.AddItem(AddTableEntry);
}
}

0 comments on commit 4a3cd92

Please sign in to comment.