The great event move

This commit is contained in:
Evil Factory
2026-02-20 18:45:41 -03:00
parent c28a08a713
commit f52617deab
22 changed files with 508 additions and 112 deletions

View File

@@ -1,5 +1,6 @@
using Barotrauma.Extensions;
using Barotrauma.Items.Components;
using Barotrauma.LuaCs.Events;
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using System;
@@ -413,7 +414,8 @@ namespace Barotrauma
{
if (GameMain.IsSingleplayer)
{
var should = GameMain.LuaCs.Hook.Call<bool?>("chatMessage", message.Text, message.SenderClient, message.Type, message);
bool? should = null;
GameMain.LuaCs.EventService.PublishEvent<IEventChatMessage>(x => should = x.OnChatMessage(message.Text, message.SenderClient, message.Type, message) ?? should);
if (should != null && should.Value) { return; }
}

View File

@@ -3003,7 +3003,8 @@ namespace Barotrauma.Networking
public override void AddChatMessage(ChatMessage message)
{
var should = GameMain.LuaCs.Hook.Call<bool?>("chatMessage", message.Text, message.SenderClient, message.Type, message);
bool? should = null;
GameMain.LuaCs.EventService.PublishEvent<IEventChatMessage>(x => should = x.OnChatMessage(message.Text, message.SenderClient, message.Type, message) ?? should);
if (should != null && should.Value) { return; }
if (string.IsNullOrEmpty(message.Text)) { return; }

View File

@@ -320,11 +320,7 @@ namespace Barotrauma
if (TalentTree.IsViableTalentForCharacter(this, prefab.Identifier, talentSelection))
{
bool? should = GameMain.LuaCs.Hook.Call<bool?>("character.updateTalent", this, prefab, c);
if (should == null)
{
GiveTalent(prefab.Identifier);
}
GiveTalent(prefab.Identifier);
talentSelection.Add(prefab.Identifier);
}
}

View File

@@ -1,6 +1,8 @@
using System;
using System.Text;
using Barotrauma.LuaCs.Events;
using MoonSharp.Interpreter;
using MoonSharp.VsCodeDebugger.SDK;
using System;
using System.Text;
namespace Barotrauma.Networking
{
@@ -86,12 +88,9 @@ namespace Barotrauma.Networking
HandleSpamFilter(c, txt, out bool flaggedAsSpam, similarityMultiplier);
if (flaggedAsSpam) { return; }
var should = GameMain.LuaCs.Hook.Call<bool?>("chatMessage", txt, c, type);
if (should != null && should.Value)
{
return;
}
bool? should = null;
GameMain.LuaCs.EventService.PublishEvent<IEventChatMessage>(x => should = x.OnChatMessage(txt, c, type, ChatMessage.Create(c.Name, txt, type, null, c)) ?? should);
if (should != null && should.Value) { return; }
if (type == ChatMessageType.Order)
{

View File

@@ -3511,7 +3511,8 @@ namespace Barotrauma.Networking
return false;
}
var result = GameMain.LuaCs.Hook.Call<bool?>("tryChangeClientName", c, newName, newJob, newTeam);
bool? result = null;
GameMain.LuaCs.EventService.PublishEvent<IEventTryClientChangeName>(x => result = x.OnTryClienChangeName(c, newName, newJob, newTeam) ?? result);
if (result != null)
{
@@ -3968,15 +3969,7 @@ namespace Barotrauma.Networking
//send to chat-linked wifi components
Signal s = new Signal(message, sender: senderCharacter, source: senderRadio.Item);
senderRadio.TransmitSignal(s, sentFromChat: true);
}
var hookChatMsg = ChatMessage.Create(senderName, message, (ChatMessageType)type, senderCharacter, senderClient, changeType);
var should = GameMain.LuaCs.Hook.Call<bool?>("modifyChatMessage", hookChatMsg, senderRadio);
if (should != null && should.Value)
return;
}
//check which clients can receive the message and apply distance effects
foreach (Client client in ConnectedClients)
@@ -4778,7 +4771,7 @@ namespace Barotrauma.Networking
{
if (GameMain.Server == null || !GameMain.Server.ServerSettings.SaveServerLogs) { return; }
GameMain.LuaCs?.Hook?.Call("serverLog", line, messageType);
GameMain.LuaCs?.EventService.PublishEvent<IEventServerLog>(x => x.OnServerLog(line, messageType));
GameMain.Server.ServerSettings.ServerLog.WriteLine(line, messageType);

View File

@@ -187,16 +187,7 @@ namespace Barotrauma.Networking
{
if (netServer == null) { return; }
var skipDeny = false;
{
var result = GameMain.LuaCs.Hook.Call<bool?>("lidgren.handleConnection", inc);
if (result != null) {
if (result.Value) skipDeny = true;
else return;
}
}
if (!skipDeny && connectedClients.Count >= serverSettings.MaxPlayers)
if (connectedClients.Count >= serverSettings.MaxPlayers)
{
inc.SenderConnection.Deny(PeerDisconnectPacket.WithReason(DisconnectReason.ServerFull).ToLidgrenStringRepresentation());
return;

View File

@@ -257,12 +257,7 @@ namespace Barotrauma.Networking
protected void UpdatePendingClient(PendingClient pendingClient)
{
var skipRemove = false;
var result = GameMain.LuaCs.Hook.Call<bool?>("handlePendingClient", pendingClient);
if (result != null) skipRemove = result.Value;
if (!skipRemove && connectedClients.Count >= serverSettings.MaxPlayers)
if (connectedClients.Count >= serverSettings.MaxPlayers)
{
RemovePendingClient(pendingClient, PeerDisconnectPacket.WithReason(DisconnectReason.ServerFull));
}

View File

@@ -1,7 +1,10 @@
using Barotrauma.Items.Components;
using Barotrauma.LuaCs.Events;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using static Barotrauma.CharacterHealth;
using static Barotrauma.MedicalClinic;
namespace Barotrauma.Networking
{
@@ -96,7 +99,8 @@ namespace Barotrauma.Networking
ChatMessage.CanUseRadio(sender.Character, out WifiComponent senderRadio) &&
(recipientSpectating || ChatMessage.CanUseRadio(recipient.Character, out recipientRadio)))
{
var canUse = GameMain.LuaCs.Hook.Call<bool?>("canUseVoiceRadio", new object[] { sender, recipient });
bool? canUse = null;
GameMain.LuaCs.EventService.PublishEvent<IEventCanUseVoiceRadio>(x => canUse = x.OnCanUseVoiceRadio(sender, recipient) ?? canUse);
if (canUse != null)
{
@@ -116,7 +120,8 @@ namespace Barotrauma.Networking
}
}
float range = GameMain.LuaCs.Hook.Call<float?>("changeLocalVoiceRange", sender, recipient) ?? 1.0f;
float range = 1.0f;
GameMain.LuaCs.EventService.PublishEvent<IEventChangeLocalVoiceRange>(x => range = x.OnChangeLocalVoiceRange(sender, recipient) ?? range);
if (recipientSpectating)
{

View File

@@ -1,5 +1,6 @@
using Barotrauma.Extensions;
using Barotrauma.Items.Components;
using Barotrauma.LuaCs.Events;
using Barotrauma.Networking;
using FarseerPhysics;
using Microsoft.Xna.Framework;
@@ -1305,11 +1306,11 @@ namespace Barotrauma
//increase oxygen and clamp it above zero
// -> the character should be revived if there are no major afflictions in addition to lack of oxygen
target.Oxygen = Math.Max(target.Oxygen + 10.0f, 10.0f);
GameMain.LuaCs.Hook.Call("human.CPRSuccess", this);
GameMain.LuaCs.EventService.PublishEvent<IEventHumanCPRSuccess>(x => x.OnCharacterCPRSuccess(this));
}
else
{
GameMain.LuaCs.Hook.Call("human.CPRFailed", this);
GameMain.LuaCs.EventService.PublishEvent<IEventHumanCPRFailed>(x => x.OnCharacterCPRFailed(this));
}
}
}

View File

@@ -1,17 +1,18 @@
using Barotrauma.Networking;
using Barotrauma.Extensions;
using Barotrauma.LuaCs.Events;
using Barotrauma.Networking;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;
using FarseerPhysics.Dynamics.Joints;
using Microsoft.Xna.Framework;
using MoonSharp.Interpreter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Barotrauma.Extensions;
using LimbParams = Barotrauma.RagdollParams.LimbParams;
using JointParams = Barotrauma.RagdollParams.JointParams;
using MoonSharp.Interpreter;
using LimbParams = Barotrauma.RagdollParams.LimbParams;
namespace Barotrauma
{
@@ -857,7 +858,8 @@ namespace Barotrauma
float impactDamage = GetImpactDamage(impact, impactTolerance);
var should = GameMain.LuaCs.Hook.Call<float?>("changeFallDamage", impactDamage, character, impactPos, velocity);
float? should = null;
GameMain.LuaCs.EventService.PublishEvent<IEventChangeFallDamage>(x => should = x.OnChangeFallDamage(impactDamage, character, impactPos, velocity) ?? should);
if (should != null)
{

View File

@@ -4,6 +4,7 @@ using System.Xml.Linq;
using System;
using Barotrauma.Extensions;
using Microsoft.Xna.Framework;
using Barotrauma.LuaCs.Events;
namespace Barotrauma
{
@@ -343,7 +344,7 @@ namespace Barotrauma
if (client != null)
{
GameMain.Server.SetClientCharacter(client, husk);
GameMain.LuaCs.Hook.Call("husk.clientControlHusk", new object[] { client, husk });
GameMain.LuaCs.EventService.PublishEvent<IEventClientControlHusk>(x => x.OnClientControlHusk(client, husk));
}
#else
if (!character.IsRemotelyControlled && character == Character.Controlled)

View File

@@ -1,17 +1,19 @@
using Barotrauma.Abilities;
using Barotrauma.Abilities;
using Barotrauma.Extensions;
using Barotrauma.Extensions;
using Barotrauma.LuaCs.Events;
using Barotrauma.Networking;
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using MoonSharp.Interpreter;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Globalization;
using System.Linq;
using System.Xml.Linq;
using Barotrauma.Networking;
using Barotrauma.Extensions;
using System.Globalization;
using MoonSharp.Interpreter;
using Barotrauma.Abilities;
using static OneOf.Types.TrueFalseOrNull;
namespace Barotrauma
{
@@ -655,7 +657,8 @@ namespace Barotrauma
return;
}
var should = GameMain.LuaCs.Hook.Call<bool?>("character.applyDamage", this, attackResult, hitLimb, allowStacking);
bool? should = null;
GameMain.LuaCs.EventService.PublishEvent<IEventCharacterApplyDamage>(x => should = x.OnCharacterApplyDamage(this, attackResult, hitLimb, allowStacking) ?? should);
if (should != null && should.Value) { return; }
foreach (Affliction newAffliction in attackResult.Afflictions)
@@ -826,10 +829,9 @@ namespace Barotrauma
if (newAffliction.Prefab.TargetSpecies.Any() && newAffliction.Prefab.TargetSpecies.None(s => s == Character.SpeciesName)) { return; }
if (Character.Params.Health.ImmunityIdentifiers.Contains(newAffliction.Identifier)) { return; }
var should = GameMain.LuaCs.Hook.Call<bool?>("character.applyAffliction", this, limbHealth, newAffliction, allowStacking);
if (should != null && should.Value)
return;
bool? should = null;
GameMain.LuaCs.EventService.PublishEvent<IEventCharacterApplyAffliction>(x => should = x.OnCharacterApplyAffliction(this, limbHealth, newAffliction, allowStacking) ?? should);
if (should != null && should.Value) { return; }
Affliction existingAffliction = null;
foreach ((Affliction affliction, LimbHealth value) in afflictions)

View File

@@ -1046,9 +1046,6 @@ namespace Barotrauma
/// </remarks>
public static ImmutableHashSet<Character> GetSessionCrewCharacters(CharacterType type)
{
var result = GameMain.LuaCs.Hook.Call<Character[]?>("getSessionCrewCharacters", type);
if (result != null) return ImmutableHashSet.Create(result);
if (GameMain.GameSession?.CrewManager is not { } crewManager) { return ImmutableHashSet<Character>.Empty; }
IEnumerable<Character> players;

View File

@@ -1,4 +1,5 @@
using FarseerPhysics;
using Barotrauma.LuaCs.Events;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;
using Microsoft.Xna.Framework;
@@ -435,7 +436,7 @@ namespace Barotrauma.Items.Components
Structure targetStructure = target.UserData as Structure ?? targetFixture.UserData as Structure;
Item targetItem = target.UserData is Holdable h ? h.Item : target.UserData as Item ?? targetFixture.UserData as Item;
Entity targetEntity = targetCharacter ?? targetStructure ?? targetItem ?? target.UserData as Entity;
GameMain.LuaCs.Hook.Call("meleeWeapon.handleImpact", this, target);
GameMain.LuaCs.EventService.PublishEvent<IEventMeleeWeaponHandleImpact>(x => x.OnMeleeWeaponHandleImpact(this, target));
if (Attack != null)
{

View File

@@ -1,11 +1,13 @@
using Barotrauma.Abilities;
using Barotrauma.Extensions;
using Barotrauma.LuaCs.Events;
using Barotrauma.Networking;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Xml.Linq;
using static OneOf.Types.TrueFalseOrNull;
namespace Barotrauma.Items.Components
{
@@ -332,8 +334,9 @@ namespace Barotrauma.Items.Components
GameAnalyticsManager.AddDesignEvent("ItemDeconstructed:" + (GameMain.GameSession?.GameMode?.Preset.Identifier.Value ?? "none") + ":" + targetItem.Prefab.Identifier);
}
bool? result = GameMain.LuaCs.Hook.Call<bool?>("item.deconstructed", targetItem, this, user, allowRemove);
if (result == true) { return; }
bool? should = null;
GameMain.LuaCs.EventService.PublishEvent<IEventItemDeconstructed>(x => should = x.OnItemDeconstructed(targetItem, this, user, allowRemove) ?? should);
if (should == true) { return; }
if (targetItem.AllowDeconstruct && allowRemove)
{

View File

@@ -1,10 +1,13 @@
using Barotrauma.Networking;
using Barotrauma.LuaCs.Events;
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Xml.Linq;
using static Barotrauma.CharacterHealth;
using static Barotrauma.MedicalClinic;
namespace Barotrauma.Items.Components
{
@@ -228,8 +231,8 @@ namespace Barotrauma.Items.Components
public void TransmitSignal(Signal signal, bool sentFromChat)
{
var should = GameMain.LuaCs.Hook.Call<bool?>("wifiSignalTransmitted", this, signal, sentFromChat);
bool? should = null;
GameMain.LuaCs.EventService.PublishEvent<IEventWifiSignalTransmitted>(x => should = x.OnWifiSignalTransmitted(this, signal, sentFromChat) ?? should);
if (should != null && should.Value) { return; }
bool chatMsgSent = false;

View File

@@ -1,20 +1,23 @@
using Barotrauma.Items.Components;
using Barotrauma.Abilities;
using Barotrauma.Extensions;
using Barotrauma.Items.Components;
using Barotrauma.LuaCs.Events;
using Barotrauma.MapCreatures.Behavior;
using Barotrauma.Networking;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;
using Microsoft.Xna.Framework;
using MoonSharp.Interpreter;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;
using System.Xml.Linq;
using Barotrauma.Extensions;
using Barotrauma.MapCreatures.Behavior;
using MoonSharp.Interpreter;
using System.Collections.Immutable;
using Barotrauma.Abilities;
using static Barotrauma.CharacterHealth;
using static Barotrauma.MedicalClinic;
#if CLIENT
using Microsoft.Xna.Framework.Graphics;
@@ -3891,9 +3894,9 @@ namespace Barotrauma
}
}
var result = GameMain.LuaCs.Hook.Call<bool?>("item.readPropertyChange", this, property, parentObject, allowEditing, sender);
if (result != null && result.Value)
return;
bool? should = null;
GameMain.LuaCs.EventService.PublishEvent<IEventItemReadPropertyChange>(x => should = x.OnItemReadPropertyChange(this, property, parentObject, allowEditing, sender) ?? should);
if (should != null && should.Value) { return; }
Type type = property.PropertyType;
string logValue = "";

View File

@@ -1,6 +1,7 @@
using Barotrauma.Items.Components;
using Barotrauma.LuaCs.Data;
using Barotrauma.Networking;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using Steamworks.Ugc;
using System;
@@ -136,6 +137,408 @@ internal interface IEventCharacterCreated : IEvent<IEventCharacterCreated>
}
}
// TODO: harmony-fy
internal interface IEventHumanCPRSuccess : IEvent<IEventHumanCPRSuccess>
{
void OnCharacterCPRSuccess(HumanoidAnimController animController);
static IEventHumanCPRSuccess IEvent<IEventHumanCPRSuccess>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventHumanCPRSuccess
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public void OnCharacterCPRSuccess(HumanoidAnimController animController)
{
LuaFuncs[nameof(OnCharacterCPRSuccess)](animController);
}
}
}
// TODO: harmony-fy
internal interface IEventHumanCPRFailed : IEvent<IEventHumanCPRFailed>
{
void OnCharacterCPRFailed(HumanoidAnimController animController);
static IEventHumanCPRFailed IEvent<IEventHumanCPRFailed>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventHumanCPRFailed
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public void OnCharacterCPRFailed(HumanoidAnimController animController)
{
LuaFuncs[nameof(OnCharacterCPRFailed)](animController);
}
}
}
// TODO: harmony-fy
internal interface IEventClientControlHusk : IEvent<IEventClientControlHusk>
{
void OnClientControlHusk(Client client, Character husk);
static IEventClientControlHusk IEvent<IEventClientControlHusk>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventClientControlHusk
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public void OnClientControlHusk(Client client, Character husk)
{
LuaFuncs[nameof(OnClientControlHusk)](client, husk);
}
}
}
// TODO: harmony-fy
internal interface IEventMeleeWeaponHandleImpact : IEvent<IEventMeleeWeaponHandleImpact>
{
void OnMeleeWeaponHandleImpact(MeleeWeapon meleeWeapon, Body target);
static IEventMeleeWeaponHandleImpact IEvent<IEventMeleeWeaponHandleImpact>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventMeleeWeaponHandleImpact
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public void OnMeleeWeaponHandleImpact(MeleeWeapon meleeWeapon, Body target)
{
LuaFuncs[nameof(OnMeleeWeaponHandleImpact)](meleeWeapon, target);
}
}
}
// TODO: harmony-fy
internal interface IEventServerLog : IEvent<IEventServerLog>
{
void OnServerLog(string line, ServerLog.MessageType messageType);
static IEventServerLog IEvent<IEventServerLog>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventServerLog
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public void OnServerLog(string line, ServerLog.MessageType messageType)
{
LuaFuncs[nameof(OnServerLog)](line, messageType);
}
}
}
// TODO: harmony-fy
internal interface IEventChatMessage : IEvent<IEventChatMessage>
{
bool? OnChatMessage(string messageText, Client sender, ChatMessageType type, ChatMessage message);
static IEventChatMessage IEvent<IEventChatMessage>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventChatMessage
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public bool? OnChatMessage(string messageText, Client sender, ChatMessageType type, ChatMessage message)
{
var result = LuaFuncs[nameof(OnChatMessage)](messageText, sender, type, message);
if (result is bool b && b)
{
return true;
}
return null;
}
}
}
// TODO: harmony-fy
internal interface IEventTryClientChangeName : IEvent<IEventTryClientChangeName>
{
bool? OnTryClienChangeName(Client client, string newName, Identifier newJob, CharacterTeamType newTeam);
static IEventTryClientChangeName IEvent<IEventTryClientChangeName>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventTryClientChangeName
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public bool? OnTryClienChangeName(Client client, string newName, Identifier newJob, CharacterTeamType newTeam)
{
var result = LuaFuncs[nameof(OnTryClienChangeName)](client, newName, newJob, newTeam);
if (result is bool b)
{
return b;
}
return null;
}
}
}
// TODO: harmony-fy
internal interface IEventChangeFallDamage : IEvent<IEventChangeFallDamage>
{
float? OnChangeFallDamage(float impactDamage, Character character, Vector2 impactPos, Vector2 velocity);
static IEventChangeFallDamage IEvent<IEventChangeFallDamage>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventChangeFallDamage
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public float? OnChangeFallDamage(float impactDamage, Character character, Vector2 impactPos, Vector2 velocity)
{
var result = LuaFuncs[nameof(OnChangeFallDamage)](impactDamage, character, impactPos, velocity);
if (result is float f)
{
return f;
}
return null;
}
}
}
// TODO: harmony-fy
internal interface IEventGapOxygenUpdate : IEvent<IEventGapOxygenUpdate>
{
bool? OnGapOxygenUpdate(Gap gap, Hull hull1, Hull hull2);
static IEventGapOxygenUpdate IEvent<IEventGapOxygenUpdate>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventGapOxygenUpdate
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public bool? OnGapOxygenUpdate(Gap gap, Hull hull1, Hull hull2)
{
var result = LuaFuncs[nameof(OnGapOxygenUpdate)](gap, hull1, hull2);
if (result is bool b)
{
return b;
}
return null;
}
}
}
// TODO: harmony-fy
internal interface IEventCharacterApplyDamage : IEvent<IEventCharacterApplyDamage>
{
bool? OnCharacterApplyDamage(CharacterHealth characterHealth, AttackResult attackResult, Limb hitLimb, bool allowStacking);
static IEventCharacterApplyDamage IEvent<IEventCharacterApplyDamage>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventCharacterApplyDamage
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public bool? OnCharacterApplyDamage(CharacterHealth characterHealth, AttackResult attackResult, Limb hitLimb, bool allowStacking)
{
var result = LuaFuncs[nameof(OnCharacterApplyDamage)](characterHealth, attackResult, hitLimb, allowStacking);
if (result is bool b)
{
return b;
}
return null;
}
}
}
// TODO: harmony-fy
internal interface IEventCharacterApplyAffliction : IEvent<IEventCharacterApplyAffliction>
{
bool? OnCharacterApplyAffliction(CharacterHealth characterHealth, CharacterHealth.LimbHealth limbHealth, Affliction newAffliction, bool allowStacking);
static IEventCharacterApplyAffliction IEvent<IEventCharacterApplyAffliction>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventCharacterApplyAffliction
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public bool? OnCharacterApplyAffliction(CharacterHealth characterHealth, CharacterHealth.LimbHealth limbHealth, Affliction newAffliction, bool allowStacking)
{
var result = LuaFuncs[nameof(OnCharacterApplyAffliction)](characterHealth, limbHealth, newAffliction, allowStacking);
if (result is bool b)
{
return b;
}
return null;
}
}
}
// TODO: harmony-fy
internal interface IEventItemReadPropertyChange : IEvent<IEventItemReadPropertyChange>
{
bool? OnItemReadPropertyChange(Item item, SerializableProperty property, object parentObject, bool allowEditing, Client sender);
static IEventItemReadPropertyChange IEvent<IEventItemReadPropertyChange>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventItemReadPropertyChange
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public bool? OnItemReadPropertyChange(Item item, SerializableProperty property, object parentObject, bool allowEditing, Client sender)
{
var result = LuaFuncs[nameof(OnItemReadPropertyChange)](item, property, parentObject, allowEditing, sender);
if (result is bool b)
{
return b;
}
return null;
}
}
}
// TODO: harmony-fy
internal interface IEventCanUseVoiceRadio : IEvent<IEventCanUseVoiceRadio>
{
bool? OnCanUseVoiceRadio(Client sender, Client recipient);
static IEventCanUseVoiceRadio IEvent<IEventCanUseVoiceRadio>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventCanUseVoiceRadio
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public bool? OnCanUseVoiceRadio(Client sender, Client recipient)
{
var result = LuaFuncs[nameof(OnCanUseVoiceRadio)](sender, recipient);
if (result is bool b)
{
return b;
}
return null;
}
}
}
// TODO: harmony-fy
internal interface IEventChangeLocalVoiceRange : IEvent<IEventChangeLocalVoiceRange>
{
float? OnChangeLocalVoiceRange(Client sender, Client recipient);
static IEventChangeLocalVoiceRange IEvent<IEventChangeLocalVoiceRange>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventChangeLocalVoiceRange
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public float? OnChangeLocalVoiceRange(Client sender, Client recipient)
{
var result = LuaFuncs[nameof(OnChangeLocalVoiceRange)](sender, recipient);
if (result is float f)
{
return f;
}
return null;
}
}
}
// TODO: harmony-fy
internal interface IEventItemDeconstructed : IEvent<IEventItemDeconstructed>
{
bool? OnItemDeconstructed(Item item, Deconstructor deconstructor, Character user, bool allowRemove);
static IEventItemDeconstructed IEvent<IEventItemDeconstructed>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventItemDeconstructed
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public bool? OnItemDeconstructed(Item item, Deconstructor deconstructor, Character user, bool allowRemove)
{
var result = LuaFuncs[nameof(OnItemDeconstructed)](item, deconstructor, user, allowRemove);
if (result is bool b)
{
return b;
}
return null;
}
}
}
// TODO: harmony-fy
internal interface IEventWifiSignalTransmitted : IEvent<IEventWifiSignalTransmitted>
{
bool? OnWifiSignalTransmitted(WifiComponent wifiComponent, Signal signal, bool sentFromChat);
static IEventWifiSignalTransmitted IEvent<IEventWifiSignalTransmitted>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc)
=> new LuaWrapper(luaFunc);
public sealed class LuaWrapper : LuaWrapperBase, IEventWifiSignalTransmitted
{
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
{
}
public bool? OnWifiSignalTransmitted(WifiComponent wifiComponent, Signal signal, bool sentFromChat)
{
var result = LuaFuncs[nameof(OnWifiSignalTransmitted)](wifiComponent, signal, sentFromChat);
if (result is bool b)
{
return b;
}
return null;
}
}
}
internal interface IEventCharacterDeath : IEvent<IEventCharacterDeath>
{
void OnCharacterDeath(Character character, Affliction causeOfDeathAffliction, CauseOfDeathType causeOfDeathType);
@@ -156,29 +559,6 @@ internal interface IEventCharacterDeath : IEvent<IEventCharacterDeath>
}
}
/*
internal interface IEventHumanCPRFailed : IEvent<IEventHumanCPRFailed>
{
void OnHumanCPRFailed(Character character);
static IEventHumanCPRFailed IEvent<IEventHumanCPRFailed>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
{
IsLuaRunner = Return<bool>.Arguments(() => true),
OnHumanCPRFailed = ReturnVoid.Arguments((Character character) => luaFunc[nameof(OnHumanCPRFailed)](character))
}.ActLike<IEventHumanCPRFailed>();
}
internal interface IEventHumanCPRSuccess : IEvent<IEventHumanCPRSuccess>
{
void OnHumanCPRSuccess(Character character);
static IEventHumanCPRSuccess IEvent<IEventHumanCPRSuccess>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) => new
{
IsLuaRunner = Return<bool>.Arguments(() => true),
OnHumanCPRSuccess = ReturnVoid.Arguments((Character character) => luaFunc[nameof(OnHumanCPRSuccess)](character))
}.ActLike<IEventHumanCPRSuccess>();
}
*/
public interface IEventKeyUpdate : IEvent<IEventKeyUpdate>
{
void OnKeyUpdate(double deltaTime);

View File

@@ -1,4 +1,5 @@
using Barotrauma.Networking;
using Barotrauma.LuaCs.Events;
using Barotrauma.Networking;
using FluentResults;
using HarmonyLib;
using Microsoft.Xna.Framework;
@@ -59,7 +60,7 @@ public partial class LoggerService : ILoggerService
if (!_isInsideLogCall)
{
_isInsideLogCall = true;
GameMain.LuaCs?.Hook?.Call("serverLog", logMessage, log.MessageType);
GameMain.LuaCs?.EventService.PublishEvent<IEventServerLog>(x => x.OnServerLog(logMessage, log.MessageType));
_isInsideLogCall = false;
}
}

View File

@@ -179,6 +179,25 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
_eventService.RegisterLuaEventAlias<IEventCharacterDeath>("character.death", nameof(IEventCharacterDeath.OnCharacterDeath));
_eventService.RegisterLuaEventAlias<IEventCharacterDamageLimb>("character.damageLimb", nameof(IEventCharacterDamageLimb.OnCharacterDamageLimb));
_eventService.RegisterLuaEventAlias<IEventGiveCharacterJobItems>("character.giveJobItems", nameof(IEventGiveCharacterJobItems.OnGiveCharacterJobItems));
_eventService.RegisterLuaEventAlias<IEventHumanCPRSuccess>("character.CPRSuccess", nameof(IEventHumanCPRSuccess.OnCharacterCPRSuccess));
_eventService.RegisterLuaEventAlias<IEventHumanCPRFailed>("character.CPRFailed", nameof(IEventHumanCPRFailed.OnCharacterCPRFailed));
_eventService.RegisterLuaEventAlias<IEventCharacterApplyDamage>("character.applyDamage", nameof(IEventCharacterApplyDamage.OnCharacterApplyDamage));
_eventService.RegisterLuaEventAlias<IEventCharacterApplyAffliction>("character.applyAffliction", nameof(IEventCharacterApplyAffliction.OnCharacterApplyAffliction));
_eventService.RegisterLuaEventAlias<IEventGapOxygenUpdate>("gapOxygenUpdate", nameof(IEventGapOxygenUpdate.OnGapOxygenUpdate));
_eventService.RegisterLuaEventAlias<IEventClientControlHusk>("husk.clientControlHusk", nameof(IEventClientControlHusk.OnClientControlHusk));
_eventService.RegisterLuaEventAlias<IEventMeleeWeaponHandleImpact>("meleeWeapon.handleImpact", nameof(IEventMeleeWeaponHandleImpact.OnMeleeWeaponHandleImpact));
_eventService.RegisterLuaEventAlias<IEventServerLog>("serverLog", nameof(IEventServerLog.OnServerLog));
_eventService.RegisterLuaEventAlias<IEventTryClientChangeName>("tryChangeClientName", nameof(IEventTryClientChangeName.OnTryClienChangeName));
_eventService.RegisterLuaEventAlias<IEventChangeFallDamage>("changeFallDamage", nameof(IEventChangeFallDamage.OnChangeFallDamage));
_eventService.RegisterLuaEventAlias<IEventCanUseVoiceRadio>("canUseVoiceRadio", nameof(IEventCanUseVoiceRadio.OnCanUseVoiceRadio));
_eventService.RegisterLuaEventAlias<IEventChangeLocalVoiceRange>("changeLocalVoiceRange", nameof(IEventChangeLocalVoiceRange.OnChangeLocalVoiceRange));
_eventService.RegisterLuaEventAlias<IEventRoundStarted>("roundStart", nameof(IEventRoundStarted.OnRoundStart));
_eventService.RegisterLuaEventAlias<IEventRoundEnded>("roundEnd", nameof(IEventRoundEnded.OnRoundEnd));
@@ -190,6 +209,8 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
_eventService.RegisterLuaEventAlias<IEventItemRemoved>("item.removed", nameof(IEventItemRemoved.OnItemRemoved));
_eventService.RegisterLuaEventAlias<IEventItemUse>("item.use", nameof(IEventItemUse.OnItemUsed));
_eventService.RegisterLuaEventAlias<IEventItemSecondaryUse>("item.secondaryUse", nameof(IEventItemSecondaryUse.OnItemSecondaryUsed));
_eventService.RegisterLuaEventAlias<IEventItemReadPropertyChange>("item.readPropertyChange", nameof(IEventItemReadPropertyChange.OnItemReadPropertyChange));
_eventService.RegisterLuaEventAlias<IEventItemDeconstructed>("item.deconstructed", nameof(IEventItemDeconstructed.OnItemDeconstructed));
_eventService.RegisterLuaEventAlias<IEventInventoryPutItem>("inventoryPutItem", nameof(IEventInventoryPutItem.OnInventoryPutItem));
_eventService.RegisterLuaEventAlias<IEventInventoryItemSwap>("inventoryItemSwap", nameof(IEventInventoryItemSwap.OnInventoryItemSwap));

View File

@@ -1,13 +1,15 @@
using Barotrauma.Extensions;
using Barotrauma.Items.Components;
using Barotrauma.LuaCs.Events;
using Barotrauma.Networking;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using MoonSharp.Interpreter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using MoonSharp.Interpreter;
namespace Barotrauma
{
@@ -883,8 +885,8 @@ namespace Barotrauma
if (Math.Max(hull1.WorldSurface + hull1.WaveY[hull1.WaveY.Length - 1], hull2.WorldSurface + hull2.WaveY[0]) > WorldRect.Y) { return; }
}
var should = GameMain.LuaCs.Hook.Call<bool?>("gapOxygenUpdate", this, hull1, hull2);
bool? should = null;
GameMain.LuaCs.EventService.PublishEvent<IEventGapOxygenUpdate>(x => should = x.OnGapOxygenUpdate(this, hull1, hull2) ?? should);
if (should != null && should.Value) return;
float totalOxygen = hull1.Oxygen + hull2.Oxygen;

View File

@@ -213,9 +213,6 @@ namespace Barotrauma.Networking
public void Update(float deltaTime)
{
var result = GameMain.LuaCs.Hook.Call<bool?>("respawnManager.update");
if (result != null && result.Value) { return; }
foreach (var teamSpecificState in teamSpecificStates.Values)
{
if (RespawnShuttles.None())