Skip to content
Merged
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: 0 additions & 2 deletions Maple2.Server.DebugGame/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Grpc.Core;
using Grpc.Net.Client;
using Maple2.Database.Storage;
using Maple2.Lua;
using Maple2.Server.Core.Constants;
using Maple2.Server.Core.Modules;
using Maple2.Server.Core.Network;
Expand Down Expand Up @@ -106,7 +105,6 @@
autofac.RegisterType<GameSession>()
.PropertiesAutowired()
.AsSelf();
autofac.RegisterInstance(new Lua(Target.LOCALE));
autofac.RegisterType<ItemStatsCalculator>()
.PropertiesAutowired()
.SingleInstance();
Expand Down
3,173 changes: 3,173 additions & 0 deletions Maple2.Server.Game/LuaFunctions/Lua.cs

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions Maple2.Server.Game/Manager/BlackMarketManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Maple2.Model.Error;
using Maple2.Model.Game;
using Maple2.Model.Metadata;
using Maple2.Server.Game.LuaFunctions;
using Maple2.Server.Game.Packets;
using Maple2.Server.Game.Session;
using Maple2.Server.World.Service;
Expand All @@ -13,15 +14,12 @@
namespace Maple2.Server.Game.Manager;

public sealed class BlackMarketManager {
private readonly Lua.Lua lua;

private readonly GameSession session;

private readonly ILogger logger = Log.Logger.ForContext<BlackMarketManager>();

public BlackMarketManager(GameSession session, Lua.Lua lua) {
public BlackMarketManager(GameSession session) {
this.session = session;
this.lua = lua;
}

public void LoadMyListings() {
Expand All @@ -47,8 +45,8 @@ public void Add(long itemUid, long price, int quantity) {
return;
}

float depositPercent = lua.CalcBlackMarketRegisterDepositPercent();
long depositFee = lua.CalcBlackMarketRegisterDeposit((long) (price * quantity * depositPercent));
float depositPercent = Lua.CalcBlackMarketRegisterDepositPercent();
long depositFee = Lua.CalcBlackMarketRegisterDeposit((long) (price * quantity * depositPercent));

if (session.Currency.CanAddMeso(-depositFee) != -depositFee) {
session.Send(BlackMarketPacket.Error(BlackMarketError.s_err_lack_meso));
Expand Down Expand Up @@ -270,7 +268,7 @@ public void Purchase(long listingId, int quantity) {
private Mail? CreateSellerMail(BlackMarketListing listing, int quantity) {
using GameStorage.Request db = session.GameStorage.Context();

float costRate = lua.CalcBlackMarketCostRate();
float costRate = Lua.CalcBlackMarketCostRate();
long tax = (long) (costRate * (quantity * listing.Price));

bool sellerIsPremium = false;
Expand Down
7 changes: 3 additions & 4 deletions Maple2.Server.Game/Manager/ExperienceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Maple2.Model.Enum;
using Maple2.Model.Game;
using Maple2.Model.Metadata;
using Maple2.Server.Game.LuaFunctions;
using Maple2.Server.Game.Model;
using Maple2.Server.Game.Packets;
using Maple2.Server.Game.Session;
Expand All @@ -12,7 +13,6 @@ namespace Maple2.Server.Game.Manager;

public sealed class ExperienceManager {
private readonly GameSession session;
private readonly Lua.Lua lua;
private long Exp {
get => session.Player.Value.Character.Exp;
set => session.Player.Value.Character.Exp = value;
Expand Down Expand Up @@ -52,9 +52,8 @@ public long PrestigeCurrentExp {

private int ChainKillCount { get; set; }

public ExperienceManager(GameSession session, Lua.Lua lua) {
public ExperienceManager(GameSession session) {
this.session = session;
this.lua = lua;
Init();
}

Expand All @@ -75,7 +74,7 @@ public void OnKill(IActor npc) {
FieldNpc fieldNpc = (npc as FieldNpc)!;
// TODO: Check if there are level requirements for Chain Kill Count to count ?
ChainKillCount++;
float expRate = lua.CalcKillCountBonusExpRate(ChainKillCount);
float expRate = Lua.CalcKillCountBonusExpRate(ChainKillCount);

// TODO: Using table ID 2. Need confirmation if particular maps (or dungeons) use a different table
long expGained = fieldNpc.Value.Metadata.Basic.CustomExp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Maple2.Model.Enum;
using Maple2.Model.Game;
using Maple2.Model.Metadata;
using Maple2.Server.Game.LuaFunctions;
using Maple2.Server.Game.Model;
using Maple2.Server.Game.Model.Skill;
using Maple2.Server.Game.Packets;
Expand Down Expand Up @@ -325,7 +326,7 @@ public FieldItem SpawnItem(IFieldEntity owner, Vector3 position, Vector3 rotatio
continue;
}

int spawnWeight = Lua.CalcNpcSpawnWeight(npc.Basic.MainTags.Length, npc.Basic.SubTags.Length, npc.Basic.RareDegree, npc.Basic.Difficulty);
int spawnWeight = (int) Lua.CalcNpcSpawnWeight(npc.Basic.MainTags.Length, npc.Basic.SubTags.Length, npc.Basic.RareDegree, npc.Basic.Difficulty);
spawnNpcs.Add(npc, spawnWeight);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public partial class FieldManager : IField {
public ServerTableMetadataStorage ServerTableMetadata { get; init; } = null!;
public RideMetadataStorage RideMetadata { get; init; } = null!;
public ItemStatsCalculator ItemStatsCalc { get; init; } = null!;
public Lua.Lua Lua { get; init; } = null!;
public Factory FieldFactory { get; init; } = null!;
public IGraphicsContext DebugGraphicsContext { get; init; } = null!;
// ReSharper restore All
Expand Down
1 change: 0 additions & 1 deletion Maple2.Server.Game/Manager/Field/FieldManager/IField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public interface IField : IDisposable {
public FunctionCubeMetadataStorage FunctionCubeMetadata { get; init; }
public ServerTableMetadataStorage ServerTableMetadata { get; init; }
public ItemStatsCalculator ItemStatsCalc { get; init; }
public Lua.Lua Lua { get; init; }
public IGraphicsContext DebugGraphicsContext { get; init; }
// ReSharper restore All
#endregion
Expand Down
4 changes: 1 addition & 3 deletions Maple2.Server.Game/Manager/ItemEnchantManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ IngredientInfo[] Build(int onyx, int chaosOnyx, int crystalFragment) {
}

private readonly GameSession session;
private readonly Lua.Lua lua;
private readonly ILogger logger = Log.Logger.ForContext<ItemEnchantManager>();

public EnchantType Type { get; private set; }
Expand All @@ -67,9 +66,8 @@ IngredientInfo[] Build(int onyx, int chaosOnyx, int crystalFragment) {
private EnchantResult enchantResult;


public ItemEnchantManager(GameSession session, Lua.Lua lua) {
public ItemEnchantManager(GameSession session) {
this.session = session;
this.lua = lua;

catalysts = new List<IngredientInfo>();
fodders = new Dictionary<long, Item>();
Expand Down
7 changes: 3 additions & 4 deletions Maple2.Server.Game/Manager/MasteryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Maple2.Model.Metadata;
using Maple2.PacketLib.Tools;
using Maple2.Server.Core.Packets;
using Maple2.Server.Game.LuaFunctions;
using Maple2.Server.Game.Manager.Field;
using Maple2.Server.Game.Model;
using Maple2.Server.Game.Packets;
Expand All @@ -15,13 +16,11 @@ namespace Maple2.Server.Game.Manager;
public class MasteryManager {

private readonly GameSession session;
private readonly Lua.Lua lua;
private Mastery Mastery => session.Player.Value.Character.Mastery;
private IDictionary<int, int> gatheringCounts => session.Config.GatheringCounts;

public MasteryManager(GameSession session, Lua.Lua lua) {
public MasteryManager(GameSession session) {
this.session = session;
this.lua = lua;
}

public int this[MasteryType type] {
Expand Down Expand Up @@ -131,7 +130,7 @@ private void GatherCommon(int recipeId, ByteWriter successPacket, ByteWriter fai
if (session.Field is HomeFieldManager homeField) {
myHome = homeField.OwnerId == session.AccountId ? 1 : 0;
}
float successRate = lua.CalcGatheringObjectSuccessRate(currentCount, recipeMetadata.HighRateLimitCount, recipeMetadata.NormalRateLimitCount, myHome);
float successRate = Lua.CalcGatheringObjectSuccessRate(currentCount, recipeMetadata.HighRateLimitCount, recipeMetadata.NormalRateLimitCount, myHome);

int gatheringAmount = 0;
BeforeConditionUpdate(recipeMetadata);
Expand Down
13 changes: 8 additions & 5 deletions Maple2.Server.Game/Manager/StatsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Maple2.Model.Game;
using Maple2.Model.Metadata;
using Maple2.Server.Core.Formulas;
using Maple2.Server.Game.LuaFunctions;
using Maple2.Server.Game.Model;
using Maple2.Server.Game.Packets;
using Maple2.Server.Game.Session;
Expand Down Expand Up @@ -87,8 +88,7 @@ double BonusAttackCoefficient(FieldPlayer player) {
/// <returns>Critical damage</returns>
public float GetCriticalDamage(float targetCriticalDamageResistance, int mode = 0) {
float criticalDamage = Actor switch {
FieldPlayer player => player.Lua.CalcCritDamage(Values[BasicAttribute.CriticalDamage].Total, mode),
FieldNpc npc => npc.Lua.CalcCritDamage(Values[BasicAttribute.CriticalDamage].Total, mode),
FieldPlayer or FieldNpc => Lua.CalcCritDamage(Values[BasicAttribute.CriticalDamage].Total, mode),
_ => 0
};
//TODO: Apply target's resistance. Need to figure out formula for this.
Expand All @@ -103,8 +103,8 @@ public float GetCriticalDamage(float targetCriticalDamageResistance, int mode =
/// <returns>DamageType. If successful crit, returns DamageType.Critical. else returns DamageType.Normal</returns>
public DamageType GetCriticalRate(long targetCriticalEvasion, double casterCriticalOverride) {
float criticalChance = Actor switch {
FieldPlayer player => player.Lua.CalcPlayerCritRate((int) player.Value.Character.Job.Code(), player.Stats.Values[BasicAttribute.Luck].Total, player.Stats.Values[BasicAttribute.CriticalRate].Total, targetCriticalEvasion, 0, 0),
FieldNpc npc => npc.Lua.CalcNpcCritRate(npc.Stats.Values[BasicAttribute.Luck].Total, npc.Stats.Values[BasicAttribute.CriticalRate].Total, targetCriticalEvasion),
FieldPlayer player => Lua.CalcPlayerCritRate((int) player.Value.Character.Job.Code(), player.Stats.Values[BasicAttribute.Luck].Total, player.Stats.Values[BasicAttribute.CriticalRate].Total, targetCriticalEvasion, 0, 0),
FieldNpc npc => Lua.CalcNpcCritRate(npc.Stats.Values[BasicAttribute.Luck].Total, npc.Stats.Values[BasicAttribute.CriticalRate].Total, targetCriticalEvasion),
_ => 0
};

Expand Down Expand Up @@ -158,7 +158,7 @@ private void AddEquips(FieldPlayer player) {
AddItemStats(item.Stats);
}
Log.Logger.Debug("Calculating Gearscore. Item ID: {id} - Gearscore: {gearscore} - Rarity: {rarity}, Enchant Level: {enchantLevel}, Limit Break Level: {limitBreakLevel}", item.Metadata.Id, item.Metadata.Property.GearScore, item.Rarity, item.Enchant?.Enchants ?? 0, item.LimitBreak?.Level ?? 0);
Values.GearScore += player.Lua.CalcItemLevel(item.Metadata.Property.GearScore, item.Rarity, item.Type.Type, item.Enchant?.Enchants ?? 0, item.LimitBreak?.Level ?? 0).Item1;
Values.GearScore += Lua.CalcItemLevel(item.Metadata.Property.GearScore, item.Rarity, item.Type.Type, item.Enchant?.Enchants ?? 0, item.LimitBreak?.Level ?? 0).Item1;
player.Session.Dungeon.UpdateDungeonEnterLimit();
player.Session.ConditionUpdate(ConditionType.item_gear_score, counter: Values.GearScore);

Expand Down Expand Up @@ -206,6 +206,9 @@ private void StatConversion(FieldPlayer player) {
private void AddItemStats(ItemStats stats) {
for (int type = 0; type < ItemStats.TYPE_COUNT; type++) {
foreach ((BasicAttribute attribute, BasicOption option) in stats[(ItemStats.Type) type].Basic) {
if (attribute is BasicAttribute.CriticalDamage) {
Log.Logger.Information("Adding {attribute} {option} to {actor}", attribute, option, Actor);
}
Values[attribute].AddTotal(option);
}
foreach ((SpecialAttribute attribute, SpecialOption option) in stats[(ItemStats.Type) type].Special) {
Expand Down
1 change: 0 additions & 1 deletion Maple2.Server.Game/Maple2.Server.Game.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<PackageReference Include="IronPython.StdLib" Version="3.4.1">
<!-- <ExcludeAssets>contentFiles</ExcludeAssets>-->
</PackageReference>
<PackageReference Include="Maple2.Lua" Version="2.0.1"/>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0"/>
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0"/>
<PackageReference Include="Serilog.Expressions" Version="3.4.1"/>
Expand Down
2 changes: 0 additions & 2 deletions Maple2.Server.Game/Model/Field/Actor/Actor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public virtual Vector3 Rotation {
public SkillQueue ActiveSkills { get; init; }

public virtual BuffManager Buffs { get; }
public Lua.Lua Lua { get; init; }

/// <summary>
/// Counter for skill casting ID creation
Expand All @@ -73,7 +72,6 @@ protected Actor(FieldManager field, int objectId, T value, NpcMetadataStorage np
SkillState = new SkillState(this);
Stats = new StatsManager(this);
PositionTick = new ValueTuple<Vector3, long, long>(Vector3.Zero, 0, 0);
Lua = new Lua.Lua(Target.LOCALE);
ActiveSkills = new SkillQueue();
}

Expand Down
1 change: 1 addition & 0 deletions Maple2.Server.Game/Model/Stats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Maple2.Model.Game;
using Maple2.Model.Metadata;
using Maple2.Server.Core.Formulas;
using Serilog;

namespace Maple2.Server.Game.Model;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Maple2.PacketLib.Tools;
using Maple2.Server.Core.Constants;
using Maple2.Server.Core.PacketHandlers;
using Maple2.Server.Game.LuaFunctions;
using Maple2.Server.Game.Packets;
using Maple2.Server.Game.Session;
using Maple2.Server.Game.Util;
Expand All @@ -25,7 +26,6 @@ private enum Command : byte {
#region Autofac Autowired
// ReSharper disable MemberCanBePrivate.Global
public required ItemStatsCalculator ItemStatsCalc { private get; init; }
public required Lua.Lua Lua { private get; init; }
// ReSharper restore All
#endregion

Expand Down
3 changes: 2 additions & 1 deletion Maple2.Server.Game/PacketHandlers/HomeDoctorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Maple2.Server.Core.Constants;
using Maple2.Server.Core.PacketHandlers;
using Maple2.Server.Core.Packets;
using Maple2.Server.Game.LuaFunctions;
using Maple2.Server.Game.Session;

namespace Maple2.Server.Game.PacketHandlers;
Expand All @@ -21,7 +22,7 @@ public override void Handle(GameSession session, IByteReader packet) {
return;
}

int cost = session.Lua.CalcResolvePenaltyPrice((ushort) session.Player.Value.Character.Level, session.Config.DeathCount, 0);
int cost = Lua.CalcResolvePenaltyPrice((ushort) session.Player.Value.Character.Level, session.Config.DeathCount, 0);
if (session.Currency.Meso < cost) {
return;
}
Expand Down
1 change: 0 additions & 1 deletion Maple2.Server.Game/PacketHandlers/ItemDismantleHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ private enum Command : byte {
// ReSharper disable MemberCanBePrivate.Global
public required ItemMetadataStorage ItemMetadata { private get; init; }
public required TableMetadataStorage TableMetadata { private get; init; }
public required Lua.Lua Lua { private get; init; }
// ReSharper restore All
#endregion

Expand Down
2 changes: 1 addition & 1 deletion Maple2.Server.Game/PacketHandlers/ItemSocketHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Maple2.PacketLib.Tools;
using Maple2.Server.Core.Constants;
using Maple2.Server.Core.PacketHandlers;
using Maple2.Server.Game.LuaFunctions;
using Maple2.Server.Game.Packets;
using Maple2.Server.Game.Session;
using static Maple2.Model.Error.ItemSocketError;
Expand All @@ -31,7 +32,6 @@ private enum Command : byte {
// ReSharper disable MemberCanBePrivate.Global
public required ItemMetadataStorage ItemMetadata { private get; init; }
public required TableMetadataStorage TableMetadata { private get; init; }
public required Lua.Lua Lua { private get; init; }
// ReSharper restore All
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Maple2.PacketLib.Tools;
using Maple2.Server.Core.Constants;
using Maple2.Server.Core.PacketHandlers;
using Maple2.Server.Game.LuaFunctions;
using Maple2.Server.Game.Model;
using Maple2.Server.Game.Session;

Expand All @@ -21,7 +22,7 @@ public override void Handle(GameSession session, IByteReader packet) {
}

int mode = session.Field.Metadata.Property.Continent == Continent.ShadowWorld ? 1 : 0;
int cost = session.Lua.CalcResolvePenaltyPrice((ushort) session.Player.Value.Character.Level, session.Config.DeathCount, mode);
int cost = Lua.CalcResolvePenaltyPrice((ushort) session.Player.Value.Character.Level, session.Config.DeathCount, mode);
if (session.Currency.Meso < cost) {
return;
}
Expand Down
5 changes: 3 additions & 2 deletions Maple2.Server.Game/PacketHandlers/RevivalHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Maple2.Server.Core.Constants;
using Maple2.Server.Core.PacketHandlers;
using Maple2.Server.Core.Packets;
using Maple2.Server.Game.LuaFunctions;
using Maple2.Server.Game.Session;

namespace Maple2.Server.Game.PacketHandlers;
Expand Down Expand Up @@ -58,12 +59,12 @@ private void HandleInstantRevive(GameSession session, IByteReader packet) {
}
session.Send(NoticePacket.Notice(NoticePacket.Flags.Alert | NoticePacket.Flags.Message, StringCode.s_revival_use_coupon));
} else {
int totalMaxCount = session.Lua.GetMesoRevivalDailyMaxCount();
int totalMaxCount = Lua.GetMesoRevivalDailyMaxCount();
if (session.Config.InstantReviveCount >= totalMaxCount) {
return;
}

int cost = session.Lua.CalcRevivalPrice((ushort) session.Player.Value.Character.Level);
int cost = Lua.CalcRevivalPrice((ushort) session.Player.Value.Character.Level);
if (session.Currency.Meso < cost) {
// Client sends error
return;
Expand Down
2 changes: 1 addition & 1 deletion Maple2.Server.Game/PacketHandlers/TaxiHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Maple2.Server.Core.Constants;
using Maple2.Server.Core.PacketHandlers;
using Maple2.Server.Core.Packets;
using Maple2.Server.Game.LuaFunctions;
using Maple2.Server.Game.Packets;
using Maple2.Server.Game.Session;
using Maple2.Server.Game.Util;
Expand All @@ -30,7 +31,6 @@ private enum Command : byte {
public required MapMetadataStorage MapMetadata { private get; init; }
public required MapEntityStorage EntityMetadata { private get; init; }
public required WorldMapGraphStorage WorldMapGraph { private get; init; }
public required Lua.Lua Lua { private get; init; }
// ReSharper restore All
#endregion

Expand Down
2 changes: 0 additions & 2 deletions Maple2.Server.Game/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Grpc.Core;
using Grpc.Net.Client;
using Maple2.Database.Storage;
using Maple2.Lua;
using Maple2.Server.Core.Constants;
using Maple2.Server.Core.Modules;
using Maple2.Server.Core.Network;
Expand Down Expand Up @@ -113,7 +112,6 @@
autofac.RegisterType<GameSession>()
.PropertiesAutowired()
.AsSelf();
autofac.RegisterInstance(new Lua(Target.LOCALE));
autofac.RegisterType<ItemStatsCalculator>()
.PropertiesAutowired()
.SingleInstance();
Expand Down
Loading