Exemple #1
0
        /// <summary>
        /// Gets the distance to target, with radius excluded
        /// </summary>
        public float GetDistanceToTarget()
        {
            if (AttackTarget == null)
            {
                return(float.MaxValue);
            }

            //var matchIndoors = Location.Indoors == AttackTarget.Location.Indoors;
            //var targetPos = matchIndoors ? AttackTarget.Location.ToGlobal() : AttackTarget.Location.Pos;
            //var sourcePos = matchIndoors ? Location.ToGlobal() : Location.Pos;

            //var dist = (targetPos - sourcePos).Length();
            //var radialDist = dist - (AttackTarget.PhysicsObj.GetRadius() + PhysicsObj.GetRadius());

            // always use spheres?
            var cylDist = (float)Physics.Common.Position.CylinderDistance(PhysicsObj.GetRadius(), PhysicsObj.GetHeight(), PhysicsObj.Position,
                                                                          AttackTarget.PhysicsObj.GetRadius(), AttackTarget.PhysicsObj.GetHeight(), AttackTarget.PhysicsObj.Position);

            if (DebugMove)
            {
                Console.WriteLine($"{Name}.DistanceToTarget: {cylDist}");
            }

            //return radialDist;
            return(cylDist);
        }
Exemple #2
0
        /// <summary>
        /// Gets the distance to target, with radius excluded
        /// </summary>
        public float GetDistanceToTarget()
        {
            var dist = (AttackTarget.Location.ToGlobal() - Location.ToGlobal()).Length();

            dist -= AttackTarget.PhysicsObj.GetRadius() + PhysicsObj.GetRadius();
            return(dist);
        }
Exemple #3
0
        public void adjust_offset(AFrame offset, double quantum)
        {
            if (PhysicsObj == null || TargetID == 0 || !Initialized)
            {
                return;
            }

            var target         = PhysicsObj.GetObjectA(TargetID);
            var targetPosition = target == null ? TargetPosition : target.Position;

            offset.Origin   = PhysicsObj.Position.GetOffset(targetPosition);
            offset.Origin   = PhysicsObj.Position.GlobalToLocalVec(offset.Origin);
            offset.Origin.Z = 0.0f;

            var radius = PhysicsObj.GetRadius();
            var dist   = Position.CylinderDistanceNoZ(radius, PhysicsObj.Position, TargetRadius, targetPosition) - StickyRadius;

            if (Vec.NormalizeCheckSmall(ref offset.Origin))
            {
                offset.Origin = Vector3.Zero;
            }

            var speed   = 0.0f;
            var minterp = PhysicsObj.get_minterp();

            if (minterp != null)
            {
                speed = minterp.get_max_speed() * 5.0f;
            }

            if (speed < PhysicsGlobals.EPSILON)
            {
                speed = 15.0f;
            }

            var delta = speed * (float)quantum;

            if (delta >= Math.Abs(dist))
            {
                delta = dist;
            }

            offset.Origin *= delta;

            var curHeading    = PhysicsObj.Position.Frame.get_heading();
            var targetHeading = PhysicsObj.Position.heading(targetPosition);
            var heading       = targetHeading - curHeading;

            if (Math.Abs(heading) < PhysicsGlobals.EPSILON)
            {
                heading = 0.0f;
            }
            if (heading < -PhysicsGlobals.EPSILON)
            {
                heading += 360.0f;
            }

            //Console.WriteLine($"StickyManager.AdjustOffset(targetHeading={targetHeading}, curHeading={curHeading}, setHeading={heading})");
            offset.set_heading(heading);
        }
Exemple #4
0
        /// <summary>
        /// Used to determine how close you need to be to use an item.
        /// </summary>
        public bool IsWithinUseRadiusOf(WorldObject wo)
        {
            var originDist = Vector3.Distance(Location.ToGlobal(), wo.Location.ToGlobal());
            var radSum     = PhysicsObj.GetRadius() + wo.PhysicsObj.GetRadius();
            var radDist    = originDist - radSum;
            var useRadius  = wo.UseRadius ?? 0.6f;

            // if (this is Player player)
            //    player.Session.Network.EnqueueSend(new GameMessageSystemChat($"OriginDist: {originDist}, RadDist: {radDist}, MyRadius: {PhysicsObj.GetRadius()}, TargetRadius: {wo.PhysicsObj.GetRadius()}, MyUseRadius: {UseRadius ?? 0}, TargetUseRadius: {wo.UseRadius ?? 0}", ChatMessageType.System));

            return(radDist <= useRadius);
        }
Exemple #5
0
        public void adjust_offset(AFrame offset, double quantum)
        {
            if (TargetID == 0 || !Initialized)
            {
                return;
            }

            var target         = PhysicsObj.GetObjectA(TargetID);
            var targetPosition = target == null ? TargetPosition : target.Position;

            offset.Origin   = PhysicsObj.Position.GetOffset(targetPosition);
            offset.Origin   = PhysicsObj.Position.GlobalToLocalVec(offset.Origin);
            offset.Origin.Z = 0.0f;

            var radius = PhysicsObj.GetRadius();
            var dist   = Position.CylinderDistanceNoZ(radius, PhysicsObj.Position, TargetRadius, targetPosition) - StickyRadius;

            CollisionInfo.NormalizeCheckSmall(ref offset.Origin);

            var speed   = 0.0f;
            var minterp = PhysicsObj.get_minterp();

            if (minterp != null)
            {
                speed = minterp.get_max_speed() * 5.0f;
            }

            var delta = speed * (float)quantum;

            if (delta >= Math.Abs(dist))
            {
                delta = dist;
            }

            offset.Origin *= delta;

            var heading = PhysicsObj.Position.heading(targetPosition) - PhysicsObj.Position.Frame.get_heading();

            if (Math.Abs(heading) < PhysicsGlobals.EPSILON)
            {
                heading = 0.0f;
            }
            if (heading < -PhysicsGlobals.EPSILON)
            {
                heading += 360.0f;
            }

            offset.set_heading(heading);
        }
Exemple #6
0
        public float GetCurrentDistance()
        {
            if (PhysicsObj == null)
            {
                return(float.MaxValue);
            }

            if (!MovementParams.Flags.HasFlag(MovementParamFlags.UseSpheres))
            {
                return(PhysicsObj.Position.Distance(CurrentTargetPosition));
            }

            return((float)Position.CylinderDistance(PhysicsObj.GetRadius(), PhysicsObj.GetHeight(), PhysicsObj.Position,
                                                    SoughtObjectRadius, SoughtObjectHeight, CurrentTargetPosition));
        }
Exemple #7
0
        public float GetCurrentDistance()
        {
            if (PhysicsObj == null)
            {
                return(float.MaxValue);
            }

            if ((MovementParams.Bitfield & 0x400) == 0)
            {
                return(PhysicsObj.Position.Distance(CurrentTargetPosition));
            }

            return((float)Position.CylinderDistance(PhysicsObj.GetRadius(), PhysicsObj.GetHeight(), PhysicsObj.Position,
                                                    SoughtObjectRadius, SoughtObjectHeight, CurrentTargetPosition));
        }
Exemple #8
0
        public override void Monster_Tick(double currentUnixTime)
        {
            NextMonsterTickTime = currentUnixTime + monsterTickInterval;
            IsMonster           = true;

            switch (GamePieceState)
            {
            case GamePieceState.MoveToSquare:
                GamePieceState = GamePieceState.WaitingForMoveToSquare;
                MoveWeenie(Position, 0.3f, true);
                break;

            // visual awareness range of piece is only 1, make sure we are close enough to attack
            case GamePieceState.MoveToAttack:
                GamePieceState = GamePieceState.WaitingForMoveToAttack;
                MoveWeenie(Position, PhysicsObj.GetRadius() + TargetPiece.PhysicsObj.GetRadius(), false);
                break;

            case GamePieceState.WaitingForMoveToSquare:
            case GamePieceState.WaitingForMoveToAttack:
                UpdatePosition();
                break;

            case GamePieceState.WaitingForMoveToSquareAnimComplete:

                /*if (PhysicsObj.IsAnimating)
                 * {
                 *  UpdatePosition();
                 *  break;
                 * }*/

                ChessMatch.PieceReady(Guid);
                GamePieceState = GamePieceState.None;
                break;

            case GamePieceState.Combat:

                if (CombatTable == null)
                {
                    GetCombatTable();
                }

                MeleeAttack();
                break;
            }
        }
Exemple #9
0
        /// <summary>
        /// Gets the distance to target, with radius excluded
        /// </summary>
        public float GetDistanceToTarget()
        {
            var dist       = (AttackTarget.Location.ToGlobal() - Location.ToGlobal()).Length();
            var radialDist = dist - (AttackTarget.PhysicsObj.GetRadius() + PhysicsObj.GetRadius());

            // always use spheres?
            var cylDist = (float)Physics.Common.Position.CylinderDistance(PhysicsObj.GetRadius(), PhysicsObj.GetHeight(), PhysicsObj.Position,
                                                                          AttackTarget.PhysicsObj.GetRadius(), AttackTarget.PhysicsObj.GetHeight(), AttackTarget.PhysicsObj.Position);

            /*if (DebugMove)
             * {
             *  Console.WriteLine($"Raw distance: {dist} ({radialDist}) - Cylinder dist: {cylDist}");
             *  Console.WriteLine($"Player radius: {AttackTarget.PhysicsObj.GetRadius()} ({AttackTarget.PhysicsObj.GetPhysicsRadius()})");
             *  Console.WriteLine($"Monster radius: {PhysicsObj.GetRadius()} ({PhysicsObj.GetPhysicsRadius()})");
             * }*/

            //return radialDist;
            return(cylDist);
        }
Exemple #10
0
        /// <summary>
        /// Sets the corpse to the final position
        /// </summary>
        public void SetFinalPosition()
        {
            if (AttackTarget == null)
            {
                return;
            }

            var playerDir = AttackTarget.Location.GetCurrentDir();

            Location.Pos = AttackTarget.Location.Pos + playerDir * (AttackTarget.PhysicsObj.GetRadius() + PhysicsObj.GetRadius());
            SendUpdatePosition();
        }
Exemple #11
0
        /// <summary>
        /// Returns the destination position the monster is attempting to move to
        /// to perform a melee attack
        /// </summary>
        public Vector3 GetDestination()
        {
            var dir = Vector3.Normalize(Location.ToGlobal() - AttackTarget.Location.ToGlobal());

            return(AttackTarget.Location.Pos + dir * (AttackTarget.PhysicsObj.GetRadius() + PhysicsObj.GetRadius()));
        }