UnitTeam.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. """
  2. This file is part of RuneOptimizer.
  3. RuneOptimizer is free software: you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the Free
  5. Software Foundation, either version 3 of the License, or (at your option)
  6. any later version.
  7. RuneOptimizer is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. RuneOptimizer. If not, see <https://www.gnu.org/licenses/>.
  13. """
  14. import database.database as database
  15. class UnitTeam():
  16. """
  17. A team of a unit.
  18. Very similar to the Team class, but this one doesn't load units, so it's
  19. safe to have as property of Unit.
  20. Parameters
  21. ----------
  22. id : str
  23. Team identifier.
  24. name : str
  25. Team name.
  26. priority : int
  27. Team priority, from 1 to 50.
  28. """
  29. _id = None
  30. _name = ""
  31. _priority = 1
  32. def __init__(self, id=None):
  33. if id != None:
  34. self._load(id)
  35. def _load(self, id):
  36. cursor = database.CONNECTION.execute(
  37. "SELECT id, name, priority FROM teams WHERE id = ?",
  38. (id,)
  39. )
  40. row = cursor.fetchone()
  41. if row != None:
  42. self._id = str(row[0])
  43. self._name = str(row[1])
  44. self._priority = int(row[2])
  45. @property
  46. def id(self):
  47. return self._id
  48. @property
  49. def name(self):
  50. return self._name
  51. @property
  52. def priority(self):
  53. return self._priority