public static void MovedPriority([NotNull] EventHandler <PlayerMovedEventArgs> callback, Priority priority) { if (callback == null) { throw new ArgumentNullException("callback"); } MovedEvent.Add(callback, priority); }
public async Task Handle(MovedEvent message, CancellationToken cancellationToken) { var player = message.Player; var roomIn = message.RoomIn; var roomOut = message.RoomOut; //更新玩家在线数据 await _chatOnlineProvider.SetPlayerOnline(new PlayerOnlineModel { IsOnline = true, LastDate = DateTime.Now, Level = player.Level, PlayerName = player.Name, PlayerId = player.Id, RoomId = player.RoomId, Gender = player.Gender, Title = player.Title }); //更新玩家聊天房间 await _mudProvider.RemoveFromRoom(player.Id, roomOut.Id); await _mudProvider.AddToRoom(player.Id, roomIn.Id); //更新新房间玩家列表 var playersIn = await _chatOnlineProvider.GetPlayerList(roomIn.Id); await _mudProvider.UpdateRoomPlayerList(roomIn.Id, playersIn); //更新旧房间玩家列表 var playersOut = await _chatOnlineProvider.GetPlayerList(roomOut.Id); await _mudProvider.UpdateRoomPlayerList(roomOut.Id, playersOut); var roomModel = _mapper.Map <RoomModel>(roomIn); await _mudProvider.Move(player.Id, roomModel); //更新当前玩家显示的npc列表 var nps = (await _npcDomainService.GetAll()).Where(x => x.RoomId == roomIn.Id); await _mudProvider.UpdatePlayerRoomNpcList(player.Id, nps); //输出移动信息 await _mudProvider.ShowMessage(player.Id, $"你来到了{roomIn.Name}。"); await _mudProvider.ShowRoomOthersMessage(roomIn.Id, player.Id, $"[{player.Name}] 从{roomOut.Name}走了过来。"); await _mudProvider.ShowRoomOthersMessage(roomOut.Id, player.Id, $"[{player.Name}] 往{roomIn.Name}离开。"); }
public void HandleEvent(IGameObject gameObject, IGameWorld gameWorld, object gameEvent) { if (gameEvent is MoveEvent) { var moveEvent = gameEvent as MoveEvent; gameObject.Azimuth = moveEvent.Direction; var amountX = (float)Math.Sin(ConvertDegreeToRadian(moveEvent.Direction)) * _speed; var amountY = (float)Math.Cos(ConvertDegreeToRadian(moveEvent.Direction)) * _speed; var moveCommand = new MoveCommand(); var moveCommandOptions = new MoveCommandOptions(amountX, amountY); moveCommand.Do(gameObject, gameWorld, moveCommandOptions); var movedEvent = new MovedEvent(gameObject.X, gameObject.Y); gameObject.HandleEvent(gameWorld, movedEvent); } }
private void Update() { if (active) { if (this._pressed) { ///Debug.Log($"Application.isMobilePlatform {Application.isMobilePlatform} Input.touchSupported: {Input.touchSupported} Application.isEditor {Application.isEditor}"); if (Application.isMobilePlatform && Input.touchSupported && !Application.isEditor) { if (this._touchId < 0) { return; } var touch = GetTouch(Input.touches, this._touchId); if (touch.fingerId < 0) { return; } this.handle.transform.position = touch.position; //Input.touches[this._touchId].position; } else { this.handle.transform.position = Input.mousePosition; } //_dir = new Vector2(Mathf.Clamp((this.Handle.transform.position.x - this._defaultPos.x) / speedMul, -1.0f, 1.0f), // Mathf.Clamp((this.Handle.transform.position.y - this._defaultPos.y) / speedMul, -1.0f, 1.0f)); // Mathf.Clamp throws exceptions on WebGL mobile, rewrite the above without using it var xVal = (this.handle.transform.position.x - this._defaultPos.x) / speedMul; xVal = xVal < -1 ? -1 : xVal; xVal = xVal > 1 ? 1 : xVal; var yVal = (this.handle.transform.position.y - this._defaultPos.y) / speedMul; yVal = yVal < -1 ? -1 : yVal; yVal = yVal > 1 ? 1 : yVal; _dir = new Vector2(xVal, yVal); //invoke the event when moved MovedEvent?.Invoke(_dir); //Debug.Log(_dir); } else { //restore the default position //this.handle.transform.position = this._defaultPos; this.handle.transform.position = this._defaultPos; this._dir = Vector2.zero; //invoke the moved event with a zero Vector2 MovedEvent?.Invoke(Vector2.zero); } // Debug.Log($"[{this.name}] " + //$"touches: {Input.touches.Length}," + //$"active {this.active} " + //$"_pressed {_pressed}, " + //$"_touchId {_touchId}, " + //$"_startPos {_startPos}, " + //$"_dir {_dir}"); } // hack to avoid pointer remaining stucked in wrong positions if (Input.touches.Length == 0) { if (_pressed) { Debug.Log($"{this.name} no touches, restoring handle position"); //restore the default position this._pressed = false; this._touchId = -1; this._startPos = Vector2.zero; this.handle.transform.position = this._defaultPos; this._dir = Vector2.zero; //invoke the moved event with a zero Vector2 MovedEvent?.Invoke(Vector2.zero); } } }
internal virtual void MovedEventSender(MoveStatisticsEventargs args) { MovedEvent?.Invoke(this, args); }
remove => RemoveHandler(MovedEvent, value);
add => AddHandler(MovedEvent, value);