private void Update()
 {
     if (Input.GetButton("Fire1"))
     {
         OnFire?.Invoke();
     }
 }
Пример #2
0
                //Hook by replacing method body of ModuleScoop.ControlInputManual()
                internal static void ControlInputManual(ModuleWeapon module, int aim, int fire)
                {
                    bool shouldFireDefault = (fire != 0) && (Time.timeScale != 0f);
                    var  shouldFireEvent   = new CanFireEvent <ModuleWeapon>(module, shouldFireDefault);

                    CanFire?.Invoke(shouldFireEvent);

                    bool performBehaviour = true;

                    if (shouldFireEvent.Fire)
                    {
                        var fireEvent = new FireEvent <ModuleWeapon>(module);
                        OnFire?.Invoke(fireEvent);
                        performBehaviour = fireEvent.PerformVanillaBehaviour;
#warning Remove duplicate versions of this
                    }
                    if (performBehaviour)
                    {
                        module.AimControl       = aim;
                        module.FireControl      = shouldFireEvent.Fire;
                        module.m_TargetPosition = Vector3.zero;
                        if (module.FireControl && module.block.tank && module.block.tank.beam.IsActive && !Mode <ModeMain> .inst.TutorialLockBeam)
                        {
                            module.block.tank.beam.EnableBeam(false, false);
                        }
                    }
                }
Пример #3
0
                //Hook by replacing method body of ModuleScoop.ControlInput()
                internal static void ControlInput(ModuleScoop module, int aim, int fire)
                {
                    bool shouldFireDefault = (fire != 0);
                    var  shouldFireEvent   = new CanFireEvent <ModuleScoop>(module, shouldFireDefault);

                    CanFire?.Invoke(shouldFireEvent);

                    bool performBehaviour = true;

                    if (shouldFireEvent.Fire)
                    {
                        var fireEvent = new FireEvent <ModuleScoop>(module);
                        OnFire?.Invoke(fireEvent);
                        performBehaviour = fireEvent.PerformVanillaBehaviour;
#warning Remove duplicate versions of this
                    }
                    if (performBehaviour)
                    {
                        /*if (module.actuator.isPlaying)
                         * {
                         *      return;
                         * }
                         * if (!module.m_Lifted && shouldFireEvent.Fire)
                         * {
                         *      module.actuator.Play(module.m_LiftAnim.name);
                         *      module.m_Lifted = true;
                         *      return;
                         * }
                         * if (module.m_Lifted && (!shouldFireEvent.Fire || (module.m_UpAndDownMode && shouldFireEvent.Fire)))
                         * {
                         *      module.actuator.Play(module.m_DropAnim.name);
                         *      module.m_Lifted = false;
                         * }*/
                    }
                }
Пример #4
0
    protected override void OnUpdate()
    {
        base.OnUpdate();

        if (emptyTimer > 0)
        {
            emptyTimer -= Time.deltaTime;
            return;
        }

        if (attackCooldownTimer > 0f)
        {
            OnFire.Invoke();

            attackCooldownTimer -= Time.deltaTime;

            ammoUseTimer += Time.deltaTime;
            if (ammoUseTimer >= AmmoUseTime)
            {
                if (character.ammunition[UsesAmmo] >= AmmoUseAmount)
                {
                    character.ammunition[UsesAmmo] -= AmmoUseAmount;
                }

                ammoUseTimer -= AmmoUseTime;
            }
        }
    }
Пример #5
0
    // Update is called once per frame
    protected void Update()
    {
        if (active && (Time.time - lastFireTime) > (interval + pauseFactor))
        {
            pauseFactor = 0.0f;
            fireWatchers?.Invoke();
            lastFireTime = Time.time;
            numberOfFires++;

            switch (countDownType)
            {
            case CountDownType.Number:
                countDownTypeParam1--;
                if (countDownTypeParam1 <= 0)
                {
                    SetActive(false);
                }
                break;

            case CountDownType.Once:
                SetActive(false);
                break;
            }
        }
    }
Пример #6
0
        private void Update()
        {
            MousePos = _camera.ScreenToWorldPoint(Input.mousePosition);

            CheckInput();
            if (_isHoldFireButton)
            {
                IncrementHoldFireButtonTimer();
            }

            if (!_isFire)
            {
                return;
            }

            if (_holdFireTimer <= _holdFirePressThreshold)
            {
                OnFire?.Invoke();
                ResetHoldFireButtonTimer();
            }
            else
            {
                OnHoldFire?.Invoke(_holdFireTimer >= _holdFireFullPressThreshold);
                ResetHoldFireButtonTimer();
            }
        }
Пример #7
0
    private void Fire(ITarget intendedTarget)
    {
        if (FireParticle)
        {
            FireParticle.Play();
        }

        for (int i = 0; i < Amount; i++)
        {
            Quaternion rotation = Muzzle.transform.rotation * Quaternion.Euler(UnityEngine.Random.Range(-Inaccuracy, Inaccuracy), UnityEngine.Random.Range(-Inaccuracy, Inaccuracy), 0f);
            GameObject proj     = _pool.GetObject(Muzzle.transform.position, rotation);

            _team.ApplyTeam(proj);
            proj.transform.position = Muzzle.transform.position;
            proj.transform.rotation = Muzzle.transform.rotation;

            Projectile projectile = proj.GetComponent <Projectile>();
            projectile.HitLayerMask = _hitLayerMask;
            projectile.Target       = intendedTarget;

            projectile.Damage     = Damage;
            projectile.DamageType = DamageType;
            projectile.Speed      = Speed;

            projectile.Fire(rotation * Vector3.forward);

            projectile.OnHit  += Projectile_OnHit;
            projectile.OnKill += Projectile_OnKill;
            projectile.OnEnd  += Projectile_OnEnd;

            OnProjectile?.Invoke(this, projectile);
        }

        OnFire?.Invoke(this);
    }
    private void FireRandomBullets()
    {
        if (_fireRandomBullets != null)
        {
            StopCoroutine(_fireRandomBullets);
        }

        _fireRandomBullets = StartCoroutine(FireRandomBulletsCoroutine());

        IEnumerator FireRandomBulletsCoroutine()
        {
            while (true)
            {
                yield return(new WaitForSeconds(0.25f)); //GetRandomNumber());

                OnFire?.Invoke(Rigidbody.velocity.magnitude, Transform.position, GetRandomDirection());
            }
        }

        int GetRandomNumber()
        {
            return(Random.Range(3, 10));
        }

        Vector2 GetRandomDirection()
        {
            var direction = Vector2.one;

            direction.x = GetRandomNumber();
            direction.x = GetRandomNumber();

            return(direction.normalized);
        }
    }
 IEnumerator Fire()
 {
     while (true)
     {
         OnFire?.Invoke();
         yield return(new WaitForFixedUpdate());
     }
 }
Пример #10
0
    public void Fire()
    {
        Fireball newFireball = Instantiate(fireball, transform.position + new Vector3(0.9f, 0, 0), Quaternion.identity);

        newFireball.gameObject.SetActive(true);
        OnFire.Invoke();
        isFire = true;
    }
Пример #11
0
    void FireUpProjectile(Vector2 direction)
    {
        //Add Pooler later
        GameObject go = Instantiate(_bulletPrefab, _spawnPosition.position, Quaternion.identity);

        go.GetComponent <Bullet>().Fire(direction);
        OnFire?.Invoke();
    }
Пример #12
0
        /// <summary>
        /// AI使用发射槽来控制发射武器
        /// 普通发射使用发射类型
        /// </summary>
        /// <param name="i"></param>
        public void FireAI(int i)
        {
            //Log.Trace("FireAI: 发射槽" + i + " 发射槽总数" + skills.Count);
            if (skills.Count <= i)
            {
                //Log.Trace("FireAI: 发射槽 超过了 发射槽总数");
                return;
            }
            if (skills[i] is ISkillContainer actor)
            {
                //var weaponactor = actor.Clone();
                //weaponactor.SetActorId(level.GetCreateInternalComponentBase().GetCreateID());
                //var weapon = weaponactor as ISkillContainer;
                if (actor.GetActorType() == ActorTypeBaseDefine.ContinuousLaserActor)
                {
                    foreach (var s in skillInitList)
                    {
                        if (s.ActorType == ActorTypeBaseDefine.ContinuousLaserActor)
                        {
                            return;
                        }
                    }
                }
                if (actor.GetActorType() == ActorTypeBaseDefine.ContinuousLaserActor)
                {
                    if (skillcd[i] == 0)
                    {
                        return;
                    }
                }
                else
                {
                    if (skillcd[i] != 0)
                    {
                        return;
                    }
                }
                var id     = level.GetCreateInternalComponentBase().GetCreateID();
                var weapon = actor as ISkillContainer;
                weapon.SetRelPosition(0, 0);
                //Log.Trace("当前发射者 位置:" + container.GetPhysicalinternalBase().GetBody().Position + " 朝向:" +
                //          container.GetPhysicalinternalBase().GetBody().Forward);
                //Log.Trace("当前武器箱 位置:"+actor.GetBody().Position + " 朝向:"+actor.GetBody().Forward);
                //Log.Trace("被发射武器"+weapon.GetBody().Id+" 位置:" + weapon.GetBody().Position + " 朝向:" + weapon.GetBody().Forward+" 朝向角度:"+weapon.GetBody().Angle);


                //level.GetEnvirinfointernalBase().AddActor(weapon as ActorBase);
                var init = weapon.GetInitData();
                level.AddEventMessagesToHandlerForward(new InitEventMessage(id, actor.GetCamp(), actor.GetActorType(), init.point_x, init.point_y, init.angle, weapon.GetLinerDamping(), ownerid: weapon.GetOwnerID(), relatpoint_x: weapon.GetRelPositionX(), relatpoint_y: weapon.GetRelPositionY()));

                skillInitList.Add(new UserData(id, weapon.GetActorType()));
                OnFire?.Invoke(weapon);
                if (actor.GetActorType() != ActorTypeBaseDefine.ContinuousLaserActor)
                {
                    skillcd[i] = DateTime.Now.Ticks;
                }
            }
        }
Пример #13
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetButtonUp("Fire1"))
     {
         RaycastHit hit = GetMouseRaycast();
         args.Set(hit);
         OnFire.Invoke(this, args);
     }
 }
 private void Fire()
 {
     if (Time.time >= _nextBulletTime)
     {
         _nextBulletTime = Time.time + _fireRate;
         OnFire?.Invoke(Rigidbody.velocity.magnitude, Transform.position, Transform.up);
         // play with rapid fire check?
         // RapidFireCheck();
     }
 }
Пример #15
0
        private void Update()
        {
            Horizontal = Input.GetAxis(HORIZONTAL);
            Vertical   = Input.GetAxis(VERTICAL);

            if (Input.GetButtonDown(FIRE))
            {
                OnFire?.Invoke();
            }
        }
Пример #16
0
        private void RpcSpawnRocketBot(bool isGreenTeam)
        {
            OnFire?.Invoke();

            GameObject rocket = GameObject.Instantiate(rocketPrefab, rocketLaunchPos.position, rocketLaunchPos.rotation) as GameObject;

            rocket.GetComponent <Rocket>().travelDir = this.transform.forward;
            rocket.GetComponent <Rocket>().greenTeam = isGreenTeam;
            NetworkServer.Spawn(rocket);
        }
Пример #17
0
 IEnumerator FireEventCoroutine()
 {
     while (GameManager.isRunning)
     {
         //erkundigt sich alle shootSpeed Sekunden nach dem Target und feuert das Event ab. Wenn kein Enemy mehr vorhanden ist und ein neuer gespawnt wird während man wartet, gibt es eine Verzögerung,
         // bis das neue Target erfasst wird, weil dies erst im nächsten Schleifendruchlauf nach der Wartezeit geschieht. Es wird sich immer erkundigt, auch wenn enemy.Count leer ist
         OnFire?.Invoke(GetTargetEnemy(towerProperties.shootTarget));
         yield return(new WaitForSeconds(1 / towerProperties.shootSpeed));     //nicht cachen, weil shootspeed sich je nach Level ändert
     }
     UnsubscribeMethods();
 }
Пример #18
0
 public void Fire(InputAction.CallbackContext context)
 {
     if (context.started && !paused && recordingManager != null && ball != null && !ball.isMoving())
     {
         // fire the ball at an angle between 20 and 160 degrees to ensure that it
         // does not start off going too horizontal or even below the paddle...
         int   frame         = recordingManager.getFrame();
         float movementSpeed = ball.getMovementSpeed();
         commandProcessor.Execute(new FireCommand(ball, frame, Random.Range(89, 91), movementSpeed));
         OnFire?.Invoke();
     }
 }
Пример #19
0
        internal void Fire(TriggerStateType triggerStateType)
        {
            IsFired          = true;
            TriggerStateType = triggerStateType;
            if (CheckConditionToFire())
            {
                CalledOnFire(triggerStateType);
                OnFire?.Invoke(this);
            }

            IsFired = false;
        }
Пример #20
0
 internal void HandleFire(float overshotTime)
 {
     Fire(overshotTime);
     ammo--;
     if (shootSounds.Count > 0)
     {
         AudioHandler.AudioContext adjustedContext = audioContext;
         adjustedContext.volume *= SettingsHandler.cache.volume_gun * SettingsHandler.cache.volume_master;
         AudioHandler.PlaySound(shootSounds[Random.Range(0, shootSounds.Count - 1)], adjustedContext, firepoint.position);
     }
     OnFire?.Invoke();
     CalculateCooldown();
 }
Пример #21
0
        private void Update()
        {
            var worldPosition = camera.ScreenToWorldPoint(UnityEngine.Input.mousePosition);

            worldPosition.z = 0f;

            OnAim?.Invoke(worldPosition);

            if (UnityEngine.Input.GetMouseButtonDown(0))
            {
                OnFire?.Invoke(worldPosition);
            }
        }
Пример #22
0
    private void CreateRocket()
    {
        Sounds.CreateSound(FireSound, transform.position);

        if (MuzzlePrefab != null)
        {
            GameObject muzzle = Instantiate(MuzzlePrefab);
            muzzle.transform.rotation = _weaponPrefab.transform.rotation * Quaternion.Euler(MuzzleRotation);
            muzzle.transform.position = _weaponPrefab.transform.position + muzzle.transform.TransformDirection(MuzzlePosition);
            muzzle.transform.SetParent(_weaponPrefab.transform);
        }

        if (RocketPrefab != null)
        {
            Rocket rocket = Instantiate(RocketPrefab, LevelLoader.DynamicObjects);
            rocket.owner           = character;
            rocket.Damage          = RocketDamage;
            rocket.ArmDistance     = RocketArmDistance;
            rocket.ArmTimeRange    = RocketArmTimeRange;
            rocket.Force           = RocketForce;
            rocket.Speed           = RocketSpeed;
            rocket.Slowdown        = RocketSlowdown;
            rocket.ExplosionRadius = RocketExplosionRadius;
            rocket.LifeTime        = RocketLifeTime;
            rocket.damageType      = RocketDamageType;
            rocket.Veer            = Random.Range(-Drunkenness, +Drunkenness);

            //make a special raycasting move from character to barrel
            rocket.transform.position = character.transform.position;
            rocket.InitialMove((_weaponPrefab.transform.position + _weaponPrefab.transform.rotation * RocketPosition) - character.transform.position);

            if (AttackDirection == Vector2.zero)
            {
                rocket.transform.rotation = character.LookDirection;
            }
            else
            {
                rocket.transform.rotation = Quaternion.Euler(0, 0, Mathf.Atan2(AttackDirection.x, -AttackDirection.y) * Mathf.Rad2Deg);
            }

            //add spread
            float firstRoll  = Random.Range(-spread, spread);
            float secondRoll = Random.Range(-spread, spread);
            rocket.transform.rotation *= Quaternion.Euler(0, 0, Mathf.Abs(firstRoll) < Mathf.Abs(secondRoll) ? firstRoll : secondRoll);

            rocket.GetComponent <SaveGameObject>().SpawnName = RocketDesignation;
        }

        OnFire.Invoke();
    }
Пример #23
0
    protected virtual void Fire()
    {
        ammo--;
        cooldownTimer = shootCooldown;
        OnFire?.Invoke(this);
        if (camShake != null)
        {
            camShake.ShakeCameraOmni();
        }

        if (shotAttentionAttractionRadius > 0)
        {
            AI.Attention.Attract(transform.position, shotAttentionAttractionRadius, attentionMask);
        }
    }
Пример #24
0
        private void Fire()
        {
            _fireAnimation.Play(Cooldown);
            _fireControl.Fire(_muzzles.Length, Cooldown, (i) =>
            {
                IProjectile[] projs = _projectilePool.Get(_muzzles[i].position, _muzzles[i].rotation, GetSpread(), GetProjectileAmount());

                foreach (IProjectile proj in projs)
                {
                    HandleProjectile(proj);
                }

                OnFire?.Invoke(projs);
                EmitFireParticle(i);
            });
        }
Пример #25
0
        private void Update()
        {
            if (!CanInput)
            {
                return;
            }

            if (Input.GetButtonDown("Fire1"))
            {
                OnFire?.Invoke();
            }

            Vertical = Input.GetAxisRaw("Vertical");

            Horizontal = Input.GetAxisRaw("Horizontal");
        }
Пример #26
0
        public void Fire(int i)
        {
            //Log.Trace("Fire: 发射槽" + i + " 发射槽总数" + skills.Count);
            for (var j = 0; j < skills.Count; j++)
            {
                if (skills[j].GetActorType() == i && skills[j] is ISkillContainer actor)
                {
                    if (i == ActorTypeBaseDefine.ContinuousLaserActor)
                    {
                        if (skillcd[j] == 0)
                        {
                            return;
                        }
                    }
                    else
                    {
                        if (skillcd[j] != 0)
                        {
                            return;
                        }
                    }
                    //var weaponactor = actor.Clone();
                    //weaponactor.SetActorId(level.GetCreateInternalComponentBase().GetCreateID());
                    var id     = level.GetCreateInternalComponentBase().GetCreateID();
                    var weapon = actor as ISkillContainer;
                    weapon.SetRelPosition(0, 0);
                    //Log.Trace("当前发射者 位置:" + container.GetPhysicalinternalBase().GetBody().GetPosition() + " 朝向:" +
                    //container.GetPhysicalinternalBase().GetBody().GetAngle());
                    //Log.Trace("当前武器箱 位置:" + actor.GetInitData().point_x + " " + actor.GetInitData().point_y + " 朝向:" + actor.GetInitData().angle);



                    //level.GetEnvirinfointernalBase().AddActor(weapon as ActorBase);
                    //weapon.StartSkill();
                    var init = weapon.GetInitData();
                    level.AddEventMessagesToHandlerForward(new InitEventMessage(id, actor.GetCamp(), actor.GetActorType(), init.point_x, init.point_y, init.angle, weapon.GetLinerDamping(), ownerid: weapon.GetOwnerID(), relatpoint_x: weapon.GetRelPositionX(), relatpoint_y: weapon.GetRelPositionY(), time: firepro));
                    skillInitList.Add(new UserData(id, weapon.GetActorType()));
                    OnFire?.Invoke(weapon);
                    if (actor.GetActorType() != ActorTypeBaseDefine.ContinuousLaserActor)
                    {
                        skillcd[j] = DateTime.Now.Ticks;
                    }
                }
            }
        }
Пример #27
0
        private void MaybeFireEvent()
        {
            Instant now = clock.GetCurrentInstant();

            if (Monitor.TryEnter(@lock))
            {
                try {
                    if (IsRunning && now - lastExecuted > RateLimit)
                    {
                        OnFire?.Invoke();
                        lastExecuted = now;
                    }
                } finally {
                    Monitor.Exit(@lock);
                }
            }
            // Else do nothing, already executing.
        }
        private void FireProjectile(int index)
        {
            Transform muzzle = Muzzles[index % Muzzles.Length];
            int       amount = Mathf.RoundToInt(Amount);

            for (int i = 0; i < amount; i++)
            {
                GameObject newProjectile    = Instantiate(Projectile, muzzle.position, muzzle.rotation);
                Projectile projectileScript = newProjectile.GetComponent <Projectile>();

                float   rad       = Pricision * Mathf.Deg2Rad;
                Vector2 direction = muzzle.right + muzzle.rotation * (Vector3.up * Mathf.Sin(UnityEngine.Random.Range(-rad, rad)));

                projectileScript.Fire(this, direction, LayerMask, Target, Damage, Range);
                AttachProjectileCallbacks(projectileScript);

                OnProjectileFired?.Invoke(new ProjectileEventInfo(projectileScript));
            }
            OnFire?.Invoke(new FireEventInfo(muzzle, this));
        }
Пример #29
0
                //Hook by replacing method body of ModuleDrill.ControlInput()
                internal static void ControlInput(ModuleDrill module, int aim, int fire)
                {
                    bool shouldFireDefault = (fire != 0);
                    var  shouldFireEvent   = new CanFireEvent <ModuleDrill>(module, shouldFireDefault);

                    CanFire?.Invoke(shouldFireEvent);

                    bool performBehaviour = true;

                    if (shouldFireEvent.Fire)
                    {
                        var fireEvent = new FireEvent <ModuleDrill>(module);
                        OnFire?.Invoke(fireEvent);
                        performBehaviour = fireEvent.PerformVanillaBehaviour;
                    }
                    if (performBehaviour)
                    {
                        module.m_Spinning = shouldFireEvent.Fire;
                    }
                }
Пример #30
0
        public void CustomUpdate()
        {
            _timer += Time.deltaTime;


            if (_user.Character.IsDead)
            {
                return;
            }

            if (_timer >= 0.5f
#if UNITY_EDITOR
                && Input.GetButton("Fire1"))
#else
                && CrossPlatformInputManager.GetButton("Fire"))
#endif
            {
                _timer = 0;
                OnFire?.Invoke();
            }
        }