예제 #1
0
    private void UpdateMapInfo()
    {
        if (MapMgr.Inited == false)
        {
            return;
        }
        InstanceTableSetting instanceTable = InstanceTableSettings.Get(MapMgr.Instance.InstanceId);

        lblMapName.text      = instanceTable.Name;
        lblMapLayerName.text = I18N.Get(1005001, MapMgr.Instance.CurrentMapLayerData.LayerId);
    }
예제 #2
0
    public override void Handle(object sender, IMessage packet)
    {
        base.Handle(sender, packet);
        GCEnterInstance data = packet as GCEnterInstance;

        //处理完数据和逻辑后,发送消息通知其他模块,绝对不可以直接操作UI等Unity主线程的东西!
        if (data.Result == 0)
        {
            InstanceTableSetting instanceTable = InstanceTableSettings.Get(data.InstanceId);
            if (instanceTable == null)
            {
                Debug.LogError("待进入的场景不存在!" + data.InstanceId);
                return;
            }

            SceneMgr.ChangeScene(instanceTable.SceneId);
            MapMgr.Create(data.InstanceId);
            MapMgr.Instance.MyMapPlayer.Update(data.MapPlayerData);
        }
        else
        {
            Debug.LogError("进入失败!" + data.Result);
        }
    }
예제 #3
0
    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);
    }
예제 #4
0
    public override void Handle(object sender, IMessage packet)
    {
        base.Handle(sender, packet);
        CGEnterInstance data = packet as CGEnterInstance;
        //处理完数据和逻辑后,发送消息通知客户端
        GCEnterInstance      response      = new GCEnterInstance();
        InstanceTableSetting instanceTable = InstanceTableSettings.Get(data.InstanceId);

        if (instanceTable == null)
        {
            response.Result = 1;
            SendToClient(MessageId_Receive.GCEnterInstance, response);
            return;
        }
        response.InstanceId               = data.InstanceId;
        response.Result                   = 0;
        response.MapPlayerData            = new PBMapPlayerData();
        response.MapPlayerData.InstanceId = data.InstanceId;
        response.MapPlayerData.PlayerPosX = Random.Range(0, instanceTable.Width);
        response.MapPlayerData.PlayerPosY = Random.Range(0, instanceTable.Height);

        PBPlayerData playerData = GetSavedData <PBPlayerData>(PLAYER_DATA_KEY);

        response.MapPlayerData.PlayerData               = new PBPlayerData();
        response.MapPlayerData.PlayerData.PlayerId      = playerData.PlayerId;
        response.MapPlayerData.PlayerData.Hp            = playerData.Hp;
        response.MapPlayerData.PlayerData.MaxHp         = playerData.MaxHp;
        response.MapPlayerData.PlayerData.Mp            = playerData.Mp;
        response.MapPlayerData.PlayerData.MaxMp         = playerData.MaxMp;
        response.MapPlayerData.PlayerData.Gold          = 0;
        response.MapPlayerData.PlayerData.Exp           = 0;
        response.MapPlayerData.PlayerData.Level         = 1;
        response.MapPlayerData.PlayerData.CharacterId   = playerData.CharacterId;
        response.MapPlayerData.PlayerData.HeadIcon      = playerData.HeadIcon;
        response.MapPlayerData.PlayerData.MapSkillId    = playerData.MapSkillId;
        response.MapPlayerData.PlayerData.BattleSkillId = playerData.BattleSkillId;
        //response.MapPlayerData.PlayerData.Equips
        if (playerData.Food > instanceTable.FoodMax)
        {
            response.MapPlayerData.PlayerData.Food = response.MapPlayerData.PlayerData.MaxFood = instanceTable.FoodMax;
            playerData.Food = playerData.Food - instanceTable.FoodMax;
        }
        else
        {
            response.MapPlayerData.PlayerData.Food = response.MapPlayerData.PlayerData.MaxFood = playerData.Food;
            playerData.Food = 0;
        }



        //response.MapPlayerData.PlayerData
        response.MapPlayerData.PlayerModelId = ClassCharacterTableSettings.Get(response.MapPlayerData.PlayerData.CharacterId).ModelID;
        PBPlayerDetailData playerDetailData = GetSavedData <PBPlayerDetailData>(PLAYER_DETAIL_DATA_KEY);
        bool exist = false;

        for (int i = 0; i < playerDetailData.Decks.Count; i++)
        {
            if (playerDetailData.Decks[i].Index == data.Deck.Index)
            {
                //更新已有的卡组
                playerDetailData.Decks[i] = data.Deck;
                exist = true;
                break;
            }
        }
        //添加新卡组
        if (exist == false)
        {
            playerDetailData.Decks.Add(data.Deck);
        }
        response.MapPlayerData.Deck = data.Deck;
        response.MapPlayerData.Items.Add(data.Items);
        response.MapPlayerData.Equips.AddRange(data.Equips);
        response.MapPlayerData.Buffs.AddRange(data.Buffs);
        for (int i = 0; i < data.Items.Count; i++)
        {
            playerDetailData.Items.Remove(data.Items[i]);
        }

        SaveData(PLAYER_DATA_KEY, playerData);
        SaveData(PLAYER_DETAIL_DATA_KEY, playerDetailData);
        SaveData(MAP_PLAYER_DATA_KEY, response.MapPlayerData);
        SendToClient(MessageId_Receive.GCEnterInstance, response);
    }