mirror of
https://github.com/seriocomedy/ShiftOS-C-.git
synced 2025-01-22 17:22:14 +00:00
More client-side fixes.
Still got some moldy bread in there... if ya know what I mean. I meant bugs.
This commit is contained in:
parent
a067684f08
commit
dec9dfac5e
3 changed files with 141 additions and 112 deletions
|
@ -61,7 +61,7 @@ public int Value
|
||||||
this.Invalidate();
|
this.Invalidate();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new ArgumentOutOfRangeException("The value must be between the minimum and maximum values.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,49 +235,52 @@ public void AddModule(Computer newModule)
|
||||||
TotalPlayerHP += newModule.HP;
|
TotalPlayerHP += newModule.HP;
|
||||||
AllPlayerComputers.Add(newModule);
|
AllPlayerComputers.Add(newModule);
|
||||||
newModule.Show();
|
newModule.Show();
|
||||||
newModule.StolenModule += (o, a) =>
|
if (!InOnlineBattle)
|
||||||
{
|
{
|
||||||
var t = new Thread(new ThreadStart(() =>
|
newModule.StolenModule += (o, a) =>
|
||||||
{
|
{
|
||||||
var rnd = new Random();
|
var t = new Thread(new ThreadStart(() =>
|
||||||
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(() =>
|
|
||||||
{
|
{
|
||||||
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.Left = (this.Width - pgpong.Width) / 2;
|
||||||
pgpong.Top = (this.Height - pgpong.Height) / 2;
|
pgpong.Top = (this.Height - pgpong.Height) / 2;
|
||||||
|
|
||||||
pgpong.Show();
|
pgpong.Show();
|
||||||
newgame();
|
newgame();
|
||||||
}
|
}
|
||||||
|
}));
|
||||||
}));
|
}));
|
||||||
}));
|
t.Start();
|
||||||
t.Start();
|
};
|
||||||
};
|
newModule.EnslavedModule += (o, e) =>
|
||||||
newModule.EnslavedModule += (o, e) =>
|
|
||||||
{
|
|
||||||
if(!newModule.Enslaved)
|
|
||||||
{
|
{
|
||||||
var pc = AllEnemyComputers[rand.Next(0, AllEnemyComputers.Count)];
|
if (!newModule.Enslaved)
|
||||||
if(!pc.Enslaved)
|
|
||||||
{
|
{
|
||||||
WriteLine($"[{newModule.Hostname}] Successfully enslaved {pc.Hostname}");
|
var pc = AllEnemyComputers[rand.Next(0, AllEnemyComputers.Count)];
|
||||||
pc.Enslaved = true;
|
if (!pc.Enslaved)
|
||||||
|
{
|
||||||
|
WriteLine($"[{newModule.Hostname}] Successfully enslaved {pc.Hostname}");
|
||||||
|
pc.Enslaved = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
|
||||||
newModule.OnDestruction += (object s, EventArgs a) =>
|
newModule.OnDestruction += (object s, EventArgs a) =>
|
||||||
{
|
{
|
||||||
if (this.SelectedPlayerComputer == newModule)
|
if (this.SelectedPlayerComputer == newModule)
|
||||||
|
@ -515,7 +518,7 @@ private void Player_System_Repaired(object s, EventArgs e)
|
||||||
lbcompromised.Location = new Point(location, y);
|
lbcompromised.Location = new Point(location, y);
|
||||||
lbcompromised.Show();
|
lbcompromised.Show();
|
||||||
c.Flash(lbcompromised);
|
c.Flash(lbcompromised);
|
||||||
|
transmitter?.send_message(Online.Hacking.NetTransmitter.Messages.SetHealth, $"{c.Hostname} {c.HP}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -529,6 +532,8 @@ private void Player_System_Damaged(object s, EventArgs e)
|
||||||
lbcompromised.Location = new Point(location, y);
|
lbcompromised.Location = new Point(location, y);
|
||||||
lbcompromised.Show();
|
lbcompromised.Show();
|
||||||
c.Flash(lbcompromised);
|
c.Flash(lbcompromised);
|
||||||
|
transmitter?.send_message(Online.Hacking.NetTransmitter.Messages.SetHealth, $"{c.Hostname} {c.HP}");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnaddmodule_Click(object sender, EventArgs e)
|
private void btnaddmodule_Click(object sender, EventArgs e)
|
||||||
|
@ -1094,7 +1099,6 @@ private void HackUI_Load(object sender, EventArgs e)
|
||||||
Audio.Play("hackerbattle_ambient");
|
Audio.Play("hackerbattle_ambient");
|
||||||
|
|
||||||
Hacking.RepairTimer.Stop(); //Don't want the player to be able to repair dead modules during a battle!
|
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;
|
this.WindowState = FormWindowState.Maximized;
|
||||||
LoadPlayerScreen();
|
LoadPlayerScreen();
|
||||||
if (InOnlineBattle)
|
if (InOnlineBattle)
|
||||||
|
@ -1114,7 +1118,7 @@ private void LoadEnemyScreen()
|
||||||
AllEnemyComputers = new List<Computer>();
|
AllEnemyComputers = new List<Computer>();
|
||||||
VisualizeEnemyNetwork();
|
VisualizeEnemyNetwork();
|
||||||
tmrenemyhealthdetect.Start();
|
tmrenemyhealthdetect.Start();
|
||||||
ThisEnemyPC.Enemy = true;
|
ThisEnemyPC.Enemy = !InOnlineBattle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void VisualizeEnemyNetwork()
|
private void VisualizeEnemyNetwork()
|
||||||
|
@ -1137,10 +1141,13 @@ private void VisualizeEnemyNetwork()
|
||||||
|
|
||||||
public void Enemy_System_Attacking(object s, EventArgs a)
|
public void Enemy_System_Attacking(object s, EventArgs a)
|
||||||
{
|
{
|
||||||
int i = new Random().Next(AllPlayerComputers.Count);
|
if (!InOnlineBattle)
|
||||||
var pc = AllPlayerComputers[i];
|
{
|
||||||
var se = (Computer)s;
|
int i = new Random().Next(AllPlayerComputers.Count);
|
||||||
pc.LaunchAttack(se.GetProperType());
|
var pc = AllPlayerComputers[i];
|
||||||
|
var se = (Computer)s;
|
||||||
|
pc.LaunchAttack(se.GetProperType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Computer SelectedEnemyComputer = null;
|
public Computer SelectedEnemyComputer = null;
|
||||||
|
@ -1292,6 +1299,7 @@ public void AddEnemyModule(Computer newModule)
|
||||||
WormToPlayer();
|
WormToPlayer();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
newModule.Enemy = !InOnlineBattle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Enemy_Firewall_Deflect(Computer fwall)
|
public void Enemy_Firewall_Deflect(Computer fwall)
|
||||||
|
@ -1563,6 +1571,16 @@ public void LoadOnlineEnemy()
|
||||||
receiver.ModulePlaced += Receiver_ModulePlaced;
|
receiver.ModulePlaced += Receiver_ModulePlaced;
|
||||||
receiver.ModuleUpgraded += Receiver_ModuleUpgraded;
|
receiver.ModuleUpgraded += Receiver_ModuleUpgraded;
|
||||||
receiver.ModuleRemoved += Receiver_ModuleRemoved;
|
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)
|
private void Receiver_ModuleRemoved(object sender, Online.Hacking.Events.ModuleRemoved e)
|
||||||
|
@ -1605,15 +1623,7 @@ private void Receiver_ModuleHealthSet(object sender, Online.Hacking.Events.Healt
|
||||||
if (m.Hostname == e.host_name)
|
if (m.Hostname == e.host_name)
|
||||||
mod = m;
|
mod = m;
|
||||||
}
|
}
|
||||||
int health_amount = mod.HP - e.health;
|
mod.HP = e.health;
|
||||||
if(health_amount > 0)
|
|
||||||
{
|
|
||||||
mod.Repair(health_amount);
|
|
||||||
}
|
|
||||||
else if(health_amount < 0)
|
|
||||||
{
|
|
||||||
mod.LaunchAttack(AttackType.Virus, -health_amount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -30,16 +30,23 @@ public static void Initiate()
|
||||||
{
|
{
|
||||||
c.Value.OnReceived += (o, e) =>
|
c.Value.OnReceived += (o, e) =>
|
||||||
{
|
{
|
||||||
var om = (e.Data.Object as ObjectModel);
|
try
|
||||||
if(om.Command == "server_info")
|
|
||||||
{
|
{
|
||||||
var si = JsonConvert.DeserializeObject<ServerInfo>(om.OptionalObject as string);
|
var om = (e.Data.Object as ObjectModel);
|
||||||
si.IPAddress = c.Value.RemoteHost;
|
if (om.Command == "server_info")
|
||||||
Servers.Add(si);
|
|
||||||
invoke(() =>
|
|
||||||
{
|
{
|
||||||
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");
|
Package_Grabber.SendMessage(c.Value.RemoteHost, "get_info");
|
||||||
|
@ -54,14 +61,21 @@ public static void Matchmake(ServerInfo si)
|
||||||
var server = Package_Grabber.clients[si.IPAddress];
|
var server = Package_Grabber.clients[si.IPAddress];
|
||||||
server.OnReceived += (o, e) =>
|
server.OnReceived += (o, e) =>
|
||||||
{
|
{
|
||||||
var om = e.Data.Object as ObjectModel;
|
try
|
||||||
if (om.Command == "matchmaking")
|
|
||||||
{
|
{
|
||||||
Players = JsonConvert.DeserializeObject<List<Network>>(om.OptionalObject as string);
|
var om = e.Data.Object as ObjectModel;
|
||||||
invoke(() =>
|
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");
|
Package_Grabber.SendMessage(si.IPAddress, "get_matchmaking");
|
||||||
|
@ -74,7 +88,7 @@ public static void Matchmake(ServerInfo si)
|
||||||
{
|
{
|
||||||
SelectedNetwork = Players[index];
|
SelectedNetwork = Players[index];
|
||||||
MakerTimer.Stop();
|
MakerTimer.Stop();
|
||||||
SelectedNetworkListener = new NetListener(si, SelectedNetwork);
|
SelectedNetworkListener = new NetListener(si, API.CurrentSave.MyOnlineNetwork);
|
||||||
SelectedNetworkTransmitter = new NetTransmitter(si, SelectedNetwork);
|
SelectedNetworkTransmitter = new NetTransmitter(si, SelectedNetwork);
|
||||||
Package_Grabber.SendMessage(SelectedServer.IPAddress, $"leave_lobby {JsonConvert.SerializeObject(API.CurrentSave.MyOnlineNetwork)}");
|
Package_Grabber.SendMessage(SelectedServer.IPAddress, $"leave_lobby {JsonConvert.SerializeObject(API.CurrentSave.MyOnlineNetwork)}");
|
||||||
}
|
}
|
||||||
|
@ -118,58 +132,63 @@ private void register_events(ServerInfo si, Network net)
|
||||||
var server = Package_Grabber.clients[si.IPAddress];
|
var server = Package_Grabber.clients[si.IPAddress];
|
||||||
server.OnReceived += (o, e) =>
|
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(' ');
|
var data = (e.Data.Object as ObjectModel);
|
||||||
if ((data.OptionalObject as Network) == net) {
|
if (data.Command != null)
|
||||||
switch (args[0].ToLower())
|
{
|
||||||
|
string[] args = data.Command.Split(' ');
|
||||||
|
if ((data.OptionalObject as Network)?.Name == net.Name)
|
||||||
{
|
{
|
||||||
case "set_health":
|
switch (args[0].ToLower())
|
||||||
string hn = args[1];
|
{
|
||||||
int hp = Convert.ToInt32(args[2]);
|
case "set_health":
|
||||||
invoke(() => { ModuleHealthSet?.Invoke(this, new Events.Health { host_name = hn, health = hp }); });
|
string hn = args[1];
|
||||||
break;
|
int hp = Convert.ToInt32(args[2]);
|
||||||
case "place_module":
|
invoke(() => { ModuleHealthSet?.Invoke(this, new Events.Health { host_name = hn, health = hp }); });
|
||||||
string hostname = args[1];
|
break;
|
||||||
int grade = Convert.ToInt32(args[2]);
|
case "place_module":
|
||||||
int newhp = Convert.ToInt32(args[3]);
|
string hostname = args[1];
|
||||||
int x = Convert.ToInt32(args[4]);
|
int grade = Convert.ToInt32(args[2]);
|
||||||
int y = Convert.ToInt32(args[5]);
|
int newhp = Convert.ToInt32(args[3]);
|
||||||
int type = Convert.ToInt32(args[6]);
|
int x = Convert.ToInt32(args[4]);
|
||||||
var moduleToPlace = new Module { Grade = grade, Hostname = hostname, HP = newhp, Type = type, X = x, Y = y };
|
int y = Convert.ToInt32(args[5]);
|
||||||
MyModules.Add(moduleToPlace);
|
int type = Convert.ToInt32(args[6]);
|
||||||
invoke(() => { ModulePlaced?.Invoke(this, new Events.ModulePlaced { new_module = moduleToPlace }); });
|
var moduleToPlace = new Module { Grade = grade, Hostname = hostname, HP = newhp, Type = type, X = x, Y = y };
|
||||||
break;
|
MyModules.Add(moduleToPlace);
|
||||||
case "remove_module":
|
invoke(() => { ModulePlaced?.Invoke(this, new Events.ModulePlaced { new_module = moduleToPlace }); });
|
||||||
string hostnametoremove = args[1];
|
break;
|
||||||
var m = new Module();
|
case "remove_module":
|
||||||
foreach (var mod in MyModules)
|
string hostnametoremove = args[1];
|
||||||
{
|
var m = new Module();
|
||||||
if (mod.Hostname == hostnametoremove)
|
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 }); });
|
invoke(() => { ModuleRemoved?.Invoke(this, new Events.ModuleRemoved { new_module = hostnametoremove }); });
|
||||||
break;
|
break;
|
||||||
case "upgrade":
|
case "upgrade":
|
||||||
invoke(() =>
|
invoke(() =>
|
||||||
{
|
{
|
||||||
string hostnametoupgrade = args[1];
|
string hostnametoupgrade = args[1];
|
||||||
int newgrade = Convert.ToInt32(args[2]);
|
int newgrade = Convert.ToInt32(args[2]);
|
||||||
ModuleUpgraded?.Invoke(this, new Events.ModuleUpgraded { hostname = hostnametoupgrade, grade = newgrade });
|
ModuleUpgraded?.Invoke(this, new Events.ModuleUpgraded { hostname = hostnametoupgrade, grade = newgrade });
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "disable":
|
case "disable":
|
||||||
invoke(() =>
|
invoke(() =>
|
||||||
{
|
{
|
||||||
string name = args[1];
|
string name = args[1];
|
||||||
ModuleDisabled?.Invoke(this, new Events.Disabled { hostName = name });
|
ModuleDisabled?.Invoke(this, new Events.Disabled { hostName = name });
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue