示例#1
0
 public void CreateModel(MapCardPos pos = null)
 {
     if (CurPos == null)
     {
         CurPos = pos;
     }
     ResourceManager.LoadGameObject(ModelTableSettings.Get(ClassCharacterTableSettings.Get(m_Data.ClassData.CharacterID).ModelID).Path, LoadPlayerSuccess,
                                    (str, obj) => { Debug.LogError("Load player Failed!"); }
                                    );
 }
示例#2
0
 public void Update(PBMapPlayerData mapPlayerData)
 {
     CurPos = new MapCardPos(mapPlayerData.PlayerPosX, mapPlayerData.PlayerPosY);
     if (m_Data.Id == MapMgr.Instance.MyMapPlayer.Data.Id && m_Data.HP > mapPlayerData.PlayerData.Hp && mapPlayerData.PlayerData.Food == 0)
     {
         //食物没有了,扣血
         Messenger.Broadcast(MessageId.MAP_PLAYER_NO_FOOD_DAMAGE);
     }
     m_InstanceId = mapPlayerData.InstanceId;
     m_Data.Update(mapPlayerData);
     if (m_Data.HP <= 0)
     {
         Messenger.BroadcastAsync <ulong>(MessageId.MAP_PLAYER_DEAD, m_Data.Id);
     }
 }
示例#3
0
 public override bool Equals(object obj)
 {
     if (obj == null)
     {
         return(false);
     }
     if (obj is MapCardPos)
     {
         MapCardPos other = obj as MapCardPos;
         if (other.X == X && other.Y == Y)
         {
             return(true);
         }
     }
     return(false);
 }
示例#4
0
    //static string MapCardPlayer = "MapCardPlayer";

    public static MapCardBase CreateMapCard <T>(MapCardPos pos = null, CardState defaultState = CardState.None) where T : MapCardBase, new()
    {
        MapCardBase mapCard = new T();

        if (pos != null)
        {
            mapCard.pos = new MapCardPos(pos.X, pos.Y);
        }
        if (defaultState != CardState.None)
        {
            mapCard.state = defaultState;
        }
        ResourceManager.LoadGameObject("MapCard/" + typeof(T).ToString(), LoadAssetSuccessess, LoadAssetFailed, mapCard);

        return(mapCard);
    }
示例#5
0
    public void MoveTo(MapCardPos pos)
    {
        if (MapMgr.Instance.GetMapCard(CurPos.X, CurPos.Y) != null)
        {
            MapMgr.Instance.GetMapCard(CurPos.X, CurPos.Y).PlayerExit();
        }
        Vector3 direction = (new Vector3(pos.X - CurPos.X, 0f, pos.Y - CurPos.Y)).normalized;

        CurPos = pos;
        TweenPosition.Begin(m_gameObject, 0.5f, MapMgr.Instance.GetTransfromByPos(pos), true);
        //Quaternion quaternion = Quaternion.FromToRotation(m_gameObject.transform.forward, direction);
        m_gameObject.transform.localRotation = Quaternion.LookRotation(direction);
        MapCardBase mapcard = MapMgr.Instance.GetMapCard(pos.X, pos.Y);

        if (mapcard != null)
        {
            mapcard.State = MapCardBase.CardState.Front;
            mapcard.PlayerEnter();
        }
    }
示例#6
0
    public static MapCardBase GetRandomMapCard(MapCardPos pos = null, CardState defaultState = CardState.None)
    {
        string cardType = MapCardName[Random.Range(0, MapCardName.Length)];

        if (Random.Range(0, 100) % 3 == 0)
        {
            cardType = "MapCardMonster";
        }
        MapCardBase mapCard = Assembly.GetExecutingAssembly().CreateInstance(cardType) as MapCardBase;

        if (pos != null)
        {
            mapCard.pos = new MapCardPos(pos.X, pos.Y);
        }
        if (defaultState != CardState.None)
        {
            mapCard.state = defaultState;
        }
        ResourceManager.LoadGameObject("MapCard/" + cardType, LoadAssetSuccessess, LoadAssetFailed, mapCard);
        return(mapCard);
    }
示例#7
0
 public MapCardBase this[MapCardPos pos]
 {
     get { return(MapPointDatas[pos.X, pos.Y]); }
     set { MapPointDatas[pos.X, pos.Y] = value; }
 }
示例#8
0
    public static MapCardBase CreateMapCard(MapCardType mapCardType, int mapcardId, MapCardPos pos)
    {
        MapCardBase         mapCard      = null;
        MapCardTableSetting mapCardTable = MapCardTableSettings.Get(mapcardId);

        if (mapCardTable == null)
        {
            return(null);
        }
        ModelTableSetting model = ModelTableSettings.Get(mapCardTable.ModelId);

        if (model == null)
        {
            return(null);
        }
        switch (mapCardType)
        {
        case MapCardType.None:
            break;

        case MapCardType.Door:
            mapCard           = new MapCardDoor();
            mapCard.Position  = pos;
            mapCard.State     = MapCardBase.CardState.Behind;
            mapCard.CardType  = mapCardType;
            mapCard.TableData = mapCardTable;
            ResourceManager.LoadGameObject("MapCard/" + typeof(MapCardDoor).ToString(), LoadAssetSuccessess, LoadAssetFailed, mapCard);
            break;

        case MapCardType.Monster:
            BattleMonsterTableSetting battleMonster = BattleMonsterTableSettings.Get(mapcardId);
            //model = ModelTableSettings.Get(battleMonster.ModelId);
            mapCard           = new MapCardMonster();
            mapCard.Position  = pos;
            mapCard.State     = MapCardBase.CardState.Behind;
            mapCard.CardType  = mapCardType;
            mapCard.TableData = mapCardTable;
            ResourceManager.LoadGameObject(model.Path, LoadAssetSuccessess, LoadAssetFailed, mapCard);
            break;

        case MapCardType.Shop:
            ShopTableSetting shopTable = ShopTableSettings.Get(mapcardId);
            //model = ModelTableSettings.Get(shopTable.ModelId);
            mapCard           = new MapCardShop();
            mapCard.Position  = pos;
            mapCard.State     = MapCardBase.CardState.Behind;
            mapCard.CardType  = mapCardType;
            mapCard.TableData = mapCardTable;
            ResourceManager.LoadGameObject(model.Path, LoadAssetSuccessess, LoadAssetFailed, mapCard);
            break;

        case MapCardType.Box:
            BoxTableSetting boxTable = BoxTableSettings.Get(mapcardId);
            //model = ModelTableSettings.Get(boxTable.ModelId);
            mapCard           = new MapCardBox();
            mapCard.Position  = pos;
            mapCard.State     = MapCardBase.CardState.Behind;
            mapCard.CardType  = mapCardType;
            mapCard.TableData = mapCardTable;
            ResourceManager.LoadGameObject(model.Path, LoadAssetSuccessess, LoadAssetFailed, mapCard);
            break;

        case MapCardType.NPC:
            NpcTableSetting npcTable = NpcTableSettings.Get(mapcardId);
            //model = ModelTableSettings.Get(npcTable.ModelId);
            mapCard           = new MapCardNpc();
            mapCard.Position  = pos;
            mapCard.State     = MapCardBase.CardState.Behind;
            mapCard.CardType  = mapCardType;
            mapCard.TableData = mapCardTable;
            ResourceManager.LoadGameObject(model.Path, LoadAssetSuccessess, LoadAssetFailed, mapCard);
            break;

        default:
            break;
        }

        return(mapCard);
    }
示例#9
0
    public Vector3 GetTransfromByPos(MapCardPos pos)
    {
        Vector3 position = new Vector3((pos.X - 2) * 2f, 0.25f, (pos.Y - 2) * 2f);

        return(position);
    }
示例#10
0
    void MakeMap(int layerId)
    {
        MapCardBase playerDoorCard = null;

        if (currentMapLayerData != null)
        {
            if (lastMapLayerData != null)
            {
                for (int i = 0; i < ConstValue.MAP_WIDTH; i++)
                {
                    for (int j = 0; j < ConstValue.MAP_HEIGHT; j++)
                    {
                        if (lastMapLayerData[i, j] != null && lastMapLayerData[i, j] != currentMapLayerData[i, j])
                        {
                            lastMapLayerData[i, j].Destory();
                        }
                    }
                }
            }
            lastMapLayerData = currentMapLayerData;
            for (int i = 0; i < ConstValue.MAP_WIDTH; i++)
            {
                for (int j = 0; j < ConstValue.MAP_HEIGHT; j++)
                {
                    //共用传送门
                    if (i == m_MyMapPlayer.CurPos.X && j == m_MyMapPlayer.CurPos.Y)
                    {
                        playerDoorCard = lastMapLayerData[i, j];
                    }
                    else if (lastMapLayerData[i, j] != null)
                    {
                        lastMapLayerData[i, j].ExitMap();
                    }
                }
            }
        }
        MapLayerData layerData = new MapLayerData(layerId, 5, 5);

        currentMapLayerData = layerData;
        List <MapCardBase> mapCards = new List <MapCardBase>();
        int cardCount = Random.Range(10, 15);

        //先确定出生点
        {
            if (playerDoorCard == null)
            {
                playerDoorCard = MapCardBase.CreateMapCard <MapCardDoor>(m_MyMapPlayer.CurPos, MapCardBase.CardState.Front);
            }
            mapCards.Add(playerDoorCard);
            layerData[playerDoorCard.X, playerDoorCard.Y] = playerDoorCard;
            playerDoorCard.SetUsed(true);
            playerDoorCard.SetActive(true);
            playerDoorCard.SetParent(MapCardRoot.transform);
        }
        for (int i = 1; i < cardCount; i++)
        {
            MapCardPos pos = mapCards[Random.Range(0, i)].Position;

            List <MapCardPos> poss = layerData.GetNearEmptyPoss(pos.X, pos.Y);

            if (poss.Count == 0)
            {
                i--;
                continue;
            }
            int count = Random.Range(0, poss.Count - 1);
            pos = poss[count];
            mapCards.Add(MapCardBase.GetRandomMapCard(pos, MapCardBase.CardState.Behind));
            layerData[mapCards[i].X, mapCards[i].Y] = mapCards[i];
            mapCards[i].SetActive(true);
            mapCards[i].SetParent(MapCardRoot.transform);
        }
        //创建出口
        {
            MapCardPos pos = mapCards[Random.Range(0, cardCount)].Position;

            List <MapCardPos> poss = layerData.GetNearEmptyPoss(pos.X, pos.Y);

            while (poss.Count == 0)
            {
                pos  = mapCards[Random.Range(0, cardCount)].Position;
                poss = layerData.GetNearEmptyPoss(pos.X, pos.Y);
            }
            int count = Random.Range(0, poss.Count - 1);
            pos = poss[count];
            MapCardBase door = MapCardBase.CreateMapCard <MapCardDoor>(pos, MapCardBase.CardState.Behind);
            mapCards.Add(door);
            layerData[door.X, door.Y] = door;
            door.SetActive(true);
            door.SetParent(MapCardRoot.transform);
        }
    }
    public override void Handle(object sender, IMessage packet)
    {
        base.Handle(sender, packet);
        CGGetMapLayerData data = packet as CGGetMapLayerData;
        //处理完数据和逻辑后,发送消息通知客户端
        GCGetMapLayerData    response      = new GCGetMapLayerData();
        InstanceTableSetting instanceTable = InstanceTableSettings.Get(data.InstanceId);

        //层数从第一层开始
        if (instanceTable.LayerMax < data.LayerIndex)
        {
            response.Result = 1;
            SendToClient(MessageId_Receive.GCGetMapLayerData, response);
            return;
        }
        InstanceLayerTableSetting layerTableSetting = InstanceLayerTableSettings.Get(instanceTable.Layers[Random.Range(0, instanceTable.Layers.Count)]);


        MapLayerData layerData = new MapLayerData(data.LayerIndex, instanceTable.Width, instanceTable.Height);

        int[,] mapType = new int[instanceTable.Width, instanceTable.Height];
        int[,] mapID   = new int[instanceTable.Width, instanceTable.Height];
        List <MapCardPos> mapCards = new List <MapCardPos>();
        int cardCount = Random.Range(layerTableSetting.MinCount, layerTableSetting.MaxCount + 1);

        //先确定出生点
        {
            MapCardPos playerDoorCard = new MapCardPos(data.PlayerX, data.PlayerY);
            mapCards.Add(playerDoorCard);
            layerData[playerDoorCard] = new MapCardBase();
            mapType[playerDoorCard.X, playerDoorCard.Y] = (int)MapCardType.Door;
        }
        for (int i = 1; i < cardCount; i++)
        {
            MapCardPos pos = mapCards[Random.Range(0, i)];

            List <MapCardPos> poss = layerData.GetNearEmptyPoss(pos.X, pos.Y);

            if (poss.Count == 0)
            {
                i--;
                continue;
            }
            int count = Random.Range(0, poss.Count - 1);
            pos = poss[count];
            mapCards.Add(pos);
            layerData[pos]        = new MapCardBase();
            mapType[pos.X, pos.Y] = Random.Range((int)MapCardType.Monster, (int)MapCardType.NPC + 1);
        }
        //创建出口
        {
            MapCardPos pos = mapCards[Random.Range(0, cardCount)];

            List <MapCardPos> poss = layerData.GetNearEmptyPoss(pos.X, pos.Y);

            while (poss.Count == 0)
            {
                pos  = mapCards[Random.Range(0, cardCount)];
                poss = layerData.GetNearEmptyPoss(pos.X, pos.Y);
            }
            int count = Random.Range(0, poss.Count - 1);
            pos = poss[count];
            mapCards.Add(pos);
            layerData[pos]        = new MapCardBase();
            mapType[pos.X, pos.Y] = (int)MapCardType.Door;
        }
        for (int i = 0; i < mapCards.Count; i++)
        {
            MapCardPos pos = new MapCardPos(mapCards[i].X, mapCards[i].Y);
            switch ((MapCardType)mapType[pos.X, pos.Y])
            {
            case MapCardType.None:
                mapID[pos.X, pos.Y] = 0;
                break;

            case MapCardType.Door:
                mapID[pos.X, pos.Y] = 2;
                break;

            case MapCardType.Monster:
                mapID[pos.X, pos.Y] = layerTableSetting.Monsters[Random.Range(0, layerTableSetting.Monsters.Count)];
                break;

            case MapCardType.Shop:
                mapID[pos.X, pos.Y] = layerTableSetting.Shop[Random.Range(0, layerTableSetting.Shop.Count)];
                break;

            case MapCardType.Box:
                mapID[pos.X, pos.Y] = layerTableSetting.Box[Random.Range(0, layerTableSetting.Box.Count)];
                break;

            case MapCardType.NPC:
                mapID[pos.X, pos.Y] = layerTableSetting.NPC[Random.Range(0, layerTableSetting.NPC.Count)];
                break;

            default:
                break;
            }
        }
        response.Result           = 0;
        response.LayerData        = new PBMapLayerData();
        response.LayerData.Index  = data.LayerIndex;
        response.LayerData.Height = instanceTable.Width;
        response.LayerData.Width  = instanceTable.Height;
        for (int i = 0; i < instanceTable.Width; i++)
        {
            for (int j = 0; j < instanceTable.Height; j++)
            {
                response.LayerData.PointTypes.Add(mapType[i, j]);
                response.LayerData.PointIds.Add(mapID[i, j]);
                response.LayerData.PointState.Add(0);
            }
        }
        response.LayerData.PointState[data.PlayerX + data.PlayerY * instanceTable.Width] = 1;
        SaveData(MAP_LAYER_DATA_KEY, response.LayerData);
        SendToClient(MessageId_Receive.GCGetMapLayerData, response);
    }
示例#12
0
 public MapPointData(MapCardPos cardPos, MapCardType cardType, int dataId)
 {
     Pos = cardPos;
     CardType = cardType;
     DataId = dataId;
 }