private void RegisterModifier(long delta)
        {
            if (Container == null)
            {
                return;
            }

            ItemComp = this.Get <MyInventoryItemComponent>();
            if (ItemComp?.ItemContainer == null)
            {
                return;
            }

            Holder    = ItemComp.ItemContainer.Entity;
            Equipment = ItemComp.Item as MyEquipmentItem;

            if (Holder == null)
            {
                return;
            }

            DamageComp = Holder.Get <MyCharacterDamageComponent>();
            if (DamageComp == null)
            {
                return;
            }

            DamageComp.RegisterDamageModifier(this);
            DamageComp.DamageTaken += OnDamageTaken;
        }
Ejemplo n.º 2
0
        private void OnEntityDetached(MyModelAttachmentComponent component, MyEntity entity)
        {
            entity.PositionComp.OnPositionChanged -= OnPositionChanged;
            var model = entity.Get <MyModelComponent>();

            if (model != null)
            {
                model.ModelChanged -= OnModelChanged;
            }
        }
Ejemplo n.º 3
0
        private void OnEntityAttached(MyModelAttachmentComponent component, MyEntity entity)
        {
            if (!Definition.Dummies.ContainsKey(component.GetEntityAttachmentPoint(entity)))
            {
                return;
            }
            entity.PositionComp.OnPositionChanged += OnPositionChanged;
            var model = entity.Get <MyModelComponent>();

            if (model != null)
            {
                model.ModelChanged += OnModelChanged;
            }
        }
Ejemplo n.º 4
0
        public void Use(string dummyName, UseActionEnum actionEnum, MyEntity user)
        {
            if (actionEnum != UseActionEnum.Manipulate)
            {
                return;
            }
            if (user != MyAPIGateway.Session.ControlledObject)
            {
                return;
            }
            var state = StateForDummy(dummyName);

            if (state == null)
            {
                return;
            }
            user.Get <EquiEntityControllerComponent>()?.RequestControl(state);
        }
Ejemplo n.º 5
0
        public override void Init(MyEntity holder, MyHandItem item, MyHandItemBehaviorDefinition definition)
        {
            base.Init(holder, item, definition);

            var def = (MrzVoxelPainterBehaviorDefinition)definition;

            _mining = MyDefinitionManager.Get <MyVoxelMiningDefinition>(def.Mining);
            for (var i = 0; i < _filter.Length; i++)
            {
                _filter[i] = _mining.MiningEntries.ContainsKey(i);
            }

            var material = MyDefinitionManager.Get <MyVoxelMaterialDefinition>(def.PaintMaterial);

            _fillMaterial = material?.Index ?? (byte)0;

            _inventory        = holder.Get <MyInventoryBase>(MyCharacterConstants.MainInventory);
            _wrongToolMessage = MrzUtils.CreateNotification(string.Format(def.WrongToolMessage, Item.GetDefinition().DisplayNameText), MrzUtils.NotificationType.Error);
        }
        public static bool ValidateQuickRemove(IMyPlayer holderPlayer, MyEntity removeEntity, out string errMessage)
        {
            var dynCon = removeEntity.Components.Get <BendyComponent>();

            if (dynCon == null)
            {
                errMessage = null;
                return(false);
            }

            if (!holderPlayer.IsCreative())
            {
                var constructionCon = removeEntity.Components.Get <ConstructableComponent>();
                // ReSharper disable once InvertIf
                if (constructionCon != null && (constructionCon.BuildIntegrity > 0 || !constructionCon.StockpileEmpty))
                {
                    errMessage = "You cannot quick deconstruct built segments";
                    return(false);
                }

                var block = removeEntity?.Get <MyBlockComponent>();
                if (block != null)
                {
                    var gbc = block.GridData.Container.Get <MyGridBuildingComponent>();
                    if (gbc == null)
                    {
                        errMessage = "You cannot quick deconstruct built segments";
                        return(false);
                    }

                    var state = gbc.GetBlockState(block.BlockId);
                    if (state == null || state.BuildIntegrity > 0)
                    {
                        errMessage = "You cannot quick deconstruct built segments";
                        return(false);
                    }
                }
            }

            errMessage = null;
            return(true);
        }
Ejemplo n.º 7
0
        private void CheckSkeleton()
        {
            var newSkeleton = _parentCache?.Get <MySkeletonComponent>();

            if (_parentSkeleton == newSkeleton)
            {
                return;
            }
            if (_parentSkeleton != null)
            {
                _parentSkeleton.OnReloadBones -= InvalidateBoneMapping;
                _parentSkeleton.OnPoseChanged -= UpdatePose;
                _parentSkeleton = null;
            }

            _parentSkeleton = newSkeleton;
            if (_parentSkeleton == null)
            {
                return;
            }
            _parentSkeleton.OnReloadBones += InvalidateBoneMapping;
            _parentSkeleton.OnPoseChanged += UpdatePose;
            InvalidateBoneMapping(_parentSkeleton);
        }
        private static void RemoveEdge(long removerEntityId, long entityIdToRemove)
        {
            MyEntity holderEntity;

            MyEntities.TryGetEntityById(removerEntityId, out holderEntity);
            var holderPlayer = holderEntity != null
                ? MyAPIGateway.Players.GetPlayerControllingEntity(holderEntity)
                : null;

            MyEntity removeEntity = null;

            MyEntities.TryGetEntityById(entityIdToRemove, out removeEntity);

            if (removeEntity == null)
            {
                MyEventContext.ValidationFailed();
                return;
            }

            #region Validation

            if (!MyEventContext.Current.IsLocallyInvoked)
            {
                if (holderEntity == null || holderPlayer == null ||
                    MyEventContext.Current.Sender.Value != holderPlayer.SteamUserId)
                {
                    MyEventContext.ValidationFailed();
                    return;
                }

                if (MyAreaPermissionSystem.Static != null && !MyAreaPermissionSystem.Static.HasPermission(
                        holderPlayer.IdentityId, removeEntity.GetPosition(), MyPermissionsConstants.QuickDeconstruct))
                {
                    holderPlayer.ShowNotification("You cannot quick deconstruct here", 2000, null,
                                                  new Vector4(1, 0, 0, 1));
                    return;
                }

                string err;
                if (!ValidateQuickRemove(holderPlayer, removeEntity, out err))
                {
                    MyEventContext.ValidationFailed();
                    if (!string.IsNullOrEmpty(err))
                    {
                        holderPlayer.ShowNotification(err, 2000, null, new Vector4(1, 0, 0, 1));
                    }
                    return;
                }
            }

            #endregion

            var block = removeEntity?.Get <MyBlockComponent>();
            if (block != null)
            {
                block.GridData.RemoveBlock(block.Block);
            }
            else
            {
                removeEntity.Close();
            }

            EntityRemoved?.Invoke(holderEntity, holderPlayer, removeEntity);
        }
        public static bool AttemptPhysicsSleep(MyEntity start)
        {
            var relativeTo = start.Get <MyPhysicsComponentBase>();

            using (PoolManager.Get(out HashSet <MyGroup> visitedGroups))
                using (PoolManager.Get(out HashSet <MyEntity> visitedEntities))
                    using (PoolManager.Get(out List <MyEntity> pruningEntities))
                        using (PoolManager.Get(out Queue <MyEntity> queue))
                        {
                            visitedEntities.Clear();
                            visitedGroups.Clear();
                            queue.Clear();

                            queue.Enqueue(start);
                            visitedEntities.Add(start);
                            while (queue.Count > 0)
                            {
                                var e = queue.Dequeue();
                                if (e.Components.TryGet(out MyBlockComponent block))
                                {
                                    if (visitedEntities.Add(block.GridData.Entity))
                                    {
                                        queue.Enqueue(block.GridData.Entity);
                                    }
                                    continue;
                                }

                                if (!e.Components.TryGet <MyPhysicsComponentBase>(out var physicsComponent) || physicsComponent.IsStatic || !physicsComponent.Enabled)
                                {
                                    continue;
                                }
                                if (e.Components.TryGet <MyCharacterPhysics>(out var characterPhysics) && characterPhysics.Enabled)
                                {
                                    return(false);
                                }
                                if (relativeTo != physicsComponent && !CanSleepPhysics(physicsComponent, relativeTo))
                                {
                                    return(false);
                                }

                                foreach (var group in MySession.Static.Scene.GetEntityGroups(e.Id))
                                {
                                    if (visitedGroups.Add(@group))
                                    {
                                        foreach (var entity in @group.Entities)
                                        {
                                            if (visitedEntities.Add(entity))
                                            {
                                                queue.Enqueue(entity);
                                            }
                                        }
                                    }
                                }

                                var queryVol = e.PositionComp.WorldVolume;
                                queryVol.Radius += 1;
                                pruningEntities.Clear();
                                MyGamePruningStructure.GetTopMostEntitiesInSphere(in queryVol, pruningEntities, MyEntityQueryType.Dynamic);
                                foreach (var nearby in pruningEntities)
                                {
                                    if (visitedEntities.Add(nearby) && nearby.PositionComp.WorldVolume.Intersects(queryVol))
                                    {
                                        queue.Enqueue(nearby);
                                    }
                                }
                            }

                            foreach (var ent in visitedEntities)
                            {
                                var gridPhysics = ent.Get <MyGridRigidBodyComponent>();
                                if (gridPhysics == null)
                                {
                                    continue;
                                }
                                gridPhysics.Gravity = MyGravityProviderSystem.CalculateTotalGravityInPoint(ent.PositionComp.GetPosition());
                                gridPhysics.Sleep();
                            }

                            return(true);
                        }
        }