Add /zg hitbox to allow configuring hitbox detection distance, more code cleanup.

This commit is contained in:
UnknownShadow200 2016-03-13 22:52:21 +11:00
parent c598df0006
commit 50f43e5bd2
3 changed files with 126 additions and 161 deletions

View File

@ -90,15 +90,24 @@ namespace MCGalaxy.Commands
} }
static void HandleHitbox(Player p, string message, string[] args) { 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) { public override void Help(Player p) {
Player.SendMessage(p, "/zombiegame start - Starts a Zombie Survival game for one round."); Player.SendMessage(p, "/zg start 0 - Starts a Zombie Survival game for an unlimited amount of rounds.");
Player.SendMessage(p, "/zombiegame 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, "/zombiegame 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, "/zombiegame 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, "/zombiegame 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).");
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2010 MCLawl Team - Copyright 2010 MCLawl Team -
Created by Snowl (David D.) and Cazzar (Cayde D.) Created by Snowl (David D.) and Cazzar (Cayde D.)
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
@ -15,7 +15,7 @@
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@ -39,23 +39,23 @@ namespace MCGalaxy {
RoundInProgress = false; RoundInProgress = false;
RoundsDone++; RoundsDone++;
if (Status == ZombieGameStatus.NotStarted) { if (Status == ZombieGameStatus.NotStarted) {
return; return;
} else if (Status == ZombieGameStatus.InfiniteRounds) { } else if (Status == ZombieGameStatus.InfiniteRounds) {
DoRound(); DoRound();
if (ChangeLevels) ChangeLevel(); if (ChangeLevels) ChangeLevel();
} else if (Status == ZombieGameStatus.SingleRound) { } else if (Status == ZombieGameStatus.SingleRound) {
DoRound(); DoRound();
ResetState(); return; ResetState(); return;
} else if (Status == ZombieGameStatus.VariableRounds) { } else if (Status == ZombieGameStatus.VariableRounds) {
if (RoundsDone == MaxRounds) { if (RoundsDone == MaxRounds) {
ResetState(); return; ResetState(); return;
} else { } else {
DoRound(); DoRound();
if (ChangeLevels) ChangeLevel(); if (ChangeLevels) ChangeLevel();
} }
} else if (Status == ZombieGameStatus.LastRound) { } else if (Status == ZombieGameStatus.LastRound) {
ResetState(); return; ResetState(); return;
} }
} }
} }
@ -64,7 +64,7 @@ namespace MCGalaxy {
if (Status == ZombieGameStatus.NotStarted) return; if (Status == ZombieGameStatus.NotStarted) return;
List<Player> players = DoRoundCountdown(); List<Player> players = DoRoundCountdown();
theEnd: theEnd:
Random random = new Random(); Random random = new Random();
int firstinfect = random.Next(players.Count()); int firstinfect = random.Next(players.Count());
Player player = null; Player player = null;
@ -75,9 +75,7 @@ namespace MCGalaxy {
Player.GlobalMessage(player.color + player.name + " %Sstarted the infection!"); Player.GlobalMessage(player.color + player.name + " %Sstarted the infection!");
player.infected = true; player.infected = true;
player.color = Colors.red; CheckPlayerColor(player, 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);
RoundInProgress = true; RoundInProgress = true;
int roundMins = random.Next(5, 8); int roundMins = random.Next(5, 8);
@ -89,7 +87,7 @@ namespace MCGalaxy {
Player[] online = PlayerInfo.Online; Player[] online = PlayerInfo.Online;
foreach (Player p in online) { foreach (Player p in online) {
if (p != player) if (p != player)
alive.Add(p); alive.Add(p);
} }
infectd.Clear(); infectd.Clear();
@ -126,7 +124,7 @@ namespace MCGalaxy {
Player.GlobalMessage("%4Round Start:%f 1..."); Player.GlobalMessage("%4Round Start:%f 1...");
Thread.Sleep(1000); if (!Server.ZombieModeOn) return null; Thread.Sleep(1000); if (!Server.ZombieModeOn) return null;
RoundInProgress = true; RoundInProgress = true;
int nonRefPlayers = 0; int nonRefPlayers = 0;
List<Player> players = new List<Player>(); List<Player> players = new List<Player>();
Player[] online = PlayerInfo.Online; Player[] online = PlayerInfo.Online;
@ -148,66 +146,59 @@ namespace MCGalaxy {
void DoCoreGame(List<Player> players, Random random) { void DoCoreGame(List<Player> players, Random random) {
while (aliveCount > 0) { while (aliveCount > 0) {
aliveCount = alive.Count; aliveCount = alive.Count;
infectd.ForEach(delegate(Player pKiller) infectd.ForEach(
{ delegate(Player pKiller)
if (pKiller.color != Colors.red)
{ {
pKiller.color = Colors.red; CheckPlayerColor(pKiller, Colors.red);
Player.GlobalDespawn(pKiller, false); alive.ForEach(
Player.GlobalSpawn(pKiller, pKiller.pos[0], pKiller.pos[1], pKiller.pos[2], pKiller.rot[0], pKiller.rot[1], false); delegate(Player pAlive)
}
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)
{ {
pAlive.infected = true; CheckPlayerColor(pAlive, pAlive.group.color);
infectd.Add(pAlive); if (Math.Abs(pAlive.pos[0] - pKiller.pos[0]) > HitboxPrecision
alive.Remove(pAlive); || Math.Abs(pAlive.pos[1] - pKiller.pos[1]) > HitboxPrecision
players.Remove(pAlive); || Math.Abs(pAlive.pos[2] - pKiller.pos[2]) > HitboxPrecision)
pAlive.blockCount = 25; return;
if (lastPlayerToInfect == pKiller.name)
if (!pAlive.infected && pKiller.infected && !pAlive.referee && !pKiller.referee &&
pKiller != pAlive && pKiller.level.name == currentLevelName && pAlive.level.name == currentLevelName)
{ {
infectCombo++; pAlive.infected = true;
if (infectCombo >= 2) infectd.Add(pAlive);
{ alive.Remove(pAlive);
pKiller.SendMessage("You gained " + (4 - infectCombo) + " " + Server.moneys); players.Remove(pAlive);
pKiller.money = pKiller.money + 4 - infectCombo; pAlive.blockCount = 25;
Player.GlobalMessage(pKiller.color + pKiller.name + " is on a rampage! " + (infectCombo + 1) + " infections in a row!"); if (lastPlayerToInfect == pKiller.name) {
infectCombo++;
if (infectCombo >= 2) {
pKiller.SendMessage("You gained " + (4 - infectCombo) + " " + Server.moneys);
pKiller.money += 4 - infectCombo;
Player.GlobalMessage(pKiller.FullName + " is on a rampage! " + (infectCombo + 1) + " infections in a row!");
}
} 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);
} }
else });
{
infectCombo = 0;
}
lastPlayerToInfect = pKiller.name;
pKiller.infectThisRound++;
Player.GlobalMessage(String.Format(
messages[random.Next(messages.Length)],
Colors.red + pKiller.DisplayName + Colors.yellow,
Colors.red + pAlive.DisplayName + Colors.yellow));
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); 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) { public void EndRound(object sender, ElapsedEventArgs e) {
if (Status == ZombieGameStatus.NotStarted) return; if (Status == ZombieGameStatus.NotStarted) return;
Player.GlobalMessage("%4Round End:%f 5"); Thread.Sleep(1000); Player.GlobalMessage("%4Round End:%f 5"); Thread.Sleep(1000);
@ -229,98 +220,63 @@ namespace MCGalaxy {
timer.Enabled = false; timer.Enabled = false;
string playersString = ""; string playersString = "";
Player[] online = null; Player[] online = null;
if (aliveCount == 0)
{ if (aliveCount == 0) {
online = PlayerInfo.Online; online = PlayerInfo.Online;
foreach (Player winners in online) foreach (Player pl in online)
{ ResetPlayer(pl, ref playersString);
if (winners.level.name == currentLevelName) } else {
{ alive.ForEach(pl => ResetPlayer(pl, ref playersString));
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 + ", ";
}
});
} }
Player.GlobalMessage(playersString); Player.GlobalMessage(playersString);
online = PlayerInfo.Online; online = PlayerInfo.Online;
foreach (Player winners in online) Random rand = new Random();
{ foreach (Player pl in online) {
if (!winners.CheckIfInsideBlock() && aliveCount == 0 && winners.level.name == currentLevelName) int money = 0;
{ if (pl.level.name != currentLevelName) continue;
Player.GlobalDespawn(winners, false); bool inBlock = pl.CheckIfInsideBlock();
Player.GlobalSpawn(winners, winners.pos[0], winners.pos[1], winners.pos[2], winners.rot[0], winners.rot[1], false);
Random random2 = new Random(); if (!inBlock && aliveCount == 0) {
int randomInt = 0; money = rand.Next(1, 5 + pl.playersInfected);
if (winners.playersInfected > 5) } else if (!inBlock && (aliveCount == 1 && !pl.infected)) {
{ money = rand.Next(5, 15);
randomInt = random2.Next(1, winners.playersInfected); } else if (inBlock) {
} money = -1;
else
{
randomInt = random2.Next(1, 5);
}
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(pl, false);
Player.GlobalDespawn(winners, false); Player.GlobalSpawn(pl, pl.pos[0], pl.pos[1], pl.pos[2], pl.rot[0], pl.rot[1], false);
Player.GlobalSpawn(winners, winners.pos[0], winners.pos[1], winners.pos[2], winners.rot[0], winners.rot[1], false); if (money == -1) {
Random random2 = new Random(); pl.SendMessage("You may not hide inside a block! No " + Server.moneys + " for you!"); money = 0;
int randomInt = 0; } else if (money > 0) {
randomInt = random2.Next(1, 15); 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.level.name == currentLevelName) pl.blockCount = 50;
{ pl.playersInfected = 0;
winners.SendMessage("You may not hide inside a block! No " + Server.moneys + " for you!"); 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{ } 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++;
}
}
}
return;
} }
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 + ", ";
}
}
public void ChangeLevel() public void ChangeLevel()
{ {
if (queLevel) if (queLevel)
@ -376,21 +332,21 @@ namespace MCGalaxy {
Level1Vote = 0; Level2Vote = 0; Level3Vote = 0; Level1Vote = 0; Level2Vote = 0; Level3Vote = 0;
lastLevelVote1 = selectedLevel1; lastLevelVote2 = selectedLevel2; lastLevelVote1 = selectedLevel1; lastLevelVote2 = selectedLevel2;
if (Status == ZombieGameStatus.NotStarted || Status == ZombieGameStatus.LastRound) if (Status == ZombieGameStatus.NotStarted || Status == ZombieGameStatus.LastRound)
return; return;
if (initialChangeLevel) if (initialChangeLevel)
{ {
Server.votingforlevel = true; Server.votingforlevel = true;
Player.GlobalMessage(" " + Colors.black + "Level Vote: %S" + selectedLevel1 + ", " + selectedLevel2 + Player.GlobalMessage(" " + Colors.black + "Level Vote: %S" + selectedLevel1 + ", " + selectedLevel2 +
" or random " + "(" + Colors.lime + "1%S/" + Colors.red + "2%S/" + Colors.blue + "3%S)"); " or random " + "(" + Colors.lime + "1%S/" + Colors.red + "2%S/" + Colors.blue + "3%S)");
System.Threading.Thread.Sleep(15000); System.Threading.Thread.Sleep(15000);
Server.votingforlevel = false; Server.votingforlevel = false;
} }
else { Level1Vote = 1; Level2Vote = 0; Level3Vote = 0; } else { Level1Vote = 1; Level2Vote = 0; Level3Vote = 0; }
if (Status == ZombieGameStatus.NotStarted || Status == ZombieGameStatus.LastRound) if (Status == ZombieGameStatus.NotStarted || Status == ZombieGameStatus.LastRound)
return; return;
if (Level1Vote >= Level2Vote) if (Level1Vote >= Level2Vote)
{ {
@ -412,7 +368,7 @@ namespace MCGalaxy {
} }
ChangeLevel(selectedLevel2, Server.ZombieOnlyServer); ChangeLevel(selectedLevel2, Server.ZombieOnlyServer);
} }
Player[] online = PlayerInfo.Online; Player[] online = PlayerInfo.Online;
foreach (Player winners in online) { foreach (Player winners in online) {
winners.voted = false; winners.voted = false;
} }

View File

@ -35,7 +35,7 @@ namespace MCGalaxy {
p.SendMessage("You are pillaring! Stop before you get kicked!"); p.SendMessage("You are pillaring! Stop before you get kicked!");
} }
if (p.blocksStacked == 4 ) { if (p.blocksStacked == 4 ) {
Command.all.Find("kick").Use(null, p.name + " No pillaring allowed!"); p.Kick(" No pillaring allowed!");
return true; return true;
} }
} }