protected FlagInstance CreateFlag(FlagUpdateData data) { FlagInstance inst = new FlagInstance(); inst.ID = data.FlagID; inst.Flag = FlagTypeList.GetFromAbriv(data.Abreviation); WorldFlags.Add(inst); return(inst); }
protected FlagInstance GetFlag(FlagUpdateData data) { FlagInstance inst = FindFlagByID(data.FlagID); if (inst != null) { return(inst); } inst = new FlagInstance(); inst.ID = data.FlagID; inst.Flag = FlagTypeList.GetFromAbriv(data.Abreviation); WorldFlags.Add(inst); return(inst); }
public void HandleKilled(NetworkMessage msg) { MsgKilled killed = msg as MsgKilled; KilledEventArgs args = new KilledEventArgs(); args.Victim = GetPlayerByID(killed.VictimID); args.Killer = GetPlayerByID(killed.KillerID); args.Reason = killed.Reason; args.KilledByFlag = FlagTypeList.GetFromAbriv(killed.FlagAbreviation); if (killed.Reason == BlowedUpReasons.DeathTouch) { args.InstrumentID = killed.PhysicsDriverID; } else { args.InstrumentID = killed.ShotID; if (killed.ShotID > 0) { // kill shot int bzfsShotID = (killed.KillerID * byte.MaxValue) + killed.ShotID; // tell the shot manager to kill that thar shot } } if (args.Victim != null) { args.Victim.SetTeleport(-1, null, null); args.Victim.Active = false; args.Victim.IsRabbit = false; } if (PlayerKilled != null) { PlayerKilled.Invoke(this, args); } }
protected void BuildRandomFlags(FlagManager manager, ServerConfig.FlagInfo flagInfo) { if (!flagInfo.SpawnRandomFlags) { return; } SpawnableFlags.Clear(); if (flagInfo.RandomFlags.UseGoodFlags) { SpawnableFlags.AddRange(FlagTypeList.GoodFlags); } if (flagInfo.RandomFlags.UseBadFlags) { SpawnableFlags.AddRange(FlagTypeList.BadFlags); if (flagInfo.AllowGeno) { SpawnableFlags.Add(FlagTypeList.Genocide); } } foreach (var f in flagInfo.RandomFlags.UseFlags) { FlagType t = FlagTypeList.GetFromAbriv(f); if (t != null && !SpawnableFlags.Contains(t)) { SpawnableFlags.Add(t); } } foreach (var f in flagInfo.RandomFlags.IgnoreFlags) { FlagType t = FlagTypeList.GetFromAbriv(f); if (t != null && SpawnableFlags.Contains(t)) { SpawnableFlags.Remove(t); } } DesiredFlagCount = 0; if (SpawnableFlags.Count == 0) { return; } // randomize the flag list int count = SpawnableFlags.Count; List <FlagType> randoFlags = new List <FlagType>(); for (int i = 0; i < count; i++) { FlagType t = SpawnableFlags[State.World.RNG.Next(SpawnableFlags.Count)]; SpawnableFlags.Remove(t); randoFlags.Add(t); } SpawnableFlags = randoFlags; // see how many random flags we need to spawn this time DesiredFlagCount = GetRandomFlagCount(); if (DesiredFlagCount > 0) { Logger.Log2("Spawning " + DesiredFlagCount.ToString() + " flags from pool " + String.Join <FlagType>(" ", SpawnableFlags.ToArray())); } for (int i = 0; i < DesiredFlagCount; i++) { FlagType ft = null; if (DesiredFlagCount < SpawnableFlags.Count) { ft = SpawnableFlags[i]; // no dupes } else { ft = GetRandomFlag(); } if (FlagValidForGameType(ft)) { manager.InitFlag(ft); } } }
public void KillPlayer(ServerPlayer player, KilledEventArgs args) { if (args == null || player == null) { return; } if (!player.Info.Alive) { Logger.Log0("Player " + player.Callsign + " killed while dead"); } player.Info.Alive = false; PlayerKilled?.Invoke(this, args); Logger.Log4("Player " + player.Callsign + " killed by " + args.KillInfo.Reason.ToString()); bool wasFromAFlag = false; switch (args.KillInfo.Reason) { case BlowedUpReasons.GotKilledMsg: break; case BlowedUpReasons.GotShot: wasFromAFlag = true; Shots.RemoveShotForDeath(player, args.KillInfo.KillerID, args.KillInfo.ShotID); if (args.Shot != null) // tell the flag it took a hit { Flags.HandlePlayerTakeHit(player, args.Killer, args.Shot); } break; case BlowedUpReasons.GotRunOver: wasFromAFlag = true; break; case BlowedUpReasons.GotCaptured: break; case BlowedUpReasons.GenocideEffect: break; case BlowedUpReasons.SelfDestruct: break; case BlowedUpReasons.WaterDeath: break; case BlowedUpReasons.DeathTouch: break; case BlowedUpReasons.LastReason: case BlowedUpReasons.Unknown: Logger.Log0("Player " + player.Callsign + " killed by a method that should not happen"); break; } if (wasFromAFlag) // tell the flag it killed { Flags.HandlePlayerDoDamage(player, args.Killer, FlagTypeList.GetFromAbriv(args.KillInfo.FlagAbreviation)); } // process any scores PlayerInfo.ScoreInfo vicScores = new PlayerInfo.ScoreInfo(); PlayerInfo.ScoreInfo killerScores = new PlayerInfo.ScoreInfo(); if (ComputeScores(args.Victim, ref vicScores, args.Killer, ref killerScores, args.KillInfo.Reason)) { args.Victim.Info.Score.ApplyScore(vicScores); if (args.Killer != null) { args.Killer.Info.Score.ApplyScore(killerScores); } MsgScore scoreMessage = new MsgScore(); if (!vicScores.Empty) { Logger.Log3("Player " + player.Callsign + " score updated by " + vicScores.ToString()); ScoreUpdated?.Invoke(this, args.Victim); args.Victim.Info.Score.Pack(args.Victim.PlayerID, scoreMessage); } if (args.Killer != null && !killerScores.Empty) { Logger.Log3("Player " + player.Callsign + " score updated by " + killerScores.ToString()); ScoreUpdated?.Invoke(this, args.Killer); args.Killer.Info.Score.Pack(args.Killer.PlayerID, scoreMessage); } if (scoreMessage.Scores.Count > 0) { SendToAll(scoreMessage, false); } } MsgKilled killedMessage = new MsgKilled(); killedMessage.VictimID = args.Victim.PlayerID; killedMessage.KillerID = args.Killer != null ? args.Killer.PlayerID : PlayerConstants.ServerPlayerID; killedMessage.ShotID = args.Shot != null ? args.Shot.PlayerShotID : -1; killedMessage.Reason = args.KillInfo.Reason; killedMessage.FlagAbreviation = (args.Shot != null && args.Shot.SourceFlag != null) ? args.Shot.SourceFlag.FlagAbbv : string.Empty; killedMessage.PhysicsDriverID = args.KillInfo.PhysicsDriverID; SendToAll(killedMessage, false); }