public int moveTo(int x, int y, byte cb, bool fly, GameUnitCampType camp, bool start, bool follow, int speed, OnEventOver over) { if (x == posX && y == posY) { return(GameDefine.INVALID_ID); } if (startMoving) { return(GameDefine.INVALID_ID); } moveBuffer.Clear(); int count = GameBattlePathFinder.instance.findPath(posX, posY, x, y, cb, fly, camp); if (count == 0) { return(GameDefine.INVALID_ID); } for (int i = count - 3; i >= 0; i--) { moveBuffer.Add(GameBattlePathFinder.instance.pathResult[i]); } int cost = 0; for (int i = 0; i < moveBuffer.Count / 2; i++) { int xx = moveBuffer[i * 2 + 1]; int yy = moveBuffer[i * 2]; cost += GameBattleUnitMovement.instance.getCellCost(xx, yy); } moveSpeed = GameDefine.getMoveSpeed(speed); sceneFollow = follow; playStartAnimation = start; onEventOver = over; canFollow = GameCameraManager.instance.canFollow(posBattleX, posBattleY, GameBattleManager.instance.LayerHeight); moveNext(); startAnimation(); startMoving = true; return(cost); }
public void addCell(int x, int y, GameUnitCampType camp) { GameObject obj = Instantiate(Resources.Load <GameObject>("Prefab/Cell"), transform); obj.name = x + "-" + y; Transform trans = obj.transform; trans.localPosition = new Vector3(GameDefine.getBattleX(x), GameDefine.getBattleY(y) + GameBattleManager.instance.LayerHeight, 0.0f); SpriteRenderer sprite = obj.GetComponent <SpriteRenderer>(); Color c = camp == GameUnitCampType.User ? new Color(1.0f, 0.0f, 1.0f, 0.5f) : new Color(1.0f, 0.0f, 0.0f, 0.5f); sprite.color = c; }
bool isClose1(List <Cell> list, int x, int y, GameUnitCampType type, bool fly) { GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(x, y); if (!fly && unit != null) { if (unit.IsAlive && unit.UnitCampType != type) { return(true); } } for (int i = 0; i < list.Count; i++) { if (list[i].x == x && list[i].y == y) { return(true); } } return(false); }
public void show(int x, int y, int move, GameUnitMoveType moveType, bool fly, GameUnitCampType camp, bool fade) { gameObject.SetActive(true); clear(); isShow = true; openList.Clear(); closeList.Clear(); Cell cell = new Cell(); cell.x = x; cell.y = y; cell.f = 0; openList.Add(cell); findCell(move, moveType, fly, camp); fadeCell(fade); }
public void show(int x, int y, GameItem item, GameUnitCampType camp, bool fade) { gameObject.SetActive(true); clear(); list.Clear(); int width = GameBattleManager.instance.Width; int height = GameBattleManager.instance.Height; int min = 1; int max = 1; GameAttackRangeType type = GameAttackRangeType.Circle; if (item != null) { min = (item.AttackRangeMin == GameDefine.INVALID_ID ? 1 : item.AttackRangeMin + 1); max = item.AttackRangeMax; type = item.AttackRangeType; } if (type == GameAttackRangeType.Line) { for (int i = min; i <= max; i++) { Cell cell = new Cell(); cell.x = x + i; cell.y = y; list.Add(cell); cell = new Cell(); cell.x = x - i; cell.y = y; list.Add(cell); cell = new Cell(); cell.x = x; cell.y = y - i; list.Add(cell); cell = new Cell(); cell.x = x; cell.y = y + i; list.Add(cell); } } else { for (int i = -max; i <= max; i++) { for (int j = -max; j <= max; j++) { int xx = Mathf.Abs(j); int yy = Mathf.Abs(i); if (xx + yy <= max && xx + yy >= min) { Cell cell = new Cell(); cell.x = x + j; cell.y = y + i; list.Add(cell); } } } } for (int i = 0; i < list.Count;) { if (list[i].x < 0 || list[i].y < 0 || list[i].x >= width || list[i].y >= height) { list.RemoveAt(i); } else { i++; } } int dis = 99; attackCell.x = x; attackCell.y = y; for (int i = 0; i < list.Count; i++) { addCell(list[i].x, list[i].y, camp); int d = Mathf.Abs(x - list[i].x) + Mathf.Abs(y - list[i].y); if (dis > d) { GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(list[i].x, list[i].y); if (unit != null && unit.UnitCampType != camp) { dis = d; attackCell.x = list[i].x; attackCell.y = list[i].y; } } } fadeCell(fade); isShow = true; GameBattleCursor.instance.show(0); }
public GameBattleUnit canAttack(int x, int y, GameItem item, GameUnitCampType camp) { list.Clear(); int width = GameBattleManager.instance.Width; int height = GameBattleManager.instance.Height; int min = 1; int max = 1; GameAttackRangeType type = GameAttackRangeType.Circle; if (item != null) { min = (item.AttackRangeMin == GameDefine.INVALID_ID ? 1 : item.AttackRangeMin + 1); max = item.AttackRangeMax; type = item.AttackRangeType; } if (type == GameAttackRangeType.Line) { for (int i = min; i <= max; i++) { Cell cell = new Cell(); cell.x = x + i; cell.y = y; list.Add(cell); cell = new Cell(); cell.x = x - i; cell.y = y; list.Add(cell); cell = new Cell(); cell.x = x; cell.y = y - i; list.Add(cell); cell = new Cell(); cell.x = x; cell.y = y + i; list.Add(cell); } } else { for (int i = -max; i <= max; i++) { for (int j = -max; j <= max; j++) { int xx = Mathf.Abs(j); int yy = Mathf.Abs(i); if (xx + yy <= max && xx + yy >= min) { Cell cell = new Cell(); cell.x = x + j; cell.y = y + i; list.Add(cell); } } } } for (int i = 0; i < list.Count; i++) { if (list[i].x < 0 || list[i].y < 0 || list[i].x >= width || list[i].y >= height) { continue; } GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(list[i].x, list[i].y); if (unit != null && unit.UnitCampType != camp) { return(unit); } } return(null); }
int getCost(int x, int y, GameUnitMove unitMove, GameUnitCampType camp, out bool bd) { // byte baseCost = 0; // byte block = 0; // bool addMove = false; // sbyte subMove = 0; // // switch ( moveType ) // { // case GameUnitMoveType.Walk0: // baseCost = 5; // block = 7; // addMove = true; // subMove = 0; // break; // case GameUnitMoveType.Walk1: // baseCost = 6; // block = 7; // addMove = true; // subMove = 0; // break; // case GameUnitMoveType.Walk2: // baseCost = 5; // block = 7; // addMove = true; // subMove = 0; // break; // case GameUnitMoveType.Walk3: // baseCost = 6; // block = 7; // addMove = true; // subMove = 1; // break; // case GameUnitMoveType.Fly4: // baseCost = 6; // block = 7; // addMove = false; // subMove = 0; // break; // case GameUnitMoveType.Fly5: // baseCost = 7; // block = 9; // addMove = false; // subMove = 0; // break; // case GameUnitMoveType.Fly6: // baseCost = 5; // block = 9; // addMove = false; // subMove = 0; // break; // case GameUnitMoveType.Walk7: // baseCost = 6; // block = 7; // addMove = true; // subMove = -1; // break; // case GameUnitMoveType.Fly8: // baseCost = 6; // block = 7; // addMove = true; // subMove = -2; // break; // case GameUnitMoveType.Fly9: // baseCost = 6; // block = 7; // addMove = true; // subMove = -2; // break; // case GameUnitMoveType.Walk10: // baseCost = 6; // block = 7; // addMove = true; // subMove = -2; // break; // case GameUnitMoveType.None: // baseCost = 100; // block = 7; // addMove = true; // subMove = 0; // break; // } bd = false; int cost = unitMove.baseCost; GameBattleDTL dtl = GameBattleManager.instance.ActiveDTL; int index1 = dtl.Width * y + x; GameBattleDTL.Point point = dtl.Points[index1]; int subMove = point.Move + unitMove.subMove; if (subMove < 0) { subMove = 0; } if (unitMove.addMove) { cost = unitMove.baseCost + subMove; } // right int index = dtl.Width * y + x + 1; if (index >= 0 && index < dtl.Points.Length) { GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(x + 1, y); if (unit != null) { if (unitMove.addMove && unit.IsAlive && unit.UnitCampType != camp) { bd = true; } } } // left index = dtl.Width * y + x - 1; if (index >= 0 && index < dtl.Points.Length) { GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(x - 1, y); if (unit != null) { if (unitMove.addMove && unit.IsAlive && unit.UnitCampType != camp) { bd = true; } } } // top index = dtl.Width * (y - 1) + x; if (index >= 0 && index < dtl.Points.Length) { GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(x, y - 1); if (unit != null) { if (unitMove.addMove && unit.IsAlive && unit.UnitCampType != camp) { bd = true; } } } // bottom index = dtl.Width * (y + 1) + x; if (index >= 0 && index < dtl.Points.Length) { GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(x, y + 1); if (unit != null) { if (unitMove.addMove && unit.IsAlive && unit.UnitCampType != camp) { bd = true; } } } return(cost); }
void findCell(int move, GameUnitMoveType moveType, bool fly, GameUnitCampType camp) { GameUnitMove unitMove = GameUnitMoveTypeData.instance.getData(moveType); bool user = (camp == GameUnitCampType.User); GameBattleDTL dtl = GameBattleManager.instance.ActiveDTL; closeList.Add(openList[0]); while (openList.Count > 0) { List <Cell> newOpenList = new List <Cell>(); for (int i = 0; i < openList.Count; i++) { Cell cell = openList[i]; GameBattleDTL.Point point = null; // right int index = dtl.Width * cell.y + cell.x + 1; if (index >= 0 && index < dtl.Points.Length && !isClose(cell.x + 1, cell.y, camp, fly)) { point = dtl.Points[index]; bool bd = false; int cost = getCost(cell.x + 1, cell.y, unitMove, camp, out bd); if (point.Move < unitMove.block && cell.f + cost <= move) { Cell newCell = new Cell(); newCell.x = cell.x + 1; newCell.y = cell.y; newCell.f = cell.f + (bd ? cost * 2 : cost); newCell.c = cost; newCell.ca = cell.f + cost; newOpenList.Add(newCell); closeList.Add(newCell); } } // left index = dtl.Width * cell.y + cell.x - 1; if (index >= 0 && index < dtl.Points.Length && !isClose(cell.x - 1, cell.y, camp, fly)) { point = dtl.Points[index]; bool bd = false; int cost = getCost(cell.x - 1, cell.y, unitMove, camp, out bd); if (point.Move < unitMove.block && cell.f + cost <= move) { Cell newCell = new Cell(); newCell.x = cell.x - 1; newCell.y = cell.y; newCell.f = cell.f + (bd ? cost * 2 : cost); newCell.c = cost; newCell.ca = cell.f + cost; newOpenList.Add(newCell); closeList.Add(newCell); } } // top index = dtl.Width * (cell.y - 1) + cell.x; if (index >= 0 && index < dtl.Points.Length && !isClose(cell.x, cell.y - 1, camp, fly)) { point = dtl.Points[index]; bool bd = false; int cost = getCost(cell.x, cell.y - 1, unitMove, camp, out bd); if (point.Move < unitMove.block && cell.f + cost <= move) { Cell newCell = new Cell(); newCell.x = cell.x; newCell.y = cell.y - 1; newCell.f = cell.f + (bd ? cost * 2 : cost); newCell.c = cost; newCell.ca = cell.f + cost; newOpenList.Add(newCell); closeList.Add(newCell); } } // bottom index = dtl.Width * (cell.y + 1) + cell.x; if (index >= 0 && index < dtl.Points.Length && !isClose(cell.x, cell.y + 1, camp, fly)) { point = dtl.Points[index]; bool bd = false; int cost = getCost(cell.x, cell.y + 1, unitMove, camp, out bd); if (point.Move < unitMove.block && cell.f + cost <= move) { Cell newCell = new Cell(); newCell.x = cell.x; newCell.y = cell.y + 1; newCell.f = cell.f + (bd ? cost * 2 : cost); newCell.c = cost; newCell.ca = cell.f + cost; newOpenList.Add(newCell); closeList.Add(newCell); } } } openList.Clear(); openList = null; openList = newOpenList; } for (int i = 1; i < closeList.Count;) { if (isUnit(closeList[i].x, closeList[i].y)) { closeList.RemoveAt(i); } else { i++; } } for (int i = 0; i < closeList.Count; i++) { addCell(closeList[i], user); } }
public bool checkSkillAI(GameBattleUnit unit1, GameBattleUnit unit, GameSkill sk, GameUnitCampType camp) { switch (sk.TargetType) { case GameTargetType.User: { if (unit == null || unit.UnitCampType != camp) { return(false); } switch (sk.ResultType) { case GameSkillResutlType.Damage: break; case GameSkillResutlType.Cure: { if (unit.HPMax - unit.HP > sk.BasePower || (unit.HP / (float)unit.HPMax) < 0.4f) { return(true); } return(false); } case GameSkillResutlType.Purge: { if (unit.checkEffect(GameSkillResutlEffect.Poison) || unit.checkEffect(GameSkillResutlEffect.Palsy) || unit.checkEffect(GameSkillResutlEffect.Silence) || unit.checkEffect(GameSkillResutlEffect.Fetter)) { return(true); } return(false); } case GameSkillResutlType.Blessing: { if (unit.checkEffect(sk.ResultEffect)) { return(false); } checkUnitAI = true; return(true); } case GameSkillResutlType.Curse: break; case GameSkillResutlType.None: case GameSkillResutlType.Special: { switch (sk.OtherEffect) { case GameSkillOtherEffect.Invincible0: { if (unit.checkEffect(GameSkillResutlEffect.PhyImmunity)) { return(false); } checkUnitAI = true; return(true); } case GameSkillOtherEffect.Invincible1: { if (unit.checkEffect(GameSkillResutlEffect.MagImmunity)) { return(false); } checkUnitAI = true; return(true); } case GameSkillOtherEffect.HealAll: { if (unit.HPMax - unit.HP > sk.BasePower || (unit.HP / (float)unit.HPMax) < 0.4f) { return(true); } return(false); } case GameSkillOtherEffect.MPAdd: { if (unit.MPMax - unit.MP > sk.BasePower || (unit.MP / (float)unit.MPMax) < 0.4f) { return(true); } return(false); } case GameSkillOtherEffect.AbilityUp: { if (unit.checkEffectOther(GameSkillOtherEffect.AbilityUp)) { return(false); } checkUnitAI = true; return(true); } } switch (sk.ResultEffect) { case GameSkillResutlEffect.Clear: break; case GameSkillResutlEffect.PhyImmunity: case GameSkillResutlEffect.MagImmunity: case GameSkillResutlEffect.Miss: case GameSkillResutlEffect.SummonKiller: case GameSkillResutlEffect.Under: { if (unit.checkEffect(sk.ResultEffect)) { return(false); } checkUnitAI = true; return(true); } } } break; } } break; case GameTargetType.Enemy: { if (unit == null || unit.UnitCampType == camp) { return(false); } if (sk.Type == GameSkillType.Physical) { return(true); } switch (sk.ResultType) { case GameSkillResutlType.Damage: { return(true); } case GameSkillResutlType.Cure: break; case GameSkillResutlType.Purge: break; case GameSkillResutlType.Blessing: break; case GameSkillResutlType.Curse: { if (unit.checkEffect(sk.ResultEffect)) { return(false); } return(true); } case GameSkillResutlType.None: case GameSkillResutlType.Special: { switch (sk.OtherEffect) { case GameSkillOtherEffect.AttackX2: case GameSkillOtherEffect.AttackX3: case GameSkillOtherEffect.AttackX4: case GameSkillOtherEffect.AttackPalsy: case GameSkillOtherEffect.AttackPoison: case GameSkillOtherEffect.AttackHP: case GameSkillOtherEffect.AttackFetter: case GameSkillOtherEffect.MP: { return(true); } case GameSkillOtherEffect.KillSelf: { return(((float)unit1.HP / unit1.HPMax) <= 0.5f); } case GameSkillOtherEffect.AttackSilence: { if (unit.checkEffect(GameSkillResutlEffect.Silence)) { return(false); } return(true); } case GameSkillOtherEffect.AbilityDown: { if (unit.checkEffect(GameSkillResutlEffect.StrUp) || unit.checkEffect(GameSkillResutlEffect.VitUp) || unit.checkEffect(GameSkillResutlEffect.IntUp) || unit.checkEffect(GameSkillResutlEffect.MoveUp) || unit.checkEffect(GameSkillResutlEffect.Violent)) { return(true); } return(false); } case GameSkillOtherEffect.HealAll: case GameSkillOtherEffect.AbilityUp: case GameSkillOtherEffect.Invincible0: case GameSkillOtherEffect.Invincible1: break; } switch (sk.ResultEffect) { case GameSkillResutlEffect.Clear: { if (unit.checkEffect(GameSkillResutlEffect.StrUp) || unit.checkEffect(GameSkillResutlEffect.VitUp) || unit.checkEffect(GameSkillResutlEffect.IntUp) || unit.checkEffect(GameSkillResutlEffect.MoveUp) || unit.checkEffect(GameSkillResutlEffect.Violent)) { return(true); } return(false); } case GameSkillResutlEffect.PhyImmunity: case GameSkillResutlEffect.MagImmunity: case GameSkillResutlEffect.Miss: case GameSkillResutlEffect.SummonKiller: case GameSkillResutlEffect.Under: { } break; } } break; } } break; case GameTargetType.Summon: { if (unit != null) { return(false); } return(true); } } return(false); }
public void showUse(int x, int y, GameItem item, GameUnitCampType camp, bool fade) { gameObject.SetActive(true); clear(); list.Clear(); int width = GameBattleManager.instance.Width; int height = GameBattleManager.instance.Height; int min = (item.UseRangeMin == GameDefine.INVALID_ID ? 1 : item.UseRangeMin + 1); int max = item.UseRangeMax; if (min > max) { min = max; } rangeType = item.UseRangeType; posX = x; posY = y; switch (rangeType) { case GameAttackRangeType.Circle: { for (int i = -max; i <= max; i++) { for (int j = -max; j <= max; j++) { int xx = Mathf.Abs(j); int yy = Mathf.Abs(i); if (xx + yy <= max && xx + yy >= min) { Cell cell = new Cell(); cell.x = x + j; cell.y = y + i; list.Add(cell); } } } if (item.UseRangeMin == 0) { Cell cell = new Cell(); cell.x = x; cell.y = y; list.Add(cell); } } break; case GameAttackRangeType.Line: { for (int i = min; i <= max; i++) { Cell cell = new Cell(); cell.x = x + i; cell.y = y; list.Add(cell); cell = new Cell(); cell.x = x - i; cell.y = y; list.Add(cell); cell = new Cell(); cell.x = x; cell.y = y - i; list.Add(cell); cell = new Cell(); cell.x = x; cell.y = y + i; list.Add(cell); } } break; } bool b = false; int dis = 99; attackCell.x = x; attackCell.y = y; int size = item.UseRange; for (int i = 0; i < list.Count;) { if (list[i].x < 0 || list[i].y < 0 || list[i].x >= width || list[i].y >= height) { list.RemoveAt(i); continue; } if (item.UseTargetType == GameTargetType.Summon && GameBattlePathFinder.instance.isBlockPos(list[i].x, list[i].y, GameBattlePathFinder.BLOCK_EVENT)) { list.RemoveAt(i); continue; } i++; } for (int i = 0; i < list.Count; i++) { addCell(list[i].x, list[i].y, camp); int d = Mathf.Abs(x - list[i].x) + Mathf.Abs(y - list[i].y); if (dis > d) { GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(list[i].x, list[i].y); if (unit != null) { switch (item.UseTargetType) { case GameTargetType.User: { if (unit.UnitCampType == camp) { dis = d; b = true; attackCell.x = list[i].x; attackCell.y = list[i].y; } } break; case GameTargetType.Enemy: { if (unit.UnitCampType != camp) { dis = d; b = true; attackCell.x = list[i].x; attackCell.y = list[i].y; } } break; } } else { switch (item.UseTargetType) { case GameTargetType.Summon: { dis = d; b = true; attackCell.x = list[i].x; attackCell.y = list[i].y; } break; } } } } if (!b) { for (int i = 0; i < list.Count; i++) { if (list[i].x < 0 || list[i].y < 0 || list[i].x >= width || list[i].y >= height) { continue; } int d = Mathf.Abs(x - list[i].x) + Mathf.Abs(y - list[i].y); if (dis > d) { for (int i0 = -size; i0 <= size; i0++) { for (int j0 = -size; j0 <= size; j0++) { int xx = Mathf.Abs(j0); int yy = Mathf.Abs(i0); if (xx + yy <= size) { GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(list[i].x + j0, list[i].y + i0); if (unit != null) { switch (item.UseTargetType) { case GameTargetType.User: { if (unit.UnitCampType == camp) { dis = d; attackCell.x = list[i].x; attackCell.y = list[i].y; } } break; case GameTargetType.Enemy: { if (unit.UnitCampType != camp) { dis = d; attackCell.x = list[i].x; attackCell.y = list[i].y; } } break; } } else { switch (item.UseTargetType) { case GameTargetType.Summon: { dis = d; attackCell.x = list[i].x; attackCell.y = list[i].y; } break; } } } } } } } } fadeCell(fade); isShow = true; GameBattleCursor.instance.show(item.UseRange); }
public void showGive(int x, int y, int rmin, int rmax, GameAttackRangeType type, int range, GameUnitCampType camp, bool fade) { gameObject.SetActive(true); clear(); list.Clear(); int width = GameBattleManager.instance.Width; int height = GameBattleManager.instance.Height; int min = (rmin == GameDefine.INVALID_ID ? 1 : rmin + 1); int max = rmax; if (min > max) { min = max; } rangeType = type; posX = x; posY = y; switch (rangeType) { case GameAttackRangeType.Circle: { for (int i = -max; i <= max; i++) { for (int j = -max; j <= max; j++) { int xx = Mathf.Abs(j); int yy = Mathf.Abs(i); if (xx + yy <= max && xx + yy >= min) { Cell cell = new Cell(); cell.x = x + j; cell.y = y + i; list.Add(cell); } } } if (rmin == 0) { Cell cell = new Cell(); cell.x = x; cell.y = y; list.Add(cell); } } break; case GameAttackRangeType.Line: { for (int i = min; i <= max; i++) { Cell cell = new Cell(); cell.x = x + i; cell.y = y; list.Add(cell); cell = new Cell(); cell.x = x - i; cell.y = y; list.Add(cell); cell = new Cell(); cell.x = x; cell.y = y - i; list.Add(cell); cell = new Cell(); cell.x = x; cell.y = y + i; list.Add(cell); } } break; } for (int i = 0; i < list.Count;) { if (list[i].x < 0 || list[i].y < 0 || list[i].x >= width || list[i].y >= height) { list.RemoveAt(i); } else { addCell(list[i].x, list[i].y, camp); i++; } } fadeCell(fade); isShow = true; GameBattleCursor.instance.show(range); }
public void getUnitsCircle(int ux, int uy, int x, int y, GameItem m, GameUnitCampType camp) { attackDirection = GameBattleAttackMapDirection.Count; List <GameBattleUnit> list = new List <GameBattleUnit>(); int size = m.AttackRange; for (int i = -size; i <= size; i++) { for (int j = -size; j <= size; j++) { int xx = Mathf.Abs(j); int yy = Mathf.Abs(i); if (xx + yy <= size) { GameBattleUnit unit = GameBattleUnitManager.instance.getUnit(x + j, y + i); if (unit != null) { switch (m.UseTargetType) { case GameTargetType.User: { if (unit.UnitCampType == camp) { list.Add(unit); } } break; case GameTargetType.Enemy: { if (unit.UnitCampType != camp) { list.Add(unit); } } break; case GameTargetType.Summon: { if (unit.IsSummon && unit.UnitCampType != camp) { list.Add(unit); } } break; } } else { switch (m.UseTargetType) { case GameTargetType.Summon: { list.Add(unit); } break; } } } } } if (list.Count > attackUnits.Count || (list.Count > 0 && list.Count == attackUnits.Count && Mathf.Abs(ux - x) + Mathf.Abs(uy - y) < Mathf.Abs(ux - attackCell.x) + Mathf.Abs(uy - attackCell.y))) { attackCell.x = x; attackCell.y = y; attackUnits.Clear(); for (int i = 0; i < list.Count; i++) { attackUnits.Add(list[i]); } } list.Clear(); }
public void getUnitsLine(int x, int y, GameItem m, GameUnitCampType camp) { List <GameBattleUnit> list = new List <GameBattleUnit>(); for (int i = 0; i < (int)GameBattleAttackMapDirection.Count; i++) { int x1 = 0; int y1 = 0; switch (i) { case (int)GameBattleAttackMapDirection.North: y1 = -1; break; case (int)GameBattleAttackMapDirection.East: x1 = 1; break; case (int)GameBattleAttackMapDirection.South: y1 = 1; break; case (int)GameBattleAttackMapDirection.West: x1 = -1; break; } for (int j = 0; j < m.AttackRangeMax; j++) { GameBattleUnit u = GameBattleUnitManager.instance.getUnit(x + i * x1, y + i * y1); switch (m.UseTargetType) { case GameTargetType.User: { if (u != null && u.UnitCampType == camp) { list.Add(u); } } break; case GameTargetType.Enemy: { if (u != null && u.UnitCampType != camp) { list.Add(u); } } break; case GameTargetType.Summon: { if (u == null) { list.Add(u); } } break; } if (list.Count > attackUnits.Count) { attackCell.x = x + x1; attackCell.y = y + y1; attackDirection = (GameBattleAttackMapDirection)i; attackUnits.Clear(); for (int k = 0; k < list.Count; k++) { attackUnits.Add(list[k]); } } list.Clear(); } } }
public void getUnitsCircleAI(GameBattleUnit unit, int ux, int uy, int mx, int my, int x, int y, GameSkill sk, GameUnitCampType camp) { if (targetID != GameDefine.INVALID_ID) { for (int j = 0; j < attackUnits.Count; j++) { if (attackUnits[j].BattleManID == targetID) { return; } } } attackDirection = GameBattleAttackMapDirection.Count; List <GameBattleUnit> list1 = new List <GameBattleUnit>(); int size = sk.AttackRange; for (int i = -size; i <= size; i++) { for (int j = -size; j <= size; j++) { int xx = Mathf.Abs(j); int yy = Mathf.Abs(i); if (xx + yy <= size) { GameBattleUnit u = GameBattleUnitManager.instance.getUnit(x + j, y + i); if (checkSkillAI(unit, u, sk, camp)) { list1.Add(u); } } } } bool bTarget = false; if (targetID != GameDefine.INVALID_ID) { for (int j = 0; j < list1.Count; j++) { if (list1[j].BattleManID == targetID) { bTarget = true; } } } if (bTarget || list1.Count > attackUnits.Count || (list1.Count > 0 && list1.Count == attackUnits.Count && Mathf.Abs(ux - x) + Mathf.Abs(uy - y) < Mathf.Abs(ux - attackCell.x) + Mathf.Abs(uy - attackCell.y)) || (list1.Count > 0 && list1.Count == attackUnits.Count && Random.Range(0, 100) > 50 && Mathf.Abs(ux - x) + Mathf.Abs(uy - y) == Mathf.Abs(ux - attackCell.x) + Mathf.Abs(uy - attackCell.y)) ) { attackCell.x = x; attackCell.y = y; attackMoveCell.x = mx; attackMoveCell.y = my; attackUnits.Clear(); IsAttackUnits = true; for (int i = 0; i < list1.Count; i++) { attackUnits.Add(list1[i]); } } list1.Clear(); }
public void getUnitsLineAI(GameBattleUnit unit, int ux, int uy, GameSkill sk, GameUnitCampType camp) { if (targetID != GameDefine.INVALID_ID) { for (int j = 0; j < attackUnits.Count; j++) { if (attackUnits[j].BattleManID == targetID) { return; } } } List <GameBattleUnit> list1 = new List <GameBattleUnit>(); for (int i = 0; i < (int)GameBattleAttackMapDirection.Count; i++) { int x1 = 0; int y1 = 0; switch (i) { case (int)GameBattleAttackMapDirection.North: y1 = -1; break; case (int)GameBattleAttackMapDirection.East: x1 = 1; break; case (int)GameBattleAttackMapDirection.South: y1 = 1; break; case (int)GameBattleAttackMapDirection.West: x1 = -1; break; } for (int j = 0; j < sk.AttackRangeMax; j++) { GameBattleUnit u = GameBattleUnitManager.instance.getUnit(ux + i * x1, uy + i * y1); if (checkSkillAI(unit, u, sk, camp)) { list1.Add(u); } } bool bTarget = false; if (targetID != GameDefine.INVALID_ID) { for (int j = 0; j < list1.Count; j++) { if (list1[j].BattleManID == targetID) { bTarget = true; } } } if (list1.Count > attackUnits.Count || bTarget) { attackCell.x = ux + x1; attackCell.y = uy + y1; attackMoveCell.x = ux; attackMoveCell.y = uy; attackDirection = (GameBattleAttackMapDirection)i; attackUnits.Clear(); IsAttackUnits = true; for (int k = 0; k < list1.Count; k++) { attackUnits.Add(list1[k]); } } list1.Clear(); } }
public void canAttack(int x, int y, GameItem m, GameUnitCampType camp) { attackUnits.Clear(); list.Clear(); int width = GameBattleManager.instance.Width; int height = GameBattleManager.instance.Height; int min = (m.AttackRangeMin == GameDefine.INVALID_ID ? 1 : m.AttackRangeMin + 1); int max = m.AttackRangeMax; if (min > max) { min = max; } rangeType = m.AttackRangeType; posX = x; posY = y; switch (rangeType) { case GameAttackRangeType.Circle: { for (int i = -max; i <= max; i++) { for (int j = -max; j <= max; j++) { int xx = Mathf.Abs(j); int yy = Mathf.Abs(i); if (xx + yy <= max && xx + yy >= min) { Cell cell = new Cell(); cell.x = x + j; cell.y = y + i; list.Add(cell); } } } if (m.AttackRangeMin == 0) { Cell cell = new Cell(); cell.x = x; cell.y = y; list.Add(cell); } for (int i = 0; i < list.Count; i++) { if (list[i].x < 0 || list[i].y < 0 || list[i].x >= width || list[i].y >= height) { continue; } getUnitsCircle(x, y, list[i].x, list[i].y, m, camp); } } break; case GameAttackRangeType.Line: { getUnitsLine(x, y, m, camp); } break; } }
public int findPathNear(int sx, int sy, int ex, int ey, byte cb, bool fly, GameUnitCampType ct) { if (maxX == 0 || maxY == 0) { return(0); } if (ex >= maxX || ey >= maxY || sx >= maxX || sy >= maxY || sx < 0 || sy < 0 || ex < 0 || ey < 0) { return(0); } checkBlock = cb; checkUnit = !fly; campType = ct; setStartEnd(sx, sy, ex, ey); findPath(); if (resultNode == null) { return(0); } cost = 0; int count = 0; PathNode node = resultNode; int lastX = 0; int lastY = 0; int lineX = 0; int lineY = 0; while (node != null) { pathResult[count] = node.posX; count++; pathResult[count] = node.posY; count++; if (lastX == node.posX) { lineY++; } if (lastY == node.posY) { lineX++; } lastX = node.posX; lastY = node.posY; cost += GameBattleManager.instance.getPoint(node.posX, node.posY).Move; if (GameBattleUnitManager.instance.getUnit(node.posX, node.posY) != null) { cost += GameBattleManager.instance.getPoint(node.posX, node.posY).Move; } node = node.parent; } cost += Mathf.Abs(lineX - lineY); return(count); }
public void canAttackAI(GameBattleUnit unit1, int ux, int uy, int x, int y, GameSkill sk, GameUnitCampType camp, int id) { targetID = id; IsAttackUnits = false; checkUnitAI = false; list.Clear(); int width = GameBattleManager.instance.Width; int height = GameBattleManager.instance.Height; int min = (sk.AttackRangeMin == GameDefine.INVALID_ID ? 1 : sk.AttackRangeMin + 1); int max = sk.AttackRangeMax; if (min > max) { min = max; } rangeType = sk.AttackRangeType; posX = x; posY = y; switch (rangeType) { case GameAttackRangeType.Circle: { for (int i = -max; i <= max; i++) { for (int j = -max; j <= max; j++) { int xx = Mathf.Abs(j); int yy = Mathf.Abs(i); if (xx + yy <= max && xx + yy >= min) { Cell cell = new Cell(); cell.x = x + j; cell.y = y + i; list.Add(cell); } } } if (sk.AttackRangeMin == 0) { Cell cell = new Cell(); cell.x = x; cell.y = y; list.Add(cell); } for (int i = 0; i < list.Count; i++) { if (list[i].x < 0 || list[i].y < 0 || list[i].x >= width || list[i].y >= height) { continue; } getUnitsCircleAI(unit1, ux, uy, x, y, list[i].x, list[i].y, sk, camp); } } break; case GameAttackRangeType.Line: { getUnitsLineAI(unit1, ux, uy, sk, camp); } break; } if (checkUnitAI) { for (int i = 0; i < attackUnits.Count; i++) { GameBattleUnit unit = attackUnits[i]; GameUnitMove unitMove = GameUnitMoveTypeData.instance.getData(unit.MoveType); bool fly = unit.checkEffect(GameSkillResutlEffect.Under) ? true : unitMove.fly; List <GameBattleUnitMovement.Cell> cells = GameBattleUnitMovement.instance.getMoveList( unit.PosX, unit.PosY, unit.Move, unit.MoveType, fly, unit.UnitCampType); for (int j = 0; j < cells.Count; j++) { GameBattleUnit u = GameBattleUnitAttackSelection.instance.canAttack( cells[j].x, cells[j].y, unit.Weapon, unit.UnitCampType); if (u != null) { return; } } } list.Clear(); attackUnits.Clear(); } }