public static void GunMove( Player player ) { World world = player.World; if ( null == world ) return; try { if ( null == world.Map ) return; if ( player.IsOnline ) { Position p = player.Position; double ksi = 2.0 * Math.PI * ( -player.Position.L ) / 256.0; double phi = 2.0 * Math.PI * ( player.Position.R - 64 ) / 256.0; double sphi = Math.Sin( phi ); double cphi = Math.Cos( phi ); double sksi = Math.Sin( ksi ); double cksi = Math.Cos( ksi ); if ( player.GunCache.Values.Count > 0 ) { foreach ( Vector3I block in player.GunCache.Values ) { if ( player.IsOnline ) { player.Send( PacketWriter.MakeSetBlock( block.X, block.Y, block.Z, world.Map.GetBlock( block ) ) ); Vector3I removed; player.GunCache.TryRemove( block.ToString(), out removed ); } } } for ( int y = -1; y < 2; ++y ) { for ( int z = -1; z < 2; ++z ) { if ( player.IsOnline ) { //4 is the distance betwen the player and the glass wall Vector3I glassBlockPos = new Vector3I( ( int )( cphi * cksi * 4 - sphi * ( 0.5 + y ) - cphi * sksi * ( 0.5 + z ) ), ( int )( sphi * cksi * 4 + cphi * ( 0.5 + y ) - sphi * sksi * ( 0.5 + z ) ), ( int )( sksi * 4 + cksi * ( 0.5 + z ) ) ); glassBlockPos += p.ToBlockCoords(); if ( world.Map.GetBlock( glassBlockPos ) == Block.Air ) { player.Send( PacketWriter.MakeSetBlock( glassBlockPos.X, glassBlockPos.Y, glassBlockPos.Z, Block.Glass ) ); player.GunCache.TryAdd( glassBlockPos.ToString(), glassBlockPos ); } } } } } } catch ( Exception ex ) { Logger.Log( LogType.SeriousError, "GunGlass: " + ex ); } }
void SetSpawn(Player player, Command cmd) { if (player.Can(Permissions.SetSpawn)) { world.map.spawn = player.pos; world.map.Save(); world.map.changesSinceBackup++; player.Send(PacketWriter.MakeTeleport(255, world.map.spawn), true); player.Message("New spawn point saved."); world.log.Log("{0} changed the spawned point.", LogType.UserActivity, player.name); } else { world.NoAccessMessage(player); } }
void Bring(Player player, Command cmd) { if (player.Can(Permissions.Bring)) { string name = cmd.Next(); Player target = world.FindPlayer(name); if (target != null) { Position pos = player.pos; pos.x += 1; pos.y += 1; pos.h += 1; target.Send(PacketWriter.MakeTeleport(255, pos)); } else { world.NoPlayerMessage(player, name); } } else { world.NoAccessMessage(player); } }
public static void SendGlobalAdd(Player p, BlockDefinition def) { if (p.Supports(CpeExtension.BlockDefinitionsExt) && def.Shape != 0) p.Send(Packet.MakeDefineBlockExt(def)); else p.Send(Packet.MakeDefineBlock(def)); p.Send(Packet.MakeSetBlockPermission((Block)def.BlockID, true, true)); }
static void towerHandler(Player player, Command cmd) { string Param = cmd.Next(); if (Param == null) { if (player.towerMode) { player.towerMode = false; player.Message("TowerMode has been turned off."); return; } else { player.towerMode = true; player.Message("TowerMode has been turned on. " + "All Iron blocks are now being replaced with Towers."); } } else if (Param.ToLower() == "remove") { if (player.TowerCache != null) { World world = player.World; if (world.Map != null) { player.World.Map.QueueUpdate(new BlockUpdate(null, player.towerOrigin, Block.Air)); foreach (Vector3I block in player.TowerCache.Values) { if (world.Map != null) { player.Send(PacketWriter.MakeSetBlock(block, player.WorldMap.GetBlock(block))); } } } player.TowerCache.Clear(); return; } else { player.Message("&WThere is no Tower to remove"); } } else CdTower.PrintUsage(player); }
// Parses message incoming from the player public void ParseMessage(string message, bool fromConsole) { if (DateTime.Now < mutedUntil) { return; } switch (Commands.GetMessageType(message)) { case MessageType.Chat: if (CheckChatSpam()) { return; } info.linesWritten++; string displayedName = nick; if (world.config.GetBool("ClassPrefixesInChat")) { displayedName = info.playerClass.prefix + displayedName; } if (world.config.GetBool("ClassColorsInChat") && info.playerClass.color != "" && info.playerClass.color != Color.White) { displayedName = info.playerClass.color + displayedName + Color.White; } world.SendToAll(PacketWriter.MakeMessage(displayedName + ": " + message), null); world.log.Log("{0}: {1}", LogType.Chat, name, message); break; case MessageType.Command: world.log.Log("{0}: {1}", LogType.UserCommand, name, message); world.cmd.ParseCommand(this, message, fromConsole); break; case MessageType.PrivateChat: if (CheckChatSpam()) { return; } string otherPlayerName = message.Substring(1, message.IndexOf(' ') - 1); Player otherPlayer = world.FindPlayer(otherPlayerName); if (otherPlayer != null) { world.log.Log("{0} to {1}: {2}", LogType.Chat, name, otherPlayer.name, message); otherPlayer.Send(PacketWriter.MakeMessage(Color.Gray + "from " + name + ": " + message.Substring(message.IndexOf(' ') + 1))); Send(PacketWriter.MakeMessage(Color.Gray + "to " + otherPlayer.name + ": " + message.Substring(message.IndexOf(' ') + 1))); } else { world.NoPlayerMessage(this, otherPlayerName); } break; case MessageType.ClassChat: if (CheckChatSpam()) { return; } string className = message.Substring(2, message.IndexOf(' ') - 2); PlayerClass playerClass = world.classes.FindClass(className); if (playerClass != null) { world.log.Log("{0} to {1}: {2}", LogType.ClassChat, name, playerClass.name, message); Packet classMsg = PacketWriter.MakeMessage(Color.Gray + "[" + playerClass.color + playerClass.name + Color.Gray + "]" + name + ": " + message.Substring(message.IndexOf(' ') + 1)); world.SendToClass(classMsg, playerClass); if (info.playerClass != playerClass) { Send(classMsg); } } else { Message("No such class: \"" + className.Substring(1) + "\""); } break; } }
internal static void TP( Player player, Command cmd ) { if( player.Can( Permissions.Teleport ) ) { string name = cmd.Next(); if( name == null ) { player.Send( PacketWriter.MakeTeleport( 255, player.world.map.spawn ) ); } else { Player target = player.world.FindPlayer( name ); if( target != null ) { Position pos = target.pos; pos.x += 1; pos.y += 1; pos.h += 1; player.Send( PacketWriter.MakeTeleport( 255, pos ) ); } else if( cmd.Next() == null ) { player.NoPlayerMessage( name ); } else { cmd.Rewind(); int x, y, h; if( cmd.NextInt( out x ) && cmd.NextInt( out y ) && cmd.NextInt( out h ) ) { if( x < 0 || x > player.world.map.widthX || y < 0 || y > player.world.map.widthY || y < 0 || y > player.world.map.height ) { player.Message( "Specified coordinates are outside the map!" ); } else { player.pos.Set( x * 32 + 16, y * 32 + 16, h * 32 + 16, player.pos.r, player.pos.l ); player.Send( PacketWriter.MakeTeleport( 255, player.pos ) ); } } else { player.Message( "See " + Color.Help + "/help tp" + Color.Sys + " for information on using /tp" ); } } } } else { player.NoAccessMessage( Permissions.Teleport ); } }
//hitted? jonty I thought you were better than that :( public void HitPlayer(World world, Vector3I pos, Player hitted, Player by, ref int restDistance, IList<BlockUpdate> updates) { //Capture the flag if (by.Info.isPlayingCTF) { //Friendly fire if ((hitted.Info.CTFBlueTeam && by.Info.CTFBlueTeam) || (hitted.Info.CTFRedTeam && by.Info.CTFRedTeam)) { by.Message("{0} is on your team!", hitted.Name); return; } if (hitted.Info.canDodge) { int dodgeChance = (new Random()).Next(0, 2); if (dodgeChance == 0) { by.Message("{0} dodged your attack!", hitted.Name); return; } } //Take the hit, one in ten chance of a critical hit which does 50 damage instead of 25 int critical = (new Random()).Next(0, 9); if (critical == 0) { if (by.Info.strengthened)//critical by a strengthened enemy instantly kills { hitted.Info.Health = 0; } else { hitted.Info.Health -= 50; } world.Players.Message("{0} landed a critical shot on {1}!", by.Name, hitted.Name); } else { if (by.Info.strengthened) { hitted.Info.Health -= 50; } else { hitted.Info.Health -= 25; } } //Create epic ASCII Health Bar string healthBar = "&f[&a--------&f]"; if (hitted.Info.Health == 75) { healthBar = "&f[&a------&8--&f]"; } else if (hitted.Info.Health == 50) { healthBar = "&f[&e----&8----&f]"; } else if (hitted.Info.Health == 25) { healthBar = "&f[&c--&8------&f]"; } else if(hitted.Info.Health <= 0) { healthBar = "&f[&8--------&f]"; } if (hitted.ClassiCube && Heartbeat.ClassiCube()) { hitted.Send(PacketWriter.MakeSpecialMessage((byte)1, healthBar)); } else { hitted.Message("You have " + hitted.Info.Health.ToString() + " health."); } //If the hit player's health is 0 or less, they die if (hitted.Info.Health <= 0) { hitted.KillCTF(world, String.Format("&f{0}&S was shot by &f{1}", hitted.Name, by.Name)); CTF.PowerUp(by); hitted.Info.CTFKills++; if (hitted.Info.hasRedFlag) { world.Players.Message("The red flag has been returned."); hitted.Info.hasRedFlag = false; //Put flag back BlockUpdate blockUpdate = new BlockUpdate(null, world.redFlag, Block.Red); foreach (Player p in world.Players) { p.World.Map.QueueUpdate(blockUpdate); } world.redFlagTaken = false; } if (hitted.Info.hasBlueFlag) { world.Players.Message("The blue flag has been returned."); hitted.Info.hasBlueFlag = false; //Put flag back BlockUpdate blockUpdate = new BlockUpdate(null, world.blueFlag, Block.Blue); foreach (Player p in world.Players) { p.World.Map.QueueUpdate(blockUpdate); } world.blueFlagTaken = false; } //revive dead players with 100% health hitted.Info.Health = 100; if (hitted.ClassiCube && Heartbeat.ClassiCube()) { hitted.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f[&a--------&f]")); } else { hitted.Message("You have 100 health."); } } return; } //TDM and FFA if ((hitted.Info.isOnBlueTeam && by.Info.isOnBlueTeam) || (hitted.Info.isOnRedTeam && by.Info.isOnRedTeam)) { by.Message("{0} is on your team!", hitted.ClassyName); } else { //Take the hit, one in ten chance of a critical hit which does 50 damage instead of 25 int critical = (new Random()).Next(0, 9); if (critical == 0) { hitted.Info.Health -= 50; world.Players.Message("{0} landed a critical shot on {1}!", by.Name, hitted.Name); } else { hitted.Info.Health -= 25; } if (hitted.Info.Health < 0) { hitted.Info.Health = 0; } //Create epic ASCII Health Bar string healthBar = "&f[&a--------&f]"; if (hitted.Info.Health == 75) { healthBar = "&f[&a------&8--&f]"; } else if (hitted.Info.Health == 50) { healthBar = "&f[&e----&8----&f]"; } else if (hitted.Info.Health == 25) { healthBar = "&f[&c--&8------&f]"; } else { healthBar = "&f[&8--------&f]"; } hitted.Send(PacketWriter.MakeSpecialMessage((byte)1, healthBar)); if (hitted.ClassiCube && Heartbeat.ClassiCube()) { hitted.Send(PacketWriter.MakeSpecialMessage((byte)1, healthBar)); } else { hitted.Message("You have " + hitted.Info.Health.ToString() + " health."); } if (hitted.Info.Health == 0) { hitted.Kill(world, String.Format("{0}&S was shot by {1}", hitted.ClassyName, hitted.ClassyName == by.ClassyName ? "theirself" : by.ClassyName)); updates.Add(new BlockUpdate(null, pos, Block.Air)); restDistance = 0; //TDM if (fCraft.TeamDeathMatch.isOn) { if (hitted.Info.isPlayingTD && hitted.Info.isOnBlueTeam && by.Info.isPlayingTD) //if the player is playing TD and on blue team, +1 for Red Team Score { fCraft.TeamDeathMatch.redScore++; hitted.Info.gameDeaths++; hitted.Info.totalDeathsTDM++; by.Info.gameKills++; by.Info.totalKillsTDM++; } if (hitted.Info.isPlayingTD && hitted.Info.isOnRedTeam && by.Info.isPlayingTD) //if the player is playing TD and on blue team, +1 for Red Team Score { fCraft.TeamDeathMatch.blueScore++; hitted.Info.gameDeaths++; //counts the individual players deaths hitted.Info.totalDeathsTDM++; //tallies total TDM deaths (never gets reset) by.Info.gameKills++; //counts the individual players amount of kills by.Info.totalKillsTDM++; //tallies total TDM kills } //update scoreboard for all players foreach (Player p in hitted.World.Players) { if (p.ClassiCube && Heartbeat.ClassiCube()) { p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&cRed&f: " + fCraft.TeamDeathMatch.redScore + ",&1 Blue&f: " + fCraft.TeamDeathMatch.blueScore)); } else { p.Message("The score is now &cRed&f: " + fCraft.TeamDeathMatch.redScore + ",&1 Blue&f: " + fCraft.TeamDeathMatch.blueScore); } } } //FFA if (FFA.isOn()) { if (hitted.Info.isPlayingFFA && by.Info.isPlayingFFA) //if the player is playing FFA and the person they hit is also playing { hitted.Info.gameDeathsFFA++; hitted.Info.totalDeathsFFA++; by.Info.gameKillsFFA++; by.Info.totalKillsFFA++; } //find current kill leader Player leader = new Player("");//create a temp pseudo player int kills = 0; foreach (Player p in hitted.World.Players) { if (p.Info.gameKillsFFA > kills) { kills = p.Info.gameKillsFFA; leader = p; } } foreach (Player p in hitted.World.Players) { if (p.ClassiCube && Heartbeat.ClassiCube()) { p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&eCurrent Leader&f: " + leader.Name + ", Kills: " + leader.Info.gameKillsFFA)); } } } //revive dead players with 100% health hitted.Info.Health = 100; if (hitted.ClassiCube && Heartbeat.ClassiCube()) { hitted.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f[&a--------&f]")); } else { hitted.Message("You have " + hitted.Info.Health.ToString() + "health."); } } } }
public static void RevertNames() //reverts names for online players. offline players get reverted upon leaving the game { List <PlayerInfo> TDPlayers = new List <PlayerInfo>(PlayerDB.PlayerInfoList.Where(r => (r.isOnBlueTeam || r.isOnRedTeam) && r.IsOnline).ToArray()); for (int i = 0; i < TDPlayers.Count(); i++) { string p1 = TDPlayers[i].Name.ToString(); PlayerInfo pI = PlayerDB.FindPlayerInfoExact(p1); Player p = pI.PlayerObject; if (p != null) { p.iName = null; pI.tempDisplayedName = null; pI.isOnRedTeam = false; pI.isOnBlueTeam = false; pI.isPlayingTD = false; pI.Health = 100; p.entityChanged = true; //reset all special messages if (p.usesCPE) { p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&f")); p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f")); p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&f")); } //undo gunmode (taken from GunHandler.cs) p.GunMode = false; try { foreach (Vector3I block in p.GunCache.Values) { p.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, p.WorldMap.GetBlock(block))); Vector3I removed; p.GunCache.TryRemove(block.ToString(), out removed); } if (p.bluePortal.Count > 0) { int j = 0; foreach (Vector3I block in p.bluePortal) { if (p.WorldMap != null && p.World.IsLoaded) { p.WorldMap.QueueUpdate(new BlockUpdate(null, block, p.blueOld[j])); j++; } } p.blueOld.Clear(); p.bluePortal.Clear(); } if (p.orangePortal.Count > 0) { int j = 0; foreach (Vector3I block in p.orangePortal) { if (p.WorldMap != null && p.World.IsLoaded) { p.WorldMap.QueueUpdate(new BlockUpdate(null, block, p.orangeOld[j])); j++; } } p.orangeOld.Clear(); p.orangePortal.Clear(); } } catch (Exception ex) { Logger.Log(LogType.SeriousError, "" + ex); } if (p.IsOnline) { p.Message("Your status has been reverted."); } } } }
static void WeatherHandler(Player player, CommandReader cmd) { if (cmd.Count == 1) { player.Message(Cdweather.Usage); return; } string name = cmd.Next(); PlayerInfo p = PlayerDB.FindPlayerInfoOrPrintMatches(player, name, SearchOptions.IncludeSelf); if (p == null) { return; } string valueText = cmd.Next(); byte weather; if (!byte.TryParse(valueText, out weather)) { if (valueText.Equals("sun", StringComparison.OrdinalIgnoreCase)) { weather = 0; } else if (valueText.Equals("rain", StringComparison.OrdinalIgnoreCase)) { weather = 1; } else if (valueText.Equals("snow", StringComparison.OrdinalIgnoreCase)) { weather = 2; } } if (weather < 0 || weather > 2) { player.Message("Please use a valid integer(0,1,2) or string(sun,rain,snow)"); return; } if (p != player.Info) { if (p.IsOnline) { if (p.PlayerObject.Supports(CpeExtension.EnvWeatherType)) { p.PlayerObject.Message("&a{0} set your weather to {1} ({2}&a)", player.Name, weather, weather == 0 ? "&sSun" : (weather == 1 ? "&1Rain" : "&fSnow")); player.Message("&aSet weather for {0} to {1} ({2}&a)", p.Name, weather, weather == 0 ? "&sSun" : (weather == 1 ? "&1Rain" : "&fSnow")); p.PlayerObject.Send(Packet.SetWeather((byte)weather)); } else { player.Message("That player does not support WeatherType packet"); } } else if (p.IsOnline == false || !player.CanSee(p.PlayerObject)) { player.Message("That player is not online!"); } } else { if (player.Supports(CpeExtension.EnvWeatherType)) { player.Message("&aSet weather to {0} ({1}&a)", weather, weather == 0 ? "&sSun" : (weather == 1 ? "&1Rain" : "&fSnow")); player.Send(Packet.SetWeather((byte)weather)); } else { player.Message("You don't support WeatherType packet"); } } }
public static void PrintCtfState(Player player) { if (player.IsPlayingCTF && player.Supports(CpeExtension.MessageType)) { player.Send(Packet.Message((byte)MessageType.BottomRight1, "")); string op = "&d<=>"; if (CTF.RedTeam.TotalScore > CTF.BlueTeam.TotalScore) { op = "&S-->"; } else if (CTF.RedTeam.TotalScore < CTF.BlueTeam.TotalScore) { op = "&S<--"; } player.Message((byte)MessageType.BottomRight3, "{0}{1} &a{2}{0}:&f{3} {4} {5}{6} &a{7}{5}:&f{8}", CTF.RedTeam.Color, CTF.RedTeam.Name, CTF.RedTeam.RoundsWon, CTF.RedTeam.Score, op, CTF.BlueTeam.Color, CTF.BlueTeam.Name, CTF.BlueTeam.RoundsWon, CTF.BlueTeam.Score); var flagholder = player.World.Players.Where(p => p.IsHoldingFlag); if (flagholder.FirstOrDefault() == null) { player.Send(Packet.Message((byte)MessageType.BottomRight2, "&sNo one has the flag!")); } else if (CTF.RedTeam.HasFlag) { player.Message((byte)MessageType.BottomRight2, "{0} &shas the {1}&s flag!", flagholder.First().ClassyName, CTF.BlueTeam.ClassyName); } else if (CTF.BlueTeam.HasFlag) { player.Message((byte)MessageType.BottomRight2,"{0} &shas the {1}&s flag!", flagholder.First().ClassyName, CTF.RedTeam.ClassyName); } if (player.Team != null) { player.Send(Packet.Message((byte)MessageType.Status3, "&sTeam: " + player.Team.ClassyName)); } else { player.Send(Packet.Message((byte)MessageType.Status3, "&sTeam: &0None")); } } if (player.IsPlayingCTF && player.Supports(CpeExtension.EnvColors)) { string color = null; if (CTF.RedTeam.Score > CTF.BlueTeam.Score) { color = CTF.RedTeam.EnvColor; } else if (CTF.BlueTeam.Score > CTF.RedTeam.Score) { color = CTF.BlueTeam.EnvColor; } else { color = Mix(CTF.RedTeam.EnvColor, CTF.BlueTeam.EnvColor); } player.Send(Packet.MakeEnvSetColor((byte)EnvVariable.SkyColor, color)); player.Send(Packet.MakeEnvSetColor((byte)EnvVariable.FogColor, color)); } }
static void RemovePlayerFromTeam(Player p, CtfTeam opposingTeam) { p.Team.Players.Remove(p); p.Message("&SRemoving you from the game"); if (p.IsHoldingFlag) { world.Players.Message("&cFlag holder " + p.ClassyName + " &cleft CTF, " + "thus dropping the flag for the " + p.Team.ClassyName + " team!"); p.Team.HasFlag = false; p.IsHoldingFlag = false; world.Map.QueueUpdate(new BlockUpdate(Player.Console, opposingTeam.FlagPos, opposingTeam.FlagBlock)); } p.IsPlayingCTF = false; p.Team = null; if (p.Supports(CpeExtension.HeldBlock)) p.Send(Packet.MakeHoldThis(Block.Stone, false)); }
public static void RemovePlayer(Player player, World world) { if (player.Supports(CpeExtension.MessageType)) player.Send(Packet.Message((byte)MessageType.Status3, "")); if (BlueTeam.Has(player)) RemovePlayerFromTeam(player, RedTeam); else if (RedTeam.Has(player)) RemovePlayerFromTeam(player, BlueTeam); foreach (Player p in world.Players) { if (!p.Supports(CpeExtension.ExtPlayerList) && !p.Supports(CpeExtension.ExtPlayerList2)) continue; p.Send(Packet.MakeExtRemovePlayerName(player.NameID)); } }
static void AddPlayerToTeam(CtfTeam team, Player p) { team.Players.Add(p); p.Message("&SAdding you to the " + team.ClassyName + " team"); p.TeleportTo(team.Spawn); p.Team = team; p.IsPlayingCTF = true; if (p.Supports(CpeExtension.HeldBlock)) p.Send(Packet.MakeHoldThis(Block.TNT, false)); }
static void chatHandler(Player player, CommandReader cmd) { byte type; byte.TryParse(cmd.Next(), out type); string message = cmd.NextAll(); player.Send(Packet.Message(type, message)); }
private static void textHotKeyHandler(Player player, CommandReader cmd) { string Label = cmd.Next(); string Action = cmd.Next(); string third = cmd.Next(); string fourth = cmd.Next(); if (Label == null || Action == null || third == null || fourth == null) { CdtextHotKey.PrintUsage(player); return; } int KeyCode; if (!int.TryParse(third, out KeyCode)) { player.Message("Error: Invalid Integer ({0})", third); return; } byte KeyMod = 0; if (null != fourth) { if (!Byte.TryParse(fourth, out KeyMod)) { player.Message("Error: Invalid Byte ({0})", fourth); return; } } if (player.Supports(CpeExtension.TextHotKey)) { player.Send(Packet.MakeSetTextHotKey(Label, Action, KeyCode, KeyMod)); } else { player.Message("You do not support TextHotKey"); return; } }
private static void SetPlayerDead( Player player ) { try { if ( player.IsOnline ) { player.Send( Packets.MakeTeleport( 255, new Position( player.World.Map.Spawn.X, player.World.Map.Spawn.Y, player.World.Map.Height - 1 ) ) ); StopWoMCrashBlocks( player ); player.Position = new Position( player.World.Map.Spawn.X, player.World.Map.Spawn.Y, player.World.Map.Spawn.Z + 1000 ); if ( !player.PublicAuxStateObjects.ContainsKey( "dead" ) ) { player.PublicAuxStateObjects.Add( "dead", true ); int Seconds = 6 - GuildManager.PlayersGuild( player.Info ).DeadSaver; player.Message( "You will respawn in {0} seconds", Seconds ); Scheduler.NewTask( t => SetPlayerNotDead( player ) ).RunOnce( TimeSpan.FromSeconds( Seconds ) ); } } } catch ( Exception e ) { Logger.Log( LogType.Error, e.ToString() ); } }
static void ClickDistanceHandler(Player player, CommandReader cmd) { PlayerInfo otherPlayer = InfoCommands.FindPlayerInfo(player, cmd, cmd.Next() ?? player.Name); if (otherPlayer == null) return; if (!player.IsStaff && otherPlayer != player.Info) { Rank staffRank = RankManager.GetMinRankWithAnyPermission(Permission.ReadStaffChat); if (staffRank != null) { player.Message("You must be {0}&s+ to change another players reach distance", staffRank.ClassyName); } else { player.Message("No ranks have the ReadStaffChat permission so no one can change other players reachdistance, yell at the owner."); } return; } if (otherPlayer.Rank.Index < player.Info.Rank.Index) { player.Message("Cannot change the Reach Distance of someone higher rank than you."); return; } string second = cmd.Next(); if (string.IsNullOrEmpty(second)) { if (otherPlayer == player.Info) { player.Message("Your current ReachDistance: {0} blocks [Units: {1}]", player.Info.ReachDistance / 32, player.Info.ReachDistance); } else { player.Message("Current ReachDistance for {2}: {0} blocks [Units: {1}]", otherPlayer.ReachDistance / 32, otherPlayer.ReachDistance, otherPlayer.Name); } return; } short distance; if (!short.TryParse(second, out distance)) { if (second != "reset") { player.Message("Please try something inbetween 0 and 32767"); return; } else { distance = 160; } } if (distance < 0 || distance > 32767) { player.Message("Reach distance must be between 0 and 32767"); return; } if (distance != otherPlayer.ReachDistance) { if (otherPlayer != player.Info) { if (otherPlayer.IsOnline == true) { if (otherPlayer.PlayerObject.Supports(CpeExtension.ClickDistance)) { otherPlayer.PlayerObject.Message("{0} set your reach distance from {1} to {2} blocks [Units: {3}]", player.Name, otherPlayer.ReachDistance / 32, distance / 32, distance); player.Message("Set reach distance for {0} from {1} to {2} blocks [Units: {3}]", otherPlayer.Name, otherPlayer.ReachDistance / 32, distance / 32, distance); otherPlayer.ReachDistance = distance; otherPlayer.PlayerObject.Send(Packet.MakeSetClickDistance(distance)); } else { player.Message("This player does not support ReachDistance packet"); } } else { player.Message("Set reach distance for {0} from {1} to {2} blocks [Units: {3}]", otherPlayer.Name, otherPlayer.ReachDistance / 32, distance / 32, distance); otherPlayer.ReachDistance = distance; } } else { if (player.Supports(CpeExtension.ClickDistance)) { player.Message("Set own reach distance from {0} to {1} blocks [Units: {2}]", player.Info.ReachDistance / 32, distance / 32, distance); player.Info.ReachDistance = distance; player.Send(Packet.MakeSetClickDistance(distance)); } else { player.Message("You don't support ReachDistance packet"); } } } else { if (otherPlayer != player.Info) { player.Message("{0}'s reach distance is already set to {1}", otherPlayer.ClassyName, otherPlayer.ReachDistance); } else { player.Message("Your reach distance is already set to {0}", otherPlayer.ReachDistance); } return; } }
public static void PowerUp(Player p) { int GetPowerUp = (new Random()).Next(1, 4); if (GetPowerUp < 3) { return; } int choosePowerUp = (new Random()).Next(1, 19); //decide which powerup to use, certain powerups have a higher chance such as first aid kit and dodge as opposed to rarer ones like holy blessing switch (choosePowerUp) { case 1: case 2: case 3: //first aid kit - heal user for 50 hp world_.Players.Message("&f{0} has discovered a &aFirst Aid Kit&f!", p.Name); world_.Players.Message("&f{0} has been healed for 50 hp.", p.Name); //set health to 100, make sure it doesn't overflow p.Info.Health += 50; if (p.Info.Health > 100) { p.Info.Health = 100; } string healthBar = "&f[&a--------&f]"; if (p.Info.Health == 75) { healthBar = "&f[&a------&8--&f]"; } else if (p.Info.Health == 50) { healthBar = "&f[&e----&8----&f]"; } else if (p.Info.Health == 25) { healthBar = "&f[&c--&8------&f]"; } else { healthBar = "&f[&8--------&f]"; } if (p.ClassiCube && Heartbeat.ClassiCube()) { p.Send(PacketWriter.MakeSpecialMessage((byte)1, healthBar)); } else { p.Message("You have " + p.Info.Health.ToString() + " health."); } break; case 4: case 5: //penicillin - heal user for 100 hp world_.Players.Message("&f{0} has discovered a &aPenicillin Case&f!", p.Name); world_.Players.Message("&f{0} has been healed for 100 hp.", p.Name); p.Info.Health = 100; if (p.ClassiCube && Heartbeat.ClassiCube()) { p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f[&8--------&f]")); } else { p.Message("You have " + p.Info.Health.ToString() + " health."); } break; case 6: case 7: //disarm world_.Players.Message("&f{0} has discovered a &aDisarm Spell&f!", p.Name); if (p.Info.CTFBlueTeam) { world_.Players.Message("The red team has lost all weaponry for 30 seconds!"); foreach (Player pl in world_.Players) { if (pl.Info.CTFRedTeam) { pl.Info.gunDisarmed = true; pl.Info.stabDisarmed = true; pl.GunMode = false; } } RedDisarmed = DateTime.Now; } else { world_.Players.Message("The blue team has lost all weaponry for 30 seconds!"); foreach (Player pl in world_.Players) { if (pl.Info.CTFBlueTeam) { pl.Info.gunDisarmed = true; pl.Info.stabDisarmed = true; pl.GunMode = false; } } BlueDisarmed = DateTime.Now; } break; case 8: case 9: //blades of fury world_.Players.Message("&f{0} has discovered the &aBlades of Fury&f!", p.Name); if (p.Info.CTFBlueTeam) { world_.Players.Message("The red team is unable to backstab for 1 minute!"); world_.Players.Message("The blue team can now stab the red team from any angle for 1 minute!"); foreach (Player pl in world_.Players) { if (pl.Info.CTFBlueTeam) { pl.Info.stabAnywhere = true; } else { pl.Info.stabDisarmed = true; } } RedBOFdebuff = DateTime.Now; } else { world_.Players.Message("The blue team is unable to backstab for 1 minute!"); world_.Players.Message("The red team can now stab the blue team from any angle for 1 minute!"); foreach (Player pl in world_.Players) { if (pl.Info.CTFRedTeam) { pl.Info.stabAnywhere = true; } else { pl.Info.stabDisarmed = true; } } RedBOFdebuff = DateTime.Now; } break; case 10: case 11: //war cry world_.Players.Message("&f{0} has discovered their &aWar Cry&f!", p.Name); if (p.Info.CTFBlueTeam) { world_.Players.Message("The red team has been frightened back into their spawn!"); foreach (Player pl in world_.Players) { if (pl.Info.CTFRedTeam) { pl.TeleportTo(world_.redCTFSpawn.ToPlayerCoords()); } } } else { world_.Players.Message("The blue team has been frightened back into their spawn!"); foreach (Player pl in world_.Players) { if (pl.Info.CTFBlueTeam) { pl.TeleportTo(world_.blueCTFSpawn.ToPlayerCoords()); } } } break; case 12: case 13: case 14: //strengthen world_.Players.Message("&f{0} has discovered a &aStrength Pack&f!", p.Name); world_.Players.Message("&f{0}'s gun now deals twice the damage for the next minute!", p.Name); p.Info.strengthened = true; p.Info.strengthTime = DateTime.Now; break; case 15: case 16: case 17: //dodge world_.Players.Message("&f{0} has discovered a new &aDodging Technique&f!", p.Name); world_.Players.Message("&f{0}'s has a 50% chance to dodge incomming gun attacks for the next minute!", p.Name); p.Info.canDodge = true; p.Info.dodgeTime = DateTime.Now; break; case 18: //holy blessing (rarest and most treasured power up, yet easiest to code :P ) world_.Players.Message("&f{0} has discovered the rare &aHoly Blessing&f!!!", p.Name); if (p.Info.CTFBlueTeam) { world_.Players.Message("The Blue Team has been granted 1 point."); redScore++; } else { world_.Players.Message("The Red Team has been granted 1 point."); blueScore++; } foreach (Player pl in world_.Players) { if (pl.ClassiCube && Heartbeat.ClassiCube()) { pl.Send(PacketWriter.MakeSpecialMessage((byte)2, "&cRed&f: " + redScore + ",&1 Blue&f: " + blueScore)); } else { pl.Message("The score is now &cRed&f: {0} and &1Blue&f: {1}.", redScore, blueScore); } } break; default: //no power up 4 u break; } }
// Change player class void ChangeClass(Player player, Command cmd) { string name = cmd.Next(); string newClassName = cmd.Next(); if (name == null || newClassName == null) { player.Message("Usage: " + Color.Help + "/user PlayerName ClassName"); player.Message("To see a list of classes and permissions, use " + Color.Help + "/class"); return; } Player target = world.FindPlayer(name); if (target == null) { world.NoPlayerMessage(player, name); return; } PlayerClass newClass = world.classes.FindClass(newClassName); if (newClass == null) { player.Message("Unrecognized player class: " + newClassName); return; } if (target.info.playerClass == newClass) { player.Message(target.name + "'s class is already " + newClass.color + newClass.name); return; } bool promote = target.info.playerClass.rank < newClass.rank; if ((promote && !player.Can(Permissions.Promote)) || !promote && !player.Can(Permissions.Demote)) { world.NoAccessMessage(player); return; } if (promote && !player.info.playerClass.CanPromote(newClass)) { PlayerClass maxRank = player.info.playerClass.maxPromote; if (maxRank == null) { player.Message("You can only promote players up to " + player.info.playerClass.color + player.info.playerClass.name); } else { player.Message("You can only promote players up to " + maxRank.color + maxRank.name); } return; } else if (!promote && !player.info.playerClass.CanDemote(target.info.playerClass)) { PlayerClass maxRank = player.info.playerClass.maxDemote; if (maxRank == null) { player.Message("You can only demote players that are " + player.info.playerClass.color + player.info.playerClass.name + Color.Sys + " or lower."); } else { player.Message("You can only demote players that are " + maxRank.color + maxRank.name + Color.Sys + " or lower."); } return; } if (promote && target.info.playerClass.rank < newClass.rank || target.info.playerClass.rank > newClass.rank) { world.log.Log("{0} changed the class of {1} from {2} to {3}.", LogType.UserActivity, player.name, target.info.name, target.info.playerClass.name, newClass.name); target.info.playerClass = newClass; target.info.classChangeDate = DateTime.Now; target.info.classChangedBy = player.name; target.Send(PacketWriter.MakeSetPermission(target)); if (promote) { player.Message("You promoted " + target.name + " to " + newClass.color + newClass.name + "."); target.Message("You have been promoted to " + newClass.color + newClass.name + Color.Sys + " by " + player.name + "!"); } else { player.Message("You demoted " + target.name + " to " + newClass.color + newClass.name + "."); target.Message("You have been demoted to " + newClass.color + newClass.name + Color.Sys + " by " + player.name + "!"); } if (world.config.GetBool("ClassPrefixesInList") || world.config.GetBool("ClassColorsInChat")) // TODO: colors in player names { world.UpdatePlayer(target); } target.mode = BlockPlacementMode.Normal; } else { if (promote) { player.Message(target.name + " is already same or lower rank than " + newClass.name); } else { player.Message(target.name + " is already same or higher rank than " + newClass.name); } } }
//hitted? jonty I thought you were better than that :( public void HitPlayer(World world, Vector3I pos, Player hitted, Player by, ref int restDistance, IList <BlockUpdate> updates) { //Capture the flag if (by.Info.isPlayingCTF) { //Friendly fire if ((hitted.Info.CTFBlueTeam && by.Info.CTFBlueTeam) || (hitted.Info.CTFRedTeam && by.Info.CTFRedTeam)) { by.Message("{0} is on your team!", hitted.Name); return; } if (hitted.Info.canDodge) { int dodgeChance = (new Random()).Next(0, 2); if (dodgeChance == 0) { by.Message("{0} dodged your attack!", hitted.Name); return; } } //Take the hit, one in ten chance of a critical hit which does 50 damage instead of 25 int critical = (new Random()).Next(0, 9); if (critical == 0) { if (by.Info.strengthened) //critical by a strengthened enemy instantly kills { hitted.Info.Health = 0; } else { hitted.Info.Health -= 50; } world.Players.Message("{0} landed a critical shot on {1}!", by.Name, hitted.Name); } else { if (by.Info.strengthened) { hitted.Info.Health -= 50; } else { hitted.Info.Health -= 25; } } //Create epic ASCII Health Bar string healthBar = "&f[&a--------&f]"; if (hitted.Info.Health == 75) { healthBar = "&f[&a------&8--&f]"; } else if (hitted.Info.Health == 50) { healthBar = "&f[&e----&8----&f]"; } else if (hitted.Info.Health == 25) { healthBar = "&f[&c--&8------&f]"; } else if (hitted.Info.Health <= 0) { healthBar = "&f[&8--------&f]"; } if (hitted.usesCPE) { hitted.Send(PacketWriter.MakeSpecialMessage((byte)1, healthBar)); } else { hitted.Message("You have " + hitted.Info.Health.ToString() + " health."); } //If the hit player's health is 0 or less, they die if (hitted.Info.Health <= 0) { hitted.KillCTF(world, String.Format("&f{0}&S was shot by &f{1}", hitted.Name, by.Name)); CTF.PowerUp(by); hitted.Info.CTFKills++; if (hitted.Info.hasRedFlag) { world.Players.Message("The red flag has been returned."); hitted.Info.hasRedFlag = false; //Put flag back BlockUpdate blockUpdate = new BlockUpdate(null, world.redFlag, Block.Red); foreach (Player p in world.Players) { p.World.Map.QueueUpdate(blockUpdate); } world.redFlagTaken = false; } if (hitted.Info.hasBlueFlag) { world.Players.Message("The blue flag has been returned."); hitted.Info.hasBlueFlag = false; //Put flag back BlockUpdate blockUpdate = new BlockUpdate(null, world.blueFlag, Block.Blue); foreach (Player p in world.Players) { p.World.Map.QueueUpdate(blockUpdate); } world.blueFlagTaken = false; } //revive dead players with 100% health hitted.Info.Health = 100; if (hitted.usesCPE) { hitted.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f[&a--------&f]")); } else { hitted.Message("You have 100 health."); } } return; } //TDM and FFA if ((hitted.Info.isOnBlueTeam && by.Info.isOnBlueTeam) || (hitted.Info.isOnRedTeam && by.Info.isOnRedTeam)) { by.Message("{0} is on your team!", hitted.ClassyName); } else { //Take the hit, one in ten chance of a critical hit which does 50 damage instead of 25 int critical = (new Random()).Next(0, 9); if (critical == 0) { hitted.Info.Health -= 50; world.Players.Message("{0} landed a critical shot on {1}!", by.Name, hitted.Name); } else { hitted.Info.Health -= 25; } if (hitted.Info.Health < 0) { hitted.Info.Health = 0; } //Create epic ASCII Health Bar string healthBar = "&f[&a--------&f]"; if (hitted.Info.Health == 75) { healthBar = "&f[&a------&8--&f]"; } else if (hitted.Info.Health == 50) { healthBar = "&f[&e----&8----&f]"; } else if (hitted.Info.Health == 25) { healthBar = "&f[&c--&8------&f]"; } else { healthBar = "&f[&8--------&f]"; } hitted.Send(PacketWriter.MakeSpecialMessage((byte)1, healthBar)); if (hitted.usesCPE) { hitted.Send(PacketWriter.MakeSpecialMessage((byte)1, healthBar)); } else { hitted.Message("You have " + hitted.Info.Health.ToString() + " health."); } if (hitted.Info.Health == 0) { hitted.Kill(world, String.Format("{0}&S was shot by {1}", hitted.ClassyName, hitted.ClassyName == by.ClassyName ? "theirself" : by.ClassyName)); updates.Add(new BlockUpdate(null, pos, Block.Air)); restDistance = 0; //TDM if (fCraft.TeamDeathMatch.isOn) { if (hitted.Info.isPlayingTD && hitted.Info.isOnBlueTeam && by.Info.isPlayingTD) //if the player is playing TD and on blue team, +1 for Red Team Score { fCraft.TeamDeathMatch.redScore++; hitted.Info.gameDeaths++; hitted.Info.totalDeathsTDM++; by.Info.gameKills++; by.Info.totalKillsTDM++; } if (hitted.Info.isPlayingTD && hitted.Info.isOnRedTeam && by.Info.isPlayingTD) //if the player is playing TD and on blue team, +1 for Red Team Score { fCraft.TeamDeathMatch.blueScore++; hitted.Info.gameDeaths++; //counts the individual players deaths hitted.Info.totalDeathsTDM++; //tallies total TDM deaths(never gets reset) by.Info.gameKills++; //counts the individual players amount of kills by.Info.totalKillsTDM++; //tallies total TDM kills } //update scoreboard for all players foreach (Player p in hitted.World.Players) { if (p.usesCPE) { p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&cRed&f: " + fCraft.TeamDeathMatch.redScore + ",&1 Blue&f: " + fCraft.TeamDeathMatch.blueScore)); } else { p.Message("The score is now &cRed&f: " + fCraft.TeamDeathMatch.redScore + ",&1 Blue&f: " + fCraft.TeamDeathMatch.blueScore); } } } //FFA if (FFA.isOn()) { if (hitted.Info.isPlayingFFA && by.Info.isPlayingFFA) //if the player is playing FFA and the person they hit is also playing { hitted.Info.gameDeathsFFA++; hitted.Info.totalDeathsFFA++; by.Info.gameKillsFFA++; by.Info.totalKillsFFA++; } //find current kill leader Player leader = new Player(""); //create a temp pseudo player int kills = 0; foreach (Player p in hitted.World.Players) { if (p.Info.gameKillsFFA > kills) { kills = p.Info.gameKillsFFA; leader = p; } } foreach (Player p in hitted.World.Players) { if (p.usesCPE) { p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&eCurrent Leader&f: " + leader.Name + ", Kills: " + leader.Info.gameKillsFFA)); } } } //revive dead players with 100% health hitted.Info.Health = 100; if (hitted.usesCPE) { hitted.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f[&a--------&f]")); } else { hitted.Message("You have " + hitted.Info.Health.ToString() + "health."); } } } }
public static void GunHandler(Player player, Command cmd) { //to prevent players from doing /gun during a TDM game that arent actually playing in if (player.World.gameMode == GameMode.TeamDeathMatch && !player.Info.isPlayingTD) { player.Message("Players who are not playing Team DeathMatch can only spectate."); return; } if (player.Info.isPlayingCTF && player.Info.gunDisarmed) { player.Message("You are currently disarmed. You cannot use a gun until the disarm powerup has worn off."); return; } if (player.GunMode) { player.GunMode = false; try { foreach (Vector3I block in player.GunCache.Values) { player.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, player.WorldMap.GetBlock(block))); Vector3I removed; player.GunCache.TryRemove(block.ToString(), out removed); } if (player.bluePortal.Count > 0) { int i = 0; foreach (Vector3I block in player.bluePortal) { if (player.WorldMap != null && player.World.IsLoaded) { player.WorldMap.QueueUpdate(new BlockUpdate(null, block, player.blueOld[i])); i++; } } player.blueOld.Clear(); player.bluePortal.Clear(); } if (player.orangePortal.Count > 0) { int i = 0; foreach (Vector3I block in player.orangePortal) { if (player.WorldMap != null && player.World.IsLoaded) { player.WorldMap.QueueUpdate(new BlockUpdate(null, block, player.orangeOld[i])); i++; } } player.orangeOld.Clear(); player.orangePortal.Clear(); } player.Message("&SGunMode deactivated"); } catch (Exception ex) { Logger.Log(LogType.SeriousError, "" + ex); } } else { if (!player.World.gunPhysics) { player.Message("&WGun physics are disabled on this world"); return; } player.GunMode = true; GunGlassTimer timer = new GunGlassTimer(player); timer.Start(); player.Message("&SGunMode activated. Fire at will!"); } }
internal static void SetSpawn( Player player, Command cmd ) { if( player.Can( Permissions.SetSpawn ) ) { player.world.map.spawn = player.pos; player.world.map.changesSinceSave++; player.Send( PacketWriter.MakeTeleport( 255, player.world.map.spawn ), true ); player.Message( "New spawn point saved." ); Logger.Log( "{0} changed the spawned point.", LogType.UserActivity, player.GetLogName() ); } else { player.NoAccessMessage( Permissions.SetSpawn ); } }
public static void GunHandler(Player player, Command cmd) { if (player.GunMode) { player.GunMode = false; try { foreach (Vector3I block in player.GunCache.Values) { player.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, player.WorldMap.GetBlock(block))); Vector3I removed; player.GunCache.TryRemove(block.ToString(), out removed); } if (player.bluePortal.Count > 0) { int i = 0; foreach (Vector3I block in player.bluePortal) { if (player.WorldMap != null && player.World.IsLoaded) { player.WorldMap.QueueUpdate(new BlockUpdate(null, block, player.blueOld[i])); i++; } } player.blueOld.Clear(); player.bluePortal.Clear(); } if (player.orangePortal.Count > 0) { int i = 0; foreach (Vector3I block in player.orangePortal) { if (player.WorldMap != null && player.World.IsLoaded) { player.WorldMap.QueueUpdate(new BlockUpdate(null, block, player.orangeOld[i])); i++; } } player.orangeOld.Clear(); player.orangePortal.Clear(); } player.Message("&SGunMode deactivated"); } catch (Exception ex) { Logger.Log(LogType.SeriousError, "" + ex); } } else { if (!player.World.gunPhysics) { player.Message("&WGun physics are disabled on this world"); return; } player.GunMode = true; GunGlassTimer timer = new GunGlassTimer(player); timer.Start(); player.Message("&SGunMode activated. Fire at will!"); } }
private static void StopWoMCrashBlocks( Player player ) { List<Vector3I> blocks = new List<Vector3I>(); Vector3I spawn = player.World.Map.Spawn.ToBlockCoords(); for ( int x = spawn.X - 2; x <= spawn.X + 2; x++ ) { for ( int y = spawn.Y - 2; y <= spawn.Y + 2; y++ ) { for ( int z = player.World.Map.Height - 2; z <= player.World.Map.Height - 1; z++ ) { if ( player.IsOnline ) { if ( player.World != null ) { if ( player.World.Map.GetBlock( x, y, z ) == Block.Air ) { player.Send( Packets.MakeSetBlock( x, y, z, Block.Glass ) ); blocks.Add( new Vector3I( x, y, z ) ); } } } } } } Scheduler.NewTask( t => ResetBlocks( blocks, player ) ).RunOnce( TimeSpan.FromSeconds( 6 ) ); }
public static void gunMove(Player player) { World world = player.World; if (null == world) { return; } try { lock (world.SyncRoot) { if (null == world.Map) { return; } if (player.IsOnline) { Position p = player.Position; double ksi = 2.0 * Math.PI * (-player.Position.L) / 256.0; double phi = 2.0 * Math.PI * (player.Position.R - 64) / 256.0; double sphi = Math.Sin(phi); double cphi = Math.Cos(phi); double sksi = Math.Sin(ksi); double cksi = Math.Cos(ksi); if (player.IsOnline) { if (player.GunCache.Values.Count > 0) { foreach (Vector3I block in player.GunCache.Values) { if (player.IsOnline) { player.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, world.Map.GetBlock(block))); Vector3I removed; player.GunCache.TryRemove(block.ToString(), out removed); } } } } for (int y = -1; y < 2; ++y) { for (int z = -1; z < 2; ++z) { if (player.IsOnline) { //4 is the distance betwen the player and the glass wall Vector3I glassBlockPos = new Vector3I((int)(cphi * cksi * 4 - sphi * (0.5 + y) - cphi * sksi * (0.5 + z)), (int)(sphi * cksi * 4 + cphi * (0.5 + y) - sphi * sksi * (0.5 + z)), (int)(sksi * 4 + cksi * (0.5 + z))); glassBlockPos += p.ToBlockCoords(); if (world.Map.GetBlock(glassBlockPos) == Block.Air) { player.Send(PacketWriter.MakeSetBlock(glassBlockPos, Block.Glass)); player.GunCache.TryAdd(glassBlockPos.ToString(), glassBlockPos); } } } } } } } catch (Exception ex) { Logger.Log(LogType.SeriousError, "GunGlass: " + ex); } }
public static void RevertGun() //Reverts names for online players. Offline players get reverted upon leaving the game { List <PlayerInfo> FFAPlayers = new List <PlayerInfo>(PlayerDB.PlayerInfoList.Where(r => (r.isPlayingFFA) && r.IsOnline).ToArray()); foreach (PlayerInfo pI in FFAPlayers) { Player p = pI.PlayerObject; p.JoinWorld(p.World, WorldChangeReason.Rejoin); //reset all special messages if (p.SupportsMessageTypes) { p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&f")); p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f")); p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&f")); } pI.isPlayingFFA = false; if (pI != null) { //undo gunmode (taken from GunHandler.cs) p.GunMode = false; try { foreach (Vector3I block in p.GunCache.Values) { p.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, p.WorldMap.GetBlock(block))); Vector3I removed; p.GunCache.TryRemove(block.ToString(), out removed); } if (p.bluePortal.Count > 0) { int j = 0; foreach (Vector3I block in p.bluePortal) { if (p.WorldMap != null && p.World.IsLoaded) { p.WorldMap.QueueUpdate(new BlockUpdate(null, block, p.blueOld[j])); j++; } } p.blueOld.Clear(); p.bluePortal.Clear(); } if (p.orangePortal.Count > 0) { int j = 0; foreach (Vector3I block in p.orangePortal) { if (p.WorldMap != null && p.World.IsLoaded) { p.WorldMap.QueueUpdate(new BlockUpdate(null, block, p.orangeOld[j])); j++; } } p.orangeOld.Clear(); p.orangePortal.Clear(); } } catch (Exception ex) { Logger.Log(LogType.SeriousError, "" + ex); } if (p.IsOnline) { p.Message("Your status has been reverted."); } } } }
void SetSpawn( Player player, Command cmd ) { if( player.Can( Permissions.SetSpawn ) ) { world.map.spawn = player.pos; world.map.Save(); world.map.changesSinceBackup++; player.Send( PacketWriter.MakeTeleport( 255, world.map.spawn ), true ); player.Message( "New spawn point saved." ); world.log.Log( "{0} changed the spawned point.", LogType.UserActivity, player.name ); } else { world.NoAccessMessage( player ); } }
public static void SendGlobalRemove(Player p, BlockDefinition def) { p.Send(Packet.MakeRemoveBlockDefinition(def.BlockID)); p.Send(Packet.MakeSetBlockPermission((Block)def.BlockID, false, false)); }
static void SetSpawnHandler(Player player, Command cmd) { string playerName = cmd.Next(); if (playerName == null) { player.World.Map.Spawn = player.Position; player.TeleportTo(player.World.Map.Spawn); player.Send(PacketWriter.MakeAddEntity(255, player.ListName, player.Position)); player.Message("New spawn point saved."); Logger.Log(LogType.UserActivity, "{0} changed the spawned point.", player.Name); } else if (player.Can(Permission.Bring)) { Player[] infos = player.World.FindPlayers(player, playerName); if (infos.Length == 1) { Player target = infos[0]; if (player.Can(Permission.Bring, target.Info.Rank)) { target.Send(PacketWriter.MakeAddEntity(255, target.ListName, player.Position)); } else { player.Message("You can only set spawn of players ranked {0}&S or lower.", player.Info.Rank.GetLimit(Permission.Bring).ClassyName); player.Message("{0}&S is ranked {1}", target.ClassyName, target.Info.Rank.ClassyName); } } else if (infos.Length > 0) { player.MessageManyMatches("player", infos); } else { infos = Server.FindPlayers(player, playerName, true); if (infos.Length > 0) { player.Message("You can only set spawn of players on the same world as you."); } else { player.MessageNoPlayer(playerName); } } } else { player.MessageNoAccess(CdRealm); } }
static void SetSpawnHandler( Player player, CommandReader cmd ) { World playerWorld = player.World; if( playerWorld == null ) PlayerOpException.ThrowNoWorld( player ); string playerName = cmd.Next(); if( playerName == null ) { Map map = player.WorldMap; map.Spawn = player.Position; player.TeleportTo( map.Spawn ); player.Send( Packet.MakeAddEntity( Packet.SelfID, player.ListName, player.Position ) ); player.Message( "New spawn point saved." ); Logger.Log( LogType.UserActivity, "{0} changed the spawned point.", player.Name ); } else if( player.Can( Permission.Bring ) ) { Player[] infos = playerWorld.FindPlayers( player, playerName ); if( infos.Length == 1 ) { Player target = infos[0]; player.LastUsedPlayerName = target.Name; if( player.Can( Permission.Bring, target.Info.Rank ) ) { target.Send( Packet.MakeAddEntity( Packet.SelfID, target.ListName, player.Position ) ); } else { player.Message( "You may only set spawn of players ranked {0}&S or lower.", player.Info.Rank.GetLimit( Permission.Bring ).ClassyName ); player.Message( "{0}&S is ranked {1}", target.ClassyName, target.Info.Rank.ClassyName ); } } else if( infos.Length > 0 ) { player.MessageManyMatches( "player", infos ); } else { infos = Server.FindPlayers( player, playerName, true, false, true ); if( infos.Length > 0 ) { player.Message( "You may only set spawn of players on the same world as you." ); } else { player.MessageNoPlayer( playerName ); } } } else { player.MessageNoAccess( CdSetSpawn ); } }
private static void ResetBlocks( List<Vector3I> Blocks, Player player ) { foreach ( Vector3I b in Blocks ) { if ( player.IsOnline ) { player.Send( Packets.MakeSetBlock( b, Block.Air ) ); } } }