void HandlePlayerCommand(Player p, string cmd, string args) { if (!Game.started || p.level != Game.Map || cmd != "teamchat") { return; } CtfData data = Game.Get(p); if (data == null) { return; } if (data.TeamChatting) { Player.Message(data.p, "You are no longer chatting with your team!"); } else { Player.Message(data.p, "You are now chatting with your team!"); } data.TeamChatting = !data.TeamChatting; p.cancelcommand = true; }
/// <summary> Called when the given player, while holding opposing team's flag, clicks on their own flag. </summary> void ReturnFlag(Player p, CtfTeam team) { Vec3U16 flagPos = team.FlagPos; p.RevertBlock(flagPos.X, flagPos.Y, flagPos.Z); CtfData data = Get(p); if (data.HasFlag) { Map.Message(team.Color + p.DisplayName + " RETURNED THE FLAG!"); data.HasFlag = false; ResetPlayerFlag(p, data); data.Points += cfg.Capture_PointsGained; data.Captures++; team.Captures++; CtfTeam opposing = Opposing(team); opposing.RespawnFlag(Map); } else { p.Message("You cannot take your own flag!"); } }
/// <summary> Called when the given player, while holding opposing team's flag, clicks on their own flag. </summary> public void ReturnFlag(Player p, CtfTeam2 team) { Vec3U16 flagPos = team.FlagPos; p.RevertBlock(flagPos.X, flagPos.Y, flagPos.Z); p.cancelBlock = true; CtfData data = Get(p); if (data.hasflag) { Chat.MessageLevel(Map, team.Color + p.DisplayName + " RETURNED THE FLAG!"); data.hasflag = false; data.Points += Config.Capture_PointsGained; data.Captures++; CtfTeam2 opposing = Opposing(team); team.Points++; flagPos = opposing.FlagPos; Map.Blockchange(flagPos.X, flagPos.Y, flagPos.Z, opposing.FlagBlock); if (team.Points >= Config.RoundPoints) { EndRound(); } } else { Player.Message(p, "You cannot take your own flag!"); } }
void ResetPlayerFlag(Player p, CtfData data) { Vec3S32 last = data.LastHeadPos; ushort x = (ushort)last.X, y = (ushort)last.Y, z = (ushort)last.Z; data.LastHeadPos = default(Vec3S32); Map.BroadcastRevert(x, y, z); }
void Tick() { int dist = (int)(Config.TagDistance * 32); Player[] online = PlayerInfo.Online.Items; foreach (Player p in online) { if (p.level != Map) { continue; } CtfTeam team = TeamOf(p); CtfData data = Get(p); // Draw flag above player head if (data.HasFlag) { DrawPlayerFlag(p, data); } if (team == null || data.TagCooldown) { continue; } if (!OnOwnTeamSide(p.Pos.BlockZ, team)) { continue; } CtfTeam opposing = Opposing(team); Player[] opponents = opposing.Members.Items; foreach (Player other in opponents) { if (!InRange(p, other, dist)) { continue; } CtfData otherData = Get(other); otherData.TagCooldown = true; other.Message(p.ColoredName + " &Stagged you!"); PlayerActions.Respawn(other); Thread.Sleep(300); // TODO: get rid of this if (otherData.HasFlag) { DropFlag(p, opposing); } data.Points += cfg.Tag_PointsGained; otherData.Points -= cfg.Tag_PointsLost; data.Tags++; otherData.TagCooldown = false; } } }
/// <summary> Called when the given player takes the opposing team's flag. </summary> void TakeFlag(Player p, CtfTeam team) { CtfTeam opposing = Opposing(team); Map.Message(team.Color + p.DisplayName + " took the " + opposing.ColoredName + " &Steam's FLAG"); CtfData data = Get(p); data.HasFlag = true; DrawPlayerFlag(p, data); }
void ResetPlayerFlag(Player p, CtfData data) { Vec3S32 last = data.LastHeadPos; ushort x = (ushort)last.X, y = (ushort)last.Y, z = (ushort)last.Z; data.LastHeadPos = default(Vec3S32); BlockID origBlock = Map.GetBlock(x, y, z); if (origBlock != Block.Invalid) { Player.GlobalBlockchange(Map, x, y, z, origBlock); } }
void DrawPlayerFlag(Player p, CtfData data) { Vec3S32 coords = p.Pos.BlockCoords; coords.Y += 3; if (coords == data.LastHeadPos) { return; } ResetPlayerFlag(p, data); data.LastHeadPos = coords; ushort x = (ushort)coords.X, y = (ushort)coords.Y, z = (ushort)coords.Z; CtfTeam opposing = Opposing(TeamOf(p)); Map.BroadcastChange(x, y, z, opposing.FlagBlock); }
static CtfData Get(Player p) { CtfData data = TryGet(p); if (data != null) { return(data); } data = new CtfData(); // TODO: Is this even thread-safe CtfStats s = LoadStats(p.name); data.Captures = s.Captures; data.Points = s.Points; data.Tags = s.Tags; p.Extras[ctfExtrasKey] = data; return(data); }
/// <summary> Called when the given player drops the opposing team's flag. </summary> public void DropFlag(Player p, CtfTeam2 team) { CtfData data = Get(p); if (!data.hasflag) { return; } data.hasflag = false; Chat.MessageLevel(Map, team.Color + p.DisplayName + " DROPPED THE FLAG!"); data.Points -= Config.Capture_PointsLost; CtfTeam2 opposing = Opposing(team); Vec3U16 pos = opposing.FlagPos; Map.Blockchange(pos.X, pos.Y, pos.Z, opposing.FlagBlock); }
/// <summary> Called when the given player drops the opposing team's flag. </summary> void DropFlag(Player p, CtfTeam team) { CtfData data = Get(p); if (!data.HasFlag) { return; } data.HasFlag = false; ResetPlayerFlag(p, data); Map.Message(team.Color + p.DisplayName + " DROPPED THE FLAG!"); data.Points -= cfg.Capture_PointsLost; CtfTeam opposing = Opposing(team); opposing.RespawnFlag(Map); }
void HandlePlayerCommand(Player p, string cmd, string args, CommandData data) { if (p.level != Map || cmd != "teamchat") { return; } CtfData data_ = Get(p); if (data_.TeamChatting) { p.Message("You are no longer chatting with your team!"); } else { p.Message("You are now chatting with your team!"); } data_.TeamChatting = !data_.TeamChatting; p.cancelcommand = true; }
protected override void SaveStats(Player p) { CtfData data = TryGet(p); if (data == null || data.Points == 0 && data.Captures == 0 && data.Tags == 0) { return; } int count = Database.CountRows("CTF", "WHERE Name=@0", p.name); if (count == 0) { Database.AddRow("CTF", "Points, Captures, tags, Name", data.Points, data.Captures, data.Tags, p.name); } else { Database.UpdateRows("CTF", "Points=@0, Captures=@1, tags=@2", "WHERE Name=@3", data.Points, data.Captures, data.Tags, p.name); } }
void ResetFlagsState() { Blue.RespawnFlag(Map); Red.RespawnFlag(Map); Player[] players = PlayerInfo.Online.Items; foreach (Player p in players) { if (p.level != Map) { continue; } CtfData data = Get(p); if (!data.HasFlag) { continue; } data.HasFlag = false; ResetPlayerFlag(p, data); } }