#Now in other news Im trying to sit here
1 messages · Page 1 of 1 (latest)
i think im not the smartest person to help you here but ill try since you just helped me
btw writing on a topic so more capable people see your question instead of it getting hidden by my answer
first you should check if you are selecting an ability or moving, that info could be stored in a variable(lets call it IsUsingAbility) that switches when you press any ability(press it once, true, press the same ability again, false, press a different ability, true).
also when you press the ability just change its sprite to the cancel ability sprite and store the selected ability in some variable so you can check if you click it again or some different ability.
then in a update function check if IsUsingAbility is true, if it is then you will have to do a check for every tile near the mouse/player(depends on what youre trying to do, id prefer checking near the mouse) to see if its valid and send that to your RedrawHighlights function.
then if you are not using an ability just run an A* pathfinding(i have no idea what A* is, i searched and found a pathfinding algorithm so i hope were talking about the same A*) from the player tile to the tile the mouse is currently and send those tiles over to the HighlightDrawer.
if you want to not move or use abilities while stuff is happening just create a variable(lets call it StuffIsHappening) and set it to true/false at the start/end of the ability animation
if i didnt cover your question please tell me and ill write it again
tldr: this covers the logic behind using abilities
I think the tricky part is the redrawing portion, specifically...
It feels wasteful to do the A* algo to draw the path from Player->Mouse for highlights... and then also do it again when they click to re-calc it when we already "have" their path
maybe thats a silly hangup to have though, I guess, its not actually expensive to do 1 extra time, it runs in milliseconds, barely even notice it
This is what I ended up coming up with, should work
https://hatebin.com/ialusmqclw
The key lies in the fact my GameState stuff all implements INotifyPropertyChanged so if TryConsumeMutations succeeds in mutating any values, it will fire off appropriate logic in other services listening for those mutations
then store the path in an array and only update it when the mouse moves tiles and is not using an ability