protected virtual void TabTargetUpdateQueuedSkill()
        {
            if (PlayerCharacterEntity.IsDead())
            {
                ClearQueueUsingSkill();
                return;
            }
            if (queueUsingSkill.skill == null || queueUsingSkill.level <= 0)
            {
                return;
            }
            if (PlayerCharacterEntity.IsPlayingActionAnimation())
            {
                return;
            }
            destination = null;
            BaseSkill skill       = queueUsingSkill.skill;
            Vector3?  aimPosition = queueUsingSkill.aimPosition;

            if (skill.HasCustomAimControls())
            {
                // Target not required, use skill immediately
                TurnCharacterToPosition(aimPosition.Value);
                RequestUsePendingSkill();
                isFollowingTarget = false;
                return;
            }

            if (skill.IsAttack() || skill.RequiredTarget())
            {
                // Let's stick to tab targeting instead of finding a random entity
                if (CacheActionTarget != null && CacheActionTarget is BaseCharacterEntity)
                {
                    UseSkillOn(CacheActionTarget);
                    return;
                }
                ClearQueueUsingSkill();
                return;
            }
            // Target not required, use skill immediately
            RequestUsePendingSkill();
        }
        public virtual void TabTargetUpdateWASDInput()
        {
            if (controllerMode == PlayerCharacterControllerMode.PointClick)
            {
                return;
            }

            // If mobile platforms, don't receive input raw to make it smooth
            bool    raw           = !InputManager.useMobileInputOnNonMobile && !Application.isMobilePlatform;
            Vector3 moveDirection = TabTargetGetMoveDirection(InputManager.GetAxis("Horizontal", raw), InputManager.GetAxis("Vertical", raw));

            moveDirection.Normalize();

            // Move
            if (moveDirection.sqrMagnitude > 0f)
            {
                TabTargetCameraController.lerpOffset = true;
                HideNpcDialog();
                ClearQueueUsingSkill();
                destination       = null;
                isFollowingTarget = false;
                if (!PlayerCharacterEntity.IsPlayingActionAnimation())
                {
                    PlayerCharacterEntity.SetLookRotation(Quaternion.LookRotation(moveDirection));
                }
            }
            // Always forward
            MovementState movementState = MovementState.Forward;

            if (InputManager.GetButtonDown("Jump"))
            {
                movementState |= MovementState.IsJump;
            }

            PlayerCharacterEntity.KeyMovement(moveDirection, movementState);
        }
Exemplo n.º 3
0
        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);
        }
        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);
                    }
                }
            }
        }
Exemplo n.º 5
0
        protected void UpdateFollowTarget()
        {
            // Temp variables
            if (TryGetAttackingCharacter(out targetEnemy))
            {
                if (targetEnemy.IsDead())
                {
                    queueUsingSkill = null;
                    PlayerCharacterEntity.StopMove();
                    PlayerCharacterEntity.SetTargetEntity(null);
                    return;
                }

                if (PlayerCharacterEntity.IsPlayingActionAnimation())
                {
                    PlayerCharacterEntity.StopMove();
                    return;
                }

                // Find attack distance and fov, from weapon or skill
                var attackDistance = 0f;
                var attackFov      = 0f;
                if (!GetAttackDistanceAndFov(out attackDistance, out attackFov))
                {
                    return;
                }
                var actDistance = attackDistance;
                actDistance -= actDistance * 0.1f;
                actDistance -= StoppingDistance;
                if (FindTarget(targetEnemy.gameObject, actDistance, gameInstance.characterLayer.Mask))
                {
                    // Stop movement to attack
                    PlayerCharacterEntity.StopMove();
                    if (PlayerCharacterEntity.IsPositionInFov(attackFov, targetEnemy.CacheTransform.position))
                    {
                        // If has queue using skill, attack by the skill
                        if (queueUsingSkill.HasValue)
                        {
                            RequestUsePendingSkill();
                        }
                        else
                        {
                            RequestAttack();
                        }
                    }
                }
                else
                {
                    UpdateTargetEntityPosition(targetEnemy);
                }
            }
            else if (PlayerCharacterEntity.TryGetTargetEntity(out targetPlayer))
            {
                if (targetPlayer.IsDead())
                {
                    queueUsingSkill = null;
                    PlayerCharacterEntity.StopMove();
                    PlayerCharacterEntity.SetTargetEntity(null);
                    return;
                }
                var actDistance = gameInstance.conversationDistance - StoppingDistance;
                if (Vector3.Distance(CharacterTransform.position, targetPlayer.CacheTransform.position) <= actDistance)
                {
                    PlayerCharacterEntity.StopMove();
                    // TODO: do something
                }
                else
                {
                    UpdateTargetEntityPosition(targetPlayer);
                }
            }
            else if (PlayerCharacterEntity.TryGetTargetEntity(out targetMonster))
            {
                if (targetMonster.IsDead())
                {
                    queueUsingSkill = null;
                    PlayerCharacterEntity.StopMove();
                    PlayerCharacterEntity.SetTargetEntity(null);
                    return;
                }
                var actDistance = gameInstance.conversationDistance - StoppingDistance;
                if (Vector3.Distance(CharacterTransform.position, targetMonster.CacheTransform.position) <= actDistance)
                {
                    PlayerCharacterEntity.StopMove();
                    // TODO: do something
                }
                else
                {
                    UpdateTargetEntityPosition(targetMonster);
                }
            }
            else if (PlayerCharacterEntity.TryGetTargetEntity(out targetNpc))
            {
                var actDistance = gameInstance.conversationDistance - StoppingDistance;
                if (Vector3.Distance(CharacterTransform.position, targetNpc.CacheTransform.position) <= actDistance)
                {
                    if (lastNpcObjectId != targetNpc.ObjectId)
                    {
                        PlayerCharacterEntity.RequestNpcActivate(targetNpc.ObjectId);
                        lastNpcObjectId = targetNpc.ObjectId;
                    }
                    PlayerCharacterEntity.StopMove();
                }
                else
                {
                    UpdateTargetEntityPosition(targetNpc);
                }
            }
            else if (PlayerCharacterEntity.TryGetTargetEntity(out targetItemDrop))
            {
                var actDistance = gameInstance.pickUpItemDistance - StoppingDistance;
                if (Vector3.Distance(CharacterTransform.position, targetItemDrop.CacheTransform.position) <= actDistance)
                {
                    PlayerCharacterEntity.RequestPickupItem(targetItemDrop.ObjectId);
                    PlayerCharacterEntity.StopMove();
                    PlayerCharacterEntity.SetTargetEntity(null);
                }
                else
                {
                    UpdateTargetEntityPosition(targetItemDrop);
                }
            }
            else if (PlayerCharacterEntity.TryGetTargetEntity(out targetBuilding))
            {
                var uiCurrentBuilding = CacheUISceneGameplay.uiCurrentBuilding;
                var actDistance       = gameInstance.buildDistance - StoppingDistance;
                if (Vector3.Distance(CharacterTransform.position, targetBuilding.CacheTransform.position) <= actDistance)
                {
                    if (uiCurrentBuilding != null && !uiCurrentBuilding.IsVisible())
                    {
                        uiCurrentBuilding.Show();
                    }
                    PlayerCharacterEntity.StopMove();
                }
                else
                {
                    UpdateTargetEntityPosition(targetBuilding);
                    if (uiCurrentBuilding != null && uiCurrentBuilding.IsVisible())
                    {
                        uiCurrentBuilding.Hide();
                    }
                }
            }
            else if (PlayerCharacterEntity.TryGetTargetEntity(out targetHarvestable))
            {
                if (targetHarvestable.IsDead())
                {
                    queueUsingSkill = null;
                    PlayerCharacterEntity.StopMove();
                    PlayerCharacterEntity.SetTargetEntity(null);
                    return;
                }

                var attackDistance = 0f;
                var attackFov      = 0f;
                if (!GetAttackDistanceAndFov(out attackDistance, out attackFov))
                {
                    return;
                }
                var actDistance = attackDistance;
                actDistance -= actDistance * 0.1f;
                actDistance -= StoppingDistance;
                if (FindTarget(targetHarvestable.gameObject, actDistance, gameInstance.harvestableLayer.Mask))
                {
                    // Stop movement to attack
                    PlayerCharacterEntity.StopMove();
                    if (PlayerCharacterEntity.IsPositionInFov(attackFov, targetHarvestable.CacheTransform.position))
                    {
                        RequestAttack();
                    }
                }
                else
                {
                    UpdateTargetEntityPosition(targetHarvestable);
                }
            }
        }
Exemplo n.º 6
0
        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"));
            }
        }