Beispiel #1
0
        protected override unsafe MyEntity DestroyItem(int itemInstanceId)
        {
            int      num;
            MyEntity entity;

            if (!base.m_localIdToPhysicsShapeInstanceId.TryGetValue(itemInstanceId, out num))
            {
                num = -1;
            }
            MyEnvironmentItems.MyEnvironmentItemData data = base.m_itemsData[itemInstanceId];
            base.RemoveItem(itemInstanceId, num, false, true);
            Vector3D position   = data.Transform.Position;
            string   modelAsset = data.Model.AssetName.Insert(data.Model.AssetName.Length - 4, "_broken");
            bool     flag       = false;

            if (MyModels.GetModelOnlyData(modelAsset) == null)
            {
                entity = MyDebris.Static.CreateDebris(data.Model.AssetName);
            }
            else
            {
                flag   = true;
                entity = MyDebris.Static.CreateDebris(modelAsset);
            }
            MyDebrisBase.MyDebrisBaseLogic gameLogic = entity.GameLogic as MyDebrisBase.MyDebrisBaseLogic;
            gameLogic.LifespanInMiliseconds = 0x4e20;
            MatrixD  xd     = MatrixD.CreateFromQuaternion(data.Transform.Rotation);
            MatrixD *xdPtr1 = (MatrixD *)ref xd;

            xdPtr1.Translation = position + (xd.Up * (flag ? ((double)0) : ((double)5)));
            gameLogic.Start(xd, Vector3.Zero, false);
            return(entity);
        }
Beispiel #2
0
        private void CutTree(int itemInstanceId, Vector3D hitWorldPosition, Vector3 hitNormal, float forceMultiplier = 1f)
        {
            int num;
            HkStaticCompoundShape shape = (HkStaticCompoundShape)base.Physics.RigidBody.GetShape();

            if (base.m_localIdToPhysicsShapeInstanceId.TryGetValue(itemInstanceId, out num))
            {
                MyEnvironmentItems.MyEnvironmentItemData itemData = base.m_itemsData[itemInstanceId];
                MyDefinitionId   id = new MyDefinitionId(base.Definition.ItemDefinitionType, itemData.SubtypeId);
                MyTreeDefinition environmentItemDefinition = (MyTreeDefinition)MyDefinitionManager.Static.GetEnvironmentItemDefinition(id);
                if ((base.RemoveItem(itemInstanceId, num, true, true) && ((environmentItemDefinition != null) && (environmentItemDefinition.BreakSound != null))) && (environmentItemDefinition.BreakSound.Length > 0))
                {
                    EndpointId targetEndpoint = new EndpointId();
                    MyMultiplayer.RaiseStaticEvent <Vector3D, string>(s => new Action <Vector3D, string>(MyTrees.PlaySound), hitWorldPosition, environmentItemDefinition.BreakSound, targetEndpoint, new Vector3D?(hitWorldPosition));
                }
                if (MyPerGameSettings.Destruction && (MyModels.GetModelOnlyData(environmentItemDefinition.Model).HavokBreakableShapes != null))
                {
                    if ((environmentItemDefinition.FallSound != null) && (environmentItemDefinition.FallSound.Length > 0))
                    {
                        this.CreateBreakableShape(environmentItemDefinition, ref itemData, ref hitWorldPosition, hitNormal, forceMultiplier, environmentItemDefinition.FallSound);
                    }
                    else
                    {
                        this.CreateBreakableShape(environmentItemDefinition, ref itemData, ref hitWorldPosition, hitNormal, forceMultiplier, "");
                    }
                }
            }
        }
Beispiel #3
0
        public override unsafe void DoDamage(float damage, int itemInstanceId, Vector3D position, Vector3 normal, MyStringHash type)
        {
            MyParticleEffect effect;

            MyEnvironmentItems.MyEnvironmentItemData data = base.m_itemsData[itemInstanceId];
            MyDefinitionId   id = new MyDefinitionId(base.Definition.ItemDefinitionType, data.SubtypeId);
            MyTreeDefinition environmentItemDefinition = (MyTreeDefinition)MyDefinitionManager.Static.GetEnvironmentItemDefinition(id);

            MyParticlesManager.TryCreateParticleEffect(environmentItemDefinition.CutEffect, MatrixD.CreateWorld(position, Vector3.CalculatePerpendicularVector(normal), normal), out effect);
            if (Sync.IsServer)
            {
                MyCutTreeInfo item  = new MyCutTreeInfo();
                int           index = -1;
                int           num2  = 0;
                while (true)
                {
                    if (num2 < this.m_cutTreeInfos.Count)
                    {
                        item = this.m_cutTreeInfos[num2];
                        if (itemInstanceId != item.ItemInstanceId)
                        {
                            num2++;
                            continue;
                        }
                        index = num2;
                    }
                    if (index == -1)
                    {
                        item = new MyCutTreeInfo {
                            ItemInstanceId = itemInstanceId
                        };
                        MyCutTreeInfo *infoPtr1 = (MyCutTreeInfo *)ref item;
                        infoPtr1->MaxPoints = item.HitPoints = environmentItemDefinition.HitPoints;
                        index = this.m_cutTreeInfos.Count;
                        this.m_cutTreeInfos.Add(item);
                    }
                    item.LastHit = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                    float *singlePtr1 = (float *)ref item.HitPoints;
                    singlePtr1[0] -= damage;
                    if (item.Progress < 1f)
                    {
                        this.m_cutTreeInfos[index] = item;
                        return;
                    }
                    this.CutTree(itemInstanceId, position, normal, (type == MyDamageType.Drill) ? 1f : 4f);
                    this.m_cutTreeInfos.RemoveAtFast <MyCutTreeInfo>(index);
                    return;
                }
            }
        }
Beispiel #4
0
        private void CreateBreakableShape(MyEnvironmentItemDefinition itemDefinition, ref MyEnvironmentItems.MyEnvironmentItemData itemData, ref Vector3D hitWorldPosition, Vector3 hitNormal, float forceMultiplier, string fallSound = "")
        {
            HkdBreakableShape oldBreakableShape = MyModels.GetModelOnlyData(itemDefinition.Model).HavokBreakableShapes[0].Clone();
            MatrixD           transformMatrix   = itemData.Transform.TransformMatrix;

            oldBreakableShape.SetMassRecursively(500f);
            oldBreakableShape.SetStrenghtRecursively(5000f, 0.7f);
            oldBreakableShape.GetChildren(base.m_childrenTmp);
            HkdBreakableShape[] havokBreakableShapes = MyModels.GetModelOnlyData(itemDefinition.Model).HavokBreakableShapes;
            Vector3D.Transform(hitWorldPosition, MatrixD.Normalize(MatrixD.Invert(transformMatrix)));
            float num = (float)(hitWorldPosition.Y - itemData.Transform.Position.Y);
            List <HkdShapeInstanceInfo> shapeList = new List <HkdShapeInstanceInfo>();
            List <HkdShapeInstanceInfo> list2     = new List <HkdShapeInstanceInfo>();
            HkdShapeInstanceInfo?       nullable  = null;

            foreach (HkdShapeInstanceInfo info in base.m_childrenTmp)
            {
                if ((nullable == null) || (info.CoM.Y < nullable.Value.CoM.Y))
                {
                    nullable = new HkdShapeInstanceInfo?(info);
                }
                if (info.CoM.Y > num)
                {
                    list2.Add(info);
                }
                else
                {
                    shapeList.Add(info);
                }
            }
            if (shapeList.Count != 2)
            {
                if ((shapeList.Count == 0) && list2.Remove(nullable.Value))
                {
                    shapeList.Add(nullable.Value);
                }
            }
            else if ((shapeList[0].CoM.Y < shapeList[1].CoM.Y) && (num < (shapeList[1].CoM.Y + 1.25f)))
            {
                list2.Insert(0, shapeList[1]);
                shapeList.RemoveAt(1);
            }
            else if ((shapeList[0].CoM.Y > shapeList[1].CoM.Y) && (num < (shapeList[0].CoM.Y + 1.25f)))
            {
                list2.Insert(0, shapeList[0]);
                shapeList.RemoveAt(0);
            }
            if (shapeList.Count > 0)
            {
                CreateFracturePiece(itemDefinition, oldBreakableShape, transformMatrix, hitNormal, shapeList, forceMultiplier, true, "");
            }
            if (list2.Count > 0)
            {
                CreateFracturePiece(itemDefinition, oldBreakableShape, transformMatrix, hitNormal, list2, forceMultiplier, false, fallSound);
            }
            base.m_childrenTmp.Clear();
        }