/
SpellHelper.cs
1795 lines (1410 loc) · 58.2 KB
/
SpellHelper.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 Server.Engines.PartySystem;
using Server.Guilds;
using Server.Items;
using Server.Misc;
using Server.Mobiles;
using Server.Multis;
using Server.Regions;
using Server.Services.Virtues;
using Server.Spells.Fifth;
using Server.Spells.Fourth;
using Server.Spells.Necromancy;
using Server.Spells.Ninjitsu;
using Server.Spells.Seventh;
using Server.Targeting;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Server.Spells
{
public enum TravelCheckType
{
RecallFrom,
RecallTo,
GateFrom,
GateTo,
Mark,
TeleportFrom,
TeleportTo
}
public class SpellHelper
{
#region Spell Focus and SDI Calculations
private static readonly SkillName[] _Schools =
{
SkillName.Magery,
SkillName.Mysticism,
SkillName.Necromancy,
SkillName.AnimalTaming,
SkillName.Musicianship,
SkillName.Spellweaving,
SkillName.Chivalry,
SkillName.Bushido,
SkillName.Ninjitsu,
SkillName.Parry,
SkillName.EvalInt,
SkillName.SpiritSpeak,
SkillName.Focus,
SkillName.Imbuing
};
private static bool IsExempt(SkillName main, SkillName secondary)
{
switch (main)
{
default: return false;
case SkillName.Magery: return secondary == SkillName.EvalInt;
case SkillName.Necromancy: return secondary == SkillName.SpiritSpeak;
case SkillName.Mysticism: return secondary == SkillName.Focus || secondary == SkillName.Imbuing;
}
}
public static bool HasSpellFocus(Mobile m, SkillName focus)
{
bool foundExempt = false;
foreach (SkillName skill in _Schools)
{
if (skill != focus && m.Skills[skill].Value >= 30.0)
{
if (!foundExempt && IsExempt(focus, skill))
{
foundExempt = true;
}
else
{
return false;
}
}
}
return true;
}
public static int PvPSpellDamageCap(Mobile m, SkillName castskill)
{
if (HasSpellFocus(m, castskill))
{
return 25;
}
else
{
return 20;
}
}
public static int GetSpellDamageBonus(Mobile caster, IDamageable damageable, SkillName skill, bool playerVsPlayer)
{
Mobile target = damageable as Mobile;
int sdiBonus = AosAttributes.GetValue(caster, AosAttribute.SpellDamage);
if (target != null)
{
if (RunedSashOfWarding.IsUnderEffects(target, WardingEffect.SpellDamage))
sdiBonus -= 10;
sdiBonus -= Block.GetSpellReduction(target);
}
// PvP spell damage increase cap of 15% from an item’s magic property, 30% if spell school focused.
if (playerVsPlayer)
{
sdiBonus = Math.Min(sdiBonus, PvPSpellDamageCap(caster, skill));
}
return sdiBonus;
}
#endregion
private static readonly TimeSpan AosDamageDelay = TimeSpan.FromSeconds(1.0);
private static readonly TimeSpan OldDamageDelay = TimeSpan.FromSeconds(0.5);
public static TimeSpan GetDamageDelayForSpell(Spell sp)
{
if (!sp.DelayedDamage)
return TimeSpan.Zero;
return (AosDamageDelay);
}
public static bool CheckMulti(Point3D p, Map map)
{
return CheckMulti(p, map, true, 0);
}
public static bool CheckMulti(Point3D p, Map map, bool houses)
{
return CheckMulti(p, map, houses, 0);
}
public static bool CheckMulti(Point3D p, Map map, bool houses, int housingrange)
{
if (map == null || map == Map.Internal)
return false;
Sector sector = map.GetSector(p.X, p.Y);
for (int i = 0; i < sector.Multis.Count; ++i)
{
BaseMulti multi = sector.Multis[i];
if (multi is BaseHouse)
{
BaseHouse bh = (BaseHouse)multi;
if ((houses && bh.IsInside(p, 16)) || (housingrange > 0 && bh.InRange(p, housingrange)))
return true;
}
else if (multi.Contains(p))
{
return true;
}
}
return false;
}
public static void Turn(Mobile from, object to)
{
IPoint3D target = to as IPoint3D;
int d = -1;
if (target == null)
return;
if (target is Item)
{
Item item = (Item)target;
if (item.RootParent != from)
d = (int)from.GetDirectionTo(item.GetWorldLocation());
}
else if (from != target)
{
d = (int)from.GetDirectionTo(target);
}
if (d > -1)
{
from.Direction = (Direction)d;
from.ProcessDelta();
}
}
public static bool CheckCombat(Mobile m, bool restrict = true)
{
if (!restrict)
return false;
return Aggression.CheckHasAggression(m, true);
}
public static bool AdjustField(ref Point3D p, Map map, int height, bool mobsBlock)
{
if (map == null)
return false;
for (int offset = 0; offset < 25; ++offset)
{
Point3D loc = new Point3D(p.X, p.Y, p.Z - offset);
if (map.CanFit(loc, height, true, mobsBlock))
{
p = loc;
return true;
}
loc = new Point3D(p.X, p.Y, p.Z + offset);
if (map.CanFit(loc, height, true, mobsBlock))
{
p = loc;
return true;
}
}
return false;
}
public static bool CheckField(Point3D p, Map map)
{
if (map == null)
return false;
IPooledEnumerable eable = map.GetItemsInRange(p, 0);
foreach (Item item in eable)
{
Type t = item.GetType();
if (t.IsDefined(typeof(DispellableFieldAttribute), false) || t.IsDefined(typeof(DispellableFieldAttribute), true))
{
eable.Free();
return false;
}
}
eable.Free();
return true;
}
public static bool CheckWater(Point3D p, Map map)
{
LandTile landTile = map.Tiles.GetLandTile(p.X, p.Y);
if (landTile.Z == p.Z && ((landTile.ID >= 168 && landTile.ID <= 171) || (landTile.ID >= 310 && landTile.ID <= 311)))
{
return false;
}
StaticTile[] tiles = map.Tiles.GetStaticTiles(p.X, p.Y, true);
foreach (StaticTile tile in tiles)
{
if (tile.Z == p.Z && tile.ID >= 0x1796 && tile.ID <= 0x17B2)
{
return false;
}
}
return true;
}
public static bool CanRevealCaster(Mobile m)
{
if (m is BaseCreature)
{
BaseCreature c = (BaseCreature)m;
if (!c.Controlled)
return true;
}
return false;
}
public static void GetSurfaceTop(ref IPoint3D p)
{
if (p is Item)
{
p = ((Item)p).GetSurfaceTop();
}
else if (p is StaticTarget)
{
StaticTarget t = (StaticTarget)p;
int z = t.Z;
if ((t.Flags & TileFlag.Surface) == 0)
z -= TileData.ItemTable[t.ItemID & TileData.MaxItemValue].CalcHeight;
p = new Point3D(t.X, t.Y, z);
}
}
protected static void RemoveStatOffsetCallback(object state)
{
if (!(state is Mobile))
return;
// This call has the side-effect of updating all stats
((Mobile)state).CheckStatTimers();
}
public static bool AddStatOffset(Mobile m, StatType type, int offset, TimeSpan duration)
{
if (offset > 0)
return AddStatBonus(m, m, type, offset, duration);
else if (offset < 0)
return AddStatCurse(m, m, type, -offset, duration);
return true;
}
public static bool AddStatBonus(Mobile caster, Mobile target, bool blockSkill, StatType type)
{
return AddStatBonus(caster, target, type, GetOffset(caster, target, type, false, blockSkill), GetDuration(caster, target));
}
public static bool AddStatBonus(Mobile caster, Mobile target, StatType type, int bonus, TimeSpan duration)
{
int offset = bonus;
string name = string.Format("[Magic] {0} Buff", type);
StatMod mod = target.GetStatMod(name);
if (mod != null)
{
offset = Math.Max(mod.Offset, offset);
}
target.AddStatMod(new StatMod(type, name, offset, duration));
Timer.DelayCall(duration, RemoveStatOffsetCallback, target);
return true;
}
public static int GetBuffOffset(Mobile m, StatType type)
{
string name = string.Format("[Magic] {0} Buff", type);
StatMod mod = m.GetStatMod(name);
return mod != null ? mod.Offset : 0;
}
public static bool AddStatCurse(Mobile caster, Mobile target, StatType type)
{
return AddStatCurse(caster, target, type, true);
}
public static bool AddStatCurse(Mobile caster, Mobile target, StatType type, bool blockSkill)
{
return AddStatCurse(caster, target, type, GetOffset(caster, target, type, true, blockSkill), TimeSpan.Zero);
}
public static bool AddStatCurse(Mobile caster, Mobile target, StatType type, bool blockSkill, int offset)
{
return AddStatCurse(caster, target, type, offset, TimeSpan.Zero);
}
public static bool AddStatCurse(Mobile caster, Mobile target, StatType type, int curse, TimeSpan duration)
{
int offset = curse;
string name = string.Format("[Magic] {0} Curse", type);
StatMod mod = target.GetStatMod(name);
if (mod != null)
offset = Math.Max(mod.Offset, offset);
offset *= -1;
target.AddStatMod(new StatMod(type, name, offset, duration));
return true;
}
public static TimeSpan GetDuration(Mobile caster, Mobile target)
{
int span = (((6 * caster.Skills.EvalInt.Fixed) / 50) + 1);
if (caster.Spell is CurseSpell && SkillMasteries.ResilienceSpell.UnderEffects(target))
span /= 2;
return TimeSpan.FromSeconds(span);
}
public static int GetCurseOffset(Mobile m, StatType type)
{
string name = string.Format("[Magic] {0} Curse", type);
StatMod mod = m.GetStatMod(name);
return mod != null ? mod.Offset : 0;
}
public static double GetOffsetScalar(Mobile caster, Mobile target, bool curse)
{
double percent;
if (curse)
{
double resistFixed = target.Skills.MagicResist.Fixed - (EvilOmenSpell.GetResistMalus(target) * 10);
percent = 8 + (caster.Skills.EvalInt.Fixed / 100) - (resistFixed / 100);
}
else
percent = 1 + (caster.Skills.EvalInt.Fixed / 100);
percent *= 0.01;
if (percent < 0)
percent = 0;
return percent;
}
public static int GetOffset(Mobile caster, Mobile target, StatType type, bool curse, bool blockSkill)
{
if (!blockSkill)
{
if (curse)
target.CheckSkill(SkillName.MagicResist, 0.0, 120.0);
}
double percent = GetOffsetScalar(caster, target, curse);
switch (type)
{
case StatType.Str:
return (int)Math.Ceiling(target.RawStr * percent);
case StatType.Dex:
return (int)Math.Ceiling(target.RawDex * percent);
case StatType.Int:
return (int)Math.Ceiling(target.RawInt * percent);
}
return 1 + (int)(caster.Skills[SkillName.Magery].Value * 0.1);
}
public static Guild GetGuildFor(Mobile m)
{
Guild g = m.Guild as Guild;
if (g == null && m is BaseCreature)
{
BaseCreature c = (BaseCreature)m;
m = c.ControlMaster;
if (m != null)
g = m.Guild as Guild;
if (g == null)
{
m = c.SummonMaster;
if (m != null)
g = m.Guild as Guild;
}
}
return g;
}
public static bool ValidIndirectTarget(Mobile from, Mobile to)
{
if (from == to)
{
return true;
}
if (to.Hidden && to.AccessLevel > from.AccessLevel || Engines.ArenaSystem.PVPArenaSystem.IsFriendly(from, to))
{
return false;
}
CheckResponsible(ref from);
CheckResponsible(ref to);
var noto = Notoriety.Compute(from, to);
if (noto == Notoriety.Enemy)
{
return true;
}
if (IsGuildAllyOrParty(from, to))
{
return false;
}
var toCreature = to as BaseCreature;
if (toCreature != null && (toCreature.Controlled || toCreature.Summoned))
{
var master = toCreature.GetMaster();
if (master == from || IsParty(master, from))
{
return false;
}
}
var fromCreature = from as BaseCreature;
if (fromCreature != null)
{
if (fromCreature.Controlled || fromCreature.Summoned)
{
var master = fromCreature.GetMaster();
if (master == to)
{
return false;
}
if (IsParty(master, to))
{
return false;
}
}
else
{
if (to.Player ||
(toCreature != null && (toCreature.Controlled || toCreature.Summoned) && toCreature.GetMaster() is PlayerMobile))
{
return true;
}
}
}
// Non-enemy monsters will no longer flag area spells on each other
if (fromCreature != null && toCreature != null)
{
if (fromCreature.GetMaster() is BaseCreature)
{
fromCreature = fromCreature.GetMaster() as BaseCreature;
}
if (toCreature.GetMaster() is BaseCreature)
{
toCreature = toCreature.GetMaster() as BaseCreature;
}
if (toCreature.IsEnemy(fromCreature)) //Natural Enemies
{
return true;
}
//All involved are monsters- no damage. If falls through this statement, normal noto rules apply
if (!toCreature.Controlled && !toCreature.Summoned && !fromCreature.Controlled && !fromCreature.Summoned) //All involved are monsters- no damage
{
return false;
}
}
if (toCreature != null && !toCreature.Controlled && toCreature.InitialInnocent)
{
return true;
}
return (noto != Notoriety.Innocent || from.Murderer);
}
public static bool CheckResponsible(ref Mobile m)
{
var bc = m as BaseCreature;
if (bc != null && bc.GetMaster() != null)
{
m = bc.GetMaster();
return true;
}
return false;
}
public static bool IsGuildAllyOrParty(Mobile from, Mobile to)
{
return IsGuild(from, to) || IsParty(from, to);
}
public static bool IsGuild(Mobile from, Mobile to)
{
Guild fromGuild = GetGuildFor(from);
Guild toGuild = GetGuildFor(to);
return fromGuild != null && toGuild != null && (fromGuild == toGuild || fromGuild.IsAlly(toGuild));
}
public static bool IsParty(Mobile from, Mobile to)
{
Party p = Party.Get(from);
return p != null && p.Contains(to);
}
public static IEnumerable<IDamageable> AcquireIndirectTargets(Mobile caster, IPoint3D p, Map map, int range)
{
return AcquireIndirectTargets(caster, p, map, range, true);
}
public static IEnumerable<IDamageable> AcquireIndirectTargets(Mobile caster, IPoint3D p, Map map, int range, bool losCheck)
{
if (map == null)
{
yield break;
}
IPooledEnumerable eable = map.GetObjectsInRange(new Point3D(p), range);
foreach (IDamageable id in eable.OfType<IDamageable>())
{
if (id == caster)
{
continue;
}
if (!id.Alive || (losCheck && !caster.InLOS(id)) || !caster.CanBeHarmful(id, false))
{
continue;
}
if (id is Mobile && !ValidIndirectTarget(caster, (Mobile)id))
{
continue;
}
yield return id;
}
eable.Free();
}
private static readonly int[] m_Offsets = new int[]
{
-1, -1,
-1, 0,
-1, 1,
0, -1,
0, 1,
1, -1,
1, 0,
1, 1
};
public static void Summon(BaseCreature creature, Mobile caster, int sound, TimeSpan duration, bool scaleDuration, bool scaleStats, bool summoned = true, SkillName useSkill = SkillName.Magery)
{
Map map = caster.Map;
if (map == null)
return;
double scale = 1.0 + ((caster.Skills[useSkill].Value - 100.0) / 200.0);
if (scaleDuration)
duration = TimeSpan.FromSeconds(duration.TotalSeconds * scale);
if (scaleStats)
{
creature.RawStr = (int)(creature.RawStr * scale);
creature.Hits = creature.HitsMax;
creature.RawDex = (int)(creature.RawDex * scale);
creature.Stam = creature.StamMax;
creature.RawInt = (int)(creature.RawInt * scale);
creature.Mana = creature.ManaMax;
}
Point3D p = new Point3D(caster);
if (FindValidSpawnLocation(map, ref p, true))
{
BaseCreature.Summon(creature, summoned, caster, p, sound, duration);
return;
}
creature.Delete();
caster.SendLocalizedMessage(501942); // That location is blocked.
}
public static bool FindValidSpawnLocation(Map map, ref Point3D p, bool surroundingsOnly)
{
if (map == null) //sanity
return false;
if (!surroundingsOnly)
{
if (map.CanSpawnMobile(p)) //p's fine.
{
p = new Point3D(p);
return true;
}
int z = map.GetAverageZ(p.X, p.Y);
if (map.CanSpawnMobile(p.X, p.Y, z))
{
p = new Point3D(p.X, p.Y, z);
return true;
}
}
int offset = Utility.Random(8) * 2;
for (int i = 0; i < m_Offsets.Length; i += 2)
{
int x = p.X + m_Offsets[(offset + i) % m_Offsets.Length];
int y = p.Y + m_Offsets[(offset + i + 1) % m_Offsets.Length];
if (map.CanSpawnMobile(x, y, p.Z))
{
p = new Point3D(x, y, p.Z);
return true;
}
else
{
int z = map.GetAverageZ(x, y);
if (map.CanSpawnMobile(x, y, z))
{
p = new Point3D(x, y, z);
return true;
}
}
}
return false;
}
public static bool RestrictRedTravel => Config.Get("General.RestrictRedsToFel", false);
private delegate bool TravelValidator(Map map, Point3D loc);
private static readonly TravelValidator[] m_Validators = new TravelValidator[]
{
IsFeluccaT2A,
IsKhaldun,
IsIlshenar,
IsTrammelWind,
IsFeluccaWind,
IsFeluccaDungeon,
IsTrammelSolenHive,
IsFeluccaSolenHive,
IsDoomGauntlet,
IsDoomFerry,
IsSafeZone,
IsChampionSpawn,
IsTokunoDungeon,
IsLampRoom,
IsGuardianRoom,
IsHeartwood,
IsMLDungeon,
IsSADungeon,
IsTombOfKings,
IsMazeOfDeath,
IsSAEntrance,
IsEodon,
};
private static readonly bool[,] m_Rules = new bool[,]
{
/*T2A(Fel), Khaldun, Ilshenar, Wind(Tram), Wind(Fel), Dungeons(Fel), Solen(Tram), Solen(Fel), Gauntlet(Malas), Gauntlet(Ferry), SafeZone, ChampionSpawn, Dungeons(Tokuno[Malas]), LampRoom(Doom), GuardianRoom(Doom), Heartwood, MLDungeons, SA Dungeons Tomb of Kings Maze of Death SA Entrance, Eodon*/
/* Recall From */ { false, false, true, true, false, false, true, false, false, false, true, false, true, false, false, false, false, true, true, false, false, true} ,
/* Recall To */ { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false },
/* Gate From */ { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false },
/* Gate To */ { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false },
/* Mark In */ { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false },
/* Tele From */ { true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, false, false, false, true },
/* Tele To */ { true, true, true, true, true, true, true, true, true, false, false, true, true, true, true, false, false, true, false, false, false, true },
};
public static void SendInvalidMessage(Mobile caster, TravelCheckType type)
{
if (type == TravelCheckType.RecallTo || type == TravelCheckType.GateTo)
caster.SendLocalizedMessage(1019004); // You are not allowed to travel there.
else if (type == TravelCheckType.TeleportTo)
caster.SendLocalizedMessage(501035); // You cannot teleport from here to the destination.
else
caster.SendLocalizedMessage(501802); // Thy spell doth not appear to work...
}
public static bool CheckTravel(Mobile caster, TravelCheckType type)
{
return CheckTravel(caster, caster.Map, caster.Location, type);
}
public static bool CheckTravel(Map map, Point3D loc, TravelCheckType type)
{
return CheckTravel(null, map, loc, type);
}
private static Mobile m_TravelCaster;
private static TravelCheckType m_TravelType;
public static bool CheckTravel(Mobile caster, Map map, Point3D loc, TravelCheckType type)
{
if (IsInvalid(map, loc)) // null, internal, out of bounds
{
if (caster != null)
SendInvalidMessage(caster, type);
return false;
}
if (caster != null)
{
if (caster.IsPlayer())
{
// Jail region
if (caster.Region.IsPartOf<Jail>())
{
caster.SendLocalizedMessage(1114345); // You'll need a better jailbreak plan than that!
return false;
}
else if (caster.Region is GreenAcres)
{
caster.SendLocalizedMessage(502360); // You cannot teleport into that area.
return false;
}
}
// Always allow monsters to teleport
if (caster is BaseCreature && (type == TravelCheckType.TeleportTo || type == TravelCheckType.TeleportFrom))
{
BaseCreature bc = (BaseCreature)caster;
if (!bc.Controlled && !bc.Summoned)
return true;
}
if (Siege.SiegeShard && !Siege.CheckTravel(caster, loc, map, type))
{
return false;
}
}
m_TravelCaster = caster;
m_TravelType = type;
int v = (int)type;
bool isValid = true;
if (caster != null)
{
BaseRegion destination = Region.Find(loc, map) as BaseRegion;
BaseRegion current = Region.Find(caster.Location, caster.Map) as BaseRegion;
if (destination != null && !destination.CheckTravel(caster, loc, type))
isValid = false;
if (isValid && current != null && !current.CheckTravel(caster, loc, type))
isValid = false;
if (caster.Region != null)
{
if (caster.Region.IsPartOf("Blighted Grove") && loc.Z < -10)
isValid = false;
}
if ((int)type <= 4 && (IsNewDungeon(caster.Map, caster.Location) || IsNewDungeon(map, loc)))
isValid = false;
if (BaseBoat.IsDriving(caster))
return false;
}
for (int i = 0; isValid && i < m_Validators.Length; ++i)
isValid = (m_Rules[v, i] || !m_Validators[i](map, loc));
if (!isValid && caster != null)
SendInvalidMessage(caster, type);
return isValid;
}
public static bool CheckCanTravel(Mobile m)
{
if (m.Criminal)
{
m.SendLocalizedMessage(1005561, "", 0x22); // Thou'rt a criminal and cannot escape so easily.
return false;
}
else if (CheckCombat(m))
{
m.SendLocalizedMessage(1005564, "", 0x22); // Wouldst thou flee during the heat of battle??
return false;
}
else if (WeightOverloading.IsOverloaded(m))
{
m.SendLocalizedMessage(502359, "", 0x22); // Thou art too encumbered to move.
return false;
}
return true;
}
public static bool IsWindLoc(Point3D loc)
{
int x = loc.X, y = loc.Y;
return (x >= 5120 && y >= 0 && x < 5376 && y < 256);
}
public static bool IsFeluccaWind(Map map, Point3D loc)
{
return (map == Map.Felucca && IsWindLoc(loc));
}
public static bool IsTrammelWind(Map map, Point3D loc)
{
return (map == Map.Trammel && IsWindLoc(loc));
}
public static bool IsIlshenar(Map map, Point3D loc)
{
return (map == Map.Ilshenar);
}
public static bool IsTrammelSolenHive(Map map, Point3D loc)
{
return map == Map.Trammel && Region.Find(loc, map).Name == "Solen Hives";
}
public static bool IsFeluccaSolenHive(Map map, Point3D loc)
{
return map == Map.Felucca && Region.Find(loc, map).Name == "Solen Hives";
}
public static bool IsFeluccaT2A(Map map, Point3D loc)
{
int x = loc.X, y = loc.Y;
return (map == Map.Felucca && x >= 5120 && y >= 2304 && x < 6144 && y < 4096);
}
public static bool IsAnyT2A(Map map, Point3D loc)
{
int x = loc.X, y = loc.Y;
return ((map == Map.Trammel || map == Map.Felucca) && x >= 5120 && y >= 2304 && x < 6144 && y < 4096);
}
public static bool IsFeluccaDungeon(Map map, Point3D loc)
{
Region region = Region.Find(loc, map);
return (region.IsPartOf<DungeonRegion>() && region.Map == Map.Felucca);
}
public static bool IsKhaldun(Map map, Point3D loc)
{
return (Region.Find(loc, map).Name == "Khaldun");
}
public static bool IsSafeZone(Map map, Point3D loc)
{
return false;
}
public static bool IsChampionSpawn(Map map, Point3D loc)
{
return (Region.Find(loc, map).IsPartOf<Engines.CannedEvil.ChampionSpawnRegion>());
}
public static bool IsDoomFerry(Map map, Point3D loc)
{
if (map != Map.Malas)
return false;
int x = loc.X, y = loc.Y;
if (x >= 426 && y >= 314 && x <= 430 && y <= 331)
return true;
if (x >= 406 && y >= 247 && x <= 410 && y <= 264)
return true;
return false;
}
public static bool IsTokunoDungeon(Map map, Point3D loc)
{
//The tokuno dungeons are really inside malas
if (map != Map.Malas)
return false;
int x = loc.X, y = loc.Y, z = loc.Z;
bool r1 = (x >= 0 && y >= 0 && x <= 128 && y <= 128);