2025-10-10 14:08:23 +08:00
|
|
|
|
using Configs;
|
2025-10-03 00:31:34 +08:00
|
|
|
|
using Data;
|
|
|
|
|
|
using Managers;
|
|
|
|
|
|
using Map;
|
|
|
|
|
|
using UI;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Base
|
|
|
|
|
|
{
|
2025-10-10 14:08:23 +08:00
|
|
|
|
public enum GameEnding
|
|
|
|
|
|
{
|
|
|
|
|
|
// 区域肃清
|
|
|
|
|
|
AreaSecured,
|
|
|
|
|
|
// 干员失联 (也可以理解为任务失败,干员失踪)
|
|
|
|
|
|
AgentMissing,
|
|
|
|
|
|
// 据点被毁
|
|
|
|
|
|
BaseDestroyed
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class PlayGameSceneControl : MonoBehaviour, ITick
|
2025-10-03 00:31:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
public Dimension dimensionPrefab;
|
2025-10-10 14:08:23 +08:00
|
|
|
|
|
2025-10-03 00:31:34 +08:00
|
|
|
|
public WaitStartUI waitStartUI;
|
|
|
|
|
|
|
|
|
|
|
|
public bool AllDimensionsLoaded => OutsideDimensionsLoaded && InsideDimensionsLoaded;
|
|
|
|
|
|
public bool OutsideDimensionsLoaded { get; private set; }
|
|
|
|
|
|
public bool InsideDimensionsLoaded { get; private set; }
|
|
|
|
|
|
|
2025-10-10 14:08:23 +08:00
|
|
|
|
public DimensionDef OutsideDef { get; private set; }
|
|
|
|
|
|
public DimensionDef InsideDef { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public Dimension OutsideDimension { get; private set; }
|
|
|
|
|
|
public Dimension InsideDimension { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public bool TaskCompleted { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int totalThreat;
|
|
|
|
|
|
private int monstersKilled;
|
|
|
|
|
|
|
|
|
|
|
|
public SettlementUI settlementUI;
|
|
|
|
|
|
|
|
|
|
|
|
private string playerAffiliation;
|
2025-10-03 00:31:34 +08:00
|
|
|
|
|
2025-10-10 14:08:23 +08:00
|
|
|
|
public Entity.Entity playerEntity;
|
2025-10-03 00:31:34 +08:00
|
|
|
|
|
2025-10-10 14:08:23 +08:00
|
|
|
|
public BaseBuildingHPBarUI baseBuildingHPBarUI;
|
|
|
|
|
|
|
2025-10-03 00:31:34 +08:00
|
|
|
|
private void Start()
|
|
|
|
|
|
{
|
2025-10-10 14:08:23 +08:00
|
|
|
|
playerAffiliation = Configs.ConfigManager.Instance.GetValue<string>("playerAffiliation");
|
2025-10-03 00:31:34 +08:00
|
|
|
|
OutsideDef = Program.Instance.OutsidePlayDimension;
|
|
|
|
|
|
InsideDef = Program.Instance.CurrentCharacter.insideDimensionDef ??
|
|
|
|
|
|
DefineManager.Instance.FindDefine<DimensionDef>(
|
2025-10-10 14:08:23 +08:00
|
|
|
|
ConfigManager.Instance.GetValue<string>("InsideDimension"));
|
2025-10-03 00:31:34 +08:00
|
|
|
|
if (OutsideDef == null || InsideDef == null)
|
|
|
|
|
|
{
|
2025-10-10 14:08:23 +08:00
|
|
|
|
MessageManager.Instance.DisplayMessage("初始化失败!检查XML文件完整性", PromptDisplayCategory.ScreenCenterLargeText,
|
|
|
|
|
|
Color.brown);
|
2025-10-03 00:31:34 +08:00
|
|
|
|
Invoke(nameof(ReturnMainMenu), 3);
|
2025-10-10 14:08:23 +08:00
|
|
|
|
return;
|
2025-10-03 00:31:34 +08:00
|
|
|
|
}
|
2025-10-10 14:08:23 +08:00
|
|
|
|
|
|
|
|
|
|
OutsideDimension = Instantiate(dimensionPrefab);
|
2025-10-03 00:31:34 +08:00
|
|
|
|
InsideDimension = Instantiate(dimensionPrefab);
|
2025-10-10 14:08:23 +08:00
|
|
|
|
|
|
|
|
|
|
OutsideDimension.transform.localPosition = new Vector3(-0.5f, -0.5f, 1);
|
|
|
|
|
|
InsideDimension.transform.localPosition = new Vector3(-0.5f, 999.5f, 1);
|
|
|
|
|
|
|
2025-10-03 00:31:34 +08:00
|
|
|
|
_ = OutsideDimension.ApplyDimensionDef(OutsideDef);
|
|
|
|
|
|
_ = InsideDimension.ApplyDimensionDef(InsideDef);
|
|
|
|
|
|
|
|
|
|
|
|
OutsideDimension.OnDimensionLoaded += OutsideDimensionLoaded;
|
2025-10-10 14:08:23 +08:00
|
|
|
|
InsideDimension.OnDimensionLoaded += InsideDimensionLoaded;
|
2025-10-03 00:31:34 +08:00
|
|
|
|
|
2025-10-10 14:08:23 +08:00
|
|
|
|
OutsideDimension.name = "OutsideDimension";
|
|
|
|
|
|
InsideDimension.name = "InsideDimension";
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-10-03 00:31:34 +08:00
|
|
|
|
Program.Instance.SetFocusedDimension(OutsideDimension.DimensionId);
|
2025-10-10 14:08:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EntityManager.Instance.OnCreateEntity += OnCreateEntity;
|
2025-10-03 00:31:34 +08:00
|
|
|
|
|
2025-10-10 14:08:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-10-03 00:31:34 +08:00
|
|
|
|
Clock.AddTick(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
|
{
|
2025-10-10 14:08:23 +08:00
|
|
|
|
EntityManager.Instance.OnCreateEntity -= OnCreateEntity;
|
|
|
|
|
|
|
2025-10-03 00:31:34 +08:00
|
|
|
|
Clock.RemoveTick(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-10 14:08:23 +08:00
|
|
|
|
public void Tick()
|
2025-10-03 00:31:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (!AllDimensionsLoaded)
|
|
|
|
|
|
return;
|
2025-10-10 14:08:23 +08:00
|
|
|
|
if (EventManager.Instance.HasStoryDisplay || TaskCompleted ||
|
|
|
|
|
|
EntityManager.Instance.ExistsHostile(OutsideDimension.DimensionId,
|
|
|
|
|
|
Program.Instance.FocusedEntity.entityPrefab))
|
|
|
|
|
|
return;
|
|
|
|
|
|
EndGame(GameEnding.AreaSecured);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void EndGame(GameEnding gameEnding)
|
|
|
|
|
|
{
|
|
|
|
|
|
KeyValueArchiveManager.Instance.Set("LastGameTotalThreat", totalThreat);
|
|
|
|
|
|
KeyValueArchiveManager.Instance.Set("LastGameMonstersKilled", monstersKilled);
|
|
|
|
|
|
KeyValueArchiveManager.Instance.Set("LastGameEnding", gameEnding);
|
|
|
|
|
|
TaskCompleted = true;
|
|
|
|
|
|
UIInputControl.Instance.Show("SettlementUI");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void StartGame()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!AllDimensionsLoaded) return;
|
2025-10-03 00:31:34 +08:00
|
|
|
|
waitStartUI.Hide();
|
|
|
|
|
|
Program.Instance.PutPlayer();
|
2025-10-10 14:08:23 +08:00
|
|
|
|
playerEntity = Program.Instance.FocusedEntity;
|
|
|
|
|
|
playerEntity.OnEntityDiedEvent += OnPlayerDied;
|
2025-10-03 00:31:34 +08:00
|
|
|
|
if (OutsideDef.story != null)
|
|
|
|
|
|
EventManager.Instance.PlayStory(OutsideDef.story.defName, OutsideDimension.DimensionId);
|
|
|
|
|
|
|
|
|
|
|
|
if (InsideDef.story != null)
|
|
|
|
|
|
EventManager.Instance.PlayStory(InsideDef.story.defName, InsideDimension.DimensionId);
|
2025-10-10 14:08:23 +08:00
|
|
|
|
|
|
|
|
|
|
Program.Instance.OnFocusedDimensionChanged += OnSwitchDimension;
|
|
|
|
|
|
baseBuildingHPBarUI.Init();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ReturnBase()
|
|
|
|
|
|
{
|
|
|
|
|
|
Program.Instance.ReturnBase();
|
2025-10-03 00:31:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
private void ReturnMainMenu()
|
|
|
|
|
|
{
|
|
|
|
|
|
EscUI.ReturnMainMenu();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OutsideDimensionLoaded(Dimension dimension)
|
|
|
|
|
|
{
|
|
|
|
|
|
OutsideDimensionsLoaded = true;
|
|
|
|
|
|
StartGame();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void InsideDimensionLoaded(Dimension dimension)
|
|
|
|
|
|
{
|
|
|
|
|
|
InsideDimensionsLoaded = true;
|
|
|
|
|
|
StartGame();
|
|
|
|
|
|
}
|
2025-10-10 14:08:23 +08:00
|
|
|
|
|
|
|
|
|
|
private void OnCreateEntity(Entity.Entity entity)
|
2025-10-03 00:31:34 +08:00
|
|
|
|
{
|
2025-10-10 14:08:23 +08:00
|
|
|
|
if (entity is not Entity.Monster monster)
|
2025-10-03 00:31:34 +08:00
|
|
|
|
return;
|
2025-10-10 14:08:23 +08:00
|
|
|
|
if (AffiliationManager.Instance.GetRelation(playerAffiliation,
|
|
|
|
|
|
entity.affiliation) == Relation.Hostile)
|
|
|
|
|
|
{
|
|
|
|
|
|
monster.OnEntityDiedEvent += OnMonsterKilled;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (entity.affiliation==Configs.ConfigManager.Instance.GetValue<string>("NanorobotsAffiliation"))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-03 00:31:34 +08:00
|
|
|
|
|
2025-10-10 14:08:23 +08:00
|
|
|
|
private void OnPlayerDied(Entity.Entity entity)
|
|
|
|
|
|
{
|
|
|
|
|
|
EndGame(GameEnding.AgentMissing);
|
|
|
|
|
|
}
|
2025-10-03 00:31:34 +08:00
|
|
|
|
|
2025-10-10 14:08:23 +08:00
|
|
|
|
private void OnMonsterKilled(Entity.Entity entity)
|
|
|
|
|
|
{
|
|
|
|
|
|
monstersKilled++;
|
|
|
|
|
|
var monster=entity as Entity.Monster;
|
|
|
|
|
|
if (monster && monster.entityDef is MonsterDef monsterDef)
|
|
|
|
|
|
{
|
|
|
|
|
|
totalThreat += monsterDef.threat;
|
|
|
|
|
|
}
|
2025-10-03 00:31:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-10 14:08:23 +08:00
|
|
|
|
private void OnSwitchDimension(Dimension dimension)
|
2025-10-03 00:31:34 +08:00
|
|
|
|
{
|
2025-10-10 14:08:23 +08:00
|
|
|
|
if (dimension == OutsideDimension)
|
|
|
|
|
|
{
|
|
|
|
|
|
Program.Instance.SetFocusedEntity(playerEntity);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (dimension == InsideDimension)
|
|
|
|
|
|
{
|
|
|
|
|
|
var nanorobots = EntityManager.Instance.FindEntitiesByFaction(dimension.DimensionId,
|
|
|
|
|
|
Configs.ConfigManager.Instance.GetValue<string>("NanorobotsAffiliation"));
|
|
|
|
|
|
if (nanorobots is { Length: > 0 })
|
|
|
|
|
|
Program.Instance.SetFocusedEntity(nanorobots[0].entity);
|
|
|
|
|
|
}
|
2025-10-03 00:31:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|