Example #1
0
        internal static void PlayerDisconnected(ClientInfo player, bool arg2)
        {
            string pId = player.playerId;

            string teamId = TeamMaker.GetPlayerTeam(pId).id;

            if (teamId != null)
            {
                VariableContainer.SetPlayerState(pId, ModState.RECONNECTING_TO_GAME);
                VariableContainer.SetPlayerLastTeam(pId, teamId);
                TeamMaker.RemovePlayerAfterDisconnect(player.playerId, teamId);
            }
            else
            {
                VariableContainer.SetPlayerState(pId, ModState.RECONNECTING_TO_LOBBY);
            }
        }
Example #2
0
        private static void HandleDiedInGame(ClientInfo player)
        {
            Map  map  = VariableContainer.GetMap(VariableContainer.selectedMap);
            Team team = TeamMaker.GetPlayerTeam(player.playerId);

            if (!VariableContainer.TeamDeaths.ContainsKey(team.id))
            {
                VariableContainer.TeamDeaths.Add(team.id, 0);
            }

            VariableContainer.TeamDeaths[team.id]++;

            foreach (Team.Member member in team.members)
            {
                member.ClientInfo().SendPackage(NetPackageManager.GetPackage <NetPackageChat>().Setup(EChatType.Whisper, member.entityId, "[FF3333]" + team.id + " Deaths to loose: " + (DEATHS_TO_LOOSE - VariableContainer.TeamDeaths[team.id]), null, false, null));
            }

            if (VariableContainer.TeamDeaths[team.id] < DEATHS_TO_LOOSE)
            {
                return;
            }

            VariableContainer.selectedMap = "none";
            refubrishedCords.Clear();
            VariableContainer.FreeMapSpawns();

            string msg = string.Format("[FFAAAA]Team of {0} [FFAAAA]has failed miserable.", team.GetMembers());

            foreach (ClientInfo pcli in ConnectionManager.Instance.Clients.List)
            {
                if (pcli == null)
                {
                    continue;
                }

                string pId = pcli.playerId;
                VariableContainer.SetPlayerState(pId, ModState.IN_LOBBY);
                pcli.SendPackage(NetPackageManager.GetPackage <NetPackageTeleportPlayer>().Setup(VariableContainer.GetLobbyPosition(), null, false));
                pcli.SendPackage(NetPackageManager.GetPackage <NetPackageChat>().Setup(EChatType.Whisper, pcli.entityId, msg, null, false, null));
            }

            TeamMaker.CleanUp();
        }
Example #3
0
        internal static void PlayerSpawnedInWorld(ClientInfo player, RespawnType respawnReason, Vector3i _pos)
        {
            string   pId         = player.playerId;
            ModState playerState = VariableContainer.GetPlayerState(pId);
            World    world       = GameManager.Instance.World;

            if (respawnReason.Equals(RespawnType.Died))
            {
                if (playerState.Equals(ModState.RECONNECTING_TO_GAME) || playerState.Equals(ModState.IN_GAME) || playerState.Equals(ModState.START_GAME))
                {
                    if (playerState.Equals(ModState.RECONNECTING_TO_GAME))
                    {
                        Team.Member member = new Team.Member
                        {
                            entityId = player.entityId,
                            nick     = player.playerName,
                            pId      = pId
                        };

                        VariableContainer.SetPlayerState(pId, ModState.IN_GAME);
                        TeamMaker.AddPlayerToTeam(member, VariableContainer.GetPlayerLastTeam(pId));
                    }

                    // Has no items, teleport to team spawn and give items
                    Map     map   = VariableContainer.GetMap(VariableContainer.selectedMap);
                    Vector3 spawn = TeamMaker.GetPlayerTeam(pId).spawn;

                    Log.Out(string.Format("Spawn for {0} is {1}", player.playerName, spawn.ToString()));

                    // Find random spor around spawn
                    Vector3 destination = Vector3.zero;
                    //if (!world.GetRandomSpawnPositionMinMaxToPosition(spawn, 0, 2, 2, false, out destination, true))
                    // {
                    destination = spawn;
                    //}

                    player.SendPackage(NetPackageManager.GetPackage <NetPackageTeleportPlayer>().Setup(destination, null, false));

                    // ReGen
                    // Rebuild terrain around spawn
                    if (!refubrishedCords.Contains(spawn))
                    {
                        // But only once
                        refubrishedCords.Add(spawn);

                        PrefabInstance prefab = GameManager.Instance.World.GetPOIAtPosition(spawn);

                        int num  = World.toChunkXZ((int)spawn.x) - 1;
                        int num2 = World.toChunkXZ((int)spawn.z) - 1;
                        int num3 = num + 2;
                        int num4 = num2 + 2;

                        HashSetLong hashSetLong = new HashSetLong();
                        for (int k = num; k <= num3; k++)
                        {
                            for (int l2 = num2; l2 <= num4; l2++)
                            {
                                hashSetLong.Add(WorldChunkCache.MakeChunkKey(k, l2));
                            }
                        }

                        ChunkCluster chunkCache = world.ChunkCache;
                        ChunkProviderGenerateWorld chunkProviderGenerateWorld = world.ChunkCache.ChunkProvider as ChunkProviderGenerateWorld;

                        foreach (long key in hashSetLong)
                        {
                            if (!chunkProviderGenerateWorld.GenerateSingleChunk(chunkCache, key, true))
                            {
                                ChatManager.Message(player, string.Format("[FF4136]Failed regenerating chunk at position [FF851B]{0}[FF4136]/[FF851B]{1}", WorldChunkCache.extractX(key) << 4, WorldChunkCache.extractZ(key) << 4));
                            }
                        }

                        world.m_ChunkManager.ResendChunksToClients(hashSetLong);

                        if (prefab != null)
                        {
                            prefab.Reset(world);
                        }
                    }

                    // Give items
                    ClassManager.ApplyClass(player);

                    if (VariableContainer.GetPlayerState(pId).Equals(ModState.START_GAME))
                    {
                        VariableContainer.SetPlayerState(pId, ModState.IN_GAME);
                    }
                    else
                    {
                        HandleDiedInGame(player);
                    }
                    return;
                }
                else
                {
                    VariableContainer.SetPlayerState(pId, ModState.IN_LOBBY);
                    player.SendPackage(NetPackageManager.GetPackage <NetPackageTeleportPlayer>().Setup(VariableContainer.GetLobbyPosition(), null, false));
                    return;
                }
            }

            if (respawnReason.Equals(RespawnType.Teleport))
            {
                return;
            }

            if (VariableContainer.GetPlayerState(pId).Equals(ModState.RECONNECTING_TO_GAME))
            {
                // Have to kill reconected player
                Log.Out("Killing bc of reconnect: " + player.playerName);
                world.Players.dict[player.entityId].DamageEntity(new DamageSource(EnumDamageSource.Internal, EnumDamageTypes.Suicide), 99999, false, 1f);
                return;
            }

            if (VariableContainer.selectedMap == "null")
            {
                VariableContainer.SetPlayerState(pId, ModState.IN_LOBBY);
                player.SendPackage(NetPackageManager.GetPackage <NetPackageTeleportPlayer>().Setup(VariableContainer.GetLobbyPosition(), null, false));
            }
        }