问题描述:

The following code is responsible to perform attacks against mobs (aka. monsters) and I want to know if the best way to place this behavior is in the Player's model.

class Player < ActiveRecord::Base

belongs_to :kind, dependent: :destroy

def attack(mob, min_damage, max_damage)

[Mob.find(mob).name, rand(min_damage..max_damage)]

end

end

Thinking in the logic: players attack monsters.

Am I right to turning this idea into code through Player's model? Or should I create a specific model just to perform this kind of behaviors?

网友答案:

I think an Move model can be good for your game. With an action model, you can specify it is a magical or physical attack, you can apply modifiers in terms of residual damage, critical hits, etc.
Also, i believe the monster can attack the player too, so with a separate model, all you need to do is create and instance of it passing the parameters/modifiers you want.

相关阅读:
Top