Example #1
0
        //---------------------------------------------------------------------
        // 玩家请求命中计算
        public void c2sFishHit(uint et_player_rpcid, int bullet_objid, int fish_objid)
        {
            CLogicFish fish = (CLogicFish)mBaseFishLordMgr.getBaseEntity(fish_objid);

            if (fish == null)
            {
                return;
            }
            CLogicTurret turret = mScene.getTurret(et_player_rpcid);

            if (turret == null)
            {
                return;
            }

            CLogicBullet bullet = turret.getBullet(bullet_objid);

            if (bullet == null)
            {
                return;
            }

            // 通知其他模块鱼命中
            mScene.getListener().onLogicSceneFishHit(et_player_rpcid, fish.FishVibId, bullet.getRate());

            _calculateFishScore(et_player_rpcid, turret, fish, bullet.getRate(), bullet_objid);

            turret.removeBullet(bullet_objid);
        }
Example #2
0
        //---------------------------------------------------------------------
        void longFire(float elapsed_tm)
        {
            mfTotalSecond += elapsed_tm;

            if (mfTotalSecond - mfLastFireSecond > mfFireTimeSpan)
            {
                mfLastFireSecond = mfTotalSecond;

                float random = getRandom01();
                if (random < 0.1f)
                {
                    mTurret.c2sEndLongpress();
                    change2observeState();
                }

                int cur_gold = mScene.getListener().onLogicSceneGetPlayerGold(mTurret.getScenePlayerInfo().et_player_rpcid);
                if (cur_gold < mTurret.getTurretRate())
                {
                    mTurret.c2sEndLongpress();
                    change2observeState();
                    return;
                }
                else
                {
                    autoFire();
                }
            }
        }
Example #3
0
        //-------------------------------------------------------------------------
        public void update(float elapsed_tm)
        {
            // 定时向客户端广播消息
            mfTotalSecond += elapsed_tm;
            if (mfTotalSecond - mfLastUpdateSecond > mfUpdateTimeSpan)
            {
                mfLastUpdateSecond = mfTotalSecond;

                // 5Hz同步所有玩家金币
                Dictionary <uint, CLogicTurret> map_turret = mScene.getMapTurret();
                List <string> vec_param_ret = new List <string>();
                vec_param_ret.Add(((byte)_eProtocolDesktop.s2allcSyncAllPlayerGold).ToString());
                vec_param_ret.Add(map_turret.Count.ToString());
                foreach (var turret in map_turret)
                {
                    uint et_player_rpcid = turret.Value.getScenePlayerInfo().et_player_rpcid;
                    vec_param_ret.Add(et_player_rpcid.ToString());
                    int player_gold = mScene.getListener().onLogicSceneGetPlayerGold(et_player_rpcid);
                    vec_param_ret.Add(player_gold.ToString());
                }
                mQueProtocol.Enqueue(vec_param_ret);

                // 5Hz广播协议,每次最多发送10条
                int per_msgcount = 10;
                if (per_msgcount > mQueProtocol.Count)
                {
                    per_msgcount = mQueProtocol.Count;
                }

                List <string> vec_param = new List <string>();
                vec_param.Add(((byte)_eProtocolDesktop.s2allcLogicUpdate).ToString());
                vec_param.Add(per_msgcount.ToString());
                while (per_msgcount > 0)
                {
                    List <string> l = mQueProtocol.Dequeue();
                    vec_param.Add(l.Count.ToString());
                    vec_param.AddRange(l);
                    --per_msgcount;
                }

                mScene.getListener().onLogicScene2RenderAll(vec_param);
            }
        }
Example #4
0
        //---------------------------------------------------------------------
        // 客户端请求手动发炮
        public void c2sManualFire(int bullet_objid, float turret_angle, int turret_rate, int locked_fish_id)
        {
            if (!_canLockFish())
            {
                locked_fish_id = -1;
            }

            // 扣币
            int cur_gold = mScene.getListener().onLogicSceneGetPlayerGold(mPlayer.et_player_rpcid);

            if (cur_gold < turret_rate)
            {
                return;
            }

            cur_gold -= turret_rate;
            mScene.getListener().onLogicSceneSetPlayerGold(mPlayer.et_player_rpcid, cur_gold, -1, "TurretFire", turret_rate);

            mTurretAngle = turret_angle;
            mTurretRate  = turret_rate;

            // 创建子弹
            float        level_cur_second = mScene.getLevel().getCurSecond();
            CLogicBullet bullet           = new CLogicBullet(mScene);

            bullet.create(mPlayer.et_player_rpcid, bullet_objid, mTurretRate,
                          -1, getFirePos(), mTurretAngle, CBulletConstant.ManualSpeed);
            if (!mMapBullet.ContainsKey(bullet_objid))
            {
                mMapBullet[bullet_objid] = bullet;
            }
            else
            {
                bullet.Dispose();
                bullet = null;
            }

            // 服务端广播发炮
            mScene.getProtocol().s2allcManualFire(mPlayer.et_player_rpcid,
                                                  bullet_objid, turret_angle, turret_rate, locked_fish_id);
        }