I have some doubts about the state pattern, but I think it is better to ask one question at a time, so it is easier to focus on the answer.
The state pattern establishes which actions can be performed according to the state. So, if the context is in state A, I can perform actions 1, 2, and 3, for example.
However, my doubt is what happens when the action depends on other variables. For example, I have a valve that can be opened and closed. But to open it, it is only possible if the pressure is below a certain value.
In this case, the action "Open()" not only depends on the state but also on other conditions, such as the pressure in this case.
Should I pass this variable to the state object and perform the action through the state? It may seem a bit confusing to perform all the actions through the state.
Furthermore, what happens if there are many other variables apart from the state? Suppose the action depends on the state and five other variables, for example. If I perform the action through the state, in some way, I am giving more importance to the state than the other variables, and perhaps it is not very intuitive.
Continuing with the valve example, suppose it is in the closed state and I want to open the valve. But it depends on the pressure, temperature, and type of operator (a worker can't open it, but a high-level operator can). Is this a case to use the state pattern, or is there a better option? If it is a good candidate for the state pattern, how could I implement it?