Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
lostinplace committed May 20, 2019
1 parent 9e5890a commit ac4016e
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 23 deletions.
3 changes: 2 additions & 1 deletion EmpyrionAPIDefinitions/APIManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public static class APIManifest
new APIEvent(CmdId.Event_Playfield_List, typeof(PlayfieldList)),
new APIEvent(CmdId.Event_Playfield_Stats, typeof(PlayfieldStats)),
new APIEvent(CmdId.Event_Structure_BlockStatistics, typeof(IdStructureBlockInfo)),
new APIEvent(CmdId.Event_DialogButtonIndex, typeof(IdAndIntValue))
new APIEvent(CmdId.Event_DialogButtonIndex, typeof(IdAndIntValue)),
new APIEvent(CmdId.Event_ChatMessageEx, typeof(ChatMsgData)),
};

public static Dictionary<CmdId, APIEvent> APIEventTable = EventManifest.ToDictionary(x => x.CmdId);
Expand Down
29 changes: 29 additions & 0 deletions EmpyrionAPITools/Autowire.APIEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,23 @@ public static event Action<IdAndIntValue> Event_DialogButtonIndex
eventTable[CmdId.Event_DialogButtonIndex] = value;
}
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1009:DeclareEventHandlersCorrectly")]
public static event Action<ChatMsgData> Event_ChatMessageEx
{
add {
if (eventTable.ContainsKey(CmdId.Event_ChatMessageEx))
eventTable[CmdId.Event_ChatMessageEx] = (Action<ChatMsgData>)eventTable[CmdId.Event_ChatMessageEx] + value;
else
eventTable[CmdId.Event_ChatMessageEx] = value;
}
remove {
if (eventTable.ContainsKey(CmdId.Event_ChatMessageEx))
eventTable[CmdId.Event_ChatMessageEx] = (Action<ChatMsgData>)eventTable[CmdId.Event_ChatMessageEx] - value;
else
eventTable[CmdId.Event_ChatMessageEx] = value;
}
}

}

Expand Down Expand Up @@ -973,5 +990,17 @@ public event Action<IdAndIntValue> Event_DialogButtonIndex
}
}


[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1009:DeclareEventHandlersCorrectly")]
public event Action<ChatMsgData> Event_ChatMessageEx
{
add {
Broker.Event_ChatMessageEx += value;
}
remove {
Broker.Event_ChatMessageEx -= value;
}
}

}
}
2 changes: 1 addition & 1 deletion EmpyrionAPITools/Autowire.APIEvents.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="C:\Program Files (x86)\Steam\SteamApps\common\Empyrion - Dedicated Server\EmpyrionDedicated_Data\Managed\Mif.dll" #>
<#@ assembly name="$(SolutionDir)dependencies\Mif.dll" #>
<#@ assembly name="$(SolutionDir)EmpyrionAPIDefinitions\bin\$(Configuration)\EmpyrionAPIDefinitions.dll" #>
<#@ import namespace="EmpyrionAPIDefinitions" #>
<#@ import namespace="System.Linq" #>
Expand Down
2 changes: 1 addition & 1 deletion EmpyrionAPITools/Autowire.APIRequests.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="C:\Program Files (x86)\Steam\SteamApps\common\Empyrion - Dedicated Server\EmpyrionDedicated_Data\Managed\Mif.dll" #>
<#@ assembly name="$(SolutionDir)dependencies\Mif.dll" #>
<#@ assembly name="$(SolutionDir)EmpyrionAPIDefinitions\bin\$(Configuration)\EmpyrionAPIDefinitions.dll" #>
<#@ import namespace="EmpyrionAPIDefinitions" #>
<#@ import namespace="System.Linq" #>
Expand Down
2 changes: 1 addition & 1 deletion EmpyrionAPITools/ChatCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace EmpyrionAPITools
{
public class ChatCommand
{
public delegate void ChatCommandHandler(ChatInfo info, Dictionary<string, string> arguments = null);
public delegate void ChatCommandHandler(ChatMsgData info, Dictionary<string, string> arguments = null);

public readonly string invocationPattern;
public ChatCommandHandler handler;
Expand Down
4 changes: 2 additions & 2 deletions EmpyrionAPITools/EmpyrionAPITools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
<DesignTime>True</DesignTime>
<DependentUpon>Autowire.APIEvents.tt</DependentUpon>
</Compile>
<Compile Include="Broker.cs" />
<Compile Include="Broker.Types.cs" />
<Compile Include="Autowire.APIRequests.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Autowire.APIRequests.tt</DependentUpon>
</Compile>
<Compile Include="Broker.cs" />
<Compile Include="Broker.Types.cs" />
<Compile Include="ChatCommand.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="GenericAPICommand.cs" />
Expand Down
13 changes: 7 additions & 6 deletions EmpyrionAPITools/SimpleMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected void MessagePlayer(int playerId, string message, MessagePriorityType p
void ModInterface.Game_Event(CmdId eventId, ushort seqNr, object data)
{
Broker.HandleGameEvent(eventId, seqNr, data);
if (eventId == CmdId.Event_ChatMessage) SimpleMod_ProcessChatCommands((ChatInfo)data);
if (eventId == CmdId.Event_ChatMessageEx) SimpleMod_ProcessChatCommands((ChatMsgData)data);

API_Message_Received?.Invoke(eventId, seqNr, data);
}
Expand All @@ -109,19 +109,20 @@ void ModInterface.Game_Start(ModGameAPI dediAPI)
this.ChatCommandManager = new ChatCommandManager(this.ChatCommands);
}

private void SimpleMod_ProcessChatCommands(ChatInfo obj)
private void SimpleMod_ProcessChatCommands(ChatMsgData data)
{
var match = ChatCommandManager.MatchCommand(obj.msg);
var match = ChatCommandManager.MatchCommand(data.Text);
if (match == null) return;
if (match.command.minimumPermissionLevel > EmpyrionAPIDefinitions.PermissionType.Player)
{
this.Request_Player_Info(obj.playerId.ToId(), (info) => {
this.Request_Player_Info(data.SenderEntityId.ToId(), (info) =>
{
if (info.permission < (int)match.command.minimumPermissionLevel) return;
match.command.handler(obj, match.parameters);
match.command.handler(data, match.parameters);
});
return;
}
match.command.handler(obj, match.parameters);
match.command.handler(data, match.parameters);
}

void ModInterface.Game_Update()
Expand Down
21 changes: 10 additions & 11 deletions ExampleMod/ExampleMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@ public override void Initialize(ModGameAPI dediAPI)
this.Event_ChatMessage += ExampleMod_Event_HandleLottoChatMessage;
this.Event_GameEvent += ExampleMod_Event_GameEvent;
this.Event_Statistics += PlayerDied_Event_Statistics;
this.ChatCommands.Add(new ChatCommand(@"/repeat (?<repeat>\S+)", ChatCommand_TestMessage));
this.ChatCommands.Add(new ChatCommand(@"::repeat (?<repeat>\S+)", ChatCommand_TestMessage));
this.ChatCommands.Add(new ChatCommand(@"!loudly (?<yellthis>.+)", (data, args) => {
var msg = new IdMsgPrio()
{
id = data.playerId,
id = data.SenderEntityId,
msg = $"{args["yellthis"].ToUpper()}!!!!!"
};
this.Request_InGameMessage_SinglePlayer(msg);
}));

this.ChatCommands.Add(new ChatCommand(@"/explosion", (data, __) => {
this.ChatCommands.Add(new ChatCommand(@"::explosion", (data, __) => {
var dialogData = new DialogBoxData()
{
Id = data.playerId,
Id = data.SenderEntityId,
MsgText = "BOOM!",
PosButtonText = "yes",
NegButtonText = "No"
};
this.Request_ShowDialog_SinglePlayer(dialogData, (result) => {
var resultInterpreted = result.Value == 0 ? "YES": "NO";
this.Request_InGameMessage_SinglePlayer(resultInterpreted.ToIdMsgPrio(data.playerId));
this.Request_InGameMessage_SinglePlayer(resultInterpreted.ToIdMsgPrio(data.SenderEntityId));
});
}, "blows it up", PermissionType.Moderator));



this.ChatCommands.Add(new ChatCommand(@"/help", (data, __) => {
this.Request_Player_Info(data.playerId.ToId(), (info) =>
this.ChatCommands.Add(new ChatCommand(@"::help", (data, __) => {
this.Request_Player_Info(data.SenderEntityId.ToId(), (info) =>
{
var playerPermissionLevel = (PermissionType)info.permission;
var header = $"Commands available to {info.playerName}; permission level {playerPermissionLevel}\n";
Expand All @@ -58,11 +58,10 @@ public override void Initialize(ModGameAPI dediAPI)
.OrderBy(x => x.Length).ToList();

lines.Insert(0, header);


var dialogData = new DialogBoxData()
{
Id = data.playerId,
Id = data.SenderEntityId,
MsgText = String.Join("\n", lines.ToArray())
};

Expand All @@ -71,12 +70,12 @@ public override void Initialize(ModGameAPI dediAPI)
}));
}

private void ChatCommand_TestMessage(ChatInfo data, Dictionary<string, string> args)
private void ChatCommand_TestMessage(ChatMsgData data, Dictionary<string, string> args)
{
var repeating = args["repeat"];
var msg = new IdMsgPrio()
{
id = data.playerId,
id = data.SenderEntityId,
msg = $"{repeating} {repeating} {repeating}!"
};
this.Request_InGameMessage_SinglePlayer(msg);
Expand Down
Binary file modified build/EmpyrionAPITools/EmpyrionAPIDefinitions.dll
Binary file not shown.
Binary file modified build/EmpyrionAPITools/EmpyrionAPITools.dll
Binary file not shown.
Binary file modified build/ExampleMod/ExampleMod.dll
Binary file not shown.
Binary file modified dependencies/Mif.dll
Binary file not shown.

0 comments on commit ac4016e

Please sign in to comment.