Skip to content

Commit

Permalink
Item upgrade improvements (X2CommunityCore#93 & X2CommunityCore#289)
Browse files Browse the repository at this point in the history
Allows any item type to be upgraded, and allows for upgrade slot handling on a per-state basis.

Implements issue X2CommunityCore#93
Implements issue X2CommunityCore#289
  • Loading branch information
GingerAvalanche authored and Iridar51 committed Jan 9, 2021
1 parent ea70fe5 commit f7a6514
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 14 deletions.
16 changes: 13 additions & 3 deletions X2WOTCCommunityHighlander/Src/XComGame/Classes/CHHelpers.uc
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
class CHHelpers extends Object config(Game);

//issue #188 - creating a struct and usable array for modders
//issue #188 - creating a struct for modders
struct TeamRequest
{
var ETeam Team; //eTeam_One and eTeam_Two should be the only ones here.
};

var config array<TeamRequest> ModAddedTeams;
//end issue #188

// Start Issue #93
struct UpgradeSlotHelper
{
var name TemplateName; // Name of the non-X2WeaponTemplate to be assigned slots (X2WeaponTemplates have NumUpgradeSlots on the template)
var int NumUpgradeSlots; // The number of slots to assign
};
// End Issue #93

var config array<TeamRequest> ModAddedTeams; //issue #188 - creating a usable array for modders

var config array<UpgradeSlotHelper> NonWeaponUpgradeSlots; // Issue #93 - configure upgrade slots for templates

var config int SPAWN_EXTRA_TILE; // Issue #18 - Add extra ini config
var config int MAX_TACTICAL_AUTOSAVES; // Issue #53 - make configurable, only use if over 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ simulated function UpdateSlots()
// Get equipped upgrades
EquippedUpgrades = Weapon.GetMyWeaponUpgradeTemplates();
WeaponTemplate = X2WeaponTemplate(Weapon.GetMyTemplate());
NumUpgradeSlots = WeaponTemplate.NumUpgradeSlots;
// Start Issue #93
//NumUpgradeSlots = WeaponTemplate.NumUpgradeSlots;
NumUpgradeSlots = Weapon.GetNumUpgradeSlots();
// End Issue #93

if (XComHQ.bExtraWeaponUpgrade)
NumUpgradeSlots++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ simulated function PopulateUpgradePanel( int Index, X2LadderUpgradeTemplate Upgr
}
WeaponTemplate = X2WeaponTemplate(primaryWeaponItem.GetMyTemplate());

bAddLine = WeaponTemplate != none && WeaponTemplate.NumUpgradeSlots > 0 && ItemUpgradeTemplate.CanApplyUpgradeToWeapon(primaryWeaponItem);
// Single line for Issue #93
bAddLine = WeaponTemplate != none && WeaponTemplate.GetNumUpgradeSlots() > 0 && ItemUpgradeTemplate.CanApplyUpgradeToWeapon(primaryWeaponItem);

//
ParamTag.StrValue0 = ClassTemplate.DisplayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,10 @@ simulated static function GetWeaponUpgradeAvailability(XComGameState_Unit Unit,
WeaponTemplate = X2WeaponTemplate(PrimaryWeapon.GetMyTemplate());
// Single line for Issue #306
EquippedUpgrades = PrimaryWeapon.GetMyWeaponUpgradeCount();
AvailableSlots = WeaponTemplate.NumUpgradeSlots;
// Start Issue #93
//AvailableSlots = WeaponTemplate.NumUpgradeSlots;
AvailableSlots = PrimaryWeapon.GetNumUpgradeSlots();
// End Issue #93

// Only add extra slots if the weapon had some to begin with
if (AvailableSlots > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,10 @@ static function EventListenerReturn OnWeaponUpgraded(Object EventData, Object Ev
{
UpgradeTemplates = WeaponState.GetMyWeaponUpgradeTemplates();

NumUpgradeSlots = WeaponTemplate.NumUpgradeSlots;
// Start Issue #93
//NumUpgradeSlots = WeaponTemplate.NumUpgradeSlots;
NumUpgradeSlots = WeaponState.GetNumUpgradeSlots();
// End Issue #93
if (XComHQ.bExtraWeaponUpgrade)
NumUpgradeSlots++;
if (XComHQ.ExtraUpgradeWeaponCats.Find(WeaponTemplate.WeaponCat) != INDEX_NONE)
Expand Down
24 changes: 24 additions & 0 deletions X2WOTCCommunityHighlander/Src/XComGame/Classes/X2ItemTemplate.uc
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,30 @@ function bool CanBeLootedByUnit(XComGameState_Item LootItem, XComGameState_Unit
return true;
}

// Start Issue #93
function int GetNumUpgradeSlots()
{
local X2WeaponTemplate SelfAsWeapon;
local int idx;

SelfAsWeapon = X2WeaponTemplate(self);

if (SelfAsWeapon != none)
{
return SelfAsWeapon.NumUpgradeSlots;
}

idx = class'CHHelpers'.default.NonWeaponUpgradeSlots.Find('TemplateName', DataName);

if (idx != INDEX_NONE)
{
return class'CHHelpers'.default.NonWeaponUpgradeSlots[idx].NumUpgradeSlots;
}

return 0;
}
// End Issue #93

DefaultProperties
{
iItemSize=1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4651,6 +4651,17 @@ static function UpgradeItems(XComGameState NewGameState, name CreatorTemplateNam
if (!XComHQ.HasItem(UpgradeItemTemplate))
{
UpgradedItemState = UpgradeItemTemplate.CreateInstanceFromTemplate(NewGameState);
// Issue #289 - handle upgrades for infinite items
/// HL-Docs: feature:ItemUpgraded; issue:289; tags:strategy,events
/// This is an event that allows mods to perform non-standard handling to item states
/// when they are upgraded to a new tier. It is fired up to four times during upgrading:
/// * When upgrading the infinite item, if any.
/// * When upgrading utility items, like grenades and medkits.
/// * When upgrading unequipped items that have attachments
/// * When upgrading equipped items that have attachments
///
/// The infinite item upgrade is the only firing that does not contain an EventData
`XEVENTMGR.TriggerEvent('ItemUpgraded', UpgradedItemState, none, NewGameState);
XComHQ.AddItemToHQInventory(UpgradedItemState);
}
}
Expand All @@ -4668,6 +4679,7 @@ static function UpgradeItems(XComGameState NewGameState, name CreatorTemplateNam
// Otherwise match the base items quantity
UpgradedItemState = UpgradeItemTemplate.CreateInstanceFromTemplate(NewGameState);
UpgradedItemState.Quantity = BaseItemState.Quantity;
`XEVENTMGR.TriggerEvent('ItemUpgraded', UpgradedItemState, BaseItemState, NewGameState); // Issue #289 - handle upgrades for utility items like grenades and medkits

// Then add the upgrade item and remove all of the base items from the inventory
XComHQ.PutItemInInventory(NewGameState, UpgradedItemState);
Expand Down Expand Up @@ -4703,6 +4715,7 @@ static function UpgradeItems(XComGameState NewGameState, name CreatorTemplateNam
UpgradedItemState.ApplyWeaponUpgradeTemplate(WeaponUpgradeTemplate);
}
}
`XEVENTMGR.TriggerEvent('ItemUpgraded', UpgradedItemState, InventoryItemState, NewGameState); // Issue #289 - handle upgrades for unequipped items with attachments

// Delete the old item, and add the new item to the inventory
NewGameState.RemoveStateObject(InventoryItemState.GetReference().ObjectID);
Expand Down Expand Up @@ -4747,6 +4760,7 @@ static function UpgradeItems(XComGameState NewGameState, name CreatorTemplateNam
UpgradedItemState.ApplyWeaponUpgradeTemplate(WeaponUpgradeTemplate);
}
}
`XEVENTMGR.TriggerEvent('ItemUpgraded', UpgradedItemState, InventoryItemState, NewGameState); // Issue #289 - handle upgrades for equipped items with attachments

// Delete the old item
NewGameState.RemoveStateObject(InventoryItemState.GetReference().ObjectID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,8 @@ simulated function bool HasBeenModified()

WeaponTemplate = X2WeaponTemplate( m_ItemTemplate );

// Single line for Issue #306
if ((WeaponTemplate != none) && (WeaponTemplate.NumUpgradeSlots > 0) && (GetMyWeaponUpgradeCount() > 0))
// Single line for Issues #93 and #306
if ((WeaponTemplate != none) && (GetNumUpgradeSlots() > 0) && (GetMyWeaponUpgradeCount() > 0))
return true;

return false;
Expand Down Expand Up @@ -2392,9 +2392,42 @@ function bool IsMissionObjectiveItem()
return false;
}
// Start Issue #93
/// HL-Docs: feature:OverrideNumUpgradeSlots; issue:93; tags:strategy,events
/// This is an event that mods can listen for which will allow them to
/// modify upgrade slots on a per-gamestate basis.
///
/// In general, it should only be used if you have some type of handling that allows
/// individual items to be customized in a way others of their type cannot.
function int GetNumUpgradeSlots()
{
local Object ThisObj;
local XComLWTuple Tuple;
ThisObj = self;
Tuple = new class'XComLWTuple';
Tuple.Id = 'OverrideNumUpgradeSlots';
Tuple.Data.Add(1);
Tuple.Data[0].kind = XComLWTVInt;
Tuple.Data[0].i = GetMyTemplate().GetNumUpgradeSlots();
`XEVENTMGR.TriggerEvent('OverrideNumUpgradeSlots', Tuple, ThisObj);
return Tuple.Data[0].i;
}
// End Issue #93
// Issue #260 start
// This function will be used to cycle through DLCInfos that will allow mods to check generally whether or not a weapon is compatible with an upgrade
// X2WeaponUpgradeTemplate::CanApplyUpgradeToWeapon still exists as the "can this upgrade be applied to this weapon RIGHT NOW?"
/// HL-Docs: feature:CanWeaponApplyUpgrade; issue:260; tags:strategy,dlcinfo
/// This function will be used to cycle through DLCInfos that will allow mods to check generally
/// whether or not a weapon is compatible with an upgrade. X2WeaponUpgradeTemplate::CanApplyUpgradeToWeapon
/// still exists as the "can this upgrade be applied to this weapon RIGHT NOW?"
///
/// * The best use case for this is to bar your weapon from applying upgrades that don't meet your criteria,
/// without having to edit those upgrades directly.
/// * Note that this check is /in addition to/, and not /in lieu of/, CanApplyUpgradeToWeapon. This means
/// you cannot use it to override that function's return value.
function bool CanWeaponApplyUpgrade(X2WeaponUpgradeTemplate UpgradeTemplate)
{
local int i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ private static function UpdateUnitState( XComGameState StartState, XComGameState
PrimaryWeapon = UnitState.GetPrimaryWeapon( );
PrimaryWeapon = XComGameState_Item( StartState.GetGameStateForObjectID( PrimaryWeapon.ObjectID ) );
WeaponTemplate = X2WeaponTemplate( PrimaryWeapon.GetMyTemplate( ) );
if (WeaponTemplate.NumUpgradeSlots > 0)
if (WeaponTemplate.GetNumUpgradeSlots() > 0) // Single line for Issue #93
PrimaryWeapon.WipeUpgradeTemplates( );

ItemManager = class'X2ItemTemplateManager'.static.GetItemTemplateManager();
Expand Down Expand Up @@ -1151,7 +1151,7 @@ private static function UpdateUnitState( XComGameState StartState, XComGameState
SwapUtilityItem( StartState, UnitState, ItemName, 1 );
}
}
else if ((WeaponUpgradeTemplate != none) && (WeaponTemplate.NumUpgradeSlots > 0))
else if ((WeaponUpgradeTemplate != none) && (WeaponTemplate.GetNumUpgradeSlots() > 0)) // Single line for Issue #93
{
WeaponUpgrades = PrimaryWeapon.GetMyWeaponUpgradeTemplateNames( );

Expand All @@ -1166,7 +1166,7 @@ private static function UpdateUnitState( XComGameState StartState, XComGameState

if (index == WeaponUpgrades.Length)
{
if (index < WeaponTemplate.NumUpgradeSlots)
if (index < WeaponTemplate.GetNumUpgradeSlots()) // Single line for Issue #93
{
PrimaryWeapon.ApplyWeaponUpgradeTemplate( WeaponUpgradeTemplate );
}
Expand Down
13 changes: 13 additions & 0 deletions docs_src/docs/dlcinfo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h1>X2DownloadableContentInfo Hooks</h1>

Many of the Highlander's features utilize function calls to the subclasses of
X2DownloadableContentInfo that all mods require. These are known colloquially
as DlcInfo hooks, and are commonly used as an alternative when an event will
not work for a given feature.

Mods can define a function of the same name with the same arguments in their
X2DownloadableContentInfo file, and then perform any custom handling.

Unlike events, these DlcInfo hooks are not limited to two arguments. However,
they are much slower than events are, so events should generally be used.

0 comments on commit f7a6514

Please sign in to comment.