-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do action is Task. Add commands: CommandDummyButton, CommandDummyInpu…
…tText. Add event monitor: DummyDead. Add interacion actions: Button, Execute, Face, Gesture, InputText, Mouse. Replace action thread to schedule task. Add options dummy is admin.
- Loading branch information
Showing
34 changed files
with
445 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace EvolutionPlugins.Dummy.API | ||
{ | ||
public interface IAction | ||
{ | ||
void Do(PlayerDummy dummy); | ||
Task Do(PlayerDummy dummy); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using EvolutionPlugins.Dummy.API; | ||
using EvolutionPlugins.Dummy.Extensions.Interaction.Actions; | ||
using OpenMod.API.Commands; | ||
using OpenMod.Core.Commands; | ||
using Steamworks; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace EvolutionPlugins.Dummy.Commands.Actions | ||
{ | ||
[Command("button")] | ||
[CommandSyntax("<id> <buttonName>")] | ||
[CommandParent(typeof(CommandDummy))] | ||
public class CommandDummyButton : Command | ||
{ | ||
private readonly IDummyProvider m_DummyProvider; | ||
|
||
public CommandDummyButton(IServiceProvider serviceProvider, IDummyProvider dummyProvider) : base(serviceProvider) | ||
{ | ||
m_DummyProvider = dummyProvider; | ||
} | ||
|
||
protected override async Task OnExecuteAsync() | ||
{ | ||
if (Context.Parameters.Count < 2) | ||
{ | ||
throw new CommandWrongUsageException(Context); | ||
} | ||
|
||
var id = (CSteamID)await Context.Parameters.GetAsync<ulong>(0); | ||
|
||
var dummy = await m_DummyProvider.GetPlayerDummy(id.m_SteamID); | ||
if (dummy == null) | ||
{ | ||
throw new UserFriendlyException($"Dummy \"{id}\" has not found!"); | ||
} | ||
dummy.Actions.Actions.Enqueue(new ButtonAction(Context.Parameters.GetArgumentLine(1))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using EvolutionPlugins.Dummy.API; | ||
using EvolutionPlugins.Dummy.Extensions.Interaction.Actions; | ||
using OpenMod.API.Commands; | ||
using OpenMod.Core.Commands; | ||
using Steamworks; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace EvolutionPlugins.Dummy.Commands.Actions | ||
{ | ||
[Command("inputfield")] | ||
[CommandAlias("if")] | ||
[CommandSyntax("<id> <inputFieldName> <text>")] | ||
[CommandParent(typeof(CommandDummy))] | ||
public class CommandDummyInputText : Command | ||
{ | ||
private readonly IDummyProvider m_DummyProvider; | ||
|
||
public CommandDummyInputText(IServiceProvider serviceProvider, IDummyProvider dummyProvider) : base(serviceProvider) | ||
{ | ||
m_DummyProvider = dummyProvider; | ||
} | ||
|
||
protected override async Task OnExecuteAsync() | ||
{ | ||
if (Context.Parameters.Count < 3) | ||
{ | ||
throw new CommandWrongUsageException(Context); | ||
} | ||
|
||
var id = (CSteamID)await Context.Parameters.GetAsync<ulong>(0); | ||
|
||
var dummy = await m_DummyProvider.GetPlayerDummy(id.m_SteamID); | ||
if (dummy == null) | ||
{ | ||
throw new UserFriendlyException($"Dummy \"{id}\" has not found!"); | ||
} | ||
dummy.Actions.Actions.Enqueue(new InputTextAction(Context.Parameters[1], Context.Parameters[2])); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Cysharp.Threading.Tasks; | ||
using EvolutionPlugins.Dummy.API; | ||
using OpenMod.API.Eventing; | ||
using OpenMod.API.Users; | ||
using OpenMod.Core.Eventing; | ||
using OpenMod.Core.Users; | ||
using OpenMod.UnityEngine.Extensions; | ||
using OpenMod.Unturned.Players.Events.Life; | ||
using SDG.Unturned; | ||
using System.Threading.Tasks; | ||
|
||
namespace Dummy.Events | ||
{ | ||
public class DummyDeadEvent : IEventListener<UnturnedPlayerDeadEvent> | ||
{ | ||
private readonly IDummyProvider m_DummyProvider; | ||
private readonly IUserManager m_UserManager; | ||
|
||
public DummyDeadEvent(IDummyProvider dummyProvider, IUserManager userManager) | ||
{ | ||
m_DummyProvider = dummyProvider; | ||
m_UserManager = userManager; | ||
} | ||
|
||
[EventListener(Priority = EventListenerPriority.Monitor)] | ||
public async Task HandleEventAsync(object sender, UnturnedPlayerDeadEvent @event) | ||
{ | ||
if (m_DummyProvider.Dummies.ContainsKey(@event.Player.SteamId)) | ||
{ | ||
foreach (var owner in m_DummyProvider.Dummies[@event.Player.SteamId].Data.Owners) | ||
{ | ||
var player = await m_UserManager.FindUserAsync(KnownActorTypes.Player, owner.ToString(), UserSearchMode.FindById); | ||
if (player == null) | ||
{ | ||
continue; | ||
} | ||
await player.PrintMessageAsync($"Dummy {@event.Player.SteamId} has died. Death reason: {@event.DeathCause.ToString().ToLower()}, killer = {@event.Instigator}. Respawning..."); | ||
} | ||
|
||
async UniTask Revive() | ||
{ | ||
await UniTask.Delay(1500); | ||
if (@event.Player.IsAlive) return; // double-check | ||
await UniTask.SwitchToMainThread(); | ||
@event.Player.Player.life.sendRevive(); | ||
@event.Player.Player.life.channel.send("tellRevive", ESteamCall.ALL, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] | ||
{ | ||
@event.Player.Transform.Position.ToUnityVector(), | ||
MeasurementTool.angleToByte(@event.Player.Player.transform.rotation.eulerAngles.y) | ||
}); | ||
} | ||
await Revive(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Cysharp.Threading.Tasks; | ||
using SDG.Unturned; | ||
using System.Threading.Tasks; | ||
|
||
namespace EvolutionPlugins.Dummy.Extensions.Interaction.Actions | ||
{ | ||
public class ButtonAction : IInteractionAction | ||
{ | ||
public ButtonAction(string buttonName) | ||
{ | ||
ButtonName = buttonName; | ||
} | ||
|
||
public string ButtonName { get; } | ||
|
||
public async Task Do(PlayerDummy dummy) | ||
{ | ||
await UniTask.SwitchToMainThread(); | ||
EffectManager.instance.tellEffectClicked(dummy.SteamID, ButtonName); | ||
} | ||
} | ||
} |
Oops, something went wrong.