public void SetPushVec(Vector2d projA, Vector2d projB, ref bool bAtLeft, ref FixedPoint offsetLen) { if (projA.x == projB.x) { if (projA.y <= projB.y) { bAtLeft = true; offsetLen = projA.y - projA.x; } else { bAtLeft = false; offsetLen = projB.y - projA.x; } } else if (projA.x < projB.x) { bAtLeft = true; offsetLen = projA.y - projB.x; } else { bAtLeft = false; offsetLen = projB.y - projA.x; } }
public void UpdateMoveSpeed() { FixedPoint speed = new FixedPoint(m_csvData.moveSpeed); speed += GetBuffSpeed(speed); SetSpeed(speed); }
public void StartAutoMove(ref List <Vector2d> pathList, FixedPoint divSpeed) { m_movePath.Clear(); m_pathTime.Clear(); m_curMoveIndex = 0; m_curMoveTime = FixedPoint.zero; m_dirList.Clear(); m_bMovePathing = true; // 给路径赋值 for (int i = 0; i < pathList.Count; i++) { m_movePath.Add(pathList[i]); } // 插入玩家当前起点位置 m_movePath.Insert(0, m_creature.GetPos()); // 开始获取移动时间 FixedPoint runTime = FixedPoint.zero; for (int i = 0; i < m_movePath.Count - 1; i++) { FixedPoint dis = Vector2d.Distance(m_movePath[i], m_movePath[i + 1]); runTime += dis * divSpeed; m_pathTime.Add(runTime); // 方向 m_dirList.Add(m_movePath[i + 1] - m_movePath[i]); } m_pathTime.Insert(0, FixedPoint.N_0); // 在第一个位置时间当然是0了 }
/// <summary> /// 点到OBB最近点 /// </summary> public static Vector2d ClosestPointOBB(Vector2d p, FPObb b) { Vector2d d = p - b.center; Vector2d q = b.center; FixedPoint distX = Vector2d.Dot(d, b.u[0]); if (distX > b.e.x) { distX = b.e.x; } if (distX < -b.e.x) { distX = -b.e.x; } q += b.u[0] * distX; FixedPoint distY = Vector2d.Dot(d, b.u[1]); if (distY > b.e.y) { distY = b.e.y; } if (distY < -b.e.y) { distY = -b.e.y; } q += b.u[1] * distY; return(q); }
/// <summary> /// 返回弧度 /// </summary> public static FixedPoint Atan2_rad(int y, int x) { FixedPoint Y_X, Y_X_temp; FixedPoint result = FixedPoint.zero; Y_X = (x == 0) ? new FixedPoint(x, y) : new FixedPoint(y, x); Y_X_temp = Y_X; if (y == 0) { if (x >= 0) { return(FixedPoint.zero * FixedPoint.Pi); // 在正x轴上为0 } else { return(FixedPoint.Pi); // 在负x轴上为π,180度 } } else if (x > 0 && y > 0) { //第一象限 Y_X = (Y_X <= 1) ? Y_X : 1 / Y_X; result = (Y_X_temp > 1) ? FixedPoint.HalfPi - g_atan_tab[(int)(Y_X * (LUT_NUM - 1))] : (FixedPoint)g_atan_tab[(int)(Y_X * (LUT_NUM - 1))]; } else if (x < 0 && y > 0) { //第二象限 Y_X = (Y_X < -1) ? Y_X = -1 / Y_X : -Y_X; result = (Y_X_temp >= -1) ? FixedPoint.Pi - g_atan_tab[(int)(Y_X * (LUT_NUM - 1))] : //小于45° FixedPoint.HalfPi + g_atan_tab[(int)(Y_X * (LUT_NUM - 1))]; } else if (x < 0 && y < 0) { //第三象限 Y_X = (Y_X <= 1) ? Y_X : 1 / Y_X; result = (Y_X_temp <= 1) ? g_atan_tab[(int)(Y_X * (LUT_NUM - 1))] - FixedPoint.Pi : -FixedPoint.HalfPi - g_atan_tab[(int)(Y_X * (LUT_NUM - 1))]; } else if (x > 0 && y < 0) { //第四象限 Y_X = (Y_X < -1) ? Y_X = -1 / Y_X : -Y_X; result = (Y_X_temp >= -1) ? (FixedPoint)(-g_atan_tab[(int)(Y_X * (LUT_NUM - 1))]) : //小于45° -(FixedPoint.HalfPi - g_atan_tab[(int)(Y_X * (LUT_NUM - 1))]); } else if (x == 0 && y > 0) { result = FixedPoint.HalfPi; } else { result = -FixedPoint.HalfPi; } return(result); }
public int GetTarget(int lookDis) { int targetUid = 0; FixedPoint m_minDis2 = new FixedPoint(999999); List <long> list = CCreatureMgr.GetCreatureList(); for (int i = 0; i < list.Count; i++) { CCreature cc = CCreatureMgr.Get(list[i]); FixedPoint abDis2 = FPCollide.GetDis2(GetPos(), cc.GetPos()); if (abDis2 > new FixedPoint(lookDis * lookDis)) { continue; } if (cc.IsDie() || cc.GetUid() == GetUid()) { continue; } if (abDis2 < new FixedPoint(lookDis * lookDis)) // 如果目标在视线范围内 { if (abDis2 < m_minDis2) { m_minDis2 = abDis2; targetUid = (int)cc.GetUid(); } } } return(targetUid); }
public static FixedPoint Distance2(Vector2d v1, Vector2d v2) { FixedPoint x = v1.x - v2.x; FixedPoint y = v1.y - v2.y; return(x * x + y * y); }
/// <summary> /// 1.获取a到b向量的方向 /// 2.获取a在此方向上的投影点 /// 3.获取a左右为圆半径的距离,组成的直线,为a的投影线 /// 4.获取b的投影线 /// 5.对比2条投影线是否相交 /// 6.如果相交,获取a是否在左边,以及相交的距离 /// 7.根据ab方向,偏移量,可以知道具体偏移向量 /// 8.根据具体偏移向量和是否a在左边,来计算推开的距离 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> private bool CheckCircleAndCircle(Circle a, Circle b, bool bPush = true) { Vector2d axis = a.c - b.c; axis.Normalize(); FixedPoint projPoint = Vector2d.Dot(a.c, axis); FixedPoint min = projPoint - a.r; FixedPoint max = projPoint + a.r; Vector2d projA = new Vector2d(min, max); projPoint = Vector2d.Dot(b.c, axis); min = projPoint - b.r; max = projPoint + b.r; Vector2d projB = new Vector2d(min, max); if (CheckLine(projA, projB)) { if (bPush) { bool bAtLeft = false; FixedPoint offset = FixedPoint.zero; SetPushVec(projA, projB, ref bAtLeft, ref offset); Push(a, b, offset, axis, bAtLeft); } return(true); } return(false); }
public static bool bSphereSphere(FPSphere a, FPSphere b) { Vector2d d = a.c - b.c; FixedPoint dis2 = Vector2d.Dot(d, d); FixedPoint rSum = a.r + b.r; return(dis2 <= rSum * rSum); }
public override bool Equals(object obj) { if (obj is FixedPoint) { FixedPoint f = (FixedPoint)obj; return(m_value == f.m_value); } return(false); }
public virtual void SetSpeed(FixedPoint speed) { m_speed = speed; if (m_vCreature != null) { m_vCreature.SetSpeed(speed.value); } }
public static Vector2d Rotate(Vector2d vec, int angle) { Vector2d last; FixedPoint cos = CustomMath.Cos(angle); FixedPoint sin = CustomMath.Sin(angle); last.x = vec.x * cos + vec.y * sin; last.y = vec.x * -sin + vec.y * cos; return(last); }
public override BtResult Execute() { GetSkillDis(); if (m_skillDis == 0) { AIParam.SendSkill(m_creature, m_dataBase); return(BtResult.Ended); } // 1.实时获取当前选择的技能和目标计算 当前的移动位置 // 2.如果到达,即可结束 int targetUid = m_dataBase.GetData <int>((int)eAIParam.INT_TARGET_UID); CCreature targetCC = CCreatureMgr.Get(targetUid); if (targetCC != null) { FixedPoint dis2 = FPCollide.GetDis2(targetCC.GetPos(), m_creature.GetPos()); if (dis2 < new FixedPoint(m_skillDis * m_skillDis)) { return(BtResult.Ended); } else { // 一秒执行一次 m_curTime += FSPParam.clientFrameMsTime; if (m_curTime >= 30 * FSPParam.clientFrameMsTime) { m_curTime = 0; //Vector2 pPos = targetCC.GetPos(); //m_creature.GoTo(pPos); Vector2d dir = targetCC.GetPos() - m_creature.GetPos(); Vector2d target = m_creature.GetPos() + dir.normalized * new FixedPoint(m_skillDis); Vector2d endPos = CMapMgr.m_map.GetRandomPos(target.x.value, target.y.value, 3, m_creature.m_aiType).ToVector2d(); //Vector2d pPos = targetCC.GetPos(); CmdFspAutoMove cmd = new CmdFspAutoMove(); cmd.m_pos = endPos; if (m_creature.m_aiType == eAIType.Player) { m_creature.SendFspCmd(cmd); } else { m_creature.PushCommand(cmd); } } return(BtResult.Running); } } return(BtResult.Ended); }
public int GetPlayerPropVal(int baseVal, float growVal, int lv) { FixedPoint preVal = new FixedPoint(baseVal); for (int i = 1; i <= lv; i++) { FixedPoint d = (new FixedPoint(baseVal) * new FixedPoint(growVal) * i); preVal = preVal + d; } return((int)preVal.value); }
public void OnHitTarget() { FixedPoint m_minDis2 = new FixedPoint(999999); CCreature target = null; List <long> list = CCreatureMgr.GetCreatureList(); for (int i = 0; i < list.Count; i++) { CCreature creature = CCreatureMgr.Get(list[i]); if (m_listHited != null && m_listHited.Contains((int)list[i])) { continue; } if (m_caster == creature || m_caster.bCamp(creature) || creature.IsDie() || creature == m_rec) { continue; } FixedPoint abDis2 = FPCollide.GetDis2(m_rec.GetPos(), creature.GetPos()); if (abDis2 < new FixedPoint(m_triggerData.Length * m_triggerData.Length)) { if (abDis2 < m_minDis2) { target = creature; m_minDis2 = abDis2; } } } if (target != null) { if (m_listHited == null) { m_listHited = new List <int>(); } Debug.Log("添加单位:" + target.GetUid()); m_listHited.Add((int)target.GetUid()); OnHitAddBuff(m_caster, target, m_listHited); VTrigger vTri = GetVTrigger(); if (vTri != null && m_rec != null && m_rec.GetVObject() != null) { Vector3 sh = m_rec.GetVObject().GetHitHeight(); Vector3 th = target.GetVObject().GetHitHeight(); vTri.SetLineStartPos(GetPos().ToVector3() + sh); vTri.SetLineTargetPos(target.GetPos().ToVector3() + th); } } else { Destory(); } }
public override void Enter(IFspCmdType cmd) { m_cmdFspAutoMove = cmd as CmdFspAutoMove; List <Vector2d> m_movePath = new List <Vector2d>(); CMapMgr.m_map.GetPath(m_creature, m_creature.GetPos(), m_cmdFspAutoMove.m_pos, ref m_movePath); //m_moveEnd = moveEnd; FixedPoint divSpeed = 1 / m_creature.GetSpeed(); StartAutoMove(ref m_movePath, divSpeed); }
public override void ExecuteFrame(int frameId) { Vector2d moveDir = m_cmdFspMove.m_dir.normalized; FixedPoint delta = new FixedPoint(FSPParam.clientFrameScTime) * m_creature.GetSpeed(); Vector2d nextPos = m_creature.m_curPos + moveDir * delta; m_creature.SetPos(nextPos); m_creature.SetDir(moveDir); // 技能前摇时,移动时,模型表现方向失效,比如机枪移动时射击 m_creature.SetSpeed(m_creature.GetSpeed()); //Debug.Log("无障碍移动"); m_creature.m_vCreature.SetBarrier(false); }
public static Vector2d Lerp(Vector2d a, Vector2d b, FixedPoint t) { if (t >= FixedPoint.one) { return(b); } else if (t <= FixedPoint.zero) { return(a); } FixedPoint x = b.x * t + a.x * (FixedPoint.one - t); FixedPoint y = b.y * t + a.y * (FixedPoint.one - t); return(new Vector2d(x, y)); }
public override void _UpdatePos() { Vector2d moveDir = GetDir(); FixedPoint delta = new FixedPoint(FSPParam.clientFrameScTime) * GetSpeed(); Vector2d nextPos = m_curPos + moveDir * delta; //Debug.Log("nextPos:" + nextPos); SetPos(nextPos); SetDir(moveDir); if (m_vCreature != null) { m_vCreature.SetMove(true); m_vCreature.SetPos(nextPos.ToVector3() + Vector3.up * m_triggerData.vBulletDeltaPos.y); // 单独设置Y } }
// 矩形检测,获取最近的单位,进行激光链接 public override void Trigger() { FixedPoint minDis = new FixedPoint(999999); CCreature minCC = null; List <long> list = CCreatureMgr.GetCreatureList(); for (int i = 0; i < list.Count; i++) { CCreature creature = CCreatureMgr.Get(list[i]); if (m_caster.bCamp(creature) || creature.IsDie()) { continue; } FPSphere playerS = new FPSphere(); playerS.c = creature.GetPos(); playerS.r = creature.GetR(); Vector2d pos = m_caster.GetPos() + GetDir().normalized *new FixedPoint((m_triggerData.Length + m_triggerData.vBulletDeltaPos.z) * 0.5f); int angle = (int)FPCollide.GetAngle(GetDir()).value; FPObb obb = new FPObb(pos, new Vector2d(m_triggerData.Width, m_triggerData.Length), angle); if (FPCollide.bSphereOBB(playerS, obb)) { FixedPoint dis = Vector2d.Distance(creature.GetPos(), GetPos()); if (dis < minDis) { minDis = dis; minCC = creature; } } } if (minCC != null) { OnHitAddBuff(m_caster, minCC); Vector2d targetPos = GetPos() + GetDir().normalized *minDis; if (m_vCreature != null) { Vector3 tH = minCC.GetVObject().GetHitHeight(); GetVTrigger().SetLineTargetPos(targetPos.ToVector3() + tH); } } else { _CheckObstacle(); } }
public void Normalize() { FixedPoint len = magnitude; if (len == FixedPoint.zero) { return; } if (len == FixedPoint.one) { return; } x = x / len; y = y / len; }
/// <summary> /// 点是否在扇形内部 /// </summary> public static bool bSectorInside(FPSector sector, Vector2d focusPos) { // 右分量 Vector2d rightVec = Rotate(sector.dir, (int)(sector.angle * new FixedPoint(0.5f)).value); // 焦点与扇形的方向 Vector2d focusDir = focusPos - sector.pos; // 扇形方向与右分量点乘值 FixedPoint rightDot = Vector2d.Dot(sector.dir.normalized, rightVec.normalized); // 扇形方向与焦点方向的点乘值 FixedPoint focusDot = Vector2d.Dot(sector.dir.normalized, focusDir.normalized); if (focusDot >= rightDot && Vector2d.Dot(focusDir, focusDir) < sector.r * sector.r) { return(true); } return(false); }
/// <summary> /// 通过BUFF的攻击增减 /// </summary> public FixedPoint GetBuffSpeed(FixedPoint cur) { if (m_buffList == null) { return(FixedPoint.N_0); } FixedPoint newVal = FixedPoint.N_0; for (int i = 0; i < m_buffList.Count; i++) { BuffBase buff = m_buffList[i]; if (buff.GetBuffType() == eBuffType.speed) { FixedPoint pct = buff.GetVal1() * new FixedPoint(0.01f); newVal += cur * pct; } } return(newVal); }
/// <summary> /// 通过BUFF的攻击增减 /// </summary> public int GetBuffAp(int cur) { if (m_buffList == null) { return(0); } int newVal = 0; for (int i = 0; i < m_buffList.Count; i++) { BuffBase buff = m_buffList[i]; if (buff.GetBuffType() == eBuffType.atk) { FixedPoint pct = buff.GetVal1() * new FixedPoint(0.01f); newVal += (int)(cur * pct).value; } } return(newVal); }
/// <summary> /// 获得战力值 生命,攻击,防御,暴击率 暴击伤害倍率 /// </summary> public int GetFightingVal(int hp, int ap, int dp, float CritChance, float CritDamage) { FixedPoint val = FixedPoint.N_0; if (ap <= 0 && dp <= 0) { val = new FixedPoint(hp) + new FixedPoint(ap) * 2 + new FixedPoint(dp); } else { val = new FixedPoint(hp) + new FixedPoint(ap) * 2 + new FixedPoint(dp) + new FixedPoint(ap) * new FixedPoint(ap) / (new FixedPoint(ap) + FixedPoint.N_1 * new FixedPoint(dp)) * (new FixedPoint(CritChance) / 1000) * (new FixedPoint(CritDamage) / 1000); } return((int)val.value); }
public static FixedPoint Sin(int tAngle) { tAngle = ClampAngle(tAngle); // -180 if (tAngle == -180) { return(new FixedPoint(0)); } // -179和-89 else if (tAngle < -90) { tAngle = -tAngle; tAngle = 180 - tAngle; FixedPoint sin = dicSin[tAngle]; sin = -sin; return(sin); } // -90到-1 else if (tAngle < 0) { tAngle = -tAngle; FixedPoint sin = dicSin[tAngle]; sin = -sin; return(sin); } // 0到89 else if (tAngle < 90) { return(dicSin[tAngle]); } // 90到179 else if (tAngle < 180) { tAngle = 180 - tAngle; return(dicSin[tAngle]); } // 180 else { return(new FixedPoint(0)); } }
/// <summary> /// 曲线图 /// </summary> public static FixedPoint Cos(int tAngle) { tAngle = ClampAngle(tAngle); // -180 if (tAngle == -180) { return(new FixedPoint(-1)); } // -179和-89 else if (tAngle < -90) { tAngle = -tAngle; tAngle = 180 - tAngle; FixedPoint cos = dicCos[tAngle]; cos = -cos; return(cos); } // -90到-1 else if (tAngle < 0) { tAngle = -tAngle; return(dicCos[tAngle]); } // 0到89 else if (tAngle < 90) { return(dicCos[tAngle]); } // 90到179 else if (tAngle < 180) { tAngle = 180 - tAngle; FixedPoint cos = dicCos[tAngle]; cos = -cos; return(cos); } // 180 else { return(new FixedPoint(-1)); } }
public override void ExecuteFrame(int frameId) { if (m_bMovePathing) { _UpdateMove(); if (Debug.logger.logEnabled) { for (int i = 0; i < m_movePath.Count - 1; i++) { FixedPoint x1 = m_movePath[i].x; FixedPoint y1 = m_movePath[i].y; FixedPoint x2 = m_movePath[i + 1].x; FixedPoint y2 = m_movePath[i + 1].y; Debug.DrawLine( new Vector3(x1.value, 4, y1.value), new Vector3(x2.value, 4, y2.value), Color.green); } } } }
public static FixedPoint Sqrt(FixedPoint t) { //double v = (double)t.m_value / One; //double d = Math.Sqrt(v); //return new FixedPoint(d); long f1 = t.m_value; if (f1 == 0) { return(new FixedPoint(0)); } n = (f1 >> 1) + 1; n1 = (n + (f1 / n)) >> 1; while (n1 < n) { n = n1; n1 = (n + (f1 / n)) >> 1; } FixedPoint fp; fp.m_value = n << (SHIFT_AMOUNT / 2); return(fp); }
private void _UpdateMove() { //float t = 0.0f; m_curMoveTime += new FixedPoint(FSPParam.clientFrameScTime); int begin = m_curMoveIndex + 1; for (int i = begin; i < m_pathTime.Count; i++) // 索引0,1,2,3,4 取 1-4 作为对比的目标时间 { if (m_curMoveTime > m_pathTime[i]) { m_curMoveIndex = i; break; } } if (m_curMoveIndex >= m_pathTime.Count - 1) { // 最后一个地点 StopAutoMove(); return; } else { FixedPoint delta = new FixedPoint(FSPParam.clientFrameScTime) * m_creature.GetSpeed(); Vector2d nextPos = m_creature.m_curPos + m_dirList[m_curMoveIndex].normalized * delta; m_creature.SetPos(nextPos); m_creature.SetDir(m_dirList[m_curMoveIndex].normalized); if (m_creature.m_vCreature != null) { m_creature.GetVObject().SetMove(true); m_creature.GetVObject().SetBarrier(false); } } }