mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-26 23:02:04 -04:00
Add /zg hitbox to allow configuring hitbox detection distance, more code cleanup.
This commit is contained in:
parent
c598df0006
commit
50f43e5bd2
@ -90,15 +90,24 @@ namespace MCGalaxy.Commands
|
||||
}
|
||||
|
||||
static void HandleHitbox(Player p, string message, string[] args) {
|
||||
|
||||
byte precision;
|
||||
if (args.Length == 1) {
|
||||
Player.SendMessage(p, "Hitbox detection is currently &a" + Server.zombie.HitboxPrecision + " %Sunits apart.");
|
||||
} else if (!byte.TryParse(args[1], out precision)) {
|
||||
Player.SendMessage(p, "Hitbox detection must be an integer between 0 and 256.");
|
||||
} else {
|
||||
Server.zombie.HitboxPrecision = precision;
|
||||
Player.SendMessage(p, "Hitbox detection set to &a" + Server.zombie.HitboxPrecision + " %Sunits apart.");
|
||||
}
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.SendMessage(p, "/zombiegame start - Starts a Zombie Survival game for one round.");
|
||||
Player.SendMessage(p, "/zombiegame start 0 - Starts a Zombie Survival game for an unlimited amount of rounds.");
|
||||
Player.SendMessage(p, "/zombiegame start [x] - Starts a Zombie Survival game for [x] amount of rounds.");
|
||||
Player.SendMessage(p, "/zombiegame stop - Stops the Zombie Survival game after the round has finished.");
|
||||
Player.SendMessage(p, "/zombiegame force - Force stops the Zombie Survival game immediately.");
|
||||
Player.SendMessage(p, "/zg start 0 - Starts a Zombie Survival game for an unlimited amount of rounds.");
|
||||
Player.SendMessage(p, "/zg start [x] - Starts a Zombie Survival game for [x] amount of rounds.");
|
||||
Player.SendMessage(p, "/zg stop - Stops the Zombie Survival game after the round has finished.");
|
||||
Player.SendMessage(p, "/zg force - Force stops the Zombie Survival game immediately.");
|
||||
Player.SendMessage(p, "/zg hitbox [distance] - Sets how far apart players need to be before " +
|
||||
"they are considered a 'hit' (32 units = 1 block).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,9 +75,7 @@ namespace MCGalaxy {
|
||||
|
||||
Player.GlobalMessage(player.color + player.name + " %Sstarted the infection!");
|
||||
player.infected = true;
|
||||
player.color = Colors.red;
|
||||
Player.GlobalDespawn(player, false);
|
||||
Player.GlobalSpawn(player, player.pos[0], player.pos[1], player.pos[2], player.rot[0], player.rot[1], false);
|
||||
CheckPlayerColor(player, Colors.red);
|
||||
|
||||
RoundInProgress = true;
|
||||
int roundMins = random.Next(5, 8);
|
||||
@ -148,64 +146,57 @@ namespace MCGalaxy {
|
||||
void DoCoreGame(List<Player> players, Random random) {
|
||||
while (aliveCount > 0) {
|
||||
aliveCount = alive.Count;
|
||||
infectd.ForEach(delegate(Player pKiller)
|
||||
infectd.ForEach(
|
||||
delegate(Player pKiller)
|
||||
{
|
||||
if (pKiller.color != Colors.red)
|
||||
CheckPlayerColor(pKiller, Colors.red);
|
||||
alive.ForEach(
|
||||
delegate(Player pAlive)
|
||||
{
|
||||
pKiller.color = Colors.red;
|
||||
Player.GlobalDespawn(pKiller, false);
|
||||
Player.GlobalSpawn(pKiller, pKiller.pos[0], pKiller.pos[1], pKiller.pos[2], pKiller.rot[0], pKiller.rot[1], false);
|
||||
}
|
||||
alive.ForEach(delegate(Player pAlive)
|
||||
{
|
||||
if (pAlive.color != pAlive.group.color)
|
||||
{
|
||||
pAlive.color = pAlive.group.color;
|
||||
Player.GlobalDespawn(pAlive, false);
|
||||
Player.GlobalSpawn(pAlive, pAlive.pos[0], pAlive.pos[1], pAlive.pos[2], pAlive.rot[0], pAlive.rot[1], false);
|
||||
}
|
||||
if (Math.Abs(pAlive.pos[0] - pKiller.pos[0]) <= HitboxPrecision
|
||||
&& Math.Abs(pAlive.pos[1] - pKiller.pos[1]) <= HitboxPrecision
|
||||
&& Math.Abs(pAlive.pos[2] - pKiller.pos[2]) <= HitboxPrecision) {
|
||||
if (!pAlive.infected && pKiller.infected && !pAlive.referee && !pKiller.referee && pKiller != pAlive && pKiller.level.name == currentLevelName && pAlive.level.name == currentLevelName)
|
||||
CheckPlayerColor(pAlive, pAlive.group.color);
|
||||
if (Math.Abs(pAlive.pos[0] - pKiller.pos[0]) > HitboxPrecision
|
||||
|| Math.Abs(pAlive.pos[1] - pKiller.pos[1]) > HitboxPrecision
|
||||
|| Math.Abs(pAlive.pos[2] - pKiller.pos[2]) > HitboxPrecision)
|
||||
return;
|
||||
|
||||
if (!pAlive.infected && pKiller.infected && !pAlive.referee && !pKiller.referee &&
|
||||
pKiller != pAlive && pKiller.level.name == currentLevelName && pAlive.level.name == currentLevelName)
|
||||
{
|
||||
pAlive.infected = true;
|
||||
infectd.Add(pAlive);
|
||||
alive.Remove(pAlive);
|
||||
players.Remove(pAlive);
|
||||
pAlive.blockCount = 25;
|
||||
if (lastPlayerToInfect == pKiller.name)
|
||||
{
|
||||
if (lastPlayerToInfect == pKiller.name) {
|
||||
infectCombo++;
|
||||
if (infectCombo >= 2)
|
||||
{
|
||||
if (infectCombo >= 2) {
|
||||
pKiller.SendMessage("You gained " + (4 - infectCombo) + " " + Server.moneys);
|
||||
pKiller.money = pKiller.money + 4 - infectCombo;
|
||||
Player.GlobalMessage(pKiller.color + pKiller.name + " is on a rampage! " + (infectCombo + 1) + " infections in a row!");
|
||||
pKiller.money += 4 - infectCombo;
|
||||
Player.GlobalMessage(pKiller.FullName + " is on a rampage! " + (infectCombo + 1) + " infections in a row!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
infectCombo = 0;
|
||||
}
|
||||
lastPlayerToInfect = pKiller.name;
|
||||
pKiller.infectThisRound++;
|
||||
pKiller.playersInfected++;
|
||||
Player.GlobalMessage(String.Format(
|
||||
messages[random.Next(messages.Length)],
|
||||
Colors.red + pKiller.DisplayName + Colors.yellow,
|
||||
Colors.red + pAlive.DisplayName + Colors.yellow));
|
||||
CheckPlayerColor(pAlive, Colors.red);
|
||||
}
|
||||
});
|
||||
});
|
||||
Thread.Sleep(50);
|
||||
}
|
||||
}
|
||||
|
||||
pAlive.color = Colors.red;
|
||||
pKiller.playersInfected = pKiller.playersInfected++;
|
||||
Player.GlobalDespawn(pAlive, false);
|
||||
Player.GlobalSpawn(pAlive, pAlive.pos[0], pAlive.pos[1], pAlive.pos[2], pAlive.rot[0], pAlive.rot[1], false);
|
||||
Thread.Sleep(50);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
Thread.Sleep(50);
|
||||
}
|
||||
static void CheckPlayerColor(Player p, string color) {
|
||||
if (p.color == color) return;
|
||||
p.color = color;
|
||||
Player.GlobalDespawn(p, false);
|
||||
Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false);
|
||||
}
|
||||
|
||||
public void EndRound(object sender, ElapsedEventArgs e) {
|
||||
@ -229,97 +220,62 @@ namespace MCGalaxy {
|
||||
timer.Enabled = false;
|
||||
string playersString = "";
|
||||
Player[] online = null;
|
||||
if (aliveCount == 0)
|
||||
{
|
||||
|
||||
if (aliveCount == 0) {
|
||||
online = PlayerInfo.Online;
|
||||
foreach (Player winners in online)
|
||||
{
|
||||
if (winners.level.name == currentLevelName)
|
||||
{
|
||||
winners.blockCount = 50;
|
||||
winners.infected = false;
|
||||
winners.infectThisRound = 0;
|
||||
if (winners.level.name == currentLevelName)
|
||||
{
|
||||
winners.color = winners.group.color;
|
||||
playersString += winners.group.color + winners.DisplayName + Colors.white + ", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
alive.ForEach(delegate(Player winners)
|
||||
{
|
||||
winners.blockCount = 50;
|
||||
winners.infected = false;
|
||||
winners.infectThisRound = 0;
|
||||
if (winners.level.name == currentLevelName)
|
||||
{
|
||||
winners.color = winners.group.color;
|
||||
playersString += winners.group.color + winners.DisplayName + Colors.white + ", ";
|
||||
}
|
||||
});
|
||||
foreach (Player pl in online)
|
||||
ResetPlayer(pl, ref playersString);
|
||||
} else {
|
||||
alive.ForEach(pl => ResetPlayer(pl, ref playersString));
|
||||
}
|
||||
|
||||
Player.GlobalMessage(playersString);
|
||||
online = PlayerInfo.Online;
|
||||
foreach (Player winners in online)
|
||||
{
|
||||
if (!winners.CheckIfInsideBlock() && aliveCount == 0 && winners.level.name == currentLevelName)
|
||||
{
|
||||
Player.GlobalDespawn(winners, false);
|
||||
Player.GlobalSpawn(winners, winners.pos[0], winners.pos[1], winners.pos[2], winners.rot[0], winners.rot[1], false);
|
||||
Random random2 = new Random();
|
||||
int randomInt = 0;
|
||||
if (winners.playersInfected > 5)
|
||||
{
|
||||
randomInt = random2.Next(1, winners.playersInfected);
|
||||
Random rand = new Random();
|
||||
foreach (Player pl in online) {
|
||||
int money = 0;
|
||||
if (pl.level.name != currentLevelName) continue;
|
||||
bool inBlock = pl.CheckIfInsideBlock();
|
||||
|
||||
if (!inBlock && aliveCount == 0) {
|
||||
money = rand.Next(1, 5 + pl.playersInfected);
|
||||
} else if (!inBlock && (aliveCount == 1 && !pl.infected)) {
|
||||
money = rand.Next(5, 15);
|
||||
} else if (inBlock) {
|
||||
money = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
randomInt = random2.Next(1, 5);
|
||||
|
||||
Player.GlobalDespawn(pl, false);
|
||||
Player.GlobalSpawn(pl, pl.pos[0], pl.pos[1], pl.pos[2], pl.rot[0], pl.rot[1], false);
|
||||
if (money == -1) {
|
||||
pl.SendMessage("You may not hide inside a block! No " + Server.moneys + " for you!"); money = 0;
|
||||
} else if (money > 0) {
|
||||
pl.SendMessage( Colors.gold + "You gained " + money + " " + Server.moneys);
|
||||
}
|
||||
Player.SendMessage(winners, Colors.gold + "You gained " + randomInt + " " + Server.moneys);
|
||||
winners.blockCount = 50;
|
||||
winners.playersInfected = 0;
|
||||
winners.money = winners.money + randomInt;
|
||||
}
|
||||
else if (!winners.CheckIfInsideBlock() && (aliveCount == 1 && !winners.infected) && winners.level.name == currentLevelName)
|
||||
{
|
||||
Player.GlobalDespawn(winners, false);
|
||||
Player.GlobalSpawn(winners, winners.pos[0], winners.pos[1], winners.pos[2], winners.rot[0], winners.rot[1], false);
|
||||
Random random2 = new Random();
|
||||
int randomInt = 0;
|
||||
randomInt = random2.Next(1, 15);
|
||||
Player.SendMessage(winners, Colors.gold + "You gained " + randomInt + " " + Server.moneys);
|
||||
winners.blockCount = 50;
|
||||
winners.playersInfected = 0;
|
||||
winners.money = winners.money + randomInt;
|
||||
}
|
||||
else if (winners.level.name == currentLevelName)
|
||||
{
|
||||
winners.SendMessage("You may not hide inside a block! No " + Server.moneys + " for you!");
|
||||
pl.blockCount = 50;
|
||||
pl.playersInfected = 0;
|
||||
pl.money += money;
|
||||
|
||||
pl.infected = false;
|
||||
pl.color = pl.group.color;
|
||||
if (pl.referee) {
|
||||
pl.SendMessage("You gained one " + Server.moneys + " because you're a ref. Would you like a medal as well?");
|
||||
pl.money++;
|
||||
}
|
||||
}
|
||||
try {alive.Clear(); infectd.Clear(); } catch{ }
|
||||
online = PlayerInfo.Online;
|
||||
foreach (Player player in online)
|
||||
{
|
||||
player.infected = false;
|
||||
player.color = player.group.color;
|
||||
Player.GlobalDespawn(player, false);
|
||||
Player.GlobalSpawn(player, player.pos[0], player.pos[1], player.pos[2], player.rot[0], player.rot[1], false);
|
||||
if (player.level.name == currentLevelName)
|
||||
{
|
||||
if (player.referee)
|
||||
{
|
||||
player.SendMessage("You gained one " + Server.moneys + " because you're a ref. Would you like a medal as well?");
|
||||
player.money++;
|
||||
}
|
||||
|
||||
void ResetPlayer(Player p, ref string playersString) {
|
||||
p.blockCount = 50;
|
||||
p.infected = false;
|
||||
p.infectThisRound = 0;
|
||||
|
||||
if (p.level.name == currentLevelName) {
|
||||
p.color = p.group.color;
|
||||
playersString += p.group.color + p.DisplayName + Colors.white + ", ";
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public void ChangeLevel()
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ namespace MCGalaxy {
|
||||
p.SendMessage("You are pillaring! Stop before you get kicked!");
|
||||
}
|
||||
if (p.blocksStacked == 4 ) {
|
||||
Command.all.Find("kick").Use(null, p.name + " No pillaring allowed!");
|
||||
p.Kick(" No pillaring allowed!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user