private static async ETTask ExpireLockEvent(this LocationComponent self, long id, long key, long timeout) { await Game.Scene.GetComponent <TimerComponent>().WaitForMilliSecondAsync(timeout); // 超時強制解鎖 self.UnlockEvent(id, key); }
public Camera() { m_location = new LocationComponent(this); m_target = new FollowTargetComponent(this, m_location); m_restrictPosition = new RestrictLocationComponent(this, m_location); m_zoom = 1.0; }
private Entity CreateProjectile(LocationComponent location, Vector2 target, WeaponComponent weaponComponent) { var projectile = new Entity { Id = 72, // todo: EntityFactory Components = new List <IComponent> { location.Clone(), new CollisionComponent(new BoundingCircle { Radius = weaponComponent.CollisionRadius }), // should this be definable? new ImageComponent { TextureId = weaponComponent.TextureId }, new MovementComponent { Velocity = target, Steering = Vector2.Zero, MaxVelocity = weaponComponent.Speed, Mass = 1, MaxForce = weaponComponent.MaxImpactForce, Destinations = new Queue <MoveOrder>(new[] { new MoveOrder { MovementMode = MovementMode.Direct, Destination = target } }) }, } }; return(projectile); }
private void InitializeLocationComponent(Style style) { LocationComponent locationComponent = mapboxMap.LocationComponent; locationComponent.ActivateLocationComponent(this, style, locationEngine); locationComponent.LocationComponentEnabled = true; locationComponent.RenderMode = RenderMode.Compass; }
public static async ETTask Remove(this LocationComponent self, long key) { using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Location, key)) { self.locations.Remove(key); Log.Info($"location remove key: {key}"); } }
public static async ETTask Add(this LocationComponent self, long key, long instanceId) { using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Location, key)) { self.locations[key] = instanceId; Log.Info($"location add key: {key} instanceId: {instanceId}"); } }
public Bullet() { m_location = new LocationComponent(this); m_move = new MoveComponent(this, m_location); m_lifeTimeTotal = 0.5; m_lifeTime = m_lifeTimeTotal; }
public Blood() { m_location = new LocationComponent(this); m_lifeTimeTotal = 0.5; m_lifeTime = m_lifeTimeTotal; m_neverDie = false; m_angle = 0f; }
public static async ETTask <long> Get(this LocationComponent self, long key) { using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Location, key)) { self.locations.TryGetValue(key, out long instanceId); Log.Info($"location get key: {key} instanceId: {instanceId}"); return(instanceId); } }
private void InitializeLocationComponent(MapboxMap mapboxMap) { LocationComponent locationComponent = mapboxMap.LocationComponent; locationComponent.ActivateLocationComponent(this, mapboxMap.Style); locationComponent.LocationComponentEnabled = true; locationComponent.RenderMode = RenderMode.Compass; locationComponent.CameraMode = CameraMode.Tracking; locationComponent.ZoomWhileTracking(10d); }
private void MostrarUbicacionTiempoReal() { if (PermissionsManager.AreLocationPermissionsGranted(this)) { LocationComponent locationComponent = mapboxMap.LocationComponent; locationComponent.ActivateLocationComponent(LocationComponentActivationOptions.InvokeBuilder(this, this.style).Build()); locationComponent.LocationComponentEnabled = true; locationComponent.SetCameraMode(CameraMode.TRACKING, this); locationComponent.RenderMode = RenderMode.COMPASS; } }
private void CreateWorld() { WorldHead = new PortalComponent("Black Hole"); WorldHead.AddComponent(new PortalComponent("White Hole??")); IWorldComponent FirstLevel = new LocationComponent(new Location("???", "easy", "i don`t know", "I DON`T KNOW!!", new List <string>())); IWorldComponent SecondLevel = new LocationComponent(new Location("Lviv", "easy", "12pm", "summer", new List <string>())); IWorldComponent Portal2 = new PortalComponent("!@)(*&("); FirstLevel.AddComponent(SecondLevel); SecondLevel.AddComponent(Portal2); WorldHead.AddComponent(FirstLevel); }
public Ennemy() { m_location = new LocationComponent(this); m_move = new MoveComponent(this, m_location); m_rigidBody = new RigidBodyComponent(this, m_location); m_life = new LifeComponent(this, 50); var r = (byte)RandomGenerator.Instance.Random.Next(0, 255); var g = (byte)RandomGenerator.Instance.Random.Next(0, 255); var b = (byte)RandomGenerator.Instance.Random.Next(0, 255); m_bloodColor = new Color4ub(r, g, b, 255); }
private void ProcessMove(Entity entity, JToken jToken) { if (jToken["destination"] == null) { return; } var travel = entity.GetComponent <TravelComponent>(); var placement = entity.GetComponent <PlacementComponent>(); if (placement == null) { //send error Console.WriteLine("no placement on player"); return; } var lastLocation = travel == null ? placement.Location : travel.Route.Last(); LocationComponent newLocation = null; foreach (var road in lastLocation.Roads) { if (road.To.Id != jToken["destination"].Value <int>()) { continue; } newLocation = road.To; break; } if (newLocation == null) { //send error Console.WriteLine("no way to this location"); return; } if (travel == null) { travel = new TravelComponent { Status = TravelComponent.TravelingStatus.Starting, Route = { newLocation } }; entity.AddComponent(travel); } else { travel.Route.Add(newLocation); } }
public void OnMapReady(MapboxMap p0) { this.mapboxMap = p0; this.mapboxMap.AddOnMapClickListener(this); mapboxMap.SetStyle(Style.Dark, new MapboxMapSetStyleListener((style) => { LocationComponent locationComponent = mapboxMap.LocationComponent; locationComponent.ActivateLocationComponent(this, style); locationComponent.LocationComponentEnabled = true; locationComponent.RenderMode = RenderMode.Gps; mockLocationEngine = new ReplayRouteLocationEngine(); GetRoute(origin, destination); })); }
private static bool TryGetTarget(LocationComponent location, MovementComponent movement, out MoveOrder target) { target = movement.Destinations.FirstOrDefault(); if (target == null) { return(false); } if (HasArrived(location.Location, target.Destination, movement.StopRadius)) { movement.Destinations.Dequeue(); ApplyBrakeForce(movement); } return(true); }
public override EntityRef create(Prefab prefab, Vector3f position) { IList <Component> components = Lists.newArrayList(); foreach (Component component in prefab.iterateComponents()) { Component newComp = componentLibrary.copy(component); components.Add(newComp); if (newComp is LocationComponent) { LocationComponent loc = (LocationComponent)newComp; loc.WorldPosition = position; } } components.Add(new EntityInfoComponent(prefab.Name, prefab.Persisted, prefab.AlwaysRelevant)); return(create(components)); }
public Shoot(Vector2 position, Vector2 direction, Color4ub startColor, Color4ub endColor, float angle = 2, float radius = 2) { m_location = new LocationComponent(this); m_location.SetPosition(position); m_cone = new Cone( position, radius, angle, startColor, endColor, (float)((Math.Atan2(direction.Y, direction.X) + Math.PI * 2) - (angle / 2.0) - Math.PI * 2) ); m_lifeTimeTotal = 0.2; m_lifeTime = m_lifeTimeTotal; }
public static bool LockEvent(this LocationComponent self, long id, long key, long timeout = 60000) { if (!self.lockEventDict.ContainsKey(key)) { self.lockEventDict.Add(key, new Queue <long>()); } if (self.lockEventHashSet.Contains(key)) { // 鎖住 self.lockEventDict[key].Enqueue(id); return(false); } self.lockEventHashSet.Add(key); self.lockEventDict[key].Enqueue(id); self.ExpireLockEvent(id, key, timeout).Coroutine(); return(true); }
public async void AddCharacter(string hubId, Guid characterId) { var player = GetCharacter(Context.ConnectionId, characterId); Entity playerEntity = _world.CreateEntity(); // you can pass an unique ID as first parameter. var playerInput = new PlayerInputComponent(); var playerLocation = new LocationComponent(); playerLocation.RoomId = 0; playerInput.connectionId = player.ConnectionId; playerInput.userId = player.AccountId; //TODO: Create character load to store/load components playerEntity.AddComponent(playerInput); playerEntity.AddComponent(playerLocation); AddCharacterToCache(Context.ConnectionId, player, playerEntity); await SendToClient($"Welcome {player.Name}. Your adventure awaits you.", Context.ConnectionId); GetRoom(Context.ConnectionId, player); }
public void OnMapReady(MapboxMap p0) { this.mapboxMap = p0; this.mapboxMap.AddOnMapClickListener(this); mapboxMap.SetStyle(Style.MapboxStreets, new MapboxMapSetStyleListener((style) => { LocationComponent locationComponent = mapboxMap.LocationComponent; locationComponent.ActivateLocationComponent(this, style); locationComponent.RenderMode = RenderMode.Gps; locationComponent.LocationComponentEnabled = false; navigationMapRoute = new NavigationMapRoute(navigation, mapView, mapboxMap); Snackbar.Make(FindViewById <ConstraintLayout>(Resource.Id.container), "Tap map to place waypoint", BaseTransientBottomBar.LengthLong).Show(); locationEngine = new ReplayRouteLocationEngine(); NewOrigin(); })); }
public static bool UnlockEvent(this LocationComponent self, long id, long key) { if (!self.lockEventHashSet.Contains(key)) { return(false); } if (self.lockEventDict.TryGetValue(key, out var queue)) { if (queue.Count != 0) { if (id == queue.Peek()) { queue.Dequeue(); if (queue.Count == 0) { self.lockEventHashSet.Remove(key); self.lockEventDict.Remove(key); } else { // 通知下一個可以進入 var next = queue.Peek(); var session = SessionHelper.GetSession(IdGenerater.GetAppId(next)); session.Send(new L2S_ReceiveUnlockEvent { Key = key, Id = next }); } return(true); } else { return(false); } } else { return(false); } } else { return(false); } }
public FireCamp() { m_location = new LocationComponent(this); m_rigidBody = new RigidBodyComponent(this, m_location); m_renderer = new SpriteRenderer(FireSprites.Instance); m_box = new Vector2(48, 48); m_sequence = new SpriteSequence( FireSprites.Instance.Camp1, FireSprites.Instance.Camp2, FireSprites.Instance.Camp3, FireSprites.Instance.Camp4, FireSprites.Instance.Camp5 ); m_sequence.SpritesPerSecond = 7; SetSprite(m_renderer); }
public Player() { m_location = new LocationComponent(this); m_rigidBody = new RigidBodyComponent(this, m_location); m_renderer = new SpriteRenderer(PlayerSprites.Instance); m_sprite = m_renderer.AddSprite(PlayerSprites.Instance.StandRight); m_walkRightSequence = new SpriteSequence( PlayerSprites.Instance.WalkRight01, PlayerSprites.Instance.WalkRight02, PlayerSprites.Instance.WalkRight03, PlayerSprites.Instance.WalkRight04, PlayerSprites.Instance.WalkRight05, PlayerSprites.Instance.WalkRight06, PlayerSprites.Instance.WalkRight07, PlayerSprites.Instance.WalkRight08, PlayerSprites.Instance.WalkRight09, PlayerSprites.Instance.WalkRight10, PlayerSprites.Instance.WalkRight11 ); m_walkLeftSequence = new SpriteSequence( PlayerSprites.Instance.WalkLeft01, PlayerSprites.Instance.WalkLeft02, PlayerSprites.Instance.WalkLeft03, PlayerSprites.Instance.WalkLeft04, PlayerSprites.Instance.WalkLeft05, PlayerSprites.Instance.WalkLeft06, PlayerSprites.Instance.WalkLeft07, PlayerSprites.Instance.WalkLeft08, PlayerSprites.Instance.WalkLeft09, PlayerSprites.Instance.WalkLeft10, PlayerSprites.Instance.WalkLeft11 ); m_standRightSequence = new SpriteSequence(PlayerSprites.Instance.StandRight); m_standLeftSequence = new SpriteSequence(PlayerSprites.Instance.StandLeft); m_jumpRightSequence = new SpriteSequence(PlayerSprites.Instance.JumpRight); m_jumpLeftSequence = new SpriteSequence(PlayerSprites.Instance.JumpLeft); m_duckRightSequence = new SpriteSequence(PlayerSprites.Instance.DuckRight); m_duckLeftSequence = new SpriteSequence(PlayerSprites.Instance.DuckLeft); }
public override void Process(Entity e) { MovementComponent movementRequest = e.GetComponent <MovementComponent>(); Console.WriteLine($"Handling movement request for {e.Id}"); LocationComponent location = e.GetComponent <LocationComponent>(); var currentRoom = _cache.GetRoom(location.RoomId); //Teleporting if (movementRequest.roomId != null) { location.RoomId = (int)movementRequest.roomId; } //Regular movement if (movementRequest.direction != Direction.None) { location.RoomId = currentRoom.ExitMap[movementRequest.direction].RoomId; } }
public void TravelTo(LocationComponent location) { if (!location) { return; } this.Log(Entity.Location ? $"Travel travelling from {Entity.Location} to {location}" : $"Travel spawning entity at {location}"); if (Entity.Location) { Entity.Location.EntityRegistry.Unregister(Entity); } CurrentDestination = location; Pathfinder.SetDestination(location.EntryCell); DestinationChanged?.Invoke(this, new MapComponent.LocationEventArgs(location)); }
private static void Seek(LocationComponent location, MovementComponent target, Vector2 destination) { //subtract the position from the target to get the vector from the vehicles position to the target. var directionVector = (destination - location.Location); //Normalize it then multiply by max speed to get the maximum velocity from your position to the target. var desiredVelocity = directionVector.Truncate(target.MaxVelocity); //subtract velocity from the desired velocity to get the force vector target.Steering = desiredVelocity - target.Velocity; //divide the steeringForce by the mass(which makes it the acceleration), target.Steering = target.Steering.Truncate(target.MaxForce) / target.Mass; //then add it to velocity to get the new velocity target.Velocity = (target.Velocity + target.Steering).Truncate(target.MaxVelocity); //Set the facingAngle (used to draw the image, in radians) to velocity location.FacingAngle = target.Velocity.Angle(); location.Location += target.Velocity; }
public static void UnLock(this LocationComponent self, long key, long oldInstanceId, long newInstanceId) { if (!self.lockInfos.TryGetValue(key, out LockInfo lockInfo)) { Log.Error($"location unlock not found key: {key} {oldInstanceId}"); return; } if (oldInstanceId != lockInfo.LockInstanceId) { Log.Error($"location unlock oldInstanceId is different: {key} {oldInstanceId}"); return; } Log.Info($"location unlock key: {key} instanceId: {oldInstanceId} newInstanceId: {newInstanceId}"); self.locations[key] = newInstanceId; self.lockInfos.Remove(key); // 解锁 lockInfo.Dispose(); }
public static async ETTask Lock(this LocationComponent self, long key, long instanceId, int time = 0) { CoroutineLock coroutineLock = await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Location, key); LockInfo lockInfo = self.AddChild <LockInfo, long, CoroutineLock>(instanceId, coroutineLock); self.lockInfos.Add(key, lockInfo); Log.Info($"location lock key: {key} instanceId: {instanceId}"); if (time > 0) { long lockInfoInstanceId = lockInfo.InstanceId; await TimerComponent.Instance.WaitAsync(time); if (lockInfo.InstanceId != lockInfoInstanceId) { return; } self.UnLock(key, instanceId, instanceId); } }
public Player() { m_location = new LocationComponent(this); m_rigidBody = new RigidBodyComponent(this, m_location); m_move = new MoveComponent(this, m_location); m_life = new LifeComponent(this, 100); m_box = new Vector2(32, 32); m_weapons = new Dictionary <string, Weapon>(); m_renderer = new SpriteRenderer(PlayerSprites.Instance); m_sprite = m_renderer.AddSprite(PlayerSprites.Instance.Front1); m_walkRightSequence = new SpriteSequence( PlayerSprites.Instance.Right1, PlayerSprites.Instance.Right2, PlayerSprites.Instance.Right3 ); m_walkLeftSequence = new SpriteSequence( PlayerSprites.Instance.Left1, PlayerSprites.Instance.Left2, PlayerSprites.Instance.Left3 ); m_walkFrontSequence = new SpriteSequence( PlayerSprites.Instance.Front1, PlayerSprites.Instance.Front2, PlayerSprites.Instance.Front3 ); m_walkBackSequence = new SpriteSequence( PlayerSprites.Instance.Back1, PlayerSprites.Instance.Back2, PlayerSprites.Instance.Back3 ); }
public RestrictLocationComponent(Entity entity, LocationComponent location) : base(entity) { m_location = location; }
public Ennemy() { m_location = new LocationComponent(this); m_rigidBody = new RigidBodyComponent(this, m_location); }
public FollowTargetComponent(Entity entity, LocationComponent location) : base(entity) { m_location = location; }
public RigidBodyComponent(Entity entity, LocationComponent location) : base(entity) { m_location = location; Velocity = new Vector2(0, 0); }
public Camera() { m_location = new LocationComponent(this); m_target = new FollowTargetComponent(this, m_location); m_restrictPosition = new RestrictLocationComponent(this, m_location); }