Exemplo n.º 1
0
        private void StabilizeTargetedObject()
        {
            TargetedObject.SetLinearVelocity(Vector2.Zero);

            m_distanceJointObject = Game.CreateObject("InvisibleBlockSmall");
            m_distanceJointObject.SetBodyType(BodyType.Dynamic);

            m_distanceJoint = (IObjectDistanceJoint)Game.CreateObject("DistanceJoint");
            m_distanceJoint.SetLineVisual(LineVisual.None);
            m_distanceJoint.SetLengthType(DistanceJointLengthType.Fixed);

            m_targetedObjectJoint = (IObjectTargetObjectJoint)Game.CreateObject("TargetObjectJoint");

            var targetedObjPosition = TargetedObject.GetAABB().Center;

            m_distanceJointObject.SetWorldPosition(targetedObjPosition);
            TargetedObject.SetWorldPosition(targetedObjPosition);
            m_pullJoint.SetWorldPosition(targetedObjPosition);
            m_distanceJoint.SetWorldPosition(targetedObjPosition);
            // if DistanceJoint and TargetObjectJoint is at the same position, weird things may happen
            // uncomment the part below to stop it
            m_targetedObjectJoint.SetWorldPosition(m_distanceJointObject.GetWorldPosition() /* - Vector2.UnitY*/);

            m_pullJoint.SetTargetObject(m_distanceJointObject);
            m_distanceJoint.SetTargetObject(m_distanceJointObject);
            m_distanceJoint.SetTargetObjectJoint(m_targetedObjectJoint);
            m_targetedObjectJoint.SetTargetObject(TargetedObject);
            m_pullJoint.SetForce(15);

            IsTargetedObjectStabilized = true;
        }
Exemplo n.º 2
0
        private void StopStabilizingTargetedObject()
        {
            if (m_distanceJointObject != null)
            {
                m_distanceJointObject.Remove();
                m_distanceJoint.Remove();
                m_targetedObjectJoint.Remove();
            }

            var player = ScriptHelper.CastPlayer(TargetedObject);

            if (player != null)
            {
                player.AddCommand(new PlayerCommand(PlayerCommandType.StopStagger));
                player.SetInputEnabled(true);
            }

            m_pullJoint.SetTargetObject(null);

            if (TargetedObject != null)
            {
                if (Owner.IsBot)
                {
                    TargetedObject.SetCollisionFilter(m_oldCollisionFilter);
                }
                if (TargetedObject.GetCollisionFilter().CategoryBits == CategoryBits.DynamicG2)
                {
                    TargetedObject.TrackAsMissile(true); // must be called after updating CollisionFilter
                }
                TargetedObject.SetMass(m_oldMass);
                TargetedObject = null;
            }
            IsTargetedObjectStabilized = false;
        }
Exemplo n.º 3
0
        public override void Update(float elapsed)
        {
            base.Update(elapsed);

            if (Owner.IsManualAiming)
            {
                var holdPosition = GetHoldPosition(true);
                m_invisibleMagnet.SetWorldPosition(holdPosition);
                // m_invisibleMagnet is a static object so the corresponding TargetObjectJoint need to be moved manually too
                m_magnetJoint.SetWorldPosition(holdPosition);

                if (TargetedObject != null)
                {
                    TryStabilizeTargetedObject(holdPosition);
                }

                if (Game.IsEditorTest)
                {
                    var scanLine = GetScanLine();

                    Game.DrawLine(scanLine[0], scanLine[1]);
                    Game.DrawCircle(holdPosition, .5f, Color.Red);

                    //Game.DrawCircle(position, .5f, Color.Blue);
                    //Game.DrawLine(position, position + direction * 6, Color.Yellow);
                    //Game.DrawArea(m_pullJoint.GetAABB(), Color.Cyan);
                    //Game.DrawArea(m_magnetJoint.GetAABB(), Color.Magenta);

                    if (TargetedObject != null)
                    {
                        Game.DrawArea(TargetedObject.GetAABB(), Color.Blue);
                    }

                    //if (m_distanceJointObject != null)
                    //    Game.DrawArea(m_distanceJointObject.GetAABB(), Color.Green);

                    var to = m_pullJoint.GetTargetObject();
                    if (to != null)
                    {
                        Game.DrawArea(to.GetAABB(), Color.Yellow);
                    }
                }
            }
            else
            {
                if (IsTargetedObjectStabilized || TargetedObject != null)
                {
                    StopStabilizingTargetedObject();

                    m_invisibleMagnet.SetWorldPosition(FarAwayPosition);
                    m_magnetJoint.SetWorldPosition(FarAwayPosition);
                }
            }
        }
Exemplo n.º 4
0
        private void TryStabilizeTargetedObject(Vector2 holdPosition)
        {
            var results        = RayCastTargetedObject(false);
            var stabilizedZone = GetStabilizedZone(holdPosition);

            Game.DrawArea(stabilizedZone, Color.Green);

            var targetedObjectFound = false;
            var targetHitbox        = TargetedObject.GetAABB();

            if (stabilizedZone.Intersects(targetHitbox))
            {
                targetedObjectFound = true;
            }

            foreach (var result in results)
            {
                if (result.HitObject == null)
                {
                    continue;
                }

                if (result.HitObject.UniqueID == TargetedObject.UniqueID)
                {
                    targetedObjectFound = true;

                    if (stabilizedZone.Intersects(targetHitbox))
                    {
                        if (!IsTargetedObjectStabilized)
                        {
                            StabilizeTargetedObject();
                            IsTargetedObjectStabilized = true;
                        }
                    }
                    break;
                }
            }

            if (!targetedObjectFound)
            {
                StopStabilizingTargetedObject();
            }
            else
            {
                var player = ScriptHelper.CastPlayer(TargetedObject);
                if (player != null && !player.IsStaggering)
                {
                    // Not sure why StaggerInfinite is not infinite!
                    player.AddCommand(new PlayerCommand(PlayerCommandType.StaggerInfinite));
                }
            }
        }
Exemplo n.º 5
0
        public bool PickupObject()
        {
            if (TargetedObject == null)
            {
                var results = RayCastTargetedObject(true);

                if (results.Count() > 0)
                {
                    var result = results.First();
                    TargetedObject = result.HitObject;
                    m_oldMass      = TargetedObject.GetMass();

                    // if is player, make them staggering
                    if (result.IsPlayer)
                    {
                        var player = (IPlayer)TargetedObject;
                        MakePlayer(player, PlayerCommandType.StaggerInfinite);
                    }

                    // destroy Joints so hanging stuff can be pulled
                    ScriptHelper.Unscrew(TargetedObject);

                    // some objects that are in dynamic collision group but is static (SurveillanceCamera)
                    if (TargetedObject.GetBodyType() == BodyType.Static)
                    {
                        TargetedObject.SetBodyType(BodyType.Dynamic);
                    }

                    // m_targetObjectJoint.Position is f****d up if key input event fires. idk why
                    m_magnetJoint.SetWorldPosition(GetHoldPosition(true));
                    m_pullJoint.Remove();
                    m_pullJoint = CreatePullJointObject();

                    // The AI when using GravityGun is not very good so I give the bots a little edge advantage
                    if (Owner.IsBot)
                    {
                        m_oldCollisionFilter = TargetedObject.GetCollisionFilter();
                        var noStaticCollision = TargetedObject.GetCollisionFilter();
                        // https://www.mythologicinteractiveforums.com/viewtopic.php?t=1012
                        noStaticCollision.CategoryBits = 0x1010; // marker or something
                        noStaticCollision.MaskBits     = (ushort)(noStaticCollision.MaskBits & 0x11);
                        TargetedObject.SetCollisionFilter(noStaticCollision);
                    }
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        public Vector2 GetHoldPosition(bool useOffset)
        {
            var offset = 0f;

            if (TargetedObject != null && useOffset)
            {
                var hitbox = TargetedObject.GetAABB();
                var length = Math.Max(hitbox.Width, hitbox.Height);
                offset = length / 2f;
            }

            Vector2 position, direction;

            Owner.GetWeaponMuzzleInfo(out position, out direction);

            return(position + direction * (6 + offset));
        }
Exemplo n.º 7
0
        private IObjectPullJoint CreatePullJointObject()
        {
            var pullJoint = (IObjectPullJoint)Game.CreateObject("PullJoint");

            if (TargetedObject != null)
            {
                TargetedObject.SetMass(.004f);
                pullJoint.SetWorldPosition(TargetedObject.GetWorldPosition());
                pullJoint.SetForce(ScriptHelper.IsPlayer(TargetedObject) ? 15 : 4); // IPlayer doesn't have mass, maybe a bit heavier than normal
                pullJoint.SetForcePerDistance(0);
            }

            pullJoint.SetTargetObject(TargetedObject);
            pullJoint.SetTargetObjectJoint(m_magnetJoint);

            return(pullJoint);
        }
Exemplo n.º 8
0
        private void UpdatePointer()
        {
            bool handled = true;

            pointerRay = new Ray(transform.position, transform.forward);
            if (InteractedObject != null)
            {
                ExecuteEvents.ExecuteHierarchy <IRemoteInputEventHandler>(InteractedObject, null,
                                                                          (x, y) => x.OnRemoteOrientation(out handled, transform));
                LaserPointer.PointerTarget = TargetedObject.transform.position;
                if (!handled)
                {
                    InteractedObject = null;
                }
            }
            else if (Physics.Raycast(pointerRay, out pointerHit, PointerDistance))
            {
                if (ExecuteEvents.ExecuteHierarchy <IRemoteInputEventHandler>(pointerHit.collider.gameObject, null,
                                                                              (x, y) => x.OnRemotePointEnter(out handled)))
                {
                    if (TargetedObject != null && !TargetedObject.Equals(pointerHit.collider.gameObject))
                    {
                        ExecuteEvents.Execute <IRemoteInputEventHandler>(TargetedObject, null,
                                                                         (x, y) => x.OnRemotePointExit(out handled));
                    }
                    TargetedObject = pointerHit.collider.gameObject;
                }
                else if (TargetedObject != null)
                {
                    ExecuteEvents.ExecuteHierarchy <IRemoteInputEventHandler>(TargetedObject, null,
                                                                              (x, y) => x.OnRemotePointExit(out handled));
                    TargetedObject = null;
                }
                LaserPointer.PointerTarget = pointerHit.point;
            }
            else
            {
                LaserPointer.PointerTarget = transform.position + transform.forward * PointerDistance;
                if (TargetedObject != null)
                {
                    ExecuteEvents.ExecuteHierarchy <IRemoteInputEventHandler>(TargetedObject, null,
                                                                              (x, y) => x.OnRemotePointExit(out handled));
                    TargetedObject = null;
                }
            }
        }
Exemplo n.º 9
0
        private void Release()
        {
            if (TargetedObject == null)
            {
                var results = RayCastTargetedObject(true);
                if (results.Count() > 0)
                {
                    var result = results.First();
                    TargetedObject = result.HitObject;
                    if (result.IsPlayer)
                    {
                        MakePlayer((IPlayer)result.HitObject, PlayerCommandType.Fall);
                    }
                }
            }

            if (TargetedObject != null)
            {
                var velocity = Owner.AimVector * 40;

                TargetedObject.SetLinearVelocity(velocity);

                // PS: I dont like the effects, uncomment if you want to see it
                //m_releasedObject = m_targetedObject;
                //m_stopPlayingReleaseEffect = true;
                //ScriptHelper.RunIn(() =>
                //{
                //    if (m_releasedObject.IsRemoved) return;

                //    Game.PlayEffect(EffectName.BulletSlowmoTrace, m_releasedObject.GetWorldPosition());
                //    for (var i = 0; i < 1; i++)
                //    {
                //        var effectPosition = ScriptHelerp.WithinArea(m_releasedObject.GetAABB());
                //        Game.PlayEffect(EffectName.ItemGleam, effectPosition);
                //    }
                //}, 1);

                StopStabilizingTargetedObject();
            }
        }
Exemplo n.º 10
0
        protected override void Update(float elapsed)
        {
            base.Update(elapsed);

            if (TargetedObject == null)
            {
                CheckIfCollide();
            }

            if (TargetedObject != null)
            {
                Game.DrawArea(TargetedObject.GetAABB(), Color.Red);
            }
            if (TargetedPlayer != null)
            {
                if (TargetedPlayer.IsOnGround)
                {
                    if (m_weldJoint != null)
                    {
                        Instance.SetBodyType(BodyType.Static);
                        m_weldJoint.Remove();
                        m_weldJoint = null;
                    }

                    if (TargetedPlayer.IsCrouching)
                    {
                        Instance.SetWorldPosition(TargetedPlayer.GetWorldPosition() - m_relPlayerPosition - Vector2.UnitY * 5);
                    }
                    else if (TargetedPlayer.IsRolling)
                    {
                        Instance.SetWorldPosition(TargetedPlayer.GetAABB().Center);
                    }
                    else
                    {
                        Instance.SetWorldPosition(TargetedPlayer.GetWorldPosition() - m_relPlayerPosition);
                    }
                }
                else if (TargetedPlayer.IsInMidAir) // cannot track position accurately when player is in mid air
                {
                    if (m_weldJoint == null)
                    {
                        Instance.SetBodyType(BodyType.Dynamic);
                        m_weldJoint = (IObjectWeldJoint)Game.CreateObject("WeldJoint");
                        m_weldJoint.SetWorldPosition(Instance.GetWorldPosition());
                        m_weldJoint.SetTargetObjects(new List <IObject>()
                        {
                            Instance, TargetedPlayer
                        });
                    }
                }
            }

            if (m_timeElasped != 0 && ScriptHelper.IsElapsed(m_timeElasped, 2000))
            {
                if (m_weldJoint != null)
                {
                    m_weldJoint.Remove();
                }
                DealExplosionDamage();
                Instance.Destroy();
            }
        }