Example #1
0
        private bool IsBeingWelded()
        {
            if (MySession.Static == null)
            {
                return(false);
            }
            if (MySession.Static.ControlledEntity == null)
            {
                return(false);
            }
            MyCharacter entity = MySession.Static.ControlledEntity.Entity as MyCharacter;

            if (entity == null)
            {
                return(false);
            }
            MyEngineerToolBase currentWeapon = entity.CurrentWeapon as MyEngineerToolBase;

            if (currentWeapon == null)
            {
                return(false);
            }
            MyCubeGrid  targetGrid = currentWeapon.GetTargetGrid();
            MyCubeBlock objB       = this.Entity as MyCubeBlock;

            if (((targetGrid == null) || ((objB == null) || !ReferenceEquals(targetGrid, objB.CubeGrid))) || !currentWeapon.HasHitBlock)
            {
                return(false);
            }
            MySlimBlock cubeBlock = targetGrid.GetCubeBlock(currentWeapon.TargetCube);

            return((cubeBlock != null) ? (ReferenceEquals(cubeBlock.FatBlock, objB) && currentWeapon.IsShooting) : false);
        }
Example #2
0
        private void UpdateScattering(ref MatrixD weaponAnimMatrix, MyHandItemDefinition handItemDefinition)
        {
            MyEngineerToolBase currentWeapon = base.Character.CurrentWeapon as MyEngineerToolBase;
            bool flag = false;

            if (handItemDefinition.ScatterSpeed > 0f)
            {
                bool hasHitBlock = false;
                if (currentWeapon != null)
                {
                    hasHitBlock = currentWeapon.HasHitBlock;
                }
                flag = this.IsShooting & hasHitBlock;
                if (!flag && (this.m_currentScatterToAnimRatio >= 1f))
                {
                    this.m_currentScatterBlend = 0f;
                }
                else
                {
                    if (this.m_currentScatterBlend == 0f)
                    {
                        this.m_lastScatterPos = Vector3.Zero;
                    }
                    if (this.m_currentScatterBlend == handItemDefinition.ScatterSpeed)
                    {
                        this.m_lastScatterPos      = this.m_currentScatterPos;
                        this.m_currentScatterBlend = 0f;
                    }
                    if ((this.m_currentScatterBlend == 0f) || (this.m_currentScatterBlend == handItemDefinition.ScatterSpeed))
                    {
                        this.m_currentScatterPos = new Vector3(MyUtils.GetRandomFloat(-handItemDefinition.ShootScatter.X / 2f, handItemDefinition.ShootScatter.X / 2f), MyUtils.GetRandomFloat(-handItemDefinition.ShootScatter.Y / 2f, handItemDefinition.ShootScatter.Y / 2f), MyUtils.GetRandomFloat(-handItemDefinition.ShootScatter.Z / 2f, handItemDefinition.ShootScatter.Z / 2f));
                    }
                    this.m_currentScatterBlend += 0.01f;
                    if (this.m_currentScatterBlend > handItemDefinition.ScatterSpeed)
                    {
                        this.m_currentScatterBlend = handItemDefinition.ScatterSpeed;
                    }
                    Vector3 vector = Vector3.Lerp(this.m_lastScatterPos, this.m_currentScatterPos, this.m_currentScatterBlend / handItemDefinition.ScatterSpeed);
                    weaponAnimMatrix.Translation += (1f - this.m_currentScatterToAnimRatio) * vector;
                }
                this.m_currentScatterToAnimRatio += flag ? -0.1f : 0.1f;
                if (this.m_currentScatterToAnimRatio > 1f)
                {
                    this.m_currentScatterToAnimRatio = 1f;
                }
                else if (this.m_currentScatterToAnimRatio < 0f)
                {
                    this.m_currentScatterToAnimRatio = 0f;
                }
            }
        }
Example #3
0
        private void UpdateLogicalWeaponPosition()
        {
            Vector3 vector;

            if (base.Character.IsCrouching)
            {
                vector = new Vector3(0f, base.Character.Definition.CharacterCollisionCrouchHeight - (base.Character.Definition.CharacterHeadHeight * 0.5f), 0f);
            }
            else
            {
                vector = new Vector3(0f, base.Character.Definition.CharacterCollisionHeight - (base.Character.Definition.CharacterHeadHeight * 0.5f), 0f);
            }
            Vector3 weaponIronsightTranslation = m_weaponIronsightTranslation;

            if (base.Character.CurrentWeapon is MyEngineerToolBase)
            {
                Vector3 toolIronsightTranslation = m_toolIronsightTranslation;
            }
            this.LogicalPositionLocalSpace = vector;
            this.LogicalPositionWorld      = Vector3D.Transform(this.LogicalPositionLocalSpace, base.Character.PositionComp.WorldMatrix);
            this.LogicalOrientationWorld   = base.Character.ShootDirection;
            this.LogicalCrosshairPoint     = this.LogicalPositionWorld + (this.LogicalOrientationWorld * 2000.0);
            if (base.Character.CurrentWeapon != null)
            {
                MyEngineerToolBase currentWeapon = base.Character.CurrentWeapon as MyEngineerToolBase;
                if (currentWeapon != null)
                {
                    currentWeapon.UpdateSensorPosition();
                }
                else
                {
                    MyHandDrill drill = base.Character.CurrentWeapon as MyHandDrill;
                    if (drill != null)
                    {
                        drill.WorldPositionChanged(null);
                    }
                }
            }
        }
 public override void OnAddedToContainer()
 {
     base.OnAddedToContainer();
     m_tool = Container.Entity as MyEngineerToolBase;
 }
 public MyDebugRenderComponentEngineerTool(MyEngineerToolBase tool)
     : base(tool)
 {
     m_tool = tool;
 }
Example #6
0
        /// <summary>
        /// Update logical weapon position (model of the weapon will be placed there, bullet will spawn on logical position).
        /// </summary>
        private void UpdateLogicalWeaponPosition()
        {
            Vector3 templogicalPositionLocalSpace;

            // head position
            if (Character.IsCrouching)
            {
                templogicalPositionLocalSpace = new Vector3(0, Character.Definition.CharacterCollisionCrouchHeight - Character.Definition.CharacterHeadHeight, 0);
            }
            else
            {
                templogicalPositionLocalSpace = new Vector3(0, Character.Definition.CharacterCollisionHeight - Character.Definition.CharacterHeadHeight, 0);
            }

            // fetch ironsight position
            Vector3 ironsightLocation = m_weaponIronsightTranslation;

            if (Character.CurrentWeapon is MyEngineerToolBase)
            {
                ironsightLocation = m_toolIronsightTranslation;
            }

            // hand item position
            var handItemDef = Character.HandItemDefinition;

            if (handItemDef != null)
            {
                templogicalPositionLocalSpace += Character.ZoomMode == MyZoomModeEnum.IronSight ? ironsightLocation : handItemDef.ItemShootLocation.Translation;
            }

            templogicalPositionLocalSpace.Z = 0;

            // store results
            LogicalPositionLocalSpace = templogicalPositionLocalSpace;
            LogicalPositionWorld      = Vector3D.Transform(LogicalPositionLocalSpace, Character.PositionComp.WorldMatrix);

            var  jetpack = Character.JetpackComp;
            bool flying  = jetpack != null && jetpack.Running;

            float headRotXRads = MathHelper.ToRadians(Character.HeadLocalXAngle);

            if (!flying)
            {
                LogicalOrientationWorld = Character.PositionComp.WorldMatrix.Forward * Math.Cos(headRotXRads)
                                          + Character.PositionComp.WorldMatrix.Up * Math.Sin(headRotXRads);
            }
            else
            {
                LogicalOrientationWorld = Character.PositionComp.WorldMatrix.Forward;
            }

            LogicalCrosshairPoint = LogicalPositionWorld + LogicalOrientationWorld * 2000;

            if (Character.CurrentWeapon != null && Character.ControllerInfo.IsLocallyControlled() == false)
            {
                // MZ fix: weapon position not updated on DS
                MyEngineerToolBase tool = Character.CurrentWeapon as MyEngineerToolBase;
                if (tool != null)
                {
                    tool.UpdateSensorPosition();
                }
                else
                {
                    MyHandDrill drill = Character.CurrentWeapon as MyHandDrill;
                    if (drill != null)
                    {
                        drill.WorldPositionChanged(null);
                    }
                }
            }
        }
 public override void OnAddedToContainer()
 {
     base.OnAddedToContainer();
     m_tool = Container.Entity as MyEngineerToolBase;
 }
 public override void OnAddedToContainer(MyComponentContainer container)
 {
     base.OnAddedToContainer(container);
     m_tool = Entity as MyEngineerToolBase;
 }
Example #9
0
        private unsafe void UpdateGraphicalWeaponPosition3rd(MyHandItemDefinition handItemDefinition)
        {
            bool jetpackRunning = base.Character.JetpackRunning;
            MyAnimationControllerComponent animationController = base.Character.AnimationController;
            MatrixD xd = base.Character.GetHeadMatrix(false, !jetpackRunning, false, true, true) * base.Character.PositionComp.WorldMatrixInvScaled;

            if (animationController.CharacterBones.IsValidIndex <MyCharacterBone>(base.Character.HeadBoneIndex))
            {
                double *numPtr1 = (double *)ref xd.M42;
                numPtr1[0] += animationController.CharacterBonesSorted[0].Translation.Y;
            }
            MatrixD xd2 = handItemDefinition.ItemLocation3rd;
            MatrixD xd3 = handItemDefinition.ItemWalkingLocation3rd;
            MatrixD xd4 = handItemDefinition.ItemShootLocation3rd;
            MatrixD itemIronsightLocation = handItemDefinition.ItemIronsightLocation;
            MatrixD xd6 = animationController.CharacterBones.IsValidIndex <MyCharacterBone>(base.Character.WeaponBone) ? (this.GetWeaponRelativeMatrix() * animationController.CharacterBones[base.Character.WeaponBone].AbsoluteTransform) : this.GetWeaponRelativeMatrix();

            itemIronsightLocation.Translation = m_weaponIronsightTranslation;
            if (base.Character.CurrentWeapon is MyEngineerToolBase)
            {
                itemIronsightLocation.Translation = m_toolIronsightTranslation;
            }
            Vector4D vectord           = this.UpdateAndGetWeaponVariantWeights(handItemDefinition);
            MatrixD  weaponMatrixLocal = MatrixD.Normalize((MatrixD)((((vectord.X * xd2) + (vectord.Y * xd3)) + (vectord.Z * xd4)) + (vectord.W * itemIronsightLocation)));
            double   num = 0.0;

            if (handItemDefinition.ItemPositioning3rd == MyItemPositioningEnum.TransformFromData)
            {
                num += vectord.X;
            }
            if (handItemDefinition.ItemPositioningWalk3rd == MyItemPositioningEnum.TransformFromData)
            {
                num += vectord.Y;
            }
            if (handItemDefinition.ItemPositioningShoot3rd == MyItemPositioningEnum.TransformFromData)
            {
                num += vectord.Z;
            }
            if (handItemDefinition.ItemPositioningIronsight3rd == MyItemPositioningEnum.TransformFromData)
            {
                num += vectord.W;
            }
            num /= ((vectord.X + vectord.Y) + vectord.Z) + vectord.W;
            double num2 = 0.0;

            if (handItemDefinition.ItemPositioning3rd != MyItemPositioningEnum.TransformFromAnim)
            {
                num2 += vectord.X;
            }
            if (handItemDefinition.ItemPositioningWalk3rd != MyItemPositioningEnum.TransformFromAnim)
            {
                num2 += vectord.Y;
            }
            if (handItemDefinition.ItemPositioningShoot3rd != MyItemPositioningEnum.TransformFromAnim)
            {
                num2 += vectord.Z;
            }
            if (handItemDefinition.ItemPositioningIronsight3rd != MyItemPositioningEnum.TransformFromAnim)
            {
                num2 += vectord.W;
            }
            num2 /= ((vectord.X + vectord.Y) + vectord.Z) + vectord.W;
            this.ApplyWeaponBouncing(handItemDefinition, ref weaponMatrixLocal, (float)(1.0 - (0.95 * vectord.W)), 0f);
            double *numPtr2 = (double *)ref xd.M43;

            numPtr2[0] += (0.5 * weaponMatrixLocal.M43) * Math.Max(0.0, xd.M32);
            double *numPtr3 = (double *)ref xd.M42;

            numPtr3[0] += (0.5 * weaponMatrixLocal.M42) * Math.Max(0.0, xd.M32);
            double *numPtr4 = (double *)ref xd.M42;

            numPtr4[0] -= 0.25 * Math.Max(0.0, xd.M32);
            double *numPtr5 = (double *)ref xd.M43;

            numPtr5[0] -= 0.05 * Math.Min(0.0, xd.M32);
            double *numPtr6 = (double *)ref xd.M41;

            numPtr6[0] -= 0.25 * Math.Max(0.0, xd.M32);
            MatrixD            xd8           = weaponMatrixLocal * xd;
            MyEngineerToolBase currentWeapon = base.Character.CurrentWeapon as MyEngineerToolBase;

            if (currentWeapon != null)
            {
                currentWeapon.SensorDisplacement = (Vector3) - weaponMatrixLocal.Translation;
            }
            double  amount           = (num * this.m_currentAnimationToIkTime) / ((double)this.m_animationToIKDelay);
            MatrixD weaponAnimMatrix = MatrixD.Lerp(xd6, xd8, amount);

            this.UpdateScattering(ref weaponAnimMatrix, handItemDefinition);
            this.ApplyBackkick(ref weaponAnimMatrix);
            MatrixD matrix = weaponAnimMatrix * base.Character.WorldMatrix;

            this.GraphicalPositionWorld = matrix.Translation;
            this.ArmsIkWeight           = (float)num2;
            ((MyEntity)base.Character.CurrentWeapon).WorldMatrix = matrix;
            if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_CHARACTER_TOOLS)
            {
                MyDebugDrawHelper.DrawNamedColoredAxis(xd6 * base.Character.WorldMatrix, 0.25f, "weapon anim " + (100.0 - (100.0 * amount)) + "%", new Color?(Color.Orange));
                MyDebugDrawHelper.DrawNamedColoredAxis(xd8 * base.Character.WorldMatrix, 0.25f, "weapon data " + (100.0 * amount) + "%", new Color?(Color.Magenta));
                MyDebugDrawHelper.DrawNamedColoredAxis(matrix, 0.25f, "weapon final", new Color?(Color.White));
            }
        }
Example #10
0
 public override void OnAddedToContainer(MyComponentContainer container)
 {
     base.OnAddedToContainer(container);
     m_tool = Entity as MyEngineerToolBase;
 }
 public MyDebugRenderComponentEngineerTool(MyEngineerToolBase tool)
     : base(tool)
 {
     m_tool = tool;
 }