PageRenderTime 79ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 1ms

/fCraft/Commands/FunCommands.cs

https://github.com/EpicClowny/LegendCraft
C# | 2392 lines | 2202 code | 150 blank | 40 comment | 571 complexity | 4bb490604a5537b1ecf0c23a6954ea71 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. //Copyright (C) <2012> <Jon Baker, Glenn MariĂŤn and Lao Tszy>
  2. //This program is free software: you can redistribute it and/or modify
  3. //it under the terms of the GNU General Public License as published by
  4. //the Free Software Foundation, either version 3 of the License, or
  5. //(at your option) any later version.
  6. //This program is distributed in the hope that it will be useful,
  7. //but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. //GNU General Public License for more details.
  10. //You should have received a copy of the GNU General Public License
  11. //along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading;
  17. using RandomMaze;
  18. namespace fCraft
  19. {
  20. internal static class FunCommands
  21. {
  22. internal static void Init()
  23. {
  24. CommandManager.RegisterCommand(CdRandomMaze);
  25. CommandManager.RegisterCommand(CdMazeCuboid);
  26. CommandManager.RegisterCommand(CdFirework);
  27. CommandManager.RegisterCommand(CdLife);
  28. CommandManager.RegisterCommand(CdPossess);
  29. CommandManager.RegisterCommand(CdUnpossess);
  30. CommandManager.RegisterCommand(CdThrow);
  31. CommandManager.RegisterCommand(CdInsult);
  32. CommandManager.RegisterCommand(CdFFAStatistics);
  33. CommandManager.RegisterCommand(CdFreeForAll);
  34. CommandManager.RegisterCommand(CdTDStatistics);
  35. CommandManager.RegisterCommand(CdTeamDeathMatch);
  36. CommandManager.RegisterCommand(CdInfection);
  37. CommandManager.RegisterCommand(CdSetModel);
  38. CommandManager.RegisterCommand(CdBot);
  39. CommandManager.RegisterCommand(CdCTF);
  40. Player.Moving += PlayerMoved;
  41. }
  42. public static string[] validEntities =
  43. {
  44. "chicken",
  45. "creeper",
  46. "croc",
  47. "humanoid",
  48. "human",
  49. "pig",
  50. "printer",
  51. "sheep",
  52. "skeleton",
  53. "spider",
  54. "zombie"
  55. };
  56. public static void PlayerMoved(object sender, fCraft.Events.PlayerMovingEventArgs e)
  57. {
  58. if (e.Player.Info.IsFrozen || e.Player.SpectatedPlayer != null || !e.Player.SpeedMode)
  59. return;
  60. Vector3I oldPos = e.OldPosition.ToBlockCoords();
  61. Vector3I newPos = e.NewPosition.ToBlockCoords();
  62. //check if has moved 1 whole block
  63. if (newPos.X == oldPos.X + 1 || newPos.X == oldPos.X - 1 || newPos.Y == oldPos.Y + 1 || newPos.Y == oldPos.Y - 1)
  64. {
  65. Server.Players.Message("Old: " + newPos.ToString());
  66. Vector3I move = newPos - oldPos;
  67. int AccelerationFactor = 4;
  68. Vector3I acceleratedNewPos = oldPos + move * AccelerationFactor;
  69. //do not forget to check for all the null pointers here - TODO
  70. Map m = e.Player.World.Map;
  71. //check if can move through all the blocks along the path
  72. Vector3F normal = move.Normalize();
  73. Vector3I prevBlockPos = e.OldPosition.ToBlockCoords();
  74. for (int i = 1; i <= AccelerationFactor * move.Length; ++i)
  75. {
  76. Vector3I pos = (oldPos + i * normal).Round();
  77. if (prevBlockPos == pos) //didnt yet hit the next block
  78. continue;
  79. if (!m.InBounds(pos) || m.GetBlock(pos) != Block.Air) //got out of bounds or some solid block
  80. {
  81. acceleratedNewPos = (oldPos + normal * (i - 1)).Round();
  82. break;
  83. }
  84. prevBlockPos = pos;
  85. }
  86. //teleport keeping the same orientation
  87. //Server.Players.Message("New: "+ acceleratedNewPos.ToString());
  88. e.Player.Send(PacketWriter.MakeSelfTeleport(new Position((short)(acceleratedNewPos.X * 32), (short)(acceleratedNewPos.Y * 32), e.Player.Position.Z, e.NewPosition.R, e.NewPosition.L)));
  89. }
  90. }
  91. #region LegendCraft
  92. /* Copyright (c) <2012-2014> <LeChosenOne, DingusBungus>
  93. Permission is hereby granted, free of charge, to any person obtaining a copy
  94. of this software and associated documentation files (the "Software"), to deal
  95. in the Software without restriction, including without limitation the rights
  96. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  97. copies of the Software, and to permit persons to whom the Software is
  98. furnished to do so, subject to the following conditions:
  99. The above copyright notice and this permission notice shall be included in
  100. all copies or substantial portions of the Software.
  101. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  102. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  103. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  104. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  105. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  106. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  107. THE SOFTWARE.*/
  108. static readonly CommandDescriptor CdBot = new CommandDescriptor
  109. {
  110. Name = "Bot",
  111. Permissions = new Permission[] { Permission.Bots },
  112. Category = CommandCategory.Fun,
  113. IsConsoleSafe = false,
  114. Usage = "/Bot <create / remove / removeAll / model / close / explode / list / summon / stop / move / fly>",
  115. Help = "Commands for manipulating bots. For help and usage for the individual options, use /help bot <option>.",
  116. HelpSections = new Dictionary<string, string>{
  117. { "create", "&H/Bot create <botname> <model>\n&S" +
  118. "Creates a new bot with the given name. Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie." },
  119. { "remove", "&H/Bot remove <botname>\n&S" +
  120. "Removes the given bot." },
  121. { "removeall", "&H/Bot removeAll\n&S" +
  122. "Removes all bots from the server."},
  123. { "model", "&H/Bot model <bot name> <model>\n&S" +
  124. "Changes the model of a bot to the given model. Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie."},
  125. { "clone", "&H/Bot clone <bot> <player>\n&S" +
  126. "Changes the skin of a bot to the skin of the given player. Leave the player parameter blank to reset the skin. Bot's model must be human. Use /bot changeModel to change the bot's model."},
  127. { "explode", "&H/Bot explode <bot>\n&S" +
  128. "Epically explodes a bot, removing it from the server."},
  129. { "list", "&H/Bot list\n&S" +
  130. "Prints out a list of all the bots on the server."},
  131. { "summon", "&H/Bot summon <botname>\n&S" +
  132. "Summons a bot from anywhere to your current position."},
  133. { "move", "&H/Bot move <botname> <player>\n&S" +
  134. "Moves the bot to a specific player."},
  135. { "fly", "&H/Bot fly <botname>\n&S" +
  136. "Toggles whether the bot can fly or not."},
  137. { "stop", "&H/Bot stop <botname>\n&S" +
  138. "Stops the bot from doing any of its movement actions."}
  139. },
  140. Handler = BotHandler,
  141. };
  142. static void BotHandler(Player player, Command cmd)
  143. {
  144. if (!player.ClassiCube || !Heartbeat.ClassiCube())
  145. {
  146. player.Message("Bots can only be used on ClassiCube servers and clients!");
  147. return;
  148. }
  149. string option = cmd.Next(); //take in the option arg
  150. if (string.IsNullOrEmpty(option)) //empty? return, otherwise continue
  151. {
  152. CdBot.PrintUsage(player);
  153. return;
  154. }
  155. //certain options that take in specific params are in here, the rest are in the switch-case
  156. if (option.ToLower() == "list")
  157. {
  158. player.Message("_Bots on {0}_", ConfigKey.ServerName.GetString());
  159. foreach (Bot botCheck in Server.Bots)
  160. {
  161. player.Message(botCheck.Name + " on " + botCheck.World.Name);
  162. }
  163. return;
  164. }
  165. else if (option.ToLower() == "removeall")
  166. {
  167. Server.Bots.ForEach(botToRemove =>
  168. {
  169. botToRemove.removeBot();
  170. });
  171. player.Message("All bots removed from the server.");
  172. return;
  173. }
  174. else if (option.ToLower() == "move")
  175. {
  176. string targetBot = cmd.Next();
  177. if (string.IsNullOrEmpty(targetBot))
  178. {
  179. CdBot.PrintUsage(player);
  180. return;
  181. }
  182. string targetPlayer = cmd.Next();
  183. if (string.IsNullOrEmpty(targetPlayer))
  184. {
  185. CdBot.PrintUsage(player);
  186. return;
  187. }
  188. Bot targetB = player.World.FindBot(targetBot);
  189. Player targetP = player.World.FindPlayerExact(targetPlayer);
  190. if (targetP == null)
  191. {
  192. player.Message("Could not find {0} on {1}! Please make sure you spelled their name correctly.", targetPlayer, player.World);
  193. return;
  194. }
  195. if (targetB == null)
  196. {
  197. player.Message("Could not find {0} on {1}! Please make sure you spelled their name correctly.", targetBot, player.World);
  198. return;
  199. }
  200. player.Message("{0} is now moving!", targetB.Name);
  201. targetB.isMoving = true;
  202. targetB.NewPosition = targetP.Position;
  203. targetB.OldPosition = targetB.Position;
  204. targetB.timeCheck.Start();
  205. return;
  206. }
  207. else if (option.ToLower() == "follow")
  208. {
  209. string targetBot = cmd.Next();
  210. if (string.IsNullOrEmpty(targetBot))
  211. {
  212. CdBot.PrintUsage(player);
  213. return;
  214. }
  215. string targetPlayer = cmd.Next();
  216. if (string.IsNullOrEmpty(targetPlayer))
  217. {
  218. CdBot.PrintUsage(player);
  219. return;
  220. }
  221. Bot targetB = player.World.FindBot(targetBot);
  222. Player targetP = player.World.FindPlayerExact(targetPlayer);
  223. if (targetP == null)
  224. {
  225. player.Message("Could not find {0} on {1}! Please make sure you spelled their name correctly.", targetPlayer, player.World);
  226. return;
  227. }
  228. if (targetB == null)
  229. {
  230. player.Message("Could not find {0} on {1}! Please make sure you spelled their name correctly.", targetBot, player.World);
  231. return;
  232. }
  233. player.Message("{0} is now following {1}!", targetB.Name, targetP.Name);
  234. targetB.isMoving = true;
  235. targetB.followTarget = targetP;
  236. targetB.OldPosition = targetB.Position;
  237. targetB.timeCheck.Start();
  238. return;
  239. }
  240. //finally away from the special cases
  241. string botName = cmd.Next(); //take in bot name arg
  242. if (string.IsNullOrEmpty(botName)) //null check
  243. {
  244. CdBot.PrintUsage(player);
  245. return;
  246. }
  247. Bot bot = new Bot();
  248. if (option != "create")//since the bot wouldn't exist for "create", we must check the bot for all cases other than "create"
  249. {
  250. bot = Server.FindBot(botName.ToLower()); //Find the bot and assign to bot var
  251. if (bot == null) //If null, return and yell at user
  252. {
  253. player.Message("Could not find {0}! Please make sure you spelled the bot's name correctly. To view all the bots, type /Bot list.", botName);
  254. return;
  255. }
  256. }
  257. //now to the cases - additional args should be taken in at the individual cases
  258. switch (option.ToLower())
  259. {
  260. case "create":
  261. string requestedModel = cmd.Next();
  262. if (string.IsNullOrEmpty(requestedModel))
  263. {
  264. player.Message("Usage is /Bot create <bot name> <bot model>. Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie.");
  265. return;
  266. }
  267. if (!validEntities.Contains(requestedModel))
  268. {
  269. player.Message("That wasn't a valid bot model! Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie.");
  270. return;
  271. }
  272. //if a botname has already been chosen, ask player for a new name
  273. var matchingNames = from b in Server.Bots
  274. where b.Name.ToLower() == botName.ToLower()
  275. select b;
  276. if (matchingNames.Count() > 0)
  277. {
  278. player.Message("A bot with that name already exists! To view all bots, type /bot list.");
  279. return;
  280. }
  281. player.Message("Successfully created a bot.");
  282. Bot botCreate = new Bot();
  283. botCreate.setBot(botName, player.World, player.Position, LegendCraft.getNewID());
  284. botCreate.createBot();
  285. botCreate.changeBotModel(requestedModel);
  286. break;
  287. case "remove":
  288. player.Message("{0} was removed from the server.", bot.Name);
  289. bot.removeBot();
  290. break;
  291. case "fly":
  292. if (bot.isFlying)
  293. {
  294. player.Message("{0} can no longer fly.", bot.Name);
  295. bot.isFlying = false;
  296. break;
  297. }
  298. player.Message("{0} can now fly!", bot.Name);
  299. bot.isFlying = true;
  300. break;
  301. case "model":
  302. if (bot.Skin != "steve")
  303. {
  304. player.Message("Bots cannot change model with a skin! Use '/bot clone' to reset a bot's skin.");
  305. return;
  306. }
  307. string model = cmd.Next();
  308. if (string.IsNullOrEmpty(model))
  309. {
  310. player.Message("Usage is /Bot model <bot> <model>. Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie.");
  311. break;
  312. }
  313. if(model == "human")//lazy parse
  314. {
  315. model = "humanoid";
  316. }
  317. if (!validEntities.Contains(model))
  318. {
  319. player.Message("Please use a valid model name! Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie.");
  320. break;
  321. }
  322. player.Message("Changed bot model to {0}.", model);
  323. bot.changeBotModel(model);
  324. break;
  325. case "clone":
  326. if (bot.Model != "humanoid")
  327. {
  328. player.Message("A bot must be a human in order to have a skin. Use '/bot model <bot> <model>' to change a bot's model.");
  329. return;
  330. }
  331. string playerToClone = cmd.Next();
  332. if (string.IsNullOrEmpty(playerToClone))
  333. {
  334. player.Message("{0}'s skin was reset!", bot.Name);
  335. bot.Clone("steve");
  336. break;
  337. }
  338. PlayerInfo targetPlayer = PlayerDB.FindPlayerInfoExact(playerToClone);
  339. if (targetPlayer == null)
  340. {
  341. player.Message("That player doesn't exists! Please use a valid playername for the skin of the bot.");
  342. break;
  343. }
  344. player.Message("{0}'s skin was updated!", bot.Name);
  345. bot.Clone(playerToClone);
  346. break;
  347. case "explode":
  348. Server.Message("{0} exploded!", bot.Name);
  349. bot.explodeBot(player);
  350. break;
  351. case "summon":
  352. if (player.World != bot.World)
  353. {
  354. bot.tempRemoveBot(); //remove the entity
  355. bot.World = player.World; //update variables
  356. bot.Position = player.Position;
  357. bot.updateBotPosition(); //replace the entity
  358. }
  359. else
  360. {
  361. bot.Position = player.Position;
  362. bot.teleportBot(player.Position);
  363. }
  364. if (bot.Model != "human")
  365. {
  366. bot.changeBotModel(bot.Model); //replace the model, if the model is set
  367. }
  368. if (bot.Skin != "steve")
  369. {
  370. bot.Clone(bot.Skin); //replace the skin, if a skin is set
  371. }
  372. break;
  373. case "stop":
  374. player.Message("{0} is no longer moving.", bot.Name);
  375. bot.isMoving = false;
  376. bot.timeCheck.Stop();
  377. bot.timeCheck.Reset();
  378. bot.followTarget = null;
  379. break;
  380. default:
  381. CdBot.PrintUsage(player);
  382. break;
  383. }
  384. }
  385. static readonly CommandDescriptor CdSetModel = new CommandDescriptor
  386. {
  387. Name = "SetModel",
  388. Permissions = new Permission[] { Permission.EditPlayerDB },
  389. Category = CommandCategory.Fun,
  390. IsConsoleSafe = false,
  391. Usage = "/SetModel [Player] [Model]",
  392. Help = "Changes the model of a target player Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie. If the model is empty, the player's model will reset.",
  393. Handler = ModelHandler,
  394. };
  395. static void ModelHandler(Player player, Command cmd)
  396. {
  397. string target = cmd.Next();
  398. if(string.IsNullOrEmpty(target))
  399. {
  400. CdSetModel.PrintUsage(player);
  401. return;
  402. }
  403. Player targetPlayer = Server.FindPlayerOrPrintMatches(player, target, false, true);
  404. if (targetPlayer == null)
  405. {
  406. return;
  407. }
  408. string model = cmd.Next();
  409. if (string.IsNullOrEmpty(model))
  410. {
  411. player.Message("Reset the model for {0}.", targetPlayer.Name);
  412. targetPlayer.Model = player.Name; //reset the model to the player's name
  413. return;
  414. }
  415. if (model == "human")//execute super lazy parse
  416. {
  417. model = "humanoid";
  418. }
  419. if (!validEntities.Contains(model))
  420. {
  421. player.Message("Please choose a valid model! Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie.");
  422. return;
  423. }
  424. player.Message("{0} has been changed into a {1}!", targetPlayer.Name, model);
  425. targetPlayer.Model = model;
  426. return;
  427. }
  428. static readonly CommandDescriptor CdTroll = new CommandDescriptor //Troll is an old command from 800craft that i have rehashed because of its popularity
  429. { //The original command and the idea for the command were done by Jonty800 and Rebelliousdude.
  430. Name = "Troll",
  431. Permissions = new Permission[] { Permission.Moderation },
  432. Category = CommandCategory.Chat | CommandCategory.Fun,
  433. IsConsoleSafe = true,
  434. Usage = "/Troll (playername) (message-type) (message)",
  435. Help = "Allows you impersonate others in the chat. Available chat types are msg, st, ac, pm, rq, and leave.",
  436. NotRepeatable = true,
  437. Handler = Troll,
  438. };
  439. static void Troll(Player p, Command c)
  440. {
  441. string name = c.Next();
  442. string chatType = c.Next();
  443. string msg = c.NextAll();
  444. if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(chatType))
  445. {
  446. p.Message("Use like : /Troll (playername) (chat-type) (message)");
  447. return;
  448. }
  449. Player tgt = Server.FindPlayerOrPrintMatches(p, name, false, true);
  450. if (tgt == null) { return; }
  451. switch (chatType)
  452. {
  453. default:
  454. p.Message("The available chat types are: st, ac, pm, msg, rq and leave");
  455. break;
  456. case "leave":
  457. Server.Message("&SPlayer {0}&S left the server.", tgt.ClassyName);
  458. break;
  459. case "ragequit":
  460. case "rq":
  461. string quitMsg = "";
  462. if (msg.Length > 1) { quitMsg = ": &C" + msg; }
  463. Server.Message("{0}&4 Ragequit from the server{1}", tgt.ClassyName, quitMsg);
  464. Server.Message("&SPlayer {0}&S left the server.", tgt.ClassyName);
  465. break;
  466. case "st":
  467. case "staffchat":
  468. case "staff":
  469. if (string.IsNullOrEmpty(msg))
  470. {
  471. p.Message("The st option requires a message: /troll (player) st (message)");
  472. return;
  473. }
  474. Server.Message("&P(staff){0}&P: {1}", tgt.ClassyName, msg);
  475. break;
  476. case "pm":
  477. case "privatemessage":
  478. case "private":
  479. case "whisper":
  480. if (string.IsNullOrEmpty(msg))
  481. {
  482. p.Message("The pm option requires a message: /troll (player) pm (message)");
  483. return;
  484. }
  485. Server.Message("&Pfrom {0}: {1}", tgt.Name, msg);
  486. break;
  487. case "ac":
  488. case "adminchat":
  489. case "admin":
  490. if (string.IsNullOrEmpty(msg))
  491. {
  492. p.Message("The ac option requires a message: /troll (player) ac (message)");
  493. return;
  494. }
  495. Server.Message("&9(Admin){0}&P: {1}", tgt.ClassyName, msg);
  496. break;
  497. case "msg":
  498. case "message":
  499. case "global":
  500. case "server":
  501. if (string.IsNullOrEmpty(msg))
  502. {
  503. p.Message("The msg option requires a message: /troll (player) msg (message)");
  504. return;
  505. }
  506. Server.Message("{0}&f: {1}", tgt.ClassyName, msg);
  507. break;
  508. }
  509. return;
  510. }
  511. #region Gamemodes
  512. static readonly CommandDescriptor CdCTF = new CommandDescriptor
  513. {
  514. Name = "CTF",
  515. Aliases = new[] { "CaptureTheFlag" },
  516. Category = CommandCategory.World,
  517. Permissions = new Permission[] { Permission.Games },
  518. IsConsoleSafe = false,
  519. Usage = "/CTF [Start | Stop | SetSpawn | SetFlag | Help]",
  520. Help = "Manage the CTF Game!",
  521. Handler = CTFHandler
  522. };
  523. private static void CTFHandler(Player player, Command cmd)
  524. {
  525. string option = cmd.Next();
  526. if (String.IsNullOrEmpty(option))
  527. {
  528. player.Message("Please select an option in the CTF menu!");
  529. return;
  530. }
  531. World world = player.World;
  532. switch (option.ToLower())
  533. {
  534. case "begin":
  535. case "start":
  536. if (world.blueCTFSpawn == new Vector3I(0, 0, 0) || world.redCTFSpawn == new Vector3I(0, 0, 0))
  537. {
  538. player.Message("&cYou must assign spawn points before the game starts! Use /CTF SetSpawn <red | blue>");
  539. return;
  540. }
  541. if (world.blueFlag == new Vector3I(0, 0, 0) || world.redFlag == new Vector3I(0, 0, 0))
  542. {
  543. player.Message("&cYou must set the flags before play! Use /CTF SetFlag <red | blue>");
  544. return;
  545. }
  546. if (world.Players.Count() < 2)
  547. {
  548. player.Message("&cYou need at least 2 players to play CTF");
  549. return;
  550. }
  551. try
  552. {
  553. foreach (Player p in player.World.Players)
  554. {
  555. p.JoinWorld(player.World, WorldChangeReason.Rejoin);
  556. }
  557. CTF.GetInstance(world);
  558. CTF.Start();
  559. }
  560. catch (Exception e)
  561. {
  562. Logger.Log(LogType.Error, "Error: " + e + e.Message);
  563. }
  564. break;
  565. case "end":
  566. case "stop":
  567. if (world.gameMode != GameMode.CaptureTheFlag)
  568. {
  569. player.Message("&cThere is no game of CTF currently going on!");
  570. break;
  571. }
  572. CTF.Stop(player);
  573. break;
  574. case "setspawn":
  575. if (world.gameMode != GameMode.NULL)
  576. {
  577. player.Message("&cYou cannot change spawns during the game!");
  578. return;
  579. }
  580. string team = cmd.Next();
  581. if (String.IsNullOrEmpty(team))
  582. {
  583. player.Message("&cPlease select a team to set a spawn for!");
  584. break;
  585. }
  586. if (team.ToLower() == "red")
  587. {
  588. world.redCTFSpawn = new Vector3I(player.Position.ToBlockCoords().X, player.Position.ToBlockCoords().Y, player.Position.ToBlockCoords().Z + 2);
  589. player.Message("&aRed team spawn set.");
  590. break;
  591. }
  592. else if (team.ToLower() == "blue")
  593. {
  594. world.blueCTFSpawn = new Vector3I(player.Position.ToBlockCoords().X, player.Position.ToBlockCoords().Y, player.Position.ToBlockCoords().Z + 2);
  595. player.Message("&aBlue team spawn set.");
  596. break;
  597. }
  598. else
  599. {
  600. player.Message("&cYou may only select the 'Blue' or 'Red' team!");
  601. break;
  602. }
  603. case "setflag":
  604. if (world.gameMode != GameMode.NULL)
  605. {
  606. player.Message("&cYou cannot change flags during the game!");
  607. return;
  608. }
  609. string flag = cmd.Next();
  610. if (String.IsNullOrEmpty(flag))
  611. {
  612. player.Message("&cPlease select a flag color to set!");
  613. break;
  614. }
  615. if (flag.ToLower() == "red")
  616. {
  617. //select red flag
  618. player.Message("&fPlease select where you wish to place the &cred&f flag. The &cred&f flag must be red wool.");
  619. player.Info.placingRedFlag = true;
  620. break;
  621. }
  622. else if (flag.ToLower() == "blue")
  623. {
  624. player.Message("&fPlease select where you wish to place the &9blue&f flag. The &9blue&f flag must be blue wool.");
  625. player.Info.placingBlueFlag = true;
  626. break;
  627. }
  628. else
  629. {
  630. player.Message("&cYou may only select a 'Blue' or 'Red' colored flag!");
  631. break;
  632. }
  633. case "help":
  634. case "rules":
  635. player.Message("Start: Starts the CTF game.");
  636. player.Message("Stop: Ends the CTF game.");
  637. player.Message("SetSpawn: Usage is /CTF SetSpawn <Red|Blue>. The spawn for each team will be set at your feet. Both spawns must be set for the game to begin.");
  638. player.Message("SetFlag: Usage is /CTF SetFlag <Red|Blue>. The next block clicked will be the corresponding team's flag. The blue flag must be a blue wool block, and the red flag must be a red wool block.");
  639. break;
  640. default:
  641. CdCTF.PrintUsage(player);
  642. break;
  643. }
  644. }
  645. static readonly CommandDescriptor CdInfection = new CommandDescriptor
  646. {
  647. Name = "Infection",
  648. Aliases = new[] { "ZombieSurvival", "zs" },
  649. Category = CommandCategory.World,
  650. Permissions = new Permission[] { Permission.Games },
  651. IsConsoleSafe = false,
  652. Usage = "/Infection [start | stop | custom | help]",
  653. Help = "Manage the Infection Gamemode!",
  654. Handler = InfectionHandler
  655. };
  656. private static void InfectionHandler(Player player, Command cmd)
  657. {
  658. string Option = cmd.Next();
  659. World world = player.World;
  660. if (string.IsNullOrEmpty(Option))
  661. {
  662. CdInfection.PrintUsage(player);
  663. return;
  664. }
  665. if (Option.ToLower() == "start")
  666. {
  667. if (world == WorldManager.MainWorld)
  668. {
  669. player.Message("&SInfection games cannot be played on the main world");
  670. return;
  671. }
  672. if (world.gameMode != GameMode.NULL)
  673. {
  674. player.Message("&SThere is already a game going on");
  675. return;
  676. }
  677. if (player.World.CountPlayers(true) < 2)
  678. {
  679. player.Message("&SThere must be at least &W2&S players on this world to play Infection");
  680. return;
  681. }
  682. else
  683. {
  684. try
  685. {
  686. player.World.Hax = false;
  687. foreach (Player p in player.World.Players)
  688. {
  689. p.JoinWorld(player.World, WorldChangeReason.Rejoin);
  690. }
  691. fCraft.Games.Infection.GetInstance(world);
  692. fCraft.Games.Infection.Start();
  693. }
  694. catch (Exception e)
  695. {
  696. Logger.Log(LogType.Error, "Error: " + e + e.Message);
  697. }
  698. return;
  699. }
  700. }
  701. if (Option.ToLower() == "stop")
  702. {
  703. if (world.gameMode == GameMode.Infection)
  704. {
  705. fCraft.Games.Infection.Stop(player);
  706. return;
  707. }
  708. else
  709. {
  710. player.Message("&SNo games of Infection are going on.");
  711. return;
  712. }
  713. }
  714. if (Option.ToLower() == "custom")
  715. {
  716. string stringLimit = cmd.Next();
  717. string stringDelay = cmd.Next();
  718. int intLimit, intDelay;
  719. if (String.IsNullOrEmpty(stringLimit) || String.IsNullOrEmpty(stringDelay))
  720. {
  721. player.Message("Usage for '/infection custom' is '/infection custom TimeLimit TimeDelay'.");
  722. }
  723. if (!int.TryParse(stringLimit, out intLimit))
  724. {
  725. player.Message("Please select a number for the time limit.");
  726. return;
  727. }
  728. if (!int.TryParse(stringDelay, out intDelay))
  729. {
  730. player.Message("Please select a number for the time delay.");
  731. return;
  732. }
  733. if (world == WorldManager.MainWorld)
  734. {
  735. player.Message("&SInfection games cannot be played on the main world");
  736. return;
  737. }
  738. if (world.gameMode != GameMode.NULL)
  739. {
  740. player.Message("&SThere is already a game going on");
  741. return;
  742. }
  743. if (player.World.CountPlayers(true) < 2)
  744. {
  745. player.Message("&SThere must be at least &W2&S players on this world to play Infection");
  746. return;
  747. }
  748. if (intLimit > 900 || intLimit < 60)
  749. {
  750. player.Message("&SThe game must be between 60 and 900 seconds! (1 and 15 minutes)");
  751. return;
  752. }
  753. if (intDelay > 60 || intDelay < 11)
  754. {
  755. player.Message("&SThe game delay must be greater than 10 seconds, but less than 60 seconds!");
  756. return;
  757. }
  758. else
  759. {
  760. try
  761. {
  762. player.World.Hax = false;
  763. foreach (Player p in player.World.Players)
  764. {
  765. p.JoinWorld(player.World, WorldChangeReason.Rejoin);
  766. }
  767. fCraft.Games.Infection.GetInstance(world);
  768. fCraft.Games.Infection.Custom(intLimit, intDelay);
  769. }
  770. catch (Exception e)
  771. {
  772. Logger.Log(LogType.Error, "Error: " + e + e.Message);
  773. }
  774. return;
  775. }
  776. }
  777. if (Option.ToLower() == "help")
  778. {
  779. player.Message("&SStart: Will begin a game of infection on the current world.\n" +
  780. "&SStop: Will end a game of infection on the current world.\n" +
  781. "&SCustom: Determines factors in the next Infection game. Factors are TimeLimit and TimeDelay. TimeDelay must be greater than 10.\n" +
  782. "&fExample: '/Infection Custom 100 12' would start an Infection game with a game length of 100 seconds, and it will begin in 12 seconds.\n"
  783. );
  784. }
  785. else
  786. {
  787. CdInfection.PrintUsage(player);
  788. return;
  789. }
  790. }
  791. static readonly CommandDescriptor CdTeamDeathMatch = new CommandDescriptor
  792. {
  793. Name = "TeamDeathMatch", //I think I resolved all of the bugs...
  794. Aliases = new[] { "td", "tdm" },
  795. Category = CommandCategory.World,
  796. Permissions = new Permission[] { Permission.Games },
  797. IsConsoleSafe = false,
  798. Usage = "/TeamDeathMatch [Start | Stop | Time | Score | ScoreLimit | TimeLimit | TimeDelay | Settings | Red | Blue | ManualTeams | About | Help]",
  799. Help = "Manage the TDM Gamemode!",
  800. Handler = TDHandler
  801. };
  802. private static void TDHandler(Player player, Command cmd) //For TDM Game: starting/ending game, customizing game options, viewing score, etc.
  803. {
  804. string Option = cmd.Next();
  805. World world = player.World;
  806. if (string.IsNullOrEmpty(Option))
  807. {
  808. CdTeamDeathMatch.PrintUsage(player);
  809. return;
  810. }
  811. if (Option.ToLower() == "start" || Option.ToLower() == "on") //starts the game
  812. {
  813. if (world == WorldManager.MainWorld)
  814. {
  815. player.Message("TDM games cannot be played on the main world");
  816. return;
  817. }
  818. if (world.gameMode != GameMode.NULL)
  819. {
  820. player.Message("There is already a game going on");
  821. return;
  822. }
  823. if (player.World.CountPlayers(true) < 2)
  824. {
  825. player.Message("There needs to be at least &W2&S players to play TDM");
  826. return;
  827. }
  828. if (TeamDeathMatch.blueSpawn == Position.Zero || TeamDeathMatch.redSpawn == Position.Zero)
  829. {
  830. player.Message("You must first assign the team's spawn points with &H/TD SetSpawn (Red/Blue)");
  831. return;
  832. }
  833. else
  834. {
  835. player.World.Hax = false;
  836. foreach (Player p in player.World.Players)
  837. {
  838. p.JoinWorld(player.World, WorldChangeReason.Rejoin);
  839. }
  840. TeamDeathMatch.GetInstance(player.World);
  841. TeamDeathMatch.Start();
  842. return;
  843. }
  844. }
  845. if (Option.ToLower() == "stop" || Option.ToLower() == "off") //stops the game
  846. {
  847. if (TeamDeathMatch.isOn)
  848. {
  849. TeamDeathMatch.Stop(player);
  850. return;
  851. }
  852. else
  853. {
  854. player.Message("No games of Team DeathMatch are going on");
  855. return;
  856. }
  857. }
  858. if (Option.ToLower() == "manualteams")
  859. {
  860. string option = cmd.Next();
  861. if (string.IsNullOrEmpty(option) || option.Length < 2 || option.Length > 9)
  862. {
  863. player.Message("Use like: /TD ManualTeams (On/Off)");
  864. return;
  865. }
  866. if (option.ToLower() == "off" || option.ToLower() == "auto" || option.ToLower() == "automatic")
  867. {
  868. if (!TeamDeathMatch.manualTeams)
  869. {
  870. player.Message("The team assign option is already set to &wAuto");
  871. return;
  872. }
  873. TeamDeathMatch.manualTeams = false;
  874. player.Message("The team assign option has been set to &WAuto&s.");
  875. return;
  876. }
  877. if (option.ToLower() == "on" || option.ToLower() == "manual")
  878. {
  879. if (TeamDeathMatch.manualTeams)
  880. {
  881. player.Message("The team assign option is already set to &wManual");
  882. return;
  883. }
  884. TeamDeathMatch.manualTeams = true;
  885. player.Message("The team assign option has been set to &WManual&s.");
  886. return;
  887. }
  888. }
  889. if (TeamDeathMatch.isOn && (Option.ToLower() == "timelimit" || Option.ToLower() == "scorelimit" || Option.ToLower() == "timedelay"))
  890. {
  891. player.Message("You cannot adjust game settings while a game is going on");
  892. return;
  893. }
  894. if (!TeamDeathMatch.isOn && (Option.ToLower() == "timelimit" || Option.ToLower() == "scorelimit" || Option.ToLower() == "timedelay"))
  895. {
  896. if (Option.ToLower() == "timelimit") //option to change the length of the game (5m default)
  897. {
  898. string time = cmd.Next();
  899. if (time == null)
  900. {
  901. player.Message("Use the syntax: /TD timelimit (whole number of minutes)\n&HNote: The acceptable times are from 1-20 minutes");
  902. return;
  903. }
  904. int timeLimit = 0;
  905. bool parsed = Int32.TryParse(time, out timeLimit);
  906. if (!parsed)
  907. {
  908. player.Message("Enter a whole number of minutes. For example: /TD timelimit 5");
  909. return;
  910. }
  911. if (timeLimit < 1 || timeLimit > 20)
  912. {
  913. player.Message("The accepted times are between 1 and 20 minutes");
  914. return;
  915. }
  916. else
  917. {
  918. TeamDeathMatch.timeLimit = (timeLimit * 60);
  919. player.Message("The time limit has been changed to &W{0}&S minutes", timeLimit);
  920. return;
  921. }
  922. }
  923. if (Option.ToLower() == "timedelay") //option to set the time delay for TDM games (20s default)
  924. {
  925. if (TeamDeathMatch.manualTeams)
  926. {
  927. player.Message("The manual team assign option is enabled so the delay is 30 seconds to enable team assigning");
  928. return;
  929. }
  930. string time = cmd.Next();
  931. if (time == null)
  932. {
  933. player.Message("Use the syntax: /TD timedelay (whole number of seconds)\n&HNote: The acceptable times incriment by 10 from 10 to 60");
  934. return;
  935. }
  936. int timeDelay = 0;
  937. bool parsed = Int32.TryParse(time, out timeDelay);
  938. if (!parsed)
  939. {
  940. player.Message("Enter a whole number of minutes. For example: /TD timedelay 20");
  941. return;
  942. }
  943. if (timeDelay != 10 && timeDelay != 20 && timeDelay != 30 && timeDelay != 40 && timeDelay != 50 && timeDelay != 60)
  944. {
  945. player.Message("The accepted times are 10, 20, 30, 40, 50, and 60 seconds");
  946. return;
  947. }
  948. else
  949. {
  950. TeamDeathMatch.timeDelay = timeDelay;
  951. player.Message("The time delay has been changed to &W{0}&s seconds", timeDelay);
  952. return;
  953. }
  954. }
  955. if (Option.ToLower() == "scorelimit") //changes the score limit (30 default)
  956. {
  957. string score = cmd.Next();
  958. if (score == null)
  959. {
  960. player.Message("Use the syntax: /TD scorelimit (whole number)\n&HNote: The acceptable scores are from 5-300 points");
  961. return;
  962. }
  963. int scoreLimit = 0;
  964. bool parsed = Int32.TryParse(score, out scoreLimit);
  965. if (!parsed)
  966. {
  967. player.Message("Enter a whole number score. For example: /TD scorelimit 50");
  968. return;
  969. }
  970. if (scoreLimit < 5 || scoreLimit > 300)
  971. {
  972. player.Message("The accepted scores are from 5-300 points");
  973. return;
  974. }
  975. else
  976. {
  977. TeamDeathMatch.scoreLimit = scoreLimit;
  978. player.Message("The score limit has been changed to &W{0}&s points", scoreLimit);
  979. return;
  980. }
  981. }
  982. }
  983. if (Option.ToLower() == "red")
  984. {
  985. string target = cmd.Next();
  986. if (target == null)
  987. {
  988. player.Message("Use like: /TD Red <PlayerName>");
  989. return;
  990. }
  991. Player targetP = Server.FindPlayerOrPrintMatches(player, target, true, true);
  992. if (targetP == null) return;
  993. if (player.World.gameMode == GameMode.TeamDeathMatch && !TeamDeathMatch.isOn)
  994. {
  995. TeamDeathMatch.AssignRed(targetP);
  996. return;
  997. }
  998. else
  999. {
  1000. player.Message("You can only assign teams during the delay of a Team DeathMatch Game.");
  1001. return;
  1002. }
  1003. }
  1004. if (Option.ToLower() == "blue")
  1005. {
  1006. string target = cmd.Next();
  1007. if (target == null)
  1008. {
  1009. player.Message("Use like: /TD Blue <PlayerName>");
  1010. return;
  1011. }
  1012. Player targetP = Server.FindPlayerOrPrintMatches(player, target, true, true);
  1013. if (targetP == null) return;
  1014. if (player.World.gameMode == GameMode.TeamDeathMatch && !TeamDeathMatch.isOn)
  1015. {
  1016. TeamDeathMatch.AssignBlue(targetP);
  1017. return;
  1018. }
  1019. else
  1020. {
  1021. player.Message("You can only assign teams during the delay of a Team DeathMatch Game.");
  1022. return;
  1023. }
  1024. }
  1025. if (Option.ToLower() == "setspawn")
  1026. {
  1027. string team = cmd.Next();
  1028. if (string.IsNullOrEmpty(team) || team.Length < 1)
  1029. {
  1030. player.Message("Use like: /TD SetSpawn (Red/Blue)");
  1031. return;
  1032. }
  1033. if (TeamDeathMatch.isOn)
  1034. {
  1035. player.Message("You cannot change the spawn during the game!");
  1036. return;
  1037. }
  1038. if (!TeamDeathMatch.isOn && player.World != WorldManager.MainWorld)
  1039. {
  1040. switch (team.ToLower())
  1041. {
  1042. default:
  1043. player.Message("Use like: /TD SetSpawn (Red/Blue)");
  1044. return;
  1045. case "red":
  1046. TeamDeathMatch.redSpawn = player.Position;
  1047. player.Message("&SSpawn for the &cRed&S team set.");
  1048. return;
  1049. case "blue":
  1050. TeamDeathMatch.blueSpawn = player.Position;
  1051. player.Message("&SSpawn for the &1Blue&S team set.");
  1052. return;
  1053. }
  1054. }
  1055. else
  1056. {
  1057. if (player.World == WorldManager.MainWorld) { player.Message("You cannot play TDM on the main world"); return; }
  1058. else if (TeamDeathMatch.isOn)
  1059. {
  1060. player.Message("You can only set the team spawns during the delay or before the game");
  1061. return;
  1062. }
  1063. }
  1064. }
  1065. if (Option.ToLower() == "score") //scoreboard for the matchs, different messages for when the game has ended. //td score
  1066. {
  1067. int red = TeamDeathMatch.redScore;
  1068. int blue = TeamDeathMatch.blueScore;
  1069. if (red > blue)
  1070. {
  1071. if (player.Info.isOnRedTeam)
  1072. {
  1073. player.Message("&sYour team is winning {0} to {1}", red, blue);
  1074. return;
  1075. }
  1076. if (player.Info.isOnBlueTeam)

Large files files are truncated, but you can click here to view the full file