private static async void PlayerPlrViewport(MapInfo Map, Character plr) { var pos = plr.Position; pos.Offset(15, 15); PartyManager.SendAll(plr.Party); var playerVP = from obj in Map.Players let rect = new Rectangle(obj.Position, new Size(30, 30)) where rect.Contains(pos) && obj.Player.Session.ID != plr.Player.Session.ID select obj; var PShop = (from obj in playerVP where obj.Shop.Open select obj).ToList(); var newPlr = (from obj in playerVP where obj.State == ObjectState.Regen select obj).ToList(); var existPlr = (from obj in playerVP where !plr.PlayersVP.Contains(obj.Player) && obj.State == ObjectState.Live select obj).ToList(); var deadPlr = (from obj in playerVP where obj.State == ObjectState.WaitRegen select obj.Player).ToList(); var lostPlr = (from obj in plr.PlayersVP where !playerVP.Contains(obj.Character) select obj).ToList(); plr.PlayersVP.AddRange(newPlr.Select(x => x.Player)); plr.PlayersVP.AddRange(existPlr.Select(x => x.Player)); var guildVP = newPlr .Where(x => x.Guild != null) .Select(x => new GuildViewPortDto { ID = x.Guild.Index, Number = x.Index, RelationShip = plr.Guild?.GetRelation(x.Guild) ?? GuildRelation.None, CastleState = 0, Status = x.Guild.Find(x.Name).Rank, Type = x.Guild.Type, }).ToList(); guildVP.AddRange(existPlr .Where(x => x.Guild != null) .Select(x => new GuildViewPortDto { ID = x.Guild.Index, Number = x.Index, RelationShip = plr.Guild?.GetRelation(x.Guild) ?? GuildRelation.None, CastleState = 0, Status = x.Guild.Find(x.Name).Rank, Type = x.Guild.Type, })); foreach (var it in deadPlr) { plr.PlayersVP.Remove(it); } foreach (var it in lostPlr) { plr.PlayersVP.Remove(it); } var addPlr = new List <VPCreateAbs>(); switch (Program.Season) { case 9: addPlr.AddRange(newPlr.Select(x => new VPCreateS9Dto { CharSet = x.Inventory.GetCharset(), DirAndPkLevel = (byte)((x.Direction << 4) | 0), Name = x.Name, Number = (ushort)(x.Player.Session.ID | 0x8000), Position = x.Position, TPosition = x.TPosition, ViewSkillState = x.Spells.ViewSkillStates, Player = x.Player, PentagramMainAttribute = 0, CurLife = (uint)x.Health, MaxLife = (uint)x.MaxHealth, Level = x.Level, MuunItem = 0xffff, MuunRideItem = 0xffff, MuunSubItem = 0xffff, ServerCodeOfHomeWorld = 0, })); addPlr.AddRange(existPlr.Select(x => new VPCreateS9Dto { CharSet = x.Inventory.GetCharset(), DirAndPkLevel = (byte)((x.Direction << 4) | 0), Name = x.Name, Number = (ushort)x.Player.Session.ID, Position = x.Position, TPosition = x.TPosition, ViewSkillState = x.Spells.ViewSkillStates, Player = x.Player, PentagramMainAttribute = 0, CurLife = (uint)x.Health, MaxLife = (uint)x.MaxHealth, Level = x.Level, MuunItem = 0xffff, MuunRideItem = 0xffff, MuunSubItem = 0xffff, ServerCodeOfHomeWorld = 0, })); break; default: addPlr.AddRange(newPlr.Select(x => new VPCreateDto { CharSet = x.Inventory.GetCharset(), DirAndPkLevel = (byte)((x.Direction << 4) | 0), Name = x.Name, Number = (ushort)(x.Player.Session.ID | 0x8000), Position = x.Position, TPosition = x.TPosition, ViewSkillState = x.Spells.ViewSkillStates, Player = x.Player })); addPlr.AddRange(existPlr.Select(x => new VPCreateDto { CharSet = x.Inventory.GetCharset(), DirAndPkLevel = (byte)((x.Direction << 4) | 0), Name = x.Name, Number = (ushort)x.Player.Session.ID, Position = x.Position, TPosition = x.TPosition, ViewSkillState = x.Spells.ViewSkillStates, Player = x.Player })); break; } switch (Program.Season) { case 9: if (addPlr.Any()) { await plr.Player.Session.SendAsync(new SViewPortCreateS9 { ViewPort = addPlr.Select(x => (VPCreateS9Dto)x).ToArray() }); } break; default: if (addPlr.Any()) { await plr.Player.Session.SendAsync(new SViewPortCreate { ViewPort = addPlr.Select(x => (VPCreateDto)x).ToArray() }); } break; } if (lostPlr.Any()) { await plr.Player.Session.SendAsync(new SViewPortDestroy(lostPlr.Select(x => new VPDestroyDto((ushort)x.Session.ID)).ToArray())); } if (PShop.Any()) { await plr.Player.Session.SendAsync(new SViewPortPShop { VPShops = PShop.Select(x => new VPPShopDto { btName = x.Shop.Name.GetBytes(), wzNumber = x.Index.ShufleEnding() }).ToArray() }); } if (guildVP.Any()) { await plr.Player.Session.SendAsync(new SGuildViewPort { Guilds = guildVP.ToArray() }); } }
private static async void PlayerPlrViewport(MapInfo Map, Character plr) { var pos = plr.Position; pos.Offset(15, 15); List <Character> newPlr, PShop, existPlr; List <Player> deadPlr, lostPlr; List <GuildViewPortDto> guildVP; List <VPGensDto> gensVP; PartyManager.SendAll(plr.Party); lock (plr.PlayersVP) { var playerVP = from obj in Map.Players let rect = new Rectangle(obj.Position, new Size(30, 30)) where rect.Contains(pos) && obj.Player.Session.ID != plr.Player.Session.ID select obj; PShop = (from obj in playerVP where obj.Shop.Open select obj).ToList(); newPlr = (from obj in playerVP where obj.State == ObjectState.Regen select obj).ToList(); existPlr = (from obj in playerVP where (!plr.PlayersVP.Contains(obj.Player) || obj.Player.Character.Change) && obj.State == ObjectState.Live select obj).ToList(); deadPlr = (from obj in playerVP where obj.State == ObjectState.WaitRegen select obj.Player).ToList(); lostPlr = (from obj in plr.PlayersVP where !playerVP.Contains(obj.Character) select obj).ToList(); plr.PlayersVP.AddRange(newPlr.Select(x => x.Player)); plr.PlayersVP.AddRange(existPlr.Select(x => x.Player)); guildVP = newPlr .Where(x => x.Guild != null) .Select(x => new GuildViewPortDto { ID = x.Guild.Index, Number = x.Index, RelationShip = plr.Guild?.GetRelation(x.Guild) ?? GuildRelation.None, CastleState = 0, Status = x.Guild.Find(x.Name).Rank, Type = x.Guild.Type, }).ToList(); guildVP.AddRange(existPlr .Where(x => x.Guild != null) .Select(x => new GuildViewPortDto { ID = x.Guild.Index, Number = x.Index, RelationShip = plr.Guild?.GetRelation(x.Guild) ?? GuildRelation.None, CastleState = 0, Status = x.Guild.Find(x.Name).Rank, Type = x.Guild.Type, })); gensVP = newPlr .Where(x => x.Gens.Influence != GensType.None) .Select(x => new VPGensDto { Influence = x.Gens.Influence, iGensClass = x.Gens.Class, iGensRanking = x.Gens.Ranking, iContributePoint = x.Gens.Contribution, wzNumber = x.Index.ShufleEnding() }).ToList(); gensVP.AddRange(existPlr.Where(x => x.Gens.Influence != GensType.None) .Select(x => new VPGensDto { Influence = x.Gens.Influence, iGensClass = x.Gens.Class, iGensRanking = x.Gens.Ranking, iContributePoint = x.Gens.Contribution, wzNumber = x.Index.ShufleEnding() })); foreach (var it in deadPlr) { plr.PlayersVP.Remove(it); } foreach (var it in lostPlr) { plr.PlayersVP.Remove(it); } } var addPlr = new List <VPCreateAbs>(); var typeBase = Program.Season switch { ServerSeason.Season16Kor => typeof(VPCreateS16KorDto), ServerSeason.Season12Eng => typeof(VPCreateS12Dto), ServerSeason.Season9Eng => typeof(VPCreateS9Dto), _ => typeof(VPCreateDto), }; foreach (var x in newPlr) { var obj = Activator.CreateInstance(typeBase) as VPCreateAbs; AssignVP(obj, x, true); addPlr.Add(obj); } foreach (var x in existPlr) { var obj = Activator.CreateInstance(typeBase) as VPCreateAbs; AssignVP(obj, x, false); addPlr.Add(obj); } var msg = VersionSelector.CreateMessage <SViewPortCreate>(addPlr); await plr.Player.Session.SendAsync(msg); if (lostPlr.Any()) { await plr.Player.Session.SendAsync(new SViewPortDestroy(lostPlr.Select(x => new VPDestroyDto((ushort)x.Session.ID)).ToArray())); } if (PShop.Any()) { await plr.Player.Session.SendAsync(new SViewPortPShop { VPShops = PShop.Select(x => new VPPShopDto { btName = x.Shop.Name.GetBytes(), wzNumber = x.Index.ShufleEnding() }).ToArray() }); } if (guildVP.Any()) { await plr.Player.Session.SendAsync(new SGuildViewPort { Guilds = guildVP.ToArray() }); } if (gensVP.Any()) { await plr.Player.Session.SendAsync(new SViewPortGens { VPGens = gensVP.ToArray() }); } }