status_controller.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. class StatusController
  2. def self.edit_status(name, effect, flag=nil)
  3. if status = Status.find_by(name: name)
  4. status.update!(effect: effect, amount: flag)
  5. status.reload
  6. else
  7. flag = flag ? flag : true
  8. status = Status.create(name: name, effect: effect, amount: flag)
  9. end
  10. status
  11. end
  12. def self.edit_char_status(char, status, amount=nil)
  13. char_st = CharStatus.where(char_id: char.id).find_by(status_id: status.id)
  14. amt = amount.to_i if amount
  15. if char_st && amt && status.amount
  16. char_st.update(amount: char_st.amount + amt)
  17. char_st.reload
  18. char_st
  19. elsif char_st && !status.amount
  20. error_embed("The user is already afflicted with #{status.name}")
  21. elsif amount && !amt && status.amount
  22. error_embed("Amount must be numerical!")
  23. elsif amt && status.amount
  24. CharStatus.create(
  25. char_id: char.id,
  26. status_id: status.id,
  27. amount: amt
  28. )
  29. elsif !status.amount
  30. CharStatus.create(
  31. char_id: char.id,
  32. status_id: status.id,
  33. )
  34. end
  35. end
  36. end