Skip to content

Commit

Permalink
Merge pull request #245 from ethanmoffat/eobot_talk
Browse files Browse the repository at this point in the history
Add chat command for EOBot scripts. Fix bug forcing password to lowercase.
  • Loading branch information
ethanmoffat authored Nov 19, 2022
2 parents a46a1ff + b8e51ee commit f96751d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions EOBot/ArgumentsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ public ArgumentsParser(string[] args)
break;
}

var pair = arg.ToLower().Split('=');
var pair = arg.Split('=');

if (pair.Length != 2)
{
Error = ArgsError.BadFormat;
return;
}

switch (pair[0])
switch (pair[0].ToLower())
{
case "script":
if (!File.Exists(pair[1]))
Expand Down
12 changes: 12 additions & 0 deletions EOBot/Interpreter/BuiltInIdentifierConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using EOLib.Config;
using EOLib.Domain.Account;
using EOLib.Domain.Character;
using EOLib.Domain.Chat;
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.Domain.NPC;
Expand Down Expand Up @@ -50,6 +51,7 @@ public void SetupBuiltInFunctions()
_state.SymbolTable[PredefinedIdentifiers.UPPER_FUNC] = Readonly(new Function<string, string>(PredefinedIdentifiers.UPPER_FUNC, s => s.ToUpper()));

BotDependencySetup();
// pre-game flow
_state.SymbolTable[PredefinedIdentifiers.CONNECT_FUNC] = Readonly(new AsyncVoidFunction<string, int>(PredefinedIdentifiers.CONNECT_FUNC, ConnectAsync));
_state.SymbolTable[PredefinedIdentifiers.DISCONNECT_FUNC] = Readonly(new VoidFunction(PredefinedIdentifiers.DISCONNECT_FUNC, Disconnect));
_state.SymbolTable[PredefinedIdentifiers.CREATE_ACCOUNT_FUNC] = Readonly(new AsyncFunction<string, string, int>(PredefinedIdentifiers.CREATE_ACCOUNT_FUNC, CreateAccountAsync));
Expand All @@ -59,7 +61,10 @@ public void SetupBuiltInFunctions()
_state.SymbolTable[PredefinedIdentifiers.CREATE_CHARACTER_FUNC] = Readonly(new AsyncFunction<string, int>(PredefinedIdentifiers.CREATE_CHARACTER_FUNC, CreateCharacterAsync));
_state.SymbolTable[PredefinedIdentifiers.DELETE_CHARACTER_FUNC] = Readonly(new AsyncFunction<string, bool, int>(PredefinedIdentifiers.DELETE_CHARACTER_FUNC, DeleteCharacterAsync));
_state.SymbolTable[PredefinedIdentifiers.LOGIN_CHARACTER_FUNC] = Readonly(new AsyncVoidFunction<string>(PredefinedIdentifiers.LOGIN_CHARACTER_FUNC, LoginToCharacterAsync));

// in-game stuff
_state.SymbolTable[PredefinedIdentifiers.JOIN_PARTY] = Readonly(new VoidFunction<int>(PredefinedIdentifiers.JOIN_PARTY, JoinParty));
_state.SymbolTable[PredefinedIdentifiers.CHAT] = Readonly(new VoidFunction<string>(PredefinedIdentifiers.CHAT, Chat));
}

public void SetupBuiltInVariables()
Expand Down Expand Up @@ -186,6 +191,12 @@ private void JoinParty(int characterId)
c.Resolve<IPartyActions>().RequestParty(PartyRequestType.Join, (short)characterId);
}

private void Chat(string chatText)
{
var c = DependencyMaster.TypeRegistry[_botIndex];
c.Resolve<IChatActions>().SendChatToServer(chatText, string.Empty);
}

private (bool, IIdentifiable) SetupAccountObject()
{
var playerInfoProv = DependencyMaster.TypeRegistry[_botIndex].Resolve<IPlayerInfoProvider>();
Expand Down Expand Up @@ -218,6 +229,7 @@ private void JoinParty(int characterId)
charObj.SymbolTable["x"] = (true, () => new IntVariable(cp.MainCharacter.RenderProperties.MapX));
charObj.SymbolTable["y"] = (true, () => new IntVariable(cp.MainCharacter.RenderProperties.MapY));
charObj.SymbolTable["direction"] = (true, () => new IntVariable((int)cp.MainCharacter.RenderProperties.Direction));
charObj.SymbolTable["admin"] = (true, () => new IntVariable((int)cp.MainCharacter.AdminLevel));
charObj.SymbolTable["inventory"] = (true,
() => new ArrayVariable(
inventoryProvider.ItemInventory.Select(x =>
Expand Down
1 change: 1 addition & 0 deletions EOBot/Interpreter/Variables/PredefinedIdentifiers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ public static class PredefinedIdentifiers
public const string DELETE_CHARACTER_FUNC = "DeleteCharacter";

public const string JOIN_PARTY = "JoinParty";
public const string CHAT = "Chat";
}
}

0 comments on commit f96751d

Please sign in to comment.