Пример #1
0
        private void InitShipDetector()
        {
            //MyDetectingCriteria detectingCriteria = new MyDetectingCriteria();

            //detectingCriteria.DetectingCriteria.Add(
            //new MyDetectingCriterium(
            //    MyDetectedEntityAction.TradeForFree,
            //    new MyDetectingCondition<MyEntity>(
            //    //x => (MyFactions.GetFactionsRelation(this.Faction, x.Faction) == MyFactionRelationEnum.Friend) && (x is MySmallShip || x is MyPrefabHangar || x is MyFoundationFactory) && ((IMyInventory)x).Inventory != null,
            //        x => (MyFactions.GetFactionsRelation(this.Faction, x.Faction) == MyFactionRelationEnum.Friend) && (x is MySmallShip || x is MyPrefabHangar) && ((IMyInventory)x).Inventory != null,
            //        MySmallShipConstants.DETECT_SHIP_RADIUS)));
            //detectingCriteria.DetectingCriteria.Add(
            //    new MyDetectingCriterium(
            //        MyDetectedEntityAction.TradeForMoney,
            //        new MyDetectingCondition<MyEntity>(
            //            x => (MyFactions.GetFactionsRelation(this.Faction, x.Faction) == MyFactionRelationEnum.Neutral) && (x is MySmallShip || x is MyPrefabHangar) && !x.IsCripple() && ((IMyInventory)x).Inventory != null,
            //            MySmallShipConstants.DETECT_SHIP_RADIUS)));
            //detectingCriteria.DetectingCriteria.Add(
            //    new MyDetectingCriterium(
            //        MyDetectedEntityAction.Steal,
            //        new MyDetectingCondition<MyEntity>(
            //            x => (MyFactions.GetFactionsRelation(this.Faction, x.Faction) == MyFactionRelationEnum.Enemy || MyFactions.GetFactionsRelation(this.Faction, x.Faction) == MyFactionRelationEnum.Neutral) && x.IsCripple() && x is MySmallShip,
            //            MySmallShipConstants.DETECT_SHIP_RADIUS)));
            //detectingCriteria.DetectingCriteria.Add(
            //    new MyDetectingCriterium(
            //        MyDetectedEntityAction.Build,
            //    //new MyDetectingCondition<MyFoundationFactory>(
            //    //    x => true,
            //        new MyDetectingCondition<MyPrefabContainer>(
            //            x => (MyFactions.GetFactionsRelation(this.Faction, x.Faction) == MyFactionRelationEnum.Friend) && x.ContainsPrefab(PrefabTypesFlagEnum.FoundationFactory),
            //            MySmallShipConstants.DETECT_FOUNDATION_FACTORY_RADIUS)));

            //ShipDetector = new MyShipDetector(this, detectingCriteria);

            List<IMyEntityDetectorCriterium> tradeCriterias = new List<IMyEntityDetectorCriterium>()
                {
                    new MyEntityDetectorCriterium<MyEntity>((int)MySmallShipInteractionActionEnum.TradeForFree, 
                        MySmallShipInteraction.CanTradeForFree, true, this),                    
                    new MyEntityDetectorCriterium<MyEntity>((int)MySmallShipInteractionActionEnum.TradeForMoney, 
                        MySmallShipInteraction.CanTrade, true, this),
                    new MyEntityDetectorCriterium<MySmallShip>((int)MySmallShipInteractionActionEnum.Loot, 
                        MySmallShipInteraction.CanLootShip, true, this),
                    new MyEntityDetectorCriterium<MyCargoBox>((int)MySmallShipInteractionActionEnum.Examine,
                        MySmallShipInteraction.CanExamineCargoBox, true, this),
                    new MyEntityDetectorCriterium<MyCargoBox>((int)MySmallShipInteractionActionEnum.ExamineEmpty,
                        MySmallShipInteraction.CanExamineEmptyCargoBox, true, this),
                    new MyEntityDetectorCriterium<MyEntity>((int)MySmallShipInteractionActionEnum.Blocked, 
                        MySmallShipInteraction.IsBlocked, true, this),
                };
            List<IMyEntityDetectorCriterium> buildCriterias = new List<IMyEntityDetectorCriterium>()
                {
                    new MyEntityDetectorCriterium<MyPrefabContainer>((int) MySmallShipInteractionActionEnum.Build,
                        MySmallShipInteraction.CanBuild, this)
                };
            List<IMyEntityDetectorCriterium> motherShipCriterias = new List<IMyEntityDetectorCriterium>()
                {
                    new MyEntityDetectorCriterium<MyPrefabHangar>(1, MySmallShipInteraction.IsNearMothership, true, this)
                };
            List<IMyEntityDetectorCriterium> useableEntityCriterias = new List<IMyEntityDetectorCriterium>()
                {
                    new MyEntityDetectorCriterium<MyEntity>((int)MySmallShipInteractionActionEnum.Use, 
                        MySmallShipInteraction.CanUse, true, this),
                    new MyEntityDetectorCriterium<MyEntity>((int)MySmallShipInteractionActionEnum.Hack, 
                        MySmallShipInteraction.CanHack, true, this),
                };

            TradeDetector = new MyEntityDetector();
            TradeDetector.Init(null, new MyMwcObjectBuilder_EntityDetector(new Vector3(MySmallShipConstants.DETECT_SHIP_RADIUS * 2f, 0f, 0f), MyMwcObjectBuilder_EntityDetector_TypesEnum.Sphere), this, WorldMatrix, tradeCriterias);
            TradeDetector.OnNearestEntityChange += OnNearestDetectedEntityChanged;
            TradeDetector.OnNearestEntityCriteriasChange += OnNearestDetectedEntityCriteriasChanged;

            BuildDetector = new MyEntityDetector();
            BuildDetector.Init(null, new MyMwcObjectBuilder_EntityDetector(new Vector3(MySmallShipConstants.DETECT_FOUNDATION_FACTORY_RADIUS * 2f, 0f, 0f), MyMwcObjectBuilder_EntityDetector_TypesEnum.Sphere), this, WorldMatrix, buildCriterias);
            BuildDetector.OnNearestEntityChange += OnNearestDetectedEntityChanged;
            BuildDetector.OnNearestEntityCriteriasChange += OnNearestDetectedEntityCriteriasChanged;

            MotherShipDetector = new MyEntityDetector();
            MotherShipDetector.Init(null, new MyMwcObjectBuilder_EntityDetector(new Vector3(MySmallShipConstants.DETECT_SHIP_RADIUS * 2f, 0f, 0f), MyMwcObjectBuilder_EntityDetector_TypesEnum.Sphere), this, WorldMatrix, motherShipCriterias);
            MotherShipDetector.OnNearestEntityChange += OnNearestDetectedEntityChanged;
            MotherShipDetector.OnNearestEntityCriteriasChange += OnNearestDetectedEntityCriteriasChanged;

            UseableEntityDetector = new MyEntityDetector();
            UseableEntityDetector.Init(null, new MyMwcObjectBuilder_EntityDetector(new Vector3(MySmallShipConstants.DETECT_SHIP_RADIUS * 2f, 0f, 0f), MyMwcObjectBuilder_EntityDetector_TypesEnum.Sphere), this, WorldMatrix, useableEntityCriterias);
            UseableEntityDetector.OnNearestEntityChange += OnNearestDetectedEntityChanged;
            UseableEntityDetector.OnNearestEntityCriteriasChange += OnNearestDetectedEntityCriteriasChanged;
        }
Пример #2
0
        void CreateDetectorForParticleEffect()
        {
            m_smallShipDetector = new MyEntityDetector();

            m_smallShipDetector.Init(
                null,
                new MyMwcObjectBuilder_EntityDetector(
                    new Vector3(MyDummyPointConstants.PARTICLE_DETECTOR_SIZE * UserScale, 0, 0),
                    MyMwcObjectBuilder_EntityDetector_TypesEnum.Sphere),
                this,
                WorldMatrix,
                new List<IMyEntityDetectorCriterium>());

            m_smallShipDetector.Save = false;
            m_smallShipDetector.SetSensorDetectRigidBodyTypes(MyConstants.RIGIDBODY_TYPE_SHIP);

            m_smallShipDetector.On();
        }