Example #1
0
    private void SetMainTask()
    {
        buttonsTF.gameObject.SetActive(false);
        actionBtn.gameObject.SetActive(true);
        missionTF.anchorMin = new Vector2(0, 0.2f);

        propPool.resetAllTarget();

        bool            isComplate = playerdata.ContainsComplateQuest(playerdata.questId);
        List <PropItem> props      = new List <PropItem>();

        if (questItem.requireStar > 0)
        {
            props.Add(new PropItem()
            {
                id    = "1",
                icon  = "XingXing",
                count = questItem.requireStar,
            });
        }

        props.AddRange(questItem.requireItem);
        foreach (PropItem item in props)
        {
            UIPropCell cell = propPool.getIdleTarget <UIPropCell>();
            if (item.id == "1")
            {
                //设置显示星星数量
                cell.SetData(item, playerdata.starNum, isComplate);
            }
            else
            {
                PropItem haveProp = playerdata.GetPropItem(item.id);
                cell.SetData(item, haveProp == null ? 0 : haveProp.count, isComplate);
            }
        }
    }
Example #2
0
        public PlayerModelErr QuestComplate(out string storyID, string selectedID = "")
        {
            Messenger.Broadcast <CallMethodInfo>(ELocalMsgID.CallPlayerModel, new CallMethodInfo()
            {
                name       = "QuestComplate",
                parameters = new object[] { "", selectedID },
            });
            storyID = "";

            //检测完成任务条件
            config.QuestItem questItem = playerData.GetQuest();
            if (questItem.type == QuestItem.QuestType.Ending)
            {
                return(PlayerModelErr.NULL);
            }
            //完成过的任务无消耗 无经验
            if (!playerData.complatedQuests.ContainsKey(questItem.id))
            {
                if (playerData.starNum < questItem.requireStar)
                {
                    return(PlayerModelErr.NOT_ENOUGH_STAR);
                }
                List <PropItem> needProps = questItem.requireItem;
                foreach (PropItem item in needProps)
                {
                    PropItem haveItem  = playerData.GetPropItem(item.id);
                    int      haveCount = haveItem == null ? 0 : haveItem.count;
                    if (haveCount < item.count)
                    {
                        return(PlayerModelErr.NOT_ENOUGH_PROP);
                    }
                }

                //扣除完成任务物品
                playerData.starNum -= questItem.requireStar;
                foreach (PropItem item in needProps)
                {
                    playerData.RemovePropItem(item.id, item.count);
                }
                playerData.complatedQuests.Add(questItem.id, 0);

                //获得奖励物品
                foreach (PropItem item in questItem.prize)
                {
                    bool isGet = Random.Range(0, 100) < item.rate;
                    if (isGet)
                    {
                        playerData.AddPropItem(item.id, item.count);
                    }
                }

                //获得经验值
                playerData.totalExp += questItem.exp;
                playerData.currExp  += questItem.exp;
                //判断升级
                config.LevelItem levelItem = GameMainManager.Instance.configManager.levelConfig.GetItem(playerData.level);
                while (levelItem != null && playerData.currExp >= levelItem.exp)
                {
                    playerData.level++;
                    playerData.currExp -= levelItem.exp;
                    levelItem           = GameMainManager.Instance.configManager.levelConfig.GetItem(playerData.level);
                }
            }

            //更新下个任务
            qy.config.Ability ability = new config.Ability();
            if (questItem.type == config.QuestItem.QuestType.Main)
            {
                playerData.nextQuestId = questItem.gotoId;
                storyID = questItem.storyID;
            }
            else if (questItem.type == config.QuestItem.QuestType.Branch)
            {
                foreach (SelectItem item in questItem.selectList)
                {
                    if (item.id == selectedID)
                    {
                        playerData.nextQuestId = item.toQuestId;
                        storyID = item.storyID;
                        ability = item.ability;

                        string selectID = questItem.id + "_" + item.id;
                        if (!playerData.selectedItems.ContainsKey(selectID))
                        {
                            playerData.selectedItems.Add(selectID, 0);
                        }
                        break;
                    }
                }
            }
            else if (questItem.type == config.QuestItem.QuestType.Important)
            {
                if (playerData.survival < questItem.endingPoint.survival)
                {
                    //进入分支任务
                    playerData.nextQuestId = questItem.endingPoint.questID;
                    storyID = questItem.endingPoint.storyID;
                }
                else
                {
                    //进入普通任务
                    playerData.nextQuestId = questItem.gotoId;
                    storyID = questItem.storyID;
                }
            }
            if (string.IsNullOrEmpty(playerData.nextQuestId))
            {
                return(PlayerModelErr.QUEST_ID_ERROR);
            }

            //增加属性值
            config.Ability addAbilty = config.Ability.GetAddAbilty(playerData.ability, ability);
            playerData.ability += addAbilty;

            GameMainManager.Instance.netManager.ComplateQuestId(playerData.questId, addAbilty, (ret, res) => {
            });
            playerData.questId = playerData.nextQuestId;

            //标记角色状态
            config.QuestItem nextQuest = playerData.GetQuest();
            if (nextQuest.type == config.QuestItem.QuestType.Ending)
            {
                GameMainManager.Instance.netManager.ComplateQuestId(nextQuest.id, new config.Ability(), (ret, res) => {});
                GameMainManager.Instance.netManager.EndingRole(nextQuest.endingType, (ret, res) => { });
                switch (nextQuest.endingType)
                {
                case 1:    //死亡
                    playerData.SetRoleState(playerData.role.id, PlayerData.RoleState.Dide);
                    break;

                case 2:    //通关
                    playerData.SetRoleState(playerData.role.id, PlayerData.RoleState.Pass);
                    break;
                }
            }

            playerData.dirty = true;
            SaveData();
            Messenger.Broadcast(ELocalMsgID.RefreshBaseData);

            if (questItem.chapter != nextQuest.chapter)
            {
                Messenger.Broadcast <string>(ELocalMsgID.LoadScene, "Film");
            }

            return(PlayerModelErr.NULL);
        }