238 lines
7.8 KiB
C#
238 lines
7.8 KiB
C#
using Assets.MyGame.Scripts.Net.APIResponses.Enum;
|
||
using Assets.MyGame.Scripts.Net.WebResponses;
|
||
using DG.Tweening;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.AddressableAssets;
|
||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||
using static MonsterMoveLine;
|
||
using Random = UnityEngine.Random;
|
||
|
||
public class MonsterControl_BossBase : MonsterContral
|
||
{
|
||
// ==================== 基础 ====================
|
||
public string bossName;
|
||
|
||
// ==================== 爆奖 ====================
|
||
[Header("爆奖")]
|
||
public bool isToUI = true; // 爆奖特效是 UI(RectTransform)还是 3D 场景物体
|
||
public LayeredPool layeredPool;
|
||
public TextMeshProUGUI tMP_CurrBossScore; // Boss 分数显示文本
|
||
public long currBossScoreValue; // 当前滚动分数
|
||
public long bossScoreValue; // 累计总分
|
||
public int poolNum; // 奖池金币
|
||
public int prizeCount = 8; // 爆奖红包数量
|
||
public Action<int> JiaFen; // 加分回调
|
||
public List<List<RedPacketRecord>> redPacketRecords = new List<List<RedPacketRecord>>();
|
||
public Camera ZhuCam;
|
||
|
||
// ==================== 死亡 ====================
|
||
public bool isDieFish;
|
||
public float dieTime = 3f;
|
||
public Vector3 v3; // 分数飞出目标位置(Inspector 设置)
|
||
private long _turretNum;
|
||
private bool _isJia;
|
||
|
||
// ==================== Unity 生命周期 ====================
|
||
|
||
public override void Awake()
|
||
{
|
||
base.Awake();
|
||
//isRotate = false;
|
||
ZhuCam = GameManager.Instance.ZhuCam;
|
||
action_effect_DieAward = obj =>
|
||
{
|
||
tMP_CurrBossScore = obj.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
|
||
};
|
||
}
|
||
|
||
public override void OnEnable()
|
||
{
|
||
base.OnEnable();
|
||
layeredPool = null;
|
||
currBossScoreValue = 0;
|
||
bossScoreValue = 0;
|
||
redPacketRecords.Clear();
|
||
_isJia = false;
|
||
isDieFish = false;
|
||
|
||
var res = FishResourcesData.fishResourcesDatasDic[fishTypeID];
|
||
if (res.showAudio != null && res.showAudio.Count > 0)
|
||
AudioManager.Instance.PlayerFX(res.showAudio[Random.Range(0, res.showAudio.Count)]);
|
||
}
|
||
|
||
public override void OnDisable()
|
||
{
|
||
base.OnDisable();
|
||
if (isDieFish)
|
||
GameManager.Instance.StartCoroutine(YanChiDie());
|
||
}
|
||
|
||
// ==================== 初始化 ====================
|
||
|
||
public async override void Init(string pathId, float time, bool isyuzhen = false, string yzID = "")
|
||
{
|
||
isyz = isyuzhen;
|
||
this.yzID = yzID;
|
||
|
||
// Boss 进场播报
|
||
if (GameManager.Instance.gameData.currGameType == GameType.XJMH)
|
||
{
|
||
var handle = Addressables.LoadAssetAsync<Sprite>($"Assets/Art/XJMH/pw/pw_sprite/handbook/{bossName}.png");
|
||
await handle.Task;
|
||
CreateFishManager.Instance.currGameType.subUIManager.ShowBoardBoss(handle.Result, bossName);
|
||
}
|
||
|
||
|
||
if (isMove)
|
||
{
|
||
var bezierData = MonsterMoveLine.dic_BezierCurveDatas[bossName + pathId];
|
||
monsterData.moveLine.Init(bezierData, time);
|
||
|
||
}
|
||
else
|
||
{
|
||
transform.position = new Vector3(0, 0, 0);
|
||
|
||
}
|
||
}
|
||
|
||
// ==================== 爆奖(公共) ====================
|
||
|
||
/// <summary>确保分数显示文本存在(自动创建)</summary>
|
||
private void EnsureScorePanel()
|
||
{
|
||
if (tMP_CurrBossScore != null) return;
|
||
var prefab = CreateFishManager.Instance.dieFXPrefabAwardTmp;
|
||
if (prefab == null) return;
|
||
var parent = CreateFishManager.Instance.currGameType.subPanelParent;
|
||
if (parent == null) return;
|
||
|
||
tMP_CurrBossScore = Instantiate(prefab, parent)
|
||
.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
|
||
}
|
||
|
||
/// <summary>初始化红包分层对象池</summary>
|
||
private void EnsureLayeredPool()
|
||
{
|
||
if (layeredPool == null)
|
||
layeredPool = new LayeredPool(poolNum, prizeCount);
|
||
}
|
||
|
||
/// <summary>爆奖:随机红包(min~max 个)</summary>
|
||
public void BigPrize(int min = 4, int max = 8)
|
||
{
|
||
EnsureScorePanel();
|
||
EnsureLayeredPool();
|
||
|
||
var records = layeredPool.BossGlodCoinRandrom(tMP_CurrBossScore.transform.position, min, max);
|
||
AddRedPacket(records);
|
||
}
|
||
|
||
/// <summary>爆奖:固定数量红包</summary>
|
||
public void BigPrizeNotFish(int count)
|
||
{
|
||
EnsureScorePanel();
|
||
EnsureLayeredPool();
|
||
|
||
var records = layeredPool.BossGlodCoinNotFish(count);
|
||
AddRedPacket(records);
|
||
}
|
||
|
||
/// <summary>爆奖:全屏小鱼数量红包</summary>
|
||
public void BigPrizeAll()
|
||
{
|
||
int smallFishCount = CreateFishManager.Instance.fishDatas_hashCodekey_Small.Count;
|
||
prizeCount = 1;
|
||
EnsureScorePanel();
|
||
EnsureLayeredPool();
|
||
|
||
var records = layeredPool.BossGlodCoin(smallFishCount, tMP_CurrBossScore.transform.position);
|
||
AddRedPacket(records);
|
||
}
|
||
|
||
/// <summary>记录红包并开始分数滚动 + 加分</summary>
|
||
private void AddRedPacket(List<RedPacketRecord> records)
|
||
{
|
||
redPacketRecords.Add(records);
|
||
foreach (var r in records)
|
||
bossScoreValue += r.Amount;
|
||
|
||
_turretNum = CreateFishManager.Instance.currGameType.currSitData.consumeGoldNum;
|
||
GameManager.Instance.StartCoroutine(ShowBigPrize());
|
||
GameManager.Instance.StartCoroutine(JiaFenRoutine());
|
||
}
|
||
|
||
// ==================== 分数滚动 ====================
|
||
|
||
private IEnumerator ShowBigPrize()
|
||
{
|
||
if (_isJia) yield break;
|
||
_isJia = true;
|
||
|
||
yield return new WaitForSeconds(1f);
|
||
_turretNum = Random.Range((int)(_turretNum / 2), (int)_turretNum + 1);
|
||
|
||
while (currBossScoreValue < bossScoreValue)
|
||
{
|
||
currBossScoreValue += _turretNum;
|
||
if (currBossScoreValue > bossScoreValue)
|
||
currBossScoreValue = bossScoreValue;
|
||
tMP_CurrBossScore.text = currBossScoreValue.ToString();
|
||
yield return null;
|
||
}
|
||
_isJia = false;
|
||
}
|
||
|
||
private IEnumerator JiaFenRoutine()
|
||
{
|
||
yield return new WaitForSeconds(1.5f);
|
||
|
||
Transform parent = tMP_CurrBossScore.transform.parent;
|
||
GameObject addScorePrefab = CreateFishManager.Instance.dieFXPrefabAwardTmp_AddScore;
|
||
|
||
var records = redPacketRecords[0];
|
||
redPacketRecords.RemoveAt(0);
|
||
|
||
foreach (var item in records)
|
||
{
|
||
yield return new WaitForSeconds(0.15f);
|
||
var inst = Instantiate(addScorePrefab, parent.position + Vector3.up * 60, Quaternion.identity, parent);
|
||
inst.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = CoinScript.NumAdd(item.Amount.ToString());
|
||
AudioManager.Instance.PlayerFX(61009);
|
||
}
|
||
}
|
||
|
||
// ==================== 死亡 ====================
|
||
|
||
public override void DieFish(RoomKillNotice obj = null)
|
||
{
|
||
isDieFish = true;
|
||
GameManager.Instance.cameraShake.ShakePresets.Explosion2D(3f, 4f, 1f);
|
||
|
||
if (obj != null)
|
||
poolNum = obj.gold;
|
||
|
||
var res = FishResourcesData.fishResourcesDatasDic[fishTypeID];
|
||
if (res.dieAudio != null && res.dieAudio.Count > 0)
|
||
AudioManager.Instance.PlayerFX(res.dieAudio[Random.Range(0, res.dieAudio.Count)]);
|
||
}
|
||
|
||
/// <summary>死亡后延迟飞分到座位</summary>
|
||
private IEnumerator YanChiDie()
|
||
{
|
||
yield return new WaitForSeconds(dieTime);
|
||
|
||
tMP_CurrBossScore.transform.parent
|
||
.DOMove(v3, 0.5f)
|
||
.OnComplete(() =>
|
||
{
|
||
JiaFen?.Invoke(0);
|
||
Destroy(tMP_CurrBossScore.transform.parent.gameObject);
|
||
});
|
||
}
|
||
}
|