Skip to content

Commit 395a0f2

Browse files
committed
fix(743): Reset player after warping to new map to prevent getting hit by a new effect while mid-respawn
1 parent 9213129 commit 395a0f2

File tree

6 files changed

+72
-55
lines changed

6 files changed

+72
-55
lines changed

Intersect.Server.Core/Entities/Entity.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public string FooterLabelJson
198198
}
199199

200200
[NotMapped]
201-
public bool Dead { get; set; }
201+
public bool IsDead { get; set; }
202202

203203
//Combat
204204
[NotMapped, JsonIgnore]
@@ -1667,7 +1667,7 @@ public virtual void TryAttack(Entity target,
16671667
}
16681668
}
16691669

1670-
if (targetPlayer == null && !(target is Npc) || target.IsDead())
1670+
if (targetPlayer == null && !(target is Npc) || target.IsDead)
16711671
{
16721672
return;
16731673
}
@@ -2309,7 +2309,7 @@ public void Attack(
23092309
else
23102310
{
23112311
//PVP Kill common events
2312-
if (!enemy.Dead && enemy is Player enemyPlayer && this is Player)
2312+
if (!enemy.IsDead && enemy is Player enemyPlayer && this is Player)
23132313
{
23142314
thisPlayer.StartCommonEventsWithTrigger(CommonEventTrigger.PVPKill, "", enemy.Name);
23152315
enemyPlayer.StartCommonEventsWithTrigger(CommonEventTrigger.PVPDeath, "", this.Name);
@@ -2352,7 +2352,7 @@ public void Attack(
23522352

23532353
protected virtual void CheckForOnhitAttack(Entity enemy, bool isAutoAttack)
23542354
{
2355-
if (isAutoAttack && !enemy.IsDead()) //Ignore spell damage.
2355+
if (isAutoAttack && !enemy.IsDead) //Ignore spell damage.
23562356
{
23572357
foreach (var status in CachedStatuses)
23582358
{
@@ -3022,7 +3022,7 @@ protected bool IsOneBlockAway(Guid mapId, int x, int y, int z = 0)
30223022
//Spawning/Dying
30233023
public virtual void Die(bool dropItems = true, Entity killer = null)
30243024
{
3025-
if (IsDead() || Items == null)
3025+
if (IsDead || Items == null)
30263026
{
30273027
return;
30283028
}
@@ -3095,7 +3095,7 @@ public virtual void Die(bool dropItems = true, Entity killer = null)
30953095
CachedStatuses = new Status[0];
30963096
Stat?.ToList().ForEach(stat => stat?.Reset());
30973097

3098-
Dead = true;
3098+
IsDead = true;
30993099
}
31003100

31013101
protected virtual bool ShouldDropItem(Entity killer, ItemBase itemDescriptor, Item item, float dropRateModifier, out Guid lootOwner)
@@ -3161,19 +3161,22 @@ protected virtual void DropItems(Entity killer, bool sendUpdate = true)
31613161

31623162
protected abstract EntityItemSource? AsItemSource();
31633163

3164-
public bool IsDead()
3165-
{
3166-
return Dead;
3167-
}
3168-
31693164
public virtual void Reset()
31703165
{
31713166
for (var i = 0; i < Enum.GetValues<Vital>().Length; i++)
31723167
{
31733168
RestoreVital((Vital)i);
31743169
}
31753170

3176-
Dead = false;
3171+
// Remove any damage over time effects
3172+
DoT.Clear();
3173+
CachedDots = [];
3174+
Statuses.Clear();
3175+
CachedStatuses = [];
3176+
3177+
CombatTimer = 0;
3178+
3179+
IsDead = false;
31773180
}
31783181

31793182
//Empty virtual functions for players

Intersect.Server.Core/Entities/Npc.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ public override void Update(long timeMs)
832832
var targetY = 0;
833833
var targetZ = 0;
834834

835-
if (tempTarget != null && (tempTarget.IsDead() || !InRangeOf(tempTarget, Options.Instance.Map.MapWidth * 2) || !CanTarget(tempTarget)))
835+
if (tempTarget != null && (tempTarget.IsDead || !InRangeOf(tempTarget, Options.Instance.Map.MapWidth * 2) || !CanTarget(tempTarget)))
836836
{
837837
_ = TryFindNewTarget(Timing.Global.Milliseconds, tempTarget.Id, !CanTarget(tempTarget));
838838
tempTarget = Target;
@@ -886,7 +886,7 @@ public override void Update(long timeMs)
886886
//Check if there is a target, if so, run their ass down.
887887
if (tempTarget != null && CanTarget(tempTarget))
888888
{
889-
if (!tempTarget.IsDead() && CanAttack(tempTarget, null))
889+
if (!tempTarget.IsDead && CanAttack(tempTarget, null))
890890
{
891891
targetMap = tempTarget.MapId;
892892
targetX = tempTarget.X;
@@ -1448,7 +1448,7 @@ public bool ShouldAttackPlayerOnSight(Player en)
14481448
}
14491449

14501450
// Is this entry dead?, if so skip it.
1451-
if (en.Key.IsDead())
1451+
if (en.Key.IsDead)
14521452
{
14531453
continue;
14541454
}
@@ -1480,7 +1480,7 @@ public bool ShouldAttackPlayerOnSight(Player en)
14801480
{
14811481
foreach (var entity in instance.GetCachedEntities())
14821482
{
1483-
if (entity != null && !entity.IsDead() && entity != this && entity.Id != avoidId)
1483+
if (entity != null && !entity.IsDead && entity != this && entity.Id != avoidId)
14841484
{
14851485
//TODO Check if NPC is allowed to attack player with new conditions
14861486
if (entity is Player player)

Intersect.Server.Core/Entities/Player.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,24 +1091,17 @@ public override EntityType GetEntityType()
10911091
//Spawning/Dying
10921092
private void Respawn()
10931093
{
1094-
//Remove any damage over time effects
1095-
DoT.Clear();
1096-
CachedDots = new DoT[0];
1097-
Statuses.Clear();
1098-
CachedStatuses = new Status[0];
1099-
1100-
CombatTimer = 0;
1101-
1102-
var cls = ClassBase.Get(ClassId);
1103-
if (cls != null)
1094+
if (ClassBase.TryGet(ClassId, out _))
11041095
{
11051096
WarpToSpawn();
11061097
}
11071098
else
11081099
{
1109-
Warp(Guid.Empty, 0, 0, 0);
1100+
Warp(default, 0, 0, 0);
11101101
}
11111102

1103+
Reset();
1104+
11121105
PacketSender.SendEntityDataToProximity(this);
11131106

11141107
//Search death common event trigger
@@ -1159,7 +1152,6 @@ public override void Die(bool dropItems = true, Entity killer = null)
11591152
}
11601153
}
11611154
PacketSender.SendEntityDie(this);
1162-
Reset();
11631155
Respawn();
11641156
PacketSender.SendInventory(this);
11651157
}
@@ -1572,7 +1564,7 @@ public override void TryAttack(Entity target,
15721564
//If Entity is resource, check for the correct tool and make sure its not a spell cast.
15731565
if (target is Resource resource)
15741566
{
1575-
if (resource.IsDead())
1567+
if (resource.IsDead)
15761568
{
15771569
return;
15781570
}
@@ -1625,7 +1617,7 @@ public override void TryAttack(Entity target,
16251617

16261618
protected override void ReactToDamage(Vital vital)
16271619
{
1628-
if (IsDead() || IsDisposed)
1620+
if (IsDead || IsDisposed)
16291621
{
16301622
base.ReactToDamage(vital);
16311623
return;
@@ -1725,7 +1717,7 @@ public void TryAttack(Entity target)
17251717
//If Entity is resource, check for the correct tool and make sure its not a spell cast.
17261718
if (target is Resource resource)
17271719
{
1728-
if (resource.IsDead())
1720+
if (resource.IsDead)
17291721
{
17301722
return;
17311723
}

Intersect.Server.Core/Entities/ProjectileSpawn.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public bool HitEntity(Entity targetEntity)
121121
}
122122
else if (targetEntity is Resource targetResource)
123123
{
124-
if (targetResource.IsDead())
124+
if (targetResource.IsDead)
125125
{
126126
if (!ProjectileBase.IgnoreExhaustedResources)
127127
{

Intersect.Server.Core/Entities/Resource.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void Destroy(bool dropItems = false, Entity killer = null)
4444
{
4545
Die(dropItems, killer);
4646
}
47-
47+
4848
PacketSender.SendEntityDie(this);
4949
PacketSender.SendEntityLeave(this);
5050
}
@@ -55,10 +55,10 @@ public override void Die(bool dropItems = true, Entity killer = null)
5555
{
5656
base.Die(false, killer);
5757
}
58-
58+
5959
Sprite = Base.Exhausted.Graphic;
6060
Passable = Base.WalkableAfter;
61-
Dead = true;
61+
IsDead = true;
6262

6363
if (dropItems)
6464
{
@@ -101,7 +101,7 @@ public void Spawn()
101101
}
102102
}
103103

104-
Dead = false;
104+
IsDead = false;
105105
PacketSender.SendEntityDataToProximity(this);
106106
PacketSender.SendEntityPositionToAll(this);
107107
}
@@ -158,7 +158,7 @@ public void SpawnResourceItems(Entity killer)
158158
{
159159
selectedTile = tiles[Randomization.Next(0, tiles.Count)];
160160
}
161-
161+
162162
var itemSource = AsItemSource();
163163

164164
// Drop items
@@ -177,7 +177,7 @@ public void SpawnResourceItems(Entity killer)
177177

178178
Items.Clear();
179179
}
180-
180+
181181
protected override EntityItemSource? AsItemSource()
182182
{
183183
return new EntityItemSource
@@ -191,13 +191,13 @@ public void SpawnResourceItems(Entity killer)
191191
public override void ProcessRegen()
192192
{
193193
//For now give npcs/resources 10% health back every regen tick... in the future we should put per-npc and per-resource regen settings into their respective editors.
194-
if (!IsDead())
194+
if (!IsDead)
195195
{
196196
if (Base == null)
197197
{
198198
return;
199199
}
200-
200+
201201
var vital = Vital.Health;
202202

203203
var vitalId = (int) vital;
@@ -216,7 +216,7 @@ public override void ProcessRegen()
216216

217217
public override bool IsPassable()
218218
{
219-
return IsDead() & Base.WalkableAfter || !IsDead() && Base.WalkableBefore;
219+
return IsDead & Base.WalkableAfter || !IsDead && Base.WalkableBefore;
220220
}
221221

222222
public override EntityPacket EntityPacket(EntityPacket packet = null, Player forPlayer = null)
@@ -230,7 +230,7 @@ public override EntityPacket EntityPacket(EntityPacket packet = null, Player for
230230

231231
var pkt = (ResourceEntityPacket) packet;
232232
pkt.ResourceId = Base.Id;
233-
pkt.IsDead = IsDead();
233+
pkt.IsDead = IsDead;
234234

235235
return pkt;
236236
}

Intersect.Server.Core/Maps/MapInstance.cs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -283,21 +283,43 @@ public void Update(long timeMs)
283283
/// <summary>
284284
/// Adds an entity to the MapInstance so that the instance knows to process them.
285285
/// </summary>
286-
/// <param name="en">The entity to add.</param>
287-
public void AddEntity(Entity en)
286+
/// <param name="entity">The entity to add.</param>
287+
public void AddEntity(Entity? entity)
288288
{
289-
if (en != null && !en.IsDead() && en.MapInstanceId == MapInstanceId)
289+
if (entity == null)
290290
{
291-
if (!mEntities.ContainsKey(en.Id))
291+
return;
292+
}
293+
294+
if (entity is not Player && entity.IsDead)
295+
{
296+
return;
297+
}
298+
299+
if (entity.MapInstanceId != MapInstanceId)
300+
{
301+
return;
302+
}
303+
304+
if (!mEntities.TryAdd(entity.Id, entity))
305+
{
306+
return;
307+
}
308+
309+
if (entity is Player player)
310+
{
311+
if (!mPlayers.TryAdd(player.Id, player))
292312
{
293-
mEntities.TryAdd(en.Id, en);
294-
if (en is Player plyr)
295-
{
296-
mPlayers.TryAdd(plyr.Id, plyr);
297-
}
298-
mCachedEntities = mEntities.Values.ToArray();
313+
ApplicationContext.CurrentContext.Logger.LogWarning(
314+
"Failed to add player {PlayerId} to map instance {MapInstanceId} of map {MapDescriptorId}",
315+
player.Id,
316+
MapInstanceId,
317+
mMapController.Id
318+
);
299319
}
300320
}
321+
322+
mCachedEntities = mEntities.Values.ToArray();
301323
}
302324

303325
/// <summary>
@@ -530,7 +552,7 @@ public void ResetNpcSpawns()
530552
lock (npcSpawn.Value.Entity.EntityLock)
531553
{
532554
var npc = npcSpawn.Value.Entity as Npc;
533-
if (!npc.Dead)
555+
if (!npc.IsDead)
534556
{
535557
// If we keep track of reset radiuses, just reset it to that value.
536558
if (Options.Instance.Npc.AllowResetRadius)
@@ -1309,7 +1331,7 @@ private void ProcessNpcRespawns()
13091331
for (var i = 0; i < spawns.Count; i++)
13101332
{
13111333
var spawn = spawns[i];
1312-
if (!NpcSpawnInstances.TryGetValue(spawn, out var spawnInstance) || spawnInstance?.Entity?.Base == default || !spawnInstance.Entity.Dead)
1334+
if (!NpcSpawnInstances.TryGetValue(spawn, out var spawnInstance) || spawnInstance?.Entity?.Base == default || !spawnInstance.Entity.IsDead)
13131335
{
13141336
continue;
13151337
}
@@ -1330,7 +1352,7 @@ private void ProcessResourceRespawns()
13301352
{
13311353
foreach (var spawn in ResourceSpawns)
13321354
{
1333-
if (!ResourceSpawnInstances.TryGetValue(spawn.Value, out var spawnInstance) || spawnInstance?.Entity?.Base == default || !spawnInstance.Entity.Dead)
1355+
if (!ResourceSpawnInstances.TryGetValue(spawn.Value, out var spawnInstance) || spawnInstance?.Entity?.Base == default || !spawnInstance.Entity.IsDead)
13341356
{
13351357
continue;
13361358
}

0 commit comments

Comments
 (0)