forked from LeagueSandbox/GameServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPacketNotifier.cs
2962 lines (2684 loc) · 137 KB
/
PacketNotifier.cs
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
using ENet;
using GameServerCore;
using GameServerCore.Content;
using GameServerCore.Domain;
using GameServerCore.Domain.GameObjects;
using GameServerCore.Domain.GameObjects.Spell;
using GameServerCore.Domain.GameObjects.Spell.Missile;
using GameServerCore.Enums;
using GameServerCore.NetInfo;
using GameServerCore.Packets.Enums;
using GameServerCore.Packets.Interfaces;
using PacketDefinitions420.Enums;
using PacketDefinitions420.PacketDefinitions.C2S;
using PacketDefinitions420.PacketDefinitions.S2C;
using LeaguePackets.Game;
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Timers;
using PingLoadInfoRequest = GameServerCore.Packets.PacketDefinitions.Requests.PingLoadInfoRequest;
using ViewRequest = GameServerCore.Packets.PacketDefinitions.Requests.ViewRequest;
using LeaguePackets.Game.Common;
using LeaguePackets.Common;
using static GameServerCore.Content.HashFunctions;
using System.Text;
using Force.Crc32;
using System.Linq;
namespace PacketDefinitions420
{
/// <summary>
/// Class containing all function related packets (except handshake) which are sent by the server to game clients.
/// </summary>
public class PacketNotifier : IPacketNotifier
{
private readonly IPacketHandlerManager _packetHandlerManager;
private readonly INavigationGrid _navGrid;
/// <summary>
/// Instantiation which preps PacketNotifier for packet sending.
/// </summary>
/// <param name="packetHandlerManager"></param>
/// <param name="navGrid"></param>
public PacketNotifier(IPacketHandlerManager packetHandlerManager, INavigationGrid navGrid)
{
_packetHandlerManager = packetHandlerManager;
_navGrid = navGrid;
}
// TODO: Maybe clean up all the function parameters somehow?
/// <summary>
/// Sends a packet to the specified user which is intended to creates a client-side debug object. *NOTE*: Has not been tested, function implementation may be incorrect.
/// </summary>
/// <param name="userId">User to send the packet to.</param>
/// <param name="unit">Unit that </param>
/// <param name="objNetId">NetID to assign to the debug object.</param>
/// <param name="lifetime">How long the debug object should exist (in seconds).</param>
/// <param name="radius">Distance from the center of the debug object to its edge.</param>
/// <param name="pos1">Position of the first point. Untested.</param>
/// <param name="pos2">Position of the second point. Untested.</param>
/// <param name="objID">Index of the debug object. Untested, function unknown.</param>
/// <param name="type">Type of debug object. Untested, possible types unknown.</param>
/// <param name="name">Name of the debug object. Untested. Might be displayed as floating text?</param>
/// <param name="r">Red hex color value.</param>
/// <param name="g">Green hex color value.</param>
/// <param name="b">Blue hex color value.</param>
public void NotifyAddDebugObject(int userId, IAttackableUnit unit, uint objNetId, float lifetime, float radius, Vector3 pos1, Vector3 pos2, int objID = 0, byte type = 0x0, string name = "debugobj", byte r = 0xFF, byte g = 0x46, byte b = 0x0)
{
//TODO: Implement a DebugObject class so this is cleaner
var color = new LeaguePackets.Game.Common.Color
{
Red = r,
Green = g,
Blue = b
};
var debugObjPacket = new S2C_AddDebugObject
{
SenderNetID = unit.NetId,
DebugID = objID,
Lifetime = lifetime,
Type = type,
NetID1 = unit.NetId,
NetID2 = objNetId,
Radius = radius,
Point1 = pos1,
Point2 = pos2,
Color = color,
MaxSize = 0, // TODO: Verify what this does
Bitfield = 0x0, // TODO: Verify what this does
StringBuffer = name
};
_packetHandlerManager.SendPacket(userId, debugObjPacket.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to all players that the specified Champion has killed a specified player and received a specified amount of gold.
/// </summary>
/// <param name="c">Champion that killed a unit.</param>
/// <param name="died">AttackableUnit that died to the Champion.</param>
/// <param name="gold">Amount of gold the Champion gained for the kill.</param>
/// TODO: Only use BroadcastPacket when the unit that died is a Champion.
public void NotifyAddGold(IChampion c, IAttackableUnit died, float gold)
{
var ag = new AddGold(c, died, gold);
_packetHandlerManager.BroadcastPacket(ag, Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to the specified team that a part of the map has changed. Known to be used in League for initializing turret vision and collision.
/// </summary>
/// <param name="newFogId">NetID of the owner of the region.</param>
/// <param name="team">Team to send the packet to.</param>
/// <param name="position">2D top-down position of the region.</param>
/// <param name="time">Amount of time the region lasts.</param>
/// <param name="radius">Radius of the region.</param>
/// <param name="regionType">Type of region, possible values unknown.</param>
/// <param name="clientInfo">Info about a client that might own (or be the target of) the region.</param>
/// <param name="obj">GameObject that might own (or be the target of) the region.</param>
/// <param name="collisionRadius">Collision radius for the region (only if it should have collision).</param>
/// <param name="grassRadius">Radius of the region's grass.</param>
/// <param name="sizemult">Multiplier that is applied to the radius of the region.</param>
/// <param name="addsize">Number of units to add to the region's radius.</param>
/// <param name="grantVis">Whether or not the region should give the region's team vision of enemy units.</param>
/// <param name="stealthVis">Whether or not invisible units should be visible in the region.</param>
/// TODO: Implement a Region class so we can easily grab these parameters instead of listing them all in the function.
public void NotifyAddRegion(uint newFogId, TeamId team, Vector2 position, float time, float radius = 0, int regionType = 0, ClientInfo clientInfo = null, IGameObject obj = null, float collisionRadius = 0, float grassRadius = 0, float sizemult = 1.0f, float addsize = 0, bool grantVis = true, bool stealthVis = false)
{
var regionPacket = new AddRegion
{
TeamID = (uint)team,
RegionType = regionType, // TODO: Find out what values this can be and make an enum for it (so far: -2 for turrets)
UnitNetID = newFogId, // TODO: Verify (usually 0 for vision only?)
BubbleNetID = newFogId, // TODO: Verify (is usually different from UnitNetID in packets, may also be a remnant or for internal use)
VisionTargetNetID = 0,
Position = position,
TimeToLive = time, // For turrets, usually 25000.0 is used
ColisionRadius = collisionRadius, // 88.4 for turrets
GrassRadius = grassRadius, // 130.0 for turrets
SizeMultiplier = sizemult,
SizeAdditive = addsize,
HasCollision = false,
GrantVision = grantVis,
RevealStealth = stealthVis,
BaseRadius = radius // 800.0 for turrets
};
if (clientInfo != null)
{
if (clientInfo.Champion != null)
{
regionPacket.VisionTargetNetID = clientInfo.Champion.NetId;
}
regionPacket.ClientID = (int)clientInfo.ClientId;
}
if (obj != null)
{
regionPacket.VisionTargetNetID = obj.NetId;
}
// TODO: Verify
if (collisionRadius > 0.0f)
{
regionPacket.HasCollision = true;
}
_packetHandlerManager.BroadcastPacketTeam(team, regionPacket.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to all players that the specified Champion has gained the specified amount of experience.
/// </summary>
/// <param name="champion">Champion that gained the experience.</param>
/// <param name="experience">Amount of experience gained.</param>
/// TODO: Verify if sending to all players is correct.
public void NotifyAddXp(IChampion champion, float experience)
{
var xp = new AddXp(champion, experience);
_packetHandlerManager.BroadcastPacket(xp, Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to all players with vision of the specified attacker detailing that they have targeted the specified target.
/// </summary>
/// <param name="attacker">AI that is targeting an AttackableUnit.</param>
/// <param name="target">AttackableUnit that is being targeted by the attacker.</param>
public void NotifyAI_TargetS2C(IObjAiBase attacker, IAttackableUnit target)
{
var targetPacket = new AI_TargetS2C
{
SenderNetID = attacker.NetId,
TargetNetID = 0
};
if (target != null)
{
targetPacket.TargetNetID = target.NetId;
}
// TODO: Verify if we need to account for other cases.
if (attacker is IBaseTurret)
{
_packetHandlerManager.BroadcastPacket(targetPacket.GetBytes(), Channel.CHL_S2C);
}
else
{
_packetHandlerManager.BroadcastPacketVision(attacker, targetPacket.GetBytes(), Channel.CHL_S2C);
}
}
/// <summary>
/// Sends a packet to all players with vision of the specified attacker detailing that they have targeted the specified champion.
/// </summary>
/// <param name="attacker">AI that is targeting a champion.</param>
/// <param name="target">Champion that is being targeted by the attacker.</param>
public void NotifyAI_TargetHeroS2C(IObjAiBase attacker, IChampion target)
{
var targetPacket = new AI_TargetHeroS2C
{
SenderNetID = attacker.NetId,
TargetNetID = 0
};
if (target != null)
{
targetPacket.TargetNetID = target.NetId;
}
_packetHandlerManager.BroadcastPacketVision(attacker, targetPacket.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to all players that announces a specified message (ex: "Minions have spawned.")
/// </summary>
/// <param name="mapId">Current map ID.</param>
/// <param name="messageId">Message ID to announce.</param>
/// <param name="isMapSpecific">Whether the announce is specific to the map ID.</param>
public void NotifyAnnounceEvent(int mapId, Announces messageId, bool isMapSpecific)
{
var announce = new Announce(messageId, isMapSpecific ? mapId : 0);
_packetHandlerManager.BroadcastPacket(announce, Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to the specified user that informs them of their summoner data such as runes, summoner spells, masteries (or talents as named internally), etc.
/// </summary>
/// <param name="userId">User to send the packet to.</param>
/// <param name="client">Info about the player's summoner data.</param>
public void NotifyAvatarInfo(int userId, ClientInfo client)
{
var avatar = new AvatarInfo_Server();
avatar.SenderNetID = client.Champion.NetId;
var skills = new uint[] { HashFunctions.HashString(client.SummonerSkills[0]), HashFunctions.HashString(client.SummonerSkills[1]) };
avatar.SummonerIDs[0] = skills[0];
avatar.SummonerIDs[1] = skills[1];
for (int i = 0; i < client.Champion.RuneList.Runes.Count; ++i)
{
int runeValue = 0;
client.Champion.RuneList.Runes.TryGetValue(i, out runeValue);
avatar.ItemIDs[i] = (uint)runeValue;
}
// TODO: add talents
_packetHandlerManager.SendPacket(userId, avatar.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to all players that have vision of the specified Azir turret that it has spawned.
/// </summary>
/// <param name="azirTurret">AzirTurret instance.</param>
public void NotifyAzirTurretSpawned(IAzirTurret azirTurret)
{
var spawnPacket = new SpawnAzirTurret(azirTurret);
_packetHandlerManager.BroadcastPacketVision(azirTurret, spawnPacket, Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to all players detailing that the specified unit is starting their next auto attack.
/// </summary>
/// <param name="attacker">Unit that is attacking.</param>
/// <param name="target">AttackableUnit being attacked.</param>
/// <param name="futureProjNetId">NetId of the auto attack projectile.</param>
/// <param name="isCrit">Whether or not the auto attack will crit.</param>
/// <param name="nextAttackFlag">Whether or this basic attack is not the first time this basic attack has been performed on the given target.</param>
/// TODO: Verify the differences between normal Basic_Attack and Basic_Attack_Pos.
public void NotifyBasic_Attack(IObjAiBase attacker, IAttackableUnit target, uint futureProjNetId, bool isCrit, bool nextAttackFlag)
{
var targetPos = MovementVector.ToCenteredScaledCoordinates(target.Position, _navGrid);
// TODO: Remove attacker, target, and futureProjNetId parameters and replace with CastInfo
var basicAttackData = new BasicAttackData
{
TargetNetID = target.NetId,
ExtraTime = attacker.AutoAttackSpell.CastInfo.ExtraCastTime, // TODO: Verify, maybe related to CastInfo.ExtraCastTime?
MissileNextID = futureProjNetId,
AttackSlot = attacker.AutoAttackSpell.CastInfo.SpellSlot,
// TODO: Verify TargetPosition, taken from LS packet
TargetPosition = new Vector3(targetPos.X, _navGrid.GetHeightAtLocation(targetPos.X, targetPos.Y), targetPos.Y)
};
if (!attacker.HasMadeInitialAttack)
{
basicAttackData.ExtraTime = -0.01f; // TODO: Verify, maybe related to CastInfo.ExtraCastTime?
}
var basicAttackPacket = new Basic_Attack
{
SenderNetID = attacker.NetId,
Attack = basicAttackData
};
_packetHandlerManager.BroadcastPacketVision(attacker, basicAttackPacket.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to all players that the specified attacker is starting their first auto attack.
/// </summary>
/// <param name="attacker">AI that is starting an auto attack.</param>
/// <param name="target">AttackableUnit being attacked.</param>
/// <param name="futureProjNetId">NetID of the projectile that will be created for the auto attack.</param>
/// <param name="isCrit">Whether or not the auto attack is a critical.</param>
/// TODO: Verify the differences between BasicAttackPos and normal BasicAttack.
public void NotifyBasic_Attack_Pos(IObjAiBase attacker, IAttackableUnit target, uint futureProjNetId, bool isCrit)
{
var targetPos = MovementVector.ToCenteredScaledCoordinates(target.Position, _navGrid);
// TODO: Remove attacker, target, and futureProjNetId parameters and replace with CastInfo
var basicAttackData = new BasicAttackData
{
TargetNetID = target.NetId,
ExtraTime = attacker.AutoAttackSpell.CastInfo.ExtraCastTime, // TODO: Verify, maybe related to CastInfo.ExtraCastTime?
MissileNextID = futureProjNetId,
AttackSlot = attacker.AutoAttackSpell.CastInfo.SpellSlot,
TargetPosition = new Vector3(targetPos.X, target.GetHeight(), targetPos.Y)
};
var basicAttackPacket = new Basic_Attack_Pos
{
SenderNetID = attacker.NetId,
Attack = basicAttackData,
Position = attacker.Position // TODO: Verify
};
_packetHandlerManager.BroadcastPacketVision(attacker, basicAttackPacket.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a side bar tip to the specified player (ex: quest tips).
/// </summary>
/// <param name="userId">User to send the packet to.</param>
/// <param name="title">Title of the tip.</param>
/// <param name="text">Description text of the tip.</param>
/// <param name="imagePath">Path to an image that will be embedded in the tip.</param>
/// <param name="tipCommand">Action suggestion(? unconfirmed).</param>
/// <param name="playerNetId">NetID to send the packet to.</param>
/// <param name="targetNetId">NetID of the target referenced by the tip.</param>
/// TODO: tipCommand should be a lib/core enum that gets translated into a league version specific packet enum as it may change over time.
public void NotifyBlueTip(int userId, string title, string text, string imagePath, byte tipCommand, uint playerNetId,
uint targetNetId)
{
var packet = new BlueTip(title, text, imagePath, tipCommand, playerNetId, targetNetId);
_packetHandlerManager.SendPacket(userId, packet, Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to the player attempting to buy an item that their purchase was successful.
/// </summary>
/// <param name="userId">User to send the packet to.</param>
/// <param name="gameObject">GameObject of type ObjAiBase that can buy items.</param>
/// <param name="itemInstance">Item instance housing all information about the item that has been bought.</param>
public void NotifyBuyItem(int userId, IObjAiBase gameObject, IItem itemInstance)
{
ItemData itemData = new ItemData
{
ItemID = (uint)itemInstance.ItemData.ItemId,
Slot = gameObject.Inventory.GetItemSlot(itemInstance),
ItemsInSlot = (byte)itemInstance.StackCount,
SpellCharges = 0 // TODO: Unhardcode
};
//TODO find out what bitfield does, currently unknown
var buyItemPacket = new BuyItemAns
{
SenderNetID = gameObject.NetId,
Item = itemData,
Bitfield = 0 //TODO: find out what this does, currently unknown
};
_packetHandlerManager.SendPacket(userId, buyItemPacket.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to all players updating a champion's death timer.
/// </summary>
/// <param name="champion">Champion that died.</param>
public void NotifyChampionDeathTimer(IChampion champion)
{
var cdt = new ChampionDeathTimer(champion);
_packetHandlerManager.BroadcastPacket(cdt, Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to all players that a champion has died and calls a death timer update packet.
/// </summary>
/// <param name="champion">Champion that died.</param>
/// <param name="killer">Unit that killed the Champion.</param>
/// <param name="goldFromKill">Amount of gold the killer received.</param>
public void NotifyChampionDie(IChampion champion, IAttackableUnit killer, int goldFromKill)
{
var cd = new ChampionDie(champion, killer, goldFromKill);
_packetHandlerManager.BroadcastPacket(cd, Channel.CHL_S2C);
NotifyChampionDeathTimer(champion);
}
/// <summary>
/// Sends a packet to all players that a champion has respawned.
/// </summary>
/// <param name="c">Champion that respawned.</param>
public void NotifyChampionRespawn(IChampion c)
{
var cr = new ChampionRespawn(c);
_packetHandlerManager.BroadcastPacket(cr, Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to the specified user detailing that the specified owner unit's spell in the specified slot has been changed.
/// </summary>
/// <param name="userId">User to send the packet to.</param>
/// <param name="owner">Unit that owns the spell being changed.</param>
/// <param name="slot">Slot of the spell being changed.</param>
/// <param name="changeType">Type of change being made.</param>
/// <param name="isSummonerSpell">Whether or not the spell being changed is a summoner spell.</param>
/// <param name="targetingType">New targeting type to set.</param>
/// <param name="newName">New internal name of a spell to set.</param>
/// <param name="newRange">New cast range for the spell to set.</param>
/// <param name="newMaxCastRange">New max cast range for the spell to set.</param>
/// <param name="newDisplayRange">New max display range for the spell to set.</param>
/// <param name="newIconIndex">New index of an icon for the spell to set.</param>
/// <param name="offsetTargets">New target netids for the spell to set.</param>
public void NotifyChangeSlotSpellData(int userId, IObjAiBase owner, byte slot, GameServerCore.Enums.ChangeSlotSpellDataType changeType, bool isSummonerSpell = false, TargetingType targetingType = TargetingType.Invalid, string newName = "", float newRange = 0, float newMaxCastRange = 0, float newDisplayRange = 0, byte newIconIndex = 0x0, List<uint> offsetTargets = null)
{
ChangeSpellData spellData = new ChangeSpellDataUnknown()
{
SpellSlot = slot,
IsSummonerSpell = isSummonerSpell
};
switch(changeType)
{
case GameServerCore.Enums.ChangeSlotSpellDataType.TargetingType:
{
if (targetingType != TargetingType.Invalid)
{
spellData = new ChangeSpellDataTargetingType()
{
SpellSlot = slot,
IsSummonerSpell = isSummonerSpell,
TargetingType = (byte)targetingType
};
}
break;
}
case GameServerCore.Enums.ChangeSlotSpellDataType.SpellName:
{
spellData = new ChangeSpellDataSpellName()
{
SpellSlot = slot,
IsSummonerSpell = isSummonerSpell,
SpellName = newName
};
break;
}
case GameServerCore.Enums.ChangeSlotSpellDataType.Range:
{
spellData = new ChangeSpellDataRange()
{
SpellSlot = slot,
IsSummonerSpell = isSummonerSpell,
CastRange = newRange
};
break;
}
case GameServerCore.Enums.ChangeSlotSpellDataType.MaxGrowthRange:
{
spellData = new ChangeSpellDataMaxGrowthRange()
{
SpellSlot = slot,
IsSummonerSpell = isSummonerSpell,
OverrideMaxCastRange = newMaxCastRange
};
break;
}
case GameServerCore.Enums.ChangeSlotSpellDataType.RangeDisplay:
{
spellData = new ChangeSpellDataRangeDisplay()
{
SpellSlot = slot,
IsSummonerSpell = isSummonerSpell,
OverrideCastRangeDisplay = newDisplayRange
};
break;
}
case GameServerCore.Enums.ChangeSlotSpellDataType.IconIndex:
{
spellData = new ChangeSpellDataIconIndex()
{
SpellSlot = slot,
IsSummonerSpell = isSummonerSpell,
IconIndex = newIconIndex
};
break;
}
case GameServerCore.Enums.ChangeSlotSpellDataType.OffsetTarget:
{
if (offsetTargets != null)
{
spellData = new ChangeSpellDataOffsetTarget()
{
SpellSlot = slot,
IsSummonerSpell = isSummonerSpell,
Targets = offsetTargets
};
}
break;
}
}
var changePacket = new ChangeSlotSpellData()
{
SenderNetID = owner.NetId,
ChangeSpellData = spellData
};
_packetHandlerManager.SendPacket(userId, changePacket.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to all players with vision of a specified ObjAiBase explaining that their specified spell's cooldown has been set.
/// </summary>
/// <param name="u">ObjAiBase who owns the spell going on cooldown.</param>
/// <param name="slotId">Slot of the spell.</param>
/// <param name="currentCd">Amount of time the spell has already been on cooldown (if applicable).</param>
/// <param name="totalCd">Maximum amount of time the spell's cooldown can be.</param>
public void NotifyCHAR_SetCooldown(IObjAiBase u, byte slotId, float currentCd, float totalCd)
{
var cdPacket = new CHAR_SetCooldown
{
SenderNetID = u.NetId,
Slot = slotId,
PlayVOWhenCooldownReady = false, // TODO: Unhardcode
IsSummonerSpell = false, // TODO: Unhardcode
Cooldown = currentCd,
MaxCooldownForDisplay = 0 // TODO: Verify (packet loses functionality otherwise)
};
if (u is IChampion && (slotId == 4 || slotId == 5))
{
cdPacket.IsSummonerSpell = true; // TODO: Verify functionality
}
_packetHandlerManager.BroadcastPacketVision(u, cdPacket.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to the specified user that highlights the specified GameObject.
/// </summary>
/// <param name="userId">ID of the user to send the packet to.</param>
/// <param name="unit">GameObject to highlght.</param>
public void NotifyCreateUnitHighlight(int userId, IGameObject unit)
{
var highlightPacket = new S2C_CreateUnitHighlight
{
SenderNetID = unit.NetId,
TargetNetID = unit.NetId
};
_packetHandlerManager.SendPacket(userId, highlightPacket.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to all players detailing a debug message.
/// </summary>
/// <param name="htmlDebugMessage">Debug message to send.</param>
public void NotifyDebugMessage(string htmlDebugMessage)
{
var dm = new DebugMessage(htmlDebugMessage);
_packetHandlerManager.BroadcastPacket(dm, Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to the specified user detailing a debug message.
/// </summary>
/// <param name="userId">ID of the user to send the packet to.</param>
/// <param name="message">Debug message to send.</param>
public void NotifyDebugMessage(int userId, string message)
{
var dm = new DebugMessage(message);
_packetHandlerManager.SendPacket(userId, dm, Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to the specified team detailing a debug message.
/// </summary>
/// <param name="team">TeamId to send the packet to; BLUE/PURPLE/NEUTRAL.</param>
/// <param name="message">Debug message to send.</param>
public void NotifyDebugMessage(TeamId team, string message)
{
var dm = new DebugMessage(message);
_packetHandlerManager.BroadcastPacketTeam(team, dm, Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to the specified user which is intended for debugging.
/// </summary>
/// <param name="userId">ID of the user to send the packet to.</param>
/// <param name="data">Array of bytes representing the packet's data.</param>
public void NotifyDebugPacket(int userId, byte[] data)
{
_packetHandlerManager.SendPacket(userId, data, Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to all players detailing the destruction of (usually) an auto attack missile.
/// </summary>
/// <param name="p">Projectile that is being destroyed.</param>
public void NotifyDestroyClientMissile(ISpellMissile p)
{
var misPacket = new S2C_DestroyClientMissile
{
SenderNetID = p.NetId
};
_packetHandlerManager.BroadcastPacket(misPacket.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to the specified team detailing the destruction of (usually) an auto attack missile.
/// </summary>
/// <param name="p">Projectile that is being destroyed.</param>
/// <param name="team">TeamId to send the packet to.</param>
public void NotifyDestroyClientMissile(ISpellMissile p, TeamId team)
{
var misPacket = new S2C_DestroyClientMissile
{
SenderNetID = p.NetId
};
_packetHandlerManager.BroadcastPacketTeam(team, misPacket.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to either all players with vision of a target, or the specified player.
/// The packet displays the specified message of the specified type as floating text over a target.
/// </summary>
/// <param name="target">Target to display on.</param>
/// <param name="message">Message to display.</param>
/// <param name="textType">Type of text to display. Refer to FloatTextType</param>
/// <param name="userId">User to send to. 0 = sends to all in vision.</param>
/// <param name="param">Optional parameters for the text. Untested, function unknown.</param>
public void NotifyDisplayFloatingText(IGameObject target, string message, FloatTextType textType = FloatTextType.Debug, int userId = 0, int param = 0)
{
var textPacket = new DisplayFloatingText
{
TargetNetID = target.NetId,
FloatTextType = (uint)textType,
Param = param,
Message = message
};
if (userId == 0)
{
_packetHandlerManager.BroadcastPacketVision(target, textPacket.GetBytes(), Channel.CHL_S2C);
}
_packetHandlerManager.SendPacket(userId, textPacket.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to all players detailing an emotion that is being performed by the unit that owns the specified netId.
/// </summary>
/// <param name="type">Type of emotion being performed; DANCE/TAUNT/LAUGH/JOKE/UNK.</param>
/// <param name="netId">NetID of the unit performing the emotion.</param>
public void NotifyEmotions(Emotions type, uint netId)
{
// convert type
EmotionType targetType;
switch (type)
{
case Emotions.DANCE:
targetType = EmotionType.DANCE;
break;
case Emotions.TAUNT:
targetType = EmotionType.TAUNT;
break;
case Emotions.LAUGH:
targetType = EmotionType.LAUGH;
break;
case Emotions.JOKE:
targetType = EmotionType.JOKE;
break;
case Emotions.UNK:
targetType = (EmotionType)type;
break;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
var packet = new EmotionPacketResponse((byte)targetType, netId);
_packetHandlerManager.BroadcastPacket(packet, Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to the specified user detailing that the GameObject that owns the specified netId has finished being initialized into vision.
/// </summary>
/// <param name="userId">User to send the packet to.</param>
/// <param name="netId">NetID of the GameObject coming into vision.</param>
public void NotifyEnterLocalVisibilityClient(int userId, uint netId)
{
var enterLocalVis = new OnEnterLocalVisibilityClient
{
SenderNetID = netId
};
_packetHandlerManager.SendPacket(userId, enterLocalVis.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to either all players with vision of the specified GameObject or a specified user. The packet contains details of the GameObject's health (given it is of the type AttackableUnit) and is meant for after the GameObject is first initialized into vision.
/// </summary>
/// <param name="o">GameObject coming into vision.</param>
/// <param name="userId">User to send the packet to.</param>
/// <param name="ignoreVision">Optionally ignore vision checks when sending this packet.</param>
public void NotifyEnterLocalVisibilityClient(IGameObject o, int userId = 0, bool ignoreVision = false)
{
var enterLocalVis = new OnEnterLocalVisibilityClient
{
SenderNetID = o.NetId,
};
if (o is IAttackableUnit u)
{
enterLocalVis.MaxHealth = u.Stats.HealthPoints.Total;
enterLocalVis.Health = u.Stats.CurrentHealth;
}
if (userId == 0)
{
if (ignoreVision)
{
_packetHandlerManager.BroadcastPacket(enterLocalVis.GetBytes(), Channel.CHL_S2C);
return;
}
_packetHandlerManager.BroadcastPacketVision(o, enterLocalVis.GetBytes(), Channel.CHL_S2C);
}
else
{
_packetHandlerManager.SendPacket(userId, enterLocalVis.GetBytes(), Channel.CHL_S2C);
}
}
/// <summary>
/// Sends a packet to either all players with vision of the specified object or the specified user. The packet details the data surrounding the specified GameObject that is required by players when a GameObject enters vision such as items, shields, skin, and movements.
/// </summary>
/// <param name="o">GameObject entering vision.</param>
/// <param name="userId">User to send the packet to.</param>
/// <param name="isChampion">Whether or not the GameObject entering vision is a Champion.</param>
/// <param name="useTeleportID">Whether or not to teleport the object to its current position.</param>
/// <param name="ignoreVision">Optionally ignore vision checks when sending this packet.</param>
/// TODO: Incomplete implementation.
public void NotifyEnterVisibilityClient(IGameObject o, int userId = 0, bool isChampion = false, bool useTeleportID = false, bool ignoreVision = false)
{
var itemData = new List<ItemData>(); //TODO: Fix item system so this can be finished
var shields = new ShieldValues(); //TODO: Implement shields so this can be finished
var charStackDataList = new List<CharacterStackData>();
var charStackData = new CharacterStackData
{
SkinID = 0,
OverrideSpells = false,
ModelOnly = false,
ReplaceCharacterPackage = false,
ID = 0
};
var buffCountList = new List<KeyValuePair<byte, int>>();
if (o is IAttackableUnit a)
{
charStackData.SkinName = a.Model;
if (a is IChampion c)
{
charStackData.SkinID = (uint)c.Skin;
}
buffCountList = new List<KeyValuePair<byte, int>>();
var tempBuffs = a.GetParentBuffs();
for (var i = 0; i < tempBuffs.Count; i++)
{
var buff = tempBuffs.ElementAt(i).Value;
buffCountList.Add(new KeyValuePair<byte, int>(buff.Slot, buff.StackCount));
}
// TODO: if (a.IsDashing), requires SpeedParams, add it to AttackableUnit so it can be accessed outside of initialization
}
charStackDataList.Add(charStackData);
var type = MovementDataType.Normal;
if (o is IAttackableUnit unit && unit.Waypoints.Count <= 1)
{
type = MovementDataType.Stop;
}
var md = PacketExtensions.CreateMovementData(o, _navGrid, type, useTeleportID: useTeleportID);
var enterVis = new OnEnterVisibilityClient // TYPO >:(
{
SenderNetID = o.NetId,
Items = itemData,
ShieldValues = shields,
CharacterDataStack = charStackDataList,
BuffCount = buffCountList,
LookAtPosition = new Vector3(1, 0, 0),
// TODO: Verify
UnknownIsHero = isChampion,
MovementData = md
};
if (userId != 0)
{
_packetHandlerManager.SendPacket(userId, enterVis.GetBytes(), Channel.CHL_S2C);
NotifyEnterLocalVisibilityClient(o, userId, ignoreVision);
}
else
{
if (ignoreVision)
{
_packetHandlerManager.BroadcastPacket(enterVis.GetBytes(), Channel.CHL_S2C);
NotifyEnterLocalVisibilityClient(o, ignoreVision: true);
return;
}
_packetHandlerManager.BroadcastPacketVision(o, enterVis.GetBytes(), Channel.CHL_S2C);
NotifyEnterLocalVisibilityClient(o);
}
}
/// <summary>
/// Sends a packet to all players with vision of the specified unit detailing that the unit has begun facing the specified direction.
/// </summary>
/// <param name="obj">GameObject that is changing their orientation.</param>
/// <param name="direction">3D direction the unit will face.</param>
/// <param name="isInstant">Whether or not the unit should instantly turn to the direction.</param>
/// <param name="turnTime">The amount of time (seconds) the turn should take.</param>
public void NotifyFaceDirection(IGameObject obj, Vector3 direction, bool isInstant = true, float turnTime = 0.0833f)
{
var facePacket = new S2C_FaceDirection()
{
SenderNetID = obj.NetId,
Direction = direction,
DoLerpTime = !isInstant,
LerpTime = turnTime
};
_packetHandlerManager.BroadcastPacketVision(obj, facePacket.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to all players that (usually) an auto attack missile has been created.
/// </summary>
/// <param name="p">Projectile that was created.</param>
public void NotifyForceCreateMissile(ISpellMissile p)
{
var misPacket = new S2C_ForceCreateMissile
{
SenderNetID = p.CastInfo.Owner.NetId,
MissileNetID = p.NetId
};
_packetHandlerManager.BroadcastPacket(misPacket.GetBytes(), Channel.CHL_S2C);
}
/// <summary>
/// Sends a packet to, optionally, a specified player, all players with vision of the particle, or all players (given the particle is set as globally visible).
/// </summary>
/// <param name="particle">Particle to network.</param>
/// <param name="userId">User to send the packet to.</param>
public void NotifyFXCreateGroup(IParticle particle, int userId = 0)
{
uint bindNetID = 0;
uint targetNetID = 0;
if (particle.BindObject != null)
{
bindNetID = particle.BindObject.NetId;
}
if (particle.TargetObject != null)
{
targetNetID = particle.TargetObject.NetId;
}
var position = particle.GetPosition3D();
var ownerPos = position;
if (particle.Caster != null)
{
ownerPos = particle.Caster.GetPosition3D();
}
var fxPacket = new FX_Create_Group();
var fxDataList = new List<FXCreateData>();
var targetHeight = _navGrid.GetHeightAtLocation(particle.TargetPosition.X, particle.TargetPosition.Y);
var higherValue = Math.Max(targetHeight, particle.GetHeight());
// TODO: implement option for multiple particles instead of hardcoding one
var fxData1 = new FXCreateData
{
NetAssignedNetID = particle.NetId,
CasterNetID = 0,
KeywordNetID = 0, // Not sure what this is
PositionX = (short)((position.X - _navGrid.MapWidth / 2) / 2),
PositionY = higherValue,
PositionZ = (short)((position.Z - _navGrid.MapHeight / 2) / 2),
TargetPositionX = (short)((particle.TargetPosition.X - _navGrid.MapWidth / 2) / 2),
TargetPositionY = higherValue,
TargetPositionZ = (short)((particle.TargetPosition.Y - _navGrid.MapHeight / 2) / 2),
OwnerPositionX = (short)((ownerPos.X - _navGrid.MapWidth / 2) / 2),
OwnerPositionY = ownerPos.Y,
OwnerPositionZ = (short)((ownerPos.Z - _navGrid.MapHeight / 2) / 2),
TimeSpent = particle.GetTimeAlive(),
ScriptScale = particle.Scale,
TargetNetID = targetNetID,
BindNetID = bindNetID
};
// TODO: Verify if there is more to this.
if (particle.FollowsGroundTilt)
{
fxData1.TargetPositionY = targetHeight;
}
if (particle.Caster != null)
{
fxData1.CasterNetID = particle.Caster.NetId;
}
if (particle.Direction.Length() <= 0)
{
fxData1.OrientationVector = Vector3.Zero;
}
else
{
fxData1.OrientationVector = particle.Direction;
}
fxDataList.Add(fxData1);
// TODO: implement option for multiple groups of particles instead of hardcoding one
var fxGroups = new List<FXCreateGroupData>();
var fxGroupData1 = new FXCreateGroupData
{
EffectNameHash = HashString(particle.Name),
//TODO: un-hardcode flags
Flags = 0x20, // Taken from SpawnParticle packet
TargetBoneNameHash = HashString(particle.TargetBoneName),
BoneNameHash = HashString(particle.BoneName),
FXCreateData = fxDataList
};
if (particle.Caster != null && particle.Caster is IObjAiBase o)
{
fxGroupData1.PackageHash = o.GetObjHash();
}
else
{
fxGroupData1.PackageHash = 0; // TODO: Verify
}
fxGroups.Add(fxGroupData1);
fxPacket.FXCreateGroup = fxGroups;
if (userId == 0)
{
if (particle.SpecificTeam != TeamId.TEAM_NEUTRAL)
{
_packetHandlerManager.BroadcastPacketTeam(particle.SpecificTeam, fxPacket.GetBytes(), Channel.CHL_S2C);
return;
}