示例#1
0
        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))
                {
                    if (skill.CanUse(PlayerCharacterEntity, skillLevel))
                    {
                        PlayerCharacterEntity.StopMove();
                        queueSkill = skill;
                    }
                }
            }
            Item item = hotkey.GetItem();

            if (item != null)
            {
                int itemIndex = PlayerCharacterEntity.IndexOfNonEquipItem(item.DataId);
                if (itemIndex >= 0)
                {
                    if (item.IsEquipment())
                    {
                        PlayerCharacterEntity.RequestEquipItem((short)itemIndex);
                    }
                    else if (item.IsPotion() || item.IsPet())
                    {
                        PlayerCharacterEntity.RequestUseItem((short)itemIndex);
                    }
                    else if (item.IsBuilding())
                    {
                        PlayerCharacterEntity.StopMove();
                        buildingItemIndex     = itemIndex;
                        CurrentBuildingEntity = Instantiate(item.buildingEntity);
                        CurrentBuildingEntity.SetupAsBuildMode();
                        CurrentBuildingEntity.CacheTransform.parent = null;
                    }
                }
            }
        }
示例#2
0
 protected void UpdateLookAtTarget()
 {
     if (destination != null)
     {
         targetLookDirection = (destination.Value - PlayerCharacterEntity.CacheTransform.position).normalized;
     }
     if (Vector3.Angle(tempLookAt * Vector3.forward, targetLookDirection) > 0)
     {
         // Update rotation when angle difference more than 1
         tempLookAt = Quaternion.RotateTowards(tempLookAt, Quaternion.LookRotation(targetLookDirection), Time.deltaTime * angularSpeed);
         PlayerCharacterEntity.UpdateYRotation(tempLookAt.eulerAngles.y);
     }
 }
示例#3
0
 protected virtual void SetTarget(BaseGameEntity entity)
 {
     targetPosition = null;
     if (pointClickSetTargetImmediately ||
         (entity != null && SelectedEntity == entity) ||
         (entity != null && entity is ItemDropEntity))
     {
         targetPosition = entity.CacheTransform.position;
         targetEntity   = entity;
         PlayerCharacterEntity.SetTargetEntity(entity);
     }
     SelectedEntity = entity;
 }
示例#4
0
        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();
        }
示例#5
0
        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);
        }
        protected virtual void Attack(IDamageableEntity entity, float distance, int layerMask)
        {
            Transform damageTransform   = PlayerCharacterEntity.GetWeaponDamageInfo(ref isLeftHandAttacking).GetDamageTransform(PlayerCharacterEntity, isLeftHandAttacking);
            Vector3   measuringPosition = damageTransform.position;
            Vector3   targetPosition    = entity.OpponentAimTransform.position;

            if (OverlappedEntity(entity.Entity, measuringPosition, targetPosition, distance))
            {
                // Turn character to attacking target
                TurnCharacterToEntity(entity.Entity);
                // Do action
                RequestAttack();
                // This function may be used by extending classes
                OnAttackOnEntity();
            }
        }
 public bool TryGetAttackingCharacter(out BaseCharacterEntity character)
 {
     character = null;
     if (PlayerCharacterEntity.TryGetTargetEntity(out character))
     {
         if (character.CanReceiveDamageFrom(PlayerCharacterEntity))
         {
             return(true);
         }
         else
         {
             character = null;
         }
     }
     return(false);
 }
示例#8
0
 public bool TryGetAttackingCharacter(out BaseCharacterEntity character)
 {
     character = null;
     if (PlayerCharacterEntity.TryGetTargetEntity(out character))
     {
         if (character != PlayerCharacterEntity && !character.IsAlly(PlayerCharacterEntity))
         {
             return(true);
         }
         else
         {
             character = null;
         }
     }
     return(false);
 }
示例#9
0
 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 void ConfirmBuild()
 {
     if (currentBuildingEntity != null)
     {
         if (currentBuildingEntity.CanBuild())
         {
             uint parentObjectId = 0;
             if (currentBuildingEntity.buildingArea != null)
             {
                 parentObjectId = currentBuildingEntity.buildingArea.EntityObjectId;
             }
             PlayerCharacterEntity.RequestBuild((ushort)buildingItemIndex, currentBuildingEntity.CacheTransform.position, currentBuildingEntity.CacheTransform.rotation, parentObjectId);
         }
         Destroy(currentBuildingEntity.gameObject);
     }
 }
        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);
            }
        }
示例#13
0
        protected void UseSkill(string id, AimPosition aimPosition)
        {
            BaseSkill skill;

            if (!GameInstance.Skills.TryGetValue(BaseGameData.MakeDataId(id), out skill) || skill == null ||
                !PlayerCharacterEntity.GetCaches().Skills.TryGetValue(skill, out _))
            {
                return;
            }

            bool isAttackSkill = skill.IsAttack();

            if (PlayerCharacterEntity.UseSkill(skill.DataId, isLeftHandAttacking, SelectedEntityObjectId, aimPosition) && isAttackSkill)
            {
                isLeftHandAttacking = !isLeftHandAttacking;
            }
        }
        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();
        }
示例#15
0
        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);
        }
示例#16
0
 public bool RequestUsePendingSkill(bool isLeftHand, Vector3?aimPosition)
 {
     if (queueUsingSkill.HasValue && PlayerCharacterEntity.CanUseSkill())
     {
         UsingSkillData queueUsingSkillValue = queueUsingSkill.Value;
         if (queueUsingSkillValue.aimPosition.HasValue)
         {
             aimPosition = queueUsingSkillValue.aimPosition.Value;
         }
         queueUsingSkill = null;
         if (aimPosition.HasValue)
         {
             return(PlayerCharacterEntity.RequestUseSkill(queueUsingSkillValue.dataId, isLeftHand, aimPosition.Value));
         }
         else
         {
             return(PlayerCharacterEntity.RequestUseSkill(queueUsingSkillValue.dataId, isLeftHand));
         }
     }
     return(false);
 }
示例#17
0
        protected void UpdateLookAtTarget()
        {
            tempCalculateAngle = Vector3.Angle(tempLookAt * Vector3.forward, targetLookDirection);
            if (turningState != TurningState.None)
            {
                if (tempCalculateAngle > 0)
                {
                    // Update rotation when angle difference more than 0
                    tempLookAt = Quaternion.Slerp(tempLookAt, Quaternion.LookRotation(targetLookDirection), turnTimeCounter / turnToTargetDuration);
                    PlayerCharacterEntity.UpdateYRotation(tempLookAt.eulerAngles.y);
                }
                else
                {
                    switch (turningState)
                    {
                    case TurningState.Attack:
                        Attack(isLeftHandAttacking);
                        break;

                    case TurningState.Activate:
                        Activate();
                        break;

                    case TurningState.UseSkill:
                        UseSkill(isLeftHandAttacking, aimPosition);
                        break;
                    }
                    turningState = TurningState.None;
                }
            }
            else
            {
                if (tempCalculateAngle > 0)
                {
                    // Update rotation when angle difference more than 0
                    tempLookAt = Quaternion.RotateTowards(tempLookAt, Quaternion.LookRotation(targetLookDirection), Time.deltaTime * angularSpeed);
                    PlayerCharacterEntity.UpdateYRotation(tempLookAt.eulerAngles.y);
                }
            }
        }
        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);
        }
示例#19
0
        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);
        }
示例#20
0
 public void Attack(bool isLeftHand)
 {
     PlayerCharacterEntity.RequestAttack(isLeftHand);
 }
示例#21
0
 public void SetAimPosition(Vector3 aimPosition)
 {
     PlayerCharacterEntity.RequestSetAimPosition(aimPosition);
 }
示例#22
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);
        }
 protected override void Update()
 {
     pointClickSetTargetImmediately = true;
     SelectedEntity = PlayerCharacterEntity.GetTargetEntity();
     base.Update();
 }
        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);
                }
            }
        }
示例#25
0
        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();
        }
示例#26
0
        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)));
                }
            }
        }
示例#27
0
 public void RequestUseItem(short itemIndex)
 {
     PlayerCharacterEntity.RequestUseItem(itemIndex);
 }
        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;
                }
            }
        }
示例#29
0
        protected void UseItem(string id, Vector3?aimPosition)
        {
            InventoryType inventoryType;
            int           itemIndex;
            byte          equipWeaponSet;
            CharacterItem characterItem;

            if (PlayerCharacterEntity.IsEquipped(
                    id,
                    out inventoryType,
                    out itemIndex,
                    out equipWeaponSet,
                    out characterItem))
            {
                PlayerCharacterEntity.RequestUnEquipItem(inventoryType, (short)itemIndex, equipWeaponSet);
                return;
            }

            if (itemIndex < 0)
            {
                return;
            }

            BaseItem item = characterItem.GetItem();

            if (item == null)
            {
                return;
            }

            if (item.IsEquipment())
            {
                PlayerCharacterEntity.RequestEquipItem((short)itemIndex);
            }
            else if (item.IsSkill())
            {
                bool isAttackSkill = (item as ISkillItem).UsingSkill.IsAttack();
                if (!aimPosition.HasValue)
                {
                    if (PlayerCharacterEntity.RequestUseSkillItem((short)itemIndex, isLeftHandAttacking) && isAttackSkill)
                    {
                        // Requested to use attack skill then change attacking hand
                        isLeftHandAttacking = !isLeftHandAttacking;
                    }
                }
                else
                {
                    if (PlayerCharacterEntity.RequestUseSkillItem((short)itemIndex, isLeftHandAttacking, aimPosition.Value) && isAttackSkill)
                    {
                        // Requested to use attack skill then change attacking hand
                        isLeftHandAttacking = !isLeftHandAttacking;
                    }
                }
            }
            else if (item.IsBuilding())
            {
                buildingItemIndex = itemIndex;
                ShowConstructBuildingDialog();
            }
            else if (item.IsUsable())
            {
                PlayerCharacterEntity.RequestUseItem((short)itemIndex);
            }
        }
示例#30
0
        protected void UseItem(string id, AimPosition aimPosition)
        {
            int      itemIndex;
            BaseItem item;
            int      dataId = BaseGameData.MakeDataId(id);

            if (GameInstance.Items.ContainsKey(dataId))
            {
                item      = GameInstance.Items[dataId];
                itemIndex = OwningCharacter.IndexOfNonEquipItem(dataId);
            }
            else
            {
                InventoryType inventoryType;
                byte          equipWeaponSet;
                CharacterItem characterItem;
                if (PlayerCharacterEntity.IsEquipped(
                        id,
                        out inventoryType,
                        out itemIndex,
                        out equipWeaponSet,
                        out characterItem))
                {
                    GameInstance.ClientInventoryHandlers.RequestUnEquipItem(
                        inventoryType,
                        (short)itemIndex,
                        equipWeaponSet,
                        -1,
                        ClientInventoryActions.ResponseUnEquipArmor,
                        ClientInventoryActions.ResponseUnEquipWeapon);
                    return;
                }
                item = characterItem.GetItem();
            }

            if (itemIndex < 0)
            {
                return;
            }

            if (item == null)
            {
                return;
            }

            if (item.IsEquipment())
            {
                GameInstance.ClientInventoryHandlers.RequestEquipItem(
                    PlayerCharacterEntity,
                    (short)itemIndex,
                    ClientInventoryActions.ResponseEquipArmor,
                    ClientInventoryActions.ResponseEquipWeapon);
            }
            else if (item.IsSkill())
            {
                bool isAttackSkill = (item as ISkillItem).UsingSkill.IsAttack();
                if (PlayerCharacterEntity.UseSkillItem((short)itemIndex, isLeftHandAttacking, SelectedEntityObjectId, aimPosition) && isAttackSkill)
                {
                    isLeftHandAttacking = !isLeftHandAttacking;
                }
            }
            else if (item.IsBuilding())
            {
                buildingItemIndex = itemIndex;
                ShowConstructBuildingDialog();
            }
            else if (item.IsUsable())
            {
                PlayerCharacterEntity.CallServerUseItem((short)itemIndex);
            }
        }