First Commit
This commit is contained in:
commit
eed6b79efc
2836 files changed
+948481
No files matched your search
@@ -0,0 +1,192 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Осмотр автомобиля: список дефектов для торга с продавцом и чек-лист состояния для продажи.
|
||||
/// Скрытые дефекты (под капотом, ошибки ДВС, перекрас) видны только после проверки игроком.
|
||||
/// </summary>
|
||||
public static class CarInspection
|
||||
{
|
||||
public class Defect
|
||||
{
|
||||
public string text;
|
||||
public float discountPercent;
|
||||
public bool revealed;
|
||||
public string howToReveal;
|
||||
}
|
||||
|
||||
public static List<Defect> CollectDefects(CarOwnership car)
|
||||
{
|
||||
List<Defect> list = new List<Defect>();
|
||||
if (car == null) return list;
|
||||
Transform root = car.transform;
|
||||
|
||||
// --- Видно сразу ---
|
||||
float dirt = 0f;
|
||||
int dirtN = 0;
|
||||
int rusted = 0;
|
||||
foreach (CarPartVisuals v in root.GetComponentsInChildren<CarPartVisuals>())
|
||||
{
|
||||
if (!v.HasPaintSlots) continue;
|
||||
dirt += v.DirtAmount;
|
||||
dirtN++;
|
||||
if (v.Stage == RepairStage.Rusted) rusted++;
|
||||
}
|
||||
if (dirtN > 0 && dirt / dirtN > 0.3f)
|
||||
list.Add(new Defect { text = "Кузов сильно загрязнен — не видно реального состояния ЛКП", discountPercent = 2f, revealed = true });
|
||||
if (rusted > 0)
|
||||
list.Add(new Defect { text = $"Ржавчина на кузове: {rusted} очаг(а)", discountPercent = Mathf.Min(8f, 2f + rusted * 1.5f), revealed = true });
|
||||
|
||||
int missing = 0;
|
||||
foreach (CarPartMountZone z in root.GetComponentsInChildren<CarPartMountZone>(true))
|
||||
{
|
||||
if (z.TargetPart != null && z.TargetPart.GetComponent<EnginePart>() != null) continue;
|
||||
if (z.TargetPart != null && z.TargetPart.IsWheel) continue;
|
||||
missing++;
|
||||
}
|
||||
if (missing > 0)
|
||||
list.Add(new Defect { text = $"Некомплект: нет {missing} кузовн. детал(и)", discountPercent = Mathf.Min(9f, 3f * missing), revealed = true });
|
||||
|
||||
int flat = 0, wheelsMissing = 0;
|
||||
foreach (CarWheelCondition w in root.GetComponentsInChildren<CarWheelCondition>(true))
|
||||
{
|
||||
CarPart p = w.GetComponent<CarPart>();
|
||||
if (p != null && (!p.gameObject.activeInHierarchy || p.State != PartState.Installed)) wheelsMissing++;
|
||||
else if (w.IsFlat) flat++;
|
||||
}
|
||||
if (wheelsMissing > 0)
|
||||
list.Add(new Defect { text = "Стоит на кирпичах — нет колеса", discountPercent = 5f, revealed = true });
|
||||
if (flat > 0)
|
||||
list.Add(new Defect { text = $"Спущено колес: {flat}", discountPercent = 2f * flat, revealed = true });
|
||||
|
||||
// --- Под капотом (нужно открыть капот) ---
|
||||
CarFluids fluids = root.GetComponent<CarFluids>();
|
||||
if (fluids != null)
|
||||
{
|
||||
if (fluids.EngineOil.FillPercent < 0.5f || fluids.EngineOil.quality < 0.3f)
|
||||
list.Add(new Defect { text = "Старое черное масло / низкий уровень", discountPercent = 3f, revealed = car.hoodInspected, howToReveal = "откройте капот / проверьте щуп" });
|
||||
if (fluids.Coolant.FillPercent < 0.5f)
|
||||
list.Add(new Defect { text = "Низкий уровень антифриза", discountPercent = 2f, revealed = car.hoodInspected, howToReveal = "откройте капот" });
|
||||
if (fluids.BrakeFluid.FillPercent < 0.3f)
|
||||
list.Add(new Defect { text = "Тормозная жидкость ниже минимума", discountPercent = 2f, revealed = car.hoodInspected, howToReveal = "откройте капот" });
|
||||
}
|
||||
|
||||
EngineBayManager bay = root.GetComponent<EngineBayManager>();
|
||||
if (bay != null)
|
||||
{
|
||||
if (bay.GetPart(EnginePartType.Battery) == null)
|
||||
list.Add(new Defect { text = "Нет аккумулятора", discountPercent = 4f, revealed = car.hoodInspected, howToReveal = "откройте капот" });
|
||||
|
||||
// --- Ошибки двигателя (нужен OBD-сканер) ---
|
||||
foreach (string code in bay.GetObdCodes())
|
||||
{
|
||||
if (code.StartsWith("C1241")) continue;
|
||||
list.Add(new Defect { text = "OBD: " + code, discountPercent = 3f, revealed = car.obdScanned, howToReveal = "OBD-сканер" });
|
||||
}
|
||||
}
|
||||
|
||||
// --- Скрытый перекрас (нужен толщиномер) ---
|
||||
int repaint = 0;
|
||||
foreach (CarPartVisuals v in root.GetComponentsInChildren<CarPartVisuals>())
|
||||
if (v.HiddenRepaint && v.Stage == RepairStage.Healthy) repaint++;
|
||||
if (repaint > 0)
|
||||
list.Add(new Defect { text = $"Скрытый перекрас/шпаклёвка: {repaint} детал(и) (250–450 мкм)", discountPercent = 4f, revealed = car.hiddenRepaintFound, howToReveal = "толщиномер ЛКП" });
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public class SaleReport
|
||||
{
|
||||
public bool washed, rustFixed, bodyComplete, wheelsOk, engineOk, fluidsOk;
|
||||
public float score;
|
||||
public float salePrice;
|
||||
public float referencePrice;
|
||||
public readonly List<string> issues = new List<string>();
|
||||
}
|
||||
|
||||
/// <summary>Комплексная оценка автомобиля для перепродажи.</summary>
|
||||
public static SaleReport EvaluateForSale(CarOwnership car)
|
||||
{
|
||||
SaleReport r = new SaleReport();
|
||||
if (car == null) return r;
|
||||
Transform root = car.transform;
|
||||
bool diploma = GameEconomyManager.Instance == null || GameEconomyManager.Instance.DiplomaFeatures;
|
||||
|
||||
// 1. Мойка
|
||||
float dirt = 0f;
|
||||
int n = 0;
|
||||
bool rustOk = true;
|
||||
foreach (CarPartVisuals v in root.GetComponentsInChildren<CarPartVisuals>())
|
||||
{
|
||||
if (!v.HasPaintSlots) continue;
|
||||
dirt += v.DirtAmount;
|
||||
n++;
|
||||
RepairStage s = v.Stage;
|
||||
if (s != RepairStage.Healthy && s != RepairStage.Repaired) rustOk = false;
|
||||
}
|
||||
float avgDirt = n > 0 ? dirt / n : 0f;
|
||||
r.washed = avgDirt <= 0.03f;
|
||||
if (!r.washed) r.issues.Add($"Кузов не вымыт (грязь {Mathf.RoundToInt(avgDirt * 100f)}%)");
|
||||
r.rustFixed = rustOk;
|
||||
if (!rustOk) r.issues.Add("Ржавчина зачищена и покрашена не везде");
|
||||
|
||||
// 2. Комплектность кузова
|
||||
int missing = 0;
|
||||
foreach (CarPartMountZone z in root.GetComponentsInChildren<CarPartMountZone>(true))
|
||||
{
|
||||
if (z.TargetPart != null && (z.TargetPart.IsWheel || z.TargetPart.GetComponent<EnginePart>() != null)) continue;
|
||||
missing++;
|
||||
}
|
||||
r.bodyComplete = missing == 0;
|
||||
if (!r.bodyComplete) r.issues.Add($"Не установлено кузовных деталей: {missing}");
|
||||
|
||||
// 3. Колеса
|
||||
int wheelsOk = 0, wheelsTotal = 0;
|
||||
foreach (WheelCollider wc in root.GetComponentsInChildren<WheelCollider>(true))
|
||||
{
|
||||
wheelsTotal++;
|
||||
bool ok = false;
|
||||
foreach (CarPart p in root.GetComponentsInChildren<CarPart>(false))
|
||||
{
|
||||
if (p.LinkedWheelCollider != wc || p.State != PartState.Installed) continue;
|
||||
CarWheelCondition cond = p.GetComponent<CarWheelCondition>();
|
||||
bool flat = cond != null && cond.IsFlat;
|
||||
bool bolted = p.TotalBoltsCount == 0 || p.TightenedBoltsCount >= p.TotalBoltsCount;
|
||||
ok = !flat && bolted && wc.enabled;
|
||||
break;
|
||||
}
|
||||
if (ok) wheelsOk++;
|
||||
}
|
||||
bool bricks = false;
|
||||
foreach (WheelBrickSupport b in Object.FindObjectsByType<WheelBrickSupport>(FindObjectsSortMode.None))
|
||||
if (Vector3.Distance(b.transform.position, root.position) < 4f) bricks = true;
|
||||
r.wheelsOk = wheelsOk >= wheelsTotal && wheelsTotal > 0 && !bricks;
|
||||
if (!r.wheelsOk) r.issues.Add($"Целых затянутых колес: {wheelsOk}/{wheelsTotal}{(bricks ? ", машина на кирпичах" : "")}");
|
||||
|
||||
// 4–5. Подкапотное пространство
|
||||
EngineBayManager bay = root.GetComponent<EngineBayManager>();
|
||||
if (diploma && bay != null)
|
||||
{
|
||||
r.engineOk = bay.IsReadyForSale(r.issues);
|
||||
r.fluidsOk = bay.AreFluidsFresh(r.issues);
|
||||
}
|
||||
else
|
||||
{
|
||||
r.engineOk = true;
|
||||
r.fluidsOk = true;
|
||||
}
|
||||
|
||||
r.score = (r.washed ? 0.12f : 0f) + (r.rustFixed ? 0.25f : 0f) + (r.bodyComplete ? 0.18f : 0f)
|
||||
+ (r.wheelsOk ? 0.15f : 0f) + (r.engineOk ? 0.18f : 0f) + (r.fluidsOk ? 0.12f : 0f);
|
||||
|
||||
// Цена: при полном восстановлении +45..75% от цены покупки, мойка +8%
|
||||
float reference = car.purchasePrice > 1f ? car.purchasePrice : car.marketValue * 0.45f;
|
||||
r.referencePrice = reference;
|
||||
int seed = Mathf.Abs((car.carTitle + car.year + car.mileageKm).GetHashCode()) % 1000;
|
||||
float fullBonus = Mathf.Lerp(0.45f, 0.75f, seed / 999f);
|
||||
float mult = Mathf.Lerp(0.72f, 1f + fullBonus, r.score * r.score);
|
||||
if (r.washed) mult *= 1.08f;
|
||||
r.salePrice = Mathf.Round(reference * mult / 10f) * 10f;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user