private IEnumerable <int> GetRemovedEntities() { foreach (var i in _clientEntities.Where(i => i is Player)) { if ((i as Player).vanished && i != this) { yield return(i.Id); } } foreach (var i in _clientEntities.Where(i => !(i is Player) || i.Owner == null)) { if (MathsUtils.DistSqr(i.X, i.Y, X, Y) > SightRadius * SightRadius && !(i is StaticObject && (i as StaticObject).Static) && i != questEntity) { yield return(i.Id); } else if (i.Owner == null) { yield return(i.Id); } if (i is Player) { if ((i as Player).vanished && i != this) { yield return(i.Id); } } } }
private Entity FindQuest() { Entity ret = null; double bestScore = 0; foreach (Enemy i in Owner.Quests.Values .OrderBy(quest => MathsUtils.DistSqr(quest.X, quest.Y, X, Y))) { if (i.ObjectDesc == null || !i.ObjectDesc.Quest) { continue; } Tuple <int, int, int> x; if (!QuestDat.TryGetValue(i.ObjectDesc.ObjectId, out x)) { continue; } if ((Level >= x.Item2 && Level <= x.Item3)) { double score = (120 - Math.Abs((i.ObjectDesc.Level ?? 0) - Level)) * x.Item1 - //priority * level diff this.Dist(i) / 100; //minus 1 for every 100 tile distance if (score > bestScore) { bestScore = score; ret = i; } } } return(ret); }
public virtual void LeaveWorld(Entity entity) { if (entity is Player) { Player dummy; Players.TryRemove(entity.Id, out dummy); PlayersCollision.Remove(entity); // if in trade, cancel it... if (dummy.tradeTarget != null) { dummy.CancelTrade(); } } else if (entity is Enemy) { Enemy dummy; Enemies.TryRemove(entity.Id, out dummy); EnemiesCollision.Remove(entity); if (entity.ObjectDesc.Quest) { Quests.TryRemove(entity.Id, out dummy); } } else if (entity is Projectile) { var p = entity as Projectile; Projectiles.TryRemove(new Tuple <int, byte>(p.ProjectileOwner.Self.Id, p.ProjectileId), out p); } else if (entity is StaticObject) { StaticObject dummy; StaticObjects.TryRemove(entity.Id, out dummy); if (entity.ObjectDesc?.BlocksSight == true) { if (Blocking == 3) { Sight.UpdateRegion(Map, (int)entity.X, (int)entity.Y); } foreach (var plr in Players.Values .Where(p => MathsUtils.DistSqr(p.X, p.Y, entity.X, entity.Y) < Player.RadiusSqr)) { plr.Sight.UpdateCount++; } } if (entity is Decoy) { PlayersCollision.Remove(entity); } else { EnemiesCollision.Remove(entity); } } entity.Dispose(); }
private IEnumerable <int> GetRemovedEntities() { foreach (var i in clientEntities.Where(i => !(i is Player) || i.Owner == null)) { if (MathsUtils.DistSqr(i.X, i.Y, X, Y) > SIGHTRADIUS * SIGHTRADIUS && !(i is StaticObject && (i as StaticObject).Static) && i != Quest) { if (i is Pet) { continue; } yield return(i.Id); } else if (i.Owner == null) { yield return(i.Id); } if (!(i is Player)) { continue; } if (i != this) { yield return(i.Id); } } }
private IEnumerable <int> GetRemovedEntities() { foreach (Entity i in clientEntities.Where(i => i is Player)) { if ((i as Player).isNotVisible && i != this && !PvP) { yield return(i.Id); } } foreach (Entity i in clientEntities) { if (i is Player && i.Owner != null) { continue; } if (MathsUtils.DistSqr(i.X, i.Y, X, Y) > RADIUS * RADIUS && !(i is StaticObject && (i as StaticObject).Static) && i != questEntity) { yield return(i.Id); } else if (i.Owner == null) { yield return(i.Id); } if (i is Player) { if ((i as Player).isNotVisible && i != this && !PvP) { yield return(i.Id); } } } }
Entity FindQuest(Position?destination = null) { Entity ret = null; double?bestScore = null; var pX = !destination.HasValue ? X : destination.Value.X; var pY = !destination.HasValue ? Y : destination.Value.Y; foreach (var i in Owner.Quests.Values .OrderBy(quest => MathsUtils.DistSqr(quest.X, quest.Y, pX, pY))) { if (i.ObjectDesc == null || !i.ObjectDesc.Quest) { continue; } Tuple <int, int, int> x; if (!QuestDat.TryGetValue(i.ObjectDesc.ObjectId, out x)) { continue; } if ((Level >= x.Item2 && Level <= x.Item3)) { var score = (20 - Math.Abs((i.ObjectDesc.Level ?? 0) - Level)) * x.Item1 - //priority * level diff this.Dist(i) / 100; //minus 1 for every 100 tile distance if (bestScore == null || score > bestScore) { bestScore = score; ret = i; } } } return(ret); }
public void BroadcastPacketNearby( Packet pkt, Position pos) { BroadcastPacketConditional( pkt, p => MathsUtils.DistSqr(p.X, p.Y, pos.X, pos.Y) < Player.RadiusSqr); }
private IEnumerable <Entity> GetNewEntities() { int xBase = (int)X; int yBase = (int)Y; var blockPos = getBlocks(xBase, yBase); foreach (var i in Owner.Players.Where(i => clientEntities.Add(i.Value))) { yield return(i.Value); } foreach (var i in Owner.PlayersCollision.HitTest(X, Y, SIGHTRADIUS).OfType <Decoy>().Where(i => clientEntities.Add(i))) { yield return(i); } foreach (var i in Owner.PlayersCollision.HitTest(X, Y, SIGHTRADIUS).OfType <Pet>().Where(i => clientEntities.Add(i))) { yield return(i); } foreach (var i in Owner.EnemiesCollision.HitTest(X, Y, SIGHTRADIUS)) { if (i is Container) { var owner = (i as Container).BagOwners?.Length == 1 ? (i as Container).BagOwners[0] : null; if (owner != null && owner != AccountId) { continue; } if (owner == AccountId) { if ((LootDropBoost || LootTierBoost) && (i.ObjectType != 0x500 || i.ObjectType != 0x506)) { (i as Container).BoostedBag = true; //boosted bag } } } if ((!(MathsUtils.DistSqr(i.X, i.Y, X, Y) <= SIGHTRADIUS * SIGHTRADIUS))) { continue; } if (Owner.Dungeon && invalidTile(xBase, yBase, (int)i.X, (int)i.Y, blockPos)) { continue; } if (clientEntities.Add(i)) { yield return(i); } } if (Quest != null && clientEntities.Add(Quest)) { yield return(Quest); } }
private IEnumerable <Entity> GetNewEntities() { var newEntities = new List <Entity>(); try { Owner.Players.Where(i => clientEntities.Add(i.Value)).Select(_ => { newEntities.Add(_.Value); return(_); }).ToList(); } catch { } try { Owner.PlayersCollision.HitTest(X, Y, SIGHTRADIUS).OfType <Decoy>().Where(i => clientEntities.Add(i)).Select(_ => { newEntities.Add(_); return(_); }).ToList(); } catch { } try { Owner.EnemiesCollision.HitTest(X, Y, SIGHTRADIUS).Where(_ => MathsUtils.DistSqr(_.X, _.Y, X, Y) <= SIGHTRADIUS * SIGHTRADIUS).Select(_ => { if (_ is Container) { var owner = (_ as Container).BagOwners?.Length == 1 ? (_ as Container).BagOwners[0] : null; if (owner != null && owner != AccountId) { return(_); } if (owner == AccountId) { if ((LootDropBoost || LootTierBoost) && (_.ObjectType != 0x500 || _.ObjectType != 0x506)) { (_ as Container).BoostedBag = true; } } } if (visibleTiles.ContainsKey(new IntPoint((int)_.X, (int)_.Y))) { if (clientEntities.Add(_)) { newEntities.Add(_); } } return(_); }).ToList(); } catch { } try { if (Quest != null && clientEntities.Add(Quest) && (Quest as Enemy).HP >= 0) { newEntities.Add(Quest); } } catch { } return(newEntities); }
public void BroadcastPacketNearby( Packet pkt, Position pos, PacketPriority priority = PacketPriority.Normal) { BroadcastPacketConditional( pkt, p => MathsUtils.DistSqr(p.X, p.Y, pos.X, pos.Y) < Player.RadiusSqr, priority); }
protected override void OnStateEntry(Entity host, RealmTime time, ref object state) { //var objType = GetObjType(_objName); XmlData dat = host.Manager.Resources.GameData; var tileId = dat.IdToTileType[_objName]; var replacedTileId = dat.IdToTileType[_replacedObjName]; var map = host.Owner.Map; var w = map.Width; var h = map.Height; for (var y = 0; y < h; y++) { for (var x = 0; x < w; x++) { var tile = map[x, y]; if (tile.TileId != tileId || tile.TileId == replacedTileId) { continue; } var dx = Math.Abs(x - (int)host.X); var dy = Math.Abs(y - (int)host.Y); if (dx > _range || dy > _range) { continue; } if (tile.ObjDesc?.BlocksSight == true) { if (host.Owner.Blocking == 3) { Sight.UpdateRegion(map, x, y); } foreach (var plr in host.Owner.Players.Values .Where(p => MathsUtils.DistSqr(p.X, p.Y, x, y) < Player.RadiusSqr)) { plr.Sight.UpdateCount++; } } tile.TileId = replacedTileId; if (tile.ObjId == 0) { tile.ObjId = host.Owner.GetNextEntityId(); } tile.UpdateCount++; map[x, y] = tile; } } }
IEnumerable <Entity> GetNewEntities() { foreach (var i in Owner.Players) { if (clientEntities.Add(i.Value)) { yield return(i.Value); } } foreach (var i in Owner.PlayersCollision.HitTest(X, Y, RADIUS)) { if (i is Decoy || i is Pet) { if (clientEntities.Add(i)) { yield return(i); } } } foreach (var i in Owner.EnemiesCollision.HitTest(X, Y, RADIUS)) { if (i is Container) { var owner = (i as Container).BagOwners?.Length == 1 ? (i as Container).BagOwners[0] : null; if (owner != null && owner != AccountId) { continue; } if (owner == AccountId) { if ((LootDropBoost || LootTierBoost) && (i.ObjectType != 0x500 || i.ObjectType != 0x506)) { (i as Container).BoostedBag = true; //boosted bag } } } if (SightTiles.Contains(new IntPoint((int)i.X, (int)i.Y))) { if (MathsUtils.DistSqr(i.X, i.Y, X, Y) <= RADIUS * RADIUS) { if (clientEntities.Add(i)) { yield return(i); } } } } if (Quest != null && clientEntities.Add(Quest)) { yield return(Quest); } }
protected internal override void Resolve(State parent) { parent.Death += (sender, e) => { XmlData dat = e.Host.Manager.Resources.GameData; var objType = dat.IdToObjectType[_objName]; var map = e.Host.Owner.Map; var w = map.Width; var h = map.Height; for (var y = 0; y < h; y++) { for (var x = 0; x < w; x++) { var tile = map[x, y]; if (tile.ObjType != objType) { continue; } var dx = Math.Abs(x - (int)e.Host.X); var dy = Math.Abs(y - (int)e.Host.Y); if (dx > _range || dy > _range) { continue; } if (tile.ObjDesc?.BlocksSight == true) { if (e.Host.Owner.Blocking == 3) { Sight.UpdateRegion(map, x, y); } foreach (var plr in e.Host.Owner.Players.Values .Where(p => MathsUtils.DistSqr(p.X, p.Y, x, y) < Player.RadiusSqr)) { plr.Sight.UpdateCount++; } } tile.ObjType = 0; tile.UpdateCount++; map[x, y] = tile; } } }; }
private void HandleQuest(RealmTime time) { if (time.TickCount % 5 != 0) { return; } int newQuestId = -1; int questId = Quest == null ? -1 : Quest.Id; HashSet <Enemy> candidates = new HashSet <Enemy>(); foreach (Enemy i in Owner.Quests.Values .OrderBy(j => MathsUtils.DistSqr(j.X, j.Y, X, Y)) .Where(k => k.ObjectDesc != null && k.ObjectDesc.Quest)) { if (!RealmManager.QuestPortraits.TryGetValue(i.ObjectDesc.ObjectId, out int questLevel)) { continue; } if (Level < questLevel) { continue; } if (!RealmManager.QuestPortraits.ContainsKey(i.ObjectDesc.ObjectId)) { continue; } candidates.Add(i); } if (candidates.Count != 0) { Enemy newQuest = candidates.OrderByDescending(i => QuestPriority(i.ObjectDesc)).Take(3).ToList()[0]; newQuestId = newQuest.Id; Quest = newQuest; } if (newQuestId == questId) { return; } Client.SendMessage(new QUESTOBJID { ObjectId = newQuestId }); }
/* * returns true if packet input is valid */ private bool VerifyInvSwap(InvSwapPacket pkt) { try { // get target objects Entity en1 = Owner.GetEntity(pkt.Obj1.ObjectId); Entity en2 = Owner.GetEntity(pkt.Obj2.ObjectId); // check to see if targets are valid if ((!(en1 is Player) && !(en1 is Container)) || (!(en2 is Player) && !(en2 is Container)) || // must be a player or container entity (en1 is Player && en1 != this) || (en2 is Player && en2 != this)) // if player, must be this player { Console.WriteLine("[invSwap:" + nName + "] Targets not valid (" + en1.nName + ", " + en2.nName + ")."); return(false); } if (en1 is Container && en2 is Container && en1 != en2) { Console.WriteLine("[invSwap:" + nName + "] Trade between two different containers detected."); return(false); } // check target distance (must be within 1 tile range) if (MathsUtils.DistSqr(this.X, this.Y, en1.X, en1.Y) > 1 || MathsUtils.DistSqr(this.X, this.Y, en2.X, en2.Y) > 1) { Console.WriteLine("[invSwap:" + nName + "] Target distance to far from player."); return(false); } // check trade items var con1 = en1 as IContainer; var con2 = en2 as IContainer; Item item1 = con1.Inventory[pkt.Obj1.SlotId]; //TODO: locker Item item2 = con2.Inventory[pkt.Obj2.SlotId]; if (!AuditItem(con2, item1, pkt.Obj2.SlotId) || !AuditItem(con1, item2, pkt.Obj1.SlotId)) { Console.WriteLine("[invSwap:" + nName + "] Invalid item swap."); return(false); } return(true); } catch (Exception e) { Console.WriteLine("[invSwap:" + nName + "] Invalid input."); return(false); } }
private IEnumerable <Entity> GetNewEntities() { var world = Manager.GetWorld(Owner.Id); foreach (var i in Owner.Players.Where(i => clientEntities.Add(i.Value))) { yield return(i.Value); } foreach (var i in Owner.PlayersCollision.HitTest(X, Y, SIGHTRADIUS).OfType <Decoy>().Where(i => clientEntities.Add(i))) { yield return(i); } foreach (var i in Owner.PlayersCollision.HitTest(X, Y, SIGHTRADIUS).OfType <Pet>().Where(i => clientEntities.Add(i))) { yield return(i); } foreach (var i in Owner.EnemiesCollision.HitTest(X, Y, SIGHTRADIUS)) { if (i is Container) { var owner = (i as Container).BagOwners?.Length == 1 ? (i as Container).BagOwners[0] : null; if (owner != null && owner != AccountId) { continue; } if (owner == AccountId) { if ((LootDropBoost || LootTierBoost) && (i.ObjectType != 0x500 || i.ObjectType != 0x506)) { (i as Container).BoostedBag = true; //boosted bag } } } if (!(MathsUtils.DistSqr(i.X, i.Y, X, Y) <= SIGHTRADIUS * SIGHTRADIUS)) { continue; } if (clientEntities.Add(i)) { yield return(i); } } if (Quest != null && clientEntities.Add(Quest)) { yield return(Quest); } }
private IEnumerable <Entity> GetNewEntities() { foreach (var i in Owner.Players) { if (clientEntities.Add(i.Value)) { yield return(i.Value); } } foreach (Entity i in Owner.PlayersCollision.HitTest(X, Y, RADIUS)) { if (!(i is Decoy)) { continue; } if (clientEntities.Add(i)) { yield return(i); } } foreach (Entity i in Owner.EnemiesCollision.HitTest(X, Y, RADIUS)) { var owners = (i as Container)?.BagOwners; if (owners?.Length > 0 && Array.IndexOf(owners, AccountId) == -1) { continue; } if (SightTiles.Contains(new IntPoint((int)(i.X - X), (int)(i.Y - Y)))) { if (clientEntities.Add(i)) { yield return(i); } } if (MathsUtils.DistSqr(i.X, i.Y, X, Y) <= RADIUS * RADIUS) { if (clientEntities.Add(i)) { yield return(i); } } } if (questEntity != null && clientEntities.Add(questEntity)) { yield return(questEntity); } }
protected override void OnStateEntry(Entity host, RealmTime time, ref object state) { var objType = GetObjType(_objName); var map = host.Owner.Map; var w = map.Width; var h = map.Height; for (var y = 0; y < h; y++) { for (var x = 0; x < w; x++) { var tile = map[x, y]; if (tile.ObjType != objType) { continue; } var dx = Math.Abs(x - (int)host.X); var dy = Math.Abs(y - (int)host.Y); if (dx > _range || dy > _range) { continue; } if (tile.ObjDesc?.BlocksSight == true) { if (host.Owner.Blocking == 3) { Sight.UpdateRegion(map, x, y); } foreach (var plr in host.Owner.Players.Values .Where(p => MathsUtils.DistSqr(p.X, p.Y, x, y) < Player.RadiusSqr)) { plr.Sight.UpdateCount++; } } tile.ObjType = 0; tile.UpdateCount++; map[x, y] = tile; } } }
private IEnumerable <int> GetRemovedEntities() { var removedEntities = new List <int>(); clientEntities.Where(entity => !(entity is Player && entity.Owner != null) && ((MathsUtils.DistSqr(entity.X, entity.Y, X, Y) > SIGHTRADIUS * SIGHTRADIUS && !(entity is GameObject && (entity as GameObject).Static) && entity != Quest) || entity.Owner == null)) .Select(clientEntity => { removedEntities.Add(clientEntity.Id); return(clientEntities); }).ToList(); return(removedEntities); }
protected override bool TickCore(Entity host, RealmTime time, ref object state) { if (_transition == false || host.Owner == null || _player == null || !host.Owner.Players.Values.Contains(_player)) { return(false); } host.AttackTarget = _setAttackTarget ? _player : null; if (_distSqr != null) { return(MathsUtils.DistSqr(_player.X, _player.Y, host.X, host.Y) <= _distSqr); } return(true); }
IEnumerable <Entity> GetNewEntities() { foreach (var i in Owner.Players) { if (clientEntities.Add(i.Value)) { yield return(i.Value); } } foreach (var i in Owner.PlayersCollision.HitTest(X, Y, RADIUS)) { if (i is Decoy) { if (clientEntities.Add(i)) { yield return(i); } } } foreach (var i in Owner.EnemiesCollision.HitTest(X, Y, RADIUS)) { if (i is Container) { int[] owners = (i as Container).BagOwners; if (owners.Length > 0 && Array.IndexOf(owners, AccountId) == -1) { continue; } } if (MathsUtils.DistSqr(i.X, i.Y, X, Y) <= RADIUS * RADIUS) { if (clientEntities.Add(i)) { yield return(i); } } } if (questEntity != null && clientEntities.Add(questEntity)) { yield return(questEntity); } }
/* * private long tickIdTime = 0; */ private IEnumerable <Entity> GetNewEntities() { foreach (var i in Owner.Players.Where(i => _clientEntities.Add(i.Value))) { if (!i.Value.vanished || i.Value == this) { yield return(i.Value); } } /* * { * yield return i.Value; * } */ foreach (var i in Owner.PlayersCollision.HitTest(X, Y, SightRadius).OfType <Decoy>().Where(i => _clientEntities.Add(i))) { yield return(i); } foreach (var i in Owner.EnemiesCollision.HitTest(X, Y, SightRadius)) { if (i is Container) { var owner = (i as Container).BagOwner; if (owner != null && owner != AccountId) { continue; } } if (MathsUtils.DistSqr(i.X, i.Y, X, Y) <= SightRadius * SightRadius) { if (_clientEntities.Add(i)) { yield return(i); } } } if (questEntity != null && _clientEntities.Add(questEntity)) { yield return(questEntity); } }
IEnumerable <Entity> GetNewEntities() { foreach (var i in Owner.Players) { if (clientEntities.Add(i.Value)) { yield return(i.Value); } } foreach (var i in Owner.PlayersCollision.HitTest(X, Y, SIGHT_RADIUS)) { if (i is Decoy) { if (clientEntities.Add(i)) { yield return(i); } } } foreach (var i in Owner.EnemiesCollision.HitTest(X, Y, SIGHT_RADIUS)) { if (i is Container) { int?owner = (i as Container).BagOwner; if (owner != null && owner != AccountId) { continue; } } if (MathsUtils.DistSqr(i.X, i.Y, X, Y) <= SIGHT_RADIUS * SIGHT_RADIUS) { if (clientEntities.Add(i)) { yield return(i); } } } if (questEntity != null && clientEntities.Add(questEntity)) { yield return(questEntity); } }
IEnumerable <int> GetRemovedEntities() { foreach (var i in clientEntities) { if (i is Player && i.Owner != null) { continue; } if (MathsUtils.DistSqr(i.X, i.Y, X, Y) > RADIUS * RADIUS && !(i is StaticObject && (i as StaticObject).Static) && i != questEntity) { yield return(i.Id); } else if (i.Owner == null) { yield return(i.Id); } } }
private Entity FindQuest() { Entity ret = null; try { float bestScore = 0; foreach (var i in Owner.Quests.Values .OrderBy(quest => MathsUtils.DistSqr(quest.X, quest.Y, X, Y)).Where(i => i.ObjectDesc != null && i.ObjectDesc.Quest)) { Tuple <int, int, int> x; if (!questDat.TryGetValue(i.ObjectDesc.ObjectId, out x)) { continue; } if ((Level < x.Item2 || Level > x.Item3)) { continue; } var score = (20 - Math.Abs((i.ObjectDesc.Level ?? 0) - Level)) * x.Item1 - //priority * level diff Dist(this, i) / 100; //minus 1 for every 100 tile distance if (score < 0) { score = 1; } if (!(score > bestScore)) { continue; } bestScore = score; ret = i; } } catch (Exception ex) { log.Error(ex); } return(ret); }