File size: 10,138 Bytes
24b81cb |
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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
class ConstructionActionData
{
Object m_Target;
//base building
ref array<ConstructionPart> m_BuildParts;
ref array<ConstructionPart> m_BuildPartsNoTool;
int m_PartIndex; //used on client only, action synchronizes it to server to avoid mismatch
string m_MainPartName;
string m_MainPartNameNoTool;
ref ConstructionPart m_TargetPart;
//combination lock
CombinationLock m_CombinationLock;
//attaching
int m_SlotId;
PlayerBase m_ActionInitiator;
//detaching
ref array<EntityAI> m_Attachments;
protected ActionVariantManager m_ActionVariantManager;
protected ActionVariantManager m_ActionNoToolVariantManager;
int m_AttachmentsIndex;
void ConstructionActionData()
{
m_BuildParts = new ref array<ConstructionPart>;
m_BuildPartsNoTool = new ref array<ConstructionPart>;
m_PartIndex = 0;
m_Attachments = new ref array<EntityAI>;
m_AttachmentsIndex = 0;
if ( GetGame().IsClient() || !GetGame().IsMultiplayer() )
{
m_ActionVariantManager = ActionManagerClient.GetVariantManager( ActionBuildPart );
m_ActionVariantManager.GetOnUpdateInvoker().Clear();
m_ActionVariantManager.GetOnUpdateInvoker().Insert(OnUpdateActions);
m_ActionNoToolVariantManager = ActionManagerClient.GetVariantManager( ActionBuildShelter );
m_ActionNoToolVariantManager.GetOnUpdateInvoker().Clear();
m_ActionNoToolVariantManager.GetOnUpdateInvoker().Insert(OnUpdateActionsNoTool);
}
}
//************************************************/
// Base building
//************************************************/
string GetMainPartName()
{
return m_MainPartName;
}
string GetMainPartNameNoTool()
{
return m_MainPartNameNoTool;
}
void SetTarget( Object target )
{
m_Target = target;
}
Object GetTarget()
{
return m_Target;
}
void SetTargetPart( ConstructionPart target_part )
{
m_TargetPart = target_part;
}
ConstructionPart GetTargetPart()
{
return m_TargetPart;
}
void SetSlotId( int slot_id )
{
m_SlotId = slot_id;
}
int GetSlotId()
{
return m_SlotId;
}
void SetActionInitiator( PlayerBase action_initiator )
{
m_ActionInitiator = action_initiator;
}
PlayerBase GetActionInitiator()
{
return m_ActionInitiator;
}
// deprecated
void SetNextIndex()
{
}
// deprecated
void RefreshPartsToBuild( string main_part_name, ItemBase tool, bool use_tool = true )
{
}
void OnUpdateActions( Object item, Object target, int component_index )
{
ItemBase tool = ItemBase.Cast( item );
if ( tool )
{
BaseBuildingBase base_building_object = BaseBuildingBase.Cast( target );
if ( base_building_object )
{
string main_part_name = target.GetActionComponentName( component_index );
base_building_object.GetConstruction().GetConstructionPartsToBuild( main_part_name, m_BuildParts, tool, m_MainPartName, true );
m_ActionVariantManager.SetActionVariantCount(m_BuildParts.Count());
}
else
{
m_BuildParts.Clear();
m_ActionVariantManager.Clear();
}
}
else
{
m_BuildParts.Clear();
m_ActionVariantManager.Clear();
}
//not needed
//m_Target = target;
}
void OnUpdateActionsNoTool( Object item, Object target, int component_index )
{
BaseBuildingBase base_building_object = BaseBuildingBase.Cast( target );
if ( base_building_object )
{
string main_part_name = target.GetActionComponentName( component_index );
base_building_object.GetConstruction().GetConstructionPartsToBuild( main_part_name, m_BuildPartsNoTool, null, m_MainPartNameNoTool, false );
m_ActionNoToolVariantManager.SetActionVariantCount(m_BuildPartsNoTool.Count());
}
else
{
m_BuildPartsNoTool.Clear();
m_ActionNoToolVariantManager.Clear();
}
}
int GetConstructionPartsCount()
{
return m_BuildParts.Count();
}
// deprecated
ConstructionPart GetCurrentBuildPart()
{
return null;
}
ConstructionPart GetBuildPartAtIndex(int idx)
{
if( m_BuildParts.Count() > idx )
{
return m_BuildParts.Get( idx );
}
return null;
}
ConstructionPart GetBuildPartNoToolAtIndex(int idx)
{
if( m_BuildPartsNoTool.Count() > idx )
{
return m_BuildPartsNoTool.Get( idx );
}
return null;
}
//************************************************/
// Combination lock
//************************************************/
CombinationLock GetCombinationLock()
{
return m_CombinationLock;
}
void SetCombinationLock( CombinationLock combination_lock )
{
m_CombinationLock = CombinationLock.Cast( combination_lock );
}
string GetDialNumberText()
{
string dial_text;
if ( m_CombinationLock )
{
string combination_text = m_CombinationLock.GetCombination().ToString();
//insert zeros to dials with 0 value
int length_diff = m_CombinationLock.GetLockDigits() - combination_text.Length();
for ( int i = 0; i < length_diff; ++i )
{
combination_text = "0" + combination_text;
}
//assemble the whole combination with selected part
for ( int j = 0; j < m_CombinationLock.GetLockDigits(); ++j )
{
if ( j == m_CombinationLock.GetDialIndex() )
{
dial_text += string.Format( "[%1]", combination_text.Get( j ) );
}
else
{
dial_text += string.Format( " %1 ", combination_text.Get( j ) );
}
}
}
return dial_text;
}
//************************************************/
// Attach/Detach actions
//************************************************/
int GetAttachmentSlotFromSelection( PlayerBase player, EntityAI target, ItemBase item_to_attach, string selection )
{
string cfg_path = "cfgVehicles" + " " + target.GetType() + " "+ "GUIInventoryAttachmentsProps";
if ( GetGame().ConfigIsExisting( cfg_path ) )
{
int child_count = GetGame().ConfigGetChildrenCount( cfg_path );
for ( int i = 0; i < child_count; i++ )
{
string child_name;
GetGame().ConfigGetChildName( cfg_path, i, child_name );
string child_selection;
GetGame().ConfigGetText( cfg_path + " " + child_name + " " + "selection", child_selection );
if ( selection == child_selection )
{
ref array<string> attachment_slots = new array<string>;
GetGame().ConfigGetTextArray( cfg_path + " " + child_name + " " + "attachmentSlots", attachment_slots );
for ( int j = 0; j < attachment_slots.Count(); ++j )
{
int target_slot_id = InventorySlots.GetSlotIdFromString( attachment_slots.Get( j ) );
int item_slot_count = item_to_attach.GetInventory().GetSlotIdCount();
for ( int k = 0; k < item_slot_count; ++k )
{
int item_slot_id = item_to_attach.GetInventory().GetSlotId( k );
ItemBase attachment_item = ItemBase.Cast( target.GetInventory().FindAttachment( item_slot_id ) );
if ( target_slot_id == item_slot_id )
{
if ( target.GetInventory().CanAddAttachmentEx( item_to_attach, item_slot_id ) && target.CanReceiveAttachment( item_to_attach, item_slot_id ) || attachment_item && attachment_item.CanBeCombined( item_to_attach ) )
{
if(target.CanDisplayAttachmentSlot(target_slot_id))
return item_slot_id;
else
return -1;
}
}
}
}
}
}
}
return -1;
}
void GetAttachmentsFromSelection( EntityAI target, string selection, out array<EntityAI> attachments )
{
attachments.Clear(); //clear output
string cfg_path = "cfgVehicles" + " " + target.GetType() + " "+ "GUIInventoryAttachmentsProps";
if ( GetGame().ConfigIsExisting( cfg_path ) )
{
int child_count = GetGame().ConfigGetChildrenCount( cfg_path );
for ( int i = 0; i < child_count; i++ )
{
string child_name;
GetGame().ConfigGetChildName( cfg_path, i, child_name );
string child_selection;
GetGame().ConfigGetText( cfg_path + " " + child_name + " " + "selection", child_selection );
if ( selection == child_selection )
{
ref array<string> attachment_slots = new array<string>;
GetGame().ConfigGetTextArray( cfg_path + " " + child_name + " " + "attachmentSlots", attachment_slots );
for ( int j = 0; j < attachment_slots.Count(); ++j )
{
int target_slot_id = InventorySlots.GetSlotIdFromString( attachment_slots.Get( j ) );
//is attached and can be detached
EntityAI attachment = target.GetInventory().FindAttachment( target_slot_id );
if ( attachment && target.GetInventory().CanRemoveAttachmentEx( attachment, target_slot_id ) && !target.GetInventory().GetSlotLock( target_slot_id ) )
{
attachments.Insert( attachment );
}
}
}
}
}
}
void CombineItems( ItemBase target, ItemBase item )
{
if ( target.ConfigGetBool( "canBeSplit" ) && item && !target.IsFullQuantity() )
{
int quantity_used = target.ComputeQuantityUsed( item, true );
if( quantity_used != 0 )
{
target.AddQuantity( quantity_used );
item.AddQuantity( -quantity_used );
}
}
}
void RefreshAttachmentsToDetach( EntityAI target, string main_part_name )
{
GetAttachmentsFromSelection( target, main_part_name, m_Attachments );
}
void SetNextAttachmentIndex()
{
if ( GetAttachmentsToDetachCount() > 1 )
{
if ( m_AttachmentsIndex <= GetAttachmentsToDetachCount() - 2 )
{
m_AttachmentsIndex++;
}
else if ( m_AttachmentsIndex >= GetAttachmentsToDetachCount() > - 1 )
{
m_AttachmentsIndex = 0;
}
}
else
{
m_AttachmentsIndex = 0;
}
}
int GetAttachmentsToDetachCount()
{
return m_Attachments.Count();
}
EntityAI GetActualAttachmentToDetach()
{
if ( GetAttachmentsToDetachCount() > 0 )
{
m_AttachmentsIndex = Math.Clamp( m_AttachmentsIndex, 0, GetAttachmentsToDetachCount() - 1 );
if ( m_Attachments && GetAttachmentsToDetachCount() > ( m_AttachmentsIndex ) )
{
return m_Attachments.Get( m_AttachmentsIndex );
}
}
return NULL;
}
//************************************************/
// Common
//************************************************/
void ResetActionIndexes()
{
m_PartIndex = 0;
m_AttachmentsIndex = 0;
}
}
|