public void TestAddMoveCtrlCommand(long time, float dirX, float dirZ, SpeedChangeType speedType, int index, bool CheckTime = true)
 {
     //检查是否是合法参数
     if (CheckTime && !CheckCMDTime(time))
     {
         return;
     }
     MMRs.AddMoveCtrlCommand(time, dirX, dirZ, speedType, index);
 }
Esempio n. 2
0
    public void Clear()
    {
        TickTime_Ms_Long = -1;
        CMDTime          = -1;

        Pos.x = -1;
        Pos.y = -1;
        Pos.z = -1;

        Dir.x = 0;
        Dir.y = 0;
        Dir.z = 0;

        Speed     = -1;
        SpeedType = SpeedChangeType.None;
        CMDIdx    = -1;
    }
Esempio n. 3
0
    public bool AddMoveCtrlCommand(long time, float dirX, float dirZ, SpeedChangeType speedType, int index)
    {
        Log("Enter AddMoveCtrlCommand:" + time);
        if (dirX == 0 && dirZ == 0 && speedType == SpeedChangeType.None)
        {
            Log("dirX == 0 && dirZ == 0 && speedType == SpeedChangeType.None");
            Log("Leave AddMoveCtrlCommand:" + time);
            return(false);
        }

        var previous = FindPreviousMMR(time);

        Log("previous:" + previous.ToString());

        SkillVector3 curDir = previous.GetDir();

        if (curDir.x == dirX && curDir.z == dirZ && speedType == SpeedChangeType.None)
        {
            Log("curDir.x == dirX && curDir.z == dirZ && speedType == SpeedChangeType.None");
            Log("Leave AddMoveCtrlCommand:" + time);
            return(false);
        }

        MagicMoveRecord newRecord = CalcNextMMR(previous, dirX, dirZ, speedType, time, index);

        var realPrevious = AddRecord(newRecord);

        if (realPrevious == null)
        {
            Log(" AddRecord(newRecord) failed:");
            Log("Leave AddMoveCtrlCommand:" + time);
            return(false);
        }
        Log("RealPrevious:" + realPrevious.ToString());

        var beforeTime = newRecord.GetTime();

        FixMMRs(realPrevious);

        if (beforeTime != newRecord.GetTime())
        {
            Log("Lesdfsdfave sfaf:" + newRecord);
        }
        Log("Leave AddMoveCtrlCommand:" + time);
        return(true);
    }
Esempio n. 4
0
    public bool TestCancelMoveCtrlCommand(long time, float dirX, float dirZ, SpeedChangeType speedType, int index, int deleteIndex)
    {
        DebugSkillUpDown("Cancel Before ADD");
        bool ret = true;

        NeedFixRecords.Clear();

        //如果要取消的操作已经执行了,那么就不需要取消了
        if (FutureExeMoves.Count > 0)
        {
            int             deleteIdx = -1;
            bool            bAdd      = false;
            MagicMoveRecord tar       = null;
            for (int i = FutureExeMoves.Count - 1; i >= 0; i--)
            {
                var tmp = FutureExeMoves[i];
                if (tmp.GetCMDIndex() == deleteIndex && tmp.GetSpeedType() == SpeedChangeType.SkillDown)
                {
                    bAdd      = true;
                    deleteIdx = i;
                    tar       = tmp;
                    break;
                }
            }
            if (deleteIdx >= 0)
            {
                DebugConsole.LogWarning("discard 22222:" + tar.ToString());
                FutureExeMoves.RemoveAt(deleteIdx);
            }


            if (bAdd)
            {
                ret = true;
                TestAddMoveCtrlCommand(time, dirX, dirZ, speedType, index);
            }
            else
            {
                ret = false;
            }
        }
        DebugSkillUpDown("Cancel After ADD");
        return(ret);
    }
Esempio n. 5
0
    public void SetInitPos(float x, float z, long NowTime_Ms_Long, float dirX, float dirZ, float speed, long cmdTime, float minX, float maxX, float minZ, float maxZ, SpeedChangeType speedType, int cmdIdx)
    {
        Pos.x            = x;
        Pos.y            = 0;
        Pos.z            = z;
        Dir.x            = dirX == 0 ? 0 : Mathf.Abs(dirX) / dirX;
        Dir.y            = 0;
        Dir.z            = dirZ == 0 ? 0 : Mathf.Abs(dirZ) / dirZ;
        Speed            = speed;
        TickTime_Ms_Long = NowTime_Ms_Long;
        CMDTime          = cmdTime;

        MinX = minX + CenterPoint + EdgeWidth;
        MaxX = maxX + CenterPoint - 1 - EdgeWidth;
        MinZ = minZ + CenterPoint + EdgeWidth;
        MaxZ = maxZ + CenterPoint - 1 - EdgeWidth;

        SpeedType = speedType;
        CMDIdx    = cmdIdx;
    }
Esempio n. 6
0
    float CalcSpeed(SpeedChangeType spdType, float nowSpd)
    {
        switch (spdType)
        {
        case SpeedChangeType.SkillUp:
            return(nowSpd * 2f);

        case SpeedChangeType.SkillDown:
            return(nowSpd / 2f);

        case SpeedChangeType.ItemUp:
            return(nowSpd * 8f);

        case SpeedChangeType.ItemDown:
            return(nowSpd / 8f);

        case SpeedChangeType.None:
            return(nowSpd);

        default:
            Log("error spdType:" + spdType);
            return(0);
        }
    }
Esempio n. 7
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() + " :" + 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 + ")" + " :" + newRecord);
            //Log(index + " Dir Changed : " + "(" + curDir.x + "," + curDir.z + ")" + "---->>>----" + "(" + dirX + "," + dirZ + ")" + " BeginPos:" + beginPos.ToString() + /*" NowPos:" + NextPos.ToString() +*/ " Time:" + newRecord.GetTime());
        }
        return(newRecord);
    }
Esempio n. 8
0
 public void SetInitPos(float x, float z, long NowTime_Ms_Long, float dirX, float dirZ, float speed, long cmdTime, float minX, float maxX, float minZ, float maxZ, SpeedChangeType speedType, int cmdIdx)
 {
     //只有这里可以设置速度和方向为0
     Clear();
     MinX = minX;
     MaxX = maxX;
     MinZ = minZ;
     MaxZ = maxZ;
     CurMagicRecord.SetInitPos(x, z, NowTime_Ms_Long, dirX, dirZ, speed, cmdTime, minX, maxX, minZ, maxZ, speedType, cmdIdx);
 }
Esempio n. 9
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");
    }