public static void OnRoundEnded(GameSession gameSession)
        {
            //made it to the destination
            if (gameSession?.Submarine != null && Level.Loaded != null && gameSession.Submarine.AtEndPosition)
            {
                float levelLengthMeters     = Physics.DisplayToRealWorldRatio * Level.Loaded.Size.X;
                float levelLengthKilometers = levelLengthMeters / 1000.0f;
                //in multiplayer the client's/host's character must be inside the sub (or end outpost) and alive
                if (GameMain.NetworkMember != null)
                {
#if CLIENT
                    Character myCharacter = Character.Controlled;
                    if (myCharacter != null &&
                        !myCharacter.IsDead &&
                        (myCharacter.Submarine == gameSession.Submarine || (Level.Loaded?.EndOutpost != null && myCharacter.Submarine == Level.Loaded.EndOutpost)))
                    {
                        SteamManager.IncrementStat("kmstraveled", levelLengthKilometers);
                    }
#endif
                }
                else
                {
                    //in sp making it to the end is enough
                    SteamManager.IncrementStat("kmstraveled", levelLengthKilometers);
                }
            }

            if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient)
            {
                return;
            }

            if (gameSession.Mission != null)
            {
                if (gameSession.Mission is CombatMission combatMission && GameMain.GameSession.WinningTeam.HasValue)
                {
                    //all characters that are alive and in the winning team get an achievement
                    UnlockAchievement(gameSession.Mission.Prefab.AchievementIdentifier + (int)GameMain.GameSession.WinningTeam, true,
                                      c => c != null && !c.IsDead && !c.IsUnconscious && combatMission.IsInWinningTeam(c));
                }
                else if (gameSession.Mission.Completed)
                {
                    //all characters get an achievement
                    if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
                    {
                        UnlockAchievement(gameSession.Mission.Prefab.AchievementIdentifier, true, c => c != null);
                    }
                    else
                    {
                        UnlockAchievement(gameSession.Mission.Prefab.AchievementIdentifier);
                    }
                }
            }
Ejemplo n.º 2
0
        public static void OnRoundEnded(GameSession gameSession)
        {
            //made it to the destination
            if (gameSession.Submarine.AtEndPosition && Level.Loaded != null)
            {
                float levelLengthMeters     = Physics.DisplayToRealWorldRatio * Level.Loaded.Size.X;
                float levelLengthKilometers = levelLengthMeters / 1000.0f;
                //in multiplayer the client's/host's character must be inside the sub (or end outpost) and alive
                if (GameMain.NetworkMember != null)
                {
#if CLIENT
                    Character myCharacter = Character.Controlled;
                    if (myCharacter != null &&
                        !myCharacter.IsDead &&
                        (myCharacter.Submarine == gameSession.Submarine || (Level.Loaded?.EndOutpost != null && myCharacter.Submarine == Level.Loaded.EndOutpost)))
                    {
                        SteamManager.IncrementStat("kmstraveled", levelLengthKilometers);
                    }
#endif
                }
                else
                {
                    //in sp making it to the end is enough
                    SteamManager.IncrementStat("kmstraveled", levelLengthKilometers);
                }
            }

#if CLIENT
            if (GameMain.Client != null)
            {
                return;
            }
#endif

            if (gameSession.Mission != null)
            {
                if (gameSession.Mission is CombatMission combatMission)
                {
                    //all characters that are alive and in the winning team get an achievement
                    UnlockAchievement(gameSession.Mission.Prefab.AchievementIdentifier + (int)GameMain.GameSession.WinningTeam, true,
                                      c => c != null && !c.IsDead && !c.IsUnconscious && combatMission.IsInWinningTeam(c));
                }
                else if (gameSession.Mission.Completed)
                {
                    //all characters get an achievement
                    if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
                    {
                        UnlockAchievement(gameSession.Mission.Prefab.AchievementIdentifier, true, c => c != null);
                    }
                    else
                    {
                        UnlockAchievement(gameSession.Mission.Prefab.AchievementIdentifier);
                    }
                }
            }

            //made it to the destination
            if (gameSession.Submarine.AtEndPosition)
            {
                bool noDamageRun = !roundData.SubWasDamaged && !roundData.Casualties.Any(c => !(c.AIController is EnemyAIController));

#if SERVER
                if (GameMain.Server != null)
                {
                    //in MP all characters that were inside the sub during reactor meltdown and still alive at the end of the round get an achievement
                    UnlockAchievement("survivereactormeltdown", true, c => c != null && !c.IsDead && roundData.ReactorMeltdown.Contains(c));
                    if (noDamageRun)
                    {
                        UnlockAchievement("nodamagerun", true, c => c != null && !c.IsDead);
                    }
                }
#endif
#if CLIENT
                if (noDamageRun)
                {
                    UnlockAchievement("nodamagerun");
                }
                if (roundData.ReactorMeltdown.Any()) //in SP getting to the destination after a meltdown is enough
                {
                    UnlockAchievement("survivereactormeltdown");
                }
#endif
                var charactersInSub = Character.CharacterList.FindAll(c =>
                                                                      !c.IsDead &&
                                                                      c.TeamID != Character.TeamType.FriendlyNPC &&
                                                                      !(c.AIController is EnemyAIController) &&
                                                                      (c.Submarine == gameSession.Submarine || (Level.Loaded?.EndOutpost != null && c.Submarine == Level.Loaded.EndOutpost)));

                if (charactersInSub.Count == 1)
                {
                    //there must be some non-enemy casualties to get the last mant standing achievement
                    if (roundData.Casualties.Any(c => !(c.AIController is EnemyAIController)))
                    {
                        UnlockAchievement(charactersInSub[0], "lastmanstanding");
                    }
                    //lone sailor achievement if alone in the sub and there are no other characters with the same team ID
                    else if (!Character.CharacterList.Any(c =>
                                                          c != charactersInSub[0] &&
                                                          c.TeamID == charactersInSub[0].TeamID &&
                                                          !(c.AIController is EnemyAIController)))
                    {
                        UnlockAchievement(charactersInSub[0], "lonesailor");
                    }
                }
                foreach (Character character in charactersInSub)
                {
                    if (character.Info.Job == null)
                    {
                        continue;
                    }
                    UnlockAchievement(character, character.Info.Job.Prefab.Identifier + "round");
                }
            }
        }
Ejemplo n.º 3
0
        public static void OnCharacterKilled(Character character, CauseOfDeath causeOfDeath)
        {
#if CLIENT
            if (GameMain.Client != null || GameMain.GameSession == null)
            {
                return;
            }
#endif

            if (character != Character.Controlled &&
                causeOfDeath.Killer != null &&
                causeOfDeath.Killer == Character.Controlled)
            {
                SteamManager.IncrementStat(
                    character.SpeciesName.ToLowerInvariant() == "human" ? "humanskilled" : "monsterskilled",
                    1);
            }

            roundData.Casualties.Add(character);

            UnlockAchievement(causeOfDeath.Killer, "kill" + character.SpeciesName);
            if (character.CurrentHull != null)
            {
                UnlockAchievement(causeOfDeath.Killer, "kill" + character.SpeciesName + "indoors");
            }

            if (character.HasEquippedItem("clownmask") &&
                character.HasEquippedItem("clowncostume") &&
                causeOfDeath.Killer != character)
            {
                UnlockAchievement(causeOfDeath.Killer, "killclown");
            }

            if (causeOfDeath.DamageSource is Item item)
            {
                switch (item.Prefab.Identifier)
                {
                case "weldingtool":
                case "plasmacutter":
                case "wrench":
                    UnlockAchievement(causeOfDeath.Killer, "killtool");
                    break;

                case "morbusine":
                    UnlockAchievement(causeOfDeath.Killer, "killpoison");
                    break;

                case "nuclearshell":
                case "nucleardepthcharge":
                    UnlockAchievement(causeOfDeath.Killer, "killnuke");
                    break;
                }
            }

#if SERVER
            if (GameMain.Server?.TraitorManager != null)
            {
                foreach (Traitor traitor in GameMain.Server.TraitorManager.TraitorList)
                {
                    if (traitor.TargetCharacter == character)
                    {
                        //killed the target as a traitor
                        UnlockAchievement(traitor.Character, "traitorwin");
                    }
                    else if (traitor.Character == character)
                    {
                        //someone killed a traitor
                        UnlockAchievement(causeOfDeath.Killer, "killtraitor");
                    }
                }
            }
#endif
        }
Ejemplo n.º 4
0
        public static void OnCharacterKilled(Character character, CauseOfDeath causeOfDeath)
        {
#if CLIENT
            if (GameMain.Client != null || GameMain.GameSession == null)
            {
                return;
            }
#endif

            if (character != Character.Controlled &&
                causeOfDeath.Killer != null &&
                causeOfDeath.Killer == Character.Controlled)
            {
                SteamManager.IncrementStat(
                    character.IsHuman ? "humanskilled" : "monsterskilled",
                    1);
            }

            roundData?.Casualties.Add(character);

            UnlockAchievement(causeOfDeath.Killer, "kill" + character.SpeciesName);
            if (character.CurrentHull != null)
            {
                UnlockAchievement(causeOfDeath.Killer, "kill" + character.SpeciesName + "indoors");
            }
            if (character.SpeciesName.EndsWith("boss"))
            {
                UnlockAchievement(causeOfDeath.Killer, "kill" + character.SpeciesName.Replace("boss", ""));
                if (character.CurrentHull != null)
                {
                    UnlockAchievement(causeOfDeath.Killer, "kill" + character.SpeciesName.Replace("boss", "") + "indoors");
                }
            }
            if (character.SpeciesName.EndsWith("_m"))
            {
                UnlockAchievement(causeOfDeath.Killer, "kill" + character.SpeciesName.Replace("_m", ""));
                if (character.CurrentHull != null)
                {
                    UnlockAchievement(causeOfDeath.Killer, "kill" + character.SpeciesName.Replace("_m", "") + "indoors");
                }
            }

            if (character.HasEquippedItem("clownmask") &&
                character.HasEquippedItem("clowncostume") &&
                causeOfDeath.Killer != character)
            {
                UnlockAchievement(causeOfDeath.Killer, "killclown");
            }

            if (character.CharacterHealth?.GetAffliction("morbusinepoisoning") != null)
            {
                UnlockAchievement(causeOfDeath.Killer, "killpoison");
            }

            if (causeOfDeath.DamageSource is Item item)
            {
                if (item.HasTag("tool"))
                {
                    UnlockAchievement(causeOfDeath.Killer, "killtool");
                }
                else
                {
                    switch (item.Prefab.Identifier)
                    {
                    case "morbusine":
                        UnlockAchievement(causeOfDeath.Killer, "killpoison");
                        break;

                    case "nuclearshell":
                    case "nucleardepthcharge":
                        UnlockAchievement(causeOfDeath.Killer, "killnuke");
                        break;
                    }
                }
            }

#if SERVER
            if (GameMain.Server?.TraitorManager != null)
            {
                if (GameMain.Server.TraitorManager.IsTraitor(character))
                {
                    UnlockAchievement(causeOfDeath.Killer, "killtraitor");
                }
            }
#endif
        }