You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
3.4 KiB
126 lines
3.4 KiB
using UnityEngine;
|
|
|
|
using static BattleMgr;
|
|
|
|
public class DeepCaveDungeon : GameMod
|
|
{
|
|
[SerializeField] DeepCaveDungeonView view;
|
|
|
|
BattleMgr battleMgr => BattleMgr.Instance;
|
|
float modElapsedTime;
|
|
|
|
IVCharacter player;
|
|
Character boss;
|
|
|
|
public DeepCaveDungeonData Data { get; private set; }
|
|
public Character Boss => boss;
|
|
public float ModRemainingTime => Mathf.Max(Data.LimitTime - modElapsedTime, 0f);
|
|
|
|
protected override void OnInitialize()
|
|
{
|
|
if(GameModDataGroup.Instance.TryGetModData(ModID, out DeepCaveDungeonData modData))
|
|
{
|
|
Data = modData;
|
|
}
|
|
|
|
Debug.Assert(Data != null, Logger.LogMessage(LogType.Assert, nameof(Data), "Data is null"));
|
|
}
|
|
|
|
protected override void OnStartMod()
|
|
{
|
|
//Summon player
|
|
player = battleMgr.GetPlayer();
|
|
|
|
var buffMgr = BuffMgr.Instance;
|
|
player.ResetDebuff();
|
|
player.SetStatus(
|
|
buffMgr.GetCharAtk(),
|
|
buffMgr.GetCharHp(),
|
|
buffMgr.GetCharCrtDam(),
|
|
buffMgr.GetCharCrtRate(),
|
|
buffMgr.GetCharMov(),
|
|
buffMgr.GetCharSpd(),
|
|
GameProperty.Instance.PlayerCharacterAttackRange);
|
|
//TODO : set player position
|
|
|
|
player.Summon();
|
|
battleMgr.SetPetsSummonState(true);
|
|
battleMgr.SetGudiansSummonState(true);
|
|
|
|
battleMgr.ShowTalkBox(TalkType.Summon);
|
|
|
|
SpawnBoss();
|
|
modElapsedTime = 0f;
|
|
|
|
//Set UI
|
|
GameUIMgr.OnOffStageInfo(false);
|
|
|
|
view?.SetDungeon(this);
|
|
view?.Show();
|
|
}
|
|
|
|
protected override void OnUpdate()
|
|
{
|
|
if (BattleMgr.Instance.BattlePause) return;
|
|
|
|
modElapsedTime += Time.deltaTime;
|
|
|
|
if (modElapsedTime >= Data.LimitTime)
|
|
{
|
|
battleMgr.ShowTalkBox(TalkType.Die);
|
|
FireOnDone(Result.Timeout);
|
|
}
|
|
else
|
|
{
|
|
if(boss.CurrentHp <= 0)
|
|
{
|
|
battleMgr.ShowTalkBox(TalkType.Attack);
|
|
battleMgr.UnregistBattleEntities(boss);
|
|
Data.SetLevel(Data.Level + 1);
|
|
|
|
Data.TryGetReward((totalReward, result) =>
|
|
{
|
|
if (!result) return;
|
|
|
|
GameUIMgr.SOpenPopupGoods(totalReward);
|
|
|
|
Data.EnterTicketCount--;
|
|
GameUIMgr.RefreshDeepCaveDungeonTicket();
|
|
});
|
|
|
|
FireOnDone(Result.Success);
|
|
}
|
|
else if(player.IsDead)
|
|
{
|
|
battleMgr.ShowTalkBox(TalkType.Die);
|
|
FireOnDone(Result.Dead);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SpawnBoss()
|
|
{
|
|
boss = Instantiate(Data.BossData.Prefab);
|
|
boss.SetData(Data.BossData);
|
|
boss.AddTags(EntityTag.Enemy);
|
|
boss.SetTargetTags(LayerMask.GetMask(GameProperty.Instance.CharacterLayerName), EntityTag.Player);
|
|
boss.Spawn(Vector2.zero);
|
|
boss.ChangeLookDirection(player.transform);
|
|
boss.OnDisposed += (obj) => Destroy(boss.gameObject);
|
|
battleMgr.RegistBattleEntities(boss);
|
|
}
|
|
|
|
protected override void OnEndMod()
|
|
{
|
|
view?.Hide();
|
|
|
|
GameUIMgr.OnOffStageInfo(true);
|
|
|
|
// if dragon is not dead, this is called by timeout or other reason
|
|
if(!boss.IsDead)
|
|
{
|
|
battleMgr.UnregistBattleEntities(boss);
|
|
CoroutineHandler.Instance.DelayCall(1f, boss.Dispose);
|
|
}
|
|
}
|
|
}
|