1010 */
1111
1212public class OrdinaryThief extends Thief {
13-
14- /**
15- * Object the represents the party of the thief
16- */
17- private AssaultParty party ;
18-
13+ private int partyID ;
14+ private int roomID ;
1915 /**
2016 * Displacement of the thief
2117 */
2218 private int displacement ;
2319
24- /**
25- * True if the thief has a canvas
26- */
27- private boolean hasCanvas ;
28-
29- /**
30- * True if ordinary thief is in a party
31- */
32- private boolean inParty ;
33-
34- /**
35- * Array of Museum Rooms
36- */
37- private Museum .Room [] rooms ;
38-
3920 /**
4021 * General repository
4122 */
4223 private GeneralRepos repos ;
4324
44-
45- /**
46- * Set AssaultParty array
47- * @param partyID AssaultParty ID
48- * @param reset True if the party should be reset
49- */
50- public void setAssaultParty (int partyID , boolean reset ) {
51- logger (this , "Assault Party: " +partyID );
52- party = assaultParties [partyID ];
53- inParty = true ;
54- repos .setOrdinaryThiefSituation (getThiefID (), isInParty ());
55- if (reset ){
56- party .resetAssaultParty ();
57-
58- }
59- }
60-
61- /**
62- * Set the room of the party
63- * @param roomID Room ID
64- */
65- public void setRoomOfParty (int roomID ) {
66- party .setRoom (rooms [roomID ]);
67- repos .setApRId (getPartyID (), roomID );
68- }
69-
70- /**
71- * Get the displacement of the thief
72- * @return Displacement
73- */
74- public int getDisplacement () {
75- return displacement ;
76- }
77-
78- /**
79- * Get thief in party
80- * @return True if the thief is in a party
81- */
82- public boolean isInParty () {
83- return inParty ;
84- }
85-
86- /**
87- * Set thief in party
88- * @param inParty True if the thief is in a party
89- */
90- public void setInParty (boolean inParty ) {
91- this .inParty = inParty ;
92- }
93-
94-
95- /**
96- * Get the room of the thief
97- * @return True if the thief has a canvas
98- */
99- public boolean hasCanvas () {
100- return hasCanvas ;
101- }
102-
103- /**
104- * Set if the thief has a canvas
105- * @param hasCanvas True if the thief has a canvas
106- */
107- public void hasCanvas (boolean hasCanvas ) {
108- this .hasCanvas = hasCanvas ;
109- }
110-
111- /**
112- * Set the party of the thief
113- * @param party Party
114- */
115- public void setParty (AssaultParty party ) {
116- this .party = party ;
117- }
118-
119- /**
120- * Get the party of the thief
121- * @return Party
122- */
123- public AssaultParty getParty () {
124- return party ;
125- }
126-
127- /**
128- * Get the party ID of the thief
129- * @return Party ID
130- */
131- public int getPartyID () {
132- return party .getID ();
133-
134- }
135-
136- /**
137- * Get the thieves from the party
138- * @return Array of thieves
139- */
140- public int [] getThievesFromParty () {
141- return party .getThieves ();
142- }
143- /**
144- * Get the room ID of the party
145- * @return Room ID
146- */
147- public int getRoomID () {
148- return party .getRoom ().getID ();
149- }
150-
15125 /**
15226 * Ordinary Thief Constructor
15327 * @param threadName Thread name
@@ -163,27 +37,38 @@ public OrdinaryThief(String threadName, int thiefID, Museum museum, Concentratio
16337 super (threadName , thiefID , museum , concentrationSite , collectionSite , assaultParties ,repos );
16438 thiefState = OrdinaryThiefStates .CONCENTRATION_SITE ;
16539 displacement = random (MIN_DISPLACEMENT , MAX_DISPLACEMENT );
166- hasCanvas = false ;
167- inParty = false ;
168- rooms = museum .getRooms ();
16940 this .repos = repos ;
41+ partyID = roomID = -1 ;
17042 repos .setOrdinaryThiefDisplacement (thiefID , displacement );
17143 }
17244
45+ @ Override
46+ public String toString () {
47+ return super .toString () + " [Party: " + partyID + ", Room: " + roomID + "]" ;
48+ }
49+
17350 /**
17451 * Life cycle of the Ordinary Thief
17552 */
17653 @ Override
17754 public void run () {
17855 while (concentrationSite .amINeeded ()) {
179- if (concentrationSite .prepareExcursion ()) {
180- party .crawlIn ();
181- museum .rollACanvas ();
56+ int [] assaultData = concentrationSite .prepareExcursion ();
57+ if (assaultData != null ) {
58+ partyID = assaultData [0 ];
59+ roomID = assaultData [1 ];
60+ Museum .Room room = museum .getRoom (roomID );
61+ AssaultParty party = assaultParties [partyID ];
62+ party .crawlIn (room .getDistance (), displacement );
63+
64+ boolean hasCanvas = museum .rollACanvas (room .getID ());
65+ if (hasCanvas )
66+ room .setPaintings (room .getPaintings () - 1 );
18267 party .reverseDirection ();
183- party .crawlOut ();
184- collectionSite . handACanvas ();
185- setInParty ( false );
186- repos .setOrdinaryThiefSituation (getThiefID (), isInParty () );
68+ party .crawlOut (room . getDistance (), displacement );
69+
70+ collectionSite . handACanvas ( partyID , roomID , hasCanvas );
71+ repos .setOrdinaryThiefSituation (getThiefID (), false );
18772 } else break ;
18873 }
18974 }
0 commit comments