River Jiang
2020-10-21 16072ec5c78cf2f183ef5cbdddeb34416225a9ea
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using Core.Health;
using TowerDefense.Agents;
using TowerDefense.Level;
using UnityEngine;
 
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;
 
            // 
            // 当前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 );
                }*/
            }
 
        }
    }
}