DayZ 1.29
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
PluginInventoryRepair.c
См. документацию.
1// *************************************************************************************
2// ! PluginInventoryRepair
3// *************************************************************************************
4class PluginInventoryRepair extends PluginBase
5{
6 protected static float PIR_REQUEST_COOLDOWN = 5;
7 protected static float PIR_MAX_ITEMS_TO_SEND = 5;
8
11 protected float m_TimeFromLastRequest = 0;
12
18
19 bool RepairItem(EntityAI itemToRepair)
20 {
21 PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
24
25 repairIl.SetTemporary(player, itemToRepair);
26 itemToRepair.GetInventory().GetCurrentInventoryLocation(currentIl);
27
28 if(GameInventory.LocationSyncMoveEntity(currentIl, repairIl))
29 {
30 if(currentIl.GetType() == InventoryLocationType.HANDS)
31 {
32 player.OnItemInHandsChanged();
33 }
34 return true;
35 }
36 return false;
37 }
38
39 //Receive from server
41 {
42 int itemCount;
43
44 if (!ctx.Read(itemCount))
45 return;
46
47 for (int i = 0; i < itemCount; i++)
48 {
50 if (!il.ReadFromContext(ctx) )
51 return;
52
53 m_CorrectILs.Insert(il);
54 }
55 }
56
58 {
59 PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
61
62 EntityAI item = ilCorrect.GetItem();
63 EntityAI parent = ilCorrect.GetParent();
64 item.GetInventory().GetCurrentInventoryLocation(ilTemp);
65
66 switch(ilCorrect.GetType())
67 {
68 case InventoryLocationType.CARGO:
69 InventoryLocation ilCargoItem = new InventoryLocation;
70 CargoBase cargo = parent.GetInventory().GetCargo();
71 for(int i = cargo.GetItemCount() - 1; i >= 0 ; --i)
72 {
73 EntityAI itemInCargo = cargo.GetItem(i);
74 if (itemInCargo != item)
75 {
76 itemInCargo.GetInventory().GetCurrentInventoryLocation(ilCargoItem);
77 if (ilCorrect.CollidesWith(ilCargoItem))
78 {
79 if (!RepairItem(itemInCargo))
80 {
81 return false;
82 }
83 }
84 }
85 }
86 break;
87 case InventoryLocationType.ATTACHMENT:
88 EntityAI entityInAttachment = parent.GetInventory().FindAttachment(ilCorrect.GetSlot());
89
90 if(entityInAttachment)
91 {
92 if (!RepairItem(entityInAttachment))
93 {
94 return false;
95 }
96 }
97
98 break;
99 case InventoryLocationType.HANDS:
100 EntityAI entityInHands = player.GetItemInHands();
101 if(entityInHands)
102 {
103 if (!RepairItem(entityInHands))
104 {
105 return false;
106 }
107 }
108
109 break;
110 default:
111 break;
112 }
113
114 if (!GameInventory.LocationSyncMoveEntity(ilTemp, ilCorrect))
115 {
116 if (ilTemp.GetType() != InventoryLocationType.TEMP)
117 RepairItem(item);
118 return false;
119 }
120
121 return true;
122 }
123
124 override void OnUpdate(float delta_time)
125 {
126 if (m_CorrectILs.Count())
127 {
128 for (int j = m_CorrectILs.Count() - 1; j >= 0 ; j--)
129 {
131 m_CorrectILs.Remove(j);
132 }
133 }
134
135 m_TimeFromLastRequest += delta_time;
136 if(m_ItemsToRepair.Count())
137 {
138 array<EntityAI> itemsToSend = new array<EntityAI>;
140 {
141 for (int i = 0; i < m_ItemsToRepair.Count() && i < PIR_MAX_ITEMS_TO_SEND; i++ )
142 {
143 itemsToSend.Insert(m_ItemsToRepair[i]);
144 }
145
148 }
149 }
150 }
151
152 void Remove(EntityAI item)
153 {
154 m_ItemsToRepair.RemoveItem(item);
155 }
156
157 void Add(EntityAI item)
158 {
159 if (m_ItemsToRepair.Find(item) < 0)
160 {
161 m_ItemsToRepair.Insert(item);
162 }
163 }
164}
DayZGame g_Game
Определения DayZGame.c:3942
InventoryLocationType
types of Inventory Location
Определения InventoryLocation.c:4
proto native int GetItemCount()
proto native EntityAI GetItem(int index)
represents base for cargo storage for entities
Определения Cargo.c:7
static proto native bool LocationSyncMoveEntity(notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc)
synchronously removes item from current inventory location and adds it to destination no anims involv...
script counterpart to engine's class Inventory
static void SendClientInventoryCheck(array< EntityAI > items)
Определения InventoryInputUserData.c:31
proto native EntityAI GetParent()
returns parent of current inventory location
proto native void SetTemporary(notnull EntityAI parent, EntityAI e)
proto native int GetSlot()
returns slot id if current type is Attachment
proto native bool CollidesWith(notnull InventoryLocation rhs)
checks if inventory locations collides each with other
proto native int GetType()
returns type of InventoryLocation
bool ReadFromContext(ParamsReadContext ctx)
Определения InventoryLocation.c:310
proto native EntityAI GetItem()
returns item of current inventory location
InventoryLocation.
Определения InventoryLocation.c:30
Определения PlayerBaseClient.c:2
float m_TimeFromLastRequest
Определения PluginInventoryRepair.c:11
static float PIR_MAX_ITEMS_TO_SEND
Определения PluginInventoryRepair.c:7
bool MoveItemToCorrectPosition(InventoryLocation ilCorrect)
Определения PluginInventoryRepair.c:57
bool RepairItem(EntityAI itemToRepair)
Определения PluginInventoryRepair.c:19
static float PIR_REQUEST_COOLDOWN
Определения PluginInventoryRepair.c:6
void OnRPC(ParamsReadContext ctx)
Определения PluginInventoryRepair.c:40
void Add(EntityAI item)
Определения PluginInventoryRepair.c:157
void Remove(EntityAI item)
Определения PluginInventoryRepair.c:152
ref array< EntityAI > m_ItemsToRepair
Определения PluginInventoryRepair.c:9
ref array< ref InventoryLocation > m_CorrectILs
Определения PluginInventoryRepair.c:10
override void OnUpdate(float delta_time)
Определения PluginInventoryRepair.c:124
void PluginInventoryRepair()
Определения PluginInventoryRepair.c:13
Plugin interface for controlling of agent pool system.
Определения PluginBase.c:2
proto bool Read(void value_in)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Serializer ParamsReadContext
Определения gameplay.c:15