コード例 #1
0
        public void InitFire(BaseTank tank, Weapon weapon, LayerTags frendlyLayer)
        {
            if (null == weapon)
            {
                GDebug.LogWarning("Weapon parameters is null", this, LogCategory.FIRE_CONTROLLER);
                return;
            }

            var dl1 = 0f;
            var dl2 = 0f;

            for (int i = 0; i < weapon.MaxBulletInShot; i++)
            {
                _delayService.DelayedCall(dl1, () =>
                {
                    foreach (var point in weapon.GamePointsPool)
                    {
                        if (weapon.InMomentShot)
                        {
                            AddBullet(point, weapon, frendlyLayer);
                        }
                        else
                        {
                            _delayService.DelayedCall(dl2, () => { AddBullet(point, weapon, frendlyLayer); });
                            dl2 += 0.1f;
                        }
                    }
                });

                dl1 += 0.1f;
            }
        }
コード例 #2
0
ファイル: RoomHandler.cs プロジェクト: mengtest/TankTCP
    private void OnNotifyBattleStart(SocketModel model)
    {
        NotifyBattleStart notify = SerializeUtil.Deserialize <NotifyBattleStart>(model.message);

        CacheManager.instance.battleid   = notify.battleid;
        CacheManager.instance.battleType = (EBattle)notify.battleType;
        CacheManager.instance.limitNum   = notify.numberLimit;

        UIManager.instance.CloseAll();

        for (int i = 0; i < notify.tanks.Count; i++)
        {
            //修改缓存
            //CacheManager.instance.tanks.Add(notify.tanks[i]);

            BaseTank tank = null;
            if (notify.tanks[i].id == CacheManager.instance.account)
            {
                //CacheManager.instance.myTank = notify.tanks[i];
                tank = new Tank(notify.tanks[i]);
            }
            else
            {
                tank = new OtherTank(notify.tanks[i]);
            }
            TankManager.instance.AddTank(tank);
        }
    }
コード例 #3
0
    public override void CollisionHandel(GameObject e)
    {
        collisionbase = e.GetComponent <BaseTank>();
        if (collisionbase != null)
        {
            blast();
            collisionbase.onHit(ref counter);
            if (counter <= 0)
            {
                counter = GeneraData.APdamage;
                pool.put(gameObject);
            }
            return;
        }

        if (e.name == "界")
        {
            pool.put(gameObject);
            return;
        }
        counter--;
        blast();
        Destroy(e.gameObject);
        if (counter <= 0)
        {
            counter = GeneraData.APdamage;
            print("撞到" + e.name);
            pool.put(gameObject);
        }
    }
コード例 #4
0
ファイル: Weapon.cs プロジェクト: 9MW/SoundsWER
    public void explosion(GameObject g)
    {
        BaseTank    b      = g.GetComponent <BaseTank>();
        Rigidbody2D physis = g.GetComponent <Rigidbody2D>();

        if (physis != null)
        {
            if (b != null)
            {
                b.onHit(ref damage);
                pool.getGMOBJ(explodEffect, transform);
            }
            else
            {
                pool.getGMOBJ(explodEffect, transform);
                float   dis       = Vector2.Distance(g.transform.position, transform.position);
                Vector2 direction = Vector3.Normalize((g.transform.position - transform.position));
                physis.AddForce(direction * dis);
            }
        }
        else
        {
            pool.getGMOBJ(explodEffect, transform);
        }
    }
コード例 #5
0
ファイル: paodan.cs プロジェクト: 9MW/SoundsWER
    void CollisionHandel(GameObject g)
    {
        switch (g.tag)
        {
        case "tile":
            Destroy(g);
            enemyexplod = pool.getGMOBJ(explod1, transform.position, transform.rotation);
            pool.put(enemyexplod, 0.2f);
            pool.put(gameObject);
            break;

        case "enemy":
            if (gameObject.name == "AIPD")   //no AIPD judgment will destory AI self
            {
                break;
            }
            {
                int z = Random.Range(1, 2);
                smz = g.gameObject.GetComponent <BaseTank>();
                //Debug.Log(z);
                if (z == 1)
                {
                    smz.hp--;
                    if (smz.hp == 0)
                    {
                        enemyexplod = pool.getGMOBJ(explod1, transform.position, transform.rotation);
                        pool.put(enemyexplod, 0.2f);
                        GM.onenemykill(g);    //击杀奖励
                        bullet_source.clip = enemy_killclip;
                        bullet_source.Play();
                        pool.put(gameObject);
                        pool.put(g);
                    }
                    else
                    {
                        bullet_source.clip = enemy_hitClip;
                        bullet_source.Play();
                        pool.put(gameObject);
                    }
                }
                else
                {
                    bullet_source.clip = enemy_hitClip;
                    bullet_source.Play();
                    pool.put(gameObject);
                }
            }
            break;

        default:
            enemyexplod = pool.getGMOBJ(explod1, transform.position, transform.rotation);
            pool.put(gameObject);
            pool.put(enemyexplod, 0.2f);
            Debug.Log("进入default name=" + g.name + " Its tag=" + g.tag);
            break;
        }
    }
コード例 #6
0
ファイル: LandMine.cs プロジェクト: 9MW/SoundsWER
    public void OnTriggerExit2D(Collider2D collision)
    {
        BaseTank bt = collision.GetComponent <BaseTank>();

        if (bt != null && bt.NetworkId == identifer)
        {
            isActived     = true;
            materia.color = Color.red;
        }
    }
コード例 #7
0
    void OnNotifyHit(SocketModel model)
    {
        NotifyHit notify = SerializeUtil.Deserialize <NotifyHit>(model.message);

        BaseTank tank = TankManager.instance.GetTank(notify.id);

        if (tank != null)
        {
            tank.Hurt(notify.damage);
        }
    }
コード例 #8
0
    void OnNotifyMove(SocketModel model)
    {
        NotifyMove notify = SerializeUtil.Deserialize <NotifyMove>(model.message);

        BaseTank tank = TankManager.instance.GetTank(notify.id);

        if (tank != null)
        {
            tank.Move(Tools.ToVec3(notify.pos), Tools.ToVec3(notify.rot));
        }
    }
コード例 #9
0
    void OnNotifyDeath(SocketModel model)
    {
        NotifyDeath notify = SerializeUtil.Deserialize <NotifyDeath>(model.message);

        BaseTank tank = TankManager.instance.GetTank(notify.id);

        if (tank != null)
        {
            tank.Death();
            TankManager.instance.RemoveTank(tank);
        }
    }
コード例 #10
0
ファイル: LandMine.cs プロジェクト: 9MW/SoundsWER
    private void OnTriggerEnter2D(Collider2D collision)
    {
        BaseTank bt = collision.GetComponent <BaseTank>();

        if (isActived)
        {
            explosion(explodEffect);
            pool.put(gameObject);
            print("mine explosion!");
            return;
        }
    }
コード例 #11
0
ファイル: BattleManager.cs プロジェクト: Severn17/UnityLearn
    private static void OnMsgBattleResult(MsgBase msgBase)
    {
        MsgBattleResult msg   = (MsgBattleResult)msgBase;
        bool            isWin = false;
        BaseTank        tank  = GetCtrlTank();

        if (tank != null && tank.camp == msg.winCamp)
        {
            isWin = true;
        }

        PanelManager.Open <ResultPanel>(isWin);
    }
コード例 #12
0
    // Start is called before the first frame update
    void Start()
    {
        GameObject tankObj  = new GameObject("myTank");
        CtrlTank   ctrlTank = tankObj.AddComponent <CtrlTank>();

        ctrlTank.Init("tankPrefab");
        tankObj.AddComponent <CameraFollow>();

        GameObject tankObj2 = new GameObject("myTank");
        BaseTank   baskTank = tankObj2.AddComponent <BaseTank>();

        baskTank.Init("tankPrefab");
        baskTank.transform.position = new Vector3(0, 10, 30);
    }
コード例 #13
0
    //收到击中协议
    public void OnMsgHit(MsgBase msgBase)
    {
        MsgHit msg = (MsgHit)msgBase;

        if (msg.targetId == GameMain.id)
        {
            BaseTank tank = BattleManager.GetCtrlTank();
            if (tank != null)
            {
                ReflashHp(Mathf.CeilToInt(tank.hp));
            }
        }
        ReflashCampInfo();
    }
コード例 #14
0
    //收到玩家退出协议
    public static void OnMsgLeaveBattle(MsgBase msgBase)
    {
        MsgLeaveBattle msg = (MsgLeaveBattle)msgBase;
        //查找坦克
        BaseTank tank = GetTank(msg.id);

        if (tank == null)
        {
            return;
        }
        //删除坦克
        RemoveTank(msg.id);
        MonoBehaviour.Destroy(tank.gameObject);
    }
コード例 #15
0
ファイル: BattleManager.cs プロジェクト: Severn17/UnityLearn
    private static void OnMsgLeaveBattle(MsgBase msgBase)
    {
        MsgLeaveBattle msg = (MsgLeaveBattle)msgBase;
        // 查找坦克
        BaseTank tank = GetTank(msg.id);

        if (tank == null)
        {
            return;
        }

        RemoveTank(msg.id);
        Destroy(tank.gameObject);
    }
コード例 #16
0
    // Use this for initialization
    void Start()
    {
        //坦克
        GameObject tankObj  = new GameObject("myTank");
        CtrlTank   ctrlTank = tankObj.AddComponent <CtrlTank>();

        ctrlTank.Init("Tank");
        //相机
        tankObj.AddComponent <CameraFollow>();
        //被打的坦克
        GameObject tankObj2 = new GameObject("enemyTank");
        BaseTank   baseTank = tankObj2.AddComponent <BaseTank>();

        baseTank.Init("Tank");
        baseTank.transform.position = new Vector3(5, 0, 0);
    }
コード例 #17
0
    //收到战斗结束协议
    public static void OnMsgBattleResult(MsgBase msgBase)
    {
        MsgBattleResult msg = (MsgBattleResult)msgBase;
        //判断显示胜利还是失败
        bool     isWin = false;
        BaseTank tank  = GetCtrlTank();

        if (tank != null && tank.camp == msg.winCamp)
        {
            isWin = true;
        }
        //显示界面
        PanelManager.Open <ResultPanel>(isWin);
        //关闭界面
        PanelManager.Close("AimPanel");
    }
コード例 #18
0
    private void MessageofShot(byte[] buffer, int playerId)
    {
        string[] mg             = NetWorkAdapter.splitString(buffer);
        string   key            = mg[0];
        byte     bulletcategory = byte.Parse(mg[1]);

        if (synchronizationObj.ContainsKey(key))
        {
            BaseTank b = synchronizationObj[key].GetComponent <BaseTank>();
            b.frie(bulletcategory);
        }
        else
        {
            Debug.LogError("KEY " + key + " not exist at sunchronization");
        }
    }
コード例 #19
0
    public void SynchronizationData(GameObject g, SerializeUDP infomation)
    {
        BaseTank operatingObj = g.GetComponent <BaseTank>();

        //  g.transform.position = new Vector3(infomation.x, infomation.y, infomation.z);
        operatingObj.setDirection(infomation.angle);
        if (!destinationList.ContainsKey(g))
        {
            destinationList.Add(g, new Vector3(infomation.x, infomation.y, infomation.z));
        }
        else
        {
            destinationList[g] = new Vector3(infomation.x, infomation.y, infomation.z);
        }
        // SyncPosition(g, new Vector3(infomation.x, infomation.y, infomation.z));
        //operatingObj.frie(infomation.state[0]); abandoned operating
    }
コード例 #20
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        print("touched goods");
        BaseTank TKinstance = collision.GetComponent <BaseTank>();

        if (TKinstance == null)
        {
            return;
        }
        else
        {
            TKinstance.replenishment(cargo);
            if (cargo.fuel == 0 && cargo.shell == 0)
            {
                pool.put(gameObject);
            }
        }
    }
コード例 #21
0
ファイル: ShotCountdownLogic.cs プロジェクト: led318/tank-bot
        public static void PopulateShotCountdownsFromPrevRound()
        {
            if (!State.HasPrevRound)
            {
                return;
            }

            var allTanks     = State.ThisRound.AllTanks;
            var allPrevTanks = State.PrevRound.AllTanks;

            foreach (var tank in allTanks)
            {
                var nearPoints = tank.Point.GetNearPoints(includeThis: true).ToList();

                var nearPrevTanks = allPrevTanks.Where(t => nearPoints.Contains(t.Point)).ToList();

                BaseTank prevTank = null;
                if (nearPrevTanks.Count == 1)
                {
                    prevTank = nearPrevTanks.First();
                }
                else
                {
                    var tankType = tank.GetType();

                    var nearPrevSameTypeTanks = nearPrevTanks.Where(t => t.GetType() == tankType).ToList();

                    if (nearPrevSameTypeTanks.Count == 1)
                    {
                        prevTank = nearPrevSameTypeTanks.First();
                    }
                    else
                    {
                        prevTank = nearPrevSameTypeTanks.FirstOrDefault(t =>
                                                                        t.GetNextPoints(t.Point).Contains(tank.Point));
                    }
                }

                if (prevTank != null)
                {
                    tank.SetShotCountdown(prevTank.ShotCountdownLeft);
                }
            }
        }
コード例 #22
0
    //产生坦克
    public static void GenerateTank(TankInfo tankInfo)
    {
        //GameObject
        string     objName = "Tank_" + tankInfo.id;
        GameObject tankObj = new GameObject(objName);
        //AddComponent
        BaseTank tank = null;

        if (tankInfo.id == GameMain.id)
        {
            tank = tankObj.AddComponent <CtrlTank>();
        }
        else
        {
            tank = tankObj.AddComponent <SyncTank>();
        }
        //camera
        if (tankInfo.id == GameMain.id)
        {
            CameraFollow cf = tankObj.AddComponent <CameraFollow>();
        }
        //属性
        tank.camp = tankInfo.camp;
        tank.id   = tankInfo.id;
        tank.hp   = tankInfo.hp;
        //pos rotation
        Vector3 pos = new Vector3(tankInfo.x, tankInfo.y, tankInfo.z);
        Vector3 rot = new Vector3(tankInfo.ex, tankInfo.ey, tankInfo.ez);

        tank.transform.position    = pos;
        tank.transform.eulerAngles = rot;
        //init
        if (tankInfo.camp == 1)
        {
            tank.Init("tankPrefab");
        }
        else
        {
            tank.Init("tankPrefab2");
        }
        //列表
        AddTank(tankInfo.id, tank);
    }
コード例 #23
0
    //显示
    public override void OnShow(params object[] args)
    {
        //寻找组件
        hpFill    = skin.transform.Find("HpBar/Fill").GetComponent <Image>();
        hpText    = skin.transform.Find("HpBar/HpText").GetComponent <Text>();
        camp1Text = skin.transform.Find("CampInfo/Camp1Text").GetComponent <Text>();
        camp2Text = skin.transform.Find("CampInfo/Camp2Text").GetComponent <Text>();
        ReflashCampInfo();

        NetManager.AddMsgListener("MsgLeaveBattle", OnMsgLeaveBattle);
        NetManager.AddMsgListener("MsgHit", OnMsgHit);

        BaseTank tank = BattleManager.GetCtrlTank();

        if (tank != null)
        {
            ReflashHp(Mathf.CeilToInt(tank.hp));
        }
    }
コード例 #24
0
ファイル: EnemyTankLogic.cs プロジェクト: led318/tank-bot
        private static void CalculateEnemyTankShotPredictions(BaseTank tank)
        {
            if (tank.CurrentDirection.HasValue)
            {
                PredictionLogic.CalculateTankShotPredictions(tank.Point, PredictionType.EnemyShot, tank.CurrentDirection.Value, tank, AppSettings.EnemyTankShotPredictionDepth);
            }

            var directions = BaseMobile.ValidDirections;

            foreach (var direction in directions)
            {
                var point = tank.Point.Shift(direction);
                var cell  = Field.GetCell(point);
                if (cell.CanMove)
                {
                    PredictionLogic.CalculateTankShotPredictions(point, PredictionType.EnemyShot, direction, tank, AppSettings.EnemyTankShotPredictionDepth);
                }
            }
        }
コード例 #25
0
ファイル: CalculationLogic.cs プロジェクト: led318/tank-bot
        private static bool ChoseKamikazeTarget(List <BaseTank> tanks)
        {
            var myTank     = State.ThisRound.MyTank;
            var nearPoints = myTank.Point.GetNearPoints();

            var      nearTanks = tanks.Where(x => nearPoints.Contains(x.Point)).ToList();
            BaseTank nearTank  = null;

            if (nearTanks.Count() > 1)
            {
                foreach (var tank in nearTanks)
                {
                    var directionToMe = tank.Point.CalculateDirectionToPoint(myTank.Point);
                    if (tank.Direction != directionToMe)
                    {
                        continue;
                    }

                    nearTank = tank;
                }
            }

            if (nearTank == null)
            {
                nearTank = nearTanks.FirstOrDefault();
            }

            if (nearTank != null)
            {
                var direction = myTank.Point.CalculateDirectionToPoint(nearTank.Point);

                if (myTank.Direction != direction)
                {
                    State.ThisRound.CurrentMoveCommands.Add(direction);
                }

                State.ThisRound.CurrentMoveCommands.Add(Direction.Act);
                return(true);
            }

            return(false);
        }
コード例 #26
0
ファイル: Sever.cs プロジェクト: 9MW/SoundsWER
    //process incoming position data
    public override void processMessage(byte[] Udpdata, IPEndPoint ipinfo)
    {
        /* print("ipinfo.Address.ToString() " + ipinfo.Address.ToString() );
         * Debug.Log(
         *   " IpToObj[ipinfo.Address.ToString()]="+IpToObj[ipinfo.Address.ToString()].ToString());
         */
        if (!IPtoId.ContainsKey(ipinfo))
        {
            string address = ipinfo.Address.ToString();
            int    IPid    = int.Parse(address.Split('.')[3]);
            IPtoId.Add(ipinfo, IPid + 1);
        }
        obj = synchronizationObj["玩家1" + IPtoId[ipinfo]];
        SerializeUDP clientInfo = (SerializeUDP)BytesToOBJ(Udpdata);

        operatingObj = obj.GetComponent <BaseTank>();
        // obj.transform.position = new Vector3(clientInfo.x, clientInfo.y,clientInfo.z);
        SyncPosition(operatingObj.transform.gameObject, new Vector3(clientInfo.x, clientInfo.y, clientInfo.z));
        operatingObj.setDirection(clientInfo.angle);
    }
コード例 #27
0
    //收到击中协议
    public static void OnMsgHit(MsgBase msgBase)
    {
        MsgHit msg = (MsgHit)msgBase;
        //查找坦克
        BaseTank tank = GetTank(msg.targetId);

        if (tank == null)
        {
            return;
        }
        bool isDie = tank.IsDie();

        //被击中
        tank.Attacked(msg.damage);
        //击杀提示
        if (!isDie && tank.IsDie() && msg.id == GameMain.id)
        {
            PanelManager.Open <KillPanel>();
        }
    }
コード例 #28
0
ファイル: Bullet.cs プロジェクト: Severn17/UnityLearn
    private void SendMsgHit(BaseTank tank, BaseTank hitTank)
    {
        if (hitTank == null || hitTank == null)
        {
            return;
        }
        // 不是自己发射的炮弹
        if (tank.id != GameMain.id)
        {
            return;
        }
        MsgHit msg = new MsgHit();

        msg.targetId = hitTank.id;
        msg.id       = tank.id;
        msg.x        = transform.position.x;
        msg.y        = transform.position.y;
        msg.z        = transform.position.z;
        NetManager.Send(msg);
    }
コード例 #29
0
        private static BaseTank CalculateNearestTank(Bullet bullet, int delta = 1)
        {
            var nearPoints = bullet.Point.GetNearPoints(delta).ToList();


            var currentRoundNearTanks = State.ThisRound.AllTanks
                                        .Where(t => nearPoints.Contains(t.Point)).ToList();

            BaseTank foundCurrentRoundNearTank = null;

            if (currentRoundNearTanks.Count() == 1)
            {
                foundCurrentRoundNearTank = currentRoundNearTanks.First();
            }
            else
            {
                foundCurrentRoundNearTank = currentRoundNearTanks
                                            .FirstOrDefault(p => p.GetNextPoints(p.Point).Last() == bullet.Point);
            }

            return(foundCurrentRoundNearTank);
        }
コード例 #30
0
ファイル: Bullet.cs プロジェクト: Severn17/UnityLearn
    private void OnCollisionEnter(Collision other)
    {
        // 打到坦克
        GameObject collObj = other.gameObject;
        BaseTank   hitTank = collObj.GetComponent <BaseTank>();

        if (hitTank == tank)
        {
            return;
        }

        if (hitTank != null)
        {
            SendMsgHit(tank, hitTank);
            //hitTank.Attacked(35);
        }

        GameObject explode = ResManager.LoadPrefab("fire");

        Instantiate(explode, transform.position, transform.rotation);
        Destroy(gameObject);
    }