public void CheckUnitAction(BaseSam unit) { var adapter = new TileAdapter(); var savedPath = adapter.GetPathMove(unit.X, unit.Y, unit.Mov, unit.Camp); Dictionary <int, int> tileDangerDict = new Dictionary <int, int>(); //x+1000*y mostDangerId = 0; int mostDangerMark = 0; List <int> mostDangerPathList = new List <int>(); foreach (var pathResult in savedPath) { var tileId = pathResult.NowCell.X + pathResult.NowCell.Y * 1000; var enemyUnits = battleManager.GetAllUnits(ConfigDatas.CampConfig.Indexer.Reborn); foreach (var enemy in enemyUnits) { var dis = enemy.GetDistanceFrom(pathResult.NowCell.X, pathResult.NowCell.Y); if (dis <= unit.Range) //射程内 { var nowDanger = 10000 / (enemy.Level * enemy.LeftHp); if (enemy.Id == mostDangerId) { mostDangerPathList.Add(tileId); } else if (enemy.Id != mostDangerId && nowDanger > mostDangerMark) { mostDangerMark = nowDanger; mostDangerId = enemy.Id; mostDangerPathList.Clear(); mostDangerPathList.Add(tileId); } } if (!tileDangerDict.ContainsKey(tileId)) { tileDangerDict[tileId] = 0; } tileDangerDict[tileId] += 10000 / (enemy.Level * enemy.LeftHp + dis * dis * 3); } } if (mostDangerId > 0) //有目标 { mostDangerPathList.Sort((a, b) => tileDangerDict[b] - tileDangerDict[a]); var x = mostDangerPathList[0] % 1000; var y = mostDangerPathList[0] / 1000; actMove(unit.Id, x, y, savedPath, OnUnitMovedAndAttack); } else { List <int> tileList = new List <int>(tileDangerDict.Keys); //所有格子排序 tileList.Sort((a, b) => tileDangerDict[b] - tileDangerDict[a]); var x = tileList[0] % 1000; var y = tileList[0] / 1000; actMove(unit.Id, x, y, savedPath, OnUnitMoved); } }
private void EnterSelectMove(BaseSam movingUnit) { var adapter = new TileAdapter(); savedPath = adapter.GetPathMove(movingUnit.X, movingUnit.Y, movingUnit.Mov, (byte)ConfigDatas.CampConfig.Indexer.Reborn); stage = ControlStage.SelectMove; refreshAll.Fire(); }
public void AddUnit(BaseSam bu) { bu.Id = unitIdOffset++; bu.BM = this; bu.Init(); unitList.Add(bu); TileManager.Instance.Enter(bu.X, bu.Y, bu.Id, bu.Camp); }
private IEnumerator DelayAttack(BaseSam atkUnit, BaseSam targetUnit) { yield return(new NLWaitForSeconds(0.2f)); var unitPos = new Point(targetUnit.X * TileManager.CellSize - baseX, targetUnit.Y * TileManager.CellSize - baseY); var unitSize = new Size(TileManager.CellSize, TileManager.CellSize); if (targetUnit.OnAttack(atkUnit)) { var effectDie = new StaticUIImageEffect(EffectBook.GetEffect("shrink"), HSIcons.GetImage("Samurai", targetUnit.Cid), unitPos, unitSize); effectRun.AddEffect(effectDie); } if (atkUnit.Camp == (byte)ConfigDatas.CampConfig.Indexer.Reborn) //todo 略ws { stage = ControlStage.None; } atkUnit.IsFinished = true;//攻击并结束回合 OnUnitFinish(); }
public void RemoveUnit(BaseSam bu) { bu.OnRemove(); TileManager.Instance.Leave(bu.X, bu.Y, bu.Id); unitList.Remove(bu); }