I have my web based rpg game already created. Inventory management, equipment system, character stats, skill tree, and etc. It's almost complete.
For the game world, I am creating a top-down rpg character movement and combat. With point and click. You click on a part of the map (in this case, it's a image, and your character .png image transitions to that spot). It's with Javascript and PHP. I'm using a PHP Websocket server. I have it where players can only move up to 200 pixels per each click. Each click is essentially a packet being sent to my gameserver. Then the gameserver validates if it's a valid input (1235x1235) format, and spits it out to other players in that specific game. (So it's a consistent world/map). This works perfect.
My question is: If I want to incorporate a monster that has AI and starts to attack the character... I can do that with javascript easily with setInterval or setTimeout functions (to make the mob move and then attack the character). But how do I do that serverside? Because a user could just press F12 and edit the javascript to stop the mob from attacking. But, I need the mob to attack the player every xxx milliseconds serverside as well. How is this done with PHP? I feel like I need some type of heartbeat going on where it's a constant check between client and server every xxx seconds? I might be going off on the deep end and I'll stop talking lol. But I hope you get the jist of it. Any ideas are greatly appreciated.
Another thought: Think of Diablo 2 or Path of Exile, and using a hack that just stops mobs from moving towards your character and attacking it. Is that just an illusion? And the "auto attacking" is done serverside regardless if you've stopped that mob on the client, right? If so, how to accomplisgh this with a PHP Websocket server, and some JS? I'm not looking for code, just an application theory or design process would help! :)
P.S. It's either I go this route, or the game becomes a simple real time strategy pokemon style combat. Which I really, really don't want...
No comments:
Post a Comment