Skip to content

Commit

Permalink
added haste to khaos, notification adjustments, coop fixes and UX imp…
Browse files Browse the repository at this point in the history
…rovements
  • Loading branch information
TalicZealot committed Apr 16, 2021
1 parent eff386b commit b04599a
Show file tree
Hide file tree
Showing 24 changed files with 1,205 additions and 672 deletions.
4 changes: 3 additions & 1 deletion KHAOS.COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* command honest
* Subweapons Only: Can only use subweapons for combat for the next minute. Gives Alucard Cube of Zoe, a subweapon and 200 hearts.
* command subonly
* Cripple: Not so fast! Speed set to 75%
* Cripple: Not so fast! Speed set to 75% for one minute.
* command cripple
* Blood Mana: Spells now cost HP instead of mana.
* command bloodmana
Expand Down Expand Up @@ -53,3 +53,5 @@
* command fourbeasts
* ZA WARUDO: mudamudamudamudamudamudamudamudamudamudamudamudamudamudamudamudamudamuda
* command zawarudo
* Haste: Increase movement speed for one minute.
* command haste
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ The new tracker has been re-written from the ground up for better performance an

## Co-Op
Currently coop requires the host to have the port they want to use forwarded. Hosting automatically copies your address(ip:port) to the clipboard. The other player uses that address to connect. Please be careful to not leak your IP!
Enable BizHawk messages through `View > Display Messages`.
Open the BizHawk console through `View > Open Log Window` for detailed information.
The Select button is used to send the currently highlighted item in the inventory or relic in the relic menu.
The Circle button is used to perform an assist action. Using a potion in your inventory and activating it for the other player.
Expand Down
15 changes: 14 additions & 1 deletion SotnRandoTools/src/Configuration/KhaosConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ public KhaosConfig()
{
Alerts = true;
ControlPannelQueueActions = true;
Volume = 8;
Volume = 2;
BotActionsFilePath = "";
WeakenFactor = 0.5F;
CrippleFactor = 0.8F;
HasteFactor = 1.3F;
ThirstDrainPerSecond = 1;
PandoraMinItems = 3;
PandoraMaxItems = 32;

Actions = new List<Action>
{
new Action{Name="Khaos Status", Aliases = new string[] {"kstatus"}, Enabled = true, Scaling = false},
Expand All @@ -25,5 +32,11 @@ public KhaosConfig()
public string BotActionsFilePath { get; set; }

public List<Action> Actions { get; set; }
public float WeakenFactor { get; set; }
public float CrippleFactor { get; set; }
public float HasteFactor { get; set; }
public uint ThirstDrainPerSecond { get; set; }
public int PandoraMinItems { get; set; }
public int PandoraMaxItems { get; set; }
}
}
9 changes: 8 additions & 1 deletion SotnRandoTools/src/Constants/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ public static class Paths
public const string AlertDeathLaugh = "./ExternalTools/SotnRandoTools/Sounds/DeathLaugh.wav";
public const string AlertLibrarianThankYou = "./ExternalTools/SotnRandoTools/Sounds/LibrarianThankYou.wav";
public const string AlertFairyPotion = "./ExternalTools/SotnRandoTools/Sounds/FairyPotion.wav";
public const string AlertMelty = "./ExternalTools/SotnRandoTools/Sounds/Melty.wav";
public const string AlertMelty = "./ExternalTools/SotnRandoTools/Sounds/Melty.mp3";
public const string AlertZaWarudo = "./ExternalTools/SotnRandoTools/Sounds/ZaWarudo.wav";
public const string AlertAlucardWhat = "./ExternalTools/SotnRandoTools/Sounds/AlucardWhat.wav";

public const string SourceLink = "https://github.com/TalicZealot/SotnRandoTools/";
public const string ReadmeLink = "https://github.com/TalicZealot/SotnRandoTools/blob/main/README.md";
public const string ApiLink = "https://github.com/TalicZealot/SotnApi";
public const string UpdaterLink = "https://github.com/TalicZealot/SimpleLatestReleaseUpdater";
public const string RandoSourceLink = "https://github.com/3snowp7im/SotN-Randomizer";
public const string DonateLink = "https://streamlabs.com/taliczealot";

public const string LatestReleaseApi = "https://api.github.com/repos/taliczealot/sotnrandotools/releases";
public const string LatestReleaseUrl = "https://github.com/TalicZealot/SotnRandoTools/releases/latest";
public const string UpdaterPath = @"\ExternalTools\SotnRandoTools\Updater\SimpleLatestReleaseUpdater.exe";
Expand Down
82 changes: 64 additions & 18 deletions SotnRandoTools/src/Coop/CoopMessanger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using SotnRandoTools.Configuration.Interfaces;
using SotnRandoTools.Coop.Enums;
using SotnRandoTools.Coop.Interfaces;
using SotnRandoTools.Coop.Models;
using SotnRandoTools.Utils;

namespace SotnRandoTools.Coop
Expand All @@ -12,24 +13,31 @@ public class CoopMessanger : ICoopMessanger
{
private readonly IToolConfig toolConfig;
private readonly ICoopReceiver coopReceiver;
private readonly ICoopViewModel coopViewModel;

private SimpleTcpServer? server;
private SimpleTcpClient? client;
private string connectedClientAddress = "";
private bool manualDisconnect = false;

public CoopMessanger(IToolConfig toolConfig, ICoopReceiver coopReceiver)
public CoopMessanger(IToolConfig toolConfig, ICoopReceiver coopReceiver, ICoopViewModel coopViewModel)
{
if (toolConfig is null) throw new ArgumentNullException(nameof(toolConfig));
if (coopReceiver is null) throw new ArgumentNullException(nameof(coopReceiver));
if (coopViewModel is null) throw new ArgumentNullException(nameof(coopViewModel));
this.toolConfig = toolConfig;
this.coopReceiver = coopReceiver;
this.coopViewModel = coopViewModel;
}

public bool Connect(string hostIp, int port)
public void Connect(string hostIp, int port)
{
if (client is null)
{
client = new SimpleTcpClient(hostIp, port);
client.Events.DataReceived += DataReceived;
client.Events.Connected += Connected;
client.Events.Disconnected += Disconnected;
}

try
Expand All @@ -38,28 +46,25 @@ public bool Connect(string hostIp, int port)
}
catch (Exception)
{
Console.WriteLine("Connection timed out.");
return false;
Console.WriteLine("Connection timed out!");
coopViewModel.ClientConnected = false;
return;
}

client.Events.DataReceived += DataReceived;
client.Events.Connected += Connected;
client.Events.Disconnected += Disconnected;

return true;
return;
}

public void Disconnect()
{
if (client is not null)
if (client is not null && client.IsConnected)
{
manualDisconnect = true;
client.Disconnect();
client.Dispose();
coopViewModel.ClientConnected = false;
}
}

public bool StartServer(int port)
public void StartServer(int port)
{
string hostName = Dns.GetHostName();

Expand All @@ -72,23 +77,47 @@ public bool StartServer(int port)
server.Events.DataReceived += DataReceived;
}

server.Start();
try
{
coopViewModel.ServerStarted = true;
server.Start();
}
catch (Exception)
{
Console.WriteLine("Error: Could not start server!");
coopViewModel.ServerStarted = false;
return;
}

string myIP = WebRequests.getExternalIP().Replace("\n", "");
System.Windows.Forms.Clipboard.SetText(myIP + ":" + port);

toolConfig.Coop.InitiateServerSettings();
Console.WriteLine($"Server started. Address copied to clipboard.");
coopViewModel.Message = "Server started";

return true;
return;
}

public void StopServer()
{
if (server is not null)
if (server is not null && server.IsListening)
{
coopViewModel.ServerStarted = false;
server.DisconnectClient(connectedClientAddress);
server.Stop();
}
}

public void DisposeAll()
{
if (server is not null)
{
server.Dispose();
}
if (client is not null)
{
client.Dispose();
}
}

public void SendData(MessageType type, byte[] data)
Expand All @@ -110,6 +139,9 @@ public void SendData(MessageType type, byte[] data)
private void Connected(object sender, ClientConnectedEventArgs e)
{
Console.WriteLine("Connected successfully.");
coopViewModel.ClientConnected = true;
coopViewModel.Message = "Connected";

if (toolConfig.Coop.StoreLastServer)
{
toolConfig.Coop.DefaultServer = client.ServerIpPort;
Expand All @@ -118,14 +150,27 @@ private void Connected(object sender, ClientConnectedEventArgs e)

private void Disconnected(object sender, ClientDisconnectedEventArgs e)
{
Console.WriteLine($"Disconnected from host.");
Console.WriteLine("Disconnected from host.");
if (!manualDisconnect)
{
Console.WriteLine($"Attempting to reconnect...");
client.ConnectWithRetries(2 * 1000);
coopViewModel.Message = "Reconnecting...";
try
{
client.ConnectWithRetries(2 * 1000);
}
catch (Exception)
{
coopViewModel.Message = "Disconnected";
Console.WriteLine("Connection timed out!");
coopViewModel.ClientConnected = false;
return;
}
}
else
{
coopViewModel.Message = "Disconnected";
coopViewModel.ClientConnected = false;
manualDisconnect = false;
}
}
Expand All @@ -140,6 +185,7 @@ private void ClientConnected(object sender, ClientConnectedEventArgs e)

private void ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
{
coopViewModel.Message = "Client disconnected";
Console.WriteLine($"Client has disconnected.");
if (connectedClientAddress == e.IpPort)
{
Expand Down
14 changes: 10 additions & 4 deletions SotnRandoTools/src/Coop/CoopReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public void ProcessMessage(byte[] data)
{
MessageType type = (MessageType) data[0];
ushort index = BitConverter.ToUInt16(data, 1);
byte indexByte = data[1];
byte dataByte = 0;
if (data.Length > 2)
{
dataByte = data[2];
}
switch (type)
{
case MessageType.Relic:
Expand All @@ -50,11 +56,11 @@ public void ProcessMessage(byte[] data)
}
break;
case MessageType.Location:
gameApi.SetRoomToVisited(watchlistService.CoopLocationWatches[index].Address);
gameApi.SetRoomValue(watchlistService.CoopLocationWatches[indexByte].Address, dataByte);
watchlistService.UpdateWatchlist(watchlistService.CoopLocationWatches);
watchlistService.CoopLocationWatches.ClearChangeCounts();
notificationService.DisplayMessage(watchlistService.CoopLocationWatches[index].Notes);
Console.WriteLine($"Received location: {watchlistService.CoopLocationWatches[index].Notes}");
//notificationService.DisplayMessage($"location {watchlistService.CoopLocationWatches[indexByte].Notes}");
Console.WriteLine($"Received location: {watchlistService.CoopLocationWatches[indexByte].Notes}");
break;
case MessageType.Item:
alucardApi.GrantItemByName(Equipment.Items[index]);
Expand Down Expand Up @@ -240,7 +246,7 @@ private void DecodeShortcut(Shortcut shortcut)
}
break;
default:
Console.WriteLine($"RShortcut {shortcut} not found!");
Console.WriteLine($"Shortcut {shortcut} not found!");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion SotnRandoTools/src/Coop/CoopSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private void UpdateLocations()
{
if (watchlistService.CoopLocationWatches[i].Value > 0)
{
coopMessanger.SendData(MessageType.Location, BitConverter.GetBytes((ushort) i));
coopMessanger.SendData(MessageType.Location, new byte[] { (byte) i, (byte) watchlistService.CoopLocationWatches[i].Value });
Console.WriteLine($"Sending Location: {watchlistService.CoopLocationWatches[i].Notes}");
}
}
Expand Down
5 changes: 3 additions & 2 deletions SotnRandoTools/src/Coop/Interfaces/ICoopMessanger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ namespace SotnRandoTools.Coop.Interfaces
{
public interface ICoopMessanger
{
bool Connect(string hostIp, int port);
void Connect(string hostIp, int port);
void Disconnect();
bool StartServer(int port);
void StartServer(int port);
void StopServer();
void DisposeAll();
void SendData(MessageType type, byte[] data);
}
}
13 changes: 13 additions & 0 deletions SotnRandoTools/src/Coop/Interfaces/ICoopViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.ComponentModel;

namespace SotnRandoTools.Coop.Models
{
public interface ICoopViewModel
{
bool ClientConnected { get; set; }
bool ServerStarted { get; set; }
string Message { get; set; }

event PropertyChangedEventHandler PropertyChanged;
}
}
62 changes: 62 additions & 0 deletions SotnRandoTools/src/Coop/Models/CoopViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.ComponentModel;

namespace SotnRandoTools.Coop.Models
{
public class CoopViewModel : INotifyPropertyChanged, ICoopViewModel
{
private bool serverStarted;
private bool clientConnected;
private string message;
public bool ServerStarted
{
get
{
return serverStarted;
}
set
{
serverStarted = value;

if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("ServerStarted"));
}
}
}
public bool ClientConnected
{
get
{
return clientConnected;
}
set
{
clientConnected = value;

if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("ClientConnected"));
}
}
}

public string Message
{
get
{
return message;
}
set
{
message = value;

if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Message"));
}
}
}

public event PropertyChangedEventHandler PropertyChanged;
}
}
Loading

0 comments on commit b04599a

Please sign in to comment.