using Core.Health;
|
using TowerDefense.Agents;
|
using TowerDefense.Level;
|
using UnityEngine;
|
using KTGMGemClient;
|
using System.Collections.Generic;
|
using Core.Utilities;
|
using DG.Tweening;
|
|
namespace TowerDefense.Economy
|
{
|
/// <summary>
|
/// A class that adds money to the currency when the attached DamagableBehaviour dies
|
/// 每一个Agent都会有一个LootDrop类,对应的DamageableBehaviour分别派生自:
|
/// Agent--Targetable--DamageableBehaviour
|
/// </summary>
|
[RequireComponent(typeof(DamageableBehaviour))]
|
public class LootDrop : MonoBehaviour
|
{
|
/// <summary>
|
/// The amount of loot/currency dropped when object "dies"
|
/// </summary>
|
public int lootDropped = 1;
|
|
/// <summary>
|
/// The attached DamagableBehaviour
|
/// </summary>
|
protected DamageableBehaviour m_DamageableBehaviour;
|
|
/// <summary>
|
/// Caches attached DamageableBehaviour
|
/// </summary>
|
protected virtual void OnEnable()
|
{
|
if (m_DamageableBehaviour == null)
|
{
|
m_DamageableBehaviour = GetComponent<DamageableBehaviour>();
|
}
|
m_DamageableBehaviour.configuration.died += OnDeath;
|
}
|
|
/// <summary>
|
/// Unsubscribed from the <see cref="m_DamageableBehaviour"/> died event
|
/// </summary>
|
protected virtual void OnDisable()
|
{
|
m_DamageableBehaviour.configuration.died -= OnDeath;
|
}
|
|
/// <summary>
|
/// The callback for when the attached object "dies".
|
/// Add <see cref="lootDropped"/> to current currency
|
/// </summary>
|
protected virtual void OnDeath(HealthChangeInfo info)
|
{
|
m_DamageableBehaviour.configuration.died -= OnDeath;
|
|
if (LevelManager.instanceExists)
|
{
|
// 当前LootDrop所在的Agent死亡后,给全局的CurrencyManager增加金币.
|
// 当前Agent死亡之后,需要在对手盘加入新的Agent
|
LevelManager levelManager = LevelManager.instance;
|
OpponentMgr opmgr = OpponentMgr.instance;
|
if (levelManager == null)
|
return;
|
Agent agent = gameObject.GetComponent<Agent>();
|
if ((agent != null) && agent.opponentAgent)
|
{
|
if (opmgr == null)
|
{
|
return;
|
}
|
opmgr.currency.AddCurrency(lootDropped);
|
/* 修改为不再死亡后发布怪物到对方视野.
|
if( agent.bRespawn)
|
{
|
AgentSetData sd = agent.mAgentData;
|
int attid = OpponentMgr.instance.GetTowerAttID(agent.waveLineID);
|
levelManager.waveManager.SpawnAgent(agent.waveLineID,sd.hp,sd.speed, attid );
|
}*/
|
}
|
else
|
{
|
levelManager.currency.AddCurrency(lootDropped);
|
/*
|
if (agent.bRespawn)
|
{
|
AgentSetData sd = agent.mAgentData;
|
int attid = levelManager.GetTowerAttID(agent.waveLineID);
|
opmgr.m_WaveManager.SpawnAgent(agent.waveLineID, sd.hp,sd.speed, attid );
|
}*/
|
}
|
}
|
else if (EndlessLevelManager.instanceExists)
|
{
|
Agent agent = gameObject.GetComponent<Agent>();
|
|
if (agent != null)
|
{
|
EndlessLevelManager.instance.Currency.AddCurrency(lootDropped);
|
PlayDropGold(lootDropped, agent.position);
|
|
// 处理掉落
|
int tunel = agent.waveLineID + 1;
|
|
List<reward> rewardList = EndlessPortData.GetDropRewardList(EndlessLevelManager.instance.CurrentLevel,
|
EndlessLevelManager.instance.WaveManager.CurrentWaveIndex + 1, tunel);
|
|
if (rewardList.Count > 0)
|
EndlessDropManager.instance.AddDrop(rewardList, gameObject.transform.position);
|
}
|
}
|
}
|
|
private void PlayDropGold(int lootDropped, Vector3 worldPos)
|
{
|
GameObject mainUI = GameObject.Find("MainUI");
|
GameObject dropGoldPrefab = Resources.Load<GameObject>("Prefabs/DropGold");
|
GameObject obj = Poolable.TryGetPoolable(dropGoldPrefab);
|
|
DropGold dropGold = obj.GetComponent<DropGold>();
|
dropGold.SetDrop(lootDropped);
|
|
obj.GetComponent<Transform>().SetParent(GameObject.Find("MainUI").GetComponent<Transform>(), false);
|
Camera camera = GameObject.Find("SceneCamera3D").GetComponent<Camera>();
|
Vector3 screenPos = camera.WorldToScreenPoint(worldPos);
|
screenPos.z = 0;
|
obj.transform.position = screenPos;
|
obj.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f);
|
float preY = obj.transform.position.y;
|
CanvasGroup canvasGroup = obj.GetComponent<CanvasGroup>();
|
|
Sequence sequence = DOTween.Sequence();
|
sequence.Append(DOTween.To(
|
() => obj.transform.position.y,
|
(float v) =>
|
{
|
Vector3 pos = obj.transform.position;
|
pos.y = v;
|
obj.transform.position = pos;
|
}, preY + 45, 0.2f)
|
.SetEase(Ease.OutCubic));
|
sequence.Append(DOTween.To(
|
() => canvasGroup.alpha,
|
(float v) =>
|
{
|
canvasGroup.alpha = v;
|
}, 0, 0.8f).SetDelay(0.5f));
|
sequence.AppendCallback(() =>
|
{
|
canvasGroup.alpha = 1;
|
Poolable.TryPool(obj);
|
});
|
}
|
}
|
}
|