コード例 #1
0
        private static bool Prefix(MpTeam team, ref LevelData.SpawnPoint __result)
        {
            // Check mode, bail if not Anarchy or Team Anarchy.
            var mode = NetworkMatch.GetMode();

            if (mode != MatchMode.ANARCHY && mode != MatchMode.TEAM_ANARCHY)
            {
                return(true);
            }

            var respawnPointCandidates = GetRespawnPointCandidates(team);

            if (respawnPointCandidates.Count == 0)
            {
                __result = (LevelData.SpawnPoint)_NetworkSpawnPoints_GetRandomRespawnPointWithoutFiltering_Method.Invoke(null, new object[] { });
            }
            else if (NetworkManager.m_Players.Count == 0)
            {
                __result = respawnPointCandidates[UnityEngine.Random.Range(0, respawnPointCandidates.Count)];
            }
            else
            {
                var scores = GetRespawnPointScores(team, respawnPointCandidates, true);
                __result = scores.OrderByDescending(s => s.Value).First().Key;
            }

            lastRespawn[__result] = DateTime.Now;
            return(false);
        }
コード例 #2
0
 public static object Serialize_SpawnPoint(object _obj, System.Type type, OverloadLevelConvertSerializer serializer)
 {
     LevelData.SpawnPoint obj = (LevelData.SpawnPoint)_obj;
     serializer.SerializeX(obj, x => x.position);
     serializer.SerializeX(obj, x => x.orientation);
     serializer.SerializeX(obj, x => x.m_current_segment);
     serializer.SerializeX(obj, x => x.multiplayer_team_association_mask);
     return(obj);
 }
コード例 #3
0
        public static float GetRespawnPointScore(MpTeam team, LevelData.SpawnPoint spawnPoint, List <float> distances, float max)
        {
            var playerPositions = (List <Vector3>)_NetworkSpawnPoints_m_player_pos_Field.GetValue(null);
            var playerTeams     = (List <MpTeam>)_NetworkSpawnPoints_m_player_team_Field.GetValue(null);

            var count = playerPositions.Count;

            // For each spawn, find the closest player, and the two players that have the least line of sight to one or the other.
            var closest         = float.MaxValue;
            var leastLoS        = float.MaxValue;
            var scale           = 1f;
            var seesEnemy       = false;
            var seesTeammate    = false;
            var closestTeammate = float.MaxValue;

            for (int i = 0; i < count; i++)
            {
                var dist = Math.Abs(distances[i]);

                Vector3 vector;
                vector.x = playerPositions[i].x - spawnPoint.position.x;
                vector.y = playerPositions[i].y - spawnPoint.position.y;
                vector.z = playerPositions[i].z - spawnPoint.position.z;
                var vectorDist = Mathf.Max(0.1f, vector.magnitude);
                vector.x /= vectorDist;
                vector.y /= vectorDist;
                vector.z /= vectorDist;

                if (team != playerTeams[i] || NetworkMatch.GetMode() == MatchMode.ANARCHY)
                {
                    closest = Math.Min(closest, dist);

                    if (VisibilityRaycast(spawnPoint.position, vector, vectorDist))
                    {
                        var angle = Math.Min(Vector3.Angle(playerPositions[i] - spawnPoint.position, spawnPoint.orientation * Vector3.forward), Vector3.Angle(spawnPoint.position - playerPositions[i], m_player_rot[i] * Vector3.forward));
                        leastLoS  = Math.Min(leastLoS, angle);
                        seesEnemy = true;
                    }
                }
                else
                {
                    if (dist <= 30f && VisibilityRaycast(spawnPoint.position, vector, vectorDist))
                    {
                        seesTeammate    = true;
                        closestTeammate = Math.Min(dist, closestTeammate);
                    }
                }

                if (dist < 15f)
                {
                    scale = (float)Math.Pow(Math.Min(scale, dist / 15f), 2);
                }
            }

            if (closest > 80f)
            {
                scale *= 80f / closest;
            }

            // Score the spawn point.
            var score = Math.Min(closest / Math.Max(max, 1f), 1f) * Math.Min(leastLoS / 60f, 1f) * scale;

            // Avoid respawning two ships on the same respawn point within a short amount of time.
            if (lastRespawn.ContainsKey(spawnPoint) && lastRespawn[spawnPoint] > DateTime.Now.AddSeconds(-2))
            {
                score -= (float)(lastRespawn[spawnPoint] - DateTime.Now.AddSeconds(-2)).TotalSeconds;
            }
            else if (NetworkMatch.GetMode() == MatchMode.TEAM_ANARCHY)
            {
                // If the spawn point is not being avoided, give a bonus in team anarchy if the spawn point sees teammates and no enemies and doesn't have a teammate on the spawn point and no enemy is within 8 cubes.
                if (seesTeammate && !seesEnemy && closestTeammate > 5f && closest > 32f)
                {
                    score += 0.5f * scale;
                }
            }

            return(score);
        }
コード例 #4
0
 public ItemSpawnPoint(int ix, Quaternion orientation)
 {
     index                  = ix;
     spawnPoint             = GameManager.m_level_data.m_item_spawn_points[ix];
     spawnPoint.orientation = orientation;
 }