コード例 #1
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="add"></param>
    /// <returns>真正意义上的前一个mmr</returns>
    private MagicMoveRecord AddRecord(MagicMoveRecord add)
    {
        //需要判断一下是否可以加入,因为有的时候会有两个连续的转向命令,但是在同一个拐点只能接受第1个命令,后来的要抛弃,加速减速也可能会有这个问题,但是如果是提前设置的减速点和拐点重合,那么可以add成功
        List <MagicMoveRecord> equalList = new List <MagicMoveRecord>();

        if (add.GetSpeedType() == SpeedChangeType.None)
        {
            foreach (var r in Records.Reverse <MagicMoveRecord>())
            {
                if (r.GetTime() == add.GetTime())
                {
                    equalList.Add(r);
                }
                else if (r.GetTime() < add.GetTime())
                {
                    break;
                }
            }
            foreach (var e in equalList)
            {
                if (e.GetSpeedType() == add.GetSpeedType())
                {
                    Log("mutli SpeedChangeType.None :" + add.ToString());
                    return(null);
                }
            }
        }


        {
            Records.Add(add);
            Records.Sort(moveRecordComparator);
            var idx = Records.IndexOf(add) - 1;
            if (idx < 0)
            {
                Log("if(idx < 0):" + idx);
                return(null);
            }
//          MagicMoveRecord l = null;
//          foreach (var r in Records)
//          {
//              if (l != null && l.GetTime() == r.GetTime())
//              {
//                  bool a = false;
//                  while(a)
//                  {
//
//                  }
//              }
//              l = r;
//          }
            return(Records[idx]);
        }
    }
コード例 #2
0
    private void CalcPoints()
    {
        if (CurNeedExeMoves.Count > 0)
        {
            MagicMoveRecord tmp = CurNeedExeMoves[0];
            if (tmp.GetTime() < NextPosTime)
            {
                BacktrackingPoints.Add(tmp.GetPos());
                BacktrackingPoints.Add(NextPos);
            }
        }
        if (BacktrackingPoints.Count <= 0)
        {
            TrackingPoints.Add(NextPos);
        }
        while (CurNeedExeMoves.Count > 0)
        {
            MagicMoveRecord tmp = CurNeedExeMoves[0];
            CurNeedExeMoves.RemoveAt(0);

            TrackingPoints.Add(tmp.GetPos());

            HistoryRecords.Add(CurMagicRecord);
            CurMagicRecord = tmp;
        }
        return;
    }
コード例 #3
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);
    }
コード例 #4
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);
    }
コード例 #5
0
 private void FindNeedExeMove(long NowTime_Ms_Long)
 {
     while (FutureExeMoves.Count > 0)
     {
         MagicMoveRecord tmp = FutureExeMoves[0];
         if (tmp != null && tmp.GetTime() < NowTime_Ms_Long)
         {
             FutureExeMoves.RemoveAt(0);
             CurNeedExeMoves.Add(tmp);
         }
         else
         {
             break;
         }
     }
 }
コード例 #6
0
 public long Compare(MagicMoveRecord other)
 {
     return(Compare(other.GetTime()));
 }
コード例 #7
0
 public bool IsOutdate(MagicMoveRecord other)
 {
     return(IsOutdate(other.GetTime()));
 }
コード例 #8
0
    private MagicMoveRecord FixMMRs(MagicMoveRecord first)
    {
        MagicMoveRecord last = first;

        for (int i = 0; i < NeedFixRecords.Count;)
        {
            if (last != null)
            {
                MagicMoveRecord tmp   = NeedFixRecords[i];
                var             temp2 = CalcNextMMR(last, tmp.GetDir().x, tmp.GetDir().z, tmp.GetSpeedType(), tmp.GetTime(), tmp.GetCMDIndex(), tmp);
                if (temp2 != null)
                {
                    i++;
                }
                else
                {
                    if (last == first && first.GetCMDIndex() > tmp.GetCMDIndex())
                    {
                        first = tmp;
                    }
                    else
                    {
                        Log("if(last==first && first.GetCMDIndex() > tmp.GetCMDIndex())@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22");
                    }
                    NeedFixRecords.RemoveAt(i);
                    Log("discard:" + tmp.ToString());
                }
                last = tmp;
            }
        }
        return(first);
    }
コード例 #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");
    }