public bool AddEffect(ClientEffect _effect, long _timeout, bool _sync = true) { if (_effect == ClientEffect.Fly && !Map.IsFlyEnabled) { return(false); } var timeout = _timeout > 0 ? Common.Clock + _timeout : 0; bool success = true; if (ClientEffects.ContainsKey(_effect)) { ClientEffects[_effect] = timeout; } else { success = ClientEffects.TryAdd(_effect, timeout); } if (success && !(this is SOB)) { SpawnPacket.StatusEffects |= _effect; if (_sync) { Send(UpdatePacket.Create(UID, UpdateType.StatusEffects, (ulong)SpawnPacket.StatusEffects)); SendToScreen(SpawnPacket); } } if (_effect == ClientEffect.Poison) //Added poison damage timer { LastPoisonDamage = Common.Clock; } return(success); }
//Gets us a new location and handles all map insertion. public void Respawn() { base.sentDeath = false; Mode = MonsterMode.Idle; DiedAt = 0; SpawnPacket.StatusEffects = 0; ClientEffects.Clear(); Direction = (byte)Common.Random.Next(9); //Pull a new location for us that fits within spawn grounds var loc = new Point(Common.Random.Next(Owner.TopLeft.X, Owner.BottomRight.X), Common.Random.Next(Owner.TopLeft.Y, Owner.BottomRight.Y)); var loop = 0; while (!Map.IsValidMonsterLocation(loc)) { loop++; loc = new Point(Common.Random.Next(Owner.TopLeft.X, Owner.BottomRight.X), Common.Random.Next(Owner.TopLeft.Y, Owner.BottomRight.Y)); if (loop > 100) { Console.WriteLine("Error assigning monster spawn! Monster will not be revived"); break; } } if (!Map.IsValidMonsterLocation(loc)) { return; } LastMove = LastAttack = Common.Clock + Common.MS_PER_SECOND + 3; X = (ushort)loc.X; Y = (ushort)loc.Y; Life = MaximumLife; Map.Insert(this); UpdateSurroundings(true); foreach (var id in VisibleObjects.Keys) { if (id > 1000000) { IsActive = true; break; } } if (IsActive) { Owner.IsActive = true; } SendToScreen(GeneralActionPacket.Create(UID, DataAction.SpawnEffect, X, Y)); Common.MapService.AddFlag(MapID, X, Y, TinyMap.TileFlag.Monster); Owner.AliveMembers.TryAdd(UID, this); if (!Alive) { Console.WriteLine("Revived a monster that is still dead! {0}", UID); } }
public bool RemoveEffect(ClientEffect _effect, bool _sync = true) { bool success = HasEffect(_effect); if (success) { long expires = 0; ClientEffects.TryRemove(_effect, out expires); success = expires > 0; SpawnPacket.StatusEffects &= ~_effect; if (_sync) { Send(UpdatePacket.Create(UID, UpdateType.StatusEffects, (ulong)SpawnPacket.StatusEffects)); SendToScreen(SpawnPacket); } if (_effect == ClientEffect.XpStart) { Xp = 0; } } return(success); }