aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaelTheShifter <[email protected]>2016-06-28 18:30:15 -0400
committerMichaelTheShifter <[email protected]>2016-06-28 18:30:15 -0400
commitdec9dfac5eebfbfd3a21ba5cfd0ca320cd5f1bfb (patch)
tree58271fa2509f724cad4c1b6caa9116fee1588766
parenta067684f084c6fce5e7d7d8140a2d2f56953b579 (diff)
downloadshiftos-c-_theultimatehacker-dec9dfac5eebfbfd3a21ba5cfd0ca320cd5f1bfb.tar.gz
shiftos-c-_theultimatehacker-dec9dfac5eebfbfd3a21ba5cfd0ca320cd5f1bfb.tar.bz2
shiftos-c-_theultimatehacker-dec9dfac5eebfbfd3a21ba5cfd0ca320cd5f1bfb.zip
More client-side fixes.
Still got some moldy bread in there... if ya know what I mean. I meant bugs.
-rw-r--r--source/WindowsFormsApplication1/Controls/ProgressBarEX.cs2
-rw-r--r--source/WindowsFormsApplication1/Gameplay/HackUI.cs108
-rw-r--r--source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs143
3 files changed, 141 insertions, 112 deletions
diff --git a/source/WindowsFormsApplication1/Controls/ProgressBarEX.cs b/source/WindowsFormsApplication1/Controls/ProgressBarEX.cs
index 0e64aad..4896292 100644
--- a/source/WindowsFormsApplication1/Controls/ProgressBarEX.cs
+++ b/source/WindowsFormsApplication1/Controls/ProgressBarEX.cs
@@ -61,7 +61,7 @@ namespace ShiftOS
this.Invalidate();
}
else {
- throw new ArgumentOutOfRangeException("The value must be between the minimum and maximum values.");
+
}
}
}
diff --git a/source/WindowsFormsApplication1/Gameplay/HackUI.cs b/source/WindowsFormsApplication1/Gameplay/HackUI.cs
index 2d17596..f62ae62 100644
--- a/source/WindowsFormsApplication1/Gameplay/HackUI.cs
+++ b/source/WindowsFormsApplication1/Gameplay/HackUI.cs
@@ -235,49 +235,52 @@ namespace ShiftOS
TotalPlayerHP += newModule.HP;
AllPlayerComputers.Add(newModule);
newModule.Show();
- newModule.StolenModule += (o, a) =>
+ if (!InOnlineBattle)
{
- var t = new Thread(new ThreadStart(() =>
+ newModule.StolenModule += (o, a) =>
{
- var rnd = new Random();
- var lst = new List<Computer>();
- if (newModule.Enslaved)
- lst = AllPlayerComputers;
- else
- lst = AllEnemyComputers;
- WriteLine($"[{newModule.Hostname}] Starting network hack...");
- Thread.Sleep(5000);
-
- var pc = lst[rnd.Next(0, lst.Count)];
- this.Invoke(new Action(() =>
+ var t = new Thread(new ThreadStart(() =>
{
- if (pc.Type != SystemType.Core)
+ var rnd = new Random();
+ var lst = new List<Computer>();
+ if (newModule.Enslaved)
+ lst = AllPlayerComputers;
+ else
+ lst = AllEnemyComputers;
+ WriteLine($"[{newModule.Hostname}] Starting network hack...");
+ Thread.Sleep(5000);
+
+ var pc = lst[rnd.Next(0, lst.Count)];
+ this.Invoke(new Action(() =>
{
- module_to_steal = pc;
+ if (pc.Type != SystemType.Core)
+ {
+ module_to_steal = pc;
- pgpong.Left = (this.Width - pgpong.Width) / 2;
- pgpong.Top = (this.Height - pgpong.Height) / 2;
+ pgpong.Left = (this.Width - pgpong.Width) / 2;
+ pgpong.Top = (this.Height - pgpong.Height) / 2;
- pgpong.Show();
- newgame();
- }
+ pgpong.Show();
+ newgame();
+ }
+ }));
}));
- }));
- t.Start();
- };
- newModule.EnslavedModule += (o, e) =>
- {
- if(!newModule.Enslaved)
+ t.Start();
+ };
+ newModule.EnslavedModule += (o, e) =>
{
- var pc = AllEnemyComputers[rand.Next(0, AllEnemyComputers.Count)];
- if(!pc.Enslaved)
+ if (!newModule.Enslaved)
{
- WriteLine($"[{newModule.Hostname}] Successfully enslaved {pc.Hostname}");
- pc.Enslaved = true;
+ var pc = AllEnemyComputers[rand.Next(0, AllEnemyComputers.Count)];
+ if (!pc.Enslaved)
+ {
+ WriteLine($"[{newModule.Hostname}] Successfully enslaved {pc.Hostname}");
+ pc.Enslaved = true;
+ }
+
}
-
- }
- };
+ };
+ }
newModule.OnDestruction += (object s, EventArgs a) =>
{
if (this.SelectedPlayerComputer == newModule)
@@ -515,7 +518,7 @@ namespace ShiftOS
lbcompromised.Location = new Point(location, y);
lbcompromised.Show();
c.Flash(lbcompromised);
-
+ transmitter?.send_message(Online.Hacking.NetTransmitter.Messages.SetHealth, $"{c.Hostname} {c.HP}");
}
@@ -529,6 +532,8 @@ namespace ShiftOS
lbcompromised.Location = new Point(location, y);
lbcompromised.Show();
c.Flash(lbcompromised);
+ transmitter?.send_message(Online.Hacking.NetTransmitter.Messages.SetHealth, $"{c.Hostname} {c.HP}");
+
}
private void btnaddmodule_Click(object sender, EventArgs e)
@@ -1094,7 +1099,6 @@ namespace ShiftOS
Audio.Play("hackerbattle_ambient");
Hacking.RepairTimer.Stop(); //Don't want the player to be able to repair dead modules during a battle!
- this.TopMost = true;
this.WindowState = FormWindowState.Maximized;
LoadPlayerScreen();
if (InOnlineBattle)
@@ -1114,7 +1118,7 @@ namespace ShiftOS
AllEnemyComputers = new List<Computer>();
VisualizeEnemyNetwork();
tmrenemyhealthdetect.Start();
- ThisEnemyPC.Enemy = true;
+ ThisEnemyPC.Enemy = !InOnlineBattle;
}
private void VisualizeEnemyNetwork()
@@ -1137,10 +1141,13 @@ namespace ShiftOS
public void Enemy_System_Attacking(object s, EventArgs a)
{
- int i = new Random().Next(AllPlayerComputers.Count);
- var pc = AllPlayerComputers[i];
- var se = (Computer)s;
- pc.LaunchAttack(se.GetProperType());
+ if (!InOnlineBattle)
+ {
+ int i = new Random().Next(AllPlayerComputers.Count);
+ var pc = AllPlayerComputers[i];
+ var se = (Computer)s;
+ pc.LaunchAttack(se.GetProperType());
+ }
}
public Computer SelectedEnemyComputer = null;
@@ -1292,6 +1299,7 @@ namespace ShiftOS
WormToPlayer();
};
}
+ newModule.Enemy = !InOnlineBattle;
}
public void Enemy_Firewall_Deflect(Computer fwall)
@@ -1563,6 +1571,16 @@ namespace ShiftOS
receiver.ModulePlaced += Receiver_ModulePlaced;
receiver.ModuleUpgraded += Receiver_ModuleUpgraded;
receiver.ModuleRemoved += Receiver_ModuleRemoved;
+ receiver.ModuleDisabled += (o, e) =>
+ {
+ foreach(var c in AllEnemyComputers)
+ {
+ if(c.Hostname == e.hostName)
+ {
+ c.Disable();
+ }
+ }
+ };
}
private void Receiver_ModuleRemoved(object sender, Online.Hacking.Events.ModuleRemoved e)
@@ -1605,15 +1623,7 @@ namespace ShiftOS
if (m.Hostname == e.host_name)
mod = m;
}
- int health_amount = mod.HP - e.health;
- if(health_amount > 0)
- {
- mod.Repair(health_amount);
- }
- else if(health_amount < 0)
- {
- mod.LaunchAttack(AttackType.Virus, -health_amount);
- }
+ mod.HP = e.health;
}
#endregion
diff --git a/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs b/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs
index 2bc72c3..ecb68ca 100644
--- a/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs
+++ b/source/WindowsFormsApplication1/Online/Hacking/Matchmaker.cs
@@ -30,16 +30,23 @@ namespace ShiftOS.Online.Hacking
{
c.Value.OnReceived += (o, e) =>
{
- var om = (e.Data.Object as ObjectModel);
- if(om.Command == "server_info")
+ try
{
- var si = JsonConvert.DeserializeObject<ServerInfo>(om.OptionalObject as string);
- si.IPAddress = c.Value.RemoteHost;
- Servers.Add(si);
- invoke(() =>
+ var om = (e.Data.Object as ObjectModel);
+ if (om.Command == "server_info")
{
- Initiated?.Invoke(null, new EventArgs());
- });
+ var si = JsonConvert.DeserializeObject<ServerInfo>(om.OptionalObject as string);
+ si.IPAddress = c.Value.RemoteHost;
+ Servers.Add(si);
+ invoke(() =>
+ {
+ Initiated?.Invoke(null, new EventArgs());
+ });
+ }
+ }
+ catch
+ {
+
}
};
Package_Grabber.SendMessage(c.Value.RemoteHost, "get_info");
@@ -54,14 +61,21 @@ namespace ShiftOS.Online.Hacking
var server = Package_Grabber.clients[si.IPAddress];
server.OnReceived += (o, e) =>
{
- var om = e.Data.Object as ObjectModel;
- if (om.Command == "matchmaking")
+ try
{
- Players = JsonConvert.DeserializeObject<List<Network>>(om.OptionalObject as string);
- invoke(() =>
+ var om = e.Data.Object as ObjectModel;
+ if (om.Command == "matchmaking")
{
- MorePlayersFound?.Invoke(null, new EventArgs());
- });
+ Players = JsonConvert.DeserializeObject<List<Network>>(om.OptionalObject as string);
+ invoke(() =>
+ {
+ MorePlayersFound?.Invoke(null, new EventArgs());
+ });
+ }
+ }
+ catch
+ {
+
}
};
Package_Grabber.SendMessage(si.IPAddress, "get_matchmaking");
@@ -74,7 +88,7 @@ namespace ShiftOS.Online.Hacking
{
SelectedNetwork = Players[index];
MakerTimer.Stop();
- SelectedNetworkListener = new NetListener(si, SelectedNetwork);
+ SelectedNetworkListener = new NetListener(si, API.CurrentSave.MyOnlineNetwork);
SelectedNetworkTransmitter = new NetTransmitter(si, SelectedNetwork);
Package_Grabber.SendMessage(SelectedServer.IPAddress, $"leave_lobby {JsonConvert.SerializeObject(API.CurrentSave.MyOnlineNetwork)}");
}
@@ -118,58 +132,63 @@ namespace ShiftOS.Online.Hacking
var server = Package_Grabber.clients[si.IPAddress];
server.OnReceived += (o, e) =>
{
- if(e.Data.Object is string)
+ if (e.Data.Object is ObjectModel)
{
- var data = JsonConvert.DeserializeObject<ObjectModel>(e.Data.Object as string);
- string[] args = data.Command.Split(' ');
- if ((data.OptionalObject as Network) == net) {
- switch (args[0].ToLower())
+
+ var data = (e.Data.Object as ObjectModel);
+ if (data.Command != null)
+ {
+ string[] args = data.Command.Split(' ');
+ if ((data.OptionalObject as Network)?.Name == net.Name)
{
- case "set_health":
- string hn = args[1];
- int hp = Convert.ToInt32(args[2]);
- invoke(() => { ModuleHealthSet?.Invoke(this, new Events.Health { host_name = hn, health = hp }); });
- break;
- case "place_module":
- string hostname = args[1];
- int grade = Convert.ToInt32(args[2]);
- int newhp = Convert.ToInt32(args[3]);
- int x = Convert.ToInt32(args[4]);
- int y = Convert.ToInt32(args[5]);
- int type = Convert.ToInt32(args[6]);
- var moduleToPlace = new Module { Grade = grade, Hostname = hostname, HP = newhp, Type = type, X = x, Y = y };
- MyModules.Add(moduleToPlace);
- invoke(() => { ModulePlaced?.Invoke(this, new Events.ModulePlaced { new_module = moduleToPlace }); });
- break;
- case "remove_module":
- string hostnametoremove = args[1];
- var m = new Module();
- foreach (var mod in MyModules)
- {
- if (mod.Hostname == hostnametoremove)
+ switch (args[0].ToLower())
+ {
+ case "set_health":
+ string hn = args[1];
+ int hp = Convert.ToInt32(args[2]);
+ invoke(() => { ModuleHealthSet?.Invoke(this, new Events.Health { host_name = hn, health = hp }); });
+ break;
+ case "place_module":
+ string hostname = args[1];
+ int grade = Convert.ToInt32(args[2]);
+ int newhp = Convert.ToInt32(args[3]);
+ int x = Convert.ToInt32(args[4]);
+ int y = Convert.ToInt32(args[5]);
+ int type = Convert.ToInt32(args[6]);
+ var moduleToPlace = new Module { Grade = grade, Hostname = hostname, HP = newhp, Type = type, X = x, Y = y };
+ MyModules.Add(moduleToPlace);
+ invoke(() => { ModulePlaced?.Invoke(this, new Events.ModulePlaced { new_module = moduleToPlace }); });
+ break;
+ case "remove_module":
+ string hostnametoremove = args[1];
+ var m = new Module();
+ foreach (var mod in MyModules)
{
- m = mod;
+ if (mod.Hostname == hostnametoremove)
+ {
+ m = mod;
+ }
}
- }
- MyModules.Remove(m);
+ MyModules.Remove(m);
- invoke(() => { ModuleRemoved?.Invoke(this, new Events.ModuleRemoved { new_module = hostnametoremove }); });
- break;
- case "upgrade":
- invoke(() =>
- {
- string hostnametoupgrade = args[1];
- int newgrade = Convert.ToInt32(args[2]);
- ModuleUpgraded?.Invoke(this, new Events.ModuleUpgraded { hostname = hostnametoupgrade, grade = newgrade });
- });
- break;
- case "disable":
- invoke(() =>
- {
- string name = args[1];
- ModuleDisabled?.Invoke(this, new Events.Disabled { hostName = name });
- });
- break;
+ invoke(() => { ModuleRemoved?.Invoke(this, new Events.ModuleRemoved { new_module = hostnametoremove }); });
+ break;
+ case "upgrade":
+ invoke(() =>
+ {
+ string hostnametoupgrade = args[1];
+ int newgrade = Convert.ToInt32(args[2]);
+ ModuleUpgraded?.Invoke(this, new Events.ModuleUpgraded { hostname = hostnametoupgrade, grade = newgrade });
+ });
+ break;
+ case "disable":
+ invoke(() =>
+ {
+ string name = args[1];
+ ModuleDisabled?.Invoke(this, new Events.Disabled { hostName = name });
+ });
+ break;
+ }
}
}
}