8 [
Attribute(
"{56EBF5038622AC95}Assets/Conflict/CanBuild.emat")]
9 ResourceName m_sCanBuildMaterial;
11 [
Attribute(
"{14A9DCEA57D1C381}Assets/Conflict/CannotBuild.emat")]
33 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
36 RplComponent rplComponent = RplComponent.Cast(Replication.FindItem(
id));
40 IEntity item = rplComponent.GetEntity();
41 SCR_PlaceableInventoryItemComponent itemComponent = SCR_PlaceableInventoryItemComponent.Cast(item.FindComponent(SCR_PlaceableInventoryItemComponent));
45 itemComponent.PlaceItem(right, up, forward,
position);
55 ChimeraCharacter character = ChimeraCharacter.Cast(from);
68 BaseWeaponManagerComponent weaponManager = BaseWeaponManagerComponent.Cast(from.FindComponent(BaseWeaponManagerComponent));
76 if (characterController)
80 if (compartmentAccessComponent)
93 BaseWeaponManagerComponent weaponManager = BaseWeaponManagerComponent.Cast(to.FindComponent(BaseWeaponManagerComponent));
101 if (characterController)
105 if (compartmentAccessComponent)
116 ChimeraCharacter characterTo = ChimeraCharacter.Cast(to);
121 m_EquippedItem = characterTo.GetCharacterController().GetRightHandItem();
138 SCR_PlaceableInventoryItemComponent placeableItem = SCR_PlaceableInventoryItemComponent.Cast(item.FindComponent(SCR_PlaceableInventoryItemComponent));
142 PlayerController playerController = PlayerController.Cast(
GetOwner());
143 if (!playerController)
146 placeableItem.PlacementDone(playerController.GetControlledEntity());
155 IEntity controlledEntity =
GetGame().GetPlayerController().GetControlledEntity();
156 if (!controlledEntity)
160 if (!characterController)
163 characterController.SetDisableWeaponControls(
true);
164 characterController.SetDisableMovementControls(
true);
166 if (characterController.IsUsingItem())
169 ChimeraCharacter character = ChimeraCharacter.Cast(controlledEntity);
170 CharacterAnimationComponent animationComponent = character.GetAnimationComponent();
171 int itemActionId = animationComponent.BindCommand(
"CMD_Item_Action");
174 PointInfo ptWS =
new PointInfo();
175 mat[2] = (mat[3] - character.GetOrigin()).Normalized();
177 mat[0] = Vector(mat[2][2], mat[2][1], -mat[2][0]);
178 ptWS.Set(
null,
"", mat);
182 params.SetAllowMovementDuringAction(
false);
183 params.SetKeepInHandAfterSuccess(
false);
184 params.SetCommandID(itemActionId);
185 params.SetCommandIntArg(1);
186 params.SetMaxAnimLength(15.0);
187 params.SetAlignmentPoint(ptWS);
189 if (characterController.TryUseItemOverrideParams(
params))
191 characterController.m_OnItemUseEndedInvoker.Insert(
OnPlacingEnded);
194 characterController.GetAnimationComponent().GetCommandHandler().AlignNewTurns();
202 IEntity controlledEntity =
GetGame().GetPlayerController().GetControlledEntity();
203 if (!controlledEntity)
207 if (!characterController)
210 characterController.SetDisableWeaponControls(
true);
211 characterController.SetDisableMovementControls(
true);
213 characterController.m_OnItemUseEndedInvoker.Remove(
OnPlacingEnded);
225 SCR_CharacterInventoryStorageComponent storage = SCR_CharacterInventoryStorageComponent.Cast(controlledEntity.FindComponent(SCR_CharacterInventoryStorageComponent));
229 RplComponent rplComponent = RplComponent.Cast(
m_EquippedItem.FindComponent(RplComponent));
233 SCR_PlaceableInventoryItemComponent placeableItem = SCR_PlaceableInventoryItemComponent.Cast(
m_EquippedItem.FindComponent(SCR_PlaceableInventoryItemComponent));
237 storageManager.TryRemoveItemFromStorage(
m_EquippedItem, storage.GetWeaponStorage());
245 GetGame().GetInputManager().RemoveActionListener(
"CharacterFire", EActionTrigger.DOWN,
StartPlaceItem);
246 ClearEventMask(
GetOwner(), EntityEvent.FRAME);
253 m_PlaceableItem = SCR_PlaceableItemComponent.Cast(weapon.FindComponent(SCR_PlaceableItemComponent));
255 EntityPrefabData prefabData = weapon.GetPrefabData();
261 SetEventMask(
GetOwner(), EntityEvent.FRAME);
267 SCR_PlaceableItemComponent placeableItemComponent = SCR_PlaceableItemComponent.Cast(weapon.FindComponent(SCR_PlaceableItemComponent));
268 if (!placeableItemComponent)
270 Print(
"SCR_PlaceableItemComponent not found! SCR_ItemPlacementComponent.EnablePreview()");
275 m_PreviewEntity.SetObject(placeableItemComponent.GetPreviewVobject(),
"");
279 protected void OnComparmentEntered(IEntity targetEntity, BaseCompartmentManagerComponent manager,
int mgrID,
int slotID,
bool move)
299 return weaponSlot.GetWeaponEntity();
328 if (
m_bInEditor || !weapon || !weapon.FindComponent(SCR_PlaceableItemComponent))
335 protected override void EOnFrame(IEntity owner,
float timeSlice)
350 CameraManager cameraManager =
GetGame().GetCameraManager();
354 CameraBase currentCamera = cameraManager.CurrentCamera();
359 currentCamera.GetTransform(cameraMat);
360 float maxPlacementDistance =
m_PlaceableItem.GetMaxPlacementDistance();
363 switch (placementType)
394 TraceParam param =
new TraceParam();
395 param.Start = character.GetOrigin() + maxPlacementDistance *
direction + vector.Up;
396 param.End = param.Start - 5 * vector.Up;
397 param.Flags = TraceFlags.WORLD | TraceFlags.ENTS;
398 param.Exclude = character;
399 param.LayerMask = EPhysicsLayerPresets.Projectile;
400 BaseWorld world = owner.GetWorld();
403 m_vCurrentMat[3] = param.Start + ((param.End - param.Start) * traceDistance);
404 vector up = param.TraceNorm;
416 Physics physics = e.GetPhysics();
417 if (physics && (physics.GetInteractionLayer() & EPhysicsLayerDefs.Water || physics.IsDynamic() || physics.IsKinematic()))
431 TraceParam param =
new TraceParam();
432 param.Start = cameraMat[3];
433 param.End = param.Start + cameraMat[2] * maxPlacementDistance;
434 param.Flags = TraceFlags.WORLD | TraceFlags.ENTS;
436 param.LayerMask = EPhysicsLayerPresets.Projectile;
437 BaseWorld world = owner.GetWorld();
440 m_vCurrentMat[3] = param.Start + ((param.End - param.Start) * traceDistance);
441 vector up = param.TraceNorm;
443 IEntity tracedEntity = param.TraceEnt;
445 if (traceDistance == 1)
448 TraceParam paramGround =
new TraceParam();
449 paramGround.Start = param.End + vector.Up;
450 paramGround.End = paramGround.Start - vector.Up * 20;
451 paramGround.Flags = TraceFlags.WORLD | TraceFlags.ENTS;
453 paramGround.LayerMask = EPhysicsLayerPresets.Projectile;
456 m_vCurrentMat[3] = paramGround.Start + ((paramGround.End - paramGround.Start) * traceGroundDistance) + vector.Up * 0.01;
458 if (traceGroundDistance < 1)
459 up = paramGround.TraceNorm;
461 tracedEntity = paramGround.TraceEnt;
469 vector characterOrigin = character.GetOrigin();
471 if (Math.AbsFloat(
m_vCurrentMat[3][1] - characterOrigin[1] > 0.4))
477 if (vector.Distance(
m_vCurrentMat[3], characterOrigin) > maxPlacementDistance)
492 Physics physics = entity.GetPhysics();
493 if (physics && physics.IsDynamic())
498 if (mainEntity && mainEntity != entity)
500 physics = mainEntity.GetPhysics();
501 if (physics && physics.IsDynamic())
517 if (vector.Dot(up, vector.Up) < 0.5)
526 array<IEntity> excludeArray = {};
528 excludeArray.Insert(character);
532 TraceOBB paramOBB =
new TraceOBB();
533 Math3D.MatrixIdentity3(paramOBB.Mat);
538 paramOBB.Flags = TraceFlags.ENTS;
539 paramOBB.ExcludeArray = excludeArray;
540 paramOBB.LayerMask = EPhysicsLayerPresets.Projectile;
545 if (paramOBB.TraceEnt)
566 vector perpend = normal.Perpend();
570 Math3D.AnglesToMatrix(Vector(-perpend.VectorToAngles()[0], 0, 0), basis);
599 SetEventMask(owner, EntityEvent.INIT);
618 protected override void EOnInit(IEntity owner)
621 if (!playerController)
623 Print(
"SCR_ItemPlacementComponent is not attached to SCR_PlayerController!", LogLevel.WARNING);