Esempio n. 1
0
    private MagicMoveRecord CalcNextMMR(MagicMoveRecord last, float dirX, float dirZ, SpeedChangeType speedType, long time, int index, MagicMoveRecord newRecord = null)
    {
        //MagicMoveRecord newRecord = null;
        SkillVector3 curDir   = last.GetDir();
        float        curSpeed = last.GetSpeed();

        if (newRecord == null)
        {
            newRecord = GetNewRecord();
        }
        if (speedType != SpeedChangeType.None)
        {
            SkillVector3 beginPos = new SkillVector3();
            last.GetNextPos_2D(time, ref beginPos);
            //newRecord = GetNewRecord();
            newRecord.SetInitPos(beginPos.x, beginPos.z, time, curDir.x, curDir.z, CalcSpeed(speedType, curSpeed), time, MinX, MaxX, MinZ, MaxZ, speedType, index);

            //FixMMRs(newRecord);
            Log(index + " Speed Changed : " + curSpeed + "---->>>----" + newRecord.GetSpeed() + " BeginPos:" + beginPos.ToString() + " NowPos:" + NextPos.ToString() + " Time:" + newRecord.GetTime());
        }
        else
        {
            SkillVector3 beginPos = new SkillVector3();
            if (last.GetTime() == newRecord.GetTime())
            {
                return(null);
            }
            long nextTime = last.GetNextMagicPosAndTime_2D(time, ref beginPos);
            //newRecord = GetNewRecord();
            newRecord.SetInitPos(beginPos.x, beginPos.z, nextTime, dirX, dirZ, last.GetSpeed(), time, MinX, MaxX, MinZ, MaxZ, speedType, index);
            Log(index + " Dir Changed : " + "(" + curDir.x + "," + curDir.z + ")" + "---->>>----" + "(" + dirX + "," + dirZ + ")" + " BeginPos:" + beginPos.ToString() + " NowPos:" + NextPos.ToString() + " Time:" + newRecord.GetTime());
        }
        return(newRecord);
    }
Esempio n. 2
0
    public void TestAddMoveCtrlCommand(long time, float dirX, float dirZ, SpeedChangeType speedType, int index)
    {
        DebugSkillUpDown("Before ADD");
        //检查是否是合法参数
        //如果这个时间点比服务器时间更早
        //if(time <= CurMagicRecord.GetTime())
        //{
        // throw new Exception("这个时间点比服务器时间更早:" + time + "@" + NowTime_Ms_Long );
        //}
        //先找到该时间点前一个MagicMoveRecord是哪个,可能是当前的MagicMoveRecord,也可能是缓存队列里某一个,所以遍历一下
        //上边已经排除了一个不可能的情况,现在看其他情况
        {
            NeedFixRecords.Clear();

            MagicMoveRecord cmdLastRecord = null;
            FindCMDType     find          = FindCMDType.None;
            int             findIdx       = -1;
            if (HistoryRecords.Count > 0)
            {
                for (int i = HistoryRecords.Count - 1; i >= 0; i--)
                {
                    MagicMoveRecord tmp = HistoryRecords[i];
                    if (tmp.GetTime() <= time && tmp.GetCMDTime() <= time)
                    {
                        cmdLastRecord = tmp;
                        break;
                    }
                    else
                    {
                        findIdx = i;
                        find    = FindCMDType.History;
                    }
                }
            }

            {
                if (find == FindCMDType.None)
                {
                    if (CurMagicRecord != null && CurMagicRecord.GetTime() <= time && CurMagicRecord.GetCMDTime() <= time)
                    {
                        cmdLastRecord = CurMagicRecord;
                        //Log("CurMagicRecord:" + CurMagicRecord.ToString());
                    }
                    else
                    {
                        find = FindCMDType.Now;
                    }
                }
                if (find == FindCMDType.None)
                {
                    if (FutureExeMoves.Count > 0)
                    {
                        foreach (var tmp in FutureExeMoves)
                        {
                            //Log("FutureExeMoves:" + tmp.ToString());
                            if (tmp.GetTime() <= time && tmp.GetCMDTime() <= time)
                            {
                                cmdLastRecord = tmp;
                            }
                            else
                            {
                                findIdx = FutureExeMoves.IndexOf(tmp);
                                find    = FindCMDType.Future;
                                //这是个优先权队列,所以一旦发现不满足了就都不用检查了
                                break;
                            }
                        }
                    }
                }
            }

            Log("LastMoveCmd:" + cmdLastRecord.ToString());
            //根据上一个关键节点计算这个关键节点
            if (dirX == 0 && dirZ == 0 && speedType == SpeedChangeType.None)
            {
                Log("dirX == 0 && dirZ == 0");
                return;
            }
            SkillVector3 curDir   = cmdLastRecord.GetDir();
            float        curSpeed = cmdLastRecord.GetSpeed();
            if (curDir.x == dirX && curDir.z == dirZ && speedType == SpeedChangeType.None)
            {
                Log("curDir.x == dirX && curDir.z == dirZ && speedType == SpeedChangeType.None");
                return;
            }
            MagicMoveRecord newRecord = CalcNextMMR(cmdLastRecord, dirX, dirZ, speedType, time, index);
            Log(" find ret :" + find);
            //速度改变的情况
            //if (speedType != SpeedChangeType.None)
            {
                switch (find)
                {
                case FindCMDType.Future:
                {
                    if (FutureExeMoves.Count > findIdx)
                    {
                        NeedFixRecords.AddRange(FutureExeMoves.GetRange(findIdx, FutureExeMoves.Count - findIdx));
                        FutureExeMoves.RemoveRange(findIdx, FutureExeMoves.Count - findIdx);
                    }
                }
                break;

                case FindCMDType.History:
                {
                    if (HistoryRecords.Count > findIdx)
                    {
                        NeedFixRecords.AddRange(HistoryRecords.GetRange(findIdx, HistoryRecords.Count - findIdx));
                        HistoryRecords.RemoveRange(findIdx, HistoryRecords.Count - findIdx);
                    }

                    if (findIdx == 0)
                    {
                        throw new Exception("findIdx == 0");
                    }

                    NeedFixRecords.Add(CurMagicRecord);
                    CurMagicRecord = HistoryRecords[findIdx - 1];
                    HistoryRecords.RemoveAt(findIdx - 1);

                    if (FutureExeMoves.Count > 0)
                    {
                        NeedFixRecords.AddRange(FutureExeMoves);
                        FutureExeMoves.Clear();
                    }
                }
                break;

                case FindCMDType.Now:
                {
                    NeedFixRecords.Add(CurMagicRecord);
                    if (HistoryRecords.Count == 0)
                    {
                        throw new Exception("HistoryRecords.Count() == 0");
                    }
                    CurMagicRecord = HistoryRecords[HistoryRecords.Count - 1];
                    HistoryRecords.RemoveAt(HistoryRecords.Count - 1);
                    if (FutureExeMoves.Count > 0)
                    {
                        NeedFixRecords.AddRange(FutureExeMoves);
                        FutureExeMoves.Clear();
                    }
                }
                break;
                }

                newRecord = FixMMRs(newRecord);
                //Log(index + " Speed Changed : " + curSpeed + "---->>>----" + speed + " BeginPos:" + beginPos.ToString() + " NowPos:" + NextPos.ToString());
            }
            if (newRecord.GetTime() > cmdLastRecord.GetTime() || (newRecord.GetTime() == cmdLastRecord.GetTime() && newRecord.GetSpeedType() != SpeedChangeType.None))
            {
                bool bAdd = true;
                foreach (var tmp in FutureExeMoves)
                {
                    if (tmp.GetTime() == newRecord.GetTime() && tmp.GetSpeedType() == SpeedChangeType.None && newRecord.GetSpeedType() == SpeedChangeType.None)
                    {
                        bAdd = false;
                    }
                }
                if (CurMagicRecord != null && CurMagicRecord.GetTime() == newRecord.GetTime() && CurMagicRecord.GetSpeedType() == SpeedChangeType.None && newRecord.GetSpeedType() == SpeedChangeType.None)
                {
                    bAdd = false;
                }
                if (bAdd)
                {
                    AddFutureExeMoves(newRecord);
                    if (newRecord.GetSpeedType() == SpeedChangeType.SkillUp)
                    {
                        skillupcount++;
                    }
                    else if (newRecord.GetSpeedType() == SpeedChangeType.SkillDown)
                    {
                        skilldowncount++;
                    }
                }
                else
                {
                    Log("abandon 222 " + newRecord.ToString());
                }
            }
            else
            {
                Log("abandon " + newRecord.ToString());
                if (newRecord.GetSpeedType() != SpeedChangeType.None)
                {
                    DebugConsole.LogError("SDFEARYTHRTHGFHGDSFSDFSDFSDAF");
                }
            }
        }
        {
            FixToFuture();
        }
        DebugSkillUpDown("After ADD");
    }