public override void UseHotkey(int hotkeyIndex) { if (hotkeyIndex < 0 || hotkeyIndex >= PlayerCharacterEntity.Hotkeys.Count) { return; } CancelBuild(); buildingItemIndex = -1; CurrentBuildingEntity = null; CharacterHotkey hotkey = PlayerCharacterEntity.Hotkeys[hotkeyIndex]; Skill skill = hotkey.GetSkill(); if (skill != null) { short skillLevel; if (PlayerCharacterEntity.CacheSkills.TryGetValue(skill, out skillLevel)) { BaseCharacterEntity attackingCharacter; if (TryGetAttackingCharacter(out attackingCharacter)) { // If attacking any character, will use skill later queueUsingSkill = new UsingSkillData(null, skill.DataId); } else if (skill.CanUse(PlayerCharacterEntity, skillLevel)) { // If not attacking any character, use skill immediately if (skill.IsAttack()) { if (IsLockTarget()) { // If attacking any character, will use skill later queueUsingSkill = new UsingSkillData(null, skill.DataId); if (SelectedEntity != null && SelectedEntity is BaseCharacterEntity) { // Attacking selected target PlayerCharacterEntity.SetTargetEntity(SelectedEntity); } else { // Attacking nearest target BaseCharacterEntity nearestTarget = PlayerCharacterEntity.FindNearestAliveCharacter <BaseCharacterEntity>(PlayerCharacterEntity.GetSkillAttackDistance(skill, isLeftHandAttacking) + lockAttackTargetDistance, false, true, false); if (nearestTarget != null) { PlayerCharacterEntity.SetTargetEntity(nearestTarget); } } } else { // Not lock target, use it immediately destination = null; PlayerCharacterEntity.StopMove(); PlayerCharacterEntity.RequestUseSkill(skill.DataId, isLeftHandAttacking); isLeftHandAttacking = !isLeftHandAttacking; } } else { // This is not attack skill, use it immediately destination = null; PlayerCharacterEntity.StopMove(); PlayerCharacterEntity.RequestUseSkill(skill.DataId, isLeftHandAttacking); } } } } Item item = hotkey.GetItem(); if (item != null) { int itemIndex = PlayerCharacterEntity.IndexOfNonEquipItem(item.DataId); if (itemIndex >= 0) { if (item.IsEquipment()) { RequestEquipItem((short)itemIndex); } else if (item.IsPotion() || item.IsPet()) { RequestUseItem((short)itemIndex); } else if (item.IsBuilding()) { destination = null; PlayerCharacterEntity.StopMove(); buildingItemIndex = itemIndex; CurrentBuildingEntity = Instantiate(item.buildingEntity); CurrentBuildingEntity.SetupAsBuildMode(); CurrentBuildingEntity.CacheTransform.parent = null; FindAndSetBuildingAreaFromCharacterDirection(); } } } }
public override void UseHotkey(int hotkeyIndex) { if (hotkeyIndex < 0 || hotkeyIndex >= PlayerCharacterEntity.Hotkeys.Count) { return; } CancelBuild(); buildingItemIndex = -1; currentBuildingEntity = null; var hotkey = PlayerCharacterEntity.Hotkeys[hotkeyIndex]; var skill = hotkey.GetSkill(); if (skill != null) { var skillIndex = PlayerCharacterEntity.IndexOfSkill(skill.DataId); if (skillIndex >= 0) { BaseCharacterEntity attackingCharacter; if (TryGetAttackingCharacter(out attackingCharacter)) { // If attacking any character, will use skill later queueUsingSkill = new UsingSkillData(null, skill.DataId); } else if (PlayerCharacterEntity.Skills[skillIndex].CanUse(PlayerCharacterEntity)) { // If not attacking any character, use skill immediately if (skill.IsAttack() && IsLockTarget()) { // If attacking any character, will use skill later queueUsingSkill = new UsingSkillData(null, skill.DataId); if (selectedTarget != null && selectedTarget is BaseCharacterEntity) { // Attacking selected target PlayerCharacterEntity.SetTargetEntity(selectedTarget); } else { // Attacking nearest target var nearestTarget = PlayerCharacterEntity.FindNearestAliveCharacter <BaseCharacterEntity>(PlayerCharacterEntity.GetSkillAttackDistance(skill) + lockAttackTargetDistance, false, true, false); if (nearestTarget != null) { PlayerCharacterEntity.SetTargetEntity(nearestTarget); } } } else { destination = null; PlayerCharacterEntity.StopMove(); RequestUseSkill(CharacterTransform.position, skill.DataId); } } } } var item = hotkey.GetItem(); if (item != null) { var itemIndex = PlayerCharacterEntity.IndexOfNonEquipItem(item.DataId); if (itemIndex >= 0) { if (item.IsEquipment()) { RequestEquipItem((ushort)itemIndex); } else if (item.IsPotion() || item.IsPet()) { RequestUseItem((ushort)itemIndex); } else if (item.IsBuilding()) { destination = null; PlayerCharacterEntity.StopMove(); buildingItemIndex = itemIndex; currentBuildingEntity = Instantiate(item.buildingEntity); currentBuildingEntity.SetupAsBuildMode(); currentBuildingEntity.CacheTransform.parent = null; FindAndSetBuildingAreaFromCharacterDirection(); } } } }
protected virtual void UpdateWASDInput() { if (controllerMode != PlayerCharacterControllerMode.WASD && controllerMode != PlayerCharacterControllerMode.Both) { return; } // 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)); if (moveDirection.magnitude != 0f) { HideNpcDialogs(); queueUsingSkill = null; FindAndSetBuildingAreaFromCharacterDirection(); } // For WASD mode, Using skill when player pressed hotkey if (queueUsingSkill.HasValue) { UsingSkillData queueUsingSkillValue = queueUsingSkill.Value; destination = null; PlayerCharacterEntity.StopMove(); Skill skill = null; if (GameInstance.Skills.TryGetValue(queueUsingSkillValue.dataId, out skill) && skill != null) { if (skill.IsAttack()) { BaseCharacterEntity targetEntity; if (TryGetSelectedTargetAsAttackingCharacter(out targetEntity)) { SetTarget(targetEntity); } if (wasdLockAttackTarget && !TryGetAttackingCharacter(out targetEntity)) { BaseCharacterEntity nearestTarget = PlayerCharacterEntity.FindNearestAliveCharacter <BaseCharacterEntity>(PlayerCharacterEntity.GetSkillAttackDistance(skill, isLeftHandAttacking) + lockAttackTargetDistance, false, true, false); if (nearestTarget != null) { // Set target, then use skill later when moved nearby target PlayerCharacterEntity.SetTargetEntity(nearestTarget); } else { // No nearby target, so use skill immediately if (RequestUsePendingSkill(isLeftHandAttacking, null)) { isLeftHandAttacking = !isLeftHandAttacking; } } } else if (!wasdLockAttackTarget) { // Not lock target, so not finding target and use skill immediately if (RequestUsePendingSkill(isLeftHandAttacking, null)) { isLeftHandAttacking = !isLeftHandAttacking; } } } else { // Not attack skill, so use skill immediately RequestUsePendingSkill(isLeftHandAttacking, null); } } else { queueUsingSkill = null; } } // Attack when player pressed attack button else if (InputManager.GetButton("Attack")) { destination = null; PlayerCharacterEntity.StopMove(); BaseCharacterEntity targetEntity; if (TryGetSelectedTargetAsAttackingCharacter(out targetEntity)) { SetTarget(targetEntity); } if (wasdLockAttackTarget && !TryGetAttackingCharacter(out targetEntity)) { // Find nearest target and move to the target BaseCharacterEntity nearestTarget = PlayerCharacterEntity .FindNearestAliveCharacter <BaseCharacterEntity>( PlayerCharacterEntity.GetAttackDistance(isLeftHandAttacking) + lockAttackTargetDistance, false, true, false); SelectedEntity = nearestTarget; if (nearestTarget != null) { // Set target, then attack later when moved nearby target PlayerCharacterEntity.SetTargetEntity(nearestTarget); } else { // No nearby target, so attack immediately if (PlayerCharacterEntity.RequestAttack(isLeftHandAttacking)) { isLeftHandAttacking = !isLeftHandAttacking; } } } else if (!wasdLockAttackTarget) { // Find nearest target and set selected target to show character hp/mp UIs BaseCharacterEntity nearestTarget = PlayerCharacterEntity .FindNearestAliveCharacter <BaseCharacterEntity>( PlayerCharacterEntity.GetAttackDistance(isLeftHandAttacking), false, true, false, true, PlayerCharacterEntity.GetAttackFov(isLeftHandAttacking)); SelectedEntity = nearestTarget; // Not lock target, so not finding target and attack immediately if (PlayerCharacterEntity.RequestAttack(isLeftHandAttacking)) { isLeftHandAttacking = !isLeftHandAttacking; } } } // Move if (moveDirection.magnitude != 0f) { PlayerCharacterEntity.StopMove(); destination = null; ClearTarget(); targetLookDirection = moveDirection.normalized; } // Always forward MovementState movementState = MovementState.Forward; if (InputManager.GetButtonDown("Jump")) { movementState |= MovementState.IsJump; } PlayerCharacterEntity.KeyMovement(moveDirection, movementState); }
protected void UpdateWASDInput() { if (controllerMode != PlayerCharacterControllerMode.WASD && controllerMode != PlayerCharacterControllerMode.Both) { return; } if (PlayerCharacterEntity.IsPlayingActionAnimation()) { PlayerCharacterEntity.StopMove(); return; } // If mobile platforms, don't receive input raw to make it smooth var raw = !InputManager.useMobileInputOnNonMobile && !Application.isMobilePlatform; var moveDirection = GetMoveDirection(InputManager.GetAxis("Horizontal", raw), InputManager.GetAxis("Vertical", raw)); if (moveDirection.magnitude != 0f) { if (CacheUISceneGameplay != null && CacheUISceneGameplay.uiNpcDialog != null) { CacheUISceneGameplay.uiNpcDialog.Hide(); } FindAndSetBuildingAreaFromCharacterDirection(); } // For WASD mode, Using skill when player pressed hotkey if (queueUsingSkill.HasValue) { var queueUsingSkillValue = queueUsingSkill.Value; destination = null; PlayerCharacterEntity.StopMove(); Skill skill = null; if (GameInstance.Skills.TryGetValue(queueUsingSkillValue.dataId, out skill) && skill != null) { if (skill.IsAttack()) { BaseCharacterEntity targetEntity; if (wasdLockAttackTarget && !TryGetAttackingCharacter(out targetEntity)) { var nearestTarget = PlayerCharacterEntity.FindNearestAliveCharacter <BaseCharacterEntity>(PlayerCharacterEntity.GetSkillAttackDistance(skill) + lockAttackTargetDistance, false, true, false); if (nearestTarget != null) { PlayerCharacterEntity.SetTargetEntity(nearestTarget); } else { RequestUsePendingSkill(); } } else if (!wasdLockAttackTarget) { RequestUsePendingSkill(); } } else { RequestUsePendingSkill(); } } else { queueUsingSkill = null; } } // Attack when player pressed attack button else if (InputManager.GetButton("Attack")) { destination = null; PlayerCharacterEntity.StopMove(); BaseCharacterEntity targetEntity; if (wasdLockAttackTarget && !TryGetAttackingCharacter(out targetEntity)) { var nearestTarget = PlayerCharacterEntity.FindNearestAliveCharacter <BaseCharacterEntity>(PlayerCharacterEntity.GetAttackDistance() + lockAttackTargetDistance, false, true, false); if (nearestTarget != null) { PlayerCharacterEntity.SetTargetEntity(nearestTarget); } else { RequestAttack(); } } else if (!wasdLockAttackTarget) { RequestAttack(); } } // Move else { if (moveDirection.magnitude != 0f) { destination = null; PlayerCharacterEntity.StopMove(); PlayerCharacterEntity.SetTargetEntity(null); } PlayerCharacterEntity.KeyMovement(moveDirection, InputManager.GetButtonDown("Jump")); } }