Skip to content

Commit

Permalink
refactor to reduce footprint
Browse files Browse the repository at this point in the history
add Mod Settings support (keeping it optional)

add SDPPL_LevelUp exec func as a command, capable of leveling up a
proficiency

add media
  • Loading branch information
p-marques committed Nov 24, 2022
1 parent cacbdf4 commit de70f99
Show file tree
Hide file tree
Showing 8 changed files with 411 additions and 187 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.psd filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
3 changes: 3 additions & 0 deletions media/sdppl_menu_showcase.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions media/sdppl_menu_showcase.psd
Git LFS file not shown
158 changes: 158 additions & 0 deletions src/r6/scripts/SDPPL/sdppl_base.reds
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
module SDPPL.Base
import SDPPL.Settings.SDPPLSettings
import SDPPL.Menu.SDPPLMenu

public class SDPPL extends ScriptableSystem {
private let player: ref<PlayerPuppet>;
private let statsSystem: ref<StatsSystem>;
private let levelUpListener: ref<LevelChangedListener>;
private let playerDevelopmentData: ref<PlayerDevelopmentData>;
private let settingsMode: SettingsMode;
private let settings: ref<SDPPLSettings>;
private func OnPlayerAttach(request: ref<PlayerAttachRequest>) -> Void {
this.Log("::OnPlayerAttach");
this.player = GameInstance.GetPlayerSystem(request.owner.GetGame()).GetLocalPlayerMainGameObject() as PlayerPuppet;
this.playerDevelopmentData = PlayerDevelopmentSystem.GetData(this.player);
this.RegisterListeners();
this.settingsMode = SDPPL_GetSettingsMode();
if Equals(this.settingsMode, SettingsMode.Default) {
this.settings = new SDPPLSettings();
this.Log("settingsMode = Default");
}
else {
this.settings = new SDPPLMenu();
this.Log("settingsMode = Menu");
}
this.settings.SetupSettings();
}
private final func OnPlayerDetach(request: ref<PlayerDetachRequest>) -> Void {
this.statsSystem.UnregisterListener(Cast<StatsObjectID>(this.player.GetEntityID()), this.levelUpListener);
}
private func RegisterListeners() -> Void {
this.statsSystem = GameInstance.GetStatsSystem(this.GetGameInstance());
this.levelUpListener = new LevelChangedListener();
this.levelUpListener.sdppl = this;
this.statsSystem.RegisterListener(Cast<StatsObjectID>(this.player.GetEntityID()), this.levelUpListener);
}
private func OnLevelUpRequest(request: ref<HandleLevelUpRequest>) -> Void {
this.Log("::OnLevelUpRequest");
this.Log("[" + EnumValueToString("gamedataStatType", Cast<Int64>(EnumInt(request.statType))) + "] leveled up to " + request.newLevel + ".");
if !this.settings.GetIsEnabled() {
this.Log("::GetIsEnabled() == false");
return;
}
if Equals(request.statType, gamedataStatType.Level) {
this.HandlePlayerLevelUp(request.newLevel);
}
else {
this.HandleSkillLevelUp();
}
}
private func HandlePlayerLevelUp(newLevel: Int32) -> Void {
let attributePointsDelta: Int32 = 0;
let perkPointsDelta: Int32 = 0;
if this.settings.GetUseConditionalPointGain() && !this.settings.GetShouldAwardPoints(newLevel) {
attributePointsDelta = -1;
perkPointsDelta = -1;
}
else {
attributePointsDelta = this.settings.GetAttributePointsOnCharacterLevelUp(newLevel) - 1;
perkPointsDelta = this.settings.GetPerkPointsOnCharacterLevelUp(newLevel) - 1;
}
if attributePointsDelta != 0 {
this.playerDevelopmentData.AddDevelopmentPoints(attributePointsDelta, gamedataDevelopmentPointType.Attribute);
}
if perkPointsDelta != 0 {
this.playerDevelopmentData.AddDevelopmentPoints(perkPointsDelta, gamedataDevelopmentPointType.Primary);
}
this.Log("::HandlePlayerLevelUp -> attributePointsDelta was " + attributePointsDelta);
this.Log("::HandlePlayerLevelUp -> perkPointsDelta was " + perkPointsDelta);
}
private func HandleSkillLevelUp() -> Void {
let perkPointsToAdd: Int32 = this.settings.GetPerkPointsOnSkillLevelUp();
if perkPointsToAdd > 0 {
this.playerDevelopmentData.AddDevelopmentPoints(perkPointsToAdd, gamedataDevelopmentPointType.Primary);
}
this.Log("::HandleSkillLevelUp -> perkPointsToAdd was " + perkPointsToAdd);
}
private func Log(msg: String) -> Void {
LogChannel(n"SDPPL", msg);
}
public static func IsStatASkill(statType: gamedataStatType) -> Bool {
switch statType {
case statType.Assault:
case statType.Athletics:
case statType.Brawling:
case statType.ColdBlood:
case statType.CombatHacking:
case statType.Crafting:
case statType.Demolition:
case statType.Engineering:
case statType.Gunslinger:
case statType.Hacking:
case statType.Kenjutsu:
case statType.Stealth:
return true;
}
return false;
}
}

public class HandleLevelUpRequest extends ScriptableSystemRequest {
public let statType: gamedataStatType;
public let newLevel: Int32;
}

public class LevelChangedListener extends ScriptStatsListener {
public let sdppl: ref<SDPPL>;
public func OnStatChanged(ownerID: StatsObjectID, statType: gamedataStatType, diff: Float, total: Float) -> Void {
let request: ref<HandleLevelUpRequest>;
if Equals(statType, gamedataStatType.Level) || SDPPL.IsStatASkill(statType) {
request = new HandleLevelUpRequest();
request.statType = statType;
request.newLevel = Cast<Int32>(total);
if IsDefined(this.sdppl) {
this.sdppl.QueueRequest(request);
}
}
}
}

@if(!ModuleExists("ModSettingsModule"))
public func SDPPL_GetSettingsMode() -> SettingsMode {
return SettingsMode.Default;
}

@if(ModuleExists("ModSettingsModule"))
public func SDPPL_GetSettingsMode() -> SettingsMode {
return SettingsMode.Menu;
}

enum SettingsMode {
Default = 0,
Menu = 1
}
32 changes: 32 additions & 0 deletions src/r6/scripts/SDPPL/sdppl_commands.reds
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public static exec func SDPPL_LevelUp(gi: GameInstance, proficiencyTypeString: String) -> Void {
let pds: ref<PlayerDevelopmentSystem>;
let player: ref<PlayerPuppet>;
let proficiencyTypeInt: Int32;
let proficiencyType: gamedataProficiencyType;
let experienceToAdd: Int32;
let addExpRequest: ref<AddExperience>;
proficiencyTypeInt = Cast<Int32>(EnumValueFromName(n"gamedataProficiencyType", StringToName(proficiencyTypeString)));
if proficiencyTypeInt >= 0 && proficiencyTypeInt <= 12 {
proficiencyType = IntEnum<gamedataProficiencyType>(proficiencyTypeInt);
pds = GameInstance.GetScriptableSystemsContainer(gi).Get(n"PlayerDevelopmentSystem") as PlayerDevelopmentSystem;
player = GameInstance.GetPlayerSystem(gi).GetLocalPlayerMainGameObject() as PlayerPuppet;
experienceToAdd = pds.GetRemainingExpForLevelUp(player, proficiencyType);
if experienceToAdd > 0 {
addExpRequest = new AddExperience();
addExpRequest.Set(player, experienceToAdd, proficiencyType, true);
pds.QueueRequest(addExpRequest);
LogChannel(n"SDPPL", "Added " + experienceToAdd + " " + proficiencyTypeString + " experience.");
}
else {
LogChannel(n"SDPPL", "No experience added since ::GetRemainingExpForLevelUp returned a negative value.");
}
}
else {
LogChannel(n"SDPPL", "\"" + proficiencyTypeString + "\" is not recognized.");
}
}
70 changes: 70 additions & 0 deletions src/r6/scripts/SDPPL/sdppl_menu.reds
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
module SDPPL.Menu

import SDPPL.Settings.SDPPLSettings

public class SDPPLMenu extends SDPPLSettings {
@runtimeProperty("ModSettings.mod", "Set Dev Points Per Level")
@runtimeProperty("ModSettings.category", "Main")
@runtimeProperty("ModSettings.displayName", "Enabled")
@runtimeProperty("ModSettings.description", "Enable/Disable mod.")
public let IsEnabled: Bool = true;
@runtimeProperty("ModSettings.mod", "Set Dev Points Per Level")
@runtimeProperty("ModSettings.category", "On Character Level Up")
@runtimeProperty("ModSettings.displayName", "Attribute Points")
@runtimeProperty("ModSettings.description", "Attribute point(s) awarded on character level up.")
@runtimeProperty("ModSettings.step", "1")
@runtimeProperty("ModSettings.min", "0")
@runtimeProperty("ModSettings.max", "5")
public let AttributePointsOnCharacterLevelUp: Int32 = 1;
@runtimeProperty("ModSettings.mod", "Set Dev Points Per Level")
@runtimeProperty("ModSettings.category", "On Character Level Up")
@runtimeProperty("ModSettings.displayName", "Perk Points")
@runtimeProperty("ModSettings.description", "Perk point(s) awarded on character level up.")
@runtimeProperty("ModSettings.step", "1")
@runtimeProperty("ModSettings.min", "0")
@runtimeProperty("ModSettings.max", "5")
public let PerkPointsOnCharacterLevelUp: Int32 = 1;
@runtimeProperty("ModSettings.mod", "Set Dev Points Per Level")
@runtimeProperty("ModSettings.category", "On Skill Level Up")
@runtimeProperty("ModSettings.displayName", "Perk Points")
@runtimeProperty("ModSettings.description", "Perk point(s) awarded on skill level up.")
@runtimeProperty("ModSettings.step", "1")
@runtimeProperty("ModSettings.min", "0")
@runtimeProperty("ModSettings.max", "5")
public let PerkPointsOnSkillLevelUp: Int32 = 0;
protected func SetupSettings() -> Void {
ModSettings.RegisterListenerToClass(this);
}
protected func GetIsEnabled() -> Bool {
return this.IsEnabled;
}
protected func GetAttributePointsOnCharacterLevelUp(level: Int32) -> Int32 {
return this.AttributePointsOnCharacterLevelUp;
}
protected func GetPerkPointsOnCharacterLevelUp(level: Int32) -> Int32 {
return this.PerkPointsOnCharacterLevelUp;
}
protected func GetPerkPointsOnSkillLevelUp() -> Int32 {
return this.PerkPointsOnSkillLevelUp;
}
protected func GetUseCustomAttributePointsMap() -> Bool {
return false;
}
protected func GetUseCustomSkillPointsMap() -> Bool {
return false;
}
protected func GetUseConditionalPointGain() -> Bool {
return false;
}
}
Loading

0 comments on commit de70f99

Please sign in to comment.