Example #1
0
    private void GenerateRandomItem()
    {
        EMapItem nextItemType = GetNextMapItemType();

        if (DebugData.TestGameEffect != EGameEffect.None)
        {
            nextItemType = EMapItem.GameEffect;
        }
        else if (DebugData.TestPowerUp != EPowerUp.None)
        {
            nextItemType = EMapItem.PowerUp;
        }
        else if (DebugData.TestGenerateMapWeapon != EWeaponId.None)
        {
            nextItemType = EMapItem.Weapon;
        }
        else if (DebugData.TestGenerateMapSpecialWeapon != EWeaponId.None)
        {
            nextItemType = EMapItem.SpecialWeapon;
        }

        int     randomIndex  = GetRandomItemIndex(nextItemType);
        Vector2?randomGenPos = game.Map.ActiveMap.GetRandomPosition();

        if (randomGenPos == null)
        {
            Debug.Log("Skipping GenerateRandomItem");
            return;
        }
        MapItem newItem = InstanceFactory.Instantiate(mapItemPrefab.gameObject).GetComponent <MapItem>();

        Vector2 randomPosition = (Vector2)randomGenPos;

        switch (nextItemType)
        {
        case EMapItem.GameEffect:
            newItem.Init(randomPosition, MapItem.EType.GameEffect, randomIndex);

            break;

        case EMapItem.PowerUp:
        case EMapItem.PowerUp2:
        case EMapItem.PowerUp3:
            //if(DebugData.TestPowerUp != EPowerUp.None)
            //	randomIndex = (int)DebugData.TestPowerUp;

            newItem.Init(randomPosition, MapItem.EType.PowerUp, randomIndex);
            break;

        case EMapItem.Weapon:
        case EMapItem.Weapon2:
            newItem.Init(randomPosition, MapItem.EType.Weapon, randomIndex);
            break;

        case EMapItem.SpecialWeapon:
            newItem.Init(randomPosition, MapItem.EType.SpecialWeapon, randomIndex);
            break;
        }
    }
Example #2
0
    //地图分为3个层次:
    //1,整个地图map
    //2,地图块MapItem,组成map的元素,移动以及旋转以mapItem为单位
    //3,瓷砖tile,组成mapItem的元素,方块

    /// <summary>
    /// 根据配置文件动态创建地图
    /// </summary>
    /// <param name="mapPath"></param>
    public void ReadJsonAndInit(string mapPath)
    {
        string   jsonText = ResourcesManager.Instance.LoadAssetByFullName <TextAsset>(mapPath).text;
        JsonData rootData = JsonMapper.ToObject(jsonText);

        tileWidth = (float)(double)rootData["Width"];
        jumpWidth = PlayerModel.Instance.Speed * PlayerModel.Instance.StandJumpTime;

        //用来控制地图生成的位置与方向
        mapCreatePoint          = new GameObject("MapCreatePoint").transform;
        mapCreatePoint.position = new Vector3(0, -0.18f, 0);
        mapCreatePoint.forward  = Vector3.forward;
        //地图元素的父物体
        mapParent          = new GameObject("MapParent").transform;
        mapParent.position = mapCreatePoint.position;

        JsonData maps = rootData["Map"];

        foreach (JsonData map in maps)
        {
            MapItem mapItem = new MapItem();
            mapItem.Init(this);
            mapItem.CreateMapItem(map);
            mapItems.Add(mapItem);
        }
    }
Example #3
0
    public void RefreshFlyPoint()
    {
        List <FlyPointRef> flyPointList = ConfigMng.Instance.GetFlyPointRefByScene(curScene);

        // List<FlyPoint> flys = GameCenter.curGameStage.GetFlypoints();
        for (int i = 0; i < flyPointList.Count; i++)
        {
            GameObject myPoint = Instantiate(flyPointInstance) as GameObject;
            myPoint.SetActive(true);
            myPoint.transform.parent        = mapCtrl.transform;
            myPoint.transform.localScale    = Vector3.one;
            myPoint.transform.localPosition = new Vector3(flyPointList[i].sceneVector.x * posXRate, flyPointList[i].sceneVector.z * posYRate, 0);
            flyPointDic.Add(flyPointList[i].id, myPoint);
            MapItem item = myPoint.GetComponent <MapItem>();
            if (item != null)
            {
                item.Init(flyPointList[i].name, new Vector3(flyPointList[i].sceneVector.x, flyPointList[i].sceneVector.z), flyPointList[i].scene);
                if (item.Obj != null)
                {
                    UIEventListener.Get(item.Obj).onClick -= OnClickMapItem;
                    UIEventListener.Get(item.Obj).onClick += OnClickMapItem;
                }
            }
        }
    }
Example #4
0
    protected void RefreshNpc()
    {
        List <NPCAIRef> NpcList = ConfigMng.Instance.GetNPCAIRefByScene(curScene);

        //List<NPC> npcs = GameCenter.curGameStage.GetNPCs();
        for (int i = 0; i < NpcList.Count; i++)
        {
            GameObject myPoint = null;
            myPoint = Instantiate(npcNoTaskPointInstance) as GameObject;
            myPoint.SetActive(true);
            myPoint.transform.parent        = mapCtrl.transform;
            myPoint.transform.localScale    = Vector3.one;
            myPoint.transform.localPosition = new Vector3(NpcList[i].sceneX * posXRate, NpcList[i].sceneY * posYRate, 0);
            npcPointDic.Add(NpcList[i].npcId, myPoint);
            MapItem item = myPoint.GetComponent <MapItem>();
            if (item != null)
            {
                item.Init(ConfigMng.Instance.GetNPCTypeRef(NpcList[i].npcId).name, new Vector3(NpcList[i].pointX, NpcList[i].pointY), NpcList[i].scene);
                if (item.Obj != null)
                {
                    UIEventListener.Get(item.Obj).onClick -= OnClickMapItem;
                    UIEventListener.Get(item.Obj).onClick += OnClickMapItem;
                }
            }
        }
    }
Example #5
0
    public void RefreshFlyMonster()
    {
        List <MonsterDistributionRef> list = ConfigMng.Instance.GetMonsterDistributionRefByScene(curScene);

        for (int i = 0; i < list.Count; i++)
        {
            GameObject myPoint = Instantiate(monsterInstance) as GameObject;
            myPoint.SetActive(true);
            myPoint.transform.parent        = mapCtrl.transform;
            myPoint.transform.localScale    = Vector3.one;
            myPoint.transform.localPosition = new Vector3(list[i].position.x * posXRate, list[i].position.z * posYRate, 0);
            mobPointDic.Add(list[i].monsterId, myPoint);
            MapItem item = myPoint.GetComponent <MapItem>();
            if (item != null)
            {
                if (list[i].refreshObjType == 2)
                {
                    SceneItemDisRef dis = ConfigMng.Instance.GetSceneItemDisRef(list[i].monsterId);
                    if (dis != null)
                    {
                        SceneItemRef S = ConfigMng.Instance.GetSceneItemRef(dis.sceneItemId);
                        if (S != null)
                        {
                            string moName = S.name;
                            item.Init(moName, new Vector3(list[i].position.x, list[i].position.z), list[i].sceneId);
                        }
                    }
                }
                else
                {
                    MonsterRef R = ConfigMng.Instance.GetMonsterRef(list[i].monsterId);
                    if (R != null)
                    {
                        string moName = R.name + "(" + R.lv + "级)";
                        item.Init(moName, new Vector3(list[i].position.x, list[i].position.z), list[i].sceneId);
                    }
                }
                if (item.Obj != null)
                {
                    UIEventListener.Get(item.Obj).onClick -= OnClickMapItem;
                    UIEventListener.Get(item.Obj).onClick += OnClickMapItem;
                }
            }
        }
    }
Example #6
0
    private void TryGenerateItem(EMapItem pItem, bool pForce = false)
    {
        Vector3?pos = game.MapController.GetItemSpawnPosition(pItem);

        if (pos == null)
        {
            return;
        }

        if (!lastGenerated.ContainsKey(pItem) || (lastGenerated.ContainsKey(pItem) && lastGenerated[pItem] == null))
        {
            pForce = true;
        }

        //todo: define chance to generate
        if (!debug_AlwayGenerate && !pForce && Random.Range(0, 1f) > 0.5f)
        {
            return;
        }



        //Debug.Log($"Generate item {type} at {pos}");

        MapItem itemInstance = Instantiate(mapItemPrefab, (Vector3)pos, Quaternion.identity);

        itemInstance.transform.parent = transform;
        itemInstance.Init(pItem);

        if (lastGenerated.ContainsKey(pItem))
        {
            lastGenerated[pItem] = itemInstance;
        }
        else
        {
            lastGenerated.Add(pItem, itemInstance);
        }
    }
Example #7
0
	protected override void HandleMsg2(EPhotonMsg pReceivedMsg, object[] pParams, ByteBuffer bb)
	{
		switch(pReceivedMsg)
		{
			case EPhotonMsg.MapItem_Init:
				Vector2 pos = (Vector2)pParams[0];
				MapItem.EType type = (MapItem.EType)pParams[1];
				int subtypeIndex = (int)pParams[2];
				item.Init(pos, type, subtypeIndex);
				break;

			case EPhotonMsg.MapItem_DoExplosionEffect:
				item.DoExplosionEffect(true);
				break;

			//case EPhotonMsg.MapItem_ReturnToPool:
			//    item.ReturnToPool();
			//    break;

			default:
				OnMsgUnhandled(pReceivedMsg);
				break;
		}
	}
Example #8
0
    public void InitMap()
    {
        col        = Reg.mapCol;
        row        = Reg.MapRow;
        allGridNum = col * row;

        for (int i = 0; i < col; i++)
        {
            for (int j = 0; j < row; j++)
            {
                if (listMapCell[i, j] != null)
                {
                    listMapCell[i, j].Init(i, j);
                }
                else
                {
                    MapCell mapcel = Instantiate(mapcellPre, transform);
                    mapcel.Init(i, j);
                    listMapCell[i, j] = mapcel;
                }
            }
        }

        for (int i = 0; i < col; i++)
        {
            for (int j = 0; j < row; j++)
            {
                if (listMapItem[i, j] != null)
                {
                    listMapItem[i, j].Init(i, j, 0);
                }
                else
                {
                    MapItem mapitem = Instantiate(mapItemPre, transform);
                    mapitem.Init(i, j, 0);
                    listMapItem[i, j] = mapitem;
                }
                listMapItem[i, j].gameObject.SetActive(false);
            }
        }


        //初始化地图上面两个item
        for (int i = 0; i < Reg.InitItemNum; i++)
        {
            int pos1 = Random.Range(0, Reg.mapCol);
            int pos2 = Random.Range(0, Reg.MapRow);


            int score = 2;
            if (Random.Range(0, 100) > 60)
            {
                score = 4;
            }

            while (listMapItem[pos1, pos2] != null && listMapItem[pos1, pos2].gameObject.activeSelf)
            {
                pos1 = Random.Range(0, Reg.mapCol);
                pos2 = Random.Range(0, Reg.MapRow);
            }

            listMapItem[pos1, pos2].Init(pos1, pos2, score);
            listMapItem[pos1, pos2].gameObject.SetActive(true);
        }
    }