public override void Execute()
    {
        var heroDataList   = new List <Dictionary <string, System.Object> >();
        var characterTable = CharacterTableData.CreateFromJson();

        // 获取英雄数据
        for (int i = 0; i < userInfoModel.heroList.Count; i++)
        {
            var heroInfo      = userInfoModel.heroList[i];
            var characterData = characterTable.GetCharacterInfoById(heroInfo.characterId);
            var heroPrefab    = (GameObject)Resources.Load(characterData.heroPath);

            heroDataList.Add(new Dictionary <string, object>
            {
                { "id", heroInfo.id },
                { "heroPath", characterData.heroPath },
                { "atk", characterData.atk },
                { "hp", heroInfo.lastHp },
                { "maxHp", characterData.hp },
                { "heroInfoId", heroInfo.id },
                { "atkDis", characterData.atkDis },
                { "atkSpeed", characterData.atkSpeed },
                { "roleType1", Role.RoleType.HERO },
                { "moveSpeed", characterData.moveSpeed }
            });
        }

        var monsterDataList    = new List <Dictionary <string, System.Object> >();
        var chapterTable       = ChapterTableData.CreateFromJson();
        var currentChapterData = chapterTable.GetChapterInfoById(userInfoModel.fightChapterId);

        //  获取副本怪物数据
        for (int i = 0; i < currentChapterData.enemy.Length; i++)
        {
            var characterData = characterTable.GetCharacterInfoById(currentChapterData.enemy[i]);
            var heroPrefab    = (GameObject)Resources.Load(characterData.heroPath);

            monsterDataList.Add(new Dictionary <string, object>
            {
                { "heroPath", characterData.heroPath },
                { "atk", characterData.atk },
                { "hp", characterData.hp },
                { "maxHp", characterData.hp },
                { "atkDis", characterData.atkDis },
                { "atkSpeed", characterData.atkSpeed },
                { "roleType1", Role.RoleType.ENEMY },
                { "moveSpeed", characterData.moveSpeed }
            });
        }

        dispatcher.Dispatch(MediatorEvent.LoadFightCharacter, new System.Object[] { heroDataList, monsterDataList });
    }
Exemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        roleGo = GameObject.Find("Role");

        var userInfo       = DataManager.GetInstance().GetUserInfo();
        var characterTable = CharacterTableData.CreateFromJson();

        // 加载英雄数据
        for (int i = 0; i < userInfo.heroList.Count; i++)
        {
            var heroInfo      = userInfo.heroList[i];
            var characterData = characterTable.GetCharacterInfoById(heroInfo.characterId);
            var heroPrefab    = (GameObject)Resources.Load(characterData.heroPath);

            GameObject go = Instantiate(heroPrefab, new Vector3(-12, -i, 0), Quaternion.identity, roleGo.transform);

            Role role = go.GetComponent <Role>();
            role.Atk        = characterData.atk;
            role.Hp         = heroInfo.lastHp; // 英雄剩下的血量
            role.MaxHp      = characterData.hp;
            role.HeroInfoId = heroInfo.id;     // 战斗模型跟英雄数据的关系
            role.AtkDis     = characterData.atkDis;
            role.AtkSpeed   = characterData.atkSpeed;
            role.RoleType1  = Role.RoleType.HERO;
            role.MoveSpeed  = characterData.moveSpeed;

            Instantiate(hpBar, go.transform); // 创建血条
        }

        var chapterTable = ChapterTableData.CreateFromJson();

        currentChapterData = chapterTable.GetChapterInfoById(userInfo.fightChapterId);

        //  加载副本怪物数据
        for (int i = 0; i < currentChapterData.enemy.Length; i++)
        {
            var characterData = characterTable.GetCharacterInfoById(currentChapterData.enemy[i]);
            var heroPrefab    = (GameObject)Resources.Load(characterData.heroPath);

            GameObject go   = Instantiate(heroPrefab, new Vector3(12, -i, 0), Quaternion.identity, roleGo.transform);
            Role       role = go.GetComponent <Role>();
            role.Atk       = characterData.atk;
            role.Hp        = characterData.hp;
            role.MaxHp     = characterData.hp;
            role.AtkDis    = characterData.atkDis;
            role.AtkSpeed  = characterData.atkSpeed;
            role.RoleType1 = Role.RoleType.ENEMY;
            role.MoveSpeed = characterData.moveSpeed;

            Instantiate(hpBar, go.transform); // 创建血条
        }
    }
Exemplo n.º 3
0
    public override void Execute()
    {
        var summonLv    = (int)evt.data;
        var summonTable = SummonTableData.CreateFromJson();

        characterTable = CharacterTableData.CreateFromJson();
        summonData     = summonTable.GetSummonDataByLv(summonLv);

        if (userInfoModel.money >= summonData.consume)
        {
            // 扣除需要的钱
            userInfoModel.money -= summonData.consume;
            RecruitHero();
            userInfoService.SaveUserInfo(userInfoModel);
            dispatcher.Dispatch(CommandEvent.GetMoney);
        }
        else
        {
            Debug.Log("钱不够");
        }
    }