Beispiel #1
0
        //---------------------------------------------------------------------
        // 服务端广播自动发炮
        public void s2allcAutoFire(uint et_player_rpcid, Queue <_tBullet> que_bullet)
        {
            List <string> vec_param = new List <string>();

            vec_param.Add(((byte)_eProtocolDesktop.s2allcAutoFire).ToString());
            vec_param.Add(et_player_rpcid.ToString());
            vec_param.Add(que_bullet.Count.ToString());
            while (que_bullet.Count > 0)
            {
                _tBullet bullet = que_bullet.Dequeue();
                vec_param.Add(bullet.bullet_objid.ToString());
                vec_param.Add(bullet.turret_angle.ToString());
                vec_param.Add(bullet.turret_rate.ToString());
                vec_param.Add(bullet.locked_fish_objid.ToString());
            }

            mQueProtocol.Enqueue(vec_param);
        }
Beispiel #2
0
        //-------------------------------------------------------------------------
        public override void update(float elapsed_tm)
        {
            if (canDestroy())
            {
                return;
            }

            CRenderLevel level = mScene.getLevel();

            if (level == null)
            {
                signDestroy();
                return;
            }

            bool level_isrun = level.isNormal();

            if (!level_isrun)
            {
                signDestroy();
                return;
            }

            mfTotalSecond += elapsed_tm;

            bool is_me = _isMe();

            if (is_me)
            {
                // 本人发炮,子弹生产者
                if (mfTotalSecond - mfLastFireSecond > mfFireTimeSpan)
                {
                    mfLastFireSecond = mfTotalSecond;

                    if (!InputController.Instance.MouseDown)
                    {
                        signDestroy();
                        return;
                    }

                    if (mTurret.getPlayerGold() < mTurret.getTurretRate())
                    {
                        mTurret.goldNotEnough();
                        return;
                    }

                    if (mTurret.checkWhetherFire())
                    {
                        Vector2 mouse_pos    = InputController.Instance.CurrentMousePosition;
                        int     bullet_objid = mTurret.genBulletObjId(1);
                        mTurret.doLocalFire(mouse_pos, bullet_objid, CBulletConstant.AutoRapidSpeed);

                        _tBullet bullet;
                        bullet.bullet_objid      = bullet_objid;
                        bullet.turret_angle      = mTurret.getTurretAngle();
                        bullet.turret_rate       = mTurret.getTurretRate();
                        bullet.locked_fish_objid = mTurret.getLockFishObjId();
                        mQueBullet.Enqueue(bullet);
                    }

                    if (miLeftBulletObjIdNum > 0)
                    {
                        miLeftBulletObjIdNum--;
                    }
                    else
                    {
                        //signDestroy();

                        // 极速转长按
                        CRenderBufferMgr buf_mgr = mTurret.getBufferMgr();
                        buf_mgr.removeBuffer("BufRapid");
                        if (!buf_mgr.hasBuffer("BufLongpress"))
                        {
                            List <object> param_list = new List <object>();
                            buf_mgr.addBuffer("BufLongpress", param_list);
                        }
                    }
                }
            }
            else
            {
                // 他人发炮,子弹消费者
                if (mfTotalSecond - mfLastFireSecond > mfFireTimeSpan)
                {
                    mfLastFireSecond = mfTotalSecond;

                    if (mQueBullet.Count > 0)
                    {
                        _tBullet bullet = mQueBullet.Dequeue();
                        mTurret.setLockFishByFishObjId(bullet.locked_fish_objid);
                        mTurret.setTurretAngle(bullet.turret_angle);
                        mTurret.setTurretRate(bullet.turret_rate);
                        mTurret.doOtherFire(bullet.bullet_objid, CBulletConstant.AutoRapidSpeed);
                    }
                }
            }

            // 如果是本人,则按5Hz的频率进行自动发炮的网络同步
            if (is_me)
            {
                if (mfTotalSecond - mfLastSyncSecond > mfSyncTimeSpan)
                {
                    mfLastSyncSecond = mfTotalSecond;

                    mScene.getProtocol().c2sAutoFire(mTurret.getScenePlayerInfo().et_player_rpcid, mQueBullet);
                }
            }
        }