I have an idea that follows the story line of another story. The plot device is similar, but the setting, context, majority of characters (with the exception of maybe two or three), and outcomes are different. There are some similar scenes and dialogue. To me the story I'm following is influential and inspired me to write what I did, but how do I know if I infringed on someone's copyright? I definitely had to create a lot of the work from scratch, probably 70%. The other 30% is different (not copying verbatim) from but similar to the other work. I don't think my work will be grossly popular nor very profitable. I understand somebody coming after you if you made millions, but I hardly believe my work will bring in the millions.
It's a clear breach of copyright. You cannot use somebody else's characters or story. Fan Fiction is permitted at the original author's discretion but it cannot be sold.
With a few exceptions characters from works where the copyright has expired (70 years in the US) may be used e.g. Tarzan.
Think about it: if we could use other people's characters we could all be raking it in writing Harry Potter books.
Parody and Satire are exceptions but again - it's complicated.