First Commit
This commit is contained in:
commit
eed6b79efc
2836 files changed
+948481
No files matched your search
@@ -0,0 +1,214 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Площадка оценки и перепродажи восстановленного авто перед гаражом.
|
||||
/// Чек-лист: мойка, ржавчина, комплектность, 4 целых затянутых колеса, агрегаты > 80%, жидкости > 85%.
|
||||
/// После продажи выводится финансовый отчет сделки (покупка, затраты, продажа, чистая прибыль).
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(BoxCollider))]
|
||||
public class CarSellZone : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private KeyCode sellKeyInCar = KeyCode.Return;
|
||||
[SerializeField] private KeyCode sellKeyOnFoot = KeyCode.B;
|
||||
|
||||
private enum View { None, Evaluation, Report }
|
||||
private View view = View.None;
|
||||
private CarOwnership car;
|
||||
private CarInspection.SaleReport report;
|
||||
private float soldPrice, soldPurchase, soldExpenses;
|
||||
private string soldTitle;
|
||||
private BoxCollider zone;
|
||||
private Transform player;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
zone = GetComponent<BoxCollider>();
|
||||
zone.isTrigger = true;
|
||||
gameObject.layer = 2; // Ignore Raycast — не мешает лучу игрока
|
||||
}
|
||||
|
||||
private bool Contains(Vector3 worldPos)
|
||||
{
|
||||
Vector3 local = transform.InverseTransformPoint(worldPos) - zone.center;
|
||||
Vector3 half = zone.size * 0.5f;
|
||||
return Mathf.Abs(local.x) <= half.x && Mathf.Abs(local.z) <= half.z && local.y > -2f && local.y < 4f;
|
||||
}
|
||||
|
||||
private CarOwnership FindOwnedCarInZone()
|
||||
{
|
||||
foreach (CarOwnership c in CarOwnership.All)
|
||||
if (c != null && c.isOwned && Contains(c.transform.position)) return c;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (view != View.None)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Escape)) Close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (GameInputLock.IsLocked) return;
|
||||
MainMenuAndBootManager menu = MainMenuAndBootManager.Instance;
|
||||
if (menu != null && !menu.IsPlaying) return;
|
||||
|
||||
VehicleInteraction current = VehicleInteraction.Current;
|
||||
if (current != null)
|
||||
{
|
||||
CarOwnership own = current.GetComponent<CarOwnership>();
|
||||
if (own == null || !own.isOwned || !Contains(current.transform.position)) return;
|
||||
GameHUD.SetContextHint("Площадка продажи: остановитесь и нажмите [Enter] — выставить автомобиль на продажу");
|
||||
if (Input.GetKeyDown(sellKeyInCar) || Input.GetKeyDown(KeyCode.KeypadEnter))
|
||||
{
|
||||
if (current.Controller != null && current.Controller.SpeedKmH > 4f)
|
||||
GameHUD.Notify("Остановите машину на площадке", GameUI.Accent);
|
||||
else
|
||||
Open(own);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
PlayerMovement pm = FindAnyObjectByType<PlayerMovement>();
|
||||
if (pm != null) player = pm.transform;
|
||||
}
|
||||
if (player == null || !player.gameObject.activeInHierarchy || !Contains(player.position)) return;
|
||||
|
||||
CarOwnership inZone = FindOwnedCarInZone();
|
||||
if (inZone == null) return;
|
||||
GameHUD.SetContextHint($"Площадка продажи: [B] Выставить {inZone.carTitle} на продажу");
|
||||
if (Input.GetKeyDown(sellKeyOnFoot)) Open(inZone);
|
||||
}
|
||||
|
||||
private void Open(CarOwnership c)
|
||||
{
|
||||
car = c;
|
||||
report = CarInspection.EvaluateForSale(c);
|
||||
view = View.Evaluation;
|
||||
GameInputLock.Lock(this);
|
||||
ProceduralAudioManager.Instance?.Play(SfxId.Notification);
|
||||
}
|
||||
|
||||
private void Close()
|
||||
{
|
||||
view = View.None;
|
||||
car = null;
|
||||
GameInputLock.Unlock(this);
|
||||
}
|
||||
|
||||
private void Sell()
|
||||
{
|
||||
if (car == null || report == null) return;
|
||||
|
||||
soldTitle = car.carTitle;
|
||||
soldPrice = report.salePrice;
|
||||
soldPurchase = car.purchasePrice;
|
||||
soldExpenses = car.expenses;
|
||||
float profit = soldPrice - soldPurchase - soldExpenses;
|
||||
|
||||
GameEconomyManager eco = GameEconomyManager.Instance;
|
||||
if (eco != null)
|
||||
{
|
||||
eco.Earn(soldPrice, $"Продажа {soldTitle}");
|
||||
eco.RegisterDeal(profit);
|
||||
}
|
||||
|
||||
VehicleInteraction vi = car.GetComponent<VehicleInteraction>();
|
||||
if (vi != null && vi.isPlayerInside) vi.ExitVehicle();
|
||||
|
||||
foreach (WheelBrickSupport b in FindObjectsByType<WheelBrickSupport>(FindObjectsSortMode.None))
|
||||
if (Vector3.Distance(b.transform.position, car.transform.position) < 4f) Destroy(b.gameObject);
|
||||
|
||||
Destroy(car.gameObject);
|
||||
car = null;
|
||||
view = View.Report;
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (view == View.None) return;
|
||||
GameUI.Begin(-10);
|
||||
float w = GameUI.VirtualWidth;
|
||||
float h = GameUI.VirtualHeight;
|
||||
GameUI.DrawRect(new Rect(0, 0, w, h), GameUI.Bg.WithAlpha(0.55f));
|
||||
|
||||
if (view == View.Evaluation && car != null && report != null) DrawEvaluation(w, h);
|
||||
else if (view == View.Report) DrawReport(w, h);
|
||||
else Close();
|
||||
}
|
||||
|
||||
private void DrawEvaluation(float w, float h)
|
||||
{
|
||||
Rect r = new Rect(w * 0.5f - 560, h * 0.5f - 420, 1120, 840);
|
||||
GUI.Box(r, GUIContent.none, GameUI.PanelSolid);
|
||||
GUI.Label(new Rect(r.x + 30, r.y + 18, r.width - 60, 44), $"ОЦЕНКА АВТОМОБИЛЯ: {car.carTitle}", GameUI.Header);
|
||||
|
||||
float y = r.y + 80;
|
||||
Line(r, ref y, report.washed, "Кузов вымыт (бонус +8% к цене)");
|
||||
Line(r, ref y, report.rustFixed, "Ржавчина зачищена и покрашена");
|
||||
Line(r, ref y, report.bodyComplete, "Все кузовные детали установлены");
|
||||
Line(r, ref y, report.wheelsOk, "4 целых колеса установлены и прикручены");
|
||||
Line(r, ref y, report.engineOk, "Подкапотные агрегаты исправны (> 80%)");
|
||||
Line(r, ref y, report.fluidsOk, "Свежие технические жидкости (> 85%)");
|
||||
|
||||
y += 10;
|
||||
GUI.Label(new Rect(r.x + 40, y, r.width - 80, 30), $"Готовность к продаже: <b>{Mathf.RoundToInt(report.score * 100f)}%</b>", GameUI.Label);
|
||||
y += 36;
|
||||
GameUI.ProgressBar(new Rect(r.x + 40, y, r.width - 80, 22), report.score, report.score > 0.95f ? GameUI.Green : GameUI.Accent);
|
||||
y += 40;
|
||||
|
||||
if (report.issues.Count > 0)
|
||||
{
|
||||
string issues = string.Join("\n", report.issues.GetRange(0, Mathf.Min(7, report.issues.Count)));
|
||||
GUI.Label(new Rect(r.x + 40, y, r.width - 80, 200), "<color=#F2A93B>Замечания покупателя:</color>\n" + issues, GameUI.Small);
|
||||
}
|
||||
|
||||
float expenses = car.expenses;
|
||||
string purchase = car.isStarterCar ? "проектная машина (без затрат на покупку)" : GameUI.Money(car.purchasePrice);
|
||||
GUI.Label(new Rect(r.x + 40, r.yMax - 190, r.width - 80, 90),
|
||||
$"Цена покупки: {purchase}\nЗатраты на запчасти и жидкости: {GameUI.Money(expenses)}\n" +
|
||||
$"Предложение покупателя: <b><color=#4CD07D>{GameUI.Money(report.salePrice)}</color></b>", GameUI.Label);
|
||||
|
||||
if (GameUI.Btn(new Rect(r.x + 40, r.yMax - 86, 460, 62), $"ПРОДАТЬ ЗА {GameUI.Money(report.salePrice).Split(' ')[0]}", GameUI.ButtonAccent))
|
||||
Sell();
|
||||
if (GameUI.Btn(new Rect(r.xMax - 330, r.yMax - 86, 290, 62), "ДОРАБОТАТЬ МАШИНУ"))
|
||||
Close();
|
||||
}
|
||||
|
||||
private static void Line(Rect r, ref float y, bool ok, string text)
|
||||
{
|
||||
GUI.Label(new Rect(r.x + 40, y, r.width - 80, 34), $"{GameUI.Check(ok)} {text} {(ok ? "<color=#4CD07D>да</color>" : "<color=#E5534B>нет</color>")}", GameUI.Label);
|
||||
y += 40;
|
||||
}
|
||||
|
||||
private void DrawReport(float w, float h)
|
||||
{
|
||||
Rect r = new Rect(w * 0.5f - 460, h * 0.5f - 300, 920, 600);
|
||||
GUI.Box(r, GUIContent.none, GameUI.PanelSolid);
|
||||
GUI.Label(new Rect(r.x, r.y + 24, r.width, 56), "ФИНАНСОВЫЙ ОТЧЕТ СДЕЛКИ", GameUI.Title);
|
||||
GUI.Label(new Rect(r.x, r.y + 84, r.width, 30), soldTitle, GameUI.SmallCenter);
|
||||
|
||||
float profit = soldPrice - soldPurchase - soldExpenses;
|
||||
GUIStyle row = new GUIStyle(GameUI.Label) { fontSize = 24 };
|
||||
GUIStyle val = new GUIStyle(row) { alignment = TextAnchor.UpperRight };
|
||||
string[] labels = { "Цена покупки:", "Затраты на запчасти и жидкости:", "Цена продажи:" };
|
||||
float[] values = { soldPurchase, soldExpenses, soldPrice };
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
GUI.Label(new Rect(r.x + 80, r.y + 150 + i * 44, 460, 40), labels[i], row);
|
||||
GUI.Label(new Rect(r.x + 480, r.y + 150 + i * 44, r.width - 560, 40), GameUI.Money(values[i]), val);
|
||||
}
|
||||
GameUI.DrawRect(new Rect(r.x + 80, r.y + 290, r.width - 160, 2), GameUI.Hex("3A3F4A"));
|
||||
GUI.Label(new Rect(r.x + 80, r.y + 306, 460, 44), "<b>Чистая прибыль:</b>", row);
|
||||
GUI.Label(new Rect(r.x + 480, r.y + 306, r.width - 560, 44), $"<b><color={(profit >= 0 ? "#4CD07D" : "#E5534B")}>{GameUI.Money(profit)}</color></b>", val);
|
||||
|
||||
GameEconomyManager eco = GameEconomyManager.Instance;
|
||||
if (eco != null && !eco.Unlimited)
|
||||
GUI.Label(new Rect(r.x + 80, r.y + 420, r.width - 160, 40), $"На счету: {eco.FormatMoney(eco.Money)} • До Автосалона: {eco.FormatShort(Mathf.Max(0f, eco.AutosalonGoal - eco.Money))}", GameUI.Small);
|
||||
|
||||
if (GameUI.Btn(new Rect(r.x + r.width * 0.5f - 180, r.yMax - 90, 360, 60), "ОТЛИЧНО!", GameUI.ButtonAccent))
|
||||
Close();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user