public static void Handle(Player player, byte[] buffer) { fixed(byte *p = buffer) { var packet = *(MsgNpcSpawn *)p; BufferPool.RecycleBuffer(buffer); var npc = new Npc { UniqueId = UniqueIdGenerator.GetNext(EntityType.DynamicNpc), MapId = player.MapId, Location = { X = packet.X, Y = packet.Y }, Look = packet.Look, Type = 2, Direction = (Direction)(packet.Look % 10) }; GameWorld.Maps[player.MapId].LoadInEntity(npc); ScreenSystem.Create(npc); ScreenSystem.SendSpawn(npc); Collections.Npcs.Add(npc.UniqueId, npc); } }
internal WebSocketContext( IHttpContextImpl httpContext, string webSocketVersion, IEnumerable <string> requestedProtocols, string?acceptedProtocol, IWebSocket webSocket, CancellationToken cancellationToken) { Id = UniqueIdGenerator.GetNext(); CancellationToken = cancellationToken; HttpContextId = httpContext.Id; Session = httpContext.Session; Items = httpContext.Items; LocalEndPoint = httpContext.LocalEndPoint; RemoteEndPoint = httpContext.RemoteEndPoint; RequestUri = httpContext.Request.Url; Headers = httpContext.Request.Headers; Origin = Headers[HttpHeaderNames.Origin]; RequestedProtocols = requestedProtocols; AcceptedProtocol = acceptedProtocol; WebSocketVersion = webSocketVersion; Cookies = httpContext.Request.Cookies; User = httpContext.User; IsAuthenticated = httpContext.Request.IsAuthenticated; IsLocal = httpContext.Request.IsLocal; IsSecureConnection = httpContext.Request.IsSecureConnection; WebSocket = webSocket; }
public void GetNext_ReturnsValidString() { var id = UniqueIdGenerator.GetNext(); Assert.IsNotNull(id); Assert.IsNotEmpty(id); }
public static Task Load() { return(Task.Run(() => { foreach (var portalFile in Directory.GetDirectories("RAW\\Portals\\").SelectMany(Directory.GetFiles)) { using (var reader = new KeyValueFormat(portalFile)) { var obj = new Portal { MapId = reader.Load <ushort>("FromMap"), ToMap = reader.Load <ushort>("ToMap"), ToX = reader.Load <ushort>("ToX"), ToY = reader.Load <ushort>("ToY"), UniqueId = UniqueIdGenerator.GetNext(EntityType.Portal) }; obj.Location.X = reader.Load <ushort>("FromX"); obj.Location.Y = reader.Load <ushort>("FromY"); if (obj.MapId == 0) { continue; } if (GameWorld.Maps.ContainsKey(obj.MapId)) { Portal.Portals.Add(obj.UniqueId, obj); //GameWorld.Maps[obj.MapId].LoadInEntity(obj); } } } })); }
internal TestContext(IHttpRequest request) { Request = request; User = null; TestResponse = new TestResponse(); Id = UniqueIdGenerator.GetNext(); LocalEndPoint = Request.LocalEndPoint; RemoteEndPoint = Request.RemoteEndPoint; }
internal HttpListenerContext(HttpConnection cnc) { Connection = cnc; Request = new HttpListenerRequest(this); Response = new HttpListenerResponse(this); User = null; Id = UniqueIdGenerator.GetNext(); LocalEndPoint = Request.LocalEndPoint; RemoteEndPoint = Request.RemoteEndPoint; }
public void GetNext_ReturnsUniqueId() { var ids = new string[100]; for (var i = 0; i < ids.Length; i++) { ids[i] = UniqueIdGenerator.GetNext(); } CollectionAssert.AllItemsAreUnique(ids); }
public static Item Create(Item original) { if (!Enum.IsDefined(typeof(RebornItemEffect), original.RebornEffect)) { original.RebornEffect = RebornItemEffect.None; } var clone = CloneChamber.Clone(original); clone.UniqueId = UniqueIdGenerator.GetNext(EntityType.Item); return(clone); }
public SystemHttpContext(System.Net.HttpListenerContext context) { _context = context; Request = new SystemHttpRequest(_context); User = _context.User; Response = new SystemHttpResponse(_context); Id = UniqueIdGenerator.GetNext(); LocalEndPoint = Request.LocalEndPoint; RemoteEndPoint = Request.RemoteEndPoint; }
internal TestContext(IHttpRequest request) { Request = request; User = Auth.NoUser; TestResponse = new TestResponse(); Id = UniqueIdGenerator.GetNext(); LocalEndPoint = Request.LocalEndPoint; RemoteEndPoint = Request.RemoteEndPoint; Route = RouteMatch.None; Session = SessionProxy.None; }
internal HttpListenerContext(HttpConnection cnc) { Connection = cnc; Request = new HttpListenerRequest(this); User = Auth.NoUser; Response = new HttpListenerResponse(this); Id = UniqueIdGenerator.GetNext(); LocalEndPoint = Request.LocalEndPoint; RemoteEndPoint = Request.RemoteEndPoint; Route = RouteMatch.None; Session = SessionProxy.None; }
public static Task Spawn(int max = 0) { return(Task.Run(() => { foreach (var spawn in Collections.Spawns) { Monster monster; if (!Collections.BaseMonsters.TryGetValue(spawn.Value.MobId, out monster)) { continue; } for (var i = 0; i < spawn.Value.Amount; i++) { var obj = CloneChamber.Clone(Collections.BaseMonsters[spawn.Value.MobId]); obj.SpawnId = spawn.Key; obj.UniqueId = UniqueIdGenerator.GetNext(EntityType.Monster); obj.MapId = spawn.Value.MapId; obj.Location.X = spawn.Value.Xstart; obj.Location.Y = spawn.Value.Ystart; if (!GameWorld.Maps.ContainsKey(obj.MapId)) { continue; } var spawnAttempts = 0; while (true) { if (spawnAttempts > 1000) { break; } spawnAttempts++; if (GameWorld.Maps[obj.MapId].MobValid(obj.Location.X, obj.Location.Y)) { Collections.Monsters.AddOrUpdate(obj.UniqueId, obj); GameWorld.Maps[obj.MapId].LoadInEntity(obj); break; } obj.Location.X = (ushort)YiCore.Random.Next(spawn.Value.Xstart - 10, spawn.Value.Xstart + spawn.Value.Xend + 10); obj.Location.Y = (ushort)YiCore.Random.Next(spawn.Value.Ystart - 10, spawn.Value.Ystart + spawn.Value.Yend + 10); if (obj.Look == 900 || obj.Look == 910)//Guard1 Guard2 { obj.Brain = new GuardBrain(obj); } } } } })); }
public SystemHttpContext(System.Net.HttpListenerContext context) { _context = context; Request = new SystemHttpRequest(_context); User = _context.User ?? Auth.NoUser; Response = new SystemHttpResponse(_context); Id = UniqueIdGenerator.GetNext(); LocalEndPoint = Request.LocalEndPoint; RemoteEndPoint = Request.RemoteEndPoint; Route = RouteMatch.None; Session = SessionProxy.None; }
private static Player CreateCharacter() { var character = new Player(true) { UniqueId = UniqueIdGenerator.GetNext(EntityType.Player), Name = CharName.Size16(), Partner = "None", Level = 1, Money = 1000, Look = Model, Class = Job, MapId = 1010, Profs = new Dictionary <int, Prof> { [134] = new Prof(134, 0, 0), [133] = new Prof(133, 0, 0), [130] = new Prof(130, 0, 0), [131] = new Prof(131, 0, 0), [117] = new Prof(117, 0, 0), [114] = new Prof(114, 0, 0), [113] = new Prof(113, 0, 0), [118] = new Prof(118, 0, 0), [111] = new Prof(111, 0, 0), [121] = new Prof(121, 0, 0), [120] = new Prof(120, 0, 0), [150] = new Prof(150, 0, 0), [151] = new Prof(151, 0, 0), [152] = new Prof(152, 0, 0), [160] = new Prof(160, 0, 0), [900] = new Prof(900, 0, 0), [400] = new Prof(400, 0, 0), [410] = new Prof(410, 0, 0), [420] = new Prof(420, 0, 0), [421] = new Prof(421, 0, 0), [430] = new Prof(430, 0, 0), [440] = new Prof(440, 0, 0), [450] = new Prof(450, 0, 0), [460] = new Prof(460, 0, 0), [480] = new Prof(480, 0, 0), [481] = new Prof(481, 0, 0), [490] = new Prof(490, 0, 0), [500] = new Prof(500, 0, 0), [510] = new Prof(510, 0, 0), [530] = new Prof(530, 0, 0), [540] = new Prof(540, 0, 0), [560] = new Prof(560, 0, 0), [561] = new Prof(561, 0, 0), [562] = new Prof(562, 0, 0), [580] = new Prof(580, 0, 0) } }; GiveStarterItems(character); EntityLogic.Recalculate(character); character.CurrentHp = character.MaximumHp; character.CurrentMp = character.MaximumMp; character.Money = 1000; character.Location = new Vector2(61, 109); return(character); }
public static void Spawn() { var _sync = new object(); var sw = Stopwatch.StartNew(); Parallel.ForEach(Collections.Spawns, spawn => { var amount = spawn.Value.Amount; if (!Collections.BaseMonsters.TryGetValue(spawn.Value.MobId, out var monster)) { return; } if (monster.Look != 900 && monster.Look != 910) { amount = (ushort)(amount * 9); } for (var i = 0; i < amount; i++) { var obj = CloneChamber.Clone(Collections.BaseMonsters[spawn.Value.MobId]); obj.SpawnId = spawn.Key; obj.MapId = spawn.Value.MapId; obj.Location.X = spawn.Value.Xstart; obj.Location.Y = spawn.Value.Ystart; var spawnAttempts = 0; while (true) { if (spawnAttempts > 100) { break; } spawnAttempts++; lock (_sync) { if (!GameWorld.Maps.ContainsKey(obj.MapId) || GameWorld.Maps[obj.MapId].MobValid(obj.Location.X, obj.Location.Y)) { if (obj.Look == 900 || obj.Look == 910) //Guard1 Guard2 { obj.Brain = new GuardBrain(obj); } obj.UniqueId = UniqueIdGenerator.GetNext(EntityType.Monster); Collections.Monsters.Add(obj.UniqueId, obj); GameWorld.Maps[obj.MapId].LoadInEntity(obj); break; } } obj.Location.X = (ushort)SafeRandom.Next(spawn.Value.Xstart - 10, spawn.Value.Xstart + spawn.Value.Xend + 10); obj.Location.Y = (ushort)SafeRandom.Next(spawn.Value.Ystart - 10, spawn.Value.Ystart + spawn.Value.Yend + 10); } } }); sw.Stop(); Debug.WriteLine($"[MobGenerator] Spawnd {Collections.Monsters.Count}\t Monsters in {sw.Elapsed.TotalMilliseconds}ms"); }