Skip to content

Commit

Permalink
Add method to handle speaker say with multiple texts
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaioru committed Sep 26, 2023
1 parent 026259e commit 6b8e7ae
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ public ConversationSpeaker(
public byte Say(string text, bool prev = false, bool next = true) =>
_context.Request(new SayRequest(this, text, prev, next)).Result;

public byte Say(string[] text, int current = 0)
{
byte result = 0;

while (current >= 0 && current < text.Length)
{
result = Say(text[current], current > 0);

if (result == 0) current = Math.Max(0, --current);
if (result != 1) continue;
if (current == text.Length)
break;
current = Math.Min(text.Length, ++current);
}

return result;
}

public bool AskYesNo(string text) =>
_context.Request(new AskYesNoRequest(this, text)).Result;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Edelstein.Common.Gameplay.Constants;
using Edelstein.Common.Gameplay.Game.Objects.User.Effects;
using Edelstein.Common.Gameplay.Game.Objects.User.Effects.Field;
using Edelstein.Common.Gameplay.Game.Objects.User.Messages;
using Edelstein.Common.Gameplay.Packets;
using Edelstein.Common.Utilities.Packets;
using Edelstein.Protocol.Gameplay.Game.Conversations;
using Edelstein.Protocol.Gameplay.Game.Conversations.Speakers;
using Edelstein.Protocol.Gameplay.Game.Objects.User;
Expand Down Expand Up @@ -131,6 +135,8 @@ public int Money
set => _user.ModifyStats(s => s.Money = value).Wait();
}

public int Gender => _user.Character.Gender;

public int Field
{
get => _user.Field?.Template.ID ?? 999999999;
Expand Down Expand Up @@ -159,4 +165,25 @@ public void IncMoney(int amount)

public void TransferField(int fieldID, string portal = "")
=> _user.StageUser.Context.Managers.Field.Retrieve(fieldID).Result?.Enter(_user, portal);

public void SetDirectionMode(bool enable, int delay = 0)
{
var p = new PacketWriter(PacketSendOperations.SetDirectionMode);
p.WriteBool(enable);
p.WriteInt(delay);
_user.Dispatch(p.Build()).Wait();
}

public void SetStandAloneMode(bool enable)
{
var p = new PacketWriter(PacketSendOperations.SetStandAloneMode);
p.WriteBool(enable);
_user.Dispatch(p.Build()).Wait();
}

public void EffectReserved(string path)
=> _user.Effect(new ReservedEffect(path), isRemote: false);

public void EffectFieldScreen(string path)
=> _user.EffectField(new ScreenFieldEffect(path));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Edelstein.Common.Gameplay.Game.Objects.User.Effects.Field;

public enum FieldEffectType
{
Summon = 0x0,
Tremble = 0x1,
Object = 0x2,
Screen = 0x3,
Sound = 0x4,
MobHPTag = 0x5,
ChangeBGM = 0x6,
RewordRullet = 0x7
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Edelstein.Protocol.Utilities.Packets;

namespace Edelstein.Common.Gameplay.Game.Objects.User.Effects.Field;

public record ScreenFieldEffect(
string Path
) : IPacketWritable
{
public void WriteTo(IPacketWriter writer)
{
writer.WriteByte((byte)FieldEffectType.Screen);
writer.WriteString(Path);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Edelstein.Protocol.Utilities.Packets;

namespace Edelstein.Common.Gameplay.Game.Objects.User.Effects;

public record ReservedEffect(
string Path
) : IPacketWritable
{
public void WriteTo(IPacketWriter writer)
{
writer.WriteByte((byte)EffectType.ReservedEffect);
writer.WriteString(Path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ public async Task Effect(IPacketWritable writable, bool isLocal = true, bool isR
if (isRemote && FieldSplit != null)
await FieldSplit.Dispatch(remotePacket, this);
}

public Task EffectField(IPacketWritable writable)
{
var packet = new PacketWriter(PacketSendOperations.FieldEffect);
packet.Write(writable);
return Dispatch(packet.Build());
}

public Task<T> Prompt<T>(Func<IConversationSpeaker, T> prompt, T def) =>
Prompt((s1, s2) => prompt.Invoke(s1), def);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class FieldOnPacketUserTransferFieldRequestPlug : IPipelinePlug<FieldOnPa

public async Task Handle(IPipelineContext ctx, FieldOnPacketUserTransferFieldRequest message)
{
if (message.FieldID != -1 && message.User.Account.GradeCode.HasFlag(AccountGradeCode.AdminLevel1))
if (message.FieldID != -1/* && message.User.Account.GradeCode.HasFlag(AccountGradeCode.AdminLevel1)*/)
{
var target = await _fieldManager.Retrieve(message.FieldID);
if (target == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface IConversationSpeaker : IIdentifiable<int>
ConversationSpeakerFlags Flags { get; }

byte Say(string text, bool prev = false, bool next = true);
byte Say(string[] text, int current = 0);
bool AskYesNo(string text);
bool AskAccept(string text);
string AskText(string text, string def = "", short lenMin = 0, short lenMax = short.MaxValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public interface IConversationSpeakerUser : IConversationSpeaker

int Money { get; set; }

int Gender { get; }

int Field { get; set; }

IConversationSpeakerUserInventory Inventory { get; }
Expand All @@ -40,4 +42,10 @@ public interface IConversationSpeakerUser : IConversationSpeaker
void IncMoney(int amount);

void TransferField(int fieldID, string portal = "");

void SetDirectionMode(bool enable, int delay = 0);
void SetStandAloneMode(bool enable);

void EffectReserved(string path);
void EffectFieldScreen(string path);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public interface IFieldUser :
Task Message(string message);
Task Message(IPacketWritable writable);
Task Effect(IPacketWritable writable, bool isLocal = true, bool isRemote = true);
Task EffectField(IPacketWritable writable);

Task<T> Prompt<T>(Func<IConversationSpeaker, T> prompt, T def);
Task<T> Prompt<T>(Func<IConversationSpeaker, IConversationSpeaker, T> prompt, T def);
Expand Down

0 comments on commit 6b8e7ae

Please sign in to comment.