1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace OSS\CoreBundle\Entity;
|
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
6
|
|
|
use OSS\CoreBundle\Transfer\ScoreCalculator;
|
7
|
|
|
|
8
|
|
|
/**
|
9
|
|
|
* @ORM\Entity
|
10
|
|
|
* @ORM\HasLifecycleCallbacks
|
11
|
|
|
*/
|
12
|
|
|
class Manager
|
13
|
|
|
{
|
14
|
|
|
const MONEY_BEHAVIOUR_DEFENSIVE = 1;
|
15
|
|
|
const MONEY_BEHAVIOUR_NEUTRAL = 2;
|
16
|
|
|
const MONEY_BEHAVIOUR_OFFENSIVE = 3;
|
17
|
|
|
|
18
|
|
|
/**
|
19
|
|
|
* @var int
|
20
|
|
|
*
|
21
|
|
|
* @ORM\Id
|
22
|
|
|
* @ORM\GeneratedValue
|
23
|
|
|
* @ORM\Column(type="integer")
|
24
|
|
|
*/
|
25
|
|
|
private $id;
|
26
|
|
|
|
27
|
|
|
/**
|
28
|
|
|
* @var string
|
29
|
|
|
*
|
30
|
|
|
* @ORM\Column(type="string")
|
31
|
|
|
*/
|
32
|
|
|
private $name;
|
33
|
|
|
|
34
|
|
|
/**
|
35
|
|
|
* @var int
|
36
|
|
|
*
|
37
|
|
|
* @ORM\Column(type="integer")
|
38
|
|
|
*/
|
39
|
|
|
private $transferFactorTackling = 10;
|
40
|
|
|
|
41
|
|
|
/**
|
42
|
|
|
* @var int
|
43
|
|
|
*
|
44
|
|
|
* @ORM\Column(type="integer")
|
45
|
|
|
*/
|
46
|
|
|
private $transferFactorPassing = 10;
|
47
|
|
|
|
48
|
|
|
/**
|
49
|
|
|
* @var int
|
50
|
|
|
*
|
51
|
|
|
* @ORM\Column(type="integer")
|
52
|
|
|
*/
|
53
|
|
|
private $transferFactorShooting = 10;
|
54
|
|
|
|
55
|
|
|
/**
|
56
|
|
|
* @var int
|
57
|
|
|
*
|
58
|
|
|
* @ORM\Column(type="integer")
|
59
|
|
|
*/
|
60
|
|
|
private $transferFactorHeading = 10;
|
61
|
|
|
|
62
|
|
|
/**
|
63
|
|
|
* @var int
|
64
|
|
|
*
|
65
|
|
|
* @ORM\Column(type="integer")
|
66
|
|
|
*/
|
67
|
|
|
private $transferFactorSpeed = 10;
|
68
|
|
|
|
69
|
|
|
/**
|
70
|
|
|
* @var int
|
71
|
|
|
*
|
72
|
|
|
* @ORM\Column(type="integer")
|
73
|
|
|
*/
|
74
|
|
|
private $transferFactorCrossing = 10;
|
75
|
|
|
|
76
|
|
|
/**
|
77
|
|
|
* @var int
|
78
|
|
|
*
|
79
|
|
|
* @ORM\Column(type="integer")
|
80
|
|
|
*/
|
81
|
|
|
private $transferFactorTechnics = 10;
|
82
|
|
|
|
83
|
|
|
/**
|
84
|
|
|
* @var int
|
85
|
|
|
*
|
86
|
|
|
* @ORM\Column(type="integer")
|
87
|
|
|
*/
|
88
|
|
|
private $transferFactorIntelligence = 10;
|
89
|
|
|
|
90
|
|
|
/**
|
91
|
|
|
* @var int
|
92
|
|
|
*
|
93
|
|
|
* @ORM\Column(type="integer")
|
94
|
|
|
*/
|
95
|
|
|
private $transferFactorSafety = 10;
|
96
|
|
|
|
97
|
|
|
/**
|
98
|
|
|
* @var int
|
99
|
|
|
*
|
100
|
|
|
* @ORM\Column(type="integer")
|
101
|
|
|
*/
|
102
|
|
|
private $transferFactorDribbling = 10;
|
103
|
|
|
|
104
|
|
|
/**
|
105
|
|
|
* @var int
|
106
|
|
|
*
|
107
|
|
|
* @ORM\Column(type="integer")
|
108
|
|
|
*/
|
109
|
|
|
private $moneyBehaviour;
|
110
|
|
|
|
111
|
|
|
/**
|
112
|
|
|
* @var int
|
113
|
|
|
*
|
114
|
|
|
* @ORM\Column(type="integer")
|
115
|
|
|
*/
|
116
|
|
|
private $acceptTransferScoreOffset;
|
117
|
|
|
|
118
|
|
|
/**
|
119
|
|
|
* @var int
|
120
|
|
|
*
|
121
|
|
|
* @ORM\Column(type="integer")
|
122
|
|
|
*/
|
123
|
|
|
private $denyTransferScoreOffset;
|
124
|
|
|
|
125
|
|
|
/**
|
126
|
|
|
* @var Team
|
127
|
|
|
*
|
128
|
|
|
* @ORM\OneToOne(targetEntity="Team", inversedBy="manager")
|
129
|
|
|
*/
|
130
|
|
|
private $team;
|
131
|
|
|
|
132
|
|
|
/**
|
133
|
|
|
* @var ScoreCalculator
|
134
|
|
|
*/
|
135
|
|
|
private $transferScoreCalculator;
|
136
|
|
|
|
137
|
26 |
|
public function __construct()
|
138
|
|
|
{
|
139
|
26 |
|
$this->initTransferScoreCalculator();
|
140
|
26 |
|
}
|
141
|
|
|
|
142
|
|
|
/**
|
143
|
|
|
* @return string
|
144
|
|
|
*/
|
145
|
|
|
public function getName()
|
146
|
|
|
{
|
147
|
|
|
return $this->name;
|
148
|
|
|
}
|
149
|
|
|
|
150
|
|
|
/**
|
151
|
|
|
* @param string $name
|
152
|
|
|
*/
|
153
|
|
|
public function setName($name)
|
154
|
|
|
{
|
155
|
|
|
$this->name = $name;
|
156
|
|
|
}
|
157
|
|
|
|
158
|
|
|
/**
|
159
|
|
|
* @return int
|
160
|
|
|
*/
|
161
|
|
|
public function getMoneyBehaviour()
|
162
|
|
|
{
|
163
|
|
|
return $this->moneyBehaviour;
|
164
|
|
|
}
|
165
|
|
|
|
166
|
|
|
/**
|
167
|
|
|
* @param int $moneyBehaviour
|
168
|
|
|
*/
|
169
|
9 |
|
public function setMoneyBehaviour($moneyBehaviour)
|
170
|
|
|
{
|
171
|
9 |
|
$this->moneyBehaviour = $moneyBehaviour;
|
172
|
9 |
|
}
|
173
|
|
|
|
174
|
|
|
/**
|
175
|
|
|
* @return Team
|
176
|
|
|
*/
|
177
|
22 |
|
public function getTeam()
|
178
|
|
|
{
|
179
|
22 |
|
return $this->team;
|
180
|
|
|
}
|
181
|
|
|
|
182
|
|
|
/**
|
183
|
|
|
* @param Team $team
|
184
|
|
|
*/
|
185
|
21 |
|
public function setTeam(Team $team)
|
186
|
|
|
{
|
187
|
21 |
|
$this->team = $team;
|
188
|
21 |
|
if (null === $this->team->getManager()) {
|
189
|
19 |
|
$this->team->setManager($this);
|
190
|
19 |
|
}
|
191
|
21 |
|
}
|
192
|
|
|
|
193
|
|
|
/**
|
194
|
|
|
* @return int
|
195
|
|
|
*/
|
196
|
|
|
public function getId()
|
197
|
|
|
{
|
198
|
|
|
return $this->id;
|
199
|
|
|
}
|
200
|
|
|
|
201
|
|
|
/**
|
202
|
|
|
* @return int
|
203
|
|
|
*/
|
204
|
16 |
|
public function getTransferFactorMoneyBehaviour()
|
205
|
|
|
{
|
206
|
16 |
|
if (self::MONEY_BEHAVIOUR_DEFENSIVE == $this->moneyBehaviour) {
|
207
|
5 |
|
return 2;
|
208
|
12 |
|
} elseif (self::MONEY_BEHAVIOUR_OFFENSIVE == $this->moneyBehaviour) {
|
209
|
5 |
|
return 0.5;
|
210
|
|
|
} else {
|
211
|
8 |
|
return 1;
|
212
|
|
|
}
|
213
|
|
|
}
|
214
|
|
|
|
215
|
|
|
/**
|
216
|
|
|
* @return int
|
217
|
|
|
*/
|
218
|
|
|
public function getAcceptTransferScoreOffset()
|
219
|
|
|
{
|
220
|
|
|
return $this->acceptTransferScoreOffset;
|
221
|
|
|
}
|
222
|
|
|
|
223
|
|
|
/**
|
224
|
|
|
* @param int $acceptTransferScoreOffset
|
225
|
|
|
*/
|
226
|
1 |
|
public function setAcceptTransferScoreOffset($acceptTransferScoreOffset)
|
227
|
|
|
{
|
228
|
1 |
|
$this->acceptTransferScoreOffset = $acceptTransferScoreOffset;
|
229
|
1 |
|
}
|
230
|
|
|
|
231
|
|
|
/**
|
232
|
|
|
* @return int
|
233
|
|
|
*/
|
234
|
|
|
public function getDenyTransferScoreOffset()
|
235
|
|
|
{
|
236
|
|
|
return $this->denyTransferScoreOffset;
|
237
|
|
|
}
|
238
|
|
|
|
239
|
|
|
/**
|
240
|
|
|
* @param int $denyTransferScoreOffset
|
241
|
|
|
*/
|
242
|
1 |
|
public function setDenyTransferScoreOffset($denyTransferScoreOffset)
|
243
|
|
|
{
|
244
|
1 |
|
$this->denyTransferScoreOffset = $denyTransferScoreOffset;
|
245
|
1 |
|
}
|
246
|
|
|
|
247
|
|
|
/**
|
248
|
|
|
* @param int $transferOfferScore
|
249
|
|
|
*
|
250
|
|
|
* @return bool
|
251
|
|
|
*/
|
252
|
1 |
|
public function acceptTransferOffer($transferOfferScore)
|
253
|
|
|
{
|
254
|
1 |
|
return $transferOfferScore >= $this->acceptTransferScoreOffset;
|
255
|
|
|
}
|
256
|
|
|
|
257
|
|
|
/**
|
258
|
|
|
* @param int $transferOfferScore
|
259
|
|
|
*
|
260
|
|
|
* @return bool
|
261
|
|
|
*/
|
262
|
1 |
|
public function denyTransferOffer($transferOfferScore)
|
263
|
|
|
{
|
264
|
1 |
|
return $transferOfferScore <= $this->denyTransferScoreOffset;
|
265
|
|
|
}
|
266
|
|
|
|
267
|
|
|
/**
|
268
|
|
|
* @param Player[] $playersToInvestigate
|
269
|
|
|
*
|
270
|
|
|
* @return null|Player
|
271
|
|
|
*/
|
272
|
1 |
|
public function selectBestFittingPlayer(array $playersToInvestigate)
|
273
|
|
|
{
|
274
|
1 |
|
$pickedPlayer = null;
|
275
|
1 |
|
$bestScore = 0;
|
276
|
1 |
|
foreach ($playersToInvestigate as $player) {
|
277
|
1 |
|
if ($player->hasTeam() && $player->getTeam()->equals($this->team)) continue;
|
278
|
1 |
|
$score = $this->transferScoreCalculator->calculateBuyScore($player);
|
279
|
1 |
|
if ($score > $bestScore) {
|
280
|
1 |
|
$pickedPlayer = $player;
|
281
|
1 |
|
$bestScore = $score;
|
282
|
1 |
|
}
|
283
|
1 |
|
}
|
284
|
|
|
|
285
|
1 |
|
return $pickedPlayer;
|
286
|
|
|
}
|
287
|
|
|
|
288
|
|
|
/**
|
289
|
|
|
* @param Player $player
|
290
|
|
|
*
|
291
|
|
|
* @return TransferOffer
|
292
|
|
|
*/
|
293
|
1 |
|
public function createTransferOffer(Player $player)
|
294
|
|
|
{
|
295
|
1 |
|
$transfer = new TransferOffer();
|
296
|
1 |
|
$transfer->setPlayer($player);
|
297
|
1 |
|
$transfer->setOriginTeam($player->getTeam());
|
298
|
1 |
|
$transfer->setTargetTeam($this->team);
|
299
|
1 |
|
$transfer->setAmount($player->getMarketValue());
|
300
|
|
|
|
301
|
1 |
|
return $transfer;
|
302
|
|
|
}
|
303
|
|
|
|
304
|
|
|
/**
|
305
|
|
|
* @param Player $player
|
306
|
|
|
*
|
307
|
|
|
* @return int
|
308
|
|
|
*/
|
309
|
|
|
public function calculateSellScore(Player $player)
|
310
|
|
|
{
|
311
|
|
|
return $this->transferScoreCalculator->calculateSellScore($player);
|
312
|
|
|
}
|
313
|
|
|
|
314
|
|
|
/**
|
315
|
|
|
* @param Player $player
|
316
|
|
|
*
|
317
|
|
|
* @return bool
|
318
|
|
|
*/
|
319
|
|
|
public function isSellAccepted(Player $player)
|
320
|
|
|
{
|
321
|
|
|
return $this->acceptTransferOffer($this->calculateSellScore($player));
|
322
|
|
|
}
|
323
|
|
|
|
324
|
|
|
/**
|
325
|
|
|
* @param Player $player
|
326
|
|
|
*
|
327
|
|
|
* @return bool
|
328
|
|
|
*/
|
329
|
|
|
public function isSellDenied(Player $player)
|
330
|
|
|
{
|
331
|
|
|
return $this->denyTransferOffer($this->calculateSellScore($player));
|
332
|
|
|
}
|
333
|
|
|
|
334
|
|
|
/**
|
335
|
|
|
* @ORM\PostLoad
|
336
|
|
|
*/
|
337
|
26 |
|
public function initTransferScoreCalculator()
|
338
|
|
|
{
|
339
|
26 |
|
$this->transferScoreCalculator = new ScoreCalculator($this);
|
340
|
26 |
|
}
|
341
|
|
|
|
342
|
|
|
/**
|
343
|
|
|
* @return int
|
344
|
|
|
*/
|
345
|
16 |
|
public function getTransferFactorTackling()
|
346
|
|
|
{
|
347
|
16 |
|
return $this->transferFactorTackling;
|
348
|
|
|
}
|
349
|
|
|
|
350
|
|
|
/**
|
351
|
|
|
* @param int $transferFactorTackling
|
352
|
|
|
*/
|
353
|
1 |
|
public function setTransferFactorTackling($transferFactorTackling)
|
354
|
|
|
{
|
355
|
1 |
|
$this->transferFactorTackling = $transferFactorTackling;
|
356
|
1 |
|
}
|
357
|
|
|
|
358
|
|
|
/**
|
359
|
|
|
* @return int
|
360
|
|
|
*/
|
361
|
16 |
|
public function getTransferFactorPassing()
|
362
|
|
|
{
|
363
|
16 |
|
return $this->transferFactorPassing;
|
364
|
|
|
}
|
365
|
|
|
|
366
|
|
|
/**
|
367
|
|
|
* @param int $transferFactorPassing
|
368
|
|
|
*/
|
369
|
|
|
public function setTransferFactorPassing($transferFactorPassing)
|
370
|
|
|
{
|
371
|
|
|
$this->transferFactorPassing = $transferFactorPassing;
|
372
|
|
|
}
|
373
|
|
|
|
374
|
|
|
/**
|
375
|
|
|
* @return int
|
376
|
|
|
*/
|
377
|
16 |
|
public function getTransferFactorShooting()
|
378
|
|
|
{
|
379
|
16 |
|
return $this->transferFactorShooting;
|
380
|
|
|
}
|
381
|
|
|
|
382
|
|
|
/**
|
383
|
|
|
* @param int $transferFactorShooting
|
384
|
|
|
*/
|
385
|
|
|
public function setTransferFactorShooting($transferFactorShooting)
|
386
|
|
|
{
|
387
|
|
|
$this->transferFactorShooting = $transferFactorShooting;
|
388
|
|
|
}
|
389
|
|
|
|
390
|
|
|
/**
|
391
|
|
|
* @return int
|
392
|
|
|
*/
|
393
|
16 |
|
public function getTransferFactorHeading()
|
394
|
|
|
{
|
395
|
16 |
|
return $this->transferFactorHeading;
|
396
|
|
|
}
|
397
|
|
|
|
398
|
|
|
/**
|
399
|
|
|
* @param int $transferFactorHeading
|
400
|
|
|
*/
|
401
|
|
|
public function setTransferFactorHeading($transferFactorHeading)
|
402
|
|
|
{
|
403
|
|
|
$this->transferFactorHeading = $transferFactorHeading;
|
404
|
|
|
}
|
405
|
|
|
|
406
|
|
|
/**
|
407
|
|
|
* @return int
|
408
|
|
|
*/
|
409
|
16 |
|
public function getTransferFactorSpeed()
|
410
|
|
|
{
|
411
|
16 |
|
return $this->transferFactorSpeed;
|
412
|
|
|
}
|
413
|
|
|
|
414
|
|
|
/**
|
415
|
|
|
* @param int $transferFactorSpeed
|
416
|
|
|
*/
|
417
|
|
|
public function setTransferFactorSpeed($transferFactorSpeed)
|
418
|
|
|
{
|
419
|
|
|
$this->transferFactorSpeed = $transferFactorSpeed;
|
420
|
|
|
}
|
421
|
|
|
|
422
|
|
|
/**
|
423
|
|
|
* @return int
|
424
|
|
|
*/
|
425
|
16 |
|
public function getTransferFactorCrossing()
|
426
|
|
|
{
|
427
|
16 |
|
return $this->transferFactorCrossing;
|
428
|
|
|
}
|
429
|
|
|
|
430
|
|
|
/**
|
431
|
|
|
* @param int $transferFactorCrossing
|
432
|
|
|
*/
|
433
|
1 |
|
public function setTransferFactorCrossing($transferFactorCrossing)
|
434
|
|
|
{
|
435
|
1 |
|
$this->transferFactorCrossing = $transferFactorCrossing;
|
436
|
1 |
|
}
|
437
|
|
|
|
438
|
|
|
/**
|
439
|
|
|
* @return int
|
440
|
|
|
*/
|
441
|
16 |
|
public function getTransferFactorTechnics()
|
442
|
|
|
{
|
443
|
16 |
|
return $this->transferFactorTechnics;
|
444
|
|
|
}
|
445
|
|
|
|
446
|
|
|
/**
|
447
|
|
|
* @param int $transferFactorTechnics
|
448
|
|
|
*/
|
449
|
|
|
public function setTransferFactorTechnics($transferFactorTechnics)
|
450
|
|
|
{
|
451
|
|
|
$this->transferFactorTechnics = $transferFactorTechnics;
|
452
|
|
|
}
|
453
|
|
|
|
454
|
|
|
/**
|
455
|
|
|
* @return int
|
456
|
|
|
*/
|
457
|
16 |
|
public function getTransferFactorIntelligence()
|
458
|
|
|
{
|
459
|
16 |
|
return $this->transferFactorIntelligence;
|
460
|
|
|
}
|
461
|
|
|
|
462
|
|
|
/**
|
463
|
|
|
* @param int $transferFactorIntelligence
|
464
|
|
|
*/
|
465
|
|
|
public function setTransferFactorIntelligence($transferFactorIntelligence)
|
466
|
|
|
{
|
467
|
|
|
$this->transferFactorIntelligence = $transferFactorIntelligence;
|
468
|
|
|
}
|
469
|
|
|
|
470
|
|
|
/**
|
471
|
|
|
* @return int
|
472
|
|
|
*/
|
473
|
16 |
|
public function getTransferFactorSafety()
|
474
|
|
|
{
|
475
|
16 |
|
return $this->transferFactorSafety;
|
476
|
|
|
}
|
477
|
|
|
|
478
|
|
|
/**
|
479
|
|
|
* @param int $transferFactorSafety
|
480
|
|
|
*/
|
481
|
|
|
public function setTransferFactorSafety($transferFactorSafety)
|
482
|
|
|
{
|
483
|
|
|
$this->transferFactorSafety = $transferFactorSafety;
|
484
|
|
|
}
|
485
|
|
|
|
486
|
|
|
/**
|
487
|
|
|
* @return int
|
488
|
|
|
*/
|
489
|
16 |
|
public function getTransferFactorDribbling()
|
490
|
|
|
{
|
491
|
16 |
|
return $this->transferFactorDribbling;
|
492
|
|
|
}
|
493
|
|
|
|
494
|
|
|
/**
|
495
|
|
|
* @param int $transferFactorDribbling
|
496
|
|
|
*/
|
497
|
|
|
public function setTransferFactorDribbling($transferFactorDribbling)
|
498
|
|
|
{
|
499
|
|
|
$this->transferFactorDribbling = $transferFactorDribbling;
|
500
|
|
|
}
|
501
|
|
|
}
|
502
|
|
|
|