Skip to content

Commit 3ae10e9

Browse files
change passability to a more dynamic model AscensionGameDev#2660 (AscensionGameDev#2662)
* change passability to a more dynamic model AscensionGameDev#2660 * return the right value in Player.CanPassPlayer --------- Co-authored-by: WeylonSantana <[email protected]>
1 parent 6c1d3f8 commit 3ae10e9

File tree

3 files changed

+12
-55
lines changed

3 files changed

+12
-55
lines changed
Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,17 @@
1-
using Newtonsoft.Json;
1+
using Intersect.Framework.Core.GameObjects.Maps;
22

33
namespace Intersect.Config;
44

5-
public partial class PassabilityOptions
5+
public partial class PassabilityOptions : Dictionary<MapZone, bool>
66
{
7-
private bool[]? _cache;
8-
private bool _arena;
9-
private bool _normal;
10-
private bool _safe = true;
7+
public bool Default { get; set; } = false;
118

12-
public bool Arena
9+
public PassabilityOptions()
1310
{
14-
get => _arena;
15-
set
16-
{
17-
if (value == _arena)
18-
{
19-
return;
20-
}
21-
22-
_arena = value;
23-
_cache = null;
24-
}
25-
}
26-
27-
//Can players move through each other on the following map types/moralities
28-
public bool Normal
29-
{
30-
get => _normal;
31-
set
32-
{
33-
if (value == _arena)
34-
{
35-
return;
36-
}
37-
38-
_normal = value;
39-
_cache = null;
40-
}
41-
}
42-
43-
public bool Safe
44-
{
45-
get => _safe;
46-
set
47-
{
48-
if (value == _arena)
49-
{
50-
return;
51-
}
52-
53-
_safe = value;
54-
_cache = null;
55-
}
11+
this[MapZone.Arena] = false;
12+
this[MapZone.Normal] = false;
13+
this[MapZone.Safe] = true;
5614
}
5715

58-
[JsonIgnore]
59-
public bool[] Passable => _cache ??= [Normal, Safe, Arena];
16+
public bool IsPassable(MapZone mapZoneType) => TryGetValue(mapZoneType, out var passable) ? passable : Default;
6017
}

Intersect.Client.Core/Entities/Entity.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,9 +2523,9 @@ public int IsTileBlocked(
25232523
break;
25242524

25252525
case Player player:
2526-
//Return the entity key as this should block the player. Only exception is if the MapZone this entity is on is passable.
2527-
var entityMap = Maps.MapInstance.Get(player.MapId);
2528-
if (Options.Instance.Passability.Passable[(int)entityMap.ZoneType])
2526+
// Return the entity key as this should block the player. Only exception is if the MapZone this entity is on is passable.
2527+
if (Maps.MapInstance.TryGet(player.MapId, out var playerMapInstance) &&
2528+
Options.Instance.Passability.IsPassable(playerMapInstance.ZoneType))
25292529
{
25302530
continue;
25312531
}

Intersect.Server.Core/Entities/Player.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7298,7 +7298,7 @@ out EntityType entityType
72987298

72997299
protected override bool CanPassPlayer(MapController targetMap)
73007300
{
7301-
return Options.Instance.Passability.Passable[(int)targetMap.ZoneType];
7301+
return Options.Instance.Passability.IsPassable(Map.ZoneType);
73027302
}
73037303

73047304
protected override bool IsBlockedByEvent(

0 commit comments

Comments
 (0)