-
Notifications
You must be signed in to change notification settings - Fork 2
/
UnitManager.cpp
657 lines (546 loc) · 20 KB
/
UnitManager.cpp
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
#include "stdafx.h"
#include "UnitManager.h"
#include "productionManager.h"
void UnitManager::init()
{
// 필드 자원
IMAGEMANAGER->addFrameImage("berry", "Images/이미지/오브젝트/resource/img_object_berry.bmp", 112, 56, 2, 1, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("rock", "Images/이미지/오브젝트/resource/img_object_rock.bmp", 112, 56, 2, 1, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("tree", "Images/이미지/오브젝트/resource/img_object_tree.bmp", 280, 168, 5, 1, true, RGB(255, 0, 255));
// 필드 드롭 아이템 (소비)
IMAGEMANAGER->addImage("berryDrop", "Images/이미지/아이템/berry.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("fishDrop", "Images/이미지/아이템/물고기.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("milkDrop", "Images/이미지/아이템/milk.bmp", 56, 56, true, RGB(255, 0, 255));
// 필드 드롭 아이템 (재료)
IMAGEMANAGER->addImage("rockDrop", "Images/이미지/아이템/돌.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("treeDrop", "Images/이미지/아이템/wood.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("ironOreDrop", "Images/이미지/아이템/Iron_ore.bmp", 40, 40, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("coalDrop", "Images/이미지/아이템/coal.bmp", 40, 40, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("ironBarDrop", "Images/이미지/아이템/괴철.bmp", 40, 40, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("goldBarDrop", "Images/이미지/아이템/금괴.bmp", 40, 40, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("goldOreDrop", "Images/이미지/아이템/금광석.bmp", 40, 40, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("brickDrop", "Images/이미지/아이템/brick.bmp", 40, 40, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("pooDrop", "Images/이미지/아이템/poo.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("leatherDrop", "Images/이미지/아이템/leather.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("skullHeadDrop", "Images/이미지/아이템/skullHead.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("arrowDrop", "Images/이미지/아이템/arrow.bmp", 62, 63, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("roast_fishDrop", "Images/이미지/아이템/roast_fish.bmp", 68, 69, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("roast_fishDrop_slot", "Images/이미지/아이템/roast_fish.bmp", 55, 55, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("SteelhDrop", "Images/이미지/아이템/Steel.bmp", 68, 69, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("high_class_SteelDrop", "Images/이미지/아이템/high_class_Steel.bmp", 68, 69, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("high_class_clothDrop", "Images/이미지/아이템/high_class_cloth.bmp", 64, 65, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("threadDrop", "Images/이미지/아이템/실.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("GlassDrop", "Images/이미지/아이템/유리.bmp", 56, 56, true, RGB(255, 0, 255));
// 필드 드롭 아이템 (장비)
IMAGEMANAGER->addImage("pickaxe1", "Images/이미지/아이템/곡괭이슬롯1.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("pickaxe2", "Images/이미지/아이템/곡괭이슬롯2.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("pickaxe3", "Images/이미지/아이템/곡괭이슬롯3.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("pickaxe4", "Images/이미지/아이템/곡괭이슬롯4.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("bowDrop1", "Images/이미지/아이템/bow_first.bmp", 50, 50, true, RGB(255, 0, 255));
IMAGEMANAGER->findImage("bowDrop1")->initForRotateImage(false);
IMAGEMANAGER->addImage("bowDrop2", "Images/이미지/아이템/bow_second.bmp", 50, 50, true, RGB(255, 0, 255));
IMAGEMANAGER->findImage("bowDrop2")->initForRotateImage(false);
IMAGEMANAGER->addImage("bowDrop3", "Images/이미지/아이템/bow_third.bmp", 50, 50, true, RGB(255, 0, 255));
IMAGEMANAGER->findImage("bowDrop3")->initForRotateImage(false);
IMAGEMANAGER->addImage("bowDrop4", "Images/이미지/아이템/bow_fourth.bmp", 50, 50, true, RGB(255, 0, 255));
IMAGEMANAGER->findImage("bowDrop4")->initForRotateImage(false);
IMAGEMANAGER->addImage("swordDrop1", "Images/이미지/아이템/칼슬롯1.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("swordDrop2", "Images/이미지/아이템/칼슬롯2.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("swordDrop3", "Images/이미지/아이템/칼슬롯3.bmp", 56, 56, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("swordDrop4", "Images/이미지/아이템/칼슬롯4.bmp", 56, 56, true, RGB(255, 0, 255));
// 플레이어 핸들 아이템
IMAGEMANAGER->addImage("carryBerry", "Images/이미지/아이템/berry.bmp", 30, 30, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("carryMilk", "Images/이미지/아이템/milk.bmp", 30, 30, true, RGB(255, 0, 255));
//에너미 - 해골
IMAGEMANAGER->addFrameImage("skull", "Images/이미지/NPC/해골idle2.bmp", 280, 112, 5, 2, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("skullAppear", "Images/이미지/NPC/해골Appear.bmp", 224, 56, 4, 1, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("skullAttack", "Images/이미지/NPC/해골attack.bmp", 393, 112, 3, 2, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("skullIdle", "Images/이미지/NPC/해골stay.bmp",224 ,112 , 4, 2, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("skullappa", "Images/이미지/NPC/skullitai.bmp", 56, 112, 1, 2, true, RGB(255, 0, 255));
//에너미 - 황소
IMAGEMANAGER->addFrameImage("cow", "Images/이미지/NPC/황소IDLE.bmp", 400, 100, 5, 2, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("cowWalk", "Images/이미지/NPC/황소WALK.bmp", 560, 100, 7, 2, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("cowDash", "Images/이미지/NPC/cowDash.bmp", 320, 100, 4, 2, true, RGB(255, 0, 255));
//에너미 - 유령
IMAGEMANAGER->addFrameImage("wraithAttack", "Images/이미지/NPC/레이스2.bmp", 1710, 400, 3, 2, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("wraithIdle", "Images/이미지/NPC/레이스IDLE2.bmp", 2280, 400, 4, 2, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("wraithBullet", "Images/이미지/NPC/레이스무기발사.bmp", 80, 600, 1, 2, true, RGB(255, 0, 255));
//에너미 - 악마
IMAGEMANAGER->addFrameImage("demonYell", "Images/이미지/NPC/small_demon_yell.bmp", 576, 128, 9, 2, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("demonIdle", "Images/이미지/NPC/small_demon_idle.bmp", 256, 128, 4, 2, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("demonWalk", "Images/이미지/NPC/small_demon_walk.bmp", 576, 102, 9, 2, true, RGB(255, 0, 255));
//에너미 - 무보스
IMAGEMANAGER->addFrameImage("muBoss", "Images/이미지/NPC/muboss_IDLE.bmp", 2898, 406, 9, 1, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("muBossCry", "Images/이미지/NPC/muBossCry.bmp", 1848, 406, 6, 1, true, RGB(255, 0, 255));
//에너미 - 슬라임
IMAGEMANAGER->addFrameImage("slime", "Images/이미지/NPC/slime_Idle2.bmp", 280, 70, 5, 1, true, RGB(255, 0, 255));
//IMAGEMANAGER->addFrameImage("slime", "Images/이미지/NPC/boss_slime.bmp", 280, 70, 4, 1, true, RGB(255, 0, 255));
//에너미 - (보스) 슬라임
//IMAGEMANAGER->addFrameImage("slimeBoss", "Images/이미지/NPC/boss_slime_test.bmp", 560, 112, 5, 1, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("slimeBoss", "Images/이미지/NPC/boss_slime(2).bmp", 448, 112, 4, 1, true, RGB(255, 0, 255));
//에너미 - 작은 무
IMAGEMANAGER->addFrameImage("smallMu", "Images/이미지/NPC/baby_mu_idle.bmp", 392, 70, 7, 1, true, RGB(255, 0, 255));
IMAGEMANAGER->addFrameImage("smallMuCry", "Images/이미지/NPC/baby_mu_cry.bmp", 336, 70, 6, 1, true, RGB(255, 0, 255));
// NPC
IMAGEMANAGER->addFrameImage("David", "Images/이미지/NPC/img_npc_David.bmp", 444, 88, 4, 1, true, RGB(255, 0, 255));
// 보물 상자
IMAGEMANAGER->addImage("treasureBox", "Images/이미지/오브젝트/treasureBox.bmp", 140, 132, true, RGB(255, 0, 255));
// 체력바
IMAGEMANAGER->addImage("hpBarBG", "Images/이미지/NPC/NPC체력(뒤).bmp", 50, 20, true, RGB(255, 0, 255));
IMAGEMANAGER->addImage("hpBar", "Images/이미지/NPC/NPC체력(앞).bmp", 40, 10, true, RGB(255, 0, 255));
// 투사체 매니저 생성
_projectileManager = new ProjectileManager;
_projectileManager->init();
_pProjectiles = _projectileManager->GetProjectile();
// 스폰 매니저 생성
//_spawnManager = new SpawnManager;
//_spawnManager->init();
SPAWNMANAGER->init();
damageCoef = 1;
expCoef = 1;
productionCoef = 1;
}
void UnitManager::release()
{
for(int i = 0 ; i < _vUnits.size(); i++)
SAFE_DELETE(_vUnits[i]);
_vUnits.clear();
_vEnemy.clear();
_vNpc.clear();
_projectileManager->release();
SAFE_DELETE(_projectileManager);
}
void UnitManager::update()
{
Sorting();
CheckRemoveUnit();
// 유닛 업데이트
for (int i = 0; i < _vUnits.size(); i++) {
if (_vUnits[i]->tag != TAG::PLAYER ) {
_vUnits[i]->update();
}
// 카메라 외곽과 NPC, 필드 아이템은 충돌처리 무시
RECT temp;
if (_vUnits[i]->tag == TAG::ITEM) continue;
if (_vUnits[i]->tag == TAG::NPC) continue;
if (!IntersectRect(&temp, &CAMERA->GetCameraRect(), &_vUnits[i]->rc)) continue;
// 투사체와 유닛간의 충돌처리
checkCollision(_vUnits[i]);
}
//_spawnManager->update();
SPAWNMANAGER->update();
if(_projectileManager)
_projectileManager->update();
EFFECTMANAGER->update();
}
void UnitManager::checkCollision(unit * p_unit)
{
for (int k = 0; k < PROJECTILE_MAX; k++) {
RECT temp;
if (!_pProjectiles[k].isAppear) continue; // 발사 안 된 투사체는 무시
// 유닛과 충돌한 투사체가 있다면
if (IntersectRect(&temp, &p_unit->rc, &RectMake(_pProjectiles[k].x,
_pProjectiles[k].y, _pProjectiles[k].width, _pProjectiles[k].height)))
{
// Enemy 투사체는 플레이어에게만 데미지 적용
if (_pProjectiles[k].isEnemyProjectTile)
{
if (p_unit->tag == TAG::PLAYER)
{
//SOUNDMANAGER->play("유령무기맞는소리", 0.4f);
//IMAGEMANAGER->findImage("스테미나")->setWidth(5);
_player->hurt(_pProjectiles[k].damage);
}
if (p_unit->tag != TAG::ENEMY) {
if(!_pProjectiles[k].isBrassing)
{
_pProjectiles[k].isAppear = false;
p_unit->hurt(_pProjectiles[k].damage, true);
}
}
}
// Player 투사체는 모든 유닛에게 데미지 적용
else {
if (p_unit->tag != TAG::PLAYER) {
// 4단계 화살 이펙트 출력
if (_pProjectiles[k].imgKey == "BowArrow") {
if (STATMANAGER->GetBowUpgradeCount() == 4)
EFFECTMANAGER->ShowEffectFrame("bowEff4", { p_unit->GetCenterX(), p_unit->GetCenterY() }, 1, true);
}
p_unit->hurt(_pProjectiles[k].damage);
_pProjectiles[k].isAppear = false;
if (p_unit->isDead())
{
if (p_unit->objKey == "skull")
SOUNDMANAGER->play("해골사망소리");
else if (p_unit->objKey == "cow")
SOUNDMANAGER->play("황소사망소리");
//스태니마 감소
STATMANAGER->setRight(5);
//그 유닛의 경험치 획득.
int t_exp = p_unit->exp;
if (t_exp > 0) {
t_exp = RANDOM->range(t_exp - 2, t_exp + 3);
POINT pt = { p_unit->rc.left, p_unit->rc.top };
string str = std::to_string(t_exp);
str.insert(0, "EXP ");
TEXTMANAGER->ShowFloatingText(str, pt, RGB(100, 255, 100), RGB(0, 0, 0));
STATMANAGER->IncreaseExp(t_exp);
}
}
}
}
}
}
}
void UnitManager::render(HDC hdc)
{
// 레이어 : Terrain
for (int i = 0; i < _vUnits.size(); i++) {
if ((*_vUnits[i]).layer == LAYER::TERRAIN) {
RECT temp;
if (!IntersectRect(&temp, &CAMERA->GetCameraRect(), &(*_vUnits[i]).rc)) continue;
(*_vUnits[i]).render(hdc);
}
}
EFFECTMANAGER->renderBack(hdc); // 이펙트 렌더
// 레이어 : Object
for (int i = 0; i < _vUnits.size(); i++) {
if ((*_vUnits[i]).layer == LAYER::OBJECT) {
RECT temp;
if (!IntersectRect(&temp, &CAMERA->GetCameraRect(), &(*_vUnits[i]).rc)) continue;
(*_vUnits[i]).render(hdc);
}
}
EFFECTMANAGER->renderFront(hdc); // 이펙트 렌더
if(_projectileManager)
_projectileManager->render(hdc);
}
bool compare(unit* i, unit* j) {
return (*i).GetCenterY() < (*j).GetCenterY();
}
// y축 정렬
void UnitManager::Sorting()
{
sort(_vUnits.begin(), _vUnits.end(), compare);
}
// 죽거나 제거해야될 객체는 삭제
void UnitManager::CheckRemoveUnit()
{
if (_vUnits.size() > 0) {
for (auto iter = _vUnits.begin(); iter != _vUnits.end();) {
if ((*iter)->isDead()) {
if ((*iter)->tag == TAG::BUILDING) {
PRODUCTIONMANAGER->removeBuildingRc((*iter)->rc);
}
SAFE_DELETE((*iter));
iter = _vUnits.erase(iter);
}
else
++iter;
}
}
if (_vEnemy.size() > 0) {
for (auto iter = _vEnemy.begin(); iter != _vEnemy.end();) {
if ((*iter)->isDead()) {
iter = _vEnemy.erase(iter);
}
else
++iter;
}
}
}
void UnitManager::AddUnits(ForagerPlayer* p_unit)
{
_player = p_unit;
_vUnits.push_back(p_unit);
// NPC 세팅
AddUnits("David", { WINSIZEX / 2 + 100, WINSIZEY / 2 + 100 }, false);
_map->setTileHasUnit(_map->GetTileIndex({ WINSIZEX / 2 + 100, WINSIZEY / 2 + 100 }));
_map->GetTileP(_map->GetTileIndex({ WINSIZEX / 2 + 100, WINSIZEY / 2 + 100 }))->canPass = false;
}
void UnitManager::AddUnits(skull* p_unit, bool test)
{
_vUnits.push_back(p_unit);
}
void UnitManager::AddUnits(wraith* p_unit, bool test)
{
_vUnits.push_back(p_unit);
}
void UnitManager::AddUnits(cow * p_unit, bool test)
{
_vUnits.push_back(p_unit);
}
void UnitManager::AddUnits(demon * p_unit, bool test)
{
_vUnits.push_back(p_unit);
}
void UnitManager::AddUnits(muBoss * p_unit, bool test)
{
_vUnits.push_back(p_unit);
}
void UnitManager::AddUnits(slime * p_unit, bool test)
{
_vUnits.push_back(p_unit);
}
void UnitManager::AddUnits(slimeBoss * p_unit, bool test)
{
_vUnits.push_back(p_unit);
}
void UnitManager::AddUnits(smallMu * p_unit, bool test)
{
_vUnits.push_back(p_unit);
}
void UnitManager::AddSlimeBoss(POINT p_ptPos, bool p_isReal, int p_hp)
{
slimeBoss* _slimeBoss = new slimeBoss;
_slimeBoss->setLinkMap(_map);
_slimeBoss->setEnemy("slimeBoss", "img_game_money_icon", _player, p_ptPos);
_slimeBoss->init(p_hp);
if(p_isReal)
_slimeBoss->setCanSpawn();
_vUnits.push_back(_slimeBoss);
_vEnemy.push_back(_slimeBoss);
}
void UnitManager::AddUnits(string p_unitName, POINT p_pos, bool enemyCheck, int p_hp)
{
// 에너미 생성
if (enemyCheck) {
//해골
if (p_unitName == "skull")
{
skull* _skull = new skull;
_skull->setLinkMap(_map);
_skull->setEnemy(p_unitName, "skullHeadDrop", _player, p_pos, p_hp);
_skull->init();
_vUnits.push_back(_skull);
_vEnemy.push_back(_skull);
}
//소
if (p_unitName == "cow")
{
cow* _cow = new cow;
_cow->setLinkMap(_map);
_cow->setEnemy(p_unitName, "milkDrop", _player, p_pos, p_hp);
_cow->init();
_vUnits.push_back(_cow);
_vEnemy.push_back(_cow);
}
//레이스
if (p_unitName == "wraithIdle")
{
wraith* _wraith = new wraith;
_wraith->setLinkMap(_map);
_wraith->setEnemy(p_unitName, "leatherDrop", _player, p_pos);
_wraith->init(p_hp);
_vUnits.push_back(_wraith);
_vEnemy.push_back(_wraith);
}
//데몬
if (p_unitName == "demonIdle")
{
demon* _demon = new demon;
_demon->setLinkMap(_map);
_demon->setEnemy(p_unitName, "img_game_money_icon", _player, p_pos, p_hp);
_demon->init();
_vUnits.push_back(_demon);
_vEnemy.push_back(_demon);
}
//무 보스
if (p_unitName == "muBoss")
{
muBoss* _muBoss = new muBoss;
_muBoss->setLinkMap(_map);
_muBoss->setEnemy(p_unitName, "img_game_money_icon", _player, p_pos);
_muBoss->init(p_hp);
_vUnits.push_back(_muBoss);
_vEnemy.push_back(_muBoss);
}
//슬라임
if (p_unitName == "slime")
{
slime* _slime = new slime;
_slime->setLinkMap(_map);
_slime->setEnemy(p_unitName, "img_game_money_icon", _player, p_pos, p_hp);
_slime->init();
_vUnits.push_back(_slime);
_vEnemy.push_back(_slime);
}
//작은 무
if (p_unitName == "smallMu")
{
smallMu* _smallMu = new smallMu;
_smallMu->setLinkMap(_map);
_smallMu->setEnemy(p_unitName, "img_game_money_icon", _player, p_pos, p_hp);
_smallMu->init();
_vUnits.push_back(_smallMu);
_vEnemy.push_back(_smallMu);
}
}
// NPC 생성
else {
if (p_unitName == "David")
{
npc* t_npc = new npc;
t_npc->setNpc(p_unitName, p_pos, &_player->rc);
_vUnits.push_back(t_npc);
_vNpc.push_back(t_npc);
}
}
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
}
// 유닛 추가
void UnitManager::AddUnits(string p_itemKey, POINT p_pos)
{
for (int i = 0; i < 3; i++) {
fieldItem* t_fieldItem = new fieldItem;
t_fieldItem->setFieldItem(p_pos, p_itemKey);
_vUnits.push_back(t_fieldItem);
}
if (p_itemKey == "rockDrop") {
if (RANDOM->range(3, 10) > 5) {
for (int i = 0; i < RANDOM->range(2) + 1; i++) {
fieldItem* t_fieldItem = new fieldItem;
t_fieldItem->setFieldItem(p_pos, "ironOreDrop");
_vUnits.push_back(t_fieldItem);
}
}
if (RANDOM->range(0, 5) < 3) {
for (int i = 0; i < RANDOM->range(2) + 1; i++) {
fieldItem* t_fieldItem = new fieldItem;
t_fieldItem->setFieldItem(p_pos, "goldOreDrop");
_vUnits.push_back(t_fieldItem);
}
}
}
}
void UnitManager::AddProduction(string p_itemKey, POINT p_pos)
{
if (p_itemKey == "arrowDrop") {
for (int i = 0; i < 3; i++) {
fieldItem* t_fieldItem = new fieldItem;
t_fieldItem->setFieldItem(p_pos, p_itemKey);
_vUnits.push_back(t_fieldItem);
}
}
else {
fieldItem* t_fieldItem = new fieldItem;
t_fieldItem->setFieldItem(p_pos, p_itemKey);
_vUnits.push_back(t_fieldItem);
}
}
int UnitManager::GetMonsterCount()
{
int t_monsterCount = 0;
for (int i = 0; i < _vUnits.size(); i++) {
if (_vUnits[i]->tag == TAG::ENEMY) {
t_monsterCount++;
}
}
return t_monsterCount;
}
void UnitManager::setLinkMap(earth * p_map)
{
_map = p_map;
//_spawnManager->setLinkMap(_map);
SPAWNMANAGER->setLinkMap(_map);
}
POINT UnitManager::GetPlayerFootPt()
{
return { CAMERA->GetRelativeX(_player->GetCenterX()) , CAMERA->GetRelativeY(_player->rc.bottom + 25) };
}
int UnitManager::GetCowCount()
{
int cowCount = 0;
for (int i = 0; i < _vUnits.size(); i++) {
if (_vUnits[i]->objKey == "cow") {
cowCount++;
}
}
return cowCount;
}
//빌딩 렙 찾기 없으면 -999리턴
int UnitManager::is_Building_level(string item_key)
{
for (int i = 0; i < _vUnits.size(); i++) {
if (_vUnits[i]->tag != TAG::BUILDING) continue;
if (_vUnits[i]->objKey == item_key) {
return _vUnits[i]->level;
}
}
return -999;
}
void UnitManager::is_Building_level_Up(string item_key)
{
for (int i = 0; i < _vUnits.size(); i++) {
if (_vUnits[i]->tag != TAG::BUILDING) continue;
if (_vUnits[i]->objKey == item_key) {
if(_vUnits[i]->level < 5){
_vUnits[i]->level++;
if (item_key == "goddess") {
damageCoef += 0.50;
}
if (item_key == "elvenstatue") {
expCoef += 0.50f;
}
if (item_key == "tombCenter") {
productionCoef -= 0.50f;
}
}
}
}
}
void UnitManager::AddBuilding(string buildkey, tile * _tile, int tileindex)
{
if (buildkey == "fishtrap") {
fishTrap *t_fishTrap = new fishTrap;
t_fishTrap->setFishTrap(buildkey, _tile, tileindex);
_vUnits.push_back(t_fishTrap);
}
else {
building* _building = new building;
_building->setBuilding(buildkey, _tile, tileindex);
_vUnits.push_back(_building);
}
}
void UnitManager::AddBuilding(string buildkey, vector<tile*> tiles, int tileindex)
{
building* _building = new building;
_building->setBuilding(buildkey, tiles, tileindex);
_vUnits.push_back(_building);
PRODUCTIONMANAGER->settion(_building->rc);
}
void UnitManager::AddSpecialBuilding(string buildkey, vector<tile*> tiles, int tileindex)
{
building* _building = new building;
_building->setSpecialBuilding(buildkey, tiles, tileindex);
_vUnits.push_back(_building);
PRODUCTIONMANAGER->settion(_building->rc);
if (buildkey == "goddess") {
damageCoef = 1.05f;
}
if (buildkey == "elvenstatue") {
expCoef = 1.05f;
}
if (buildkey == "tombCenter") {
productionCoef = 0.95f;
}
}
void UnitManager::AddResource(tile* p_tile, int p_tileIndex)
{
inGameResource* _res = new inGameResource;
_res->setRandomRes(p_tile, p_tileIndex);
_vUnits.push_back(_res);
}
void UnitManager::AddResource(string key, tile * _tile, int p_tileIndex)
{
inGameResource* _res = new inGameResource;
_res->setResource(key, _tile, p_tileIndex);
_vUnits.push_back(_res);
}
void UnitManager::AddTreasure(string p_key, string p_itemRewardKey, POINT p_ptPos)
{
treasureBox *t_tBox = new treasureBox;
t_tBox->setTreasureBox(p_key, p_itemRewardKey, p_ptPos, &_player->rc);
_vUnits.push_back(t_tBox);
}