예제 #1
0
    public PractiseStep GetStep(uint ID)
    {
        PractiseStep step = null;

        steps.TryGetValue(ID, out step);
        return(step);
    }
    void EndStep()
    {
        Debug.Log("PractiseStep, End step:" + curStep.ID + " Success:" + !stepFailed);

        if (!stepFailed)
        {
            EndObjective();
        }

        stepFinished = false;

        plot.Hide();
        guideTip.Hide();
        foreach (GameObject tip in tipOnScene)
        {
            DestroyUIEffect(tip);
        }
        tipOnScene.Clear();
        foreach (GameObject effect in effects)
        {
            Object.DestroyImmediate(effect);
        }
        effects.Clear();
        if (curStep.disabledAction != null && InputReader.Instance.player != null)
        {
            foreach (Command cmd in curStep.disabledAction)
            {
                InputReader.Instance.player.m_skillSystem.CancelDisableCommand(cmd);
            }
        }
        UnhighlightButton();

        readyStepID = stepFailed ? curStep.failNext : curStep.next;
        Debug.Log("PractiseStep, Ready step:" + readyStepID);
        curStep = null;
        if (!stepFailed && readyStepID == 0)
        {
            StartCoroutine(Step_Over());
        }
    }
예제 #3
0
    void ReadStep()
    {
        string text = ResourceLoadManager.Instance.GetConfigText(name1);

        if (text == null)
        {
            Debug.LogError("LoadConfig failed: " + name1);
            return;
        }

        XmlDocument doc  = CommonFunction.LoadXmlConfig(GlobalConst.DIR_XML_PRACTICE_STEP, text);
        XmlNode     root = doc.SelectSingleNode("Data");

        foreach (XmlNode line in root.SelectNodes("Line"))
        {
            if (CommonFunction.IsCommented(line))
            {
                continue;
            }

            PractiseStep step = new PractiseStep();
            if (!uint.TryParse(line.SelectSingleNode("ID").InnerText, out step.ID))
            {
                LogError("ID is empty.");
            }
            XmlNode nodeName = line.SelectSingleNode("name");
            if (nodeName != null)
            {
                step.name = nodeName.InnerText;
            }
            uint.TryParse(line.SelectSingleNode("next").InnerText, out step.next);
            uint.TryParse(line.SelectSingleNode("fail_next").InnerText, out step.failNext);
            string strObjective = line.SelectSingleNode("objective").InnerText;
            if (!string.IsNullOrEmpty(strObjective))
            {
                string[] tokens = strObjective.Split(',');
                if (tokens.Length == 3 && tokens[0] == "S")
                {
                    step.startObjective = new KeyValuePair <int, string>(int.Parse(tokens[1]), tokens[2]);
                }
                else if (tokens.Length == 2 && tokens[0] == "E")
                {
                    step.endObjective = int.Parse(tokens[1]);
                }
                else
                {
                    LogError(step.ID, "Illegal format: objective");
                }
            }
            string strDlg = line.SelectSingleNode("dialog").InnerText;
            if (!string.IsNullOrEmpty(strDlg))
            {
                string[] tokens = strDlg.Split(':');
                if (tokens.Length == 2 && int.TryParse(tokens[0], out step.dialogRole))
                {
                    step.dialog = tokens[1];
                }
                else
                {
                    LogError(step.ID, "Illegal format: dialog");
                }
            }
            step.voiceover = line.SelectSingleNode("voiceover").InnerText;
            if (!int.TryParse(line.SelectSingleNode("ball_owner").InnerText, out step.ballOwner))
            {
                step.ballOwner = -2;
            }
            string strOppos = line.SelectSingleNode("oppo").InnerText;
            if (!string.IsNullOrEmpty(strOppos))
            {
                step.oppo = new Dictionary <int, int>();
                foreach (string strOppo in CommonFunction.SplitLines(strOppos))
                {
                    if (string.IsNullOrEmpty(strOppo))
                    {
                        continue;
                    }
                    string[] tokens = strOppo.Split('-');
                    int      o = -1, d = -1;
                    if (!int.TryParse(tokens[0], out o))
                    {
                        o = -1;
                    }
                    if (tokens.Length <= 1 || !int.TryParse(tokens[1], out d))
                    {
                        d = -1;
                    }
                    step.oppo.Add(o, d);
                }
            }
            string strCanPick = line.SelectSingleNode("can_pick").InnerText;
            if (!string.IsNullOrEmpty(strCanPick))
            {
                step.canPick = new List <int>();
                string[] tokens = strCanPick.Split('&');
                foreach (string token in tokens)
                {
                    int index = 0;
                    if (int.TryParse(token, out index))
                    {
                        step.canPick.Add(index);
                    }
                }
            }
            string strVisibles = line.SelectSingleNode("visible").InnerText;
            if (!string.IsNullOrEmpty(strVisibles))
            {
                step.visible = new Dictionary <int, bool>();
                foreach (string strVisible in CommonFunction.SplitLines(strVisibles))
                {
                    if (string.IsNullOrEmpty(strVisible))
                    {
                        continue;
                    }
                    string[] tokens  = strVisible.Split(':');
                    int      index   = 0;
                    bool     visible = false;
                    if (!(tokens.Length == 2 && int.TryParse(tokens[0], out index) && bool.TryParse(tokens[1], out visible)))
                    {
                        LogError(step.ID, "Illegal format: visible");
                    }
                }
            }
            string strPositions = line.SelectSingleNode("position").InnerText;
            if (!string.IsNullOrEmpty(strPositions))
            {
                step.position = new Dictionary <int, IM.Vector3>();
                foreach (string strPosition in CommonFunction.SplitLines(strPositions))
                {
                    if (string.IsNullOrEmpty(strPosition))
                    {
                        continue;
                    }
                    string[]  tokens = strPosition.Split(':');
                    int       index = 0;
                    IM.Number x = IM.Number.zero, y = IM.Number.zero, z = IM.Number.zero;
                    if (tokens.Length == 2 && int.TryParse(tokens[0], out index))
                    {
                        string[] tokens1 = tokens[1].Split(',');
                        if (!(tokens1.Length == 3 &&
                              IM.Number.TryParse(tokens1[0], out x) &&
                              IM.Number.TryParse(tokens1[1], out y) &&
                              IM.Number.TryParse(tokens1[2], out z)))
                        {
                            LogError(step.ID, "Illegal format: position");
                        }
                    }
                    else
                    {
                        LogError(step.ID, "Illegal format: position");
                    }
                    step.position.Add(index, new IM.Vector3(x, y, z));
                }
            }
            string strOrientations = line.SelectSingleNode("orientation").InnerText;
            if (!string.IsNullOrEmpty(strOrientations))
            {
                step.orientation = new Dictionary <int, string>();
                foreach (string strOrientation in CommonFunction.SplitLines(strOrientations))
                {
                    if (string.IsNullOrEmpty(strOrientation))
                    {
                        continue;
                    }
                    string[] tokens = strOrientation.Split(':');
                    int      index  = 0;
                    if (tokens.Length == 2 && int.TryParse(tokens[0], out index))
                    {
                        step.orientation.Add(index, tokens[1]);
                    }
                    else
                    {
                        LogError(step.ID, "Illegal format: orientation");
                    }
                }
            }
            string strBehaviours = line.SelectSingleNode("behaviour").InnerText;
            if (!string.IsNullOrEmpty(strBehaviours))
            {
                step.behaviour = new Dictionary <int, PractiseStepBehaviour>();
                foreach (string strBehaviour in CommonFunction.SplitLines(strBehaviours))
                {
                    if (string.IsNullOrEmpty(strBehaviour))
                    {
                        continue;
                    }
                    string[] tokens = strBehaviour.Split(':');
                    int      index;
                    PractiseStepBehaviour behaviour;
                    if (tokens.Length == 2 && int.TryParse(tokens[0], out index))
                    {
                        behaviour = (PractiseStepBehaviour)Enum.Parse(PractiseStepBehaviour.None.GetType(), tokens[1]);
                        step.behaviour.Add(index, behaviour);
                    }
                    else
                    {
                        LogError(step.ID, "Illegal format: behaviour");
                    }
                }
            }
            string strAction = line.SelectSingleNode("action").InnerText;
            if (!string.IsNullOrEmpty(strAction))
            {
                string[] tokens = strAction.Split('&');
                foreach (string token in tokens)
                {
                    if (token == "Move")
                    {
                        step.canMove = true;
                    }
                    else if (token.StartsWith("-"))
                    {
                        if (step.disabledAction == null)
                        {
                            step.disabledAction = new List <Command>();
                        }
                        step.disabledAction.Add((Command)Enum.Parse(Command.Max.GetType(), token.Substring(1)));
                    }
                    else
                    {
                        if (step.action == null)
                        {
                            step.action = new List <Command>();
                        }
                        step.action.Add((Command)Enum.Parse(Command.Max.GetType(), token));
                    }
                }
            }
            string strHint = line.SelectSingleNode("hint").InnerText;
            if (!string.IsNullOrEmpty(strHint))
            {
                string[] tokens = strHint.Split('&');
                foreach (string token in tokens)
                {
                    if (token.StartsWith("Move"))
                    {
                        step.hintMove = true;
                        string[] moveTokens = token.Split(',');
                        if (moveTokens.Length >= 2)
                        {
                            step.hintMoveAngle = float.Parse(moveTokens[1]);
                        }
                    }
                    else
                    {
                        if (step.hintAction == null)
                        {
                            step.hintAction = new List <Command>();
                        }
                        step.hintAction.Add((Command)Enum.Parse(Command.Max.GetType(), token));
                    }
                }
            }
            step.screenEffect = line.SelectSingleNode("screen_effect").InnerText;
            string strSceneEffects = line.SelectSingleNode("scene_effect").InnerText;
            if (!string.IsNullOrEmpty(strSceneEffects))
            {
                step.sceneEffect = new Dictionary <string, string>();
                foreach (string effect in CommonFunction.SplitLines(strSceneEffects))
                {
                    if (string.IsNullOrEmpty(effect))
                    {
                        continue;
                    }
                    string[] tokens = effect.Split(':');
                    Assert(tokens.Length == 2, step.ID, "Illegal format: scene_effect");
                    step.sceneEffect.Add(tokens[0], tokens[1]);
                }
            }
            string strSceneHint = line.SelectSingleNode("scene_hint").InnerText;
            if (!string.IsNullOrEmpty(strSceneHint))
            {
                step.sceneHint = new Dictionary <string, string>();
                foreach (string hint in CommonFunction.SplitLines(strSceneHint))
                {
                    if (string.IsNullOrEmpty(hint))
                    {
                        continue;
                    }
                    string[] tokens = hint.Split(':');
                    Assert(tokens.Length == 2, step.ID, "Illegal format: scene_hint");
                    step.sceneHint.Add(tokens[0], tokens[1]);
                }
            }
            if (!float.TryParse(line.SelectSingleNode("time_scale").InnerText, out step.timeScale))
            {
                step.timeScale = 1f;
            }
            string strMustGoal = line.SelectSingleNode("must_goal").InnerText;
            if (!string.IsNullOrEmpty(strMustGoal))
            {
                bool goal;
                bool.TryParse(strMustGoal, out goal);
                if (goal)
                {
                    step.mustGoal = true;
                }
                else
                {
                    step.cantGoal = true;
                }
            }
            string strShootSolution = line.SelectSingleNode("shoot_solution").InnerText;
            if (!string.IsNullOrEmpty(strShootSolution))
            {
                string[] tokens = strShootSolution.Split(',');
                step.shootSolution = new KeyValuePair <int, int>(int.Parse(tokens[0]), int.Parse(tokens[1]));
            }
            bool.TryParse(line.SelectSingleNode("must_block").InnerText, out step.mustBlock);
            bool.TryParse(line.SelectSingleNode("must_cross").InnerText, out step.mustCross);
            try{
                ParseCondition(line.SelectSingleNode("end_cond").InnerText, out step.endCondition);
            }
            catch (System.Exception ex)
            {
                LogError(step.ID, "Illegal format: end_cond. " + ex);
            }
            try{
                ParseCondition(line.SelectSingleNode("fail_cond").InnerText, out step.failCondition);
            }
            catch (System.Exception ex)
            {
                LogError(step.ID, "Illegal format: fail_cond" + ex);
            }

            steps.Add(step.ID, step);
        }
    }
    public override void GameUpdate(IM.Number deltaTime)
    {
        base.GameUpdate(deltaTime);

        if (curStep != null)
        {
            stepRunningTime += (float)deltaTime;

            if (HasCondition(PractiseStepCondition.OnGround))
            {
                ValidateCondition(PractiseStepCondition.OnGround, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    return(player.m_bOnGround);
                });
            }
            if (HasCondition(PractiseStepCondition.Wait))
            {
                ValidateCondition(PractiseStepCondition.Wait, (param) =>
                {
                    float waitTime = (float)(param[0]);
                    return(stepRunningTime >= waitTime);
                });
            }
            if (HasCondition(PractiseStepCondition.InDist))
            {
                ValidateCondition(PractiseStepCondition.InDist, (param) =>
                {
                    int index      = (int)(param[0]);
                    Player player  = GetPlayer(index);
                    GameObject obj = GetSceneObject((string)(param[1]));
                    float dist     = (float)(param[2]);
                    bool value     = (bool)(param[3]);
                    return((GameUtils.HorizonalDistance(obj.transform.position, (Vector3)player.position) <= dist) == value);
                });
            }
            if (HasCondition(PractiseStepCondition.EnterRow))
            {
                ValidateCondition(PractiseStepCondition.EnterRow, (param) =>
                {
                    int index     = (int)(param[0]);
                    int rowStart  = (int)(param[1]);
                    int rowEnd    = (int)(param[2]);
                    Player player = GetPlayer(index);
                    int secIdx    = RoadPathManager.Instance.CalcSectorIdx(player.position);
                    if (secIdx == -1)
                    {
                        return(false);
                    }
                    int rowIdx = secIdx / RoadPathManager.Instance.m_angleNum;
                    return(rowStart <= rowIdx && rowIdx <= rowEnd);
                });
            }
            if (HasCondition(PractiseStepCondition.EnterArea))
            {
                ValidateCondition(PractiseStepCondition.EnterArea, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    Area area     = (Area)(param[1]);
                    return(match.mCurScene.mGround.GetArea(player) == area);
                });
            }
            if (HasCondition(PractiseStepCondition.EnterState))
            {
                ValidateCondition(PractiseStepCondition.EnterState, (param) =>
                {
                    int index               = (int)(param[0]);
                    Player player           = GetPlayer(index);
                    PlayerState.State state = (PlayerState.State)(param[1]);
                    return(state == player.m_StateMachine.m_curState.m_eState);
                });
            }
            if (HasCondition(PractiseStepCondition.BlockTiming))
            {
                ValidateCondition(PractiseStepCondition.BlockTiming, (param) =>
                {
                    Player attacker = ball.m_owner;
                    if (attacker == null)
                    {
                        attacker = ball.m_actor;
                    }
                    if (attacker.m_StateMachine.m_curState.m_eState != PlayerState.State.eShoot &&
                        attacker.m_StateMachine.m_curState.m_eState != PlayerState.State.eLayup &&
                        attacker.m_StateMachine.m_curState.m_eState != PlayerState.State.eDunk)
                    {
                        return(false);
                    }
                    if (!PlayerState_Block.InBlockArea(attacker, attacker.m_defenseTarget, match.mCurScene.mBasket.m_vShootTarget))
                    {
                        return(false);
                    }
                    return(attacker.m_blockable.blockable);
                });
            }
            if (HasCondition(PractiseStepCondition.Blocked))
            {
                ValidateCondition(PractiseStepCondition.Blocked, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    if (player.m_StateMachine.m_curState.m_eState != PlayerState.State.eBlock)
                    {
                        return(false);
                    }
                    PlayerState_Block blockState = player.m_StateMachine.m_curState as PlayerState_Block;
                    bool success = (bool)(param[1]);
                    return(blockState.m_success == success);
                });
            }
            if (HasCondition(PractiseStepCondition.BlockInArea))
            {
                ValidateCondition(PractiseStepCondition.BlockInArea, (param) =>
                {
                    int index       = (int)(param[0]);
                    Player player   = GetPlayer(index);
                    Player attacker = ball.m_owner;
                    if (attacker == null)
                    {
                        attacker = ball.m_actor;
                    }
                    bool inArea = (bool)(param[1]);
                    return(PlayerState_Block.InBlockArea(attacker, player, match.mCurScene.mBasket.m_vShootTarget) == inArea);
                });
            }
            if (HasCondition(PractiseStepCondition.BlockTooLate))
            {
                ValidateCondition(PractiseStepCondition.BlockTooLate, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    if (player.m_StateMachine.m_curState.m_eState != PlayerState.State.eBlock)
                    {
                        return(false);
                    }
                    PlayerState_Block blockState = player.m_StateMachine.m_curState as PlayerState_Block;
                    if (blockState.m_success)
                    {
                        return(false);
                    }
                    Player attacker = ball.m_owner;
                    if (attacker == null)
                    {
                        attacker = ball.m_actor;
                    }
                    bool tooLate = (bool)(param[1]);
                    if (tooLate)
                    {
                        return(blockState.m_failReason == PlayerState_Block.FailReason.TooLate);
                    }
                    else
                    {
                        return(blockState.m_failReason == PlayerState_Block.FailReason.TooEarly);
                    }
                });
            }
            if (HasCondition(PractiseStepCondition.ReboundTiming))
            {
                ValidateCondition(PractiseStepCondition.ReboundTiming, (param) =>
                {
                    if (ball.m_ballState == BallState.eRebound)
                    {
                        IM.Vector3 velocity = ball.curVel;
                        if (velocity.y < IM.Number.zero)
                        {
                            int index           = (int)(param[0]);
                            Player player       = GetPlayer(index);
                            IM.Number eventTime = PlayerState_Rebound.GetEventTime(player);
                            IM.Vector3 pos;
                            ball.GetPositionInAir(ball.m_fTime + eventTime, out pos);
                            IM.Number ball_height = pos.y;
                            IM.Number minHeight, maxHeight;
                            PlayerState_Rebound.GetDefaultHeightRange(player, out minHeight, out maxHeight);
                            return(minHeight < ball_height && ball_height < maxHeight);
                        }
                    }
                    return(false);
                });
            }
            if (HasCondition(PractiseStepCondition.Rebound))
            {
                ValidateCondition(PractiseStepCondition.Rebound, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    if (player.m_StateMachine.m_curState.m_eState != PlayerState.State.eRebound)
                    {
                        return(false);
                    }
                    PlayerState_Rebound reboundState = player.m_StateMachine.m_curState as PlayerState_Rebound;
                    bool success = (bool)(param[1]);
                    if (success)
                    {
                        reboundState.m_toReboundBall = true;
                    }
                    return(reboundState.m_success == success);
                });
            }
            if (HasCondition(PractiseStepCondition.ReboundInArea))
            {
                ValidateCondition(PractiseStepCondition.ReboundInArea, (param) =>
                {
                    int index           = (int)(param[0]);
                    Player player       = GetPlayer(index);
                    IM.Number dist2Ball = GameUtils.HorizonalDistance(player.position, ball.position);
                    IM.Number maxDist   = PlayerState_Rebound.GetDefaultMaxDist(player);
                    bool inArea         = (bool)(param[1]);
                    return((dist2Ball <= maxDist) == inArea);
                });
            }
            if (HasCondition(PractiseStepCondition.ReboundTooLate))
            {
                ValidateCondition(PractiseStepCondition.ReboundTooLate, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    if (player.m_StateMachine.m_curState.m_eState != PlayerState.State.eRebound)
                    {
                        return(false);
                    }
                    PlayerState_Rebound reboundState = player.m_StateMachine.m_curState as PlayerState_Rebound;
                    if (reboundState.m_success)
                    {
                        return(false);
                    }
                    bool tooLate = (bool)(param[1]);
                    return(reboundState.tooLate == tooLate);
                });
            }
            if (HasCondition(PractiseStepCondition.Undefended))
            {
                ValidateCondition(PractiseStepCondition.Undefended, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    return(!player.IsDefended());
                });
            }
            if (HasCondition(PractiseStepCondition.Defended))
            {
                ValidateCondition(PractiseStepCondition.Defended, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    return(player.IsDefended());
                });
            }
        }

        if (stepFinished)
        {
            EndStep();
        }

        if (readyStepID != 0)
        {
            curStep     = GameSystem.Instance.PractiseStepConfig.GetStep(readyStepID);
            readyStepID = 0;
            RunStep();
            return;
        }
    }
    protected override void OnFirstStart()
    {
        base.OnFirstStart();

        plot = UIManager.Instance.CreateUI("UIPlayPlot").GetComponent <UIPlayPlot>();
        plot.Hide();
        plot.onNext = OnPlotNext;

        match.HideSignal();
        match.HideTitle();
        match.HideBackButton();

        guideTip = UIManager.Instance.CreateUI("GuideTip_3").AddMissingComponent <GuideTip>();
        guideTip.transform.localPosition = new Vector3(18, -316, 0);
        guideTip.firstButtonVisible      = false;
        guideTip.Hide();


        foreach (UController.Button btn in match.m_uiController.m_btns)
        {
            if (btn.btn != null)
            {
                UIEventListener.Get(btn.btn.gameObject).onPress += OnBtnPress;
            }
        }

        match.onTipClick += OnTipClick;
        ball.onGrab      += OnGrab;
        ball.onCatch     += OnCatch;
        ball.onShoot     += OnShoot;
        ball.onHitGround += OnHitGround;
        match.mCurScene.mBasket.onGoal += OnGoal;

        prefabObjFinish = ResourceLoadManager.Instance.LoadPrefab("Prefab/GUI/MatchGuideObjectiveFinish") as GameObject;
        paneObjective   = UIManager.Instance.CreateUI("MatchGuideObjectivePane");
        UIGrid     gridObj    = paneObjective.transform.FindChild("Grid").GetComponent <UIGrid>();
        GameObject prefabItem = ResourceLoadManager.Instance.LoadPrefab("Prefab/GUI/MatchGuideObjectiveItem") as GameObject;

        PractiseStep step = GameSystem.Instance.PractiseStepConfig.GetFirstStep();

        readyStepID = step.ID;
        while (true)
        {
            if (step.startObjective.Key != 0)
            {
                lastObjID = step.startObjective.Key;
                GameObject item = CommonFunction.InstantiateObject(prefabItem, gridObj.transform);
                item.GetComponentInChildren <UILabel>().text = step.startObjective.Value;
                objectives.Add(step.startObjective.Key, item);
            }
            if (step.next == 0)
            {
                break;
            }
            else
            {
                step = GameSystem.Instance.PractiseStepConfig.GetStep(step.next);
            }
        }
        gridObj.Reposition();
    }