A simple class for toggle-able debug messages. Debug messages for editor tools are useful when developing the tool itself, but annoying for end users.
Example #1
0
    /// <summary>
    /// 通过id获取数量
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public int GetItemNum(int itemId)
    {
        int num = 0;

        if (itemList == null)
        {
            num = 0;
        }
        else
        {
            for (int i = 0; i < itemList.Count; i++)
            {
                if (itemList[i].itemId == itemId)
                {
                    EDebug.Log(itemList[i].itemNum);
                    num = itemList[i].itemNum;
                    break;
                }
            }
        }
        return(999);
    }
Example #2
0
    public void Send(ServerMsgId pMsgId, object o, short sub_id = 0, uint arg1 = 0, uint arg2 = 0)
    {
        EDebug.Log("Send " + pMsgId.ToString());
        //if (NetStatus.Disconnected == status)
        //    Connect();
        MsgHead head = new MsgHead
        {
            cmd_id = (short)pMsgId,
            sub_id = sub_id,
            param1 = (int)arg1,
            param2 = (int)arg2
        };
        string msg = JsonUtility.ToJson(o);

        byte[] bMsg = System.Text.Encoding.UTF8.GetBytes(msg);
        head.len = bMsg.Length;
        byte[] bHead  = ProtocolByt.StructToBytes(head, 16);
        byte[] buffer = new byte[bHead.Length + bMsg.Length];
        System.Array.Copy(bHead, buffer, bHead.Length);
        System.Array.Copy(bMsg, 0, buffer, bHead.Length, bMsg.Length);
        _msgSend.AddLast(buffer);
    }
Example #3
0
    /// <summary>
    /// 选择一个攻击目标
    /// </summary>
    /// <param name="self">自己</param>
    /// <param name="canAttack">是否考虑必须可以攻击到</param>
    /// <returns></returns>
    public FightUnit SelectFightTarget(FightUnit self, bool canAttack)
    {
        if (self == null || self.IsDead)
        {
            EDebug.LogError("FightLogic.SelectFightTarget failed, fightunit is null or dead");
            return(null);
        }
        int   selIdx = -1;
        float dis    = float.MaxValue;

        //先循环一遍看看有没有可以攻击的对象,如果没有,则不考虑是否无敌
        int targetsCanBeAttackCnt = 0;

        for (int idx = 0; idx < AllFighters.Count; ++idx)
        {
            FightUnit unit = AllFighters[idx];
            if (!unit.CanBeAttack(self, false, true, true))
            {
                continue;
            }
            targetsCanBeAttackCnt++;
        }
        for (int idx = 0; idx < AllFighters.Count; ++idx)
        {
            FightUnit unit = AllFighters[idx];
            if (!unit.CanBeAttack(self, 0 == targetsCanBeAttackCnt, !canAttack, false))
            {
                continue;
            }
            //计算距离
            float gridDis = PathFinder.GridDis(self.GridPos, unit.GridPos);
            if (gridDis < dis)
            {
                selIdx = idx;
                dis    = gridDis;
            }
        }
        return((selIdx >= 0) ? AllFighters[selIdx] : null);
    }
Example #4
0
    private void openMonsterTip(int monsterId, Vector2 pos, int align, Vector2 offset, bool isBoss)
    {
        Monster monsterJson = JsonMgr.GetSingleton().GetMonsterByID(monsterId);

        if (monsterJson == null)
        {
            EDebug.LogErrorFormat("openMonsterTip invalid monster id {0}", monsterId);
            return;
        }
        this.monsterhead_img.sprite  = ResourceMgr.Instance.LoadSprite(monsterJson.headid);
        this.monsterlevel_img.sprite = ResourceMgr.Instance.LoadSprite(ColorMgr.Border[monsterJson.rare - 1]);
        HeroRare rareData = JsonMgr.GetSingleton().GetHeroRareByID(monsterJson.rare);

        this.monsterlevel_img.sprite = ResourceMgr.Instance.LoadSprite(rareData.HeadBorder);
        string monsterName = string.Format("{0}({1})", monsterJson.name, rareData.Name);

        this.monstername_txt.text  = monsterName.AddColorLabel(rareData.Color);
        this.monsterlevel_txt.text = string.Format(JsonMgr.GetSingleton().GetGlobalStringArrayByID(2004).desc, monsterJson.level);
        this.monsterisboss_obj.SetActive(isBoss);
        this.monsterintroduce_txt.text         = monsterJson.desc;
        this.monstertips_rect.anchoredPosition = calAlignment(pos, this.monstertips_rect.sizeDelta, align, offset);
        this.monstertips_rect.gameObject.SetActive(true);
    }
Example #5
0
    public static void Register(string eventName, object register, string funcName)
    {
        List <EventPair> lst = _events.ContainsKey(eventName) ? _events[eventName] : new List <EventPair>();

        for (int i = 0; i < lst.Count; i++)
        {
            if (register.Equals(lst[i].obj) && lst[i].method.Name.Equals(funcName))
            {
                return;
            }
        }
        EventPair ep = new EventPair();

        ep.obj    = register;
        ep.method = register.GetType().GetMethod(funcName);
        if (ep.method == null)
        {
            EDebug.LogErrorFormat("ZEventSystem register failed, obj {0} get method:{1} failed, no this method", register, funcName);
            return;
        }
        lst.Add(ep);
        _events[eventName] = lst;
    }
Example #6
0
    private void _analyzeBuffRes(int buffId, ref HashSet <int> sound, ref HashSet <int> gos)
    {
        JObject jBuff = JsonMgr.GetSingleton().GetBuff(buffId);

        if (jBuff == null)
        {
            EDebug.LogErrorFormat("PreloadMgr._analyzeBuff failed, no such buff:{0}", buffId);
            return;
        }
        int resId = jBuff["resid"].ToObject <int>();

        if (resId != 0)
        {
            gos.Add(resId);
        }
        int effect  = jBuff["effect"].ToObject <int>();
        int calType = jBuff["caltype"].ToObject <int>();

        if (1 == calType)
        {
            return;
        }
        Vector3 buffParams = AttrUtil.CalExpression(calType, jBuff["buffparam"].ToObject <JArray>());

        switch (effect)
        {
        case (int)BuffEffect.UsePromotSkill:
        case (int)BuffEffect.UseSkill:
            _analyzeSkillRes((int)buffParams.y, ref sound, ref gos);
            break;

        case (int)BuffEffect.AddBuff:
            _analyzeBuffRes((int)buffParams.y, ref sound, ref gos);
            break;
        }
    }
Example #7
0
 void CheckVersion()
 {
     EDebug.Log("check version");
     GameStart();
 }
Example #8
0
    /// <summary>
    /// 计算公式,返回Vector3,
    /// </summary>
    /// <param name="type"></param>
    /// <param name="expression"></param>
    /// <param name="user"></param>
    /// <param name="target"></param>
    /// <param name="extra">额外参数,现在只是表示等级</param>
    /// <returns></returns>
    public static Vector3 CalExpression(int type, JArray expression, FightUnit user = null, FightUnit target = null, float extra = 0)
    {
        switch (type)
        {
        case 1:
        {
            // attr * (a + extra * b)的形式
            if (user == null || target == null)
            {
                EDebug.LogErrorFormat("CalExpression failed. type {0} need user and target", type);
                return(Vector2.zero);
            }
            if (expression.Count != 3)
            {
                EDebug.LogErrorFormat("CalExpression failed. type {0} expression {1} is invalid", type, expression);
                return(Vector2.zero);
            }
            Vector3 ret = expression2Attr(expression[0].ToObject <string>(), user, target);
            float   a   = expression[1].ToObject <float>();
            float   b   = expression[2].ToObject <float>();
            ret.y = ret.y * (a + extra * b);
            return(ret);
        }
        break;

        case 2:
        {
            //直接返回原值的形式
            float v = expression[0].ToObject <float>();
            return(new Vector3(1, v, 0));
        }
        break;

        case 3:
        {
            //a + 等级 * b形式
            if (expression.Count != 2)
            {
                EDebug.LogErrorFormat("CalExpression failed. type {0} expression {1} is invalid", type, expression);
                return(Vector2.zero);
            }
            float a = expression[0].ToObject <float>();
            float b = expression[1].ToObject <float>();
            return(new Vector3(0, a + extra * b, 0));
        }
        break;

        case 4:
        {
            //返回两个参数,第一个参数为a + 等级 * b形式,第二个参数为返回原值形式
            if (expression.Count != 3)
            {
                EDebug.LogErrorFormat("CalExpression failed. type {0} expression {1} is invalid", type, expression);
                return(Vector2.zero);
            }
            float a = expression[0].ToObject <float>();
            float b = expression[1].ToObject <float>();
            float c = expression[2].ToObject <float>();
            return(new Vector3(a + extra * b, c, 0));
        }
        break;

        case 5:
        {
            //返回三个参数,(a, b, c)
            if (expression.Count != 3)
            {
                EDebug.LogErrorFormat("CalExpression failed. type {0} expression {1} is invalid", type, expression);
                return(Vector2.zero);
            }
            float a = expression[0].ToObject <float>();
            float b = expression[1].ToObject <float>();
            float c = expression[2].ToObject <float>();
            return(new Vector3(a, b, c));
        }
        break;

        default:
            return(Vector3.zero);
        }
    }
Example #9
0
    /// <summary>
    /// 开始一场战斗
    /// </summary>
    /// <param name="isPvp">比赛性质,pve还是pvp</param>
    /// <param name="treasures">宝箱数量</param>
    public void CreateFight(bool isPvp, int treasures = 0)
    {
        this.State = FightState.Init;
        if (this.Fighters == null)
        {
            EDebug.LogError("FightLogic.CreateFight failed, fighters is null");
            return;
        }
        if (this.EnemyFighters == null)
        {
            EDebug.LogError("FightLogic.CreateFight failed, fighters is null");
            return;
        }
        if (this.Fighters.Count == 0)
        {
            EDebug.LogError("FightLogic.CreateFight failed, fighters is empty");
            return;
        }
        if (this.EnemyFighters.Count == 0)
        {
            EDebug.LogError("FightLogic.CreateFight failed, enemyFighters is empty");
            return;
        }

        this.TotalRound = this.EnemyFighters.Count;
        this.CurRound   = 0;
        this.IsPvp      = isPvp;
        this.Treasures  = treasures;
        this.DropMgrObj = new DropMgr();
        aStarFinder     = new AStarFinder(PathFinder.V_GRID, (this.TotalRound * 3 + 1) * PathFinder.H_GRID);

        List <FightUnit> allUnit = new List <FightUnit>();

        for (int idx = 0; idx < Fighters.Count; ++idx)
        {
            allUnit.Add(Fighters[idx]);
        }
        for (int idx = 0; idx < EnemyFighters.Count; ++idx)
        {
            for (int idx2 = 0; idx2 < EnemyFighters[idx].Count; ++idx2)
            {
                allUnit.Add(EnemyFighters[idx][idx2]);
            }
        }

        for (int idx = 0; idx < allUnit.Count; ++idx)
        {
            allUnit[idx].UID = ++UID;
        }
        ZEventSystem.Dispatch(EventConst.OnCreateFight, allUnit);

        //Test~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        for (int idx = 0; idx < Fighters.Count; ++idx)
        {
            FightUnit unit = Fighters[idx];
            _createFightUnitView(unit);
        }

        MapMgr.Instance.CreateFightMap(1, TotalRound);
        CamMgrObj = GameObject.Find("Main Camera").GetComponent <CamMgr>();

        //EndTest~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        //注册事件
        ZEventSystem.Register(EventConst.OnFightUnitDie, this, "OnUnitDie");
        ZEventSystem.Register(EventConst.OnFightStateChange, this, "OnFightStateChange");
        ZEventSystem.Register(EventConst.OnRequestUnitPause, this, "OnRequestUnitPause");
        ZEventSystem.Register(EventConst.OnFightMaskOver, this, "OnFightMaskOver");
        ZEventSystem.Register(EventConst.OnGamePause, this, "OnGamePause");

        //CamMgrObj.StartDissolve();
        CamMgrObj.PlayStartEffect();
        NextRound();
        ProcessCtrl.Instance.AddUpdate(this);
    }
Example #10
0
    public void Update()
    {
        if (_openDisconnect)
        {
            CanvasView.Instance.OpenConnect(true);
            _openDisconnect = false;
        }
        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            return;
        }
        if (client.Connected == true)
        {
            if (_login)
            {
                if (lastKeepAliveReceive > 0 && Time.time - lastKeepAliveReceive > KeepAliveTimeOut)
                {
                    OnDisconnect();
                    return;
                }
                if (Time.time - lastKeepAliveSend >= KeepAliveInterval)
                {
                    try
                    {
                        client.BeginSend(keepalive, 0, 16, SocketFlags.None, OnSendCallback, client);
                        lastKeepAliveSend = Time.time;
                    }
                    catch (SocketException se)
                    {
                        EDebug.LogErrorFormat("Client KeepAlive Socket Exception {0}", se.Message);
                        OnDisconnect();
                        return;
                    }
                }
                if (_msgSend.Count > 0)
                {
                    byte[] buffer = _msgSend.First.Value;
                    try
                    {
                        client.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, OnSendCallback, client);
                        Debug.Log("Send Data Over");
                        _msgSend.RemoveFirst();
                    }
                    catch (Exception e)
                    {
                        EDebug.LogErrorFormat("Client Socket Exception {0}", e.ToString());
                        OnDisconnect();
                    }
                }
            }
            if (_msgReceived.Count > 0)
            {
                ServerMsgObj serverMsgPair = _msgReceived.First.Value;
                //如果是登录消息,截获一下
                if (serverMsgPair.MsgId == (int)ServerMsgId.DCMD_AUTH_SUCCEEDED)
                {
                    OnLoginResult(true);
                }
                else if (serverMsgPair.MsgId == (int)ServerMsgId.ECMD_AUTH_FAILED)
                {
                    OnLoginResult(false);
                }
                else if (serverMsgPair.MsgId == (int)ServerMsgId.CCMD_KEEP_ALIVE)
                {
                    //收到心跳
                    lastKeepAliveReceive = Time.time;
                }

                try
                {
                    MsgFactory.Instance.OnRecvMsg(serverMsgPair);
                }
                catch (Exception e)
                {
                    throw new Exception(string.Format("Client->MsgFactory.Instance.OnRecvMsg error, {0}", e.ToString()));
                }
                finally
                {
                    if (_msgReceived != null && _msgReceived.Count > 0)
                    {
                        _msgReceived.RemoveFirst();
                    }
                }
            }
        }
    }
Example #11
0
    public void SetDataAnalyze(List <FightUnit> fighters, List <FightUnit> enemies)
    {
        if (DataAnalyzeViewLeft == null || DataAnalyzeViewRight == null)
        {
            EDebug.LogError("DataAnalyzeNode missing!");
            return;
        }
        int maxHarm = 0;

        for (int idx = 0; idx < fighters.Count; ++idx)
        {
            FightUnit unit = fighters[idx];
            if (unit == null)
            {
                continue;
            }
            if (unit.HarmCount > maxHarm)
            {
                maxHarm = unit.HarmCount;
            }
        }
        for (int idx = 0; idx < enemies.Count; ++idx)
        {
            FightUnit unit = enemies[idx];
            if (unit == null)
            {
                continue;
            }
            if (unit.HarmCount > maxHarm)
            {
                maxHarm = unit.HarmCount;
            }
        }

        float nodeHeight = DataAnalyzeViewLeft.gameObject.GetComponent <RectTransform>().sizeDelta.y;

        for (int idx = 0; idx < fighters.Count; ++idx)
        {
            FightUnit unit = fighters[idx];
            if (unit == null)
            {
                continue;
            }
            GameObject node = GameObject.Instantiate(DataAnalyzeViewLeft.gameObject);
            node.transform.SetParent(Datas_obj.transform, false);
            RectTransform nodeRect = node.GetComponent <RectTransform>();
            nodeRect.anchoredPosition = new Vector2(nodeRect.sizeDelta.x / 2, -(idx + 0.5f) * nodeRect.sizeDelta.y);
            DataAnalyzeView nodeView = node.GetComponent <DataAnalyzeView>();
            nodeView.Init();
            nodeView.SetInfo(JsonMgr.GetSingleton().GetHeroByID(unit.HeroId).headid, unit.Rare, unit.Star, unit.Level, unit.HarmCount, maxHarm);
        }

        for (int idx = 0; idx < enemies.Count; ++idx)
        {
            FightUnit unit = enemies[idx];
            if (unit == null)
            {
                continue;
            }
            GameObject node = GameObject.Instantiate(DataAnalyzeViewRight.gameObject);
            node.transform.SetParent(Datas_obj.transform, false);
            RectTransform nodeRect = node.GetComponent <RectTransform>();
            nodeRect.anchoredPosition = new Vector2(-nodeRect.sizeDelta.x / 2, -(idx + 0.5f) * nodeRect.sizeDelta.y);
            DataAnalyzeView nodeView = node.GetComponent <DataAnalyzeView>();
            nodeView.Init();
            int headId = 0;
            if (unit.IsMonster)
            {
                headId = JsonMgr.GetSingleton().GetMonsterByID(unit.HeroId).headid;
            }
            else
            {
                headId = JsonMgr.GetSingleton().GetHeroByID(unit.HeroId).headid;
            }

            nodeView.SetInfo(headId, unit.Rare, unit.Star, unit.Level, unit.HarmCount, maxHarm);
        }
        RectTransform datasRect = Datas_obj.GetComponent <RectTransform>();

        datasRect.sizeDelta = new Vector2(datasRect.sizeDelta.x, Mathf.Max(fighters.Count, enemies.Count) * nodeHeight);
    }
Example #12
0
    public void Update()
    {
        if (this.BuffTime > 0)
        {
            this.AccTime += Time.deltaTime;
            if (AccTime >= this.BuffTime)
            {
                if (this.Mgr != null)
                {
                    Mgr.RemoveBuff(this.UID);
                }
                else
                {
                    EDebug.LogErrorFormat("Buff {0} over, Could not find the mgr..", this.BuffId);
                }
            }
        }

        switch (Type)
        {
        case BuffType.Shield:
        {
            if (this.ShieldHP <= 0)
            {
                if (Mgr != null)
                {
                    Mgr.OnShieldBreak(this.BuffId);
                    Mgr.RemoveBuff(this.UID);
                }
                else
                {
                    EDebug.LogErrorFormat("Buff {0} over, Could not find the mgr..", this.BuffId);
                }
            }
        }
        break;

        case BuffType.Times:
        {
            this.AccBuffCD += Time.deltaTime;
            if (this.AccBuffCD >= this.BuffCD)
            {
                if (Mgr != null)
                {
                    Mgr.TakeEffect(this);
                }
                else
                {
                    EDebug.LogErrorFormat("Buff {0} cd over, Could not find the mgr..", this.BuffId);
                }
                this.UseTimes--;
                this.AccBuffCD = 0;
                if (this.UseTimes <= 0)
                {
                    if (Mgr != null)
                    {
                        Mgr.RemoveBuff(this.UID);
                    }
                    else
                    {
                        EDebug.LogErrorFormat("Buff {0} over, Could not find the mgr..", this.BuffId);
                    }
                }
            }
        }
        break;

        default:
            break;
        }
    }
Example #13
0
 public void OnStubSaveFailed(ServerMsgObj msg)
 {
     EDebug.LogErrorFormat("Stub Save failed");
 }
Example #14
0
    /// <summary>
    /// 有战斗单位死亡
    /// </summary>
    public void OnUnitDie(FightUnit unit)
    {
        if (unit == null)
        {
            EDebug.LogError("FightLogic.OnUnitDie, unit is null");
            return;
        }

        bool isEnemyDie = unit.IsEnemy;

        List <FightUnit> unitList   = isEnemyDie ? EnemyFighters[CurRound - 1] : Fighters;
        bool             allUnitDie = true;

        for (int idx = 0; idx < unitList.Count; ++idx)
        {
            if (!unitList[idx].IsDead)
            {
                allUnitDie = false;
                break;
            }
        }
        if (allUnitDie)
        {
            for (int idx = 0; idx < AllFighters.Count; ++idx)
            {
                FightUnit fightUnit = AllFighters[idx];
                if (fightUnit.IsSummon)
                {
                    ZEventSystem.Dispatch(EventConst.ForceDestroyView, fightUnit);
                }
                fightUnit.SystemProtect = true;
            }
            if (isEnemyDie)
            {
                //敌人死光了
                for (int idx = 0; idx < AllFighters.Count; ++idx)
                {
                    FightUnit u = AllFighters[idx];
                    if (u.IsDead)
                    {
                        continue;
                    }
                }
                if (CurRound < TotalRound)
                {
                    State = FightState.Continue;
                }
                else
                {
                    //战斗胜利
                    _terminate(true);
                }
            }
            else
            {
                //自己死光了
                _terminate(false);
            }
        }

        //宝箱掉落
        if (Treasures > 0)
        {
            if (isEnemyDie)
            {
                if (allUnitDie && CurRound >= TotalRound)
                {
                    this.DropMgrObj.CreateTreasure(unit.CurPos, Treasures);
                    Treasures = 0;
                }
                else
                {
                    if (Random.Range(0, 1.0f) < this.DropMgrObj.TreasureRate)
                    {
                        this.DropMgrObj.CreateTreasure(unit.CurPos, 1);
                        --Treasures;
                    }
                }
            }
        }
    }
    public void BuildHeroEvent(int heroId)
    {
        if (showID == heroId)
        {
            return;
        }
        if (Herotf != null)
        {
            Destroy(Herotf.gameObject);
        }
        Vector3 v3 = billboard.GetCamPos();

        v3.y           += -1.45f;
        v3.z           += 10f;
        billboard.Layer = LayerMask.NameToLayer("Hero");
        HeroData data = HeroMgr.GetSingleton().GetHeroData(heroId);

        GameObject heroGo = ResourceMgr.Instance.LoadResource(data.JsonData.resid) as GameObject;

        if (heroGo == null)
        {
            return;
        }
        heroGo = Instantiate(heroGo);
        Herotf = heroGo.transform;
        Herotf.localPosition = v3;
        int horseid = data.JsonData.horseid;

        if (horseid != 0)
        {
            GameObject horseGo = ResourceMgr.Instance.LoadResource(horseid) as GameObject;
            if (horseGo == null)
            {
                EDebug.LogError("加载马匹资源失败 -- " + horseid);
                return;
            }
            horseGo = Instantiate(horseGo, heroGo.transform, false);
            horseGo.transform.localPosition = Vector3.zero;
            horseGo.transform.localScale    = Vector3.one;
        }
        HeroShow hs = JsonMgr.GetSingleton().GetHeroShowByID(heroId);
        Vector3  vc = billboard.Cam.transform.eulerAngles;

        vc.x = hs.RotX;
        Quaternion qc = new Quaternion
        {
            eulerAngles = vc
        };

        billboard.Cam.transform.rotation = qc;
        Vector3 vh = heroGo.transform.localEulerAngles;

        vh.y = hs.RotY + +180f;
        Quaternion qh = new Quaternion
        {
            eulerAngles = vh
        };

        heroGo.transform.rotation = qh;
        billboard.Fov             = hs.Fov;
        showID = heroId;
        heroGo.SetLayer("Hero");
        player = heroGo.AddComponent <AnimatorPlayer>();
        player.RandomPlay(true);
    }
Example #16
0
    /// <summary>
    /// 开始下一回合,生成当前回合的出手顺序列表
    /// </summary>
    public void NextRound()
    {
        if (CurRound != 0)
        {
            List <FightUnit> curEnemy = EnemyFighters[CurRound - 1];
            for (int idx = 0; idx < curEnemy.Count; ++idx)
            {
                //最好判断一下死没死光
                if (!curEnemy[idx].IsDead && !curEnemy[idx].IsSummon)
                {
                    EDebug.LogErrorFormat("FightLogic.NextRound failed, round {0} has enemy alive", CurRound);
                    return;
                }
            }
        }
        CurRound++;
        if (CurRound > TotalRound)
        {
            EDebug.LogErrorFormat("FightLogic.NextRound failed, round:{0} total round:{1}", CurRound, TotalRound);
            return;
        }
        ZEventSystem.Dispatch(EventConst.OnNewRound, this.CurRound, this.TotalRound);
        this.AccRoundTime = 0;
        AllFighters.Clear();
        AllFighters.AddRange(Fighters);
        List <FightUnit> curRoundEnemy = EnemyFighters[CurRound - 1];

        //Test~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        for (int idx = 0; idx < curRoundEnemy.Count; ++idx)
        {
            FightUnit enemyUnit = curRoundEnemy[idx];
            _createFightUnitView(enemyUnit);
        }

        //EndTest~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        AllFighters.AddRange(curRoundEnemy);
        //排出手顺序
        AllFighters.Sort((FightUnit a, FightUnit b) => {
            if (a.Order > b.Order)
            {
                return(1);
            }
            else if (a.Order < b.Order)
            {
                return(-1);
            }
            else
            {
                if (a.IsEnemy && !b.IsEnemy)
                {
                    return(IsPvp ? 1 : -1);
                }
                else if (!a.IsEnemy && b.IsEnemy)
                {
                    return(IsPvp ? -1 : 1);
                }
                else
                {
                    return(0);
                }
            }
        });

        State = FightState.Prepare;
        ZEventSystem.Dispatch(EventConst.OnInitEvent);
    }
Example #17
0
    /// <summary>
    /// 战斗状态改变
    /// </summary>
    /// <param name="state"></param>
    public void OnFightStateChange(FightState state)
    {
        switch (state)
        {
        case FightState.Init:
            break;

        case FightState.Prepare:
            //设置所有单位初始站位,目标站位
            for (int idx = 0; idx < AllFighters.Count; ++idx)
            {
                AllFighters[idx].SystemProtect = false;
                AllFighters[idx].InitPassiveSkill();
            }
            ZEventSystem.Register(EventConst.OnUnitMoveOver, this, "OnUnitMoveOver");
            EnterBattileField();
            break;

        case FightState.Fight:
            EDebug.Log("战斗开始");
            CamMgrObj.ChangeCam(true);
            //使用被动技能
            for (int idx = 0; idx < AllFighters.Count; ++idx)
            {
                FightUnit u = AllFighters[idx];
                if (u.IsDead)
                {
                    continue;
                }
                AllFighters[idx].FightIntervalAcc = 0;
                AllFighters[idx].FightInterval    = 0;
            }
            break;

        case FightState.Continue:
            CamMgrObj.ChangeCam(false);

            clearFightState(false);

            for (int idx = 0; idx < Fighters.Count; ++idx)
            {
                FightUnit u = Fighters[idx];
                if (u.IsDead)
                {
                    continue;
                }
                u.RoundOver();
                u.NewRound();
            }
            ExitBattleField();
            break;

        case FightState.Over:
            EDebug.Log("战斗结束, 是否胜利:" + HasWin);
            clearFightState(true);
            break;

        default:
            break;
        }
    }