forked from PerpetuumOnline/PerpetuumServer
-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathPlayer.cs
More file actions
1326 lines (1059 loc) · 42.5 KB
/
Player.cs
File metadata and controls
1326 lines (1059 loc) · 42.5 KB
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 Perpetuum.Accounting.Characters;
using Perpetuum.Builders;
using Perpetuum.Collections.Spatial;
using Perpetuum.Common.Loggers.Transaction;
using Perpetuum.Containers;
using Perpetuum.Containers.SystemContainers;
using Perpetuum.Data;
using Perpetuum.EntityFramework;
using Perpetuum.ExportedTypes;
using Perpetuum.Groups.Corporations;
using Perpetuum.Groups.Gangs;
using Perpetuum.Items;
using Perpetuum.Log;
using Perpetuum.Modules;
using Perpetuum.Robots;
using Perpetuum.Services.ExtensionService;
using Perpetuum.Services.Looting;
using Perpetuum.Services.MissionEngine;
using Perpetuum.Services.MissionEngine.MissionTargets;
using Perpetuum.Services.MissionEngine.TransportAssignments;
using Perpetuum.Timers;
using Perpetuum.Units;
using Perpetuum.Units.DockingBases;
using Perpetuum.Zones;
using Perpetuum.Zones.Beams;
using Perpetuum.Zones.Blobs;
using Perpetuum.Zones.Blobs.BlobEmitters;
using Perpetuum.Zones.CombatLogs;
using Perpetuum.Zones.DamageProcessors;
using Perpetuum.Zones.Effects;
using Perpetuum.Zones.Finders;
using Perpetuum.Zones.Finders.PositionFinders;
using Perpetuum.Zones.Locking;
using Perpetuum.Zones.Locking.Locks;
using Perpetuum.Zones.NpcSystem;
using Perpetuum.Zones.PBS;
using Perpetuum.Zones.PlantTools;
using Perpetuum.Zones.ProximityProbes;
using Perpetuum.Zones.RemoteControl;
using Perpetuum.Zones.Teleporting;
using Perpetuum.Zones.Teleporting.Strategies;
using Perpetuum.Zones.Terrains;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Transactions;
namespace Perpetuum.Players
{
public sealed class Player : Robot, IBlobableUnit, IBlobEmitter
{
private readonly IExtensionReader extensionReader;
private readonly ICorporationManager corporationManager;
private readonly MissionHandler.Factory missionHandlerFactory;
private readonly ITeleportStrategyFactories teleportStrategyFactories;
private readonly DockingBaseHelper dockingBaseHelper;
private readonly CombatLogger.Factory combatLoggerFactory;
private readonly IBlobEmitter blobEmitter;
private readonly BlobHandler<Player> blobHandler;
private readonly PlayerMovement movement;
private readonly IntervalTimer combatTimer = new IntervalTimer(TimeSpan.FromSeconds(10));
private readonly GlobalConfiguration globalConfiguration;
private CombatLogger combatLogger;
private PlayerMoveCheckQueue check;
private CancellableDespawnHelper despawnHelper;
public static readonly TimeSpan NormalUndockDelay = TimeSpan.FromSeconds(7);
public static readonly TimeSpan BlessedUndockDelay = TimeSpan.FromMinutes(3); // Supposed to be 15
public const int ARKHE_REQUEST_TIMER_MINUTES_PVP = 3;
public const int ARKHE_REQUEST_TIMER_MINUTES_NPC = 1;
private readonly Dictionary<CategoryFlags, int> baseTokenPrices = new Dictionary<CategoryFlags, int>
{
{ CategoryFlags.cf_runners, 50 },
{ CategoryFlags.cf_nuimqol_runners, 50 },
{ CategoryFlags.cf_pelistal_runners, 50 },
{ CategoryFlags.cf_thelodica_runners, 50 },
{ CategoryFlags.cf_industrial_runners, 50 },
{ CategoryFlags.cf_crawlers, 150 },
{ CategoryFlags.cf_nuimqol_crawlers, 150 },
{ CategoryFlags.cf_pelistal_crawlers, 150 },
{ CategoryFlags.cf_thelodica_crawlers, 150 },
{ CategoryFlags.cf_industrial_crawlers, 150 },
{ CategoryFlags.cf_mechs, 500 },
{ CategoryFlags.cf_nuimqol_mechs, 500 },
{ CategoryFlags.cf_pelistal_mechs, 500 },
{ CategoryFlags.cf_thelodica_mechs, 500 },
{ CategoryFlags.cf_industrial_mechs, 500 },
{ CategoryFlags.cf_heavy_mechs, 2000 },
{ CategoryFlags.cf_nuimqol_heavymechs, 2000 },
{ CategoryFlags.cf_pelistal_heavymechs, 2000 },
{ CategoryFlags.cf_thelodica_heavymechs, 2000 },
{ CategoryFlags.cf_industrial_heavymechs, 2000 },
{ CategoryFlags.cf_walkers, 5000 },
};
private bool HasAggressorEffect => EffectHandler.ContainsEffect(EffectType.effect_aggressor);
public long CorporationEid { get; set; }
public IZoneSession Session { get; private set; }
public Character Character { get; set; } = Character.None;
public bool HasGMStealth { get; set; }
public MissionHandler MissionHandler { get; private set; }
public bool HasSelfTeleportEnablerEffect => EffectHandler.ContainsEffect(EffectType.effect_teleport_self_enabler);
public Gang Gang { get; set; }
public bool IsInSafeArea
{
get
{
IZone zone = Zone;
return zone != null
&& (zone.Configuration.Protected ||
EffectHandler.ContainsEffect(EffectType.effect_syndicate_area) ||
EffectHandler.ContainsEffect(EffectType.effect_safe_spot));
}
}
public override bool IsLockable
{
get
{
bool isInvulnerable = IsInvulnerable;
return !isInvulnerable && base.IsLockable;
}
}
public IBlobHandler BlobHandler => blobHandler;
public double BlobEmission => blobEmitter.BlobEmission;
public double BlobEmissionRadius => blobEmitter.BlobEmissionRadius;
public Player(
IExtensionReader extensionReader,
ICorporationManager corporationManager,
MissionHandler.Factory missionHandlerFactory,
ITeleportStrategyFactories teleportStrategyFactories,
DockingBaseHelper dockingBaseHelper,
CombatLogger.Factory combatLoggerFactory,
GlobalConfiguration globalConfiguration)
{
this.extensionReader = extensionReader;
this.corporationManager = corporationManager;
this.missionHandlerFactory = missionHandlerFactory;
this.teleportStrategyFactories = teleportStrategyFactories;
this.dockingBaseHelper = dockingBaseHelper;
this.combatLoggerFactory = combatLoggerFactory;
this.globalConfiguration = globalConfiguration;
Session = ZoneSession.None;
movement = new PlayerMovement(this);
blobEmitter = new BlobEmitter(this);
blobHandler = new BlobHandler<Player>(this);
}
public void EnableSelfTeleport(TimeSpan duration, int affectedZoneId = -1)
{
if (affectedZoneId != -1 && Zone.Id != affectedZoneId)
{
return;
}
ApplySelfTeleportEnablerEffect(duration);
}
public bool TryMove(Position position)
{
if (!IsWalkable(position))
{
return false;
}
check.EnqueueMove(position);
CurrentPosition = position;
return true;
}
public void SetSession(IZoneSession session)
{
Session = session;
}
public override void AcceptVisitor(IEntityVisitor visitor)
{
if (!TryAcceptVisitor(this, visitor))
{
base.AcceptVisitor(visitor);
}
}
public override void OnUpdateToDb()
{
try
{
if (!IsRepackaged)
{
DynamicProperties.Update(k.armor, Armor.Ratio(ArmorMax));
DynamicProperties.Update(k.currentCore, Core);
}
IZone zone = Zone;
if (zone == null || States.Dead)
{
return;
}
Character character = Character;
character.ZoneId = zone.Id;
character.ZonePosition = CurrentPosition;
IDynamicProperty<int> p = DynamicProperties.GetProperty<int>(k.pvpRemaining);
Effect pvpEffect = EffectHandler.GetEffectsByType(EffectType.effect_pvp).FirstOrDefault();
if (pvpEffect == null)
{
p.Clear();
return;
}
IntervalTimer effectTimer = pvpEffect.Timer;
if (effectTimer != null)
{
p.Value = (int)effectTimer.Remaining.TotalMilliseconds;
}
}
finally
{
base.OnUpdateToDb();
}
}
public void SetStrongholdDespawn(TimeSpan time, UnitDespawnStrategy strategy)
{
if (despawnHelper == null)
{
despawnHelper = CancellableDespawnHelper.Create(this, time);
despawnHelper.DespawnStrategy = strategy;
}
}
public void ClearStrongholdDespawn()
{
despawnHelper?.Cancel(this);
despawnHelper = null;
}
public void SendModuleProcessError(Module module, ErrorCodes error)
{
Packet packet = new Packet(ZoneCommand.ModuleEvaluateError);
packet.AppendByte((byte)module.ParentComponent.Type);
packet.AppendByte((byte)module.Slot);
packet.AppendInt((int)error);
Session.SendPacket(packet);
}
public void ApplyInvulnerableEffect()
{
RemoveInvulnerableEffect(); // Remove existing effect, set new
EffectBuilder builder = NewEffectBuilder().SetType(EffectType.effect_invulnerable);
_ = builder.WithDurationModifier(0.75); //Reduce span of syndicate protection
ApplyEffect(builder);
}
public void RemoveInvulnerableEffect()
{
EffectHandler.RemoveEffectsByType(EffectType.effect_invulnerable);
}
public void ApplyTeleportSicknessEffect()
{
IZone zone = Zone;
if (zone == null || zone is TrainingZone)
{
return;
}
EffectBuilder effectBuilder = NewEffectBuilder().SetType(EffectType.effect_teleport_sickness);
if (HasPvpEffect)
{
_ = effectBuilder.WithDurationModifier(3.0);
}
ApplyEffect(effectBuilder);
}
public void ApplySelfTeleportEnablerEffect(TimeSpan duration)
{
Effect effect = EffectHandler.GetEffectsByType(EffectType.effect_teleport_self_enabler).FirstOrDefault();
if (effect != null)
{
EffectHandler.Remove(effect);
}
EffectBuilder builder = NewEffectBuilder().SetType(EffectType.effect_teleport_self_enabler).WithDuration(duration);
ApplyEffect(builder);
}
public void RemoveSelfTeleportEnablerEffect()
{
EffectHandler.RemoveEffectsByType(EffectType.effect_teleport_self_enabler);
}
public void CheckDockingConditionsAndThrow(long baseEid, bool checkRange = true)
{
if (!Session.AccessLevel.IsAdminOrGm())
{
HasAggressorEffect.ThrowIfTrue(ErrorCodes.NotAllowedForAggressors);
HasPvpEffect.ThrowIfTrue(ErrorCodes.CantDockThisState);
HasTeleportSicknessEffect.ThrowIfTrue(ErrorCodes.CantDockThisState);
EffectHandler.ContainsEffect(EffectType.effect_dreadnought);
}
IZone zone = Zone;
if (zone == null)
{
return;
}
DockingBase dockingBase = dockingBaseHelper.GetDockingBase(baseEid);
if (dockingBase == null)
{
return;
}
if (dockingBase.Zone == zone && checkRange)
{
dockingBase.IsInDockingRange(this).ThrowIfFalse(ErrorCodes.DockingOutOfRange);
}
AccessLevel currentAccess = Session.AccessLevel;
if (!currentAccess.IsAdminOrGm())
{
_ = dockingBase.IsDockingAllowed(Character).ThrowIfError();
}
DockToBase(zone, dockingBase);
}
/// <summary>
/// Make the docking happen
/// </summary>
/// <param name="zone"></param>
/// <param name="dockingBase"></param>
public void DockToBase(IZone zone, DockingBase dockingBase)
{
States.Dock = true;
PublicContainer publicContainer = dockingBase.GetPublicContainer();
FullArmorRepair();
publicContainer.AddItem(this, false);
publicContainer.Save();
dockingBase.DockIn(Character, NormalUndockDelay, ZoneExitType.Docked);
Transaction.Current.OnCommited(() =>
{
RemoveFromZone();
MissionHelper.MissionAdvanceDockInTarget(Character.Id, zone.Id, CurrentPosition);
_ = TransportAssignment.DeliverTransportAssignmentAsync(Character);
});
}
public ErrorCodes CheckPvp()
{
IZone zone = Zone;
Debug.Assert(zone != null);
return !HasPvpEffect && (zone.Configuration.Protected || EffectHandler.ContainsEffect(EffectType.effect_syndicate_area))
? ErrorCodes.PvpIsNotAllowed
: ErrorCodes.NoError;
}
public bool IsInDefaultCorporation()
{
return DefaultCorporationDataCache.IsCorporationDefault(CorporationEid);
}
public override ItemPropertyModifier GetPropertyModifier(AggregateField field)
{
ItemPropertyModifier modifier = base.GetPropertyModifier(field);
if (Character == Character.None)
{
return modifier;
}
CharacterExtensionCollection characterExtensions = Character.GetExtensions();
System.Collections.Immutable.ImmutableDictionary<int, ExtensionInfo> extensions = extensionReader.GetExtensions();
double extensionBonus = characterExtensions
.Select(e => extensions[e.id])
.Where(e => e.aggregateField == field)
.Sum(e => characterExtensions.GetLevel(e.id) * e.bonus);
extensionBonus += ExtensionBonuses
.Where(e => e.aggregateField == field)
.Sum(e => characterExtensions.GetLevel(e.extensionId) * e.bonus);
if (!extensionBonus.IsZero())
{
ItemPropertyModifier m = ItemPropertyModifier.Create(field, extensionBonus);
m.NormalizeExtensionBonus();
m.Modify(ref modifier);
}
return modifier;
}
public override void OnAggression(Unit victim)
{
base.OnAggression(victim);
AddInCombatWith(victim);
if (victim is ITaggable taggable)
{
taggable.Tag(this, TimeSpan.Zero);
}
if (IsUnitPVPAggro(victim))
{
ApplyPvPEffect();
return;
}
if (!(victim is Player victimPlayer))
{
return;
}
victimPlayer.Session.CancelLogout();
ApplyPvPEffect();
if (IsInSameCorporation(victimPlayer))
{
return;
}
if (HasPvpEffect && victimPlayer.HasPvpEffect)
{
return;
}
}
public void OnPvpSupport(Unit target)
{
if (target is Player player && player.HasPvpEffect)
{
ApplyPvPEffect();
}
}
public override string InfoString => $"Player:{Character.Id}:{Definition}:{Eid}";
public void SendInitSelf()
{
IZone zone = Zone;
Debug.Assert(zone != null, "zone != null");
Session.SendPacket(EnterPacketBuilder);
Session.SendTerrainData();
zone.SendBeamsToPlayer(this, GridDistricts.All);
IEnumerable<Packet> lockPackets = GetLockPackets();
Session.SendPackets(lockPackets);
foreach (IUnitVisibility visibility in GetVisibleUnits())
{
Session.SendPacket(visibility.Target.EnterPacketBuilder);
if (!(visibility.Target is Robot robot))
{
continue;
}
IEnumerable<Packet> unitLockPackets = robot.GetLockPackets();
Session.SendPackets(unitLockPackets);
}
Session.SendPacket(new GangUpdatePacketBuilder(Visibility.Visible, zone.GetGangMembers(Gang)));
Session.SendPacket(zone.Weather.GetCurrentWeather().CreateUpdatePacket());
foreach (Effect effect in EffectHandler.Effects)
{
Session.SendPacket(new EffectPacketBuilder(effect, true));
}
foreach (ActiveModule module in ActiveModules)
{
module.ForceUpdate();
}
}
public void WriteFQLog(string message)
{
LogEvent e = new LogEvent
{
LogType = LogType.Info,
Tag = "FQ",
Message = $"{InfoString} - {message}",
};
Logger.Log(e);
}
public void SendForceUpdate()
{
Session.SendPacket(new UnitUpdatePacketBuilder(this, UpdatePacketControl.ForceReposition));
}
public override void OnCombatEvent(Unit source, CombatEventArgs e)
{
base.OnCombatEvent(source, e);
Player player = Zone.ToPlayerOrGetOwnerPlayer(source);
if (player == null)
{
return;
}
CombatLogger logger = LazyInitializer.EnsureInitialized(ref combatLogger, CreateCombatLogger);
logger.Log(player, e);
}
public static Player LoadPlayerAndAddToZone(IZone zone, Character character)
{
using (TransactionScope scope = Db.CreateTransaction())
{
Player player = (Player)character.GetActiveRobot().ThrowIfNull(ErrorCodes.ARobotMustBeSelected);
DockingBase dockingBase = null;
ZoneEnterType zoneEnterType;
Position spawnPosition;
if (character.IsDocked)
{
zoneEnterType = ZoneEnterType.Undock;
dockingBase = character.GetCurrentDockingBase();
spawnPosition = UndockSpawnPositionSelector.SelectSpawnPosition(dockingBase);
character.ZoneId = zone.Id;
character.ZonePosition = spawnPosition;
character.IsDocked = false;
}
else
{
zoneEnterType = ZoneEnterType.Teleport;
_ = zone.Id.ThrowIfNotEqual(character.ZoneId ?? -1, ErrorCodes.InvalidZoneId);
Position? zonePosition = character.ZonePosition.ThrowIfNull(ErrorCodes.InvalidPosition);
spawnPosition = (Position)zonePosition;
}
spawnPosition = zone.FixZ(spawnPosition);
ClosestWalkablePositionFinder finder = new ClosestWalkablePositionFinder(zone, spawnPosition, player);
Position validPosition = finder.FindOrThrow();
ZoneStorage zoneStorage = zone.Configuration.GetStorage();
player.Parent = zoneStorage.Eid;
player.FullCoreRecharge();
player.Save();
Transaction.Current.OnCommited(() =>
{
dockingBase?.LeaveChannel(character);
player.CorporationEid = character.CorporationEid;
zone.SetGang(player);
player.AddToZone(zone, validPosition, zoneEnterType);
player.ApplyInvulnerableEffect();
});
scope.Complete();
return player;
}
}
[CanBeNull]
public Task TeleportToPositionAsync(Position target, bool applyTeleportSickness, bool applyInvulnerable)
{
IZone zone = Zone;
if (zone == null)
{
return null;
}
TeleportWithinZone teleport = teleportStrategyFactories.TeleportWithinZoneFactory();
if (teleport == null)
{
return null;
}
teleport.TargetPosition = target;
teleport.ApplyTeleportSickness = applyTeleportSickness;
teleport.ApplyInvulnerable = applyInvulnerable;
Task task = teleport.DoTeleportAsync(this);
return task?.LogExceptions();
}
public void SendStartProgressBar(Unit unit, TimeSpan timeout, TimeSpan start)
{
Dictionary<string, object> data = unit.BaseInfoToDictionary();
data.Add(k.timeOut, (int)timeout.TotalMilliseconds);
data.Add(k.started, (long)start.TotalMilliseconds);
data.Add(k.now, (long)start.TotalMilliseconds);
Message.Builder
.SetCommand(Commands.AlarmStart)
.WithData(data)
.ToCharacter(Character)
.Send();
}
public void SendEndProgressBar(Unit unit, bool success = true)
{
Dictionary<string, object> info = unit.BaseInfoToDictionary();
info.Add(k.success, success);
Message.Builder.SetCommand(Commands.AlarmOver).WithData(info).ToCharacter(Character).Send();
}
public void SendArtifactRadarBeam(Position targetPosition)
{
BeamBuilder builder = Beam.NewBuilder()
.WithType(BeamType.artifact_radar)
.WithSourcePosition(targetPosition)
.WithTargetPosition(targetPosition)
.WithState(BeamState.AlignToTerrain)
.WithDuration(TimeSpan.FromSeconds(30));
Session.SendBeam(builder);
}
public bool IsStandingMatch(long targetCorporationEid, double? standingLimit)
{
return corporationManager.IsStandingMatch(targetCorporationEid, CorporationEid, standingLimit);
}
public void ReloadContainer()
{
if (Transaction.Current != null)
{
Reload();
}
else
{
using (TransactionScope scope = Db.CreateTransaction())
{
Reload();
scope.Complete();
}
}
}
public void UpdateCorporationOnZone(long newCorporationEid)
{
CorporationEid = newCorporationEid;
Character[] playersOnZone = Zone.GetCharacters().ToArray();
if (playersOnZone.Length <= 0)
{
return;
}
Dictionary<string, object> result = new Dictionary<string, object>
{
{k.corporationEID, newCorporationEid},
{k.characterID, Character.Id},
};
Message.Builder.SetCommand(Commands.CharacterUpdate).WithData(result).ToCharacters(playersOnZone).Send();
}
public override void UpdateVisibilityOf(Unit target)
{
target.UpdatePlayerVisibility(this);
}
public void SetCombatState(bool state)
{
States.Combat = state;
combatTimer.Reset();
if (state)
{
Session.ResetLogoutTimer();
}
}
public void AddInCombatWith(Unit enemy)
{
SetCombatState(true);
Player enemyPlayer = enemy as Player;
enemyPlayer?.SetCombatState(true);
}
public bool IsInSameCorporation(Player player)
{
return (CorporationEid == player.CorporationEid) && !IsInDefaultCorporation();
}
public bool IsUnitPVPAggro(Unit unit)
{
return unit is MobileTeleport ||
unit is IPBSObject ||
unit is WallHealer ||
unit is ProximityDeviceBase ||
(unit is BlobEmitterUnit b && b.IsPlayerSpawned) ||
(unit is RemoteControlledCreature remoteControlledCreature &&
remoteControlledCreature.CommandRobot is Player player &&
remoteControlledCreature.CommandRobot != player);
}
protected override void OnDead(Unit killer)
{
_ = HandlePlayerDeadAsync(Zone, killer).ContinueWith(t => base.OnDead(killer));
}
protected override void OnTileChanged()
{
base.OnTileChanged();
IZone zone = Zone;
if (zone == null)
{
return;
}
MissionHandler?.MissionUpdateOnTileChange();
TerrainControlInfo controlInfo = zone.Terrain.Controls.GetValue(CurrentPosition);
ApplyHighwayEffect(controlInfo.IsAnyHighway);
if (zone.Configuration.Protected)
{
return;
}
ApplySyndicateAreaEffect(controlInfo.SyndicateArea);
}
protected override void OnCellChanged(CellCoord lastCellCoord, CellCoord currentCellCoord)
{
base.OnCellChanged(lastCellCoord, currentCellCoord);
IZone zone = Zone;
if (zone == null)
{
return;
}
_ = Task.Run(() =>
{
GridDistricts district = currentCellCoord.ComputeDistrict(lastCellCoord);
zone.SendBeamsToPlayer(this, district);
Session.SendTerrainData();
}).LogExceptions();
}
protected override void UpdateUnitVisibility(Unit target)
{
UpdateVisibility(target);
}
protected internal override void UpdatePlayerVisibility(Player player)
{
UpdateVisibility(player);
}
protected override bool IsDetected(Unit target)
{
return Gang.IsMember(target) || base.IsDetected(target);
}
protected override bool IsHostileFor(Unit unit)
{
return unit.IsHostile(this);
}
protected override void OnBroadcastPacket(IBuilder<Packet> packetBuilder)
{
base.OnBroadcastPacket(packetBuilder);
Session.SendPacket(packetBuilder.Build());
}
protected override void OnUnitVisibilityUpdated(Unit target, Visibility visibility)
{
switch (visibility)
{
case Visibility.Visible:
{
target.BroadcastPacket += OnUnitBroadcastPacket;
target.Updated += OnUnitUpdated;
Session.SendPacket(target.EnterPacketBuilder);
break;
}
case Visibility.Invisible:
{
target.BroadcastPacket -= OnUnitBroadcastPacket;
target.Updated -= OnUnitUpdated;
Session.SendPacket(target.ExitPacketBuilder);
break;
}
}
if (Gang.IsMember(target))
{
Session.SendPacket(new GangUpdatePacketBuilder(visibility, (Player)target));
}
base.OnUnitVisibilityUpdated(target, visibility);
}
protected override void OnLockStateChanged(Lock @lock)
{
base.OnLockStateChanged(@lock);
if (@lock is UnitLock u)
{
Player player = u.Target as Player;
player?.Session.CancelLogout();
if (@lock.State == LockState.Locked)
{
if (u.Target is Npc npc)
{
MissionHandler.EnqueueMissionEventInfo(new LockUnitEventInfo(this, npc, npc.CurrentPosition));
MissionHandler.SignalParticipationByLocking(npc.GetMissionGuid());
}
}
}
if (@lock.State == LockState.Inprogress && EffectHandler.ContainsEffect(EffectType.effect_invulnerable))
{
EffectHandler.RemoveEffectsByType(EffectType.effect_invulnerable);
}
}
protected override void OnEffectChanged(Effect effect, bool apply)
{
base.OnEffectChanged(effect, apply);
if (!apply)
{
return;
}
switch (effect.Type)
{
case EffectType.effect_demobilizer:
{
OnCombatEvent(effect.Source, new DemobilizerEventArgs());
break;
}
case EffectType.effect_sensor_supress:
{
OnCombatEvent(effect.Source, new SensorDampenerEventArgs());
break;
}
}
}
protected override void OnLockError(Lock @lock, ErrorCodes error)
{
SendError(error);
base.OnLockError(@lock, error);
}
protected override void OnEnterZone(IZone zone, ZoneEnterType enterType)
{
base.OnEnterZone(zone, enterType);
check = PlayerMoveCheckQueue.Create(this, CurrentPosition);
zone.SendPacketToGang(Gang, new GangUpdatePacketBuilder(Visibility.Visible, this));
MissionHandler = missionHandlerFactory(zone, this);
MissionHandler.InitMissions();
Direction = FastRandom.NextDouble();
IDynamicProperty<int> p = DynamicProperties.GetProperty<int>(k.pvpRemaining);
if (!p.HasValue)
{
return;
}
ApplyPvPEffect(TimeSpan.FromMilliseconds(p.Value));
p.Clear();
}
protected override void OnRemovedFromZone(IZone zone)
{
Session.SendPacket(ExitPacketBuilder);
zone.SendPacketToGang(Gang, new GangUpdatePacketBuilder(Visibility.Invisible, this));
check.StopAndDispose();
if (!States.LocalTeleport)
{
Session.Stop();
}
base.OnRemovedFromZone(zone);
}
protected override void OnUpdate(TimeSpan time)
{
base.OnUpdate(time);
UpdateCombat(time);
movement.Update(time);
blobHandler.Update(time);
MissionHandler.Update(time);
combatLogger?.Update(time);
despawnHelper?.Update(time, this);
}
private void OnUnitUpdated(Unit unit, UnitUpdatedEventArgs e)
{
if (!Gang.IsMember(unit))
{
return;
}
bool send = (e.UpdateTypes & UnitUpdateTypes.Visibility) > 0 || (e.UpdatedProperties != null && e.UpdatedProperties.Any(p => p.Field.IsPublic()));
if (!send)
{
return;
}
Visibility v = Visibility.Invisible;
if (unit.InZone)
{
v = Visibility.Visible;
}
Session.SendPacket(new GangUpdatePacketBuilder(v, (Player)unit));
}
private void OnUnitBroadcastPacket(Unit sender, Packet packet)
{
Session.SendPacket(packet);
}
private void UpdateCombat(TimeSpan time)
{
if (!States.Combat)
{
return;
}
_ = combatTimer.Update(time);