public static void StartBpMode() { if (bpMode) { return; } bpMode = true; var actionBuild = GameMain.data.mainPlayer.controller.actionBuild; actionBuild.altitude = 0; actionBuild.player.SetHandItems(0, 0, 0); actionBuild.controller.cmd.type = ECommand.Build; actionBuild.controller.cmd.mode = 0; BuildLogic.lastPosition = Vector3.zero; BlueprintManager.Reset(); if (circleGizmo == null) { circleGizmo = CircleGizmo.Create(6, Vector3.zero, 10); circleGizmo.fadeOutScale = circleGizmo.fadeInScale = 1.8f; circleGizmo.fadeOutTime = circleGizmo.fadeInTime = 0.15f; circleGizmo.autoRefresh = true; circleGizmo.Open(); } }
public static void AlterSelection(PlayerAction_Build __instance) { bool removeMode = VFInput.control; if (referenceSelectionGizmo != null) { referenceSelectionGizmo.Close(); referenceSelectionGizmo = null; } if (areaSelectionGizmo == null) { areaSelectionGizmo = CircleGizmo.Create(6, Vector3.zero, 10); areaSelectionGizmo.fadeOutScale = areaSelectionGizmo.fadeInScale = 1.8f; areaSelectionGizmo.fadeOutTime = areaSelectionGizmo.fadeInTime = 0.15f; areaSelectionGizmo.autoRefresh = true; areaSelectionGizmo.Open(); } areaSelectionGizmo.color = removeMode ? REMOVE_SELECTION_GIZMO_COLOR : ADD_SELECTION_GIZMO_COLOR; areaSelectionGizmo.radius = selectionRadius; if (__instance.groundTestPos != Vector3.zero) { areaSelectionGizmo.position = __instance.groundTestPos; } if (VFInput._buildConfirm.pressing) { areaSelectionGizmo.color = removeMode ? REMOVE_SELECTION_GIZMO_COLOR : ADD_SELECTION_GIZMO_COLOR; // target only buildings int mask = 131072; int found = Physics.OverlapBoxNonAlloc(__instance.groundTestPos, new Vector3(selectionRadius, 100f, selectionRadius), _tmp_cols, Maths.SphericalRotation(__instance.groundTestPos, 0f), mask, QueryTriggerInteraction.Collide); PlanetPhysics planetPhysics = __instance.player.planetData.physics; for (int i = 0; i < found; i++) { planetPhysics.GetColliderData(_tmp_cols[i], out ColliderData colliderData); if (colliderData.objId > 0) { var entityId = colliderData.objId; if (removeMode) { if (bpSelection.ContainsKey(entityId)) { bpSelection[entityId].Close(); bpSelection.Remove(entityId); } if (entityId == referenceId) { referenceId = 0; } } else if (!bpSelection.ContainsKey(entityId)) { var entityData = __instance.factory.entityPool[entityId]; ItemProto itemProto = LDB.items.Select((int)entityData.protoId); var gizmo = BoxGizmo.Create(entityData.pos, entityData.rot, itemProto.prefabDesc.selectCenter, itemProto.prefabDesc.selectSize); gizmo.multiplier = 1f; gizmo.alphaMultiplier = itemProto.prefabDesc.selectAlpha; gizmo.fadeInScale = gizmo.fadeOutScale = 1.3f; gizmo.fadeInTime = gizmo.fadeOutTime = 0.05f; gizmo.fadeInFalloff = gizmo.fadeOutFalloff = 0.5f; gizmo.color = Color.white; gizmo.Open(); bpSelection.Add(entityId, gizmo); } } } if (referenceId == 0) { var belts = new List <int>(); var buildings = new List <int>(); foreach (var entityId in bpSelection.Keys) { var entityData = __instance.factory.entityPool[entityId]; if (entityId != entityData.id) { continue; } ItemProto itemProto = LDB.items.Select((int)entityData.protoId); if (itemProto.prefabDesc.isBelt) { belts.Add(entityId); } else if (!itemProto.prefabDesc.isInserter) { buildings.Add(entityId); } } if (buildings.Count > 0) { referenceId = buildings.First(); } else if (belts.Count > 0) { referenceId = belts.First(); } } } if (referenceId != 0 && bpSelection.TryGetValue(referenceId, out BoxGizmo reference)) { if (referenceGizmo == null) { referenceGizmo = BoxGizmo.Create(Vector3.zero, Quaternion.identity, Vector3.zero, new Vector3(0.5f, 100f, 0.5f)); referenceGizmo.multiplier = 1f; referenceGizmo.alphaMultiplier = 0.5f; referenceGizmo.fadeInScale = referenceGizmo.fadeOutScale = 1.3f; referenceGizmo.fadeInTime = referenceGizmo.fadeOutTime = 0.05f; referenceGizmo.fadeInFalloff = referenceGizmo.fadeOutFalloff = 0.5f; referenceGizmo.color = Color.green; referenceGizmo.Open(); } referenceGizmo.transform.position = reference.transform.position; referenceGizmo.transform.rotation = reference.transform.rotation; referenceGizmo.center = reference.center; } }
public static bool DestructMainLogic_Prefix(ref PlayerAction_Build __instance) { if (__instance.player.planetData.type == EPlanetType.Gas) { multiDestructPossible = false; } else { multiDestructPossible = true; } if (IsMultiDestructAvailable() && multiDestructEnabled) { if (circleGizmo == null) { circleGizmo = CircleGizmo.Create(1, __instance.groundTestPos, area); circleGizmo.fadeOutScale = circleGizmo.fadeInScale = 1.8f; circleGizmo.fadeOutTime = circleGizmo.fadeInTime = 0.15f; circleGizmo.color = DESTRUCT_GIZMO_COLOR; circleGizmo.autoRefresh = true; circleGizmo.Open(); } circleGizmo.position = __instance.groundTestPos; circleGizmo.radius = 1.2f * area; if (!VFInput.onGUI) { UICursor.SetCursor(ECursor.Delete); } __instance.ClearBuildPreviews(); int found = __instance.nearcdLogic.GetBuildingsInAreaNonAlloc(__instance.groundTestPos, area, _nearObjectIds); var ids = new HashSet <int>(); for (int x = 0; x < found; x++) { var objId = _nearObjectIds[x]; if (ids.Contains(objId)) { continue; } ids.Add(objId); ItemProto itemProto = __instance.GetItemProto(objId); PrefabDesc desc = itemProto.prefabDesc; if ( (itemProto.prefabDesc.isBelt && filter == EDestructFilter.Buildings) || (!itemProto.prefabDesc.isBelt && filter == EDestructFilter.Belts)) { continue; } Pose objectPose = __instance.GetObjectPose(objId); BuildPreview buildPreview = new BuildPreview { item = itemProto, desc = itemProto.prefabDesc, lpos = objectPose.position, lrot = objectPose.rotation, objId = objId, needModel = desc.lodCount > 0 && desc.lodMeshes[0] != null, isConnNode = true }; bool isInserter = buildPreview.desc.isInserter; if (isInserter) { Pose objectPose2 = __instance.GetObjectPose2(buildPreview.objId); buildPreview.lpos2 = objectPose2.position; buildPreview.lrot2 = objectPose2.rotation; } if (buildPreview.desc.multiLevel) { bool flag; int num; int num2; __instance.factory.ReadObjectConn(buildPreview.objId, 15, out flag, out num, out num2); if (num != 0) { _nearObjectIds[found++] = num; } } __instance.AddBuildPreview(buildPreview); } // reverse list so the building on 'top' are deleted first __instance.buildPreviews.Reverse(); __instance.DetermineMoreDestructionTargets(); __instance.UpdatePreviews(); __instance.UpdateGizmos(); if ((VFInput._buildConfirm.onDown || VFInput._buildConfirm.pressing) && __instance.buildPreviews.Count > 0) { Destruct(__instance); } return(false); } else { if (circleGizmo != null) { circleGizmo.Close(); circleGizmo = null; } return(true); } }
public static void GameTick(PlayerAction_Build __instance) { if (VFInput.shift && __instance.controller.cmd.mode == 0) { if (circleGizmo == null) { circleGizmo = CircleGizmo.Create(1, __instance.groundTestPos, 10); circleGizmo.fadeOutScale = circleGizmo.fadeInScale = 1.8f; circleGizmo.fadeOutTime = circleGizmo.fadeInTime = 0.15f; circleGizmo.color = COPY_GIZMO_COLOR; circleGizmo.autoRefresh = true; circleGizmo.Open(); } circleGizmo.position = __instance.groundTestPos; circleGizmo.radius = 1.2f * 10; if (VFInput._buildConfirm.onDown) { copiedAssemblers.Clear(); copiedInserters.Clear(); int found = __instance.nearcdLogic.GetBuildingsInAreaNonAlloc(__instance.groundTestPos, 10, _nearObjectIds); AssemblerCopy firstItem = null; for (int i = 0; i < found; i++) { var sourceEntityId = _nearObjectIds[i]; var sourceEntity = __instance.factory.entityPool[sourceEntityId]; var sourcePos = sourceEntity.pos; var sourceRot = sourceEntity.rot; var sourceEntityProto = LDB.items.Select(sourceEntity.protoId); if (sourceEntityProto.prefabDesc.insertPoses.Length == 0) { continue; } var assemblerCopy = new AssemblerCopy() { itemProto = sourceEntityProto, originalEntity = sourceEntity, originalPos = sourcePos, originalRot = sourceRot }; if (!sourceEntityProto.prefabDesc.isAssembler) { assemblerCopy.recipeId = __instance.factory.factorySystem.assemblerPool[sourceEntity.assemblerId].recipeId; } if (firstItem == null) { firstItem = assemblerCopy; } else { var inverseRot = Quaternion.Inverse(firstItem.originalRot); assemblerCopy.cursorRelativePos = inverseRot * (assemblerCopy.originalPos - firstItem.originalPos); int path = 0; Vector3[] snaps = new Vector3[1000]; var snappedPointCount = __instance.planetAux.SnapLineNonAlloc(firstItem.originalPos, assemblerCopy.originalPos, ref path, snaps); Vector3 lastSnap = firstItem.originalPos; Vector3[] snapMoves = new Vector3[snappedPointCount]; for (int s = 0; s < snappedPointCount; s++) { // note: reverse rotation of the delta so that rotation works Vector3 snapMove = inverseRot * (snaps[s] - lastSnap); snapMoves[s] = snapMove; lastSnap = snaps[s]; } assemblerCopy.snapCount = snappedPointCount; assemblerCopy.snapMoves = snapMoves; //assemblerCopy.cursorRelativeRot = Quaternion.Inverse(firstItem.originalRot) * assemblerCopy.originalRot; } copiedAssemblers.Add(sourceEntityId, assemblerCopy); } if (copiedAssemblers.Count > 0) { __instance.player.SetHandItems(firstItem.itemProto.ID, 0, 0); __instance.controller.cmd.type = ECommand.Build; __instance.controller.cmd.mode = 1; } } } else { if (circleGizmo != null) { circleGizmo.Close(); circleGizmo = null; } } }