Пример #1
0
        private void addNPC(NPCBasicMover npc)
        {
            npcsSpawned.Add(npc);
            var matrix = MyAPIGateway.Session.Player.Character.WorldMatrix;
            var offset = calcOffset(npcsSpawned.Count, matrix.Forward * 2, matrix.Right * 2);

            offsets[npc.ID] = offset;
        }
Пример #2
0
        public static NPCBasicMover getElite(IMySlimBlock npc)
        {
            var npcDataAnimator = new NPCDataAnimator(npc.CubeGrid, npc, 12f);
            var eliteMover      = new NPCBasicMover(npcDataAnimator, 180, 4f,
                                                    0.5f, "NPC_Elite", 9000);

            npc.CubeGrid.Physics.Friction = 2f;

            return(eliteMover);
        }
Пример #3
0
        public static NPCBasicMover getEngineer(IMySlimBlock npc)
        {
            var npcDataAnimator = new NPCDataAnimator(npc.CubeGrid, npc, 6f);
            var basicMover      = new NPCBasicMover(npcDataAnimator, 120, 1f,
                                                    1f, "NPC_Basic", 3000);

            npc.CubeGrid.Physics.Friction = 1.5f;

            return(basicMover);
        }
Пример #4
0
        public override void UpdateBeforeSimulation()
        {
            ticks++;
            if (ticks == 5)
            {
                try {
                    loadSettings();
                }
                catch (Exception ex) {
                    MyLog.Default.WriteLine("caught excetion while loading settings: " + ex);
                }
            }

            if (ticks < 6)
            {
                return;
            }

            updateNPCSpawn();
            updateNPCList();
            updateMode(block);
            updateInput();
            checkDeleteMarker();

            switch (selectedMode)
            {
            case NPCMode.patrol:
                updatePatrols(block);
                break;

            case NPCMode.attack:
                attackPointOrder(block);
                break;

            case NPCMode.stand:
                standAtPoint(block);
                NPCBasicMover.drawDebugLine(this.block.WorldMatrix.Translation, localToWorldPos(block, standPoint),
                                            Color.Gold);
                break;

            case NPCMode.follow:
                followPlayer(block);
                break;
            }

            updateTerminalInformation();

            if (ticks % 600 == 0)
            {
                saveSettings();
            }
        }
Пример #5
0
        private void updateMovement()
        {
            bool hasTarget = !CurrentMovementTarget.Equals(Vector3.Zero);


            var grid            = animator.grid;
            var gridWorldMatrix = grid.WorldMatrix;

            var ownPos = grid.WorldMatrix.Translation;
            var down   = grid.Physics.Gravity;

            down.Normalize();
            if (relativeTo != null)
            {
                NPCBasicMover.drawDebugLine(ownPos, CurrentMovementTarget, Color.Gold);
            }

            if (Vector3.Distance(CurrentMovementTarget, ownPos) < 1f)
            {
                hasTarget = false;
            }

            var downRayTarget = ownPos + down * 1.5f;
            var forwardDir    = gridWorldMatrix.Backward;

            List <IHitInfo> hits     = new List <IHitInfo>();
            var             skipCast = true;

            if (MainNPCLoop.ticks % 10 == 0 || cachedSurfaceHit == null)
            {
                //TODO raycasts parallel/async using asyncraycast or parallelfor later
                MyAPIGateway.Physics.CastRay(ownPos - down * 0.3f, downRayTarget, hits);
                skipCast = false;
                flying   = hits.Count == 0;
            }

            if ((hits.Count > 0 || skipCast) && !flying)
            {
                doValidMoment(skipCast, hits, grid, forwardDir, hasTarget, ownPos);
            }
            else
            {
                animator.relativeMoveSpeed = 0f;
            }
        }
Пример #6
0
        private void followPlayer(IMyCubeBlock myCubeBlock)
        {
            var playerPos = MyAPIGateway.Session.Player.GetPosition();

            playerPos = NPCBasicMover.toSurfacePos(playerPos, MyAPIGateway.Session.Player.Character, playerPos);
            foreach (var npc in npcsSpawned)
            {
                var offset            = offsets[npc.ID];
                var npcPositionTarget = playerPos + offset;
                if (Vector3.Distance(npc.getCurrentWaypoint(), npcPositionTarget) < 1f)
                {
                    return;
                }

                npc.clearWaypointsConservingEnemy();
                npc.addWaypoint(npcPositionTarget);
            }
        }
Пример #7
0
        private void createNPCatPos(Vector3 pos, string subtype)
        {
            var color  = block.SlimBlock.ColorMaskHSV;
            var entity = MainNPCLoop.spawnNPC(block.OwnerId, color, pos, subtype);

            var gridBlocks = new List <IMySlimBlock>();

            (entity as IMyCubeGrid)?.GetBlocks(gridBlocks);
            NPCBasicMover npc = null;

            switch (subtype)
            {
            case "NPC_Basic":
                npc = NPCBasicMover.getEngineer(gridBlocks.First());
                break;

            case "NPC_Elite":
                npc = NPCBasicMover.getElite(gridBlocks.First());
                break;
            }

            block.GameLogic.GetAs <NPCControlBlock>()?.addNPC(npc);
        }