private void Drag() { firstSelectionFrame = false; AttachedEntity.Move(Grid.grid.WorldToGrid(MouseWorldPosition())); UpdateRenderers(); UpdateGridHighlight(); if (!WorldEditor.WorldEditorManager.IsWorldEditorActive) { arrowTarget = Grid.GridToLocal(AttachedEntity.coordinates, 0.2f); arrow.positionCount = 4; arrow.SetPositions(new Vector3[] { arrowOrigin , Vector3.Lerp(arrowOrigin, arrowTarget, 0.999f - arrowHeadPer) , Vector3.Lerp(arrowOrigin, arrowTarget, 1 - arrowHeadPer) , arrowTarget }); if (!fixedRotation) { // Rotate to face movement direction Quaternion orientation = Quaternion.LookRotation(arrowTarget - arrowOrigin, Vector3.up); transform.rotation = orientation; } } }
protected override void FrameUpdate(FrameEventArgs args) { base.FrameUpdate(args); if (AttachedEntity?.IsValid() != true || !AttachedEntity.TryGetComponent(out DoAfterComponent? doAfterComponent)) { return; } var doAfters = doAfterComponent.DoAfters; if (doAfters.Count == 0) { return; } // Set position ready for 2nd+ frames. _playerPosition = _eyeManager.CoordinatesToScreen(AttachedEntity.Transform.Coordinates); LayoutContainer.SetPosition(this, new Vector2(_playerPosition.X - Width / 2, _playerPosition.Y - Height - 30.0f)); if (FirstDraw) { Visible = false; FirstDraw = false; return; } Visible = true; var currentTime = _gameTiming.CurTime; var toCancel = new List <byte>(); // Cleanup cancelled DoAfters foreach (var(id, cancelTime) in _cancelledDoAfters) { if ((currentTime - cancelTime).TotalSeconds > DoAfterSystem.ExcessTime) { toCancel.Add(id); } } foreach (var id in toCancel) { RemoveDoAfter(id); } // Update 0 -> 1.0f of the things foreach (var(id, message) in doAfters) { if (_cancelledDoAfters.ContainsKey(id) || !_doAfterControls.ContainsKey(id)) { continue; } var doAfterBar = _doAfterBars[id]; doAfterBar.Ratio = MathF.Min(1.0f, (float)(currentTime - message.StartTime).TotalSeconds / message.Delay); } }
private void Deselect() { Vector2Int targetCoordinates = gridHighlight.coordinates; bool isReachable = false; if (requiresPath && !WorldEditor.WorldEditorManager.IsWorldEditorActive) { // Check if path between old and new position is possible GridPathfinder ptf = new GridPathfinder(Grid.grid); List <Vector2Int> path = ptf.GetPath(AttachedEntity.BookmarkedCoordinates, targetCoordinates); isReachable = path != null; } else { // Check if the new position is vacant isReachable = !Grid.grid.CheckCollisionFlags(targetCoordinates, AttachedEntity.GetCollisionFlags()); } if (isReachable) { // Can move to new position AttachedEntity.Move(targetCoordinates); } else { if (WorldEditor.WorldEditorManager.IsWorldEditorActive) { // Cannot move to selected position - abort placement return; } else { // Cannot move to new position - go back to old position AttachedEntity.LoadBookmark(); } } DestroyGridHighlight(); // Update collision data AttachedEntity.UpdateCollision(); HasSelection = false; isSelected = false; UpdateRenderers(); arrow.positionCount = 0; }
// *** INTERNAL FUNCTIONS *** private void Select() { AttachedEntity.SetBookmark(); AttachedEntity.ClearCollisionAtBookmark(); HasSelection = true; isSelected = true; firstSelectionFrame = true; UpdateRenderers(); movePlane = new Plane(Vector3.up, transform.position); CreateGridHighlight(); arrowOrigin = transform.position; arrowOrigin.y = 0.2f; //make the arrow plane a little bit higher than the game board }
private void RunInteractions() { if (toggleCollision) { AttachedEntity.ToggleCollision(); } foreach (var animator in objectsToAnimate) { animator.SetTrigger(ANIM_TRIGGER_ID); } foreach (var item in objectsToToggle) { item.SetActive(!item.activeSelf); } }
public IEnumerator CommitActions() { IsBusy = true; // First move the AI if (FoundMovePos.HasValue) { AttachedEntity.StartMoveAnimation(FoundMovePos.Value); yield return(new WaitWhile(() => AttachedEntity.IsMoving)); } // Then attack the target if (FoundTarget.HasValue) { AttachedSkill.ActivateSkill(AttachedUnit, FoundTarget.Value); } IsBusy = false; }
private void Start() { attachedNpc = AttachedEntity.AsActor().AsNPC(); }
public void Shoot(Vector3 target = default) { if (currentShotInterval > 0) { return; } AttachedEntity.AsItem().Owner.ReadyTimer += Settings.ShotInterval + 0.2f; Vector3 mousePos = InputManager.Instance.MouseWorldPosition; Quaternion startRotation = Quaternion.LookRotation(new Vector3(mousePos.x, ProjectileSpawn.position.y, mousePos.z) - ProjectileSpawn.position); if (target != default) { startRotation = Quaternion.LookRotation(target - ProjectileSpawn.position); } Projectile proj = Instantiate(LoadedProjectile.Prefab, ProjectileSpawn.position, startRotation).GetComponent <Projectile>(); proj.Direction = proj.transform.forward; proj.Creator = AttachedEntity; proj.Settings = LoadedProjectile; proj.Initialize(); float spreadRandomX = Random.Range(-currentSpreading, currentSpreading); float spreadRandomY = Random.Range(-currentSpreading, currentSpreading); float spreadRandomZ = Random.Range(-currentSpreading, currentSpreading); proj.Direction += new Vector3(spreadRandomX, spreadRandomY, spreadRandomZ); proj.GetComponent <Rigidbody>().AddForce(proj.Direction * proj.ProjectileStats["Speed"].EffectiveValue); EffectsManager.Instance.SpawnEffect(ShotEffect, ProjectileSpawn.position, Quaternion.identity); if (Settings.ShootSounds.Count > 0) { SoundManager.Instance.PlayClipAtPoint(Settings.ShootSounds.RandomItem(), transform.position, Settings.ShootVolume); } if (NetManager.Instance.Connect) { //Sending packet to the server using (Packet packet = new Packet()) { ProjectileSpawnData data = new ProjectileSpawnData(); data.DataType = typeof(ProjectileSpawnData).ToString(); data.Prefix = "PREFIX: PROJECTILE"; data.Force = proj.Direction * proj.ProjectileStats["Speed"].EffectiveValue; data.DataId = LoadedProjectile.Id; data.PrefabResourcePath = LoadedProjectile.Prefab.name; data.Position = ProjectileSpawn.position; data.Rotation = startRotation.eulerAngles; data.DeathEffectPath = LoadedProjectile.DeathEffect.name; data.Speed = LoadedProjectile.Speed; data.Heatlh = LoadedProjectile.Heatlh; packet.Write(JsonUtility.ToJson(data, true)); NetManager.Instance.SendData(packet); } //------------------- } ((Weapon)AttachedEntity).OnShoot?.Invoke(); currentShotInterval = Settings.ShotInterval; // Recoil grow (spreading grows) currentSpreading = Mathf.Clamp(currentSpreading + Settings.Recoil, Settings.Spreading, Settings.Spreading + Settings.MaxRecoil); currentClipSize--; if (currentClipSize == 0) { currentShotInterval += Settings.ReloadTime - Settings.ShotInterval; currentClipSize = Settings.ClipSize; if (Settings.ReloadSounds.Count > 0) { StartCoroutine(PlayReloadSounds()); } } }