-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpdesk.py
More file actions
88 lines (72 loc) · 3.59 KB
/
helpdesk.py
File metadata and controls
88 lines (72 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import math
import random
import resources
import settings
from asset import Asset
import incidents
from incidents import Incident, Expertise
class Helpdesk(Asset):
""" Le centre d'appels (helpdesk). """
def __init__(self, tile_position: tuple) -> None:
"""
Initialise une instance du centre d'appels (objet Helpdesk) et le positionne dans le bureau.
:param tile_position: position de tuile (x, y) dans le bureau
"""
super().__init__('Helpdesk', settings.HELPDESK_ASSET_ID, tile_position)
# contient la liste des expertises sollicitées par les incidents créés par le centre d'appels
self.__incident_types = list(Expertise)
# on ne crée pas d'incidents qui demandent une expertise de superhéro - à (presque) l'impossible nul n'est tenu
self.__incident_types.remove(Expertise.SUPERHERO)
# on ne crée pas non plus d'incidents pour le centre d'appels - il faut quand même s'aider...
self.__incident_types.remove(Expertise.HELPDESK)
self.__phone_sound = resources.sounds_collection.get(
'HELPDESK-PHONE-RING')
self._solve_sound = resources.sounds_collection.get(
'HELPDESK-PHONE-HANGUP')
# on veut que le téléphone sonne lorsqu'un incident arrive au centre d'appels
self.set_incoming_action(self._ring_the_phone)
# on veut que le téléphone cesse de sonner si la personne raccroche (incident expiré)
self.set_expiring_action(self._stop_the_phone)
def solve_incident(self) -> None:
"""
Rédéfinition de Asset:solve_incident().
Solutionne un incident du centre d'appels (helpdesk).
:return: aucun
"""
if self._active_incident:
if self._solving_action:
self._play_solve_sound()
remaining_percentage = self._active_incident.get_remaining_time_percentage()
self._solving_action(math.floor(remaining_percentage))
self._stop_the_phone()
self._active_incident.stop()
self._active_incident = None
# Redistribution de l'incident vers un actif autre que le centre d'appels
# en le renvoyant à travers le spawner
incident_type = random.choice(self.__incident_types)
# Initialisation des temps par défaut a 30/60
__time_to_solve_min = 30
__time_to_solve_max = 60
# Si les temps des settings sont valides, utiliser ceux cis plutot
if settings.DEFAULT_TIME_TO_SOLVE_MIN > 0 and settings.DEFAULT_TIME_TO_SOLVE_MAX > settings.DEFAULT_TIME_TO_SOLVE_MIN:
__time_to_solve_min = settings.DEFAULT_TIME_TO_SOLVE_MIN
__time_to_solve_max = settings.DEFAULT_TIME_TO_SOLVE_MAX
# Randomizer le time to solve par defaut et creer l'incident
time_to_solve = random.randint(
__time_to_solve_min, __time_to_solve_max)
incident = Incident(incident_type, time_to_solve)
incidents.spawner.put(incident)
def _ring_the_phone(self) -> None:
"""
Joue la sonnerie du téléphone.
:return: aucun
"""
# si la sonnerie n'est pas déjà en train de joueur... (le téléphone n'a qu'une sonnerie)
if self.__phone_sound.get_num_channels() == 0:
self.__phone_sound.play(-1)
def _stop_the_phone(self) -> None:
"""
Arrête la sonnerie du téléphone.
:return: aucun
"""
self.__phone_sound.stop()