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:
MichaelTheShifter 2016-06-28 18:30:15 -04:00
parent a067684f08
commit dec9dfac5e
3 changed files with 141 additions and 112 deletions

View file

@ -61,7 +61,7 @@ public int Value
this.Invalidate();
}
else {
throw new ArgumentOutOfRangeException("The value must be between the minimum and maximum values.");
}
}
}

View file

@ -235,49 +235,52 @@ public void AddModule(Computer newModule)
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 @@ private void Player_System_Repaired(object s, EventArgs e)
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 @@ private void Player_System_Damaged(object s, EventArgs e)
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 @@ private void HackUI_Load(object sender, EventArgs e)
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 @@ private void LoadEnemyScreen()
AllEnemyComputers = new List<Computer>();
VisualizeEnemyNetwork();
tmrenemyhealthdetect.Start();
ThisEnemyPC.Enemy = true;
ThisEnemyPC.Enemy = !InOnlineBattle;
}
private void VisualizeEnemyNetwork()
@ -1137,10 +1141,13 @@ private void VisualizeEnemyNetwork()
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 @@ public void AddEnemyModule(Computer newModule)
WormToPlayer();
};
}
newModule.Enemy = !InOnlineBattle;
}
public void Enemy_Firewall_Deflect(Computer fwall)
@ -1563,6 +1571,16 @@ public void LoadOnlineEnemy()
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 @@ private void Receiver_ModuleHealthSet(object sender, Online.Hacking.Events.Healt
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

View file

@ -30,16 +30,23 @@ public static void Initiate()
{
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 @@ public static void Matchmake(ServerInfo si)
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 @@ public static void Matchmake(ServerInfo si)
{
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 @@ private void register_events(ServerInfo si, Network net)
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())
{
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)
{
m = mod;
}
}
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;
var data = (e.Data.Object as ObjectModel);
if (data.Command != null)
{
string[] args = data.Command.Split(' ');
if ((data.OptionalObject as Network)?.Name == net.Name)
{
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)
{
if (mod.Hostname == hostnametoremove)
{
m = mod;
}
}
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;
}
}
}
}