예제 #1
0
    public void RpcShoot()
    {
        var data      = new ShootData();
        var hasBullet = false;
        var type      = (WeaponType)photonView.Owner.GetWeapon();
        var weapon    = GameSetting.Instance.Weapons.Find(x => x.Type == type);

        if (weapon != null && photonView.IsMine)
        {
            var bulletCount = photonView.Owner.GetBulletCount((int)type, weapon.MagCapacity);
            if (bulletCount > 0)
            {
                hasBullet        = true;
                data.BulletCount = bulletCount - 1;
                photonView.Owner.SetBulletCount((int)type, data.BulletCount);
            }
            data.MagCount      = photonView.Owner.GetMagCount((int)type, weapon.MagCount);
            data.CrosshairSize = weapon.CrosshairSize;
        }
        _message.Publish(new MsgData()
        {
            Type = GameConst.MsgShoot, Data = data
        });

        if (hasBullet)
        {
            Fire(weapon, _local.ShootPoint.position, _local.ShootPoint.rotation);
        }
    }
예제 #2
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var index = chunk.GetSharedComponentIndex(launchType);

            var translations = chunk.GetNativeArray(translationType);
            var scales       = chunk.GetNativeArray(scaleType);
            var actions      = chunk.GetNativeArray(actionType);
            var targets      = chunk.GetNativeArray(targetType);

            for (int i = 0; i < chunk.Count; i++)
            {
                var action = actions[i];
                if (!action.out_ActionFlag)
                {
                    continue;
                }

                var shootData = new ShootData()
                {
                    ownerPosition  = translations[i].Value,
                    ownerScale     = scales[i].Value,
                    targetPosition = targets[i].value,
                };

                detectedActions.Add(index, shootData);
            }
        }
예제 #3
0
    /// <summary>
    /// Draws the path of the shoot from source object current position to
    /// target object current position.
    /// </summary>
    /// <param name="source">Source.</param>
    /// <param name="target">Target.</param>
    /// <param name="gravity">Gravity.</param>
    /// <param name="delta_h">The maximum height of the shoot starting from
    /// target y postion.</param>
    public static void DrawPath(Transform source, Transform target,
                                float gravity, float delta_h)
    {
        ShootData shootData = Kinematic.CalculateShoot(source,
                                                       target,
                                                       gravity,
                                                       delta_h);
        Vector3 previousDrawPoint = source.position;

        int resolution = 30;

        for (int i = 1; i <= resolution; i++)
        {
            float   simulationTime = (i / (float)resolution) * shootData.timeToTarget;
            Vector3 displacement   = shootData.initialVelocity * simulationTime
                                     + Vector3.up * gravity
                                     * simulationTime * simulationTime /
                                     2f;
            Vector3 drawPoint = source.position + displacement;

            // TODO Find a way to draw trajectory not only in debug mode (to be
            //      able to visualizing it in the actual scene, not only in Scene tab)
            Debug.DrawLine(previousDrawPoint, drawPoint, Color.green);
            previousDrawPoint = drawPoint;
        }
    }
예제 #4
0
    void OnTakenShot(GameObject subject, ActionType action, Interactable.Data data)
    {
        if (action != ActionType.Shoot)
        {
            return;
        }

        var       rb        = GetComponent <Rigidbody>();
        ShootData shootData = (ShootData)data;

        if (rb && (shootData != null))
        {
            Debug.Log($"{subject.name} shoots {gameObject.name}");
            if (shootData.center)
            {
                rb.AddForce(shootData.force);
            }
            else
            {
                rb.AddForceAtPosition(shootData.force, shootData.position);
            }
        }

        var death = GetComponent <Death>();

        if (death)
        {
            Debug.Log($"{subject.name} kills {gameObject.name}");
            death.Kill(subject);
        }
    }
예제 #5
0
        // PUBLIC METHODS: ------------------------------------------------------------------------

        public bool StartChargedShot(CharacterShooter shooter)
        {
            if (!this.CanStartChargedShoot(shooter))
            {
                return(false);
            }

            shooter.chargeShotStartTime = Time.time;
            shooter.isChargingShot      = true;

            if (this.actionsOnStartCharge)
            {
                ShootData shootData = this.GetShootData(shooter);

                GameObject actionsInstance = Instantiate(
                    this.actionsOnStartCharge.gameObject,
                    shootData.originWeapon,
                    Quaternion.FromToRotation(
                        Vector3.up,
                        shootData.destination - shootData.originWeapon
                        )
                    );

                actionsInstance.hideFlags = HideFlags.HideInHierarchy;
                Actions actions = actionsInstance.GetComponent <Actions>();
                if (actions)
                {
                    actions.Execute(shooter.gameObject, null);
                }
            }

            if (this.aimingMode == AimType.Trajectory)
            {
                if (shooter.trajectoryRenderer)
                {
                    Destroy(shooter.trajectoryRenderer.gameObject);
                }

                this.trajectory.layerMask   = this.layerMask;
                this.trajectory.maxDistance = this.distance;
                this.trajectory.shooter     = shooter;

                Transform parent = (shooter.muzzle != null
                    ? shooter.muzzle.transform
                    : shooter.transform
                                    );

                shooter.trajectoryRenderer = TrajectoryRenderer.Create(this.trajectory, parent);
            }

            shooter.eventChargedShotStart.Invoke(shooter.currentWeapon, this);

            return(true);
        }
예제 #6
0
 private void ChooseFireMode()
 {
     keyUp = false;
     if (currentSightMode == SightType.Ads)
     {
         ShootData shootData = new ShootData(this.gameObject, this, true, centerPoint, fpsCamera);
         currentGun.AdsFire(shootData);
     }
     else
     {
         ShootData shootData = new ShootData(this.gameObject, this, true, centerPoint, fpsCamera);
         currentGun.AdsFire(shootData);
     }
 }
예제 #7
0
    void Shoot(ShootData shootData)
    {
        //		print (shootData.start);

        Vector3 startPos = shootData.start;
        //	startPos.z -= Camera.main.transform.position.z/4f;// - nearPlane.transform.position.z;

        GameObject ball = Instantiate(ballPrefab) as GameObject;//StaticPool.GetObj("red");//ballPrefabDict[shootData.color.ToString()]);
        //ball.GetComponent<Ball>().Reset();

        ball.transform.position = Camera.main.ScreenToWorldPoint(startPos + Camera.main.transform.forward * 4f);
        ball.GetComponent<Rigidbody>().velocity = Vector3.zero;

        Vector3 shootDir = shootData.dest - ball.transform.position;
        shootDir.Normalize();
        ball.GetComponent<Rigidbody>().AddForce(shootDir*shootStrength);
    }
예제 #8
0
    public void Shoot(ShootData shootData)
    {
        if (Time.time - _lastShotTime < SHOOT_INTERVAL_S)
        {
            return;
        }

        GameObject newPaintBall = Instantiate(paintBallPrefab);

        newPaintBall.transform.position = shootData.position;

        Rigidbody rb = newPaintBall.GetComponent <Rigidbody>();

        Vector3 startForce = shootData.direction * SHOOT_FORCE;

        rb.AddForce(startForce, ForceMode.Impulse);

        _lastShotTime = Time.time;
    }
예제 #9
0
    public override void HipFire(ShootData shootData)
    {
        shootData.gunScript.Fire();
        if (shootData.gunScript.currentShootMode == ShootModes.Burst)
        {
            shootData.gunScript.burstCounter++;
        }

        shootData.gunScript.fireTimer   = 0f;
        shootData.gunScript.currentAcc -= shootData.gunScript.currentGun.accuracyDropPerShot;

        if (shootData.gunScript.currentAcc <= 0)
        {
            shootData.gunScript.currentAcc = 10;
        }


        if (shootData.useRecoil)
        {
            AddHipRecoil(shootData.gunObject);
        }
    }
예제 #10
0
        public void StopCharge(CharacterShooter shooter)
        {
            if (!this.actionsOnEndCharge)
            {
                return;
            }
            if (!shooter.isChargingShot)
            {
                return;
            }
            if (this.chargeType == TriggerType.DisableCharge)
            {
                return;
            }

            shooter.isChargingShot = false;
            ShootData shootData = this.GetShootData(shooter);

            GameObject actionsInstance = Instantiate(
                this.actionsOnEndCharge.gameObject,
                shootData.originWeapon,
                Quaternion.FromToRotation(Vector3.up, shootData.destination - shootData.originWeapon)
                );

            actionsInstance.hideFlags = HideFlags.HideInHierarchy;
            Actions actions = actionsInstance.GetComponent <Actions>();

            if (actions)
            {
                actions.Execute(shooter.gameObject, null);
            }
            if (shooter.trajectoryRenderer)
            {
                Destroy(shooter.trajectoryRenderer.gameObject);
            }

            shooter.eventChargedShotStart.Invoke(shooter.currentWeapon, this);
        }
예제 #11
0
    void Shoot(ShootData shootData)
    {
//		print (shootData.start);

        Vector3 startPos = shootData.start;

        if (DebugMode.CENTERSPAWN)
        {
            startPos.z -= Camera.main.transform.position.z / 4f;          // - nearPlane.transform.position.z;
        }
        GameObject ball = StaticPool.GetObj(ballPrefabDict[shootData.color.ToString()]);

        ball.GetComponent <Ball>().Reset();

        ball.transform.position = Camera.main.ScreenToWorldPoint(startPos + Camera.main.transform.forward * 4f);
        ball.GetComponent <Rigidbody>().velocity = Vector3.zero;

        PlayerManager.IncreaseShots(shootData.color);

        Vector3 shootDir = shootData.dest - ball.transform.position;

        shootDir.Normalize();

        if (DebugMode.FORWARDMODE)
        {
            ball.GetComponent <Rigidbody>().AddForce(Vector3.forward * (shootStrength + DebugMode.FORCECHANGE));
        }
        else
        {
            ball.GetComponent <Rigidbody>().AddForce(shootDir * (shootStrength + DebugMode.FORCECHANGE));
        }

//		Debug.Break();

        ball.GetComponent <Rigidbody>().useGravity = DebugMode.GRAVITY;
//		Destroy (ball, 10f);
    }
예제 #12
0
        private void ShootProjectile(CharacterShooter shooter, float deviation,
                                     CharacterShooter.ShotType shotType)
        {
            ShootData  shootData = this.GetShootData(shooter);
            GameObject bullet    = null;
            float      velocity  = 1f;

            if (this.aimingMode == AimType.Crosshair || this.aimingMode == AimType.None)
            {
                Vector3 shootPositionA = shootData.originWeapon;
                Vector3 shootPositionB = shootData.destination;

                shootPositionB += this.CalculateError(
                    shooter.gameObject,
                    shootPositionA,
                    shootPositionB,
                    deviation
                    );

                velocity = this.projectileVelocity;

                bullet = PoolManager.Instance.Pick(this.prefabProjectile);
                bullet.transform.SetPositionAndRotation(
                    shootPositionA,
                    Quaternion.LookRotation(shootPositionB - shootPositionA)
                    );
            }
            else if (this.aimingMode == AimType.Trajectory)
            {
                Vector3 shootPositionA = shootData.originWeapon;

                velocity = Mathf.Lerp(
                    this.trajectory.minVelocity,
                    this.trajectory.maxVelocity,
                    shooter.GetCharge()
                    );

                Vector3 shootDirection = shooter.muzzle.GetDirection();

                bullet = PoolManager.Instance.Pick(this.prefabProjectile);
                bullet.transform.SetPositionAndRotation(
                    shootPositionA,
                    Quaternion.LookRotation(shootDirection)
                    );
            }

            if (bullet)
            {
                Rigidbody bulletRB = bullet.GetComponent <Rigidbody>();
                if (bulletRB)
                {
                    Vector3 direction = bullet.transform.TransformDirection(Vector3.forward);
                    bulletRB.velocity        = Vector3.zero;
                    bulletRB.angularVelocity = Vector3.zero;

                    bulletRB.AddForce(direction * velocity, ForceMode.VelocityChange);
                }

                this.ExecuteShootActions(
                    shooter.gameObject,
                    shooter.muzzle.GetPosition(),
                    shooter.muzzle.GetRotation()
                    );
            }
        }
예제 #13
0
    GameObject Shoot(Vector2 pos)
    {
        //ShootData shootData) {
          RaycastHit hit;
          if(Physics.Raycast(Camera.main.ScreenPointToRay(pos),out hit)){
        ShootData shootData = new ShootData(pos, hit.point);

        Vector3 startPos = shootData.start;
        //	startPos.z -= Camera.main.transform.position.z/4f;// - nearPlane.transform.position.z;

        GameObject ball = Instantiate(ballPrefab) as GameObject;//StaticPool.GetObj("red");//ballPrefabDict[shootData.color.ToString()]);
        //ball.GetComponent<Ball>().Reset();

        ball.transform.position = Camera.main.ScreenToWorldPoint(startPos + Camera.main.transform.forward * 4f);
        ball.GetComponent<Rigidbody>().velocity = Vector3.zero;

        Vector3 shootDir = shootData.dest - ball.transform.position;
        shootDir.Normalize();
        ball.GetComponent<Rigidbody>().AddForce(shootDir*shootStrength);
        return ball;
          }else{
        return null;
          }
    }
 public abstract void AdsFire(ShootData shootData);
예제 #15
0
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            // We own this player: send the others our data
            stream.SendNext(shootsToSend.Count);
            while(shootsToSend.Count>0){
                shootsToSend.Dequeue().PhotonSerialization(stream);
            }
            ///stream.SendNext(transform.rotation);

        }
        else
        {
            // Network player, receive data
            int shootCount = (int) stream.ReceiveNext();
            for(int i=0;i<shootCount;i++){
                ShootData data = new ShootData();
                data.PhotonDeserialization(stream);
                shootsToSpawn.Enqueue(data);
            }
            //this.transform.rotation = (Quaternion) stream.ReceiveNext();

        }
    }
예제 #16
0
 public override void HipFire(ShootData shootData)
 {
     AddHipRecoil(shootData.gunObject);
 }
예제 #17
0
 protected void SendShoot(Vector3 position, Quaternion rotation)
 {
     ShootData send = new ShootData ();
     send.position = position;
     send.direction = rotation;
     send.timeShoot = PhotonNetwork.time;
     shootsToSend.Enqueue (send);
 }
예제 #18
0
        private void ShootGenericCast(CharacterShooter shooter, float deviation,
                                      CharacterShooter.ShotType shotType, CastType castType)
        {
            ShootData shootData = this.GetShootData(shooter);

            Vector3 shootPositionRaycast = shootData.originRaycast;
            Vector3 shootPositionWeapon  = shootData.originWeapon;
            Vector3 shootPositionTarget  = shootData.destination;

            shootPositionTarget += this.CalculateError(
                shooter.gameObject,
                shootPositionRaycast,
                shootPositionTarget,
                deviation
                );

            Vector3 direction = (shootPositionTarget - shootPositionRaycast).normalized;

            int hitCounter = 0;

            switch ((((int)castType) & 2) >> 1)
            {
            case 0:     // Raycast
                hitCounter = Physics.RaycastNonAlloc(
                    shootPositionRaycast, direction, this.bufferCastHits,
                    this.distance, this.layerMask, this.triggersMask
                    );
                break;

            case 1:     // SphereCast
                hitCounter = Physics.SphereCastNonAlloc(
                    shootPositionRaycast, this.radius, direction, this.bufferCastHits,
                    this.distance, this.layerMask, this.triggersMask
                    );
                break;
            }

            int maxCount = Mathf.Min(hitCounter, this.bufferCastHits.Length);

            Array.Sort(this.bufferCastHits, 0, maxCount, SHOT_COMPARE);

            for (int i = 0; hitCounter > 0 && i < maxCount; ++i)
            {
                Vector3 point = this.bufferCastHits[i].point;
                if (this.bufferCastHits[i].distance <= 0.01f && point == Vector3.zero)
                {
                    // special case in which sphere sweep overlaps the initial value:
                    point = shootPositionWeapon + (direction.normalized * 0.1f);
                }

                if (this.bufferCastHits[i].collider.gameObject.Equals(shooter.gameObject))
                {
                    continue;
                }

                Vector3    rotationDirection = (shootPositionWeapon - point).normalized;
                Quaternion rotation          = Quaternion.FromToRotation(Vector3.forward, rotationDirection);

                GameObject other = this.bufferCastHits[i].collider.gameObject;
                this.ExecuteShootActions(other, point, rotation);

                IgniterOnReceiveShot[] igniters = other.GetComponentsInChildren <IgniterOnReceiveShot>();
                foreach (IgniterOnReceiveShot igniter in igniters)
                {
                    if (igniter)
                    {
                        igniter.OnRecevieShot(shooter, shotType);
                    }
                }

                if (!Mathf.Approximately(this.pushForce, 0f) && this.bufferCastHits[i].rigidbody)
                {
                    this.bufferCastHits[i].rigidbody.AddForceAtPosition(
                        -rotationDirection * this.pushForce,
                        point,
                        ForceMode.Impulse
                        );
                }

                shootPositionTarget = point;

                if (this.prefabImpactEffect)
                {
                    GameObject impact = PoolManager.Instance.Pick(this.prefabImpactEffect);
                    impact.transform.SetPositionAndRotation(shootPositionTarget, rotation);
                }

                if ((((int)castType) & 1) == 0)
                {
                    break;
                }
            }

            if (this.shootTrail.useShootingTrail)
            {
                this.shootTrail.position1 = shootPositionWeapon;
                this.shootTrail.position2 = shootPositionTarget;
                ShootingTrailRenderer.Create(this.shootTrail);
            }
        }
 public abstract void HipFire(ShootData shootData);
예제 #20
0
 public override void AdsFire(ShootData shootData)
 {
     AddAdsRecoil(shootData.gunObject);
 }