Esempio n. 1
0
        protected void UpdateTargetEntityPosition(BaseGameEntity entity)
        {
            if (entity == null)
            {
                return;
            }
            Vector3 targetPosition = entity.CacheTransform.position;

            PlayerCharacterEntity.PointClickMovement(targetPosition);
            targetLookDirection = (targetPosition - PlayerCharacterEntity.CacheTransform.position).normalized;
        }
Esempio n. 2
0
        protected void UpdateTargetEntityPosition(BaseGameEntity entity)
        {
            if (entity == null)
            {
                return;
            }

            var targetPosition = entity.CacheTransform.position;

            PlayerCharacterEntity.PointClickMovement(targetPosition);
        }
        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);
                }
            }
        }
        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;
                }
            }
        }
Esempio n. 5
0
        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);
                    }
                }
            }
        }
Esempio n. 6
0
        protected 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;
                var mouseUpOnTarget = getMouseUp && !isMouseDragOrHoldOrOverUI && (controllerMode == PlayerCharacterControllerMode.PointClick || controllerMode == PlayerCharacterControllerMode.Both);
                tempCount = FindClickObjects(out tempVector3);
                for (tempCounter = 0; tempCounter < tempCount; ++tempCounter)
                {
                    tempTransform = GetRaycastTransform(tempCounter);
                    // When clicking on target
                    if (mouseUpOnTarget)
                    {
                        targetPlayer      = tempTransform.GetComponent <BasePlayerCharacterEntity>();
                        targetMonster     = tempTransform.GetComponent <BaseMonsterCharacterEntity>();
                        targetNpc         = tempTransform.GetComponent <NpcEntity>();
                        targetItemDrop    = tempTransform.GetComponent <ItemDropEntity>();
                        targetHarvestable = tempTransform.GetComponent <HarvestableEntity>();
                        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 (tempCounter == tempCount - 1)
                            {
                                // If it is last entry and not base game entity
                                // Assume that player clicked on ground / terrain
                                selectedTarget = null;
                                targetPosition = GetRaycastPoint(tempCounter);
                            }
                        }
                    }
                    // When holding on target
                    else if (isMouseHoldAndNotDrag)
                    {
                        var buildingMaterial = tempTransform.GetComponent <BuildingMaterial>();
                        if (buildingMaterial != null && buildingMaterial.buildingEntity != null && !buildingMaterial.buildingEntity.IsDead())
                        {
                            targetPosition = buildingMaterial.buildingEntity.CacheTransform.position;
                            targetEntity   = buildingMaterial.buildingEntity;
                            PlayerCharacterEntity.SetTargetEntity(buildingMaterial.buildingEntity);
                            selectedTarget = buildingMaterial.buildingEntity;
                            break;
                        }
                    }
                }
                // 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 (dimensionType == DimensionType.Dimension2D && mouseUpOnTarget && tempCount == 0)
                {
                    PlayerCharacterEntity.SetTargetEntity(null);
                    selectedTarget = null;
                    tempVector3.z  = 0;
                    targetPosition = tempVector3;
                }
                // If Found target, do something
                if (targetPosition.HasValue)
                {
                    // Close NPC dialog, when target changes
                    if (CacheUISceneGameplay != null && CacheUISceneGameplay.uiNpcDialog != null)
                    {
                        CacheUISceneGameplay.uiNpcDialog.Hide();
                    }

                    // Move to target, will hide destination when target is object
                    if (targetEntity != null)
                    {
                        destination = null;
                    }
                    else
                    {
                        destination = targetPosition.Value;
                        PlayerCharacterEntity.PointClickMovement(targetPosition.Value);
                    }
                }
            }
        }