I am making a browser game, it's completely AJAX-based, so I am trying to create a proper RESTful API.
So, I have a User
model (basically, User
has weapon, health and action points).
So I have a users
resource. Now, I want to implement user attacks.
Scenario: user with id = 1
attacks user with id = 2
.
What I would do is like this:
- Send the following info (with POST-request):
- target_id (well, it's stored in ApplicationController from session)
- attacker_id
- weapon_id (weapon attacker uses to attack his target)
to/users/attacker_id/attack/
- Validate if user has enough action points and health for attack, if target is not dead yet. If these conditions fail - do nothing, if they succeed - decrease attackers action points and ammo, decrease target HP. All of this is done in model method called
attack
for attacker.
Is it a proper way in general or if there is a better, Rails way?
Thank you!