This repository has been archived by the owner on Dec 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathzone.cpp
1064 lines (886 loc) · 35.3 KB
/
zone.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
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
===========================================================================
Copyright (c) 2010-2015 Darkstar Dev Teams
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
===========================================================================
*/
// TODO:
// нужно разделить класс czone на базовый и наследников. уже нарисовались: Standard, Rezident, Instance и Dinamis
// у каждой из указанных зон особое поведение
#include "../common/showmsg.h"
#include "../common/timer.h"
#include "../common/utils.h"
#include "../common/socket.h"
#include <string.h>
#include "battlefield.h"
#include "enmity_container.h"
#include "latent_effect_container.h"
#include "linkshell.h"
#include "map.h"
#include "message.h"
#include "party.h"
#include "spell.h"
#include "status_effect_container.h"
#include "treasure_pool.h"
#include "vana_time.h"
#include "zone.h"
#include "zone_entities.h"
#include "entities/npcentity.h"
#include "entities/petentity.h"
#include "entities/automatonentity.h"
#include "lua/luautils.h"
#include "packets/action.h"
#include "packets/char.h"
#include "packets/char_sync.h"
#include "packets/char_update.h"
#include "packets/entity_update.h"
#include "packets/inventory_assign.h"
#include "packets/inventory_finish.h"
#include "packets/inventory_item.h"
#include "packets/lock_on.h"
#include "packets/message_basic.h"
#include "packets/server_ip.h"
#include "packets/wide_scan.h"
#include "utils/battleutils.h"
#include "utils/charutils.h"
#include "utils/itemutils.h"
#include "utils/mobutils.h"
#include "utils/petutils.h"
#include "utils/zoneutils.h"
/************************************************************************
* *
* Cервер для обработки активности сущностей (по серверу на зону) без *
* активных областей *
* *
************************************************************************/
int32 zone_server(time_point tick, CTaskMgr::CTask* PTask)
{
std::any_cast<CZone*>(PTask->m_data)->ZoneServer(tick, false);
return 0;
}
/************************************************************************
* *
* Cервер для обработки активности сущностей (по серверу на зону) c *
* активными областями *
* *
************************************************************************/
int32 zone_server_region(time_point tick, CTaskMgr::CTask* PTask)
{
CZone* PZone = std::any_cast<CZone*>(PTask->m_data);
if ((tick - PZone->m_RegionCheckTime) < 800ms)
{
PZone->ZoneServer(tick, false);
}
else
{
PZone->ZoneServer(tick, true);
PZone->m_RegionCheckTime = tick;
}
return 0;
}
/************************************************************************
* *
* *
* *
************************************************************************/
int32 zone_update_weather(time_point tick, CTaskMgr::CTask* PTask)
{
CZone* PZone = std::any_cast<CZone*>(PTask->m_data);
if (!PZone->IsWeatherStatic())
{
PZone->UpdateWeather();
}
return 0;
}
/************************************************************************
* *
* Класс CZone *
* *
************************************************************************/
CZone::CZone(ZONEID ZoneID, REGIONTYPE RegionID, CONTINENTTYPE ContinentID)
{
ZoneTimer = nullptr;
m_zoneID = ZoneID;
m_zoneType = ZONETYPE_NONE;
m_regionID = RegionID;
m_continentID = ContinentID;
m_TreasurePool = 0;
m_BattlefieldHandler = nullptr;
m_Weather = WEATHER_NONE;
m_WeatherChangeTime = 0;
m_navMesh = nullptr;
m_zoneEntities = new CZoneEntities(this);
// settings should load first
LoadZoneSettings();
LoadZoneLines();
LoadZoneWeather();
LoadNavMesh();
}
CZone::~CZone()
{
delete m_zoneEntities;
}
/************************************************************************
* *
* Функции доступа к полям класса *
* *
************************************************************************/
ZONEID CZone::GetID()
{
return m_zoneID;
}
ZONETYPE CZone::GetType()
{
return m_zoneType;
}
REGIONTYPE CZone::GetRegionID()
{
return m_regionID;
}
CONTINENTTYPE CZone::GetContinentID()
{
return m_continentID;
}
uint32 CZone::GetIP()
{
return m_zoneIP;
}
uint16 CZone::GetPort()
{
return m_zonePort;
}
uint16 CZone::GetTax()
{
return m_tax;
}
WEATHER CZone::GetWeather()
{
return m_Weather;
}
uint32 CZone::GetWeatherChangeTime()
{
return m_WeatherChangeTime;
}
const int8* CZone::GetName()
{
return (const int8*)m_zoneName.c_str();
}
uint8 CZone::GetSoloBattleMusic()
{
return m_zoneMusic.m_bSongS;
}
uint8 CZone::GetPartyBattleMusic()
{
return m_zoneMusic.m_bSongM;
}
uint8 CZone::GetBackgroundMusicDay()
{
return m_zoneMusic.m_songDay;
}
uint8 CZone::GetBackgroundMusicNight()
{
return m_zoneMusic.m_songNight;
}
bool CZone::CanUseMisc(uint16 misc)
{
return (m_miscMask & misc) == misc;
}
bool CZone::IsWeatherStatic()
{
return m_WeatherVector.empty() || m_WeatherVector.size() == 1;
}
zoneLine_t* CZone::GetZoneLine(uint32 zoneLineID)
{
for (zoneLineList_t::const_iterator i = m_zoneLineList.begin();
i != m_zoneLineList.end();
i++)
{
if ((*i)->m_zoneLineID == zoneLineID)
{
return (*i);
}
}
return nullptr;
}
/************************************************************************
* *
* Загружаем ZoneLines, необходимые для правильного перемещения между *
* зонами. *
* *
************************************************************************/
void CZone::LoadZoneLines()
{
static const char fmtQuery[] = "SELECT zoneline, tozone, tox, toy, toz, rotation FROM zonelines WHERE fromzone = %u";
int32 ret = Sql_Query(SqlHandle, fmtQuery, m_zoneID);
if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0)
{
while (Sql_NextRow(SqlHandle) == SQL_SUCCESS)
{
zoneLine_t* zl = new zoneLine_t;
zl->m_zoneLineID = (uint32)Sql_GetIntData(SqlHandle, 0);
zl->m_toZone = (uint16)Sql_GetIntData(SqlHandle, 1);
zl->m_toPos.x = Sql_GetFloatData(SqlHandle, 2);
zl->m_toPos.y = Sql_GetFloatData(SqlHandle, 3);
zl->m_toPos.z = Sql_GetFloatData(SqlHandle, 4);
zl->m_toPos.rotation = (uint8)Sql_GetIntData(SqlHandle, 5);
m_zoneLineList.push_back(zl);
}
}
}
/************************************************************************
* *
* Загружаем параметры погоды *
* *
************************************************************************/
void CZone::LoadZoneWeather()
{
static const char* Query =
"SELECT "
"weather_day,"
"normal,"
"common,"
"rare "
"FROM zone_weather "
"WHERE zoneid = %u "
"ORDER BY weather_day";
int32 ret = Sql_Query(SqlHandle, Query, m_zoneID);
if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0)
{
while (Sql_NextRow(SqlHandle) == SQL_SUCCESS)
{
m_WeatherVector.insert(std::make_pair((uint16)Sql_GetUIntData(SqlHandle, 0), zoneWeather_t(Sql_GetIntData(SqlHandle, 1),
Sql_GetIntData(SqlHandle, 2), Sql_GetIntData(SqlHandle, 3))));
}
}
else
{
ShowFatalError(CL_RED"CZone::LoadZoneWeather: Cannot load zone weather (%u)\n" CL_RESET, m_zoneID);
}
}
/************************************************************************
* *
* Загружаем настройки зоны из базы *
* *
************************************************************************/
void CZone::LoadZoneSettings()
{
static const char* Query =
"SELECT "
"zone.name,"
"zone.zoneip,"
"zone.zoneport,"
"zone.music_day,"
"zone.music_night,"
"zone.battlesolo,"
"zone.battlemulti,"
"zone.tax,"
"zone.misc,"
"zone.zonetype,"
"bcnm.name "
"FROM zone_settings AS zone "
"LEFT JOIN bcnm_info AS bcnm "
"USING (zoneid) "
"WHERE zoneid = %u "
"LIMIT 1";
if (Sql_Query(SqlHandle, Query, m_zoneID) != SQL_ERROR &&
Sql_NumRows(SqlHandle) != 0 &&
Sql_NextRow(SqlHandle) == SQL_SUCCESS)
{
m_zoneName.insert(0, (const char*)Sql_GetData(SqlHandle, 0));
m_zoneIP = inet_addr((const char*)Sql_GetData(SqlHandle, 1));
m_zonePort = (uint16)Sql_GetUIntData(SqlHandle, 2);
m_zoneMusic.m_songDay = (uint8)Sql_GetUIntData(SqlHandle, 3); // background music (day)
m_zoneMusic.m_songNight = (uint8)Sql_GetUIntData(SqlHandle, 4); // background music (night)
m_zoneMusic.m_bSongS = (uint8)Sql_GetUIntData(SqlHandle, 5); // solo battle music
m_zoneMusic.m_bSongM = (uint8)Sql_GetUIntData(SqlHandle, 6); // party battle music
m_tax = (uint16)(Sql_GetFloatData(SqlHandle, 7) * 100); // tax for bazaar
m_miscMask = (uint16)Sql_GetUIntData(SqlHandle, 8);
m_zoneType = (ZONETYPE)Sql_GetUIntData(SqlHandle, 9);
if (Sql_GetData(SqlHandle, 10) != nullptr) // сейчас нельзя использовать bcnmid, т.к. они начинаются с нуля
{
m_BattlefieldHandler = new CBattlefieldHandler(this);
}
if (m_miscMask & MISC_TREASURE)
{
m_TreasurePool = new CTreasurePool(TREASUREPOOL_ZONE);
}
}
else
{
ShowFatalError(CL_RED"CZone::LoadZoneSettings: Cannot load zone settings (%u)\n" CL_RESET, m_zoneID);
}
}
void CZone::LoadNavMesh()
{
if (m_navMesh == nullptr)
{
m_navMesh = new CNavMesh((uint16)GetID());
}
char file[255];
memset(file, 0, sizeof(file));
snprintf(file, sizeof(file), "navmeshes/%s.nav", GetName());
if (!m_navMesh->load(file))
{
delete m_navMesh;
m_navMesh = nullptr;
}
}
/************************************************************************
* *
* Добавляем в зону MOB *
* *
************************************************************************/
void CZone::InsertMOB(CBaseEntity* PMob)
{
m_zoneEntities->InsertMOB(PMob);
}
/************************************************************************
* *
* Добавляем в зону NPC *
* *
************************************************************************/
void CZone::InsertNPC(CBaseEntity* PNpc)
{
m_zoneEntities->InsertNPC(PNpc);
}
void CZone::DeletePET(CBaseEntity* PPet)
{
m_zoneEntities->DeletePET(PPet);
}
/************************************************************************
* *
* Добавляем в зону PET (свободные targid 0x700-0x7FF) *
* *
************************************************************************/
void CZone::InsertPET(CBaseEntity* PPet)
{
m_zoneEntities->InsertPET(PPet);
}
/************************************************************************
* *
* Add a trust to the zone *
* *
************************************************************************/
void CZone::InsertTRUST(CBaseEntity* PTrust)
{
m_zoneEntities->InsertTRUST(PTrust);
}
void CZone::DeleteTRUST(CBaseEntity* PTrust)
{
m_zoneEntities->DeleteTRUST(PTrust);
}
/************************************************************************
* *
* Добавляем в зону активную область *
* *
************************************************************************/
void CZone::InsertRegion(CRegion* Region)
{
if (Region != nullptr)
{
m_regionList.push_back(Region);
}
}
/************************************************************************
* *
* Ищем группу для монстра. Для монстров, объединенных в группу *
* работает система взаимопомощи (link) *
* *
************************************************************************/
void CZone::FindPartyForMob(CBaseEntity* PEntity)
{
m_zoneEntities->FindPartyForMob(PEntity);
}
/************************************************************************
* *
* Транспотр отправляется, необходимо собрать пассажиров *
* *
************************************************************************/
void CZone::TransportDepart(uint16 boundary, uint16 zone)
{
m_zoneEntities->TransportDepart(boundary, zone);
}
/************************************************************************
* *
* *
* *
************************************************************************/
void CZone::SetWeather(WEATHER weather)
{
TPZ_DEBUG_BREAK_IF(weather >= MAX_WEATHER_ID);
if (m_Weather == weather)
return;
m_zoneEntities->WeatherChange(weather);
m_Weather = weather;
m_WeatherChangeTime = CVanaTime::getInstance()->getVanaTime();
m_zoneEntities->PushPacket(nullptr, CHAR_INZONE, new CWeatherPacket(m_WeatherChangeTime, m_Weather, tpzrand::GetRandomNumber(4, 28)));
}
void CZone::UpdateWeather()
{
uint32 CurrentVanaDate = CVanaTime::getInstance()->getDate(); // Current Vanadiel timestamp in minutes
uint32 StartFogVanaDate = (CurrentVanaDate - (CurrentVanaDate % VTIME_DAY)) + (VTIME_HOUR * 2); // Vanadiel timestamp of 2 AM in minutes
uint32 EndFogVanaDate = StartFogVanaDate + (VTIME_HOUR * 5); // Vanadiel timestamp of 7 AM in minutes
uint32 WeatherNextUpdate = 0;
uint32 WeatherDay = 0;
uint8 WeatherChance = 0;
// Random time between 3 minutes and 30 minutes for the next weather change
WeatherNextUpdate = (tpzrand::GetRandomNumber(180, 1801));
// Find the timestamp since the start of vanadiel
WeatherDay = CVanaTime::getInstance()->getVanaTime();
// Calculate what day we are on since the start of vanadiel time
// 1 Vana'diel Day = 57 minutes 36 seconds or 3456 seconds
WeatherDay = WeatherDay / 3456;
// The weather starts over again every 2160 days
WeatherDay = WeatherDay % WEATHER_CYCLE;
// Get a random number to determine which weather effect we will use
WeatherChance = tpzrand::GetRandomNumber(100);
zoneWeather_t&& weatherType = zoneWeather_t(0, 0, 0);
for (auto& weather : m_WeatherVector)
{
if (weather.first > WeatherDay)
{
break;
}
weatherType = weather.second;
}
uint8 Weather = 0;
// 15% chance for rare weather, 35% chance for common weather, 50% chance for normal weather
// * Percentages were generated from a 6 hour sample and rounded down to closest multiple of 5*
if (WeatherChance < 15) //15% chance to have the weather_rare
{
Weather = weatherType.rare;
}
else if (WeatherChance < 50) // 35% chance to have weather_common
{
Weather = weatherType.common;
}
else
{
Weather = weatherType.normal;
}
// Fog in the morning between the hours of 2 and 7 if there is not a specific elemental weather to override it
if ((CurrentVanaDate >= StartFogVanaDate) && (CurrentVanaDate < EndFogVanaDate) && (Weather < WEATHER_HOT_SPELL) && (GetType() > ZONETYPE_CITY))
{
Weather = WEATHER_FOG;
//Force the weather to change by 7 am
// 2.4 vanadiel minutes = 1 earth second
WeatherNextUpdate = (uint32)((EndFogVanaDate - CurrentVanaDate) * 2.4);
}
SetWeather((WEATHER)Weather);
luautils::OnZoneWeatherChange(GetID(), Weather);
//ShowDebug(CL_YELLOW"Zone::zone_update_weather: Weather of %s updated to %u\n" CL_RESET, PZone->GetName(), Weather);
CTaskMgr::getInstance()->AddTask(new CTaskMgr::CTask("zone_update_weather",
server_clock::now() + std::chrono::seconds(WeatherNextUpdate), this, CTaskMgr::TASK_ONCE, zone_update_weather));
}
/************************************************************************
* *
* Удаляем персонажа из зоны. Если запущен ZoneServer и персонажей *
* в зоне больше не осталось, то останавливаем ZoneServer *
* *
************************************************************************/
void CZone::DecreaseZoneCounter(CCharEntity* PChar)
{
m_zoneEntities->DecreaseZoneCounter(PChar);
if (ZoneTimer && m_zoneEntities->CharListEmpty())
{
ZoneTimer->m_type = CTaskMgr::TASK_REMOVE;
ZoneTimer = nullptr;
m_zoneEntities->HealAllMobs();
}
else
{
m_zoneEntities->DespawnPC(PChar);
}
CharZoneOut(PChar);
}
/************************************************************************
* *
* Добавляем персонажа в зону. Если ZoneServer не запущен то запускам. *
* Обязательно проверяем количество персонажей в зоне. *
* Максимальное число персонажей в одной зоне - 768 *
* *
************************************************************************/
void CZone::IncreaseZoneCounter(CCharEntity* PChar)
{
TPZ_DEBUG_BREAK_IF(PChar == nullptr);
TPZ_DEBUG_BREAK_IF(PChar->loc.zone != nullptr);
TPZ_DEBUG_BREAK_IF(PChar->PTreasurePool != nullptr);
PChar->targid = m_zoneEntities->GetNewTargID();
if (PChar->targid >= 0x700)
{
ShowError(CL_RED"CZone::InsertChar : targid is high (03hX)\n" CL_RESET, PChar->targid);
return;
}
m_zoneEntities->InsertPC(PChar);
if (!ZoneTimer && !m_zoneEntities->CharListEmpty())
{
createZoneTimer();
}
CharZoneIn(PChar);
}
/************************************************************************
* *
* Проверка видимости монстров персонажем. Дистанцию лучше вынести в *
* глобальную переменную (настройки сервера) *
* Именно в этой функции будем проверять агрессию мостров, чтобы не *
* вычислять distance несколько раз (например в ZoneServer) *
* *
************************************************************************/
void CZone::SpawnMOBs(CCharEntity* PChar)
{
m_zoneEntities->SpawnMOBs(PChar);
}
/************************************************************************
* *
* Проверка видимости питомцев персонажем. Для появления питомцев *
* используем UPDATE вместо SPAWN. SPAWN используется лишь при вызове *
* *
************************************************************************/
void CZone::SpawnPETs(CCharEntity* PChar)
{
m_zoneEntities->SpawnPETs(PChar);
}
void CZone::SpawnTRUSTs(CCharEntity* PChar)
{
m_zoneEntities->SpawnTRUSTs(PChar);
}
/************************************************************************
* *
* Проверка видимости NPCs персонажем. *
* *
************************************************************************/
void CZone::SpawnNPCs(CCharEntity* PChar)
{
m_zoneEntities->SpawnNPCs(PChar);
}
/************************************************************************
* *
* Проверка видимости персонажей. Смысл действий в том, что персонажи *
* сами себя обновляют и добавляются в списки других персонажей. *
* В оригинальной версии размер списка ограничен и изменяется в *
* пределах 25-50 видимых персонажей. *
* *
************************************************************************/
void CZone::SpawnPCs(CCharEntity* PChar)
{
m_zoneEntities->SpawnPCs(PChar);
}
/************************************************************************
* *
* Отображаем Moogle в MogHouse *
* *
************************************************************************/
void CZone::SpawnMoogle(CCharEntity* PChar)
{
m_zoneEntities->SpawnMoogle(PChar);
}
/************************************************************************
* *
* Отображаем транспотр в зоне (не хранится в основном списке) *
* *
************************************************************************/
void CZone::SpawnTransport(CCharEntity* PChar)
{
m_zoneEntities->SpawnTransport(PChar);
}
/************************************************************************
* *
* Получаем указатель на любую сущность в зоне по ее targid *
* *
************************************************************************/
CBaseEntity* CZone::GetEntity(uint16 targid, uint8 filter)
{
return m_zoneEntities->GetEntity(targid, filter);
}
/************************************************************************
* *
* Oбработка реакции мира на смену времени суток *
* *
************************************************************************/
void CZone::TOTDChange(TIMETYPE TOTD)
{
m_zoneEntities->TOTDChange(TOTD);
luautils::OnTOTDChange(m_zoneID, TOTD);
}
void CZone::SavePlayTime()
{
m_zoneEntities->SavePlayTime();
}
/************************************************************************
* *
* *
* *
************************************************************************/
CCharEntity* CZone::GetCharByName(int8* name)
{
return m_zoneEntities->GetCharByName(name);
}
CCharEntity* CZone::GetCharByID(uint32 id)
{
return m_zoneEntities->GetCharByID(id);
}
/************************************************************************
* *
* Отправляем глобальные пакеты *
* *
************************************************************************/
void CZone::PushPacket(CBaseEntity* PEntity, GLOBAL_MESSAGE_TYPE message_type, CBasicPacket* packet)
{
m_zoneEntities->PushPacket(PEntity, message_type, packet);
}
/************************************************************************
* *
* Wide Scan *
* *
************************************************************************/
void CZone::WideScan(CCharEntity* PChar, uint16 radius)
{
m_zoneEntities->WideScan(PChar, radius);
}
/************************************************************************
* *
* Cервер для обработки активности и статус-эффектов сущностей в зоне. *
* При любом раскладе последними должны обрабатываться персонажи *
* *
************************************************************************/
void CZone::ZoneServer(time_point tick, bool check_regions)
{
m_zoneEntities->ZoneServer(tick, check_regions);
if (m_BattlefieldHandler != nullptr)
{
m_BattlefieldHandler->HandleBattlefields(tick);
}
}
void CZone::ForEachChar(std::function<void(CCharEntity*)> func)
{
for (auto PChar : m_zoneEntities->GetCharList())
{
func((CCharEntity*)PChar.second);
}
}
void CZone::ForEachCharInstance(CBaseEntity* PEntity, std::function<void(CCharEntity*)> func)
{
for (auto PChar : m_zoneEntities->GetCharList())
{
func((CCharEntity*)PChar.second);
}
}
void CZone::ForEachMob(std::function<void(CMobEntity*)> func)
{
for (auto PMob : m_zoneEntities->m_mobList)
{
func((CMobEntity*)PMob.second);
}
}
void CZone::ForEachMobInstance(CBaseEntity* PEntity, std::function<void(CMobEntity*)> func)
{
for (auto PMob : m_zoneEntities->m_mobList)
{
func((CMobEntity*)PMob.second);
}
}
void CZone::ForEachTrust(std::function<void(CTrustEntity*)> func)
{
for (auto PTrust : m_zoneEntities->m_trustList)
{
func((CTrustEntity*)PTrust.second);
}
}
void CZone::ForEachTrustInstance(CBaseEntity* PEntity, std::function<void(CTrustEntity*)> func)
{
for (auto PTrust : m_zoneEntities->m_trustList)
{
func((CTrustEntity*)PTrust.second);
}
}
void CZone::ForEachNpc(std::function<void(CNpcEntity*)> func)
{
for (auto PNpc : m_zoneEntities->m_npcList)
{
func((CNpcEntity*)PNpc.second);
}
}
void CZone::createZoneTimer()
{
ZoneTimer = CTaskMgr::getInstance()->AddTask(
m_zoneName,
server_clock::now(),
this,
CTaskMgr::TASK_INTERVAL,
m_regionList.empty() ? zone_server : zone_server_region,
std::chrono::milliseconds((int)(1000 / server_tick_rate)));
}
void CZone::CharZoneIn(CCharEntity* PChar)
{
// ищем свободный targid для входящего в зону персонажа
PChar->loc.zone = this;
PChar->loc.zoning = false;
PChar->loc.destination = 0;
PChar->m_InsideRegionID = 0;
if (PChar->isMounted() && !CanUseMisc(MISC_MOUNT))
{
PChar->animation = ANIMATION_NONE;
PChar->StatusEffectContainer->DelStatusEffectSilent(EFFECT_MOUNTED);
}
if (PChar->m_Costume != 0)
{
PChar->m_Costume = 0;
PChar->StatusEffectContainer->DelStatusEffect(EFFECT_COSTUME);
}
PChar->ReloadPartyInc();
if (PChar->PParty != nullptr)
{
if (m_TreasurePool != nullptr)
{
PChar->PTreasurePool = m_TreasurePool;
PChar->PTreasurePool->AddMember(PChar);
}
else
{
PChar->PParty->ReloadTreasurePool(PChar);
}
}
else
{
PChar->PTreasurePool = new CTreasurePool(TREASUREPOOL_SOLO);
PChar->PTreasurePool->AddMember(PChar);
}
if (m_zoneType != ZONETYPE_DUNGEON_INSTANCED)
{
charutils::ClearTempItems(PChar);
PChar->PInstance = nullptr;
}
if (m_BattlefieldHandler)
if (auto PBattlefield = m_BattlefieldHandler->GetBattlefield(PChar, true))
PBattlefield->InsertEntity(PChar, true);
PChar->PLatentEffectContainer->CheckLatentsZone();
}
void CZone::CharZoneOut(CCharEntity* PChar)
{
for (regionList_t::const_iterator region = m_regionList.begin(); region != m_regionList.end(); ++region)
{
if ((*region)->GetRegionID() == PChar->m_InsideRegionID)
{
luautils::OnRegionLeave(PChar, *region);
break;
}
}
if (PChar->m_LevelRestriction != 0)
{
if (PChar->PParty)
{
if (PChar->PParty->GetSyncTarget() == PChar || PChar->PParty->GetLeader() == PChar)
{
PChar->PParty->SetSyncTarget(nullptr, 551);
}
if (PChar->PParty->GetSyncTarget() != nullptr)
{
uint8 count = 0;
for (uint32 i = 0; i < PChar->PParty->members.size(); ++i)
{
if (PChar->PParty->members.at(i) != PChar && PChar->PParty->members.at(i)->getZone() == PChar->PParty->GetSyncTarget()->getZone())
{
count++;
}
}
if (count < 2) //3, because one is zoning out - thus at least 2 will be left
{
PChar->PParty->SetSyncTarget(nullptr, 552);
}
}
}
PChar->StatusEffectContainer->DelStatusEffectSilent(EFFECT_LEVEL_SYNC);
PChar->StatusEffectContainer->DelStatusEffectSilent(EFFECT_LEVEL_RESTRICTION);
}
if (PChar->PLinkshell1 != nullptr)
{
PChar->PLinkshell1->DelMember(PChar);
}
if (PChar->PLinkshell2 != nullptr)
{
PChar->PLinkshell2->DelMember(PChar);
}
if (PChar->PTreasurePool != nullptr) // TODO: условие для устранения проблем с MobHouse, надо блин решить ее раз и навсегда
{
PChar->PTreasurePool->DelMember(PChar);
}
PChar->ClearTrusts(); // trusts don't survive zone lines
if (PChar->isDead())
charutils::SaveDeathTime(PChar);
PChar->loc.zone = nullptr;
if (PChar->status == STATUS_SHUTDOWN)
{
PChar->loc.destination = m_zoneID;
}
else
{
PChar->loc.prevzone = m_zoneID;
}
PChar->SpawnPCList.clear();
PChar->SpawnNPCList.clear();
PChar->SpawnMOBList.clear();