private AimPosition GetCurrentAimPosition()
    {
        // Work around for CustomStandaloneInput being null in the first couple seconds after the scene load
        if (Time.timeSinceLevelLoad < 1)
        {
            return(AimPosition.FromMouse(cam, false, mouseRaycastDistance));
        }

        var sim = (CustomStandaloneInputModule)EventSystem.current.currentInputModule;
        var go  = sim.GetPointerData().pointerCurrentRaycast.gameObject;

        if (go != null)
        {
            if (go.CompareTag("TargetReticle"))
            {
                var indicator = go.GetComponent <TargetReticle>().indicator;
                if (indicator.targetRb != null)
                {
                    return(new AimPosition(indicator.targetRb));
                }
            }
        }

        return(AimPosition.FromMouse(cam, false, mouseRaycastDistance));
    }
Exemple #2
0
        private static float3 ComputeAimDirectionRelativeToEntity(AimPosition aimPositions, LocalToWorld localToWorlds)
        {
            var direction = aimPositions.Value - localToWorlds.Position;

            direction.y = 0;
            return(direction);
        }
Exemple #3
0
 public void FireActiveWeapons(AimPosition aimPos)
 {
     foreach (Gun gun in guns)
     {
         if (gun.IsActive)
         {
             FireWeaponHardpoint(gun, aimPos);
         }
     }
 }
Exemple #4
0
        public override AimPosition UpdateBuildAimControls(Vector2 aimAxes, BuildingEntity prefab)
        {
            // Instantiate constructing building
            if (ConstructingBuildingEntity == null)
            {
                InstantiateConstructingBuilding(prefab);
                buildYRotate = 0f;
            }
            // Rotate by keys
            Vector3 buildingAngles = Vector3.zero;

            if (CurrentGameInstance.DimensionType == DimensionType.Dimension3D)
            {
                if (buildRotationSnap)
                {
                    if (InputManager.GetButtonDown("RotateLeft"))
                    {
                        buildYRotate -= buildRotateAngle;
                    }
                    if (InputManager.GetButtonDown("RotateRight"))
                    {
                        buildYRotate += buildRotateAngle;
                    }
                    // Make Y rotation set to 0, 90, 180
                    buildingAngles.y = buildYRotate = Mathf.Round(buildYRotate / buildRotateAngle) * buildRotateAngle;
                }
                else
                {
                    float deltaTime = Time.deltaTime;
                    if (InputManager.GetButton("RotateLeft"))
                    {
                        buildYRotate -= buildRotateSpeed * deltaTime;
                    }
                    if (InputManager.GetButton("RotateRight"))
                    {
                        buildYRotate += buildRotateSpeed * deltaTime;
                    }
                    // Rotate by set angles
                    buildingAngles.y = buildYRotate;
                }
                ConstructingBuildingEntity.BuildYRotation = buildYRotate;
            }
            ConstructingBuildingEntity.Rotation = Quaternion.Euler(buildingAngles);
            // Find position to place building
            if (InputManager.useMobileInputOnNonMobile || Application.isMobilePlatform)
            {
                FindAndSetBuildingAreaByAxes(aimAxes);
            }
            else
            {
                FindAndSetBuildingAreaByMousePosition();
            }
            return(AimPosition.CreatePosition(ConstructingBuildingEntity.Position));
        }
Exemple #5
0
        public override void UseHotkey(HotkeyType type, string relateId, AimPosition aimPosition)
        {
            ClearQueueUsingSkill();
            switch (type)
            {
            case HotkeyType.Skill:
                UseSkill(relateId, aimPosition);
                break;

            case HotkeyType.Item:
                UseItem(relateId, aimPosition);
                break;
            }
        }
Exemple #6
0
    public void FireWeaponHardpoint(int hardpointSlot, AimPosition aim)
    {
        hardpointSlot--;

        if (hardpointSlot >= guns.Capacity || hardpointSlot < 0)
        {
            return;
        }

        if (guns[hardpointSlot] != null)
        {
            FireWeaponHardpoint(guns[hardpointSlot], aim);
        }
    }
Exemple #7
0
    public Projectile Fire(AimPosition aim)
    {
        var proj = SpawnProjectile();

        if (proj == null)
        {
            return(null);
        }
        var pos = aim.rb == null ?
                  aim.pos : Utilities.CalculateAimPosition(SpawnPoint, rbTarget, stats.thrust);

        proj.Initialize(pos, stats, ignoredColliders);

        return(proj);
    }
Exemple #8
0
    public bool FireActiveWeapons(AimPosition aim)
    {
        var allFired = false;

        foreach (Gun gun in guns)
        {
            if (gun.IsActive)
            {
                if (!gun.Fire(aim))
                {
                    allFired = false;
                }
            }
        }
        return(allFired);
    }
Exemple #9
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;
            }
        }
Exemple #10
0
    public void FireWeaponHardpoint(Gun gun, AimPosition aim)
    {
        if (CanFireWeapons == false || gun.stats == null)
        {
            return;
        }

        if (gun.stats.energyDraw < energy && gun.Fire(aim, ship.colliders.ToArray()))
        {
            energy -= gun.stats.energyDraw;
            if (WeaponFired != null)
            {
                WeaponFired(gun);
            }
            energyCooldown.Begin(this);
        }
    }
Exemple #11
0
    public bool Fire(AimPosition aim, Collider[] colliders)
    {
        if (aim.HitAnything && aim.HitTargetReticle)
        {
            return(FireAtMovingTarget(aim.TargetIndicator.Ship.rb, colliders));

            // else
            // {
            //     return Fire(aim.hit.transform.position, colliders);
            // }
        }

        else if (aim.rb != null)
        {
            return(FireAtMovingTarget(aim.rb, colliders));
        }

        else
        {
            return(Fire(aim.pos, colliders));
        }
    }
Exemple #12
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);
            }
        }
    private void Update()
    {
        CurrentAimPosition = GetCurrentAimPosition();

        if (Input.GetKeyDown(InputManager.PauseGameKey) && canPause)
        {
            GameStateUtils.TogglePause();
            return;
        }

        if (!inputAllowed || ship == null)
        {
            return;
        }

        #region movement
        if (Input.GetKey(InputManager.ThrottleUpKey) || Input.GetAxis("Mouse ScrollWheel") > 0f)
        {
            ship.engine.ThrottleUp();
        }

        else if (Input.GetKeyUp(InputManager.ThrottleUpKey))
        {
            Action <bool> action = ship.engine.Blink;
            StartCoroutine(DoubleTap(InputManager.ThrottleUpKey, action, true));
        }

        if (Input.GetKey(InputManager.ThrottleDownKey) || Input.GetAxis("Mouse ScrollWheel") < 0f)
        {
            ship.engine.ThrottleDown();
        }

        if (Input.GetKey(InputManager.StrafeLeftKey))
        {
            ship.engine.Strafe = -1;
        }
        else if (Input.GetKeyUp(InputManager.StrafeLeftKey))
        {
            Action action = ship.engine.SidestepLeft;
            StartCoroutine(DoubleTap(InputManager.StrafeLeftKey, action));
        }

        if (Input.GetKey(InputManager.StrafeRightKey))
        {
            ship.engine.Strafe = 1;
        }
        else if (Input.GetKeyUp(InputManager.StrafeRightKey))
        {
            Action action = ship.engine.SidestepRight;
            StartCoroutine(DoubleTap(InputManager.StrafeRightKey, action));
        }

        // If neither strafe key is pressed, reset the ship's strafing
        if (!Input.GetKey(InputManager.StrafeRightKey) && !Input.GetKey(InputManager.StrafeLeftKey))
        {
            ship.engine.Strafe = 0;
        }

        if (Input.GetKeyDown(InputManager.ToggleMouseFlightKey))
        {
            ToggleMouseFlight();
        }

        if (Input.GetKeyDown(InputManager.AfterburnerKey))
        {
            ship.ToggleAfterburner(true);
        }

        else if (Input.GetKeyUp(InputManager.AfterburnerKey))
        {
            ship.ToggleAfterburner(false);
        }

        if (Input.GetKeyDown(InputManager.ManualMouseFlightKey))
        {
            if (MouseState == MouseState.Off)
            {
                StartCoroutine("ManualMouseFlightCoroutine");
            }
        }

        if (Input.GetKeyUp(InputManager.ManualMouseFlightKey))
        {
            StopAllCoroutines();

            if (MouseState == MouseState.Held)
            {
                MouseState = MouseState.Off;
            }
        }

        if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(InputManager.ThrottleUpKey))
        {
            ship.cruiseEngine.ToggleCruiseEngines();
        }

        if (Input.GetKeyDown(InputManager.KillEnginesKey))
        {
            ship.engine.Drifting = !ship.engine.Drifting;
        }

        #endregion

        #region hardpoints
        if (Input.GetKey(InputManager.Hardpoint1Key))
        {
            ship.guns[0].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint2Key))
        {
            ship.guns[1].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint3Key))
        {
            ship.guns[2].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint4Key))
        {
            ship.guns[3].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint5Key))
        {
            ship.guns[4].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint6Key))
        {
            ship.guns[5].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint7Key))
        {
            ship.guns[6].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint8Key))
        {
            ship.guns[7].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint9Key))
        {
            ship.guns[8].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.Hardpoint10Key))
        {
            ship.guns[9].Fire(CurrentAimPosition);
        }

        if (Input.GetKey(InputManager.FireKey))
        {
            ship.FireActiveWeapons(CurrentAimPosition);
        }

        #endregion
    }