Exemplo n.º 1
0
    /// <summary>
    /// 地图上设置兵种
    /// </summary>
    private void Build()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                //没有点在UI上
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;

                /*bool hasArmy = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MyArmy"));
                 * Queue<Collider> colliders = new Queue<Collider>();
                 * while (hasArmy)
                 * {
                 *  Collider collider = hit.collider.GetComponent<Collider>();
                 *  collider.enabled = false;
                 *  colliders.Enqueue(collider);
                 *  hasArmy = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapPoint"));
                 * }*/

                bool isCollider = Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("MapPoint"));
                if (isCollider)
                {
                    turnDelegate.Invoke(ref TurnCount);//获取回合数
                    MapPointCtrl mapPointCtrl = hit.collider.GetComponent <MapPointCtrl>();
                    if (selectArmyCard != null && armyPrefab != null)
                    {
                        if (selectArmyCard.Class == ArmyClassType.Hero && hit.collider.tag != "BossStart")
                        {
                            //如果是英雄单位只能箭头处
                            Dispatch(AreoCode.UI, UIEvent.PROMPT_PANEL_EVENTCODE, "英雄单位只能箭头处");
                            return;
                        }
                        else if (selectArmyCard.Class != ArmyClassType.Hero && hit.collider.tag == "BossStart")
                        {
                            Dispatch(AreoCode.UI, UIEvent.PROMPT_PANEL_EVENTCODE, "非英雄单位不能箭头处");
                            return;
                        }

                        if (TurnCount <= 1)
                        {
                            if (hit.collider.tag != "StartAreo" && hit.collider.tag != "Winline" && hit.collider.tag != "BossStart")
                            {
                                //如果第一回合不在屯兵区放置
                                Dispatch(AreoCode.UI, UIEvent.PROMPT_PANEL_EVENTCODE, "初始阶段只能后三排");
                                return;
                            }
                        }
                        else
                        {
                            if (hit.collider.tag != "StartAreo" && hit.collider.tag != "Winline" && hit.collider.tag != "BossStart" && hit.collider.tag != "FeatureArea")
                            {
                                Dispatch(AreoCode.UI, UIEvent.PROMPT_PANEL_EVENTCODE, "只能放置在后五排");
                                return;
                            }
                        }

                        switch (selectArmyCard.MoveType)
                        {
                        case ArmyMoveType.LAND:    //陆地单位
                            if (mapPointCtrl.HasLandArmy())
                            {
                                Dispatch(AreoCode.UI, UIEvent.PROMPT_PANEL_EVENTCODE, "此处已有陆地单位");
                                return;
                            }
                            //放置陆地单位
                            GameObject army;
                            army = mapPointCtrl.SetLandArmy(armyPrefab, true);
                            mapPointCtrl.LandArmyRace = selectArmyCard.Race;
                            mapPointCtrl.LandArmyName = selectArmyCard.Name;
                            //向我的兵种控制器集合添加兵种管理器
                            ArmyCtrl armyctrl = army.GetComponent <ArmyCtrl>();

                            armyctrl.Init(selectArmyCard, mapPointCtrl, army);
                            armyctrl.armyState.MoveType = (ushort)selectArmyCard.MoveType;
                            //更新地图点控制器
                            mapPointCtrl.UpdateLandArmy(army);
                            myArmyCtrls.Add(armyctrl);

                            //向发送发送出牌消息,让其他人消除卡牌
                            socketMsg.Change(OpCode.FIGHT, FightCode.DEAL_ARMYCARD_CREQ, selectArmyCard);
                            Dispatch(AreoCode.NET, NetEvent.SENDMSG, socketMsg);
                            //移除卡牌
                            Dispatch(AreoCode.CHARACTER, CharacterEvent.REMOVE_MY_CARDS, selectArmyCard);
                            //向服务器发送消息
                            pointDto.Change(mapPointCtrl.mapPoint, mapPointCtrl.LandArmyRace, mapPointCtrl.LandArmyName, mapPointCtrl.SkyArmyRace, mapPointCtrl.SkyArmyName);
                            socketMsg.Change(OpCode.FIGHT, FightCode.MAP_SET_ARMY_CREQ, pointDto);
                            Dispatch(AreoCode.NET, NetEvent.SENDMSG, socketMsg);
                            //向发送发送出牌消息,让其他人消除卡牌
                            //socketMsg.Change(OpCode.FIGHT, FightCode.DEAL_CARD_CREQ, "出牌请求");
                            //socketMsg.Change(OpCode.FIGHT, FightCode.DEAL_ARMYCARD_CREQ, selectArmyCard);
                            //Dispatch(AreoCode.NET, NetEvent.SENDMSG, socketMsg);
                            break;

                        case ArmyMoveType.SKY:
                            if (mapPointCtrl.HasSkyArmy())
                            {
                                Dispatch(AreoCode.UI, UIEvent.PROMPT_PANEL_EVENTCODE, "此处已有飞行单位");
                                return;
                            }
                            //放置飞行单位
                            army = mapPointCtrl.SetSkyArmy(armyPrefab, true);
                            //mapPointCtrl.SkyArmyCard = selectArmyCard;
                            mapPointCtrl.SkyArmyRace = selectArmyCard.Race;
                            mapPointCtrl.SkyArmyName = selectArmyCard.Name;

                            //向我的兵种控制器集合添加兵种管理器
                            armyctrl = army.GetComponent <ArmyCtrl>();

                            armyctrl.Init(selectArmyCard, mapPointCtrl, army);
                            armyctrl.armyState.MoveType = (ushort)selectArmyCard.MoveType;
                            //更新地图点控制器
                            mapPointCtrl.UpdateSkyArmy(army);
                            myArmyCtrls.Add(armyctrl);

                            //向发送发送出牌消息,让其他人消除卡牌
                            socketMsg.Change(OpCode.FIGHT, FightCode.DEAL_ARMYCARD_CREQ, selectArmyCard);
                            Dispatch(AreoCode.NET, NetEvent.SENDMSG, socketMsg);
                            //移除卡牌
                            Dispatch(AreoCode.CHARACTER, CharacterEvent.REMOVE_MY_CARDS, selectArmyCard);
                            //向服务器发送消息
                            pointDto.Change(mapPointCtrl.mapPoint, mapPointCtrl.LandArmyRace, mapPointCtrl.LandArmyName, mapPointCtrl.SkyArmyRace, mapPointCtrl.SkyArmyName);
                            socketMsg.Change(OpCode.FIGHT, FightCode.MAP_SET_ARMY_CREQ, pointDto);
                            Dispatch(AreoCode.NET, NetEvent.SENDMSG, socketMsg);

                            /*//向发送发送出牌消息,让其他人消除卡牌
                             * socketMsg.Change(OpCode.FIGHT, FightCode.DEAL_ARMYCARD_CREQ, selectArmyCard);
                             * Dispatch(AreoCode.NET, NetEvent.SENDMSG, socketMsg);*/

                            break;
                        }

                        /*while(colliders.Count != 0)
                         * {
                         *  colliders.Dequeue().enabled = true;
                         * }*/
                        foreach (var item in MyArmyCtrlManager.Instance.CardCtrllist)
                        {
                            item.canBeSeletced = true;//所有单位可交互
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// 处理设置其他人放置兵种
    /// </summary>
    /// <param name="mapPointDto"></param>
    private void processSetOtherArmy(MapPointDto mapPointDto)
    {
        //镜像对称
        int totalX = 12;
        int totalZ = 8;

        int x = mapPointDto.mapPoint.X;
        int z = mapPointDto.mapPoint.Z;

        int otherx = totalX - x;
        int otherz = totalZ - z;//对方兵种真实位置

        MapPointCtrl mapPointCtrl = null;
        GameObject   prefab;

        foreach (var item in MapManager.mapPointCtrls)
        {
            if (item.mapPoint.X == otherx && item.mapPoint.Z == otherz)
            {
                mapPointCtrl = item;
                break;
            }
        }

        //fixbug 放置第二个单位时会额外放置第一个单位
        if (mapPointCtrl)
        {
            //传送的地图数据陆地单位不为空,且该地块上单位为空
            if (mapPointDto.LandArmyRace != -1 && mapPointCtrl.LandArmyRace == -1)
            {
                //陆地单位
                mapPointCtrl.mapPoint.X   = otherx;
                mapPointCtrl.mapPoint.Z   = otherz;
                mapPointCtrl.LandArmyRace = mapPointDto.LandArmyRace;
                mapPointCtrl.LandArmyName = mapPointDto.LandArmyName;
                setArmyPrefab(mapPointCtrl.LandArmyRace, mapPointCtrl.LandArmyName, out prefab);

                GameObject army = mapPointCtrl.SetLandArmy(prefab, false);
                //初始化敌方兵种信息
                army.gameObject.GetComponent <OtherArmyCtrl>().Init(mapPointDto.LandArmyRace, mapPointDto.LandArmyName, mapPointCtrl);
                army.gameObject.GetComponent <OtherArmyCtrl>().armyState.Position = new Protocol.Constants.Map.MapPoint(otherx, otherz);
                //army.gameObject.GetComponent<OtherArmyCtrl>().armyState.CanFly = false;
                army.gameObject.GetComponent <OtherArmyCtrl>().armyState.MoveType = ArmyMoveType.LAND;
                mapPointCtrl.UpdateLandArmy(army);
                //向其他人添加兵种
                Dispatch(AreoCode.ARMY, ArmyEvent.ADD_OTHER_ARMY, army);
            }
            if (mapPointDto.SkyArmyRace != -1 && mapPointCtrl.SkyArmyRace == -1)
            {
                //飞行单位
                mapPointCtrl.mapPoint.X  = otherx;
                mapPointCtrl.mapPoint.Z  = otherz;
                mapPointCtrl.SkyArmyRace = mapPointDto.SkyArmyRace;
                mapPointCtrl.SkyArmyName = mapPointDto.SkyArmyName;
                setArmyPrefab(mapPointCtrl.SkyArmyRace, mapPointCtrl.SkyArmyName, out prefab);

                GameObject army = mapPointCtrl.SetSkyArmy(prefab, false);

                //初始化敌方兵种信息
                army.gameObject.GetComponent <OtherArmyCtrl>().Init(mapPointDto.SkyArmyRace, mapPointDto.SkyArmyName, mapPointCtrl);
                army.gameObject.GetComponent <OtherArmyCtrl>().armyState.Position = new Protocol.Constants.Map.MapPoint(otherx, otherz);
                army.gameObject.GetComponent <OtherArmyCtrl>().armyState.MoveType = ArmyMoveType.SKY;
                mapPointCtrl.UpdateSkyArmy(army);
                Dispatch(AreoCode.ARMY, ArmyEvent.ADD_OTHER_ARMY, army);
            }
        }
    }