private void ClampRoad(List <Vector2w> road, int ap, int dir, UnitInfoItem unitInfo) { int curDir = dir; int count = 0; for (int i = 0; i < road.Count - 1; i++) { int direction = GameUtil.GetDir(road[i], road[i + 1]); if (direction != curDir) { ap -= GameUtil.CalcDir(curDir, direction) * unitInfo.apRotate; if (ap < 0) { break; } } ap -= unitInfo.apMove; if (ap < 0) { break; } count++; } road.RemoveRange(count, road.Count - count); }
private void BuyUnit(uint userId, string unitId) { User user = d.GetUser(userId); if (user == null) { return; } if (user.units.Find(f => f.id == unitId) != null) { return; } UnitInfoItem info = GameData.unitInfo[unitId]; int cost = info.cost; if (user.money < cost) { Data.t.netMsg.Add(new MsgServerNotification(userId, "no_money")); return; } user.money -= cost; user.units.Add(new Unit(unitId, d.GetUnitUID())); Data.t.netMsg.Add(new MsgServerUser(user.id, user)); }