Example #1
0
        public virtual bool Init(IMyRemoteControl rc = null)
        {
            Rc = rc ?? Term.GetBlocksOfType <IMyRemoteControl>(collect: x => x.IsFunctional).FirstOrDefault();
            if (rc == null)
            {
                return(false);
            }
            DroneName = DroneNameProvider;

            Antennae = Term.GetBlocksOfType <IMyRadioAntenna>(collect: x => x.IsFunctional);

            bool hasSetup = ParseSetup();

            if (!hasSetup)
            {
                return(false);
            }

            AiSessionCore.AddDamageHandler(Grid, (block, damage) => { OnDamaged?.Invoke(block, damage); });

            Grid.OnBlockAdded += block => { OnBlockPlaced?.Invoke(block); };

            _ownerFaction = Grid.GetOwnerFaction(true);

            BotOperable = true;

            return(true);
        }
        public void DetachChildren(Transform blockTransform)
        {
            var parentTransform = blockTransform.parent;

            if (parentTransform != null)
            {
                blockTransform.parent = null;
                DestroyGameObject(parentTransform);
            }

            blockTransform.DetachChildren();
            DestroyGameObject(blockTransform);

            if (_isTopBoarderReached)
            {
                OnTopBorderReached?.Invoke();
                return;
            }
            OnBlockPlaced?.Invoke();
        }