Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

action.py 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. from django.db import models
  2. from polymorphic.models import PolymorphicModel
  3. # from .company import Company
  4. from .worker import Worker
  5. from .offer import Offer
  6. from .order import Order
  7. # Action und erbende Klassen
  8. class Action(PolymorphicModel):
  9. name = models.CharField(default="random Action", max_length=20)
  10. actionmaker = models.ForeignKey("Company", default=1, on_delete=models.CASCADE)
  11. def execute(self):
  12. pass
  13. def cancel(self):
  14. pass
  15. def addActionToCompany(self):
  16. self.actionmaker.addAction(self)
  17. def __str__(self):
  18. return self.name
  19. class ActionEmploy(Action):
  20. worker = models.ForeignKey(Worker, default=1, on_delete=models.CASCADE)
  21. @classmethod
  22. def create(cls, worker, actionmaker):
  23. # klassenobject erstellen
  24. name = "Hiring " + worker.name
  25. action = cls(name=name, worker=worker, actionmaker=actionmaker)
  26. action.save()
  27. # worker von market entferenen und action zu company hinzufügen
  28. actionmaker.removeFromWorkermarket(worker)
  29. action.addActionToCompany()
  30. return action
  31. def execute(self):
  32. self.worker.setStatus(1)
  33. self.worker.save()
  34. self.actionmaker.workers.add(self.worker)
  35. # Arbeiter zu Company hinzufügen
  36. def cancel(self):
  37. self.actionmaker.addToWorkermarket(self.worker)
  38. class ActionUnemploy(Action):
  39. worker = models.ForeignKey(Worker, null=True, blank=True, on_delete=models.CASCADE)
  40. @classmethod
  41. def create(cls, worker, actionmaker):
  42. # klassenobject erstellen
  43. name = "Firing " + worker.name
  44. action = cls(name=name, worker=worker, actionmaker=actionmaker)
  45. action.save()
  46. # workerstatus anpassen und action zu company hinzufügen
  47. actionmaker.workers.remove(worker)
  48. action.addActionToCompany()
  49. return action
  50. def execute(self):
  51. pass # self.worker.delete() hier das delete noch machbar machen
  52. def cancel(self):
  53. self.actionmaker.workers.add(self.worker)
  54. class ActionOffer(Action):
  55. order = models.ForeignKey(Order, default=1, on_delete=models.CASCADE)
  56. amount = models.IntegerField(default=0)
  57. @classmethod
  58. def create(cls, order, amount, actionmaker):
  59. # klassenobject erstellen
  60. name = "Offer for " + order.name
  61. action = cls(
  62. name=name,
  63. order=order,
  64. amount=amount,
  65. actionmaker=actionmaker,
  66. )
  67. action.save()
  68. # order von market entfernen und action zu company hinzufügen
  69. action.addActionToCompany()
  70. return action
  71. def execute(self):
  72. self.order.setStatus(1)
  73. self.order.save()
  74. offer = Offer.objects.create(
  75. company=self.actionmaker, amount=self.amount, order=self.order
  76. )
  77. self.order.offers.add(offer)
  78. # Angebot einer Order auf OrderMarket vorlegen
  79. def cancel(self):
  80. # bleibt leer actually
  81. pass
  82. class ActionCancelOrder(Action):
  83. order = models.ForeignKey(Order, default=1, on_delete=models.CASCADE)
  84. @classmethod
  85. def create(cls, order, actionmaker):
  86. # klassenobject erstellen
  87. name = "Cancel " + order.name
  88. action = cls(
  89. name=name,
  90. order=order,
  91. actionmaker=actionmaker,
  92. )
  93. action.save()
  94. # action zu company hinzufügen
  95. action.addActionToCompany()
  96. return action
  97. def execute(self):
  98. self.actionmaker.calculateCustomerSatisfaction(-30)
  99. self.order.cancelOrder()
  100. self.order.delete()
  101. def cancel(self):
  102. # bleibt leer actually
  103. pass
  104. class ActionTrain(Action):
  105. worker = models.ForeignKey(Worker, null=True, blank=True, on_delete=models.CASCADE)
  106. trainskill = models.CharField(default="empty", max_length=50)
  107. cost = models.IntegerField(default=1000)
  108. @classmethod
  109. def create(cls, worker, trainskill, actionmaker):
  110. # klassenobject erstellen
  111. name = "Train Worker " + worker.name
  112. action = cls(
  113. name=name,
  114. worker=worker,
  115. trainskill=trainskill,
  116. actionmaker=actionmaker,
  117. )
  118. # worker locken status 3
  119. worker.setStatus(3)
  120. action.save()
  121. # action zu company hinzufügen
  122. action.addActionToCompany()
  123. return action
  124. def execute(self):
  125. # Arbeiter in bestimmtem Skill verbesser und für eine runde locken
  126. self.worker.improveAttribute(attribute=self.trainskill, amount=10)
  127. self.worker.setLockedRounds(1)
  128. # trainingskosten zahlen
  129. self.actionmaker.addProfit(-self.cost)
  130. def cancel(self):
  131. self.worker.setStatus(1)