protected void OnAttributesOperation(LiteNetLibSyncList.Operation operation, int index) { if (PlayerCharacterEntity.IsOwnerClient && CacheUISceneGameplay != null) { CacheUISceneGameplay.UpdateCharacter(); } }
protected void OnQuestsOperation(LiteNetLibSyncList.Operation operation, int index) { if (CharacterEntity.IsOwnerClient && CacheUISceneGameplay != null) { CacheUISceneGameplay.UpdateQuests(); } }
protected void OnEquipWeaponsChange(EquipWeapons equipWeapons) { if (CharacterEntity.IsOwnerClient && CacheUISceneGameplay != null) { CacheUISceneGameplay.UpdateCharacter(); CacheUISceneGameplay.UpdateEquipItems(); } }
protected virtual void TabTargetUpdate() { if (PlayerCharacterEntity == null || !PlayerCharacterEntity.IsOwnerClient) { return; } if (Targeting.SelectedTarget == null && Targeting.PotentialTarget == null && Targeting.CastingTarget == null) { ClearTarget(); } if (CacheGameplayCameraControls != null) { CacheGameplayCameraControls.target = CameraTargetTransform; } if (CacheMinimapCameraControls != null) { CacheMinimapCameraControls.target = CameraTargetTransform; } if (CacheTargetObject != null) { CacheTargetObject.gameObject.SetActive(destination.HasValue); } if (PlayerCharacterEntity.IsDead()) { ClearTarget(); ClearQueueUsingSkill(); destination = null; isFollowingTarget = false; CancelBuild(); CacheUISceneGameplay.SetTargetEntity(null); } else { TabTargetUpdateTarget(); } if (destination.HasValue) { if (CacheTargetObject != null) { CacheTargetObject.transform.position = destination.Value; } if (Vector3.Distance(destination.Value, MovementTransform.position) < StoppingDistance + 0.5f) { destination = null; } } Targeting.UpdateTargeting(); ClearQueuedSkillIfInSafeZone(); TabTargetUpdateInput(); TabTargetUpdateFollowTarget(); }
protected void OnSkillsOperation(LiteNetLibSyncList.Operation operation, int index) { if (CharacterEntity.IsOwnerClient && CacheUISceneGameplay != null) { CacheUISceneGameplay.UpdateCharacter(); CacheUISceneGameplay.UpdateSkills(); CacheUISceneGameplay.UpdateHotkeys(); } }
protected void OnNonEquipItemsOperation(LiteNetLibSyncList.Operation operation, int index) { if (PlayerCharacterEntity.IsOwnerClient && CacheUISceneGameplay != null) { CacheUISceneGameplay.UpdateCharacter(); CacheUISceneGameplay.UpdateNonEquipItems(); CacheUISceneGameplay.UpdateHotkeys(); CacheUISceneGameplay.UpdateQuests(); } }
protected void OnDataIdChange(int dataId) { if (CharacterEntity.IsOwnerClient && CacheUISceneGameplay != null) { CacheUISceneGameplay.UpdateCharacter(); CacheUISceneGameplay.UpdateSkills(); CacheUISceneGameplay.UpdateEquipItems(); CacheUISceneGameplay.UpdateNonEquipItems(); } }
protected void OnIdChange(string id) { if (PlayerCharacterEntity.IsOwnerClient && CacheUISceneGameplay != null) { CacheUISceneGameplay.UpdateCharacter(); CacheUISceneGameplay.UpdateSkills(); CacheUISceneGameplay.UpdateEquipItems(); CacheUISceneGameplay.UpdateNonEquipItems(); } }
protected void UpdateBuilding() { // Current building UI BuildingEntity currentBuilding; var uiCurrentBuilding = CacheUISceneGameplay.uiCurrentBuilding; if (uiCurrentBuilding != null) { if (uiCurrentBuilding.IsVisible() && !PlayerCharacterEntity.TryGetTargetEntity(out currentBuilding)) { uiCurrentBuilding.Hide(); } } // Construct building UI var uiConstructBuilding = CacheUISceneGameplay.uiConstructBuilding; if (uiConstructBuilding != null) { if (uiConstructBuilding.IsVisible() && currentBuildingEntity == null) { uiConstructBuilding.Hide(); } if (!uiConstructBuilding.IsVisible() && currentBuildingEntity != null) { uiConstructBuilding.Show(); } } if (currentBuildingEntity == null) { return; } var isPointerOverUI = CacheUISceneGameplay != null && CacheUISceneGameplay.IsPointerOverUIObject(); if (Input.GetMouseButtonDown(0)) { isMouseDragOrHoldOrOverUI = false; mouseDownTime = Time.unscaledTime; mouseDownPosition = Input.mousePosition; } var isMouseDragDetected = (Input.mousePosition - mouseDownPosition).magnitude > DETECT_MOUSE_DRAG_DISTANCE; var isMouseHoldDetected = Time.unscaledTime - mouseDownTime > DETECT_MOUSE_HOLD_DURATION; if (!isMouseDragOrHoldOrOverUI && (isMouseDragDetected || isMouseHoldDetected || isPointerOverUI)) { isMouseDragOrHoldOrOverUI = true; } if (!isPointerOverUI && Input.GetMouseButtonUp(0) && !isMouseDragOrHoldOrOverUI) { FindAndSetBuildingAreaFromMousePosition(); } }
protected void OnBuffsOperation(LiteNetLibSyncList.Operation operation, int index) { if (PlayerCharacterEntity.IsOwnerClient && CacheUISceneGameplay != null) { if (operation == LiteNetLibSyncList.Operation.Add || operation == LiteNetLibSyncList.Operation.RemoveAt || operation == LiteNetLibSyncList.Operation.Insert || operation == LiteNetLibSyncList.Operation.Clear) { CacheUISceneGameplay.UpdateCharacter(); } } }
protected virtual void Setup(BasePlayerCharacterEntity characterEntity) { if (characterEntity == null) { return; } // Instantiate Minimap camera, it will render to render texture if (CacheMinimapCameraControls != null) { CacheMinimapCameraControls.target = characterEntity.CacheTransform; } // Instantiate gameplay UI if (CacheUISceneGameplay != null) { characterEntity.onShowNpcDialog += CacheUISceneGameplay.OnShowNpcDialog; characterEntity.onShowNpcRefine += CacheUISceneGameplay.OnShowNpcRefine; characterEntity.onDead += CacheUISceneGameplay.OnCharacterDead; characterEntity.onRespawn += CacheUISceneGameplay.OnCharacterRespawn; characterEntity.onShowDealingRequestDialog += CacheUISceneGameplay.OnShowDealingRequest; characterEntity.onShowDealingDialog += CacheUISceneGameplay.OnShowDealing; characterEntity.onUpdateDealingState += CacheUISceneGameplay.OnUpdateDealingState; characterEntity.onUpdateDealingGold += CacheUISceneGameplay.OnUpdateDealingGold; characterEntity.onUpdateDealingItems += CacheUISceneGameplay.OnUpdateDealingItems; characterEntity.onUpdateAnotherDealingState += CacheUISceneGameplay.OnUpdateAnotherDealingState; characterEntity.onUpdateAnotherDealingGold += CacheUISceneGameplay.OnUpdateAnotherDealingGold; characterEntity.onUpdateAnotherDealingItems += CacheUISceneGameplay.OnUpdateAnotherDealingItems; characterEntity.onShowPartyInvitationDialog += CacheUISceneGameplay.OnShowPartyInvitation; characterEntity.onShowGuildInvitationDialog += CacheUISceneGameplay.OnShowGuildInvitation; CacheUISceneGameplay.UpdateCharacter(); CacheUISceneGameplay.UpdateSkills(); CacheUISceneGameplay.UpdateSummons(); CacheUISceneGameplay.UpdateEquipItems(); CacheUISceneGameplay.UpdateNonEquipItems(); CacheUISceneGameplay.UpdateHotkeys(); CacheUISceneGameplay.UpdateQuests(); } characterEntity.onIdChange += OnIdChange; characterEntity.onEquipWeaponsChange += OnEquipWeaponsChange; characterEntity.onAttributesOperation += OnAttributesOperation; characterEntity.onSkillsOperation += OnSkillsOperation; characterEntity.onSummonsOperation += OnSummonsOperation; characterEntity.onBuffsOperation += OnBuffsOperation; characterEntity.onEquipItemsOperation += OnEquipItemsOperation; characterEntity.onNonEquipItemsOperation += OnNonEquipItemsOperation; characterEntity.onHotkeysOperation += OnHotkeysOperation; characterEntity.onQuestsOperation += OnQuestsOperation; }
protected override void Update() { if (PlayerCharacterEntity == null || !PlayerCharacterEntity.IsOwnerClient) { return; } base.Update(); if (CacheTargetObject != null) { CacheTargetObject.gameObject.SetActive(destination.HasValue); } if (PlayerCharacterEntity.IsDead()) { queueUsingSkill = null; destination = null; if (CacheUISceneGameplay != null) { CacheUISceneGameplay.SetTargetEntity(null); } CancelBuild(); } else { if (CacheUISceneGameplay != null) { CacheUISceneGameplay.SetTargetEntity(SelectedEntity); } } if (destination.HasValue) { if (CacheTargetObject != null) { CacheTargetObject.transform.position = destination.Value; } if (Vector3.Distance(destination.Value, CharacterTransform.position) < StoppingDistance + 0.5f) { destination = null; } } UpdateInput(); UpdateFollowTarget(); UpdateLookAtTarget(); }
protected void UpdateWASDInput() { // If mobile platforms, don't receive input raw to make it smooth bool raw = !InputManager.useMobileInputOnNonMobile && !Application.isMobilePlatform; Vector3 moveDirection = GetMoveDirection(InputManager.GetAxis("Horizontal", raw), InputManager.GetAxis("Vertical", raw)); moveDirection.Normalize(); if (moveDirection.sqrMagnitude > 0f) { // Character start moving, so hide npc dialog HideNpcDialog(); } bool isPointerOverUIObject = CacheUISceneGameplay.IsPointerOverUIObject(); // If pointer over ui, start avoid attack inputs // to prevent character attack while pointer over ui if (isPointerOverUIObject) { avoidAttackWhileCursorOverUI = true; } // Attack when player pressed attack button if (!avoidAttackWhileCursorOverUI && !UICharacterHotkeys.UsingHotkey && (InputManager.GetButton("Fire1") || InputManager.GetButton("Attack") || InputManager.GetButtonUp("Fire1") || InputManager.GetButtonUp("Attack"))) { UpdateFireInput(); } // No pointer over ui and all attack key released, stop avoid attack inputs if (avoidAttackWhileCursorOverUI && !isPointerOverUIObject && !InputManager.GetButton("Fire1") && !InputManager.GetButton("Attack")) { avoidAttackWhileCursorOverUI = false; } // Always forward MovementState movementState = Vector3.Angle(moveDirection, MovementTransform.forward) < 120 ? MovementState.Forward : MovementState.Backward; if (InputManager.GetButtonDown("Jump")) { movementState |= MovementState.IsJump; } PlayerCharacterEntity.KeyMovement(moveDirection, movementState); }
public void Activate() { // Priority Player -> Npc -> Buildings if (targetPlayer != null && CacheUISceneGameplay != null) { CacheUISceneGameplay.SetActivePlayerCharacter(targetPlayer); } else if (targetNpc != null) { PlayerCharacterEntity.RequestNpcActivate(targetNpc.ObjectId); } else if (targetBuilding != null) { ActivateBuilding(targetBuilding); } }
public virtual void Activate() { Transform tempTransform = SelectedEntity ? SelectedEntity.transform : null; if (tempTransform == null) { return; } targetPlayer = tempTransform.GetComponent <BasePlayerCharacterEntity>(); targetMonster = tempTransform.GetComponent <BaseMonsterCharacterEntity>(); targetNpc = tempTransform.GetComponent <NpcEntity>(); targetItemDrop = tempTransform.GetComponent <ItemDropEntity>(); targetHarvestable = tempTransform.GetComponent <HarvestableEntity>(); targetBuilding = null; targetVehicle = tempTransform.GetComponent <VehicleEntity>(); targetActionType = TargetActionType.Activate; isFollowingTarget = true; isAutoAttacking = false; // Priority Player -> Npc -> Buildings if (targetPlayer != null) { CacheUISceneGameplay.SetActivePlayerCharacter(targetPlayer); } else if (targetMonster != null || targetHarvestable != null) { targetActionType = TargetActionType.Attack; isAutoAttacking = true; } else if (targetNpc != null) { PlayerCharacterEntity.CallServerNpcActivate(targetNpc.ObjectId); } else if (targetBuilding != null) { SelectedEntity = targetBuilding; ActivateBuilding(targetBuilding); } else if (targetVehicle != null) { PlayerCharacterEntity.CallServerEnterVehicle(targetVehicle.ObjectId); } else if (targetWarpPortal != null) { PlayerCharacterEntity.CallServerEnterWarp(targetWarpPortal.ObjectId); } }
public virtual void TabTargetUpdateTarget() { bool hasChanged = cachePotentialTarget != Targeting.PotentialTarget || cacheSelectedTarget != Targeting.SelectedTarget; PlayerCharacterEntity.SetSubTarget(CachePotentialTarget); PlayerCharacterEntity.SetTargetEntity(CacheSelectedTarget); PlayerCharacterEntity.SetCastingTarget(CacheCastingTarget); SelectedEntity = CacheSelectedTarget; TargetEntity = SelectedEntity; if (hasChanged) { isAutoAttacking = false; CacheUISceneGameplay.SetTargetEntity(null); CacheUISceneGameplay.SetTargetEntity(CacheActionTarget); } }
protected override void Update() { base.Update(); if (CacheTargetObject != null) { CacheTargetObject.gameObject.SetActive(destination.HasValue); } if (CharacterEntity.CurrentHp <= 0) { queueUsingSkill = null; destination = null; if (CacheUISceneGameplay != null) { CacheUISceneGameplay.SetTargetCharacter(null); } } else { BaseCharacterEntity targetCharacter = null; CharacterEntity.TryGetTargetEntity(out targetCharacter); if (CacheUISceneGameplay != null) { CacheUISceneGameplay.SetTargetCharacter(targetCharacter); } } if (destination.HasValue) { var destinationValue = destination.Value; if (CacheTargetObject != null) { CacheTargetObject.transform.position = destinationValue; } if (Vector3.Distance(destinationValue, CharacterTransform.position) < StoppingDistance + 0.5f) { destination = null; } } UpdateInput(); UpdateFollowTarget(); }
protected void UpdateBuilding() { // Current building UI UICurrentBuilding uiCurrentBuilding = CacheUISceneGameplay.uiCurrentBuilding; if (uiCurrentBuilding != null) { if (uiCurrentBuilding.IsVisible() && ActiveBuildingEntity == null) { uiCurrentBuilding.Hide(); } } // Construct building UI UIConstructBuilding uiConstructBuilding = CacheUISceneGameplay.uiConstructBuilding; if (uiConstructBuilding != null) { if (uiConstructBuilding.IsVisible() && CurrentBuildingEntity == null) { uiConstructBuilding.Hide(); } if (!uiConstructBuilding.IsVisible() && CurrentBuildingEntity != null) { uiConstructBuilding.Show(); } } if (CurrentBuildingEntity == null) { return; } bool isPointerOverUI = CacheUISceneGameplay != null && CacheUISceneGameplay.IsPointerOverUIObject(); if (Input.GetMouseButton(0) && !isPointerOverUI) { mouseDownTime = Time.unscaledTime; mouseDownPosition = Input.mousePosition; FindAndSetBuildingAreaFromMousePosition(); } }
protected void UpdateWASDInput() { // If mobile platforms, don't receive input raw to make it smooth bool raw = !InputManager.useMobileInputOnNonMobile && !Application.isMobilePlatform; Vector3 moveDirection = GetMoveDirection(InputManager.GetAxis("Horizontal", raw), InputManager.GetAxis("Vertical", raw)); moveDirection.Normalize(); if (moveDirection.sqrMagnitude > 0f) { // Character start moving, so hide npc dialog HideNpcDialog(); } // Attack when player pressed attack button if (CacheUISceneGameplay.IsPointerOverUIObject()) { waitForKeyup = true; } else if (!InputManager.GetButton("Fire1") && !InputManager.GetButton("Attack")) { waitForKeyup = false; } if (!waitForKeyup && !UICharacterHotkeys.UsingHotkey && (InputManager.GetButton("Fire1") || InputManager.GetButton("Attack") || InputManager.GetButtonUp("Fire1") || InputManager.GetButtonUp("Attack"))) { UpdateFireInput(); } // Always forward MovementState movementState = Vector3.Angle(moveDirection, MovementTransform.forward) < 120 ? MovementState.Forward : MovementState.Backward; if (InputManager.GetButtonDown("Jump")) { movementState |= MovementState.IsJump; } PlayerCharacterEntity.KeyMovement(moveDirection, movementState); }
protected virtual void Start() { if (CharacterEntity == null) { return; } // Instantiate Minimap camera, it will render to render texture if (minimapCameraPrefab != null) { CacheMinimapCameraControls = Instantiate(minimapCameraPrefab); CacheMinimapCameraControls.target = CharacterTransform; } // Instantiate gameplay UI if (gameInstance.UISceneGameplayPrefab != null) { CacheUISceneGameplay = Instantiate(gameInstance.UISceneGameplayPrefab); CacheUISceneGameplay.UpdateCharacter(); CacheUISceneGameplay.UpdateSkills(); CacheUISceneGameplay.UpdateEquipItems(); CacheUISceneGameplay.UpdateNonEquipItems(); CacheUISceneGameplay.UpdateHotkeys(); CacheUISceneGameplay.UpdateQuests(); CharacterEntity.onShowNpcDialog += CacheUISceneGameplay.OnShowNpcDialog; CharacterEntity.onDead += CacheUISceneGameplay.OnCharacterDead; CharacterEntity.onRespawn += CacheUISceneGameplay.OnCharacterRespawn; } CharacterEntity.onDataIdChange += OnDataIdChange; CharacterEntity.onEquipWeaponsChange += OnEquipWeaponsChange; CharacterEntity.onAttributesOperation += OnAttributesOperation; CharacterEntity.onSkillsOperation += OnSkillsOperation; CharacterEntity.onBuffsOperation += OnBuffsOperation; CharacterEntity.onEquipItemsOperation += OnEquipItemsOperation; CharacterEntity.onNonEquipItemsOperation += OnNonEquipItemsOperation; CharacterEntity.onHotkeysOperation += OnHotkeysOperation; CharacterEntity.onQuestsOperation += OnQuestsOperation; }
public override void UpdatePointClickInput() { // If it's building something, not allow point click movement if (ConstructingBuildingEntity != null) { return; } isPointerOverUI = CacheUISceneGameplay != null && CacheUISceneGameplay.IsPointerOverUIObject(); if (isPointerOverUI) { return; } // Temp mouse input value getMouseDown = Input.GetMouseButtonDown(0); getMouseUp = Input.GetMouseButtonUp(0); getMouse = Input.GetMouseButton(0); getRMouseDown = Input.GetMouseButtonDown(1); getRMouseUp = Input.GetMouseButtonUp(1); getRMouse = Input.GetMouseButton(1); // Prepare temp variables bool foundTargetEntity = false; Transform tempTransform; Vector3 tempVector3; int tempCount; BuildingMaterial tempBuildingMaterial; // Clear target if (!getMouse || getMouseDown) { TargetEntity = null; didActionOnTarget = false; } tempCount = FindClickObjects(out tempVector3); for (int tempCounter = 0; tempCounter < tempCount; ++tempCounter) { tempTransform = physicFunctions.GetRaycastTransform(tempCounter); targetPlayer = tempTransform.GetComponent <BasePlayerCharacterEntity>(); targetMonster = tempTransform.GetComponent <BaseMonsterCharacterEntity>(); targetNpc = tempTransform.GetComponent <NpcEntity>(); targetItemDrop = tempTransform.GetComponent <ItemDropEntity>(); targetHarvestable = tempTransform.GetComponent <HarvestableEntity>(); targetVehicle = tempTransform.GetComponent <VehicleEntity>(); tempBuildingMaterial = tempTransform.GetComponent <BuildingMaterial>(); if (tempBuildingMaterial != null) { targetBuilding = tempBuildingMaterial.BuildingEntity; } targetPosition = physicFunctions.GetRaycastPoint(tempCounter); if (targetPlayer != null && !targetPlayer.IsHideOrDead()) { foundTargetEntity = true; if (!getMouse) { SelectedEntity = targetPlayer; } if (getMouseDown) { SetTarget(targetPlayer, TargetActionType.Attack); } break; } else if (targetMonster != null && !targetMonster.IsHideOrDead()) { foundTargetEntity = true; if (!getMouse) { SelectedEntity = targetMonster; } if (getMouseDown) { SetTarget(targetMonster, TargetActionType.Attack); } break; } else if (targetNpc != null) { foundTargetEntity = true; if (!getMouse) { SelectedEntity = targetNpc; } if (getMouseDown) { SetTarget(targetNpc, TargetActionType.Activate); } break; } else if (targetItemDrop != null) { foundTargetEntity = true; if (!getMouse) { SelectedEntity = targetItemDrop; } if (getMouseDown) { SetTarget(targetItemDrop, TargetActionType.Activate); } break; } else if (targetHarvestable != null && !targetHarvestable.IsDead()) { foundTargetEntity = true; if (!getMouse) { SelectedEntity = targetHarvestable; } if (getMouseDown) { SetTarget(targetHarvestable, TargetActionType.Attack); } break; } else if (targetVehicle != null) { foundTargetEntity = true; if (!getMouse) { SelectedEntity = targetVehicle; } if (getMouseDown) { if (targetVehicle.ShouldBeAttackTarget) { SetTarget(targetVehicle, TargetActionType.Attack); } else { SetTarget(targetVehicle, TargetActionType.Activate); } } break; } else if (targetBuilding != null && !targetBuilding.IsDead()) { foundTargetEntity = true; if (!getMouse) { SelectedEntity = targetBuilding; } if (getMouseDown && targetBuilding.Activatable) { SetTarget(targetBuilding, TargetActionType.Activate); } if (getRMouseDown) { SetTarget(targetBuilding, TargetActionType.ViewOptions); } break; } } if (!foundTargetEntity) { SelectedEntity = null; } if (getMouse) { if (TargetEntity != null) { // Has target so move to target not the destination cantSetDestination = true; } else { // Close NPC dialog, when target changes HideNpcDialog(); } // Move to target if (!cantSetDestination && tempCount > 0) { // When moving, find target position which mouse click on targetPosition = physicFunctions.GetRaycastPoint(0); // When clicked on map (any non-collider position) // tempVector3 is come from FindClickObjects() // - Clear character target to make character stop doing actions // - Clear selected target to hide selected entity UIs // - Set target position to position where mouse clicked if (CurrentGameInstance.DimensionType == DimensionType.Dimension2D) { PlayerCharacterEntity.SetTargetEntity(null); tempVector3.z = 0; targetPosition = tempVector3; } destination = targetPosition; PlayerCharacterEntity.PointClickMovement(targetPosition.Value); } } else { // Mouse released, reset states if (TargetEntity == null) { cantSetDestination = false; } } }
protected virtual void UpdateInput() { if (GenericUtils.IsFocusInputField()) { return; } if (CacheGameplayCameraControls != null) { CacheGameplayCameraControls.updateRotationX = false; CacheGameplayCameraControls.updateRotationY = false; CacheGameplayCameraControls.updateRotation = InputManager.GetButton("CameraRotate"); } if (PlayerCharacterEntity.IsDead()) { return; } // If it's building something, don't allow to activate NPC/Warp/Pickup Item if (CurrentBuildingEntity == null) { // Activate nearby npcs / players / activable buildings if (InputManager.GetButtonDown("Activate")) { targetPlayer = null; if (activatingEntityDetector.players.Count > 0) { targetPlayer = activatingEntityDetector.players[0]; } targetNpc = null; if (activatingEntityDetector.npcs.Count > 0) { targetNpc = activatingEntityDetector.npcs[0]; } targetBuilding = null; if (activatingEntityDetector.buildings.Count > 0) { targetBuilding = activatingEntityDetector.buildings[0]; } // Priority Player -> Npc -> Buildings if (targetPlayer != null && CacheUISceneGameplay != null) { // Show dealing, invitation menu CacheUISceneGameplay.SetActivePlayerCharacter(targetPlayer); } else if (targetNpc != null) { // Talk to NPC PlayerCharacterEntity.RequestNpcActivate(targetNpc.ObjectId); } else if (targetBuilding != null) { // Use building ActivateBuilding(targetBuilding); } else { // Enter warp, For some warp portals that `warpImmediatelyWhenEnter` is FALSE PlayerCharacterEntity.RequestEnterWarp(); } } // Pick up nearby items if (InputManager.GetButtonDown("PickUpItem")) { targetItemDrop = null; if (itemDropEntityDetector.itemDrops.Count > 0) { targetItemDrop = itemDropEntityDetector.itemDrops[0]; } if (targetItemDrop != null) { PlayerCharacterEntity.RequestPickupItem(targetItemDrop.ObjectId); } } // Reload if (InputManager.GetButtonDown("Reload")) { // Reload ammo when press the button ReloadAmmo(); } // Find target to attack if (InputManager.GetButtonDown("FindEnemy")) { ++findingEnemyIndex; if (findingEnemyIndex < 0 || findingEnemyIndex >= enemyEntityDetector.characters.Count) { findingEnemyIndex = 0; } if (enemyEntityDetector.characters.Count > 0) { SetTarget(null); if (!enemyEntityDetector.characters[findingEnemyIndex].IsDead()) { SetTarget(enemyEntityDetector.characters[findingEnemyIndex]); if (SelectedEntity != null) { targetLookDirection = (SelectedEntity.CacheTransform.position - PlayerCharacterEntity.CacheTransform.position).normalized; } } } } // Auto reload if (PlayerCharacterEntity.EquipWeapons.rightHand.IsAmmoEmpty() || PlayerCharacterEntity.EquipWeapons.leftHand.IsAmmoEmpty()) { // Reload ammo when empty and not press any keys ReloadAmmo(); } } // Update enemy detecting radius to attack distance enemyEntityDetector.detectingRadius = PlayerCharacterEntity.GetAttackDistance(false) + lockAttackTargetDistance; // Update inputs UpdatePointClickInput(); UpdateWASDInput(); UpdateBuilding(); }
protected void UpdateInput() { if (GenericUtils.IsFocusInputField()) { return; } if (PlayerCharacterEntity.IsDead()) { return; } // If it's building something, don't allow to activate NPC/Warp/Pickup Item if (!ConstructingBuildingEntity) { // Activate nearby npcs / players / activable buildings if (InputManager.GetButtonDown("Activate")) { targetPlayer = null; if (ActivatableEntityDetector.players.Count > 0) { targetPlayer = ActivatableEntityDetector.players[0]; } targetNpc = null; if (ActivatableEntityDetector.npcs.Count > 0) { targetNpc = ActivatableEntityDetector.npcs[0]; } targetBuilding = null; if (ActivatableEntityDetector.buildings.Count > 0) { targetBuilding = ActivatableEntityDetector.buildings[0]; } targetVehicle = null; if (ActivatableEntityDetector.vehicles.Count > 0) { targetVehicle = ActivatableEntityDetector.vehicles[0]; } // Priority Player -> Npc -> Buildings if (targetPlayer && CacheUISceneGameplay) { // Show dealing, invitation menu SelectedEntity = targetPlayer; CacheUISceneGameplay.SetActivePlayerCharacter(targetPlayer); } else if (targetNpc) { // Talk to NPC SelectedEntity = targetNpc; PlayerCharacterEntity.RequestNpcActivate(targetNpc.ObjectId); } else if (targetBuilding) { // Use building SelectedEntity = targetBuilding; ActivateBuilding(targetBuilding); } else if (targetVehicle) { // Enter vehicle PlayerCharacterEntity.RequestEnterVehicle(targetVehicle.ObjectId); } else { // Enter warp, For some warp portals that `warpImmediatelyWhenEnter` is FALSE PlayerCharacterEntity.RequestEnterWarp(); } } // Pick up nearby items if (InputManager.GetButtonDown("PickUpItem")) { targetItemDrop = null; if (ItemDropEntityDetector.itemDrops.Count > 0) { targetItemDrop = ItemDropEntityDetector.itemDrops[0]; } if (targetItemDrop != null) { PlayerCharacterEntity.RequestPickupItem(targetItemDrop.ObjectId); } } // Reload if (InputManager.GetButtonDown("Reload")) { // Reload ammo when press the button ReloadAmmo(); } if (InputManager.GetButtonDown("ExitVehicle")) { // Exit vehicle PlayerCharacterEntity.RequestExitVehicle(); } if (InputManager.GetButtonDown("SwitchEquipWeaponSet")) { // Switch equip weapon set PlayerCharacterEntity.RequestSwitchEquipWeaponSet((byte)(PlayerCharacterEntity.EquipWeaponSet + 1)); } if (InputManager.GetButtonDown("Sprint")) { // Toggles sprint state isSprinting = !isSprinting; } // Auto reload if (PlayerCharacterEntity.EquipWeapons.rightHand.IsAmmoEmpty() || PlayerCharacterEntity.EquipWeapons.leftHand.IsAmmoEmpty()) { // Reload ammo when empty and not press any keys ReloadAmmo(); } } // Update inputs UpdateLookInput(); UpdateWASDInput(); // Set sprinting state PlayerCharacterEntity.SetExtraMovement(isSprinting ? ExtraMovementState.IsSprinting : ExtraMovementState.None); }
public override void UpdatePointClickInput() { // If it's building something, not allow point click movement if (CurrentBuildingEntity != null) { return; } if (controllerMode != PlayerCharacterControllerMode.PointClick && controllerMode != PlayerCharacterControllerMode.Both) { return; } getMouseDown = Input.GetMouseButtonDown(0); getMouseUp = Input.GetMouseButtonUp(0); getMouse = Input.GetMouseButton(0); isPointerOverUI = CacheUISceneGameplay != null && CacheUISceneGameplay.IsPointerOverUIObject(); if (isPointerOverUI) { return; } if (getMouseUp) { // Clear target when player release mouse button targetEntity = null; return; } if (getMouseDown) { targetEntity = null; int tempCount = FindClickObjects(out tempVector3); for (int tempCounter = 0; tempCounter < tempCount; ++tempCounter) { tempTransform = GetRaycastTransform(tempCounter); targetPlayer = tempTransform.GetComponent <BasePlayerCharacterEntity>(); targetMonster = tempTransform.GetComponent <BaseMonsterCharacterEntity>(); targetNpc = tempTransform.GetComponent <NpcEntity>(); targetItemDrop = tempTransform.GetComponent <ItemDropEntity>(); targetHarvestable = tempTransform.GetComponent <HarvestableEntity>(); BuildingMaterial buildingMaterial = tempTransform.GetComponent <BuildingMaterial>(); targetPosition = GetRaycastPoint(tempCounter); PlayerCharacterEntity.SetTargetEntity(null); lastNpcObjectId = 0; if (targetPlayer != null && !targetPlayer.IsDead()) { SetTarget(targetPlayer); break; } else if (targetMonster != null && !targetMonster.IsDead()) { SetTarget(targetMonster); break; } else if (targetNpc != null) { SetTarget(targetNpc); break; } else if (targetItemDrop != null) { SetTarget(targetItemDrop); break; } else if (targetHarvestable != null && !targetHarvestable.IsDead()) { SetTarget(targetHarvestable); break; } else if (buildingMaterial != null && buildingMaterial.buildingEntity != null && !buildingMaterial.buildingEntity.IsDead()) { SetTarget(buildingMaterial.buildingEntity); break; } } } if (getMouse) { // Close NPC dialog, when target changes if (CacheUISceneGameplay != null && CacheUISceneGameplay.uiNpcDialog != null) { CacheUISceneGameplay.uiNpcDialog.Hide(); } // Move to target if (targetEntity != null) { // Hide destination when target is object (not map ground) destination = null; PlayerCharacterEntity.SetTargetEntity(targetEntity); } else { // When moving, find target position which mouse click on int tempCount = FindClickObjects(out tempVector3); if (tempCount > 0) { targetPosition = GetRaycastPoint(0); // When clicked on map (any non-collider position) // tempVector3 is come from FindClickObjects() // - Clear character target to make character stop doing actions // - Clear selected target to hide selected entity UIs // - Set target position to position where mouse clicked if (gameInstance.DimensionType == DimensionType.Dimension2D) { PlayerCharacterEntity.SetTargetEntity(null); tempVector3.z = 0; targetPosition = tempVector3; } } destination = targetPosition; PlayerCharacterEntity.PointClickMovement(targetPosition.Value); } } }
protected override void Update() { if (PlayerCharacterEntity == null || !PlayerCharacterEntity.IsOwnerClient) { return; } base.Update(); UpdateLookAtTarget(); tempDeltaTime = Time.deltaTime; turnTimeCounter += tempDeltaTime; // Hide construction UI if (CurrentBuildingEntity == null) { if (CacheUISceneGameplay.uiConstructBuilding.IsVisible()) { CacheUISceneGameplay.uiConstructBuilding.Hide(); } } if (ActiveBuildingEntity == null) { if (CacheUISceneGameplay.uiCurrentBuilding.IsVisible()) { CacheUISceneGameplay.uiCurrentBuilding.Hide(); } } IsBlockController = CacheUISceneGameplay.IsBlockController(); // Lock cursor when not show UIs Cursor.lockState = !IsBlockController ? CursorLockMode.Locked : CursorLockMode.None; Cursor.visible = IsBlockController; CacheGameplayCameraControls.updateRotation = !IsBlockController; // Clear selected entity SelectedEntity = null; // Update crosshair (with states from last update) if (isDoingAction) { UpdateCrosshair(currentCrosshairSetting, currentCrosshairSetting.expandPerFrameWhileAttacking); } else if (movementState.HasFlag(MovementState.Forward) || movementState.HasFlag(MovementState.Backward) || movementState.HasFlag(MovementState.Left) || movementState.HasFlag(MovementState.Right) || movementState.HasFlag(MovementState.IsJump)) { UpdateCrosshair(currentCrosshairSetting, currentCrosshairSetting.expandPerFrameWhileMoving); } else { UpdateCrosshair(currentCrosshairSetting, -currentCrosshairSetting.shrinkPerFrame); } // Clear controlling states from last update isDoingAction = false; movementState = MovementState.None; UpdateActivatedWeaponAbility(tempDeltaTime); if (IsBlockController || GenericUtils.IsFocusInputField()) { mustReleaseFireKey = false; PlayerCharacterEntity.KeyMovement(Vector3.zero, MovementState.None); DeactivateWeaponAbility(); return; } // Find target character Ray ray = CacheGameplayCameraControls.CacheCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); Vector3 forward = CacheGameplayCameraControls.CacheCameraTransform.forward; Vector3 right = CacheGameplayCameraControls.CacheCameraTransform.right; float distanceFromOrigin = Vector3.Distance(ray.origin, PlayerCharacterEntity.CacheTransform.position); float aimDistance = distanceFromOrigin; // Calculating aim distance, also read attack inputs here // Attack inputs will be used to calculate attack distance if (CurrentBuildingEntity == null) { // Attack with right hand weapon tempPressAttackRight = InputManager.GetButton("Fire1"); if (weaponAbility == null && leftHandWeapon != null) { // Attack with left hand weapon if left hand weapon not empty tempPressAttackLeft = InputManager.GetButton("Fire2"); } else if (weaponAbility != null) { // Use weapon ability if it can tempPressWeaponAbility = InputManager.GetButtonDown("Fire2"); } // Is left hand attack when not attacking with right hand // So priority is right > left isLeftHandAttacking = !tempPressAttackRight && tempPressAttackLeft; // Calculate aim distance by skill or weapon if (queueSkill != null && queueSkill.IsAttack()) { // Increase aim distance by skill attack distance aimDistance += PlayerCharacterEntity.GetSkillAttackDistance(queueSkill, isLeftHandAttacking); } else { // Increase aim distance by attack distance aimDistance += PlayerCharacterEntity.GetAttackDistance(isLeftHandAttacking); } } actionLookDirection = aimPosition = ray.origin + ray.direction * aimDistance; actionLookDirection.y = PlayerCharacterEntity.CacheTransform.position.y; actionLookDirection = actionLookDirection - PlayerCharacterEntity.CacheTransform.position; actionLookDirection.Normalize(); // Prepare variables to find nearest raycasted hit point float tempDistance; float tempNearestDistance = float.MaxValue; // Find for enemy character if (CurrentBuildingEntity == null) { int tempCount = Physics.RaycastNonAlloc(ray, raycasts, aimDistance); for (int tempCounter = 0; tempCounter < tempCount; ++tempCounter) { tempHitInfo = raycasts[tempCounter]; tempEntity = tempHitInfo.collider.GetComponent <BaseGameEntity>(); // Find building entity from building material if (tempEntity == null) { tempBuildingMaterial = tempHitInfo.collider.GetComponent <BuildingMaterial>(); if (tempBuildingMaterial != null) { tempEntity = tempBuildingMaterial.buildingEntity; } } if (tempEntity == null || tempEntity == PlayerCharacterEntity) { continue; } // Target must be alive if (tempEntity is IDamageableEntity && (tempEntity as IDamageableEntity).IsDead()) { continue; } // Target must be in front of player character if (!PlayerCharacterEntity.IsPositionInFov(15f, tempEntity.CacheTransform.position, forward)) { continue; } // Set aim position and found target tempDistance = Vector3.Distance(CacheGameplayCameraControls.CacheCameraTransform.position, tempHitInfo.point); if (tempDistance < tempNearestDistance) { tempNearestDistance = tempDistance; aimPosition = tempHitInfo.point; if (tempEntity != null) { SelectedEntity = tempEntity; } } } // Show target hp/mp CacheUISceneGameplay.SetTargetEntity(SelectedEntity); } else { // Clear area before next find CurrentBuildingEntity.buildingArea = null; // Find for position to construction building bool foundSnapBuildPosition = false; int tempCount = Physics.RaycastNonAlloc(ray, raycasts, gameInstance.buildDistance); BuildingArea buildingArea = null; for (int tempCounter = 0; tempCounter < tempCount; ++tempCounter) { tempHitInfo = raycasts[tempCounter]; tempEntity = tempHitInfo.collider.GetComponentInParent <BuildingEntity>(); if (tempEntity == null || tempEntity == CurrentBuildingEntity) { continue; } buildingArea = tempHitInfo.transform.GetComponent <BuildingArea>(); if (buildingArea == null || (buildingArea.buildingEntity != null && buildingArea.buildingEntity == CurrentBuildingEntity) || !CurrentBuildingEntity.buildingType.Equals(buildingArea.buildingType)) { continue; } // Set aim position tempDistance = Vector3.Distance(CacheGameplayCameraControls.CacheCameraTransform.position, tempHitInfo.point); if (tempDistance < tempNearestDistance) { aimPosition = tempHitInfo.point; CurrentBuildingEntity.buildingArea = buildingArea; if (buildingArea.snapBuildingObject) { foundSnapBuildPosition = true; break; } } } // Update building position if (!foundSnapBuildPosition) { CurrentBuildingEntity.CacheTransform.position = aimPosition; // Rotate to camera Vector3 direction = (aimPosition - CacheGameplayCameraControls.CacheCameraTransform.position).normalized; direction.y = 0; CurrentBuildingEntity.transform.rotation = Quaternion.LookRotation(direction); } } // If mobile platforms, don't receive input raw to make it smooth bool raw = !InputManager.useMobileInputOnNonMobile && !Application.isMobilePlatform; Vector3 moveDirection = Vector3.zero; forward.y = 0f; right.y = 0f; forward.Normalize(); right.Normalize(); float inputV = InputManager.GetAxis("Vertical", raw); float inputH = InputManager.GetAxis("Horizontal", raw); moveDirection += forward * inputV; moveDirection += right * inputH; // Set movement state by inputs switch (mode) { case Mode.Adventure: if (inputV > 0.5f || inputV < -0.5f || inputH > 0.5f || inputH < -0.5f) { movementState = MovementState.Forward; } moveLookDirection = moveDirection; break; case Mode.Combat: moveDirection += forward * inputV; moveDirection += right * inputH; if (inputV > 0.5f) { movementState |= MovementState.Forward; } else if (inputV < -0.5f) { movementState |= MovementState.Backward; } if (inputH > 0.5f) { movementState |= MovementState.Right; } else if (inputH < -0.5f) { movementState |= MovementState.Left; } moveLookDirection = actionLookDirection; break; } // normalize input if it exceeds 1 in combined length: if (moveDirection.sqrMagnitude > 1) { moveDirection.Normalize(); } if (CurrentBuildingEntity != null) { mustReleaseFireKey = false; // Building tempPressAttackRight = InputManager.GetButtonUp("Fire1"); if (tempPressAttackRight) { if (showConfirmConstructionUI) { // Show confirm UI if (!CacheUISceneGameplay.uiConstructBuilding.IsVisible()) { CacheUISceneGameplay.uiConstructBuilding.Show(); } } else { // Build when click ConfirmBuild(); } } else { // Update move direction if (moveDirection.magnitude != 0f) { targetLookDirection = moveLookDirection; } } } else { // Have to release fire key, then check press fire key later on next frame if (mustReleaseFireKey) { tempPressAttackRight = false; tempPressAttackLeft = false; if (!isLeftHandAttacking && (InputManager.GetButtonUp("Fire1") || !InputManager.GetButton("Fire1"))) { mustReleaseFireKey = false; } if (isLeftHandAttacking && (InputManager.GetButtonUp("Fire2") || !InputManager.GetButton("Fire2"))) { mustReleaseFireKey = false; } } // Not building so it is attacking tempPressActivate = InputManager.GetButtonDown("Activate"); tempPressPickupItem = InputManager.GetButtonDown("PickUpItem"); tempPressReload = InputManager.GetButtonDown("Reload"); if (queueSkill != null || tempPressAttackRight || tempPressAttackLeft || tempPressActivate || PlayerCharacterEntity.IsPlayingActionAnimation()) { // Find forward character / npc / building / warp entity from camera center targetPlayer = null; targetNpc = null; targetBuilding = null; if (tempPressActivate && !tempPressAttackRight && !tempPressAttackLeft) { if (SelectedEntity is BasePlayerCharacterEntity) { targetPlayer = SelectedEntity as BasePlayerCharacterEntity; } if (SelectedEntity is NpcEntity) { targetNpc = SelectedEntity as NpcEntity; } if (SelectedEntity is BuildingEntity) { targetBuilding = SelectedEntity as BuildingEntity; } } // While attacking turn to camera forward tempCalculateAngle = Vector3.Angle(PlayerCharacterEntity.CacheTransform.forward, actionLookDirection); if (tempCalculateAngle > 15f) { if (queueSkill != null && queueSkill.IsAttack()) { turningState = TurningState.UseSkill; } else if (tempPressAttackRight || tempPressAttackLeft) { turningState = TurningState.Attack; } else if (tempPressActivate) { turningState = TurningState.Activate; } turnTimeCounter = ((180f - tempCalculateAngle) / 180f) * turnToTargetDuration; targetLookDirection = actionLookDirection; // Set movement state by inputs if (inputV > 0.5f) { movementState |= MovementState.Forward; } else if (inputV < -0.5f) { movementState |= MovementState.Backward; } if (inputH > 0.5f) { movementState |= MovementState.Right; } else if (inputH < -0.5f) { movementState |= MovementState.Left; } } else { // Attack immediately if character already look at target if (queueSkill != null && queueSkill.IsAttack()) { UseSkill(isLeftHandAttacking, aimPosition); isDoingAction = true; } else if (tempPressAttackRight || tempPressAttackLeft) { Attack(isLeftHandAttacking); isDoingAction = true; } else if (tempPressActivate) { Activate(); } } // If skill is not attack skill, use it immediately if (queueSkill != null && !queueSkill.IsAttack()) { UseSkill(false); } queueSkill = null; } else if (tempPressWeaponAbility) { switch (weaponAbilityState) { case WeaponAbilityState.Activated: case WeaponAbilityState.Activating: DeactivateWeaponAbility(); break; case WeaponAbilityState.Deactivated: case WeaponAbilityState.Deactivating: ActivateWeaponAbility(); break; } } else if (tempPressPickupItem) { // Find for item to pick up if (SelectedEntity != null) { PlayerCharacterEntity.RequestPickupItem((SelectedEntity as ItemDropEntity).ObjectId); } } else if (tempPressReload) { // Reload ammo when press the button ReloadAmmo(); } else { // Update move direction if (moveDirection.magnitude != 0f) { targetLookDirection = moveLookDirection; } } // Setup releasing state if (tempPressAttackRight && rightHandWeapon != null && rightHandWeapon.fireType == FireType.SingleFire) { // The weapon's fire mode is single fire, so player have to release fire key for next fire mustReleaseFireKey = true; } else if (tempPressAttackLeft && leftHandWeapon != null && leftHandWeapon.fireType == FireType.SingleFire) { // The weapon's fire mode is single fire, so player have to release fire key for next fire mustReleaseFireKey = true; } // Auto reload if (!tempPressAttackRight && !tempPressAttackLeft && !tempPressReload && (PlayerCharacterEntity.EquipWeapons.rightHand.IsAmmoEmpty() || PlayerCharacterEntity.EquipWeapons.leftHand.IsAmmoEmpty())) { // Reload ammo when empty and not press any keys ReloadAmmo(); } } SetAimPosition(aimPosition); // Hide Npc UIs when move if (moveDirection.magnitude != 0f) { HideNpcDialogs(); PlayerCharacterEntity.StopMove(); PlayerCharacterEntity.SetTargetEntity(null); } // If jumping add jump state if (InputManager.GetButtonDown("Jump")) { movementState |= MovementState.IsJump; } PlayerCharacterEntity.KeyMovement(moveDirection, movementState); }
protected virtual void UpdatePointClickInput() { // If it's building something, not allow point click movement if (CurrentBuildingEntity != null) { return; } getMouseDown = Input.GetMouseButtonDown(0); getMouseUp = Input.GetMouseButtonUp(0); getMouse = Input.GetMouseButton(0); if (getMouseDown) { isMouseDragOrHoldOrOverUI = false; mouseDownTime = Time.unscaledTime; mouseDownPosition = Input.mousePosition; } isPointerOverUI = CacheUISceneGameplay != null && CacheUISceneGameplay.IsPointerOverUIObject(); isMouseDragDetected = (Input.mousePosition - mouseDownPosition).magnitude > DETECT_MOUSE_DRAG_DISTANCE; isMouseHoldDetected = Time.unscaledTime - mouseDownTime > DETECT_MOUSE_HOLD_DURATION; isMouseHoldAndNotDrag = !isMouseDragDetected && isMouseHoldDetected; if (!isMouseDragOrHoldOrOverUI && (isMouseDragDetected || isMouseHoldDetected || isPointerOverUI)) { isMouseDragOrHoldOrOverUI = true; } if (!isPointerOverUI && (getMouse || getMouseUp)) { targetEntity = null; targetPosition = null; Vector3? tempMapPosition = null; float tempHighestY = float.MinValue; BuildingMaterial tempBuildingMaterial; bool mouseUpOnTarget = getMouseUp && !isMouseDragOrHoldOrOverUI && (controllerMode == PlayerCharacterControllerMode.PointClick || controllerMode == PlayerCharacterControllerMode.Both); int tempCount = FindClickObjects(out tempVector3); for (int tempCounter = 0; tempCounter < tempCount; ++tempCounter) { tempTransform = GetRaycastTransform(tempCounter); // When holding on target, or already enter edit building mode if (isMouseHoldAndNotDrag || IsEditingBuilding) { targetBuilding = null; tempBuildingMaterial = tempTransform.GetComponent <BuildingMaterial>(); if (tempBuildingMaterial != null && tempBuildingMaterial.buildingEntity != null) { targetBuilding = tempBuildingMaterial.buildingEntity; } if (targetBuilding && !targetBuilding.IsDead()) { IsEditingBuilding = true; SetTarget(targetBuilding); tempMapPosition = null; break; } } // When clicking on target else if (mouseUpOnTarget) { targetPlayer = tempTransform.GetComponent <BasePlayerCharacterEntity>(); targetMonster = tempTransform.GetComponent <BaseMonsterCharacterEntity>(); targetNpc = tempTransform.GetComponent <NpcEntity>(); targetItemDrop = tempTransform.GetComponent <ItemDropEntity>(); targetHarvestable = tempTransform.GetComponent <HarvestableEntity>(); targetBuilding = null; tempBuildingMaterial = tempTransform.GetComponent <BuildingMaterial>(); if (tempBuildingMaterial != null && tempBuildingMaterial.buildingEntity != null) { targetBuilding = tempBuildingMaterial.buildingEntity; } PlayerCharacterEntity.SetTargetEntity(null); lastNpcObjectId = 0; if (targetPlayer != null && !targetPlayer.IsDead()) { SetTarget(targetPlayer); tempMapPosition = null; break; } else if (targetMonster != null && !targetMonster.IsDead()) { SetTarget(targetMonster); tempMapPosition = null; break; } else if (targetNpc != null) { SetTarget(targetNpc); tempMapPosition = null; break; } else if (targetItemDrop != null) { SetTarget(targetItemDrop); tempMapPosition = null; break; } else if (targetHarvestable != null && !targetHarvestable.IsDead()) { SetTarget(targetHarvestable); tempMapPosition = null; break; } else if (targetBuilding && !targetBuilding.IsDead() && targetBuilding.Activatable) { IsEditingBuilding = false; SetTarget(targetBuilding); tempMapPosition = null; break; } else if (!GetRaycastIsTrigger(tempCounter)) { // Set clicked map position, it will be used if no activating entity found tempMapPosition = GetRaycastPoint(tempCounter); if (tempMapPosition.Value.y > tempHighestY) { tempHighestY = tempMapPosition.Value.y; } } } } // When clicked on map (Not touch any game entity) // - Clear selected target to hide selected entity UIs // - Set target position to position where mouse clicked if (tempMapPosition.HasValue) { SelectedEntity = null; targetPosition = tempMapPosition.Value; } // When clicked on map (any non-collider position) // tempVector3 is come from FindClickObjects() // - Clear character target to make character stop doing actions // - Clear selected target to hide selected entity UIs // - Set target position to position where mouse clicked if (gameInstance.DimensionType == DimensionType.Dimension2D && mouseUpOnTarget && tempCount == 0) { PlayerCharacterEntity.SetTargetEntity(null); SelectedEntity = null; tempVector3.z = 0; targetPosition = tempVector3; } // If Found target, do something if (targetPosition.HasValue) { // Close NPC dialog, when target changes HideNpcDialogs(); queueUsingSkill = null; // Move to target, will hide destination when target is object if (targetEntity != null) { destination = null; } else { destination = targetPosition.Value; PlayerCharacterEntity.PointClickMovement(targetPosition.Value); } } } }
protected void UpdatePointClickInput() { var isPointerOverUI = CacheUISceneGameplay != null && CacheUISceneGameplay.IsPointerOverUIObject(); if (Input.GetMouseButtonDown(0)) { isMouseDragOrHoldOrOverUI = false; mouseDownTime = Time.unscaledTime; mouseDownPosition = Input.mousePosition; } var isMouseDragDetected = (Input.mousePosition - mouseDownPosition).magnitude > DETECT_MOUSE_DRAG_DISTANCE; var isMouseHoldDetected = Time.unscaledTime - mouseDownTime > DETECT_MOUSE_HOLD_DURATION; if (!isMouseDragOrHoldOrOverUI && (isMouseDragDetected || isMouseHoldDetected || isPointerOverUI)) { isMouseDragOrHoldOrOverUI = true; } if (!isPointerOverUI && Input.GetMouseButtonUp(0) && !isMouseDragOrHoldOrOverUI) { var targetCamera = CacheGameplayCameraControls != null ? CacheGameplayCameraControls.targetCamera : Camera.main; CharacterEntity.SetTargetEntity(null); LiteNetLibIdentity targetIdentity = null; Vector3? targetPosition = null; var layerMask = 0; if (gameInstance.nonTargetingLayers.Length > 0) { foreach (var nonTargetingLayer in gameInstance.nonTargetingLayers) { layerMask = layerMask | ~(nonTargetingLayer.Mask); } } else { layerMask = -1; } RaycastHit[] hits = Physics.RaycastAll(targetCamera.ScreenPointToRay(Input.mousePosition), 100f, layerMask); foreach (var hit in hits) { var hitTransform = hit.transform; targetPosition = hit.point; var playerEntity = hitTransform.GetComponent <PlayerCharacterEntity>(); var monsterEntity = hitTransform.GetComponent <MonsterCharacterEntity>(); var npcEntity = hitTransform.GetComponent <NpcEntity>(); var itemDropEntity = hitTransform.GetComponent <ItemDropEntity>(); CharacterEntity.SetTargetEntity(null); if (playerEntity != null && playerEntity.CurrentHp > 0) { targetPosition = playerEntity.CacheTransform.position; targetIdentity = playerEntity.Identity; CharacterEntity.SetTargetEntity(playerEntity); break; } else if (monsterEntity != null && monsterEntity.CurrentHp > 0) { targetPosition = monsterEntity.CacheTransform.position; targetIdentity = monsterEntity.Identity; CharacterEntity.SetTargetEntity(monsterEntity); break; } else if (npcEntity != null) { targetPosition = npcEntity.CacheTransform.position; targetIdentity = npcEntity.Identity; CharacterEntity.SetTargetEntity(npcEntity); break; } else if (itemDropEntity != null) { targetPosition = itemDropEntity.CacheTransform.position; targetIdentity = itemDropEntity.Identity; CharacterEntity.SetTargetEntity(itemDropEntity); break; } } if (targetPosition.HasValue) { if (CacheUISceneGameplay != null && CacheUISceneGameplay.uiNpcDialog != null) { CacheUISceneGameplay.uiNpcDialog.Hide(); } queueUsingSkill = null; if (targetIdentity != null) { destination = null; } else { destination = targetPosition.Value; CharacterEntity.PointClickMovement(targetPosition.Value); } } } }
protected void UpdateLookInput() { bool foundTargetEntity = false; bool isMobile = InputManager.useMobileInputOnNonMobile || Application.isMobilePlatform; Vector2 lookDirection; if (isMobile) { // Turn character by joystick lookDirection = new Vector2(InputManager.GetAxis("Mouse X", false), InputManager.GetAxis("Mouse Y", false)); Transform tempTransform; IGameEntity tempGameEntity; Vector3 tempTargetPosition; int pickedCount; if (GameInstance.Singleton.DimensionType == DimensionType.Dimension2D) { pickedCount = physicFunctions.Raycast(PlayerCharacterEntity.MeleeDamageTransform.position, lookDirection, 100f, Physics.DefaultRaycastLayers); } else { pickedCount = physicFunctions.Raycast(PlayerCharacterEntity.MeleeDamageTransform.position, new Vector3(lookDirection.x, 0, lookDirection.y), 100f, Physics.DefaultRaycastLayers); } for (int i = pickedCount - 1; i >= 0; --i) { aimTargetPosition = physicFunctions.GetRaycastPoint(i); tempTransform = physicFunctions.GetRaycastTransform(i); tempGameEntity = tempTransform.GetComponent <IGameEntity>(); if (tempGameEntity != null) { foundTargetEntity = true; CacheUISceneGameplay.SetTargetEntity(tempGameEntity.Entity); SelectedEntity = tempGameEntity.Entity; if (tempGameEntity.Entity != PlayerCharacterEntity.Entity) { // Turn to pointing entity, so find pointing target position and set look direction if (!doNotTurnToPointingEntity) { // Find target position if (tempGameEntity is IDamageableEntity) { tempTargetPosition = (tempGameEntity as IDamageableEntity).OpponentAimTransform.position; } else { tempTargetPosition = tempGameEntity.GetTransform().position; } // Set look direction if (GameInstance.Singleton.DimensionType == DimensionType.Dimension2D) { lookDirection = (tempTargetPosition - CacheTransform.position).normalized; } else { lookDirection = (XZ(tempTargetPosition) - XZ(CacheTransform.position)).normalized; } } } break; } } } else { // Turn character follow cursor lookDirection = (InputManager.MousePosition() - new Vector3(Screen.width, Screen.height) * 0.5f).normalized; // Pick on object by mouse position Transform tempTransform; IGameEntity tempGameEntity; Vector3 tempTargetPosition; int pickedCount = physicFunctions.RaycastPickObjects(CacheGameplayCamera, InputManager.MousePosition(), Physics.DefaultRaycastLayers, 100f, out _); for (int i = pickedCount - 1; i >= 0; --i) { aimTargetPosition = physicFunctions.GetRaycastPoint(i); tempTransform = physicFunctions.GetRaycastTransform(i); tempGameEntity = tempTransform.GetComponent <IGameEntity>(); if (tempGameEntity != null) { foundTargetEntity = true; CacheUISceneGameplay.SetTargetEntity(tempGameEntity.Entity); SelectedEntity = tempGameEntity.Entity; if (tempGameEntity.Entity != PlayerCharacterEntity.Entity) { // Turn to pointing entity, so find pointing target position and set look direction if (!doNotTurnToPointingEntity) { // Find target position if (tempGameEntity is IDamageableEntity) { tempTargetPosition = (tempGameEntity as IDamageableEntity).OpponentAimTransform.position; } else { tempTargetPosition = tempGameEntity.GetTransform().position; } // Set look direction if (GameInstance.Singleton.DimensionType == DimensionType.Dimension2D) { lookDirection = (tempTargetPosition - CacheTransform.position).normalized; } else { lookDirection = (XZ(tempTargetPosition) - XZ(CacheTransform.position)).normalized; } } } break; } } } if (!foundTargetEntity) { CacheUISceneGameplay.SetTargetEntity(null); SelectedEntity = null; } // Set aim position if (setAimPositionToRaycastHitPoint) { PlayerCharacterEntity.AimPosition = PlayerCharacterEntity.GetAttackAimPosition(ref isLeftHandAttacking, aimTargetPosition); if (GameInstance.Singleton.DimensionType == DimensionType.Dimension3D) { Quaternion aimRotation = Quaternion.LookRotation(PlayerCharacterEntity.AimPosition.direction); PlayerCharacterEntity.Pitch = aimRotation.eulerAngles.x; } } else { PlayerCharacterEntity.AimPosition = PlayerCharacterEntity.GetAttackAimPosition(ref isLeftHandAttacking); } // Turn character if (lookDirection.sqrMagnitude > 0f) { if (GameInstance.Singleton.DimensionType == DimensionType.Dimension2D) { PlayerCharacterEntity.SetLookRotation(Quaternion.LookRotation(lookDirection)); } else { PlayerCharacterEntity.SetLookRotation(Quaternion.LookRotation(new Vector3(lookDirection.x, 0, lookDirection.y))); } } }
public virtual void TabTargetUpdatePointClickInput() { if (controllerMode == PlayerCharacterControllerMode.WASD) { return; } // If it's building something, not allow point click movement if (ConstructingBuildingEntity != null) { return; } // If it's aiming skills, not allow point click movement if (UICharacterHotkeys.UsingHotkey != null) { return; } getMouseDown = Input.GetMouseButtonDown(0); getMouseUp = Input.GetMouseButtonUp(0); getMouse = Input.GetMouseButton(0); if (getMouseDown) { isMouseDragOrHoldOrOverUI = false; mouseDownTime = Time.unscaledTime; mouseDownPosition = Input.mousePosition; } // Read inputs isPointerOverUI = CacheUISceneGameplay.IsPointerOverUIObject(); isMouseDragDetected = (Input.mousePosition - mouseDownPosition).sqrMagnitude > DETECT_MOUSE_DRAG_DISTANCE_SQUARED; isMouseHoldDetected = Time.unscaledTime - mouseDownTime > DETECT_MOUSE_HOLD_DURATION; isMouseHoldAndNotDrag = !isMouseDragDetected && isMouseHoldDetected; if (!isMouseDragOrHoldOrOverUI && (isMouseDragDetected || isMouseHoldDetected || isPointerOverUI)) { // Detected mouse dragging or hold on an UIs isMouseDragOrHoldOrOverUI = true; } // Will set move target when pointer isn't point on an UIs if (!isPointerOverUI && (getMouse || getMouseUp)) { didActionOnTarget = false; // Prepare temp variables Transform tempTransform; Vector3 tempVector3; bool tempHasMapPosition = false; Vector3 tempMapPosition = Vector3.zero; BuildingMaterial tempBuildingMaterial; // If mouse up while cursor point to target (character, item, npc and so on) bool mouseUpOnTarget = getMouseUp && !isMouseDragOrHoldOrOverUI; int tempCount = TabTargetFindClickObjects(out tempVector3); for (int tempCounter = 0; tempCounter < tempCount; ++tempCounter) { tempTransform = physicFunctions.GetRaycastTransform(tempCounter); // When holding on target, or already enter edit building mode if (isMouseHoldAndNotDrag) { targetBuilding = null; tempBuildingMaterial = tempTransform.GetComponent <BuildingMaterial>(); if (tempBuildingMaterial != null) { targetBuilding = tempBuildingMaterial.BuildingEntity; } if (targetBuilding && !targetBuilding.IsDead()) { Targeting.Target(targetBuilding.gameObject); break; } } else if (mouseUpOnTarget) { isAutoAttacking = false; if (tempTransform.gameObject.GetComponent <BaseGameEntity>() == CacheSelectedTarget) { Activate(); } else { Targeting.UnHighlightPotentialTarget(); Targeting.Target(tempTransform.gameObject); } } // End mouseUpOnTarget } // When clicked on map (Not touch any game entity) // - Clear selected target to hide selected entity UIs // - Set target position to position where mouse clicked if (tempHasMapPosition) { targetPosition = tempMapPosition; } // When clicked on map (any non-collider position) // tempVector3 is come from FindClickObjects() // - Clear character target to make character stop doing actions // - Clear selected target to hide selected entity UIs // - Set target position to position where mouse clicked if (CurrentGameInstance.DimensionType == DimensionType.Dimension2D && mouseUpOnTarget && tempCount == 0) { ClearTarget(); tempVector3.z = 0; targetPosition = tempVector3; } // Found ground position if (targetPosition.HasValue) { // Close NPC dialog, when target changes HideNpcDialog(); ClearQueueUsingSkill(); isFollowingTarget = false; if (PlayerCharacterEntity.IsPlayingActionAnimation()) { if (pointClickInterruptCastingSkill) { PlayerCharacterEntity.CallServerSkillCastingInterrupt(); } } else { OnPointClickOnGround(targetPosition.Value); } } } }
public virtual void TabTargetUpdateInput() { bool isFocusInputField = GenericUtils.IsFocusInputField(); bool isPointerOverUIObject = CacheUISceneGameplay.IsPointerOverUIObject(); if (CacheGameplayCameraControls != null) { CacheGameplayCameraControls.updateRotationX = false; CacheGameplayCameraControls.updateRotationY = false; CacheGameplayCameraControls.updateRotation = !isFocusInputField && !isPointerOverUIObject && InputManager.GetButton("CameraRotate"); CacheGameplayCameraControls.updateZoom = !isFocusInputField && !isPointerOverUIObject; } if (isFocusInputField) { return; } if (PlayerCharacterEntity.IsDead()) { return; } // If it's building something, don't allow to activate NPC/Warp/Pickup Item if (ConstructingBuildingEntity == null) { Targeting.HandleTargeting(); if (InputManager.GetButtonDown("PickUpItem")) { PickUpItem(); } if (InputManager.GetButtonDown("Reload")) { ReloadAmmo(); } if (InputManager.GetButtonDown("ExitVehicle")) { PlayerCharacterEntity.CallServerExitVehicle(); } if (InputManager.GetButtonDown("SwitchEquipWeaponSet")) { PlayerCharacterEntity.CallServerSwitchEquipWeaponSet((byte)(PlayerCharacterEntity.EquipWeaponSet + 1)); } if (InputManager.GetButtonDown("Sprint")) { isSprinting = !isSprinting; } // Auto reload if (PlayerCharacterEntity.EquipWeapons.rightHand.IsAmmoEmpty() || PlayerCharacterEntity.EquipWeapons.leftHand.IsAmmoEmpty()) { ReloadAmmo(); } } // Update enemy detecting radius to attack distance EnemyEntityDetector.detectingRadius = Mathf.Max(PlayerCharacterEntity.GetAttackDistance(false), wasdClearTargetDistance); // Update inputs TabTargetUpdateQueuedSkill(); TabTargetUpdatePointClickInput(); TabTargetUpdateWASDInput(); // Set sprinting state PlayerCharacterEntity.SetExtraMovement(isSprinting ? ExtraMovementState.IsSprinting : ExtraMovementState.None); }