DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
QuickBarBase.c
См. документацию.
2// Script File
4{
7
9 {
10 m_entity = NULL;
11 m_enabled = false;
12 }
13}
14
15class QuickBarBase
16{
18 protected PlayerBase _player;
19 protected int m_slotsCount;
20
22 {
23 for (int i = 0; i < MAX_QUICKBAR_SLOTS_COUNT; i++)
24 {
26 m_aQuickbarEnts[i].m_enabled = false;
27 m_aQuickbarEnts[i].m_entity = NULL;
28 }
29
30 _player = player;
31 m_slotsCount = 0;
32 }
33//-------------------------------------------------------------
34 void SetSize(int newSize)
35 {
36 int i = m_slotsCount;
37 if ( newSize == m_slotsCount )
38 return;
39
40 if (newSize > MAX_QUICKBAR_SLOTS_COUNT)
42
43 if ( newSize > i )
44 {
45 for (; i < newSize; i++)
46 {
47 EntityAI entity = m_aQuickbarEnts[i].m_entity;
48 if ( entity != NULL && entity.GetHierarchyRootPlayer() == _player )
49 {
50 m_aQuickbarEnts[i].m_enabled = true;
51 }
52 }
53 }
54 else
55 {
56 for (i--; i >= newSize; i--)
57 m_aQuickbarEnts[i].m_enabled = false;
58 }
59
60 m_slotsCount = newSize;
61
62 if (_player.m_Hud)
63 _player.m_Hud.RefreshQuickbar(true);
64 }
65//-------------------------------------------------------------
67 {
68 int count = 0;
69 for ( int i = 0; i < m_slotsCount; i++ )
70 {
71 if (m_aQuickbarEnts[i].m_enabled)
72 count++;
73 }
74
75 return count;
76 }
77//-------------------------------------------------------------
79 {
80 if (index < 0 || index >= m_slotsCount)
81 return NULL;
82
83 if (m_aQuickbarEnts[index].m_enabled)
84 return m_aQuickbarEnts[index].m_entity;
85
86 return NULL;
87 }
88
89//-------------------------------------------------------------
90 int GetSize()
91 {
92 return m_slotsCount;
93 }
94//-------------------------------------------------------------
96 {
97 for (int i = 0; i < MAX_QUICKBAR_SLOTS_COUNT; i++)
98 {
99 if (m_aQuickbarEnts[i].m_entity == entity)
100 return i;
101 }
102
103 return -1;
104 }
105//-------------------------------------------------------------
106 bool OnInputUserDataProcess(int userDataType, ParamsReadContext ctx)
107 {
108 if ( userDataType == INPUT_UDT_QUICKABARSHORTCUT)
109 {
111 return true;
112 }
113
114 return false;
115 }
116//-------------------------------------------------------------
118 {
119 m_aQuickbarEnts[index].m_enabled = CanAddAsShortcut(m_aQuickbarEnts[index].m_entity);
120 if (!m_aQuickbarEnts[index].m_enabled)
121 CancelContinuousUse(index);
122
123 if (_player.m_Hud)
124 _player.m_Hud.RefreshQuickbar(true);
125 }
126//-------------------------------------------------------------
127 void SetShotcutEnable(int index, bool value)
128 {
129 m_aQuickbarEnts[index].m_enabled = value && CanAddAsShortcut(m_aQuickbarEnts[index].m_entity);
130 if (!m_aQuickbarEnts[index].m_enabled)
131 CancelContinuousUse(index);
132
133 if (_player.m_Hud)
134 _player.m_Hud.RefreshQuickbar(true);
135 }
136//-------------------------------------------------------------
138 {
140 entity.GetInventory().GetCurrentInventoryLocation(loc);
141 EntityAI parent = loc.GetParent();
142
143 return (entity && entity.GetHierarchyRootPlayer() == _player && parent.CanAssignAttachmentsToQuickbar() && entity.CanAssignToQuickbar());
144 }
145//-------------------------------------------------------------
146 void SetEntityShortcut(EntityAI entity, int index, bool force = false)
147 {
148 //Client
149 if (GetGame().IsClient())
150 {
152 {
155 ctx.Write(entity);
156 ctx.Write(index);
157 ctx.Write(force);
158 ctx.Send();
159
160 _SetEntityShortcut(entity, index, force);
161 }
162 }
163 //Server
164 else if (GetGame().IsMultiplayer() && GetGame().IsServer())
165 {
167 }
168 else
169 {
170 // Single player
171 _SetEntityShortcut(entity,index,force);
172 }
173 }
174//-------------------------------------------------------------
175 void OnSetEntityNoSync(EntityAI entity, int index, bool force = false )
176 {
177 _SetEntityShortcut(entity, index, force);
178 }
179//-------------------------------------------------------------
182 {
183 Param2<Entity,int> param;
184 if (!ctx.Read(param))
185 return;
186
187 EntityAI entity1 = EntityAI.Cast(param.param1);
188 _SetEntityShortcut(entity1, param.param2, false);
189 }
190//-------------------------------------------------------------
193 {
194 EntityAI eai = null;
195 if (!ctx.Read(eai))
196 return;
197
198 int index = -1;
199 if (!ctx.Read(index))
200 return;
201
202 bool force = false;
203 if (!ctx.Read(force))
204 return
205
206 _SetEntityShortcut(eai, index, force);
207 }
208//-------------------------------------------------------------
209 protected void _SetEntityShortcut(EntityAI entity, int index, bool force = false)
210 {
211 //TODO Check, if is in inventory
212 //if(entity.GetLoca)
213 if ( entity == NULL )
214 {
215 _RemoveEntity(index);
216 return;
217 }
218
219 int i = FindEntityIndex(entity);
220
221 if ( i != -1 )
222 _RemoveEntity(i);
223
224 _RemoveEntity(index);
225 _SetEntity( entity, index, force);
226 }
227//-------------------------------------------------------------
229 {
230 int slotsCount = _player.GetQuickBarBonus();
231 int attCount = _player.GetInventory().AttachmentCount();
232
233 for ( int i = 0; i < attCount; ++i)
234 {
235 slotsCount += _player.GetInventory().GetAttachmentFromIndex(i).GetQuickBarBonus();
236 }
237
238 //max slots is 10
239 SetSize(Math.Min(slotsCount, 10));
240 }
241//-------------------------------------------------------------
242 protected void _RemoveEntity(int index)
243 {
244 if ( index >= 0 && index < MAX_QUICKBAR_SLOTS_COUNT )
245 {
246 CancelContinuousUse(index);
247
248 m_aQuickbarEnts[index].m_entity = NULL;
249 m_aQuickbarEnts[index].m_enabled = false;
250
251 if (_player.m_Hud)
252 _player.m_Hud.RefreshQuickbar(true);
253 }
254 }
255//-------------------------------------------------------------
256 protected void _SetEntity( EntityAI entity, int index, bool force = false)
257 {
258 if ( index >= 0 && index < MAX_QUICKBAR_SLOTS_COUNT )
259 {
260 if ( CanAddAsShortcut(entity) )
261 {
262 m_aQuickbarEnts[index].m_entity = entity;
263 m_aQuickbarEnts[index].m_enabled = true;
264 }
265 else
266 {
267 CancelContinuousUse(index);
268 m_aQuickbarEnts[index].m_enabled = false;
269 }
270
271 if (_player.m_Hud)
272 _player.m_Hud.RefreshQuickbar(true);
273 }
274 }
275//-------------------------------------------------------------
277 {
278
279 }
280//-------------------------------------------------------------
281 protected void CancelContinuousUse(int index)
282 {
283 if (_player.m_QuickBarHold)
284 {
285 HumanInputController hic = _player.GetInputController();
286 if (hic && hic.IsQuickBarSlot() == index + 1)
287 _player.OnQuickBarContinuousUseEnd(index + 1);
288 }
289 }
290}
const int INPUT_UDT_QUICKABARSHORTCUT
Определения _constants.c:5
bool OnInputUserDataProcess(int userDataType, ParamsReadContext ctx)
Определения EmoteManager.c:500
void _RemoveEntity(int index)
Определения QuickBarBase.c:242
void QuickBarBase(PlayerBase player)
Определения QuickBarBase.c:21
void OnSetEntityRequest(ParamsReadContext ctx)
Reaction on SetEntityShortcut from client.
Определения QuickBarBase.c:192
class QuickBarItem m_aQuickbarEnts[MAX_QUICKBAR_SLOTS_COUNT]
PlayerBase _player
Определения QuickBarBase.c:18
EntityAI GetEntity(int index)
Определения QuickBarBase.c:78
void _SetEntity(EntityAI entity, int index, bool force=false)
Определения QuickBarBase.c:256
void ~QuickBarBase()
Определения QuickBarBase.c:276
void OnSetEntityRPC(ParamsReadContext ctx)
Reaction on Rpc from server for set inicial state for quickbar.
Определения QuickBarBase.c:181
void _SetEntityShortcut(EntityAI entity, int index, bool force=false)
Определения QuickBarBase.c:209
void SetEntityShortcut(EntityAI entity, int index, bool force=false)
Определения QuickBarBase.c:146
void OnSetEntityNoSync(EntityAI entity, int index, bool force=false)
Определения QuickBarBase.c:175
void updateSlotsCount()
Определения QuickBarBase.c:228
int m_slotsCount
Определения QuickBarBase.c:19
const int MAX_QUICKBAR_SLOTS_COUNT
Определения QuickBarBase.c:1
void CancelContinuousUse(int index)
Определения QuickBarBase.c:281
bool CanAddAsShortcut(EntityAI entity)
Определения QuickBarBase.c:137
int GetNonEmptyCount()
Определения QuickBarBase.c:66
void SetShotcutEnable(int index, bool value)
Определения QuickBarBase.c:127
void UpdateShotcutVisibility(int index)
Определения QuickBarBase.c:117
int GetSize()
Определения QuickBarBase.c:90
int FindEntityIndex(EntityAI entity)
Определения QuickBarBase.c:95
static void SendQuickbarSetShortcut(DayZPlayer pPlayer, EntityAI item, int index, bool force=false)
Определения DayZPlayerSyncJunctures.c:325
Определения Building.c:6
proto native int IsQuickBarSlot()
returns 1..10 if some quickbar slot is used, 0 otherwise
Определения human.c:18
proto native EntityAI GetParent()
returns parent of current inventory location
InventoryLocation.
Определения InventoryLocation.c:29
Определения EnMath.c:7
Определения PPEConstants.c:68
Определения PlayerBaseClient.c:2
EntityAI m_entity
Определения QuickBarBase.c:5
bool m_enabled
Определения QuickBarBase.c:6
void QuickBarItem()
Определения QuickBarBase.c:8
Определения QuickBarBase.c:4
proto native void Send()
proto static native bool CanStoreInputUserData()
Returns true when the channel is free, AND the InputBuffer is NOT full (same as '!...
Определения gameplay.c:121
proto bool Write(void value_out)
proto bool Read(void value_in)
Serializer ParamsReadContext
Определения gameplay.c:15
proto native CGame GetGame()
static proto float Min(float x, float y)
Returns smaller of two given values.
proto native void SetSize(float w, float h, bool immedUpdate=true)