mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-20 05:37:11 +08:00
(client) feat:健康给予,路径优化,结算界面,商店界面 (#60)
Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com> Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/60
This commit is contained in:
@@ -1,87 +1,143 @@
|
||||
using System;
|
||||
using Configs;
|
||||
using Data;
|
||||
using Entity;
|
||||
using Managers;
|
||||
using Map;
|
||||
using UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Base
|
||||
{
|
||||
public class PlayGameSceneControl:MonoBehaviour,ITick
|
||||
public enum GameEnding
|
||||
{
|
||||
// 区域肃清
|
||||
AreaSecured,
|
||||
// 干员失联 (也可以理解为任务失败,干员失踪)
|
||||
AgentMissing,
|
||||
// 据点被毁
|
||||
BaseDestroyed
|
||||
}
|
||||
|
||||
|
||||
public class PlayGameSceneControl : MonoBehaviour, ITick
|
||||
{
|
||||
public Dimension dimensionPrefab;
|
||||
|
||||
|
||||
public WaitStartUI waitStartUI;
|
||||
|
||||
public bool AllDimensionsLoaded => OutsideDimensionsLoaded && InsideDimensionsLoaded;
|
||||
public bool OutsideDimensionsLoaded { get; private set; }
|
||||
public bool InsideDimensionsLoaded { get; private set; }
|
||||
|
||||
public DimensionDef OutsideDef{get; private set;}
|
||||
public DimensionDef InsideDef{get; private set;}
|
||||
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 Dimension OutsideDimension{get; private set;}
|
||||
public Dimension InsideDimension{get; private set;}
|
||||
public SettlementUI settlementUI;
|
||||
|
||||
private string playerAffiliation;
|
||||
|
||||
public bool TaskCompleted{get; private set;}
|
||||
public Entity.Entity playerEntity;
|
||||
|
||||
public BaseBuildingHPBarUI baseBuildingHPBarUI;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
playerAffiliation = Configs.ConfigManager.Instance.GetValue<string>("playerAffiliation");
|
||||
OutsideDef = Program.Instance.OutsidePlayDimension;
|
||||
InsideDef = Program.Instance.CurrentCharacter.insideDimensionDef ??
|
||||
DefineManager.Instance.FindDefine<DimensionDef>(
|
||||
Configs.ConfigManager.Instance.GetValue<string>("InsideDimension"));
|
||||
ConfigManager.Instance.GetValue<string>("InsideDimension"));
|
||||
if (OutsideDef == null || InsideDef == null)
|
||||
{
|
||||
MessageManager.Instance.DisplayMessage("初始化失败!检查XML文件完整性",PromptDisplayCategory.ScreenCenterLargeText,Color.brown);
|
||||
MessageManager.Instance.DisplayMessage("初始化失败!检查XML文件完整性", PromptDisplayCategory.ScreenCenterLargeText,
|
||||
Color.brown);
|
||||
Invoke(nameof(ReturnMainMenu), 3);
|
||||
return;
|
||||
}
|
||||
OutsideDimension=Instantiate(dimensionPrefab);
|
||||
|
||||
OutsideDimension = Instantiate(dimensionPrefab);
|
||||
InsideDimension = Instantiate(dimensionPrefab);
|
||||
|
||||
OutsideDimension.transform.localPosition = new Vector3(0, 0, 1);
|
||||
InsideDimension.transform.localPosition = new Vector3(0, 1000, 1);
|
||||
|
||||
|
||||
OutsideDimension.transform.localPosition = new Vector3(-0.5f, -0.5f, 1);
|
||||
InsideDimension.transform.localPosition = new Vector3(-0.5f, 999.5f, 1);
|
||||
|
||||
_ = OutsideDimension.ApplyDimensionDef(OutsideDef);
|
||||
_ = InsideDimension.ApplyDimensionDef(InsideDef);
|
||||
|
||||
OutsideDimension.OnDimensionLoaded += OutsideDimensionLoaded;
|
||||
OutsideDimension.OnDimensionLoaded += InsideDimensionLoaded;
|
||||
|
||||
|
||||
InsideDimension.OnDimensionLoaded += InsideDimensionLoaded;
|
||||
|
||||
OutsideDimension.name = "OutsideDimension";
|
||||
InsideDimension.name = "InsideDimension";
|
||||
|
||||
|
||||
Program.Instance.SetFocusedDimension(OutsideDimension.DimensionId);
|
||||
|
||||
|
||||
EntityManager.Instance.OnCreateEntity += OnCreateEntity;
|
||||
|
||||
|
||||
|
||||
Clock.AddTick(this);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
EntityManager.Instance.OnCreateEntity -= OnCreateEntity;
|
||||
|
||||
Clock.RemoveTick(this);
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
if (!AllDimensionsLoaded)
|
||||
return;
|
||||
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;
|
||||
}
|
||||
if (!AllDimensionsLoaded) return;
|
||||
waitStartUI.Hide();
|
||||
Program.Instance.PutPlayer();
|
||||
playerEntity = Program.Instance.FocusedEntity;
|
||||
playerEntity.OnEntityDiedEvent += OnPlayerDied;
|
||||
if (OutsideDef.story != null)
|
||||
{
|
||||
EventManager.Instance.PlayStory(OutsideDef.story.defName, OutsideDimension.DimensionId);
|
||||
}
|
||||
|
||||
if (InsideDef.story != null)
|
||||
{
|
||||
EventManager.Instance.PlayStory(InsideDef.story.defName, InsideDimension.DimensionId);
|
||||
}
|
||||
|
||||
Program.Instance.OnFocusedDimensionChanged += OnSwitchDimension;
|
||||
baseBuildingHPBarUI.Init();
|
||||
}
|
||||
|
||||
private void ReturnBase()
|
||||
{
|
||||
Program.Instance.ReturnBase();
|
||||
}
|
||||
|
||||
|
||||
private void ReturnMainMenu()
|
||||
{
|
||||
EscUI.ReturnMainMenu();
|
||||
@@ -98,29 +154,50 @@ namespace Base
|
||||
InsideDimensionsLoaded = true;
|
||||
StartGame();
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
|
||||
private void OnCreateEntity(Entity.Entity entity)
|
||||
{
|
||||
if(!AllDimensionsLoaded)
|
||||
if (entity is not Entity.Monster monster)
|
||||
return;
|
||||
if (EventManager.Instance.HasStoryDisplay || TaskCompleted)
|
||||
return;
|
||||
MessageManager.Instance.DisplayMessage("清理完毕!", PromptDisplayCategory.ScreenCenterLargeText,
|
||||
Color.softYellow);
|
||||
TaskCompleted = true;
|
||||
Invoke(nameof(ReturnBase), 5);
|
||||
|
||||
var player = Program.Instance.FocusedEntity as Character;
|
||||
if(!player)
|
||||
return;
|
||||
Program.Instance.CoinCount += player.Coin.Quantity;
|
||||
|
||||
if (AffiliationManager.Instance.GetRelation(playerAffiliation,
|
||||
entity.affiliation) == Relation.Hostile)
|
||||
{
|
||||
monster.OnEntityDiedEvent += OnMonsterKilled;
|
||||
}
|
||||
else if (entity.affiliation==Configs.ConfigManager.Instance.GetValue<string>("NanorobotsAffiliation"))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void ReturnBase()
|
||||
private void OnPlayerDied(Entity.Entity entity)
|
||||
{
|
||||
Program.Instance.EndPlayGame();
|
||||
SceneManager.LoadScene("Base");
|
||||
EndGame(GameEnding.AgentMissing);
|
||||
}
|
||||
|
||||
private void OnMonsterKilled(Entity.Entity entity)
|
||||
{
|
||||
monstersKilled++;
|
||||
var monster=entity as Entity.Monster;
|
||||
if (monster && monster.entityDef is MonsterDef monsterDef)
|
||||
{
|
||||
totalThreat += monsterDef.threat;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSwitchDimension(Dimension dimension)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user