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 committed Oct 23, 2020
1 parent dcf6cd4 commit b72e08e
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 97 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 @@ -242,7 +242,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
152 changes: 68 additions & 84 deletions X2WOTCCommunityHighlander/Src/XComGame/Classes/X2AchievementTracker.uc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static function EventListenerReturn OnTacticalGameEnd(Object EventData, Object E

History = `XCOMHISTORY;
Settings = XComGameState_CampaignSettings(History.GetSingleGameStateObjectForClass(class'XComGameState_CampaignSettings'));
Battle = XComGameState_BattleData(History.GetSingleGameStateObjectForClass(class'XComGameState_BattleData'));
Battle = XComGameState_BattleData(`XCOMHISTORY.GetSingleGameStateObjectForClass(class'XComGameState_BattleData'));

`log("XComGameState_AchievementTracker.OnTacticalGameEnd");

Expand All @@ -180,19 +180,19 @@ static function EventListenerReturn OnTacticalGameEnd(Object EventData, Object E
}

// Recover the Forge Item
if (string(Battle.MapData.ActiveMission.MissionName) == "AdventFacilityFORGE" && !class'X2TacticalGameRulesetDataStructures'.static.TacticalOnlyGameMode())
if (string(Battle.MapData.ActiveMission.MissionName) == "AdventFacilityFORGE")
{
`ONLINEEVENTMGR.UnlockAchievement(AT_RecoverForgeItem);
}

// Recover the Psi Gate
if (string(Battle.MapData.ActiveMission.MissionName) == "AdventFacilityPSIGATE" && !class'X2TacticalGameRulesetDataStructures'.static.TacticalOnlyGameMode())
if (string(Battle.MapData.ActiveMission.MissionName) == "AdventFacilityPSIGATE")
{
`ONLINEEVENTMGR.UnlockAchievement(AT_RecoverPsiGate);
}

// Recover the Black Site Data
if (string(Battle.MapData.ActiveMission.MissionName) == "AdventFacilityBLACKSITE" && !class'X2TacticalGameRulesetDataStructures'.static.TacticalOnlyGameMode())
if (string(Battle.MapData.ActiveMission.MissionName) == "AdventFacilityBLACKSITE")
{
`ONLINEEVENTMGR.UnlockAchievement(AT_RecoverBlackSiteData);
}
Expand Down Expand Up @@ -237,18 +237,6 @@ static function EventListenerReturn OnTacticalGameEnd(Object EventData, Object E
`ONLINEEVENTMGR.UnlockAchievement(AT_BeatMissionNoCivilianDeath);
}
}

if (Battle.m_strDesc == "Skirmish Mode")
{
class'X2TacticalGameRuleset'.static.ReleaseScriptLog("TLE Achievement Awarded: Complete Custom Skirmish");
`ONLINEEVENTMGR.UnlockAchievement(AT_CompleteCustomSkirmish);
}

if ((History.GetSingleGameStateObjectForClass(class'XComGameState_ChallengeData', true) != none) && `ONLINEEVENTMGR.bIsLocalChallengeModeGame)
{
class'X2TacticalGameRuleset'.static.ReleaseScriptLog("TLE Achievement Awarded: Complete Local Challenge");
`ONLINEEVENTMGR.UnlockAchievement(AT_CompleteLocalChallenge);
}

// Check for AT_BeatMissionJuneOrLater - Beat a mission in June or later using only Rookies
AllRookies = true;
Expand Down Expand Up @@ -308,7 +296,7 @@ static function EventListenerReturn OnTacticalGameEnd(Object EventData, Object E
// Recover a Codex Brain
// Once in the mission use "DropUnit Cyberus 1 False". Then kill it and finish the mission.
// Only applicable in the single-player campaign (not MP, not challenge mode)
if (AchievementData.bKilledACyberusThisMission && `XENGINE.IsSinglePlayerGame() && !class'X2TacticalGameRulesetDataStructures'.static.TacticalOnlyGameMode())
if (AchievementData.bKilledACyberusThisMission && `XENGINE.IsSinglePlayerGame() && !(`ONLINEEVENTMGR.bIsChallengeModeGame))
{
`ONLINEEVENTMGR.UnlockAchievement(AT_RecoverCodexBrain);
}
Expand Down Expand Up @@ -481,57 +469,57 @@ static function EventListenerReturn OnWeaponKillType(Object EventData, Object Ev
{
return ELR_NoInterrupt;
}

if (`XENGINE.IsSinglePlayerGame() && !(`ONLINEEVENTMGR.bIsChallengeModeGame))
{
Ability = XComGameState_Ability(EventData);
Ability = XComGameState_Ability(EventData);

History = `XCOMHISTORY;
History = `XCOMHISTORY;

Item = XComGameState_Item(History.GetGameStateForObjectID(Ability.SourceWeapon.ObjectID));
if (Item == none)
return ELR_NoInterrupt;

TemplateName = Item.GetMyTemplateName();
Item = XComGameState_Item(History.GetGameStateForObjectID(Ability.SourceWeapon.ObjectID));
if (Item == none)
return ELR_NoInterrupt;

switch (TemplateName)
{
case 'RocketLauncher':
`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask = `XPROFILESETTINGS.Data.m_HeavyWeaponKillMask | (0x1 << HWK_RocketLauncher);
break;
TemplateName = Item.GetMyTemplateName();

case 'ShredderGun':
`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask = `XPROFILESETTINGS.Data.m_HeavyWeaponKillMask | (0x1 << HWK_ShredderGun);
break;
switch (TemplateName)
{
case 'RocketLauncher':
`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask = `XPROFILESETTINGS.Data.m_HeavyWeaponKillMask | (0x1 << HWK_RocketLauncher);
break;

case 'Flamethrower':
`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask = `XPROFILESETTINGS.Data.m_HeavyWeaponKillMask | (0x1 << HWK_Flamethrower);
break;
case 'ShredderGun':
`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask = `XPROFILESETTINGS.Data.m_HeavyWeaponKillMask | (0x1 << HWK_ShredderGun);
break;

case 'FlamethrowerMk2':
`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask = `XPROFILESETTINGS.Data.m_HeavyWeaponKillMask | (0x1 << HWK_HellfireProjector);
break;
case 'Flamethrower':
`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask = `XPROFILESETTINGS.Data.m_HeavyWeaponKillMask | (0x1 << HWK_Flamethrower);
break;

case 'BlasterLauncher':
`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask = `XPROFILESETTINGS.Data.m_HeavyWeaponKillMask | (0x1 << HWK_BlasterLauncher);
break;
case 'FlamethrowerMk2':
`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask = `XPROFILESETTINGS.Data.m_HeavyWeaponKillMask | (0x1 << HWK_HellfireProjector);
break;

case 'PlasmaBlaster':
`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask = `XPROFILESETTINGS.Data.m_HeavyWeaponKillMask | (0x1 << HWK_PlasmaBlaster);
break;
case 'BlasterLauncher':
`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask = `XPROFILESETTINGS.Data.m_HeavyWeaponKillMask | (0x1 << HWK_BlasterLauncher);
break;

case 'ShredstormCannon':
`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask = `XPROFILESETTINGS.Data.m_HeavyWeaponKillMask | (0x1 << HWK_ShredstormCannon);
break;
}
case 'PlasmaBlaster':
`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask = `XPROFILESETTINGS.Data.m_HeavyWeaponKillMask | (0x1 << HWK_PlasmaBlaster);
break;

// Achievement: Kill an enemy with every heavy weapon in the game (Doesn't have to be in the same game)
if (`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask == ((0x1 << HeavyWeaponKill.EnumCount) - 1))
{
`ONLINEEVENTMGR.UnlockAchievement(AT_KillWithEveryHeavyWeapon);
}
case 'ShredstormCannon':
`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask = `XPROFILESETTINGS.Data.m_HeavyWeaponKillMask | (0x1 << HWK_ShredstormCannon);
break;
}

// Achievement: Kill an enemy with every heavy weapon in the game (Doesn't have to be in the same game)
if (`XPROFILESETTINGS.Data.m_HeavyWeaponKillMask == ((0x1 << HeavyWeaponKill.EnumCount) - 1))
{
`ONLINEEVENTMGR.UnlockAchievement(AT_KillWithEveryHeavyWeapon);
}

`ONLINEEVENTMGR.SaveProfileSettings();
`ONLINEEVENTMGR.SaveProfileSettings();
}

return ELR_NoInterrupt;
Expand Down Expand Up @@ -591,7 +579,7 @@ static function OnUnitDied(XComGameState_Unit Unit, XComGameState NewGameState,

CharacterGroupName = Unit.GetMyTemplate().CharacterGroupName;

if (CharacterGroupName == 'AdventPsiWitch' && !class'X2TacticalGameRulesetDataStructures'.static.TacticalOnlyGameMode())
if (CharacterGroupName == 'AdventPsiWitch')
{
// Achievement: Kill an Avatar
`ONLINEEVENTMGR.UnlockAchievement(AT_KillAvatar);
Expand Down Expand Up @@ -818,12 +806,6 @@ static function FinalMissionOnSuccess()
{
`ONLINEEVENTMGR.UnlockAchievement(AT_WinGameUsingConventionalGear);
}

if (Settings.RequiredDLC.Find( 'TLE' ) != INDEX_NONE)
{
class'X2TacticalGameRuleset'.static.ReleaseScriptLog("TLE Achievement Awarded: Complete Campaign with TLE");
`ONLINEEVENTMGR.UnlockAchievement(AT_CompleTLECampaign);
}
}

// This is called when a unit is skulljacked
Expand Down Expand Up @@ -866,45 +848,44 @@ static function EventListenerReturn OnMissionObjectiveComplete(Object EventData,
local MissionObjectiveDefinition MissionObjective;
local XComGameState_Unit Unit;
local bool IsSquadConcealed;

if (GameState.GetContext( ).InterruptionStatus == eInterruptionStatus_Interrupt)
{
return ELR_NoInterrupt;
}

if (`XENGINE.IsSinglePlayerGame() && !(`ONLINEEVENTMGR.bIsChallengeModeGame))
{
BattleData = XComGameState_BattleData(EventData);
BattleData = XComGameState_BattleData(EventData);

// Reach the objective item in a Guerilla Ops mission with the entire squad still concealed
foreach BattleData.MapData.ActiveMission.MissionObjectives(MissionObjective)
// Reach the objective item in a Guerilla Ops mission with the entire squad still concealed
foreach BattleData.MapData.ActiveMission.MissionObjectives(MissionObjective)
{
if (MissionObjective.bCompleted &&
(string(MissionObjective.ObjectiveName) == "Hack" ||
string(MissionObjective.ObjectiveName) == "Recover" ||
string(MissionObjective.ObjectiveName) == "ProtectDevice" ||
string(MissionObjective.ObjectiveName) == "DestroyObject"))
{
if (MissionObjective.bCompleted &&
(string(MissionObjective.ObjectiveName) == "Hack" ||
string(MissionObjective.ObjectiveName) == "Recover" ||
string(MissionObjective.ObjectiveName) == "ProtectDevice" ||
string(MissionObjective.ObjectiveName) == "DestroyObject"))
IsSquadConcealed = true;
foreach `XCOMHISTORY.IterateByClassType(class'XComGameState_Unit', Unit)
{
IsSquadConcealed = true;
foreach `XCOMHISTORY.IterateByClassType(class'XComGameState_Unit', Unit)
if (Unit.IsPlayerControlled() && Unit.IsSoldier())
{
if (Unit.IsPlayerControlled() && Unit.IsSoldier())
if (!Unit.IsSquadConcealed())
{
if (!Unit.IsSquadConcealed())
{
IsSquadConcealed = false;
break;
}
IsSquadConcealed = false;
break;
}
}
}

if (IsSquadConcealed)
{
`ONLINEEVENTMGR.UnlockAchievement(AT_GuerillaWarfare);
}
if (IsSquadConcealed)
{
`ONLINEEVENTMGR.UnlockAchievement(AT_GuerillaWarfare);
}
}
}
}

return ELR_NoInterrupt;
}
Expand Down Expand Up @@ -943,7 +924,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
Loading

0 comments on commit b72e08e

Please sign in to comment.