summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XChestProgress.cs
blob: f8824b84fa238e6d898ec8fe24b7333062c6a051 (plain)
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using System.Collections.Generic;
using UILib;
using UnityEngine;

namespace XMainClient
{
	internal class XChestProgress
	{
		public uint IncreaseSpeed
		{
			get
			{
				return this._IncreaseSpeed;
			}
			set
			{
				this._IncreaseSpeed = value;
			}
		}

		public List<XChest> ChestList
		{
			get
			{
				return this.m_ChestList;
			}
		}

		public uint TargetExp
		{
			set
			{
				this.m_TargetExp = value;
			}
		}

		private IXUIProgress m_Progress;

		private IXUISprite m_ProgressSprite;

		private IXUISprite m_ForegroundSprite;

		private uint m_StartExp;

		private uint m_EndExp;

		private uint m_CurrentExp;

		private uint m_TargetExp;

		private uint m_ExpRange;

		private float m_fCurrentExp;

		private uint _IncreaseSpeed = 80u;

		private List<XChest> m_ChestList = new List<XChest>();

		public XChestProgress(IXUIProgress progress)
		{
			this.m_Progress = progress;
			this.m_ProgressSprite = (progress.gameObject.GetComponent("XUISprite") as IXUISprite);
			this.m_ForegroundSprite = (progress.foreground.GetComponent("XUISprite") as IXUISprite);
		}

		public void Unload()
		{
			for (int i = 0; i < this.m_ChestList.Count; i++)
			{
				XChest xchest = this.m_ChestList[i];
				bool flag = xchest != null;
				if (flag)
				{
					xchest.ResetState();
				}
			}
			this.m_ChestList.Clear();
		}

		public void SetExp(uint start, uint end)
		{
			this.m_StartExp = start;
			this.m_EndExp = end;
			this.m_TargetExp = start;
			this.m_ExpRange = this.m_EndExp - this.m_StartExp;
			this._SetProgressBar();
			for (int i = 0; i < this.m_ChestList.Count; i++)
			{
				this.m_ChestList[i].ResetState();
			}
			this._RefreshChestState();
			this._UpdateChestPosition();
		}

		public void Update(float time)
		{
			bool flag = this.m_CurrentExp != this.m_TargetExp;
			if (flag)
			{
				bool flag2 = this.m_CurrentExp > this.m_TargetExp;
				if (flag2)
				{
					this.m_CurrentExp = this.m_TargetExp;
					this.m_fCurrentExp = this.m_CurrentExp;
				}
				else
				{
					bool flag3 = this.m_fCurrentExp < this.m_StartExp;
					if (flag3)
					{
						this.m_fCurrentExp = this.m_StartExp;
					}
					this.m_fCurrentExp += this.IncreaseSpeed * time;
					this.m_CurrentExp = (uint)this.m_fCurrentExp;
					bool flag4 = this.m_CurrentExp > this.m_TargetExp;
					if (flag4)
					{
						this.m_CurrentExp = this.m_TargetExp;
					}
				}
				this._SetProgressBar();
				this._RefreshChestState();
			}
		}

		private void _SetProgressBar()
		{
			bool flag = this.m_ExpRange > 0u;
			if (flag)
			{
				this.m_Progress.value = (this.m_CurrentExp - this.m_StartExp) / this.m_ExpRange;
			}
			else
			{
				this.m_Progress.value = 0f;
			}
		}

		public void AddChest(XChest chest)
		{
			this.m_ChestList.Add(chest);
			bool flag = this.m_ExpRange == 0u;
			if (!flag)
			{
				Vector3 position = chest.Position;
				chest.Position = new Vector3((float)this.m_ForegroundSprite.spriteWidth * (chest.m_RequiredExp - this.m_StartExp) / this.m_ExpRange, position.y, position.z);
			}
		}

		private void _UpdateChestPosition()
		{
			for (int i = 0; i < this.m_ChestList.Count; i++)
			{
				XChest xchest = this.m_ChestList[i];
				Vector3 position = xchest.Position;
				xchest.Position = new Vector3((float)this.m_ForegroundSprite.spriteWidth * (xchest.m_RequiredExp - this.m_StartExp) / this.m_ExpRange, position.y, position.z);
			}
		}

		private void _RefreshChestState()
		{
			for (int i = 0; i < this.m_ChestList.Count; i++)
			{
				this.m_ChestList[i].Update(this.m_CurrentExp);
			}
		}

		public bool IsExpEnough(int index)
		{
			bool flag = index >= 0 && index < this.m_ChestList.Count;
			return flag && this.m_ChestList[index].m_RequiredExp <= this.m_CurrentExp;
		}
	}
}