Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add C# scripting support #667

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ root = true
indent_style = space

# Code files
[*.{cs,sql,json}]
[*.{cs,sql,json,csx}]
indent_size = 4
insert_final_newline = true
charset = utf-8
21 changes: 14 additions & 7 deletions Arrowgene.Ddon.Cli/Command/ServerCommand.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Threading;
using Arrowgene.Ddon.Database;
using Arrowgene.Ddon.GameServer;
using Arrowgene.Ddon.LoginServer;
using Arrowgene.Ddon.Rpc.Web;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.WebServer;
using Arrowgene.Logging;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;

namespace Arrowgene.Ddon.Cli.Command
{
Expand All @@ -20,6 +20,7 @@ public class ServerCommand : ICommand
private readonly Setting _setting;
private DdonLoginServer _loginServer;
private DdonGameServer _gameServer;
private ServerScriptManager _serverScriptManager;
private DdonWebServer _webServer;
private RpcWebServer _rpcWebServer;
private IDatabase _database;
Expand Down Expand Up @@ -110,9 +111,15 @@ public CommandResultType Run(CommandParameter parameter)
_assetRepository.Initialize();
}

if (_serverScriptManager == null)
{
_serverScriptManager = new ServerScriptManager(_setting.AssetPath);
_serverScriptManager.Initialize();
}

if (_loginServer == null)
{
_loginServer = new DdonLoginServer(_setting.LoginServerSetting, _setting.GameServerSetting.GameLogicSetting, _database, _assetRepository);
_loginServer = new DdonLoginServer(_setting.LoginServerSetting, _serverScriptManager.GameServerSettings.GameLogicSetting, _database, _assetRepository);
}

if (_webServer == null)
Expand All @@ -122,7 +129,7 @@ public CommandResultType Run(CommandParameter parameter)

if (_gameServer == null)
{
_gameServer = new DdonGameServer(_setting.GameServerSetting, _database, _assetRepository);
_gameServer = new DdonGameServer(_setting.GameServerSetting, _serverScriptManager.GameServerSettings.GameLogicSetting, _database, _assetRepository);
}

if (_rpcWebServer == null)
Expand Down
8 changes: 4 additions & 4 deletions Arrowgene.Ddon.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
* along with Arrowgene.Ddon.Cli. If not, see <https://www.gnu.org/licenses/>.
*/

using Arrowgene.Ddon.Cli.Command;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using Arrowgene.Ddon.Cli.Command;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.Cli
{
Expand Down
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.GameServer/Arrowgene.Ddon.GameServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
</PropertyGroup>
<Import Project="./../SetSourceRevision.targets" />
<ItemGroup>
<ProjectReference Include="..\Arrowgene.Ddon.Server\Arrowgene.Ddon.Server.csproj" />
<ProjectReference Include="..\Arrowgene.Ddon.Server\Arrowgene.Ddon.Server.csproj" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions Arrowgene.Ddon.GameServer/BazaarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ulong Exhibit(GameClient client, StorageType storageType, string itemUID,
exhibition.Info.ItemInfo.ExhibitionTime = now;
exhibition.Info.State = BazaarExhibitionState.OnSale;
exhibition.Info.Proceeds = calculateProceeds(exhibition.Info.ItemInfo.ItemBaseInfo);
exhibition.Info.Expire = now.AddSeconds(Server.Setting.GameLogicSetting.BazaarExhibitionTimeSeconds);
exhibition.Info.Expire = now.AddSeconds(Server.GameLogicSettings.BazaarExhibitionTimeSeconds);

ulong bazaarId = Server.Database.InsertBazaarExhibition(exhibition);
return bazaarId;
Expand All @@ -59,7 +59,7 @@ public ulong ReExhibit(ulong bazaarId, uint newPrice)
exhibition.Info.ItemInfo.ItemBaseInfo.Price = newPrice;
exhibition.Info.ItemInfo.ExhibitionTime = now;
exhibition.Info.Proceeds = calculateProceeds(exhibition.Info.ItemInfo.ItemBaseInfo);
exhibition.Info.Expire = now.AddSeconds(Server.Setting.GameLogicSetting.BazaarExhibitionTimeSeconds);
exhibition.Info.Expire = now.AddSeconds(Server.GameLogicSettings.BazaarExhibitionTimeSeconds);
Server.Database.UpdateBazaarExhibiton(exhibition);

return exhibition.Info.ItemInfo.BazaarId;
Expand Down Expand Up @@ -157,7 +157,7 @@ public uint ReceiveProceeds(GameClient client)
ulong totalCooldown;
try
{
totalCooldown = Server.Setting.GameLogicSetting.BazaarCooldownTimeSeconds - Server.GpCourseManager.BazaarReExhibitShorten();
totalCooldown = Server.GameLogicSettings.BazaarCooldownTimeSeconds - Server.GpCourseManager.BazaarReExhibitShorten();
}
catch (OverflowException _)
{
Expand Down
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)
if (_Server.GameLogicSettings.EnableEpitaphWeeklyRewards)
{
character.EpitaphRoadState.WeeklyRewardsClaimed = _Server.Database.GetEpitaphClaimedWeeklyRewards(character.CharacterId, connectionIn);
}
Expand Down
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.GameServer/Characters/CraftManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public double GetCraftingTimeReductionRate(List<uint> productionSpeedLevels)
{
return Math.Clamp(
productionSpeedLevels.Select(level => level * ProductionSpeedIncrementPerLevel + ProductionSpeedMinimumPerPawn).Sum() *
_server.Setting.GameLogicSetting.AdditionalProductionSpeedFactor, 0, 100);
_server.GameLogicSettings.AdditionalProductionSpeedFactor, 0, 100);
}

public uint CalculateRecipeProductionSpeed(uint recipeTime, List<uint> productionSpeedLevels)
Expand Down
18 changes: 17 additions & 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)
if (_Server.GameLogicSettings.EnableEpitaphWeeklyRewards)
{
character.EpitaphRoadState.WeeklyRewardsClaimed.Add(reward.EpitaphId);
_Server.Database.InsertEpitaphWeeklyReward(character.CharacterId, reward.EpitaphId);
Expand Down Expand Up @@ -1322,6 +1322,22 @@ public List<InstancedGatheringItem> RollGatheringLoot(GameClient client, Charact
return results;
}

public bool CheckUnlockConditions(GameClient client, EpitaphBarrier barrier)
{
foreach (var sectionId in barrier.DependentSectionIds)
{
var sectionInfo = _Server.EpitaphRoadManager.GetSectionById(sectionId);
foreach (var unlockId in sectionInfo.UnlockDependencies)
{
if (!client.Character.EpitaphRoadState.UnlockedContent.Contains(unlockId))
{
return false;
}
}
}
return true;
}

/// <summary>
/// Called by the task manager. The main task will signal all channels
/// to flush the cached information queried by the player when first
Expand Down
34 changes: 15 additions & 19 deletions Arrowgene.Ddon.GameServer/Characters/ExpManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Arrowgene.Ddon.GameServer.Party;
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Server.Scripting.interfaces;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;
Expand Down Expand Up @@ -399,7 +400,7 @@ public ExpManager(DdonGameServer server, GameClientLookup gameClientLookup)
{
this._Server = server;
this._gameClientLookup = gameClientLookup;
this._GameSettings = server.Setting.GameLogicSetting;
this._GameSettings = server.GameLogicSettings;
}

private DdonGameServer _Server;
Expand Down Expand Up @@ -460,7 +461,7 @@ public PacketQueue AddExp(GameClient client, CharacterCommon characterToAddExpTo
PacketQueue packets = new();

var lvCap = (client.GameMode == GameMode.Normal)
? _Server.Setting.GameLogicSetting.JobLevelMax
? _Server.GameLogicSettings.JobLevelMax
: BitterblackMazeManager.LevelCap(client.Character.BbmProgress);

CDataCharacterJobData? activeCharacterJobData = characterToAddExpTo.ActiveCharacterJobData;
Expand Down Expand Up @@ -698,30 +699,25 @@ public static uint TotalExpToLevelUpTo(uint level, GameMode gameMode)
return totalExp;
}

private double RookiesRingBonus()
{
return _GameSettings.RookiesRingBonus;
}

private uint RookiesRingMaxLevel()
{
return _GameSettings.RookiesRingMaxLevel;
}

private uint GetRookiesRingBonus(CharacterCommon characterCommon, uint baseExpAmount)
{
if (characterCommon.ActiveCharacterJobData.Lv > RookiesRingMaxLevel())
if (!_Server.GameLogicSettings.Get<bool>("RookiesRing", "EnableRookiesRing"))
{
return 0;
}

if (!characterCommon.Equipment.GetItems(EquipType.Performance).Exists(x => x?.ItemId == 11718))
if (!characterCommon.Equipment.GetItems(EquipType.Performance).Exists(x => x?.ItemId == (uint) ItemId.RookiesRing))
{
return 0;
}

double result = baseExpAmount * RookiesRingBonus();
return (uint)result;
var rookiesRingInterface = _Server.ScriptManager.GameItemModule.GetItemInterface(ItemId.RookiesRing);
if (rookiesRingInterface == null)
{
return baseExpAmount;
}

return (uint)(baseExpAmount * rookiesRingInterface.GetBonusMultiplier(_Server, characterCommon));
}

private uint GetCourseExpBonus(CharacterCommon characterCommon, uint baseExpAmount, RewardSource source, QuestType questType)
Expand Down Expand Up @@ -846,7 +842,7 @@ private bool AllMembersOwnedBySameCharacter(PartyGroup party)

private double CalculatePartyRangeMultipler(GameMode gameMode, PartyGroup party)
{
if (!_GameSettings.AdjustPartyEnemyExp || gameMode == GameMode.BitterblackMaze)
if (!_GameSettings.EnableAdjustPartyEnemyExp || gameMode == GameMode.BitterblackMaze)
{
return 1.0;
}
Expand All @@ -873,7 +869,7 @@ private double CalculatePartyRangeMultipler(GameMode gameMode, PartyGroup party)

private double CalculateTargetLvMultiplier(GameMode gameMode, PartyGroup party, uint targetLv)
{
if (!_GameSettings.AdjustTargetLvEnemyExp || gameMode == GameMode.BitterblackMaze)
if (!_GameSettings.EnableAdjustTargetLvEnemyExp || gameMode == GameMode.BitterblackMaze)
{
return 1.0;
}
Expand Down Expand Up @@ -992,7 +988,7 @@ public bool RequiresPawnCatchup(GameMode gameMode, PartyGroup party, Pawn pawn)

private double CalculatePawnCatchupTargetLvMultiplier(GameMode gameMode, Pawn pawn, uint targetLv)
{
if (!_GameSettings.AdjustTargetLvEnemyExp || gameMode == GameMode.BitterblackMaze)
if (!_GameSettings.EnableAdjustTargetLvEnemyExp || gameMode == GameMode.BitterblackMaze)
{
return 1.0;
}
Expand Down
4 changes: 2 additions & 2 deletions Arrowgene.Ddon.GameServer/Characters/HubManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public HashSet<GameClient> GetClientsInHub(StageId stageId)

public HashSet<GameClient> GetClientsInHub(uint stageId)
{
if (Server.Setting.GameLogicSetting.NaiveLobbyContextHandling)
if (Server.GameLogicSettings.NaiveLobbyContextHandling)
{
return Server.ClientLookup.GetAll().Distinct().ToHashSet();
}
Expand All @@ -54,7 +54,7 @@ public HashSet<GameClient> GetClientsInHub(uint stageId)
public void UpdateLobbyContextOnStageChange(GameClient client, uint previousStageId, uint targetStageId)
{
// Fallback to naive method.
if (Server.Setting.GameLogicSetting.NaiveLobbyContextHandling)
if (Server.GameLogicSettings.NaiveLobbyContextHandling)
{
NaiveLobbyHandling(client, previousStageId);
return;
Expand Down
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.GameServer/Characters/PlayPointManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PlayPointManager

private uint PP_MAX { get
{
return _Server.Setting.GameLogicSetting.PlayPointMax;
return _Server.GameLogicSettings.PlayPointMax;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.GameServer/Characters/RewardManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,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)
if (currentRewards.Count >= _Server.GameLogicSettings.RewardBoxMax)
{
return false;
}
Expand Down
10 changes: 2 additions & 8 deletions Arrowgene.Ddon.GameServer/Characters/StageManager.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
using Arrowgene.Ddon.GameServer.Dump;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Network;
using System.IO;

namespace Arrowgene.Ddon.GameServer.Characters
{
Expand Down
10 changes: 5 additions & 5 deletions Arrowgene.Ddon.GameServer/Characters/WalletManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class WalletManager
public WalletManager(DdonGameServer server)
{
Server = server;
WalletLimits = server.Setting.GameLogicSetting.WalletLimits;
WalletLimits = server.GameLogicSettings.WalletLimits;
}
public bool AddToWalletNtc(Client Client, Character Character, WalletType Type, uint Amount, uint BonusAmount = 0, ItemNoticeType updateType = ItemNoticeType.Default, DbConnection? connectionIn = null)
{
Expand Down Expand Up @@ -107,16 +107,16 @@ public uint GetScaledWalletAmount(WalletType type, uint amount)
switch (type)
{
case WalletType.Gold:
modifier = Server.Setting.GameLogicSetting.GoldModifier;
modifier = Server.GameLogicSettings.GoldModifier;
break;
case WalletType.RiftPoints:
modifier = Server.Setting.GameLogicSetting.RiftModifier;
modifier = Server.GameLogicSettings.RiftModifier;
break;
case WalletType.BloodOrbs:
modifier = Server.Setting.GameLogicSetting.BoModifier;
modifier = Server.GameLogicSettings.BoModifier;
break;
case WalletType.HighOrbs:
modifier = Server.Setting.GameLogicSetting.HoModifier;
modifier = Server.GameLogicSettings.HoModifier;
break;
default:
modifier = 1.0;
Expand Down
Loading
Loading