public void SetMovePoint(MovePoint mp) { SetPosition(mp.start.x, mp.start.y); moveToPoint = mp.end; SetAnimState(AnimationState.WalkForward); }
public Character_Movement_c(Int32 charId, MovePoint movePoint) : base((Int32)PacketType.Character_Movement_c) { this.charId = charId; this.movePoint = movePoint; }
private void JumpIfNeed(MovePoint movePoint) { if (_isInverseDirection == false && movePoint.IsJump || _isInverseDirection && movePoint.IsInverseJump) { _mover.Jump(); } }
void Update(float time) { float fDiff; float fIndex = time * MovePoints.Count; int index = (int)fIndex; fDiff = fIndex - index; if (index >= MovePoints.Count) { index = MovePoints.Count - 1; } MovePoint move_point = new MovePoint(); if (index < MovePoints.Count - 1) { MovePoint move_point1 = MovePoints[index]; MovePoint move_point2 = MovePoints[index + 1]; move_point.Position = Vector2.Lerp(move_point1.Position, move_point2.Position, fDiff); move_point.Angle = Mathf.LerpAngle(move_point1.Angle, move_point2.Angle, fDiff); } else { move_point = MovePoints[index]; } transform.position = move_point.Position; transform.rotation = Quaternion.identity; transform.Rotate(transform.forward, move_point.Angle); }
/// <summary> /// MovePoint内の座標からランダムに座標を取得 /// </summary> /// <param name="iMovePoint">MovePoint</param> /// <returns>ランダムな座標</returns> private Point getRandomPoint(MovePoint iMovePoint) { Point ret = new Point(0, 0); int min = 0; int max = 0; //X if (iMovePoint.Point1.X > iMovePoint.Point2.X) { min = (int)(iMovePoint.Point2.X * 10); max = (int)(iMovePoint.Point1.X * 10); } else { min = (int)(iMovePoint.Point1.X * 10); max = (int)(iMovePoint.Point2.X * 10); } ret.X = rnd.Next(min, max) / 10; //Z if (iMovePoint.Point1.Z > iMovePoint.Point2.Z) { min = (int)(iMovePoint.Point2.Z * 10); max = (int)(iMovePoint.Point1.Z * 10); } else { min = (int)(iMovePoint.Point1.Z * 10); max = (int)(iMovePoint.Point2.Z * 10); } ret.Z = rnd.Next(min, max) / 10; return(ret); }
void Update(float time) { float fDiff; float fIndex = time * MovePoints.Count; int index = (int)fIndex; fDiff = fIndex - index; if (index >= MovePoints.Count) { index = MovePoints.Count - 1; } MovePoint move_point = new MovePoint(); if (index<MovePoints.Count-1) { MovePoint move_point1 = MovePoints[index]; MovePoint move_point2 = MovePoints[index+1]; move_point.Position = Vector2.Lerp(move_point1.Position, move_point2.Position, fDiff); move_point.Angle = Mathf.LerpAngle(move_point1.Angle, move_point2.Angle, fDiff); } else { move_point = MovePoints[index]; } transform.position = move_point.Position; transform.rotation = Quaternion.identity; transform.Rotate(transform.forward, move_point.Angle); }
public void SetMovePointsPath(MovePoint[] points) { currentMovePoint = null; movePoints.Clear(); foreach (MovePoint p in points) { movePoints.Enqueue(p); } }
private void SetCurrentMovePoint(MovePoint mp) { currentMovePoint = mp; position = currentMovePoint.start; this.Inform_CharacterMovePoint(this, currentMovePoint); foreach (GameCharacter c in this.CharsSeenBy) { c.Inform_CharacterMovePoint(this, currentMovePoint); } }
// public void OnDrawGizmos() // { // Gizmos.color = Color; // List<Vector3> points = GetPoints(); // for (int i = 0; i < points.Count - 1; i++) // { // Gizmos.DrawLine(points[i]., points[i + 1]); // Gizmos.DrawSphere(points[i], HandleUtility.GetHandleSize(transform.position) * 0.04f); // } // //// //// #if UNITY_EDITOR //// if (Selection.activeGameObject != gameObject) //// { //// foreach (Transform waypoint in Waypoints) //// { //// Gizmos.DrawSphere(waypoint.transform.position, HandleUtility.GetHandleSize(transform.position) * 0.05f); //// } //// } //// #endif // } public List<MovePoint> GetPoints() { List<MovePoint> ret = new List<MovePoint>(); foreach (var item in Points) { MovePoint pt = new MovePoint(item); pt.Position += new Vector2(transform.position.x, transform.position.y); ret.Add(pt); } return ret; }
public void SetCharacter_MovePoint(int id, MovePoint mp) { if (characters.ContainsKey(id)) { characters[id].SetMovePoint(mp); } else { Debug.LogError("CharacterListController failed to update stats for character. Does not exist: " + id); } }
// public void OnDrawGizmos() // { // Gizmos.color = Color; // List<Vector3> points = GetPoints(); // for (int i = 0; i < points.Count - 1; i++) // { // Gizmos.DrawLine(points[i]., points[i + 1]); // Gizmos.DrawSphere(points[i], HandleUtility.GetHandleSize(transform.position) * 0.04f); // } // //// //// #if UNITY_EDITOR //// if (Selection.activeGameObject != gameObject) //// { //// foreach (Transform waypoint in Waypoints) //// { //// Gizmos.DrawSphere(waypoint.transform.position, HandleUtility.GetHandleSize(transform.position) * 0.05f); //// } //// } //// #endif // } public List <MovePoint> GetPoints() { List <MovePoint> ret = new List <MovePoint>(); foreach (var item in Points) { MovePoint pt = new MovePoint(item); pt.Position += new Vector2(transform.position.x, transform.position.y); ret.Add(pt); } return(ret); }
void CalcMoveEvalution(MovePoint mp) { // 行動の対象がいるかどうかと、その価値 var action_e = 5; { int num, effective_point_avg, effective_point_max; if (IsExistActionTarget(mp.map_x, mp.map_y, out num, out effective_point_avg, out effective_point_max, null)) { action_e = 0; } } mp.evaluation -= action_e; }
//Private private void HandleMovement(float frameDiff) { float unitsToMove = stats.MoveSpeed * frameDiff; while (!float.IsNaN(unitsToMove)) { this.position = CalculateMove(position, currentMovePoint.end, ref unitsToMove); if (!float.IsNaN(unitsToMove)) { if (movePoints.Count != 0) { SetCurrentMovePoint(movePoints.Dequeue()); } else { unitsToMove = float.NaN; currentMovePoint = null; } } } }
protected internal SpriteMovePointFinishedEventArgs(Sprite _sprite, Movement _movement, MovePoint _movePoint) { sprite = _sprite; movement = _movement; movePoint = _movePoint; }
public override void Inform_CharacterMovePoint(GameCharacter charFrom, MovePoint mp) { this.SendPacket(new ClientToInstancePackets.Character_Movement_c(charFrom.Id, mp)); }
public MovePointSerializable(MovePoint point) { x = point.Position.x; y = point.Position.y; Angle = point.Angle; }
public abstract void Inform_CharacterMovePoint(GameCharacter charFrom, MovePoint mp);
// Lot of starting shit happends here void findStartEndPoint() { int offNum; switch(spawnPoint) { case MovePoint.leftBottom: offNum = Random.Range(0, 3); switch(offNum) { case 0: offPoint = MovePoint.rightBottom; willRear = (((int)Mathf.Round((Random.value))) == 1) ? true : false; break; case 1: offPoint = MovePoint.rightSide; willRear = true; break; case 2: offPoint = MovePoint.rightBack; willRear = true; break; default: offPoint = MovePoint.rightSide; willRear = true; break; } quitPoint = MovePoint.rightBottom; startLocation = getMovePointPos(spawnPoint); offLocation = getMovePointPos(offPoint); break; case MovePoint.rightBottom: offNum = Random.Range(0, 3); switch(offNum) { case 0: offPoint = MovePoint.leftBottom; willRear = (((int)Mathf.Round((Random.value))) == 1) ? true : false; break; case 1: offPoint = MovePoint.leftSide; willRear = true; break; case 2: offPoint = MovePoint.leftBack; willRear = true; break; default: offPoint = MovePoint.leftSide; willRear = true; break; } quitPoint = MovePoint.leftBottom; startLocation = getMovePointPos(spawnPoint); offLocation = getMovePointPos(offPoint); break; case MovePoint.leftSide: offPoint = MovePoint.rightBottom; quitPoint = MovePoint.rightBottom; startLocation = getMovePointPos(spawnPoint); offLocation = getMovePointPos(offPoint); willRear = true; break; case MovePoint.rightSide: offPoint = MovePoint.leftBottom; quitPoint = MovePoint.leftBottom; startLocation = getMovePointPos(spawnPoint); offLocation = getMovePointPos(offPoint); willRear = true; break; default: break; } }
public MovePoint(MovePoint point) { Position = point.Position; Angle = point.Angle; }
Vector3 getMovePointPos(MovePoint point) { Vector3 posVector = new Vector3(0, 0, 0); float xPos = 0; float zPos = 0; switch(point) { case MovePoint.leftBottom: xPos = Random.Range(enterPointX[0].min, enterPointX[0].max); zPos = Random.Range(enterPointZ[0].min, enterPointZ[0].max); posVector = new Vector3(xPos, 0, zPos); break; case MovePoint.rightBottom: xPos = Random.Range(enterPointX[1].min, enterPointX[1].max); zPos = Random.Range(enterPointZ[0].min, enterPointZ[0].max); posVector = new Vector3(xPos, 0, zPos); break; case MovePoint.leftSide: xPos = Random.Range(enterPointX[0].min, enterPointX[0].max); zPos = Random.Range(enterPointZ[1].min, enterPointZ[1].max); posVector = new Vector3(xPos, 0, zPos); break; case MovePoint.rightSide: xPos = Random.Range(enterPointX[1].min, enterPointX[1].max); zPos = Random.Range(enterPointZ[1].min, enterPointZ[1].max); posVector = new Vector3(xPos, 0, zPos); break; case MovePoint.leftBack: xPos = Random.Range(enterPointX[2].min, enterPointX[2].max); zPos = Random.Range(enterPointZ[2].min, enterPointZ[2].max); posVector = new Vector3(xPos, 0, zPos); break; case MovePoint.rightBack: xPos = Random.Range(enterPointX[3].min, enterPointX[3].max); zPos = Random.Range(enterPointZ[2].min, enterPointZ[2].max); posVector = new Vector3(xPos, 0, zPos); break; default: break; } return posVector; }
protected override Composite CreateBehavior() { return(_root ?? (_root = new PrioritySelector( // first state catches if we are done just in case new Decorator(ret => _isBehaviorDone, new Action(delegate { return RunStatus.Success; })), // if we hit the load screen and we are back in game new Decorator(ret => _isInPortal && ObjectManager.IsInGame && StyxWoW.Me != null, new Action(delegate { _isBehaviorDone = true; UtilLogMessage("info", "Went thru portal."); Thread.Sleep(500); WoWMovement.MoveStop(); Thread.Sleep(500); return RunStatus.Success; })), // if zone name changed new Decorator(ret => ZoneText != StyxWoW.Me.ZoneText, new Action(ret => _isInPortal = true)), // if load screen is visible new Decorator(ret => !ObjectManager.IsInGame || StyxWoW.Me == null, new Action(ret => _isInPortal = true)), // if we are within 2 yards of calculated end point we should never reach new Decorator(ret => MovePoint.Distance(Me.Location) < 2, new Action(delegate { _isBehaviorDone = true; WoWMovement.MoveStop(); UtilLogMessage("fatal", "Unable to reach end point. Failed to go through portal."); return RunStatus.Success; })), new Decorator(ret => Timeout != 0 && Timeout < System.Environment.TickCount, new Action(delegate { _isBehaviorDone = true; WoWMovement.MoveStop(); UtilLogMessage("fatal", "Timed out after {0} ms. Failed to go through portal", Timeout); return RunStatus.Success; })), new Decorator(ret => !StyxWoW.Me.IsMoving, new Action(delegate { UtilLogMessage("info", "Moving to {0}", MovePoint); WoWMovement.ClickToMove(MovePoint); return RunStatus.Success; })) ) )); }
public override void Inform_CharacterMovePoint(GameCharacter charFrom, MovePoint mp) { //Log.Log(this.GetHashCode() + ": Move- " + charFrom.GetHashCode() + "- " + mp.start.ToString() + "->" + mp.end.ToString()); }
int FindPath(int count, Vector3 start, Vector3 previous, List <MovePoint> result) { //超過步數限制 終止 if (count > maxSteps) { Debug.Log("STEP OUT"); return(-1); } //在一步範圍內 =>到達 else if (Vector3.Distance(start, goal.position) < stepWidth) { MovePoint final = new MovePoint(); final.point = goal.position; result.Add(final); Debug.Log("到達!"); return(0); } //判斷下個點 else { Vector3 dir = goal.position - start; RaycastHit hit; if (Physics.Raycast(start, dir.normalized, out hit, stepWidth)) { //遇到障礙物 檢查是否可以跳過 Vector3 _next = new Vector3(); if (CheckCanJump(hit.point, start, out _next)) { Debug.Log("可跳過 " + hit.transform.name); if (FindPath(count + 1, _next, start, result) != -1) { result.Add(new MovePoint(start)); return(count); } else { return(-1); } } //不可跳躍障礙 => 分裂路線 else if (hit.normal != previous_split_normal) { Debug.Log("不可跳過 " + hit.transform.name + " " + count); //Split previous_split_normal = hit.normal; var s = Split(previous, start, hit); List <MovePoint> res1 = new List <MovePoint>(); List <MovePoint> res2 = new List <MovePoint>(); //res1.Add(new MovePoint(start)); //res2.Add(new MovePoint(start)); if (s.Count == 2) { Debug.DrawLine(start, s[0], Color.magenta, 15); Debug.DrawLine(start, s[1], Color.magenta, 15); int r1 = FindPath(count + 1, s[0], start, res1); Debug.Log("split 1 result: " + r1); //若不取最短路線,則找到第一條可行的就好 if (!shortest && r1 != -1) { result.AddRange(res1); return(count); } else { int r2 = FindPath(count + 1, s[1], start, res2); Debug.Log("split 2 result: " + r2); //Debug.Log(res1.Count + " vs " + res2.Count); //兩條路都可走則取最短 if (r1 != -1 && r2 != -1) { if (res1.Count > res2.Count) { result.AddRange(res2); } else { result.AddRange(res1); } } //走r2 else if (r1 == -1 && r2 != -1) { result.AddRange(res2); } //走r1 else if (r2 == -1 && r1 != -1) { result.AddRange(res1); } //兩條都不通 else if (r2 == -1 && r1 == -1) { return(-1); } } result.Add(new MovePoint(start)); return(count); } //只有一條路 else if (s.Count == 1) { if (FindPath(count + 1, s[0], previous, res1) != -1) { result.AddRange(res1); result.Add(new MovePoint(start)); return(count); } } //找不到路 else { Debug.Log("split to 0 => return -1 " + count); return(-1); } } else { //照上一次移動方向移動 Vector3 _move = (start - previous).normalized * stepWidth + start; if (FindPath(count + 1, _move, start, result) != -1) { result.Add(new MovePoint(start)); return(count); } } } //無障礙物 else { previous_split_normal = Vector3.zero; //檢查下個點是否浮空 Vector3 _next = new Vector3(); Vector3 nextStop = start + dir.normalized * stepWidth; //跳躍 if (CheckCanJump(Vector3.zero, start, out _next)) { if (FindPath(count + 1, _next, start, result) != -1) { result.Add(new MovePoint(start)); return(count); } else { return(-1); } } //可直行 else if (FindPath(count + 1, nextStop, start, result) != -1) { //Debug.Log("直行"); result.Add(new MovePoint(start)); return(count); } else { return(-1); } } } return(-1); }
public void Run() { var game_main = GameMain.GetInstance(); var g3d_map = game_main.g3d_map; // まず移動させよう // 移動範囲を表示、算出して move_area.Check(select_unit.map_x, select_unit.map_y, select_unit.bt.status["MOVE"].now, select_unit.bt.status["JUMP"].now); // 移動できる場所をリストアップ var move_point_list = new List <MovePoint>(); for (var mx = 0; mx < move_area.map_w; mx++) { for (var my = 0; my < move_area.map_h; my++) { if (move_area.IsInside(mx, my)) { var mp = new MovePoint(); mp.map_x = mx; mp.map_y = my; mp.evaluation = 0; //とりあえず初期値 move_point_list.Add(mp); } } } { // 移動しない場合 var mp = new MovePoint(); mp.map_x = select_unit.map_x; mp.map_y = select_unit.map_y; move_point_list.Add(mp); } // 移動できる場所を判定 MovePoint max_mp = null; var max_evalution = 0.0; foreach (var mp in move_point_list) { var evalution = 0.0; CalcMoveEvalution(mp); evalution = mp.evaluation * 3; var rs = CalcRangeStatus(mp.map_x, mp.map_y, false); evalution += (-rs.evaluation_min) / 5 + (-rs.evaluation_avg) / 10; //Console.WriteLine("{0},{1} ({2}) {3} {4}", mp.map_x,mp.map_y, mp.evaluation, rs.evaluation_min, rs.evaluation_avg); if (max_mp == null || max_evalution < evalution) { max_evalution = evalution; max_mp = mp; } } Thread.Sleep(100); // 移動を実行 if (max_mp.map_x != select_unit.map_x || max_mp.map_y != select_unit.map_y) { var t = new STask((param) => { select_unit.Move(max_mp.map_x, max_mp.map_y, true); GameMain.GetInstance().g3d_map.ClearRangeAreaEffect(); }, null); STaskManager.Add(t); t.WaitEnd(); } Console.WriteLine("pos " + select_unit.map_x + "," + select_unit.map_y); Thread.Sleep(100); // 行動を決める { var action_datas = new ActionDatas(); int num, effective_point_avg, effective_point_max; if (IsExistActionTarget(max_mp.map_x, max_mp.map_y, out num, out effective_point_avg, out effective_point_max, action_datas)) { Console.WriteLine("----A"); Console.WriteLine("pos " + select_unit.map_x + "," + select_unit.map_y); var t = new STask((param) => { var a = action_datas.actions[0]; var ad = ActionDataManager.GetActionData(a.command); var target_unit = game_main.unit_manager.GetUnit(a.target_map_x, a.target_map_y); if (target_unit != null) { game_main.user_interface.SetStatusUnit(target_unit); } Console.WriteLine("DoAction {0} {1} {2} {3}", a.command, ad.range_type, select_unit.name, a.target.name); scene_battle.DoAction(a.command, ad.range_type, select_unit, a.target_map_x, a.target_map_y, false); }, null); Console.WriteLine("----B"); Console.WriteLine("pos " + select_unit.map_x + "," + select_unit.map_y); STaskManager.Add(t); Console.WriteLine("----C"); Console.WriteLine("pos " + select_unit.map_x + "," + select_unit.map_y); t.WaitEnd(); } } Thread.Sleep(100); g3d_map.ClearRangeAreaEffect(); //Thread.Sleep(1000); //scene_battle.NextUnitTurn(); is_thread_end = true; Console.WriteLine("BattleAI Run End"); }
public void Move(int dx, int dy) { this.Point = MovePoint.Move(this.Point, dx, dy); }
// Public method to start the deer when not debug public void setPreInits(Transform newFlowerLink, MovePoint newSpawnPoint) { flowerLink = newFlowerLink; spawnPoint = newSpawnPoint; preInitedCheck(); }