From 4f3ba4b61d05ed8190044e1fe57d09e0d6509443 Mon Sep 17 00:00:00 2001 From: Ryan Yappert Date: Thu, 19 Dec 2024 18:07:10 -0800 Subject: [PATCH] Better default behavior for config files. --- .../Characters/CharacterManager.cs | 2 +- .../Characters/EpitaphRoadManager.cs | 2 +- .../Characters/ExpManager.cs | 7 +- .../Characters/RewardManager.cs | 8 +- .../Characters/WalletManager.cs | 8 +- .../GameServerSetting.cs | 27 +++-- .../Handler/InstanceEnemyKillHandler.cs | 4 +- .../QuestGetCycleContentsStateListHandler.cs | 5 +- .../Tasks/EpitaphSchedulerTask.cs | 3 +- Arrowgene.Ddon.Server/GameLogicSetting.cs | 106 ++++++------------ Arrowgene.Ddon.Server/LoginServerSetting.cs | 31 +++-- 11 files changed, 93 insertions(+), 110 deletions(-) diff --git a/Arrowgene.Ddon.GameServer/Characters/CharacterManager.cs b/Arrowgene.Ddon.GameServer/Characters/CharacterManager.cs index cb3e1c3c8..247655845 100644 --- a/Arrowgene.Ddon.GameServer/Characters/CharacterManager.cs +++ b/Arrowgene.Ddon.GameServer/Characters/CharacterManager.cs @@ -61,7 +61,7 @@ public Character SelectCharacter(uint characterId, DbConnection? connectionIn = character.EpitaphRoadState.UnlockedContent = _Server.Database.GetEpitaphRoadUnlocks(character.CharacterId, connectionIn); - if (_Server.Setting.GameLogicSetting.EnableEpitaphWeeklyRewards.Value) + if (_Server.Setting.GameLogicSetting.EnableEpitaphWeeklyRewards) { character.EpitaphRoadState.WeeklyRewardsClaimed = _Server.Database.GetEpitaphClaimedWeeklyRewards(character.CharacterId, connectionIn); } diff --git a/Arrowgene.Ddon.GameServer/Characters/EpitaphRoadManager.cs b/Arrowgene.Ddon.GameServer/Characters/EpitaphRoadManager.cs index 34c959d00..41bce2482 100644 --- a/Arrowgene.Ddon.GameServer/Characters/EpitaphRoadManager.cs +++ b/Arrowgene.Ddon.GameServer/Characters/EpitaphRoadManager.cs @@ -1290,7 +1290,7 @@ public List RollGatheringLoot(GameClient client, Charact { results.AddRange(RollWeeklyChestReward(dungeonInfo, reward)); - if (_Server.Setting.GameLogicSetting.EnableEpitaphWeeklyRewards.Value) + if (_Server.Setting.GameLogicSetting.EnableEpitaphWeeklyRewards) { character.EpitaphRoadState.WeeklyRewardsClaimed.Add(reward.EpitaphId); _Server.Database.InsertEpitaphWeeklyReward(character.CharacterId, reward.EpitaphId); diff --git a/Arrowgene.Ddon.GameServer/Characters/ExpManager.cs b/Arrowgene.Ddon.GameServer/Characters/ExpManager.cs index 45c3bde9f..b85978659 100644 --- a/Arrowgene.Ddon.GameServer/Characters/ExpManager.cs +++ b/Arrowgene.Ddon.GameServer/Characters/ExpManager.cs @@ -10,7 +10,6 @@ using System; using System.Collections.Generic; using System.Data.Common; -using System.Drawing; using System.Linq; namespace Arrowgene.Ddon.GameServer.Characters @@ -906,13 +905,13 @@ public uint GetScaledPointAmount(RewardSource source, ExpType type, uint amount) switch (type) { case ExpType.ExperiencePoints: - modifier = (source == RewardSource.Enemy) ? _GameSettings.EnemyExpModifier.Value : _GameSettings.QuestExpModifier.Value; + modifier = (source == RewardSource.Enemy) ? _GameSettings.EnemyExpModifier : _GameSettings.QuestExpModifier; break; case ExpType.JobPoints: - modifier = _GameSettings.JpModifier.Value; + modifier = _GameSettings.JpModifier; break; case ExpType.PlayPoints: - modifier = _GameSettings.PpModifier.Value; + modifier = _GameSettings.PpModifier; break; default: modifier = 1.0; diff --git a/Arrowgene.Ddon.GameServer/Characters/RewardManager.cs b/Arrowgene.Ddon.GameServer/Characters/RewardManager.cs index a6a9eea34..b922f3c2c 100644 --- a/Arrowgene.Ddon.GameServer/Characters/RewardManager.cs +++ b/Arrowgene.Ddon.GameServer/Characters/RewardManager.cs @@ -1,10 +1,8 @@ -using Arrowgene.Ddon.Server; using Arrowgene.Ddon.GameServer.Quests; +using Arrowgene.Ddon.Server; +using Arrowgene.Ddon.Shared.Model.Quest; using Arrowgene.Logging; using System.Collections.Generic; -using Arrowgene.Ddon.Shared.Model.Quest; -using Arrowgene.Ddon.Shared.Model; -using Arrowgene.Ddon.Database.Model; using System.Data.Common; namespace Arrowgene.Ddon.GameServer.Characters @@ -24,7 +22,7 @@ public bool AddQuestRewards(GameClient client, Quest quest, DbConnection? connec var rewards = quest.GenerateBoxRewards(); var currentRewards = GetQuestBoxRewards(client, connectionIn); - if (currentRewards.Count >= _Server.Setting.GameLogicSetting.RewardBoxMax.Value) + if (currentRewards.Count >= _Server.Setting.GameLogicSetting.RewardBoxMax) { return false; } diff --git a/Arrowgene.Ddon.GameServer/Characters/WalletManager.cs b/Arrowgene.Ddon.GameServer/Characters/WalletManager.cs index f77e0a996..91e407be5 100644 --- a/Arrowgene.Ddon.GameServer/Characters/WalletManager.cs +++ b/Arrowgene.Ddon.GameServer/Characters/WalletManager.cs @@ -107,16 +107,16 @@ public uint GetScaledWalletAmount(WalletType type, uint amount) switch (type) { case WalletType.Gold: - modifier = Server.Setting.GameLogicSetting.GoldModifier.Value; + modifier = Server.Setting.GameLogicSetting.GoldModifier; break; case WalletType.RiftPoints: - modifier = Server.Setting.GameLogicSetting.RiftModifier.Value; + modifier = Server.Setting.GameLogicSetting.RiftModifier; break; case WalletType.BloodOrbs: - modifier = Server.Setting.GameLogicSetting.BoModifier.Value; + modifier = Server.Setting.GameLogicSetting.BoModifier; break; case WalletType.HighOrbs: - modifier = Server.Setting.GameLogicSetting.HoModifier.Value; + modifier = Server.Setting.GameLogicSetting.HoModifier; break; default: modifier = 1.0; diff --git a/Arrowgene.Ddon.GameServer/GameServerSetting.cs b/Arrowgene.Ddon.GameServer/GameServerSetting.cs index 2839e7727..b1fba56c1 100644 --- a/Arrowgene.Ddon.GameServer/GameServerSetting.cs +++ b/Arrowgene.Ddon.GameServer/GameServerSetting.cs @@ -1,4 +1,4 @@ -using System.Runtime.Serialization; +using System.Runtime.Serialization; using Arrowgene.Ddon.Server; namespace Arrowgene.Ddon.GameServer @@ -11,13 +11,7 @@ public class GameServerSetting public GameServerSetting() { - ServerSetting = new ServerSetting(); - ServerSetting.Id = 10; - ServerSetting.Name = "Game"; - ServerSetting.ServerPort = 52000; - ServerSetting.ServerSocketSettings.Identity = "Game"; - - GameLogicSetting = new GameLogicSetting(); + SetDefaultValues(); } public GameServerSetting(GameServerSetting setting) @@ -41,5 +35,22 @@ void OnDeserialized(StreamingContext context) GameLogicSetting ??= new GameLogicSetting(); } + + [OnDeserializing] + void OnDeserializing(StreamingContext context) + { + SetDefaultValues(); + } + + void SetDefaultValues() + { + ServerSetting = new ServerSetting(); + ServerSetting.Id = 10; + ServerSetting.Name = "Game"; + ServerSetting.ServerPort = 52000; + ServerSetting.ServerSocketSettings.Identity = "Game"; + + GameLogicSetting = new GameLogicSetting(); + } } } diff --git a/Arrowgene.Ddon.GameServer/Handler/InstanceEnemyKillHandler.cs b/Arrowgene.Ddon.GameServer/Handler/InstanceEnemyKillHandler.cs index cb575a332..e891245d0 100644 --- a/Arrowgene.Ddon.GameServer/Handler/InstanceEnemyKillHandler.cs +++ b/Arrowgene.Ddon.GameServer/Handler/InstanceEnemyKillHandler.cs @@ -209,7 +209,7 @@ public override S2CInstanceEnemyKillRes Handle(GameClient client, C2SInstanceEne if (enemyKilled.BloodOrbs > 0) { // Drop BO - uint gainedBo = (uint) (enemyKilled.BloodOrbs * _gameServer.Setting.GameLogicSetting.BoModifier.Value); + uint gainedBo = (uint) (enemyKilled.BloodOrbs * _gameServer.Setting.GameLogicSetting.BoModifier); uint bonusBo = (uint) (gainedBo * _gameServer.GpCourseManager.EnemyBloodOrbBonus()); CDataUpdateWalletPoint boUpdateWalletPoint = _gameServer.WalletManager.AddToWallet(memberClient.Character, WalletType.BloodOrbs, gainedBo + bonusBo, bonusBo, connectionIn: connectionIn); updateCharacterItemNtc.UpdateWalletList.Add(boUpdateWalletPoint); @@ -218,7 +218,7 @@ public override S2CInstanceEnemyKillRes Handle(GameClient client, C2SInstanceEne if (enemyKilled.HighOrbs > 0) { // Drop HO - uint gainedHo = (uint)(enemyKilled.HighOrbs * _gameServer.Setting.GameLogicSetting.HoModifier.Value); + uint gainedHo = (uint)(enemyKilled.HighOrbs * _gameServer.Setting.GameLogicSetting.HoModifier); CDataUpdateWalletPoint hoUpdateWalletPoint = _gameServer.WalletManager.AddToWallet(memberClient.Character, WalletType.HighOrbs, gainedHo, connectionIn: connectionIn); updateCharacterItemNtc.UpdateWalletList.Add(hoUpdateWalletPoint); } diff --git a/Arrowgene.Ddon.GameServer/Handler/QuestGetCycleContentsStateListHandler.cs b/Arrowgene.Ddon.GameServer/Handler/QuestGetCycleContentsStateListHandler.cs index fe946366c..45a3c99a4 100644 --- a/Arrowgene.Ddon.GameServer/Handler/QuestGetCycleContentsStateListHandler.cs +++ b/Arrowgene.Ddon.GameServer/Handler/QuestGetCycleContentsStateListHandler.cs @@ -1,6 +1,5 @@ using Arrowgene.Ddon.GameServer.Characters; using Arrowgene.Ddon.GameServer.Dump; -using Arrowgene.Ddon.GameServer.Quests; using Arrowgene.Ddon.Server; using Arrowgene.Ddon.Shared.Entity; using Arrowgene.Ddon.Shared.Entity.PacketStructure; @@ -36,8 +35,8 @@ public override S2CQuestGetCycleContentsStateListRes Handle(GameClient client, C ntc.WorldManageQuestOrderList = pcap.WorldManageQuestOrderList; // Recover paths + change vocation ntc.QuestDefine = pcap.QuestDefine; // Recover quest log data to be able to accept quests - ntc.QuestDefine.OrderMaxNum = Server.Setting.GameLogicSetting.QuestOrderMax.Value; - ntc.QuestDefine.RewardBoxMaxNum = Server.Setting.GameLogicSetting.RewardBoxMax.Value; + ntc.QuestDefine.OrderMaxNum = Server.Setting.GameLogicSetting.QuestOrderMax; + ntc.QuestDefine.RewardBoxMaxNum = Server.Setting.GameLogicSetting.RewardBoxMax; // pcap.MainQuestIdList; (this will add back all missing functionality which depends on complete MSQ) var completedMsq = client.Character.CompletedQuests.Values.Where(x => x.QuestType == QuestType.Main); diff --git a/Arrowgene.Ddon.GameServer/Tasks/EpitaphSchedulerTask.cs b/Arrowgene.Ddon.GameServer/Tasks/EpitaphSchedulerTask.cs index 204e86585..a47fd3dc1 100644 --- a/Arrowgene.Ddon.GameServer/Tasks/EpitaphSchedulerTask.cs +++ b/Arrowgene.Ddon.GameServer/Tasks/EpitaphSchedulerTask.cs @@ -1,5 +1,4 @@ using Arrowgene.Ddon.Server; -using Arrowgene.Ddon.Shared.Model; using Arrowgene.Ddon.Shared.Model.Rpc; using Arrowgene.Ddon.Shared.Model.Scheduler; using Arrowgene.Logging; @@ -18,7 +17,7 @@ public EpitaphSchedulerTask(DayOfWeek day, uint hour, uint minute) : base(TaskTy public override bool IsEnabled(DdonGameServer server) { - return server.Setting.GameLogicSetting.EnableEpitaphWeeklyRewards.Value; + return server.Setting.GameLogicSetting.EnableEpitaphWeeklyRewards; } public override void RunTask(DdonGameServer server) diff --git a/Arrowgene.Ddon.Server/GameLogicSetting.cs b/Arrowgene.Ddon.Server/GameLogicSetting.cs index 201e1b75f..d6bbd6eb1 100644 --- a/Arrowgene.Ddon.Server/GameLogicSetting.cs +++ b/Arrowgene.Ddon.Server/GameLogicSetting.cs @@ -1,30 +1,9 @@ using Arrowgene.Ddon.Shared.Model; -using System; using System.Collections.Generic; using System.Runtime.Serialization; -using YamlDotNet.Serialization; namespace Arrowgene.Ddon.Server { - [DataContract] - public class DefaultDataMember - { - private T _DefaultValue; - private T? _Value; - - [DataMember] - public T Value { - get => _Value ?? _DefaultValue; - set => _Value = Value; - } - - public DefaultDataMember(T defaultValue) - { - _DefaultValue = defaultValue; - } - } - - [DataContract] public class GameLogicSetting { @@ -189,58 +168,58 @@ public class GameLogicSetting /// /// Global modifier for enemy exp calculations to scale up or down. /// - [DataMember(Order = 27)] public double? EnemyExpModifier { get; set; } = 1.0; + [DataMember(Order = 27)] public double EnemyExpModifier { get; set; } /// /// Global modifier for quest exp calculations to scale up or down. /// - [DataMember(Order = 28)] public double? QuestExpModifier { get; set; } = 1.0; + [DataMember(Order = 28)] public double QuestExpModifier { get; set; } /// /// Global modifier for pp calculations to scale up or down. /// - [DataMember(Order = 29)] public double? PpModifier { get; set; } = 1.0; + [DataMember(Order = 29)] public double PpModifier { get; set; } /// /// Global modifier for Gold calculations to scale up or down. /// - [DataMember(Order = 30)] public double? GoldModifier { get; set; } = 1.0; + [DataMember(Order = 30)] public double GoldModifier { get; set; } /// /// Global modifier for Rift calculations to scale up or down. /// - [DataMember(Order = 31)] public double? RiftModifier { get; set; } = 1.0; + [DataMember(Order = 31)] public double RiftModifier { get; set; } /// /// Global modifier for BO calculations to scale up or down. /// - [DataMember(Order = 32)] public double? BoModifier { get; set; } = 1.0; + [DataMember(Order = 32)] public double BoModifier { get; set; } /// /// Global modifier for HO calculations to scale up or down. /// - [DataMember(Order = 33)] public double? HoModifier { get; set; } = 1.0; + [DataMember(Order = 33)] public double HoModifier { get; set; } /// /// Global modifier for JP calculations to scale up or down. /// - [DataMember(Order = 34)] public double? JpModifier { get; set; } = 1.0; + [DataMember(Order = 34)] public double JpModifier { get; set; } /// /// Configures the maximum amount of reward box slots. /// - [DataMember(Order = 35)] public byte? RewardBoxMax { get; set; } = 100; + [DataMember(Order = 35)] public byte RewardBoxMax { get; set; } /// /// Configures the maximum amount of quests that can be ordered at one time. /// - [DataMember(Order = 36)] public byte? QuestOrderMax { get; set; } = 20; + [DataMember(Order = 36)] public byte QuestOrderMax { get; set; } /// /// Configures if epitaph rewards are limited once per weekly reset. /// - [DataMember(Order = 37)] public bool? EnableEpitaphWeeklyRewards { get; set; } = true; + [DataMember(Order = 37)] public bool EnableEpitaphWeeklyRewards { get; set; } /// Enables main pawns in party to gain EXP and JP from quests /// Original game apparantly did not have pawns share quest reward, so will set to false for default, @@ -273,6 +252,11 @@ public class GameLogicSetting [DataMember(Order = 200)] public string UrlCompanionImage { get; set; } public GameLogicSetting() + { + SetDefaultValues(); + } + + void SetDefaultValues() { LaternBurnTimeInSeconds = 1500; AdditionalProductionSpeedFactor = 1.0; @@ -334,6 +318,20 @@ public GameLogicSetting() EnableEpitaphWeeklyRewards = false; EnableMainPartyPawnsQuestRewards = false; + EnemyExpModifier = 1.0; + QuestExpModifier = 1.0; + PpModifier = 1.0; + GoldModifier = 1.0; + RiftModifier = 1.0; + BoModifier = 1.0; + HoModifier = 1.0; + JpModifier = 1.0; + + QuestOrderMax = 20; + RewardBoxMax = 100; + + EnableEpitaphWeeklyRewards = true; + string urlDomain = $"http://localhost:{52099}"; UrlManual = $"{urlDomain}/manual_nfb/"; UrlShopDetail = $"{urlDomain}/shop/ingame/stone/detail"; @@ -356,6 +354,12 @@ public GameLogicSetting() UrlCompanionImage = $"{urlDomain}/"; } + [OnDeserializing] + void OnDeserializing(StreamingContext context) + { + SetDefaultValues(); + } + public GameLogicSetting(GameLogicSetting setting) { LaternBurnTimeInSeconds = setting.LaternBurnTimeInSeconds; @@ -425,44 +429,6 @@ public GameLogicSetting(GameLogicSetting setting) [OnDeserialized] void OnDeserialized(StreamingContext context) { - // Initialize reference types so tests work properly. - AdjustPartyEnemyExpTiers ??= new(); - AdjustTargetLvEnemyExpTiers ??= new(); - WeatherStatistics ??= new(); - WalletLimits ??= new(); - UrlManual ??= string.Empty; - UrlShopDetail ??= string.Empty; - UrlShopCounterA ??= string.Empty; - UrlShopAttention ??= string.Empty; - UrlShopStoneLimit ??= string.Empty; - UrlShopCounterB ??= string.Empty; - UrlChargeCallback ??= string.Empty; - UrlChargeA ??= string.Empty; - UrlSample9 ??= string.Empty; - UrlSample10 ??= string.Empty; - UrlCampaignBanner ??= string.Empty; - UrlSupportIndex ??= string.Empty; - UrlPhotoupAuthorize ??= string.Empty; - UrlApiA ??= string.Empty; - UrlApiB ??= string.Empty; - UrlIndex ??= string.Empty; - UrlCampaign ??= string.Empty; - UrlChargeB ??= string.Empty; - UrlCompanionImage ??= string.Empty; - - EnableEpitaphWeeklyRewards ??= true; - - EnemyExpModifier ??= 1; - QuestExpModifier ??= 1; - PpModifier ??= 1; - GoldModifier ??= 1; - RiftModifier ??= 1; - BoModifier ??= 1; - HoModifier ??= 1; - JpModifier ??= 1; - RewardBoxMax ??= 100; - QuestOrderMax ??= 20; - if (RookiesRingBonus < 0) { RookiesRingBonus = 1.0; diff --git a/Arrowgene.Ddon.Server/LoginServerSetting.cs b/Arrowgene.Ddon.Server/LoginServerSetting.cs index bad40b475..27fd0e632 100644 --- a/Arrowgene.Ddon.Server/LoginServerSetting.cs +++ b/Arrowgene.Ddon.Server/LoginServerSetting.cs @@ -13,6 +13,27 @@ public class LoginServerSetting [DataMember(Order = 112)] public int KickOnMultipleLoginTimer { get; set; } public LoginServerSetting() + { + SetDefaultValues(); + } + + public LoginServerSetting(LoginServerSetting setting) + { + ServerSetting = new ServerSetting(setting.ServerSetting); + AccountRequired = setting.AccountRequired; + NoOperationTimeOutTime = setting.NoOperationTimeOutTime; + KickOnMultipleLogin = setting.KickOnMultipleLogin; + KickOnMultipleLoginTries = setting.KickOnMultipleLoginTries; + KickOnMultipleLoginTimer = setting.KickOnMultipleLoginTimer; + } + + [OnDeserializing] + void OnDeserializing(StreamingContext context) + { + SetDefaultValues(); + } + + void SetDefaultValues() { ServerSetting = new ServerSetting(); ServerSetting.Id = 1; @@ -26,15 +47,5 @@ public LoginServerSetting() KickOnMultipleLoginTries = 3; KickOnMultipleLoginTimer = 5000; } - - public LoginServerSetting(LoginServerSetting setting) - { - ServerSetting = new ServerSetting(setting.ServerSetting); - AccountRequired = setting.AccountRequired; - NoOperationTimeOutTime = setting.NoOperationTimeOutTime; - KickOnMultipleLogin = setting.KickOnMultipleLogin; - KickOnMultipleLoginTries = setting.KickOnMultipleLoginTries; - KickOnMultipleLoginTimer = setting.KickOnMultipleLoginTimer; - } } }