Skip to content

Commit

Permalink
Refactoring and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alphanin9 committed Nov 22, 2024
1 parent 5c4e8a4 commit 3dff747
Show file tree
Hide file tree
Showing 24 changed files with 123 additions and 224 deletions.
2 changes: 1 addition & 1 deletion scripting/NGPlusBugfixing.reds
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class NGPlusEP1StatusListener extends ScriptableSystem {
let ngPlusSystem = GameInstance.GetNewGamePlusSystem();
// Fix: Encounter testing no longer triggers EP1 activation
if ngPlusSystem.IsInNewGamePlusSave() {
if ngPlusSystem.IsInNewGamePlusPrologue() || ngPlusSystem.IsInNewGamePlusHeistOrStandalone() {
ngPlusSystem.Spew("EP1 installed, but not activated: loading...");
ngPlusSystem.LoadExpansionIntoSave();
}
Expand Down
1 change: 1 addition & 0 deletions scripting/NGPlusButtonAdder.reds
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ private func AddMenuItem(const label: script_ref<String>, spawnEvent: CName) ->
// Assuming no modifications, the only call with OnNewGame as an arg should be from singleplayer menu
if Equals(spawnEvent, n"OnNewGame") {
// Make this async and recall PopulateMenuItems
if !GameInstance.GetNewGamePlusSystem().HasPointOfNoReturnSave() {
return;
}
Expand Down
29 changes: 17 additions & 12 deletions scripting/NGPlusCharacterInitialStats.reds
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ private final func SetNGPlusAttributePreset() -> Void {
protected cb func OnInitialize() -> Bool {
let ngPlusSystem = GameInstance.GetNewGamePlusSystem();
let isNgPlusActive = ngPlusSystem.GetNewGamePlusState();
let isStandalone = ngPlusSystem.GetStandaloneState();
let ngPlusQuest = ngPlusSystem.GetNewGamePlusQuest();
let isNgPlusActive = Equals(ngPlusQuest, ENGPlusType.StartFromQ001) || Equals(ngPlusQuest, ENGPlusType.StartFromQ101);
let isStandalone = Equals(ngPlusQuest, ENGPlusType.StartFromQ101_ProgressionBuild);
super.OnInitialize();
inkWidgetRef
Expand Down Expand Up @@ -91,8 +94,10 @@ let m_ngPlusSaveData: ref<NGPlusProgressionData>;

@wrapMethod(CharacterCreationStatsMenu)
protected cb func OnInitialize() -> Bool {
this.m_isNgPlusActive = GameInstance.GetNewGamePlusSystem().GetNewGamePlusState();
this.m_ngPlusSaveData = GameInstance.GetNewGamePlusSystem().GetProgressionData();
let ngPlusSystem = GameInstance.GetNewGamePlusSystem();
let ngPlusQuest = ngPlusSystem.GetNewGamePlusQuest();
this.m_isNgPlusActive = Equals(ngPlusQuest, ENGPlusType.StartFromQ001) || Equals(ngPlusQuest, ENGPlusType.StartFromQ101);
this.m_ngPlusSaveData = ngPlusSystem.GetProgressionData();
return wrappedMethod();
}
Expand Down Expand Up @@ -127,14 +132,14 @@ private final func ResetAllBtnBackToBaseline() -> Void {
i += 1;
}
if this.m_isNgPlusActive {
let minAttributeValue = 3.0;
let minAttributeValue = 3;
let statsSystemResults = this.m_ngPlusSaveData.GetStatsSystemResults();
let bodyAttributeAdded: Int32 = Cast<Int32>(statsSystemResults.GetBody() - minAttributeValue);
let reflexAttributeAdded: Int32 = Cast<Int32>(statsSystemResults.GetReflexes() - minAttributeValue);
let techAttributeAdded: Int32 = Cast<Int32>(statsSystemResults.GetTechnicalAbility() - minAttributeValue);
let intAttributeAdded: Int32 = Cast<Int32>(statsSystemResults.GetIntelligence() - minAttributeValue);
let coolAttributeAdded: Int32 = Cast<Int32>(statsSystemResults.GetCool() - minAttributeValue);
let bodyAttributeAdded: Int32 = Cast<Int32>(statsSystemResults.GetBody()) - minAttributeValue;
let reflexAttributeAdded: Int32 = Cast<Int32>(statsSystemResults.GetReflexes()) - minAttributeValue;
let techAttributeAdded: Int32 = Cast<Int32>(statsSystemResults.GetTechnicalAbility()) - minAttributeValue;
let intAttributeAdded: Int32 = Cast<Int32>(statsSystemResults.GetIntelligence()) - minAttributeValue;
let coolAttributeAdded: Int32 = Cast<Int32>(statsSystemResults.GetCool()) - minAttributeValue;
this.m_startingAttributePoints = bodyAttributeAdded
+ reflexAttributeAdded
Expand Down Expand Up @@ -162,7 +167,7 @@ protected cb func OnInitialize() -> Bool {
let attributeType: gamedataStatType;
super.OnInitialize();
this.RequestCameraChange(n"Summary_Preview");
if this.m_characterCustomizationState.IsExpansionStandalone() || GameInstance.GetNewGamePlusSystem().GetStandaloneState() {
if this.m_characterCustomizationState.IsExpansionStandalone() || Equals(GameInstance.GetNewGamePlusSystem().GetNewGamePlusQuest(), ENGPlusType.StartFromQ101_ProgressionBuild) {
this.SkipStatsMenu();
}
attributeType = gamedataStatType.Strength;
Expand Down Expand Up @@ -279,7 +284,7 @@ protected cb func OnInitialize() -> Bool {

@replaceMethod(characterCreationSummaryMenu)
protected cb func OnInitialize() -> Bool {
let isStandalone = this.m_characterCustomizationState.IsExpansionStandalone() || GameInstance.GetNewGamePlusSystem().GetStandaloneState();
let isStandalone = this.m_characterCustomizationState.IsExpansionStandalone() || Equals(GameInstance.GetNewGamePlusSystem().GetNewGamePlusQuest(), ENGPlusType.StartFromQ101_ProgressionBuild);
super.OnInitialize();
this.SetUpLifePath();
Expand Down
2 changes: 0 additions & 2 deletions scripting/NGPlusOnReadyForEquipment.reds
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module NGPlus.PlayerProgression

import NGPlus.SpawnTags.NewGamePlusSpawnTagController
import NGPlus.EP1Listener.NGPlusEP1StatusListener
import NGPlus.Ripperdoc.NGPlusTutorialCyberwareProvider

Expand Down Expand Up @@ -69,7 +68,6 @@ class PlayerProgressionLoader {
let playerDevelopmentData = PlayerDevelopmentSystem.GetInstance(player).GetDevelopmentData(player);
playerDevelopmentData.ScaleNPCsToPlayerLevel();
NewGamePlusSpawnTagController.RestoreSpawnTags();
NGPlusEP1StatusListener.ApplyRandomEncounterDisabler(questsSystem);
this.m_ngPlusSystem.Spew("PlayerProgressionLoader::LoadPlayerProgression done!");
Expand Down
1 change: 1 addition & 0 deletions scripting/NGPlusPlayerDevelopmentData.reds
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module NGPlus.PlayerDevelopmentData
@addField(PlayerDevelopmentData)
let m_isInNgPlus: Bool;

// TODO: make this compatible with Replay - eventually
@replaceMethod(PlayerDevelopmentData)
private const final func ModifyProficiencyLevel(proficiencyIndex: Int32, isDebug: Bool, opt levelIncrease: Int32) -> Void {
let Blackboard: ref<IBlackboard>;
Expand Down
28 changes: 0 additions & 28 deletions scripting/NGPlusSpawnTagController.reds

This file was deleted.

32 changes: 32 additions & 0 deletions scripting/NGPlusStartNewGameReplacer.reds
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

@replaceMethod(characterCreationSummaryMenu)
protected cb func OnOutroComplete(anim: ref<inkAnimProxy>) {
let ccSystem = this.GetCharacterCustomizationSystem();
ccSystem.FinalizeState();
let ngPlusSystem = GameInstance.GetNewGamePlusSystem();
let ngPlusQuest = ngPlusSystem.GetNewGamePlusQuest();
if NotEquals(ngPlusQuest, ENGPlusType.Count) && NotEquals(ngPlusQuest, ENGPlusType.Invalid) {
// Fairly safe cast, no other derivatives
ngPlusSystem.Spew(s"Starting NG+ playthrough with quest type \(ngPlusQuest)...");
ngPlusSystem
.LaunchNewGamePlus(
this.m_characterCustomizationState as gameuiCharacterCustomizationState
);
} else {
this
.GetSystemRequestsHandler()
.StartNewGame(this.m_characterCustomizationState);
if this.m_characterCustomizationState.IsExpansionStandalone() {
this.GetTelemetrySystem().LogPlaythroughEp1();
}
}
this
.GetTelemetrySystem()
.LogInitialChoiceSetStatege(telemetryInitalChoiceStage.Finished);
this.GetTelemetrySystem().LogNewGameStarted();
super.NextMenu();
}
29 changes: 13 additions & 16 deletions scripting/NewGamePlusSystem.reds
Original file line number Diff line number Diff line change
Expand Up @@ -114,30 +114,21 @@ public native class NGPlusProgressionData extends IScriptable {
}
// End aggregator

enum ENewGamePlusStartType {
enum ENGPlusType {
StartFromQ001 = 0,
StartFromQ101 = 1,
StartFromQ001_NoEP1 = 2,
StartFromQ101_NoEP1 = 3,
StartFromQ101_ProgressionBuild = 4,
StartFromQ101_ProgressionBuild_NoEP1 = 5,
Count = 6,
Invalid = 7
StartFromQ101_ProgressionBuild = 2,
Count = 3,
Invalid = 4
}

public native class NewGamePlusSystem extends IGameSystem {
public native func HasPointOfNoReturnSave() -> Bool;
public native func ParsePointOfNoReturnSaveData(saveName: script_ref<String>) -> Bool;
public native func GetNewGamePlusState() -> Bool;
public native func SetNewGamePlusState(newState: Bool) -> Void;
public native func GetProgressionData() -> ref<NGPlusProgressionData>;
public native func SetNewGamePlusGameDefinition(startType: ENewGamePlusStartType) -> Void ;
public native func IsSaveValidForNewGamePlus(saveName: script_ref<String>) -> Bool;
public native func ResolveNewGamePlusSaves(saves: script_ref<[String]>) -> [Int32];
Expand All @@ -148,10 +139,16 @@ public native class NewGamePlusSystem extends IGameSystem {
public native func Spew(str: script_ref<String>) -> Void;
public native func Error(str: script_ref<String>) -> Void;
public native func GetStandaloneState() -> Bool;
public native func SetStandaloneState(aNewState: Bool) -> Void;
public native func IsInNewGamePlusSave() -> Bool;
public native func IsInNewGamePlusPrologue() -> Bool;
public native func IsInNewGamePlusHeistOrStandalone() -> Bool;
// Used in place of StartNewGame, starts new session with selected game definition
public native func LaunchNewGamePlus(state: ref<gameuiCharacterCustomizationState>) -> Void;
// Used in place of SetNewGamePlusState() and SetStandaloneState()
public native func SetNewGamePlusQuest(type: ENGPlusType) -> Void;
public native func GetNewGamePlusQuest() -> ENGPlusType;
}

@addMethod(GameInstance)
Expand Down
20 changes: 3 additions & 17 deletions scripting/Scenario/NGPlusController.reds
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import NGPlus.SpawnTags.NewGamePlusSpawnTagController

public class NewGamePlusSelectionController extends gameuiSaveHandlingController {
private let m_list: inkCompoundRef;
private let m_noSavedGamesLabel: inkWidgetRef;
Expand Down Expand Up @@ -28,10 +26,6 @@ public class NewGamePlusSelectionController extends gameuiSaveHandlingController
private let m_sourceIndex: Int32;
private let m_ngPlusSystem: ref<NewGamePlusSystem>;
private static func GetPointOfNoReturnPrefix() -> String {
return "PointOfNoReturn";
}
// WolvenKit only lets me specify *some* things, but inkwidgets generally are just enough
private final func InitializeUninitializableWKitVariables() {
this.m_animDelayBetweenSlots = 0.150000006;
Expand All @@ -54,7 +48,7 @@ public class NewGamePlusSelectionController extends gameuiSaveHandlingController
this.m_systemHandler = this.GetSystemRequestsHandler();
this.m_ngPlusSystem = GameInstance.GetNewGamePlusSystem();
this.m_ngPlusSystem.SetStandaloneState(false);
this.m_ngPlusSystem.SetNewGamePlusQuest(ENGPlusType.Invalid);
this
.m_systemHandler
.RegisterToCallback(n"OnSavesForLoadReady", this, n"OnSavesForLoadReady");
Expand All @@ -76,7 +70,6 @@ public class NewGamePlusSelectionController extends gameuiSaveHandlingController
this.m_isInputDisabled = false;
this.PlayLoadingAnimation();
this.m_isEp1Enabled = IsEP1();
this.m_ngPlusSystem.SetNewGamePlusState(false); // HACK, NOT SURE ABOUT THIS WORKING OUT FINE
}
protected cb func OnUninitialize() -> Bool {
Expand All @@ -85,8 +78,7 @@ public class NewGamePlusSelectionController extends gameuiSaveHandlingController
protected cb func OnButtonRelease(evt: ref<inkPointerEvent>) -> Bool {
if evt.IsAction(n"back") {
NewGamePlusSpawnTagController.RestoreSpawnTags();
this.m_ngPlusSystem.SetNewGamePlusState(false);
this.m_ngPlusSystem.SetNewGamePlusQuest(ENGPlusType.Invalid);
this.m_eventDispatcher.SpawnEvent(n"OnMainMenuBack");
}
}
Expand Down Expand Up @@ -144,19 +136,13 @@ public class NewGamePlusSelectionController extends gameuiSaveHandlingController
private final func OnSelectedSave(controller: ref<LoadListItem>) -> Void {
let saveName = this.m_saves[controller.Index()];
this.m_ngPlusSystem.Spew(s"Loading save \(saveName) for player progression transfer...");
let result = this.m_ngPlusSystem.ParsePointOfNoReturnSaveData(saveName);
this.m_ngPlusSystem.Spew(s"Progression loader result: \(result)");
if !result {
if !this.m_ngPlusSystem.ParsePointOfNoReturnSaveData(saveName) {
// NOTE: add localization? Better error messages?
controller.SetInvalid("Failed to parse progression data!\nTry going into a game and saving again.");
return;
}
this.m_ngPlusSystem.SetNewGamePlusState(true);
this.m_eventDispatcher.SpawnEvent(n"OnAccept");
}
Expand Down
24 changes: 4 additions & 20 deletions scripting/Scenario/NGPlusExpansionNewGameMenuAdditions.reds
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module NGPlus.ExpansionNewGameAdditions

import NGPlus.SpawnTags.NewGamePlusSpawnTagController

@addField(ExpansionNewGame)
private let m_ngPlusStandaloneButton: inkWidgetRef;

Expand Down Expand Up @@ -46,11 +44,8 @@ protected cb func OnIntroComplete(anim: ref<inkAnimProxy>) -> Bool {
protected func PriorMenu() -> Void {
// Just in case...
let newGamePlusSystem = GameInstance.GetNewGamePlusSystem();
newGamePlusSystem.SetNewGamePlusQuest(ENGPlusType.Invalid);
newGamePlusSystem.SetNewGamePlusState(false);
newGamePlusSystem.SetStandaloneState(false);
NewGamePlusSpawnTagController.RestoreSpawnTags();
wrappedMethod();
}

Expand All @@ -69,21 +64,16 @@ protected cb func OnHoverOverNGPlusStandalone(evt: ref<inkPointerEvent>) -> Bool
protected cb func OnPressBaseGame(evt: ref<inkPointerEvent>) -> Bool {
let newGamePlusSystem = GameInstance.GetNewGamePlusSystem();
newGamePlusSystem.SetNewGamePlusState(false);
newGamePlusSystem.SetStandaloneState(false);
newGamePlusSystem.SetNewGamePlusQuest(ENGPlusType.Invalid);
NewGamePlusSpawnTagController.RestoreSpawnTags();
wrappedMethod(evt);
}

@wrapMethod(ExpansionNewGame)
protected cb func OnPressExpansion(evt: ref<inkPointerEvent>) -> Bool {
let newGamePlusSystem = GameInstance.GetNewGamePlusSystem();
newGamePlusSystem.SetNewGamePlusState(false);
newGamePlusSystem.SetStandaloneState(false);
NewGamePlusSpawnTagController.RestoreSpawnTags();
newGamePlusSystem.SetNewGamePlusQuest(ENGPlusType.Invalid);
wrappedMethod(evt);
}

Expand All @@ -93,16 +83,10 @@ protected cb func OnPressNGPlusStandalone(evt: ref<inkPointerEvent>) -> Bool {
this.PlaySound(n"Button", n"OnPress");
let newGamePlusSystem = GameInstance.GetNewGamePlusSystem();
newGamePlusSystem.SetNewGamePlusState(true);
newGamePlusSystem.SetStandaloneState(true);
newGamePlusSystem.SetNewGamePlusQuest(ENGPlusType.StartFromQ101_ProgressionBuild);
this.m_characterCustomizationState.SetIsExpansionStandalone(false);
newGamePlusSystem.SetNewGamePlusGameDefinition(ENewGamePlusStartType.StartFromQ101_ProgressionBuild);
NewGamePlusSpawnTagController.SetSpawnTags(n"#q101_spwn_player");
this.NextMenu();
}
}
20 changes: 2 additions & 18 deletions scripting/Scenario/NGPlusGameDefinitionSelector.reds
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import NGPlus.SpawnTags.NewGamePlusSpawnTagController

public class NewGamePlusStartingPointController extends BaseCharacterCreationController {
public let m_newGameDescription: inkTextRef;
public let m_textureTop: inkImageRef;
Expand Down Expand Up @@ -72,29 +70,15 @@ public class NewGamePlusStartingPointController extends BaseCharacterCreationCon
protected cb func OnPressQ001(evt: ref<inkPointerEvent>) -> Bool {
if evt.IsAction(n"click") && !this.m_isInputLocked {
this.PlaySound(n"Button", n"OnPress");
NewGamePlusSpawnTagController.SetSpawnTags(n"#q000_hym_theater_start");
if this.m_ep1Enabled {
this.m_ngPlusSystem.SetNewGamePlusGameDefinition(ENewGamePlusStartType.StartFromQ001);
} else {
this.m_ngPlusSystem.SetNewGamePlusGameDefinition(ENewGamePlusStartType.StartFromQ001_NoEP1);
}
this.m_ngPlusSystem.SetNewGamePlusQuest(ENGPlusType.StartFromQ001);
this.OnSelectedOption();
}
}
protected cb func OnPressQ101(evt: ref<inkPointerEvent>) -> Bool {
if evt.IsAction(n"click") && !this.m_isInputLocked {
this.PlaySound(n"Button", n"OnPress");
NewGamePlusSpawnTagController.SetSpawnTags(n"#q101_spwn_player");
if this.m_ep1Enabled {
this.m_ngPlusSystem.SetNewGamePlusGameDefinition(ENewGamePlusStartType.StartFromQ101);
} else {
this.m_ngPlusSystem.SetNewGamePlusGameDefinition(ENewGamePlusStartType.StartFromQ101_NoEP1);
}
this.m_ngPlusSystem.SetNewGamePlusQuest(ENGPlusType.StartFromQ101);
this.OnSelectedOption();
}
}
Expand Down
Loading

0 comments on commit 3dff747

Please sign in to comment.