status_controller.rb 711 B

1234567891011121314151617181920212223242526272829303132
  1. class StatusController
  2. def self.edit_status(name, effect)
  3. if status = Status.find_by(name: name)
  4. status.update!(effect: effect)
  5. status.reload
  6. else
  7. status = Status.create(name: name, effect: effect)
  8. end
  9. status
  10. end
  11. def self.edit_char_status(status, amount, char)
  12. char_st = CharStatus.where(char_id: char.id).find_by(status_id: status.id)
  13. amt = amount.to_i
  14. if char_st && amt
  15. char_st.update(amount: char_st.amount + amt)
  16. char_st.reload
  17. char_st
  18. elsif amt
  19. CharStatus.create(
  20. char_id: char.id,
  21. status_id: status.id,
  22. amount: amt
  23. )
  24. else
  25. error_embed("Amount must be numerical!")
  26. end
  27. end
  28. end