當前位置: 首頁>>代碼示例>>C#>>正文


C# Position.IsZero方法代碼示例

本文整理匯總了C#中fCraft.Position.IsZero方法的典型用法代碼示例。如果您正苦於以下問題:C# Position.IsZero方法的具體用法?C# Position.IsZero怎麽用?C# Position.IsZero使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fCraft.Position的用法示例。


在下文中一共展示了Position.IsZero方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: IoLoop


//.........這裏部分代碼省略.........
                                    player.ParseMessage( message, false );
                                }
                                break;

                            // Player movement
                            case InputCodes.MoveRotate:
                                reader.ReadByte();
                                Position newPos = new Position();
                                newPos.x = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                newPos.h = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                newPos.y = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                newPos.r = reader.ReadByte();
                                newPos.l = reader.ReadByte();

                                if( newPos.h < 0 || newPos.x < -32 || newPos.x >= world.map.widthX * 32+32 || newPos.y < -32 || newPos.y > world.map.widthY * 32+32 ) {
                                    world.log.Log( player.name + " was kicked for moving out of map boundaries.", LogType.SuspiciousActivity );
                                    world.SendToAll( player.name + " was kicked for moving out of map boundaries.", null );
                                    KickNow( "Hacking detected: out of map boundaries." );
                                    return;
                                }

                                Position delta = new Position(), oldPos = player.pos;
                                bool posChanged, rotChanged;

                                if( !player.isHidden ) {
                                    delta.Set( newPos.x - oldPos.x, newPos.y - oldPos.y, newPos.h - oldPos.h, newPos.r, newPos.l );
                                    posChanged = delta.x != 0 || delta.y != 0 || delta.h != 0;
                                    rotChanged = newPos.r != oldPos.r || newPos.l != oldPos.l;

                                    if( player.isFrozen ) {
                                        if( rotChanged ) {
                                            world.SendToAll( PacketWriter.MakeRotate( player.id, newPos ), player );
                                            player.pos.r = newPos.r;
                                            player.pos.l = newPos.l;
                                        }
                                        if( posChanged ) {
                                            SendNow( PacketWriter.MakeTeleport( 255, player.pos ) );
                                        }

                                    } else {
                                        if( delta.FitsIntoByte() && fullPositionUpdateCounter < fullPositionUpdateInterval ) {
                                            if( posChanged && rotChanged ) {
                                                world.SendToAll( PacketWriter.MakeMoveRotate( player.id, delta ), player );
                                            } else if( posChanged ) {
                                                world.SendToAll( PacketWriter.MakeMove( player.id, delta ), player );
                                            } else if( rotChanged ) {
                                                world.SendToAll( PacketWriter.MakeRotate( player.id, newPos ), player );
                                            }
                                        } else if( !delta.IsZero() && !player.isFrozen ) {
                                            world.SendToAll( PacketWriter.MakeTeleport( player.id, newPos ), player );
                                        }
                                        player.pos = newPos;
                                        if( player.isDummySpamming ) {
                                            world.cmd.standardCommands.Dummy( player, new Command( "/dummy " + player.name ) );
                                        }
                                    }

                                    fullPositionUpdateCounter++;
                                    if( fullPositionUpdateCounter >= fullPositionUpdateInterval ) fullPositionUpdateCounter = 0;
                                }
                                break;

                            // Set tile
                            case InputCodes.SetTile:
                                x = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                h = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                y = IPAddress.NetworkToHostOrder( reader.ReadInt16() );
                                mode = reader.ReadByte();
                                type = reader.ReadByte();
                                if( type > 49 || x < 0 || x > world.map.widthX || y < 0 || y > world.map.widthY || h < 0 || h > world.map.height ) {
                                    world.log.Log( player.name + " was kicked for sending bad SetTile packets.", LogType.SuspiciousActivity );
                                    world.SendToAll( player.name + " was kicked for sending bad SetTile packets.", null );
                                    KickNow( "Hacking detected: illegal SetTile packet." );
                                    return;
                                } else {
                                    player.SetTile( x, y, h, mode == 1, (Block)type );
                                }
                                break;
                        }
                    }
                }

            } catch( ThreadAbortException ) {
                world.log.Log( "Session.IoLoop: Thread aborted!", LogType.Error );

            } catch( IOException ex ) {
                world.log.Log( "Session.IoLoop: {0}.", LogType.Warning, ex.Message );

            } catch( SocketException ex ) {
                world.log.Log( "Session.IoLoop: {0}.", LogType.Warning, ex.Message );

            } catch( Exception ex ) {
                world.log.Log( "Session.IoLoop: {0}: {1}.", LogType.Error, ex.ToString(), ex.Message );

            } finally {
                canQueue = false;
                canSend = false;
                canDispose = true;
            }
        }
開發者ID:fragmer,項目名稱:fCraft,代碼行數:101,代碼來源:Session.cs

示例2: ProcessMovementPacket

        void ProcessMovementPacket() {
            bytesReceived += 10;
            reader.ReadByte();
            Position newPos = new Position {
                X = IPAddress.NetworkToHostOrder( reader.ReadInt16() ),
                H = IPAddress.NetworkToHostOrder( reader.ReadInt16() ),
                Y = IPAddress.NetworkToHostOrder( reader.ReadInt16() ),
                R = reader.ReadByte(),
                L = reader.ReadByte()
            };

            Position oldPos = Player.Position;

            // calculate difference between old and new positions
            Position delta = new Position {
                X = (short)(newPos.X - oldPos.X),
                Y = (short)(newPos.Y - oldPos.Y),
                H = (short)(newPos.H - oldPos.H),
                R = (byte)Math.Abs( newPos.R - oldPos.R ),
                L = (byte)Math.Abs( newPos.L - oldPos.L )
            };

            // skip everything if player hasn't moved
            if( delta.IsZero() ) return;

            bool rotChanged = (delta.R != 0) || (delta.L != 0);

            // only reset the timer if player rotated
            // if player is just pushed around, rotation does not change (and timer should not reset)
            if( rotChanged ) Player.ResetIdleTimer();

            if( Player.Info.IsFrozen ) {
                // special handling for frozen players
                if( delta.X * delta.X + delta.Y * delta.Y > AntiSpeedMaxDistanceSquared ||
                    Math.Abs( delta.H ) > 40 ) {
                    SendNow( PacketWriter.MakeSelfTeleport( Player.Position ) );
                }
                newPos.X = Player.Position.X;
                newPos.Y = Player.Position.Y;
                newPos.H = Player.Position.H;

                // recalculate deltas
                delta.X = 0;
                delta.Y = 0;
                delta.H = 0;

            } else if( !Player.Can( Permission.UseSpeedHack ) ) {
                int distSquared = delta.X * delta.X + delta.Y * delta.Y + delta.H * delta.H;
                // speedhack detection
                if( DetectMovementPacketSpam() ) {
                    return;

                } else if( (distSquared - delta.H * delta.H > AntiSpeedMaxDistanceSquared || delta.H > AntiSpeedMaxJumpDelta) &&
                           speedHackDetectionCounter >= 0 ) {

                    if( speedHackDetectionCounter == 0 ) {
                        Player.LastValidPosition = Player.Position;
                    } else if( speedHackDetectionCounter > 1 ) {
                        DenyMovement();
                        speedHackDetectionCounter = 0;
                        return;
                    }
                    speedHackDetectionCounter++;

                } else {
                    speedHackDetectionCounter = 0;
                }
            }

            if( Server.RaisePlayerMovingEvent( Player, newPos ) ) {
                DenyMovement();
                return;
            }

            Player.Position = newPos;
            Server.RaisePlayerMovedEvent( Player, oldPos );
        }
開發者ID:fragmer,項目名稱:fCraft,代碼行數:77,代碼來源:Session.cs


注:本文中的fCraft.Position.IsZero方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。