static public bool TryCalculatePath(NPC npc, NPCMoveToCommand NPCtc, BasicMap parentMap, BasicTile start, BasicTile end)
        {
            BasicMap mapToCheckIn;

            if (NPCtc.mapID == 0)
            {
                mapToCheckIn = parentMap;
            }
            else
            {
                mapToCheckIn = parentMap.subMaps.Find(m => m.identifier == NPCtc.mapID);
            }

            var chunks = MapChunk.returnChunkRadius(mapToCheckIn, start.mapPosition.Location.ToVector2(), 2);

            if (chunks.Count != 0)
            {
                List <BasicTile> tiles = new List <BasicTile>();
                foreach (var chunk in chunks)
                {
                    tiles.AddRange(mapToCheckIn.possibleTilesWithController(chunk.region, mapToCheckIn));
                }
                tiles = tiles.Distinct().ToList();
                var test = PathFinder.NewPathSearch(start, end, tiles);
                if (test != null && test.Count != 0)
                {
                    return(true);
                }
            }


            return(false);
        }
        public void ChangeCommand(int tick)
        {
            currentTimeCommand.EndOfCommand();
            var tempList = npcCommands.FindAll(command => command.CanBeActivated(currentTimeCommand, this) && command.IsWithinTimeBlock(tick));

            if (tempList.Count == 0)
            {
                tempList = npcCommands.FindAll(command => command.CanBeActivatedResetTest(currentTimeCommand, this) && command.IsWithinTimeBlock(tick));
            }
            currentTimeCommand = tempList[0];
            //currentTimeCommand = npcCommands[4];
            currentTimeCommand.areaIndex = 0;
            baseCharacter.speed          = currentTimeCommand.speed;
            baseCharacter.position       = ((baseCharacter.position / 64).ToPoint().ToVector2() * 64);
            if (currentTimeCommand.GetType() == typeof(NPCMoveToCommand))
            {
                baseCharacter.StartSpriteMoveHandler(currentTimeCommand.destination, currentTimeCommand.mapID, currentTimeCommand);
                bResetCycle = true;
            }

            bReachedDestinationAtLeastOnce       = false;
            currentTimeCommand.bCompletedCommand = false;
            currentTimeCommand.parentObject      = this;
            currentTimeCommand.Execute();
            skip : { }
        }
        public void ChangeCommandEdit(int index)
        {
            currentTimeCommand.EndOfCommand();
            currentTimeCommand           = npcCommands[index];
            currentTimeCommand.areaIndex = 0;
            baseCharacter.position       = ((baseCharacter.position / 64).ToPoint().ToVector2() * 64);
            baseCharacter.speed          = npcCommands[index].speed;
            baseCharacter.StartSpriteMoveHandler(currentTimeCommand.destination, currentTimeCommand.mapID, currentTimeCommand);

            bReachedDestinationAtLeastOnce       = false;
            currentTimeCommand.bCompletedCommand = false;
            currentTimeCommand.parentObject      = this;
            currentTimeCommand.Execute();
        }
        public bool CanBeActivatedResetTest(NPCMoveToCommand currentCommand, NPC npc)
        {
            if (!sbc.CanBeActivated())
            {
                return(false);
            }

            if (currentCommand == this)
            {
                return(false);
            }

            if (this.GetType() != typeof(NPCChangeMap))
            {
                if (parentObject == null)
                {
                    parentObject = npc;
                }
                if (parentObject.baseCharacter.currentMapToDisplayOn.identifier != mapID)
                {
                    return(false);
                }
            }
            else if (this.GetType() == typeof(NPCChangeMap))
            {
                if (parentObject == null)
                {
                    parentObject = npc;
                }

                if (parentObject.baseCharacter.position != currentCommand.destination)
                {
                    return(false);
                }
            }

            return(true);

            if (wayPointsToDestination.Count != 0 && wayPointsToDestination[0].mapPosition.Contains(destination))
            {
                return(true);
            }
            else
            {
                //   parentObject.baseCharacter.smh.Start(parentObject.baseCharacter,);
            }

            return(false);
        }
        public bool MustChangeCommand(int tick)
        {
            if (!currentTimeCommand.bCompletedCommand)
            {
                return(false);
            }
            if (npcCommands.Count < 2)
            {
                return(false);
            }
            var futureAvailableCommands = npcCommands.FindAll(command => command.CanBeActivated(currentTimeCommand, this));
            NPCMoveToCommand temp       = null;

            if (futureAvailableCommands.Count != 0)
            {
                if (futureAvailableCommands[0].IsWithinTimeBlock(tick))
                {
                    temp = futureAvailableCommands[0];
                }
                else
                {
                    int timeFinal          = futureAvailableCommands[0].tickStop;
                    var bestCommandInstead = futureAvailableCommands.FindLast(c => c.tickStart <tick && c.tickStop> tick);

                    temp = bestCommandInstead;
                }
            }
            // var temp = npcCommands.Find(command => command.CanBeActivated(currentTimeCommand, this) && command.IsWithinTimeBlock(tick));
            if (currentTimeCommand != temp && temp != null)
            {
                return(true);
            }
            else
            {
                if (temp == null && bResetCycle)
                {
                    bResetCycle = false;
                    return(true);
                }
                return(false);
            }
        }