public void Execute() { if (!needUpdate) { return; } needUpdate = false; var actualValues = messages.Last(); foreach (var pair in actualValues.entityIdToValue) { ushort entityId = pair.Key; float health = pair.Value; var entity = gameContext.GetEntityWithId(entityId); if (entity == null) { log.Debug("Нет сущности с id " + entityId); continue; } if (!entity.hasMaxHealthPoints) { entity.AddMaxHealthPoints((int)health); } else if (Math.Abs(entity.maxHealthPoints.value - health) > 0.01f) { entity.ReplaceMaxHealthPoints((int)health); } // log.Debug("Обновление хп "+health); } }
public void Execute() { ServerGameEntity playerEntity = gameContext.GetEntityWithId(PlayerIdStorage.PlayerEntityId); if (playerEntity == null) { log.Debug("playerEntity is null"); return; } if (!playerEntity.hasTransform) { log.Debug("playerEntity dont have hasViewTransform"); return; } Vector3 playerPosition = playerEntity.transform.value.position; Transform cameraTransform = mainCamera.transform; Vector3 targetPosition = playerPosition + cameraShift; Vector3 currentPosition = cameraTransform.position; Vector3 currentVelocity = Vector3.zero; float smoothTime = 0.07f; cameraTransform.position = Vector3.SmoothDamp(currentPosition, targetPosition, ref currentVelocity, smoothTime); mainCamera.transform.LookAt(cameraTransform.position - cameraShift); }
public void Execute() { HashSet <ushort> ids = new HashSet <ushort>(withTransformGroup .GetEntities() .Select(item => item.id.value)); float matchTime = matchTimeStorage.GetMatchTime(); Snapshot snapshot; try { snapshot = snapshotManager.CreateInterpolatedSnapshot(matchTime); } catch (Exception e) { log.Error(e.FullMessage()); return; } if (snapshot == null) { throw new NullReferenceException($"snapshot is null"); } foreach (var pair in snapshot.transforms) { ushort entityId = pair.Key; ViewTransformCompressed viewTransform = pair.Value; ServerGameEntity gameEntity = gameContext.GetEntityWithId(entityId); if (gameEntity == null) { AddNewObject(entityId, viewTransform); } else { UpdateTransform(gameEntity, viewTransform); ids.Remove(gameEntity.id.value); } } foreach (ushort id in ids) { // log.Debug($"Удаление объекта id = {id}"); ServerGameEntity gameEntity = gameContext.GetEntityWithId(id); gameEntity.isDestroyed = true; } }
public void Execute() { var playerEntity = gameContext.GetEntityWithId(PlayerIdStorage.PlayerEntityId); if (playerEntity == null) { TryEnableLoadingImage(); } else { TryDisableLoadingImage(); } }
public void Execute() { ushort playerEntityId = PlayerIdStorage.PlayerEntityId; if (playerEntityId == 0) { throw new Exception("Пустой playerEntityId"); } ServerGameEntity playerEntity = gameContext.GetEntityWithId(playerEntityId); if (playerEntity.hasRigidbody) { playerEntity.rigidbody.value.velocity = Vector3.zero; playerEntity.rigidbody.value.angularVelocity = Vector3.zero; } }
public void Predict(ushort playerEntityId, InputMessageModel inputMessageModel, float physicsSimulationDuration) { //взять ввод игрока if (inputMessageModel == null) { log.Debug("Нет ввода"); return; } if (physicsSimulationDuration < 0.005f) { log.Debug("Что за космический fps?"); } // log.Debug("Тик физики "+physicsSimulationDuration); //линейное движение игрока ServerGameEntity playerEntity = gameContext.GetEntityWithId(playerEntityId); Rigidbody warshipRigidbody = playerEntity.rigidbody.value; Vector3 inputVector = inputMessageModel.GetVector3(); float maxSpeed = 10f; warshipRigidbody.velocity = Vector3.zero; if (inputVector.sqrMagnitude > 0.001f) { // log.Debug("Линейное движение игрока"); physicsVelocityManager.ApplyVelocity(warshipRigidbody, inputVector, maxSpeed); } //вращательное движение игрока if (!float.IsNaN(inputMessageModel.Angle)) { float angularVelocity = 90; physicsRotationManager.ApplyRotation(playerEntity.rigidbody.value, inputMessageModel.Angle, angularVelocity, physicsSimulationDuration); } //todo спавн пуль игрока //todo движение пуль игрока //симуляция физики scene.GetPhysicsScene().Simulate(physicsSimulationDuration); }
public void Execute() { lock (lockObj) { if (entityIds == null) { return; } if (entityIds.Count == 0) { return; } log.Info("Обработка новых игроков " + entityIds.Count); var currentEntityIds = new Dictionary <int, ushort>(entityIds); foreach (var pair in currentEntityIds) { int accountId = pair.Key; ushort entityId = pair.Value; // log.Debug($"accountId={accountId} entityId={entityId}"); ServerGameEntity entity = gameContext.GetEntityWithId(entityId); //todo обновление id сущности игрока int currentPlayerAccountId = PlayerIdStorage.AccountId; if (accountId == currentPlayerAccountId) { log.Info($"Установка PlayerEntityId={entityId} accountId={accountId}"); PlayerIdStorage.PlayerEntityId = entityId; } if (entity != null) { entity.ReplaceNickname(playerInfos[accountId].Nickname); entityIds.Remove(accountId); } else { log.Debug($"Нет сущности с таким id entityId = {entityId}"); } } } }