Skip to content

Commit

Permalink
Better default behavior for config files.
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanYappert committed Dec 20, 2024
1 parent f5a1103 commit 4f3ba4b
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 110 deletions.
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.GameServer/Characters/CharacterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.GameServer/Characters/EpitaphRoadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ public List<InstancedGatheringItem> 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);
Expand Down
7 changes: 3 additions & 4 deletions Arrowgene.Ddon.GameServer/Characters/ExpManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions Arrowgene.Ddon.GameServer/Characters/RewardManager.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions Arrowgene.Ddon.GameServer/Characters/WalletManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 19 additions & 8 deletions Arrowgene.Ddon.GameServer/GameServerSetting.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Runtime.Serialization;
using System.Runtime.Serialization;
using Arrowgene.Ddon.Server;

namespace Arrowgene.Ddon.GameServer
Expand All @@ -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)
Expand All @@ -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();
}
}
}
4 changes: 2 additions & 2 deletions Arrowgene.Ddon.GameServer/Handler/InstanceEnemyKillHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions Arrowgene.Ddon.GameServer/Tasks/EpitaphSchedulerTask.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand Down
106 changes: 36 additions & 70 deletions Arrowgene.Ddon.Server/GameLogicSetting.cs
Original file line number Diff line number Diff line change
@@ -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<T>
{
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
{
Expand Down Expand Up @@ -189,58 +168,58 @@ public class GameLogicSetting
/// <summary>
/// Global modifier for enemy exp calculations to scale up or down.
/// </summary>
[DataMember(Order = 27)] public double? EnemyExpModifier { get; set; } = 1.0;
[DataMember(Order = 27)] public double EnemyExpModifier { get; set; }

/// <summary>
/// Global modifier for quest exp calculations to scale up or down.
/// </summary>

[DataMember(Order = 28)] public double? QuestExpModifier { get; set; } = 1.0;
[DataMember(Order = 28)] public double QuestExpModifier { get; set; }

/// <summary>
/// Global modifier for pp calculations to scale up or down.
/// </summary>
[DataMember(Order = 29)] public double? PpModifier { get; set; } = 1.0;
[DataMember(Order = 29)] public double PpModifier { get; set; }

/// <summary>
/// Global modifier for Gold calculations to scale up or down.
/// </summary>
[DataMember(Order = 30)] public double? GoldModifier { get; set; } = 1.0;
[DataMember(Order = 30)] public double GoldModifier { get; set; }

/// <summary>
/// Global modifier for Rift calculations to scale up or down.
/// </summary>
[DataMember(Order = 31)] public double? RiftModifier { get; set; } = 1.0;
[DataMember(Order = 31)] public double RiftModifier { get; set; }

/// <summary>
/// Global modifier for BO calculations to scale up or down.
/// </summary>
[DataMember(Order = 32)] public double? BoModifier { get; set; } = 1.0;
[DataMember(Order = 32)] public double BoModifier { get; set; }

/// <summary>
/// Global modifier for HO calculations to scale up or down.
/// </summary>
[DataMember(Order = 33)] public double? HoModifier { get; set; } = 1.0;
[DataMember(Order = 33)] public double HoModifier { get; set; }

/// <summary>
/// Global modifier for JP calculations to scale up or down.
/// </summary>
[DataMember(Order = 34)] public double? JpModifier { get; set; } = 1.0;
[DataMember(Order = 34)] public double JpModifier { get; set; }

/// <summary>
/// Configures the maximum amount of reward box slots.
/// </summary>
[DataMember(Order = 35)] public byte? RewardBoxMax { get; set; } = 100;
[DataMember(Order = 35)] public byte RewardBoxMax { get; set; }

/// <summary>
/// Configures the maximum amount of quests that can be ordered at one time.
/// </summary>
[DataMember(Order = 36)] public byte? QuestOrderMax { get; set; } = 20;
[DataMember(Order = 36)] public byte QuestOrderMax { get; set; }

/// <summary>
/// Configures if epitaph rewards are limited once per weekly reset.
/// </summary>
[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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -356,6 +354,12 @@ public GameLogicSetting()
UrlCompanionImage = $"{urlDomain}/";
}

[OnDeserializing]
void OnDeserializing(StreamingContext context)
{
SetDefaultValues();
}

public GameLogicSetting(GameLogicSetting setting)
{
LaternBurnTimeInSeconds = setting.LaternBurnTimeInSeconds;
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 4f3ba4b

Please sign in to comment.