少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    [XLua.Hotfix]
    public class GatherSoulBuildBehaviour : MonoBehaviour
    {
        [SerializeField] RectTransform m_AttackDefend;
        [SerializeField] Button m_BuildAttackDefend;
        [SerializeField] RectTransform m_IceDefend;
        [SerializeField] Button m_BuildIceDefend;
        [SerializeField] UIEffect m_AttackEffect;
        [SerializeField] UIEffect m_IceEffect;
 
        int collectNpcId = 0;
        uint serverInstanceId = 0;
        int buildNpcId = 0;
 
        static bool m_SatisfyBuild = false;
        public static event Action defendBuildRefresh;
        public static bool satisfyBuild
        {
            get { return m_SatisfyBuild; }
            set
            {
                m_SatisfyBuild = value;
                if (defendBuildRefresh != null)
                {
                    defendBuildRefresh();
                }
            }
        }
 
        bool isCollecting
        {
            get
            {
                return WindowCenter.Instance.IsOpen<NormalCollectWin>();
            }
        }
 
        GatherSoulDungeonModel model
        {
            get { return ModelCenter.Instance.GetModel<GatherSoulDungeonModel>(); }
        }
 
        private void Awake()
        {
            m_BuildAttackDefend.AddListener(BuildAttackDefend);
            m_BuildIceDefend.AddListener(BuildIceDefend);
        }
 
        public void Display(int npcId,uint sid)
        {
            collectNpcId = npcId;
            serverInstanceId = sid;
 
            model.missionHelpUpdate -= MissionHelpUpdate;
            model.missionHelpUpdate += MissionHelpUpdate;
            WindowCenter.Instance.windowAfterOpenEvent -= WindowAfterOpenEvent;
            WindowCenter.Instance.windowAfterCloseEvent -= WindowAfterCloseEvent;
            WindowCenter.Instance.windowAfterOpenEvent += WindowAfterOpenEvent;
            WindowCenter.Instance.windowAfterCloseEvent += WindowAfterCloseEvent;
            DisplayBase();
            DisplayEffect();
        }
 
        public void Dispose()
        {
            model.missionHelpUpdate -= MissionHelpUpdate;
            WindowCenter.Instance.windowAfterOpenEvent -= WindowAfterOpenEvent;
            WindowCenter.Instance.windowAfterCloseEvent -= WindowAfterCloseEvent;
            collectNpcId = 0;
            serverInstanceId = 0;
            satisfyBuild = false;
        }
 
        void DisplayBase()
        {
            var attackDefendCount = model.GetDefendNpcCount(model.attckDefendNpcId);
            var iceDefendCount = model.GetDefendNpcCount(model.iceDefendNpcId);
            m_AttackDefend.gameObject.SetActive(attackDefendCount < model.attackDefendCountLimit);
            m_IceDefend.gameObject.SetActive(iceDefendCount < model.iceDefendCountLimit);
 
            satisfyBuild = iceDefendCount < model.iceDefendCountLimit || attackDefendCount < model.attackDefendCountLimit;
        }
 
        void DisplayEffect()
        {
            m_AttackEffect.StopImediatly();
            m_IceEffect.StopImediatly();
            if (isCollecting)
            {
                if (buildNpcId == model.attckDefendNpcId)
                {
                    m_AttackEffect.Play();
                }
                else if (buildNpcId == model.iceDefendNpcId)
                {
                    m_IceEffect.Play();
                }
            }
        }
 
        private void WindowAfterOpenEvent(Window window)
        {
            DisplayEffect();
        }
 
        private void WindowAfterCloseEvent(Window window)
        {
            DisplayEffect();
        }
 
        private void BuildAttackDefend()
        {
            if (isCollecting)
            {
                return;
            }
            if (collectNpcId != 0 && serverInstanceId != 0)
            {
                CA508_tagCMDoFBAction pak = new CA508_tagCMDoFBAction();
                pak.ActionType = 0;
                pak.ActionInfo = (uint)model.attckDefendNpcId;
                GameNetSystem.Instance.SendInfo(pak);
                buildNpcId = model.attckDefendNpcId;
                NPCInteractProcessor.InvokeEvent(E_NpcType.Collect, collectNpcId, serverInstanceId);
            }
        }
 
        private void BuildIceDefend()
        {
            if (isCollecting)
            {
                return;
            }
            if (collectNpcId != 0 && serverInstanceId != 0)
            {
                CA508_tagCMDoFBAction pak = new CA508_tagCMDoFBAction();
                pak.ActionType = 0;
                pak.ActionInfo = (uint)model.iceDefendNpcId;
                GameNetSystem.Instance.SendInfo(pak);
                buildNpcId = model.iceDefendNpcId;
                NPCInteractProcessor.InvokeEvent(E_NpcType.Collect, collectNpcId, serverInstanceId);
            }
        }
 
        private void MissionHelpUpdate()
        {
            DisplayBase();
        }
    }
}