コード例 #1
0
        private static bool HandlePlayerDamage(GetDataHandlerArgs args)
        {
            var index        = args.Player.Index;
            var playerId     = (byte)args.Data.ReadByte();
            var hitDirection = (byte)args.Data.ReadByte();
            var damage       = args.Data.ReadInt16();
            var text         = args.Data.ReadString();
            var player       = CTG.Tools.GetPlayerByIndex(playerId);
            var pvp          = args.Data.ReadBoolean();
            var crit         = args.Data.ReadBoolean();
            var ply          = Main.player[playerId];
            var hitDamage    = Main.CalculateDamage(damage, ply.statDefense);

            if (index != playerId)
            {
                hitDamage            = hitDamage > ply.statLife ? ply.statLife : hitDamage;
                player.killingPlayer = CTG.Tools.GetPlayerByIndex(index);
            }
            else
            {
                player.killingPlayer = null;
            }

            return(false);
        }
コード例 #2
0
        private static bool HandlePlayerKillMe(GetDataHandlerArgs args)
        {
            var index        = args.Player.Index;
            var playerId     = (byte)args.Data.ReadByte();
            var hitDirection = (byte)args.Data.ReadByte();
            var damage       = args.Data.ReadInt16();
            var pvp          = args.Data.ReadBoolean();
            var player       = CTG.Tools.GetPlayerByIndex(playerId);
            var text         = args.Data.ReadString();

            if (player == null)
            {
                return(false);
            }

            if (pvp)
            {
                var    messages = new string[] { " was slain by ", " was murdered by ", " was brutally bashed by ", " was royally smashed by ", " has slain ", " gave up on " };
                Random rnd      = new Random();
                string message  = messages[rnd.Next(0, 6)];
                foreach (var ply in CTG.CTGplayer)
                {
                    if (ply != null)
                    {
                        if (ply.team == player.team)
                        {
                            ply.TSPlayer.SendMessage(player.PlayerName + message + player.killingPlayer.PlayerName, Color.Magenta);
                        }
                        else
                        {
                            ply.TSPlayer.SendMessage(player.PlayerName + message + player.killingPlayer.PlayerName, Color.LawnGreen);
                        }
                    }
                }
            }

            var deadPlayer = player;

            deadPlayer.TSPlayer.RespawnTimer = 0;
            deadPlayer.TSPlayer.Spawn((int)player.spawn.X, (int)player.spawn.Y);
            player.TSPlayer.Teleport(player.spawn.X, player.spawn.Y);
            Main.player[player.Index].dead = false;
            deadPlayer.TSPlayer.Dead       = false;

            // This timer is used to make sure the player does not get effected by the border when they are teleported to spawn.
            deadPlayer.respawn          = new Timer(1500);
            deadPlayer.respawn.Enabled  = true;
            deadPlayer.respawn.Elapsed += deadPlayer.PlayerRespawned;
            deadPlayer.Dead             = true;
            return(true);
        }