2005-04-22
[開発ログ]回復コマンドを書いてみたが
手探りで使っている Acrive Record の使い方やその他どうもすっきりしない。
class Heal < CoreCommand
def exec
doll_id = @options[0]
doll = @session.user.dolls.find(doll_id)
return nil unless doll.temp_states.find_all("expiration_time > now()").empty?
doll.temp_states.find_all("state = 'action_wait'").each{|s|s.destroy}
wait = 10
doll.temp_states.create(:state => "action_wait", :expiration_time => Time.now + wait)
d = 1
old_hp = doll.hp
doll.hp = old_hp + d
doll.hp = doll.state.hpmax if doll.hp > doll.state.hpmax
doll.save
doll.hp - old_hp
end
end
そもそもローカルの時間と DB の時間のズレが問題になりそうだし。後半のロジックももっと短く書けないものだろうか。 ツッコミお願いします。