First Commit
This commit is contained in:
commit
eed6b79efc
2836 files changed
+948481
No files matched your search
@@ -0,0 +1,104 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Сведения о сделке по конкретной машине: объявление, цена покупки, затраты на ремонт
|
||||
/// и что игрок уже проверил при осмотре (капот, OBD-сканер, толщиномер).
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
public class CarOwnership : MonoBehaviour
|
||||
{
|
||||
public static readonly List<CarOwnership> All = new List<CarOwnership>();
|
||||
|
||||
[Header("Объявление")]
|
||||
public string carTitle = "Автомобиль";
|
||||
public int year = 2001;
|
||||
public int mileageKm = 180000;
|
||||
public float askingPrice = 2500f;
|
||||
[Tooltip("Цена идеального экземпляра на рынке")]
|
||||
public float marketValue = 4500f;
|
||||
public string sellerName = "Продавец";
|
||||
|
||||
[Header("Сделка")]
|
||||
public bool isOwned;
|
||||
public bool isStarterCar;
|
||||
public float purchasePrice;
|
||||
public float expenses;
|
||||
public readonly List<string> expenseLog = new List<string>();
|
||||
|
||||
[Header("Осмотр перед покупкой")]
|
||||
public bool hoodInspected;
|
||||
public bool obdScanned;
|
||||
public bool thicknessChecked;
|
||||
public bool hiddenRepaintFound;
|
||||
|
||||
public CarListing Listing { get; set; }
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void ResetStatics() => All.Clear();
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (!All.Contains(this)) All.Add(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
All.Remove(this);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (hoodInspected || isOwned) return;
|
||||
foreach (CarPartAnimator anim in GetComponentsInChildren<CarPartAnimator>())
|
||||
{
|
||||
if (anim.IsOpen && anim.name.ToLowerInvariant().Contains("hood"))
|
||||
{
|
||||
hoodInspected = true;
|
||||
GameHUD.Notify("Вы осмотрели подкапотное пространство: уровни жидкостей и АКБ видны", GameUI.Blue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddExpense(float usd, string reason)
|
||||
{
|
||||
expenses += usd;
|
||||
expenseLog.Add($"{reason}: ${usd:N0}");
|
||||
}
|
||||
|
||||
public void SetupFromListing(CarListing listing)
|
||||
{
|
||||
Listing = listing;
|
||||
if (listing == null) return;
|
||||
carTitle = listing.catalogItem != null ? listing.catalogItem.carTitle : carTitle;
|
||||
year = listing.year;
|
||||
mileageKm = listing.mileageKm;
|
||||
askingPrice = listing.price;
|
||||
marketValue = listing.catalogItem != null ? listing.catalogItem.idealPrice : askingPrice * 1.6f;
|
||||
sellerName = listing.sellerName;
|
||||
}
|
||||
|
||||
public static CarOwnership Get(GameObject anyChild)
|
||||
{
|
||||
if (anyChild == null) return null;
|
||||
return anyChild.GetComponentInParent<CarOwnership>();
|
||||
}
|
||||
|
||||
public static CarOwnership FindNearestNotOwned(Vector3 pos, float maxDist)
|
||||
{
|
||||
CarOwnership best = null;
|
||||
float bestD = maxDist;
|
||||
foreach (CarOwnership c in All)
|
||||
{
|
||||
if (c == null || c.isOwned) continue;
|
||||
float d = Vector3.Distance(pos, c.transform.position);
|
||||
if (d < bestD)
|
||||
{
|
||||
bestD = d;
|
||||
best = c;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user