Пример #1
0
        public static void PlayerAction_Build_AfterPrebuilds_Prefix(ref PlayerAction_Build __instance)
        {
            foreach (var pastedEntity in BlueprintManager.pastedEntities.Values)
            {
                var buildPreview   = pastedEntity.buildPreview;
                var sourceBuilding = pastedEntity.sourceBuilding;

                if (buildPreview.objId >= 0)
                {
                    continue;
                }
                pastedEntity.objId = buildPreview.objId;

                if (pastedEntity.type == EPastedType.BUILDING && !toPostProcess.ContainsKey(buildPreview.objId))
                {
                    if (sourceBuilding.itemProto.prefabDesc.isStation && sourceBuilding.slotFilters.Count + sourceBuilding.stationSettings.Count > 0)
                    {
                        toPostProcess.Add(buildPreview.objId, pastedEntity);
                    }
                    if (sourceBuilding.itemProto.prefabDesc.isStorage && sourceBuilding.recipeId > 0)
                    {
                        toPostProcess.Add(buildPreview.objId, pastedEntity);
                    }
                    if (sourceBuilding.itemProto.prefabDesc.isSplitter)
                    {
                        toPostProcess.Add(buildPreview.objId, pastedEntity);
                        foreach (var otherPastedEntity in pastedEntity.connectedEntities.Values)
                        {
                            // postpocess the splitter after every belt has been built
                            toPostProcess.Add(otherPastedEntity.buildPreview.objId, pastedEntity);
                        }
                    }
                }
            }
            if (BlueprintManager.pastedEntities.Count > 0)
            {
                __instance.ClearBuildPreviews();
            }

            forceRecalculation = true;
        }
Пример #2
0
        public static void DetermineBuildPreviews_Postfix(ref PlayerAction_Build __instance)
        {
            if (IsMultiBuildRunning())
            {
                __instance.ClearBuildPreviews();

                if (__instance.previewPose.position == Vector3.zero)
                {
                    return;
                }

                __instance.previewPose.position = Vector3.zero;
                __instance.previewPose.rotation = Quaternion.identity;

                int       snapPath = path;
                Vector3[] snaps    = new Vector3[1024];

                var snappedPointCount = __instance.planetAux.SnapLineNonAlloc(startPos, __instance.groundSnappedPos, ref snapPath, snaps);

                var        desc        = __instance.handPrefabDesc;
                Collider[] colliders   = new Collider[desc.buildColliders.Length];
                Vector3    previousPos = Vector3.zero;

                var usedSnaps = new List <Vector3>(10);

                var maxSnaps = Math.Max(1, snappedPointCount - spacing);

                for (int s = 0; s < maxSnaps; s++)
                {
                    var pos = snaps[s];
                    var rot = Maths.SphericalRotation(snaps[s], __instance.yaw);

                    if (s > 0)
                    {
                        var sqrDistance = (previousPos - pos).sqrMagnitude;

                        // power towers
                        if (desc.isPowerNode && sqrDistance < 12.25f)
                        {
                            continue;
                        }

                        // wind turbines
                        if (desc.windForcedPower && sqrDistance < 110.25f)
                        {
                            continue;
                        }

                        // ray receivers
                        if (desc.gammaRayReceiver && sqrDistance < 110.25f)
                        {
                            continue;
                        }

                        // logistic stations
                        if (desc.isStation && sqrDistance < (desc.isStellarStation ? 841f : 225f))
                        {
                            continue;
                        }

                        // ejector
                        if (desc.isEjector && sqrDistance < 110.25f)
                        {
                            continue;
                        }

                        if (desc.hasBuildCollider)
                        {
                            var foundCollision = false;
                            for (var j = 0; j < desc.buildColliders.Length && !foundCollision; j++)
                            {
                                var colliderData = desc.buildColliders[j];
                                colliderData.pos = pos + rot * colliderData.pos;
                                colliderData.q   = rot * colliderData.q;
                                // check only collision with layer 27 (the layer used by the our own building colliders for the previously 'placed' building)
                                foundCollision = Physics.CheckBox(colliderData.pos, colliderData.ext, colliderData.q, 134217728, QueryTriggerInteraction.Collide);
                            }

                            if (foundCollision)
                            {
                                continue;
                            }
                        }
                    }

                    if (s > 0 && spacing > 0)
                    {
                        s  += spacing;
                        pos = snaps[s];
                        rot = Maths.SphericalRotation(snaps[s], __instance.yaw);
                    }

                    previousPos = pos;
                    usedSnaps.Add(pos);

                    var bp = BuildPreview.CreateSingle(__instance.handItem, __instance.handPrefabDesc, true);
                    bp.ResetInfos();
                    bp.desc     = desc;
                    bp.lpos     = pos;
                    bp.lrot     = rot;
                    bp.item     = __instance.handItem;
                    bp.recipeId = __instance.copyRecipeId;
                    bp.filterId = __instance.copyFilterId;

                    if (desc.hasBuildCollider)
                    {
                        for (var j = 0; j < desc.buildColliders.Length; j++)
                        {
                            // create temporary collider entities for the latest 'positioned' building
                            if (colliders[j] != null)
                            {
                                ColliderPool.PutCollider(colliders[j]);
                            }

                            var colliderData = desc.buildColliders[j];
                            colliderData.pos = pos + rot * colliderData.pos;
                            colliderData.q   = rot * colliderData.q;
                            colliders[j]     = ColliderPool.TakeCollider(colliderData);
                            colliders[j].gameObject.layer = 27;
                        }
                    }

                    __instance.AddBuildPreview(bp);
                }

                foreach (var collider in colliders)
                {
                    if (collider != null)
                    {
                        ColliderPool.PutCollider(collider);
                    }
                }


                ActivateColliders(ref __instance.nearcdLogic, usedSnaps);
            }
        }
Пример #3
0
            public static bool DetermineDestructPreviewsPatch(PlayerAction_Build __instance,
                                                              ref NearColliderLogic ___nearcdLogic,
                                                              ref PlanetFactory ___factory)
            {
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.LeftControl))
                {
                    if (!VFInput.onGUI)
                    {
                        UICursor.SetCursor(ECursor.Delete);
                    }
                }
                else
                {
                    return(true);
                }

                if (!Utils.CheckIfInBuildDistance(__instance.cursorTarget))
                {
                    // Out of reach
                    UnityEngine.Debug.Log("out of reach");
                    return(true);
                }

                List <EntityData> deleteEntitiesList = new List <EntityData>();
                ItemProto         itemProto          = Traverse.Create(__instance).Method(
                    "GetItemProto", __instance.castObjId).GetValue <ItemProto>();

                __instance.ClearBuildPreviews();

                if (VFInput.reformMinusKey.onDown)
                {
                    if (__instance.reformSize >= 0)
                    {
                        __instance.reformSize--;
                    }
                }

                if (VFInput.reformPlusKey.onDown)
                {
                    if (__instance.reformSize < _configDisassemblingRadiusMax.Value)
                    {
                        __instance.reformSize++;
                    }
                }

                // Management of the sphere delete
                if (Input.GetKey(KeyCode.LeftControl))
                {
                    int[] buildingIdsToDelete = new int[_maxArrayOfBuildingSize.Value];
                    if (itemProto != null)
                    {
                        ___nearcdLogic.GetBuildingsInAreaNonAlloc(__instance.castObjPos, __instance.reformSize, buildingIdsToDelete);
                    }
                    else
                    {
                        ___nearcdLogic.GetBuildingsInAreaNonAlloc(__instance.cursorTarget, __instance.reformSize, buildingIdsToDelete);
                    }

                    List <int> listBuildingIdsToDelete = new List <int>();

                    foreach (var id in buildingIdsToDelete)
                    {
                        if (id != 0)
                        {
                            listBuildingIdsToDelete.Add(id);
                        }
                    }

                    foreach (var item in listBuildingIdsToDelete)
                    {
                        deleteEntitiesList.Add(___factory.entityPool[item]);
                    }

                    // Management of both
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        if (itemProto != null)
                        {
                            deleteEntitiesList = Utils.GetEntitySortedByTypeAndRadius(itemProto, deleteEntitiesList,
                                                                                      __instance.castObjPos, __instance.reformSize);
                        }
                    }
                }

                // Management of the Mass Item delete
                if (Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.LeftControl))
                {
                    __instance.previewPose.position = Vector3.zero;
                    __instance.previewPose.rotation = Quaternion.identity;
                    if ((uint)__instance.castObjId > 0U)
                    {
                        if (itemProto != null)
                        {
                            if ((uint)___factory.entityPool[__instance.castObjId].beltId > 0U)
                            {
                                CargoPath pathByBeltId = Utils.GetPathWithBeltId(___factory,
                                                                                 ___factory.entityPool[__instance.castObjId].beltId);
                                deleteEntitiesList = Utils.GetBeltsEntitiesByCargoPathBuildRange(___factory, pathByBeltId);
                            }
                            else
                            {
                                // deleteEntitiesList = Utils.GetEntitiesByProtoBuildRange(___factory, itemProto);
                                return(true);
                            }
                        }
                    }
                }


                foreach (var entityData in deleteEntitiesList)
                {
                    __instance.AddBuildPreview(new BuildPreview());
                }

                // Common Code
                for (int index = 0; index < __instance.buildPreviews.Count; ++index)
                {
                    BuildPreview buildPreview = __instance.buildPreviews[index];
                    ItemProto    itemProto2   = Traverse.Create(__instance).Method(
                        "GetItemProto", deleteEntitiesList[index].id).GetValue <ItemProto>();
                    buildPreview.item  = itemProto2;
                    buildPreview.desc  = itemProto2.prefabDesc;
                    buildPreview.lpos  = deleteEntitiesList[index].pos;
                    buildPreview.lrot  = deleteEntitiesList[index].rot;
                    buildPreview.objId = deleteEntitiesList[index].id;
                    int num = buildPreview.desc.lodCount <= 0
                        ? 0
                        : ((Object)buildPreview.desc.lodMeshes[0] != (Object)null ? 1 : 0);
                    buildPreview.needModel  = num != 0;
                    buildPreview.isConnNode = true;
                    if (buildPreview.desc.isInserter)
                    {
                        Pose pose = Traverse.Create(__instance).Method("GetObjectPose2", buildPreview.objId)
                                    .GetValue <Pose>();
                        buildPreview.lpos2 = pose.position;
                        buildPreview.lrot2 = pose.rotation;
                    }

                    if ((buildPreview.lpos - __instance.player.position).sqrMagnitude >
                        __instance.player.mecha.buildArea *
                        __instance.player.mecha.buildArea)
                    {
                        buildPreview.condition   = EBuildCondition.OutOfReach;
                        __instance.cursorText    = "目标超出范围".Translate();
                        __instance.cursorWarning = true;
                    }
                    else
                    {
                        buildPreview.condition = EBuildCondition.Ok;
                        __instance.cursorText  = "拆除".Translate() + buildPreview.item.name;
                    }

                    if (buildPreview.desc.multiLevel)
                    {
                        ___factory.ReadObjectConn(buildPreview.objId, 15, out bool _, out int otherObjId,
                                                  out int _);
                        if ((uint)otherObjId > 0U)
                        {
                            buildPreview.condition = EBuildCondition.Covered;
                            __instance.cursorText  = buildPreview.conditionText;
                        }
                    }
                }


                return(false);
            }
Пример #4
0
        public static bool DetermineBuildPreviewsPrefix(ref PlayerAction_Build __instance)
        {
            CommandState cmd = __instance.controller.cmd;
            //__instance.waitConfirm = false;
            bool flag  = false;
            bool flag2 = false;

            if (__instance.handPrefabDesc == null)
            {
                if (cmd.mode == 4)
                {
                    int[] consumeRegister = GameMain.statistics.production.factoryStatPool[__instance.factory.index].consumeRegister;
                    if (__instance.reformSize < 1)
                    {
                        __instance.reformSize = 1;
                    }
                    else if (__instance.reformSize > 30)
                    {
                        __instance.reformSize = 30;
                    }
                    if ((__instance.reformCenterPoint - __instance.player.position).sqrMagnitude > __instance.player.mecha.buildArea * __instance.player.mecha.buildArea)
                    {
                        if (!VFInput.onGUI)
                        {
                            __instance.cursorText    = "目标超出范围".Translate();
                            __instance.cursorWarning = true;
                            UICursor.SetCursor(ECursor.Ban);
                        }
                    }
                    else
                    {
                        if (!VFInput.onGUI)
                        {
                            UICursor.SetCursor(ECursor.Reform);
                        }
                        bool flag24 = false;
                        if (VFInput._reformPlusKey.onDown)
                        {
                            if (__instance.reformSize < 30)
                            {
                                __instance.reformSize++;
                                flag24 = true;
                                for (int num61 = 0; num61 < __instance.reformSize * __instance.reformSize; num61++)
                                {
                                    __instance.reformIndices[num61] = -1;
                                }
                            }
                        }
                        else if (VFInput._reformMinusKey.onDown && __instance.reformSize > 1)
                        {
                            __instance.reformSize--;
                            flag24 = true;
                        }
                        float radius = 0.99094594f * (float)__instance.reformSize;
                        int   num62  = __instance.factory.ComputeFlattenTerrainReform(__instance.reformPoints, __instance.reformCenterPoint, radius, __instance.reformPointsCount, 3f, 1f);
                        if (__instance.cursorValid && !VFInput.onGUI)
                        {
                            if (num62 > 0)
                            {
                                string soilCount = num62.ToString();

                                if (FreeFoundationsFreeSoilPlugin.freeSoilEnabled)
                                {
                                    soilCount = "0";
                                }
                                //Debug.Log("IF");
                                __instance.cursorText = string.Concat(new string[]
                                {
                                    "沙土消耗".Translate(),
                                    " ",
                                    soilCount,
                                    " ",
                                    "个沙土".Translate(),
                                    "\n",
                                    "改造大小".Translate(),
                                    __instance.reformSize.ToString(),
                                    "x",
                                    __instance.reformSize.ToString(),
                                    (FreeFoundationsFreeSoilPlugin.freeSoilEnabled) ?       "\n       (Free Soil is Enabled)" : string.Empty,
                                    (FreeFoundationsFreeSoilPlugin.freeFoundationEnabled) ? "\n(Free Foundations is Enabled)" : string.Empty
                                });
                            }
                            else if (num62 == 0)
                            {
                                __instance.cursorText = "改造大小".Translate() + __instance.reformSize.ToString() + "x" + __instance.reformSize.ToString() +
                                                        ((FreeFoundationsFreeSoilPlugin.freeSoilEnabled) ?       "\n       (Free Soil is Enabled)" : string.Empty) +
                                                        ((FreeFoundationsFreeSoilPlugin.freeFoundationEnabled) ? "\n(Free Foundations is Enabled)" : string.Empty);
                            }
                            else
                            {
                                int num63 = -num62;



                                string soilCount = num63.ToString();

                                if (!FreeFoundationsFreeSoilPlugin.collectSoilEnabled)
                                {
                                    soilCount = "0";
                                }
                                //Debug.Log("ELSE");



                                __instance.cursorText = string.Concat(new string[]
                                {
                                    "沙土获得".Translate(),
                                    " ",
                                    soilCount,
                                    " ",
                                    "个沙土".Translate(),
                                    "\n",
                                    "改造大小".Translate(),
                                    __instance.reformSize.ToString(),
                                    "x",
                                    __instance.reformSize.ToString(),
                                    (FreeFoundationsFreeSoilPlugin.freeSoilEnabled) ?       "\n       (Free Soil is Enabled)" : string.Empty,
                                    (FreeFoundationsFreeSoilPlugin.freeFoundationEnabled) ? "\n(Free Foundations is Enabled)" : string.Empty
                                });
                            }
                            if (VFInput._buildConfirm.pressing)
                            {
                                bool flag25 = false;
                                if (VFInput._buildConfirm.onDown)
                                {
                                    flag25 = true;
                                    __instance.reformMouseOnDown = true;
                                }
                                if (__instance.reformMouseOnDown)
                                {
                                    __instance.inReformOperation = true;
                                    if (__instance.reformChangedPoint.x != __instance.reformCenterPoint.x || __instance.reformChangedPoint.y != __instance.reformCenterPoint.y || __instance.reformChangedPoint.z != __instance.reformCenterPoint.z || flag24)
                                    {
                                        bool doItFoundation = true;
                                        if (FreeFoundationsFreeSoilPlugin.freeFoundationEnabled)
                                        {
                                            doItFoundation = __instance.handItem.BuildMode == 4;
                                        }
                                        else
                                        {
                                            doItFoundation = __instance.handItem.BuildMode == 4 && __instance.player.package.GetItemCount(__instance.handItem.ID) + __instance.player.inhandItemCount >= __instance.reformPointsCount;
                                        }
                                        if (doItFoundation)
                                        {
                                            bool doItSoil = false;

                                            if (FreeFoundationsFreeSoilPlugin.freeSoilEnabled || !FreeFoundationsFreeSoilPlugin.collectSoilEnabled)
                                            {
                                                doItSoil = __instance.player.sandCount >= 0;
                                            }
                                            else
                                            {
                                                doItSoil = __instance.player.sandCount - num62 >= 0;
                                            }
                                            //num64 = 100000;
                                            if (doItSoil)
                                            {
                                                //Debug.Log(num62);
                                                __instance.factory.FlattenTerrainReform(__instance.reformCenterPoint, radius, __instance.reformSize, __instance.veinBuried, 3f);
                                                VFAudio.Create("reform-terrain", null, __instance.reformCenterPoint, true);

                                                if (num62 < 0)
                                                {
                                                    if (FreeFoundationsFreeSoilPlugin.collectSoilEnabled)
                                                    {
                                                        __instance.player.SetSandCount(__instance.player.sandCount - num62);
                                                    }
                                                    else
                                                    {
                                                        __instance.player.SetSandCount(__instance.player.sandCount);
                                                    }
                                                }
                                                else
                                                {
                                                    if (FreeFoundationsFreeSoilPlugin.freeSoilEnabled)
                                                    {
                                                        __instance.player.SetSandCount(__instance.player.sandCount);
                                                    }
                                                    else
                                                    {
                                                        __instance.player.SetSandCount(__instance.player.sandCount - num62);
                                                    }
                                                }

                                                int num65 = __instance.reformSize * __instance.reformSize;
                                                for (int num66 = 0; num66 < num65; num66++)
                                                {
                                                    int            num67          = __instance.reformIndices[num66];
                                                    PlatformSystem platformSystem = __instance.factory.platformSystem;
                                                    if (num67 >= 0)
                                                    {
                                                        int num68 = platformSystem.GetReformType(num67);
                                                        int num69 = platformSystem.GetReformColor(num67);
                                                        if (num68 != __instance.reformType || num69 != __instance.reformColor)
                                                        {
                                                            __instance.factory.platformSystem.SetReformType(num67, __instance.reformType);
                                                            __instance.factory.platformSystem.SetReformColor(num67, __instance.reformColor);
                                                        }
                                                    }
                                                }
                                                int num70 = __instance.reformPointsCount;
                                                if (__instance.player.inhandItemCount > 0)
                                                {
                                                    int num71 = (__instance.reformPointsCount >= __instance.player.inhandItemCount) ? __instance.player.inhandItemCount : __instance.reformPointsCount;
                                                    __instance.player.UseHandItems(num71);
                                                    num70 -= num71;
                                                }
                                                int id = __instance.handItem.ID;
                                                consumeRegister[id] += __instance.reformPointsCount;
                                                __instance.player.package.TakeTailItems(ref id, ref num70, false);
                                                GameMain.gameScenario.NotifyOnBuild(__instance.player.planetId, __instance.handItem.ID, 0);
                                            }
                                            else if (flag25)
                                            {
                                                //Debug.Log("No1");
                                                UIRealtimeTip.Popup("沙土不足".Translate(), true, 0);
                                            }
                                        }
                                        else if (flag25)
                                        {
                                            //Debug.Log("No2");
                                            UIRealtimeTip.Popup("物品不足".Translate(), true, 1);
                                        }
                                    }
                                }
                                else
                                {
                                    __instance.inReformOperation = false;
                                }
                                __instance.reformChangedPoint = __instance.reformCenterPoint;
                            }
                            else
                            {
                                __instance.inReformOperation  = false;
                                __instance.reformChangedPoint = Vector3.zero;
                                __instance.reformMouseOnDown  = false;
                            }
                        }
                    }
                }
                else
                {
                    // Just do original code instead
                    return(true);
                }
                __instance.ClearBuildPreviews();
            }
            else
            {
                return(true);
            }
            if (!flag)
            {
                UIRoot.instance.uiGame.CloseInserterBuildTip();
            }
            if (!flag2)
            {
                UIRoot.instance.uiGame.beltBuildTip.SetOutputEntity(0, -1);
                UIRoot.instance.uiGame.CloseBeltBuildTip();
            }


            // Don't execute original put original above instead?
            return(false);
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        public static bool PlayerAction_Build_DetermineBuildPreviews_Prefix(ref PlayerAction_Build __instance)
        {
            if (__instance.controller.cmd.mode != 1 ||
                __instance.player.planetData.type == EPlanetType.Gas ||
                !__instance.cursorValid ||
                __instance.groundSnappedPos == Vector3.zero ||
                (__instance.handPrefabDesc != null && __instance.handPrefabDesc.minerType != EMinerType.None)
                )
            {
                lastRunOriginal = true;
                return(true);
            }

            __instance.waitConfirm        = __instance.cursorValid;
            __instance.multiLevelCovering = false;
            if (__instance.handPrefabDesc != null && __instance.handPrefabDesc.multiLevel)
            {
                int objectProtoId = __instance.GetObjectProtoId(__instance.castObjId);
                if (objectProtoId == __instance.handItem.ID)
                {
                    __instance.multiLevelCovering = true;
                }
            }

            if (!MultiBuild.IsMultiBuildRunning() && (__instance.multiLevelCovering || !BlueprintManager.hasData))
            {
                if (!lastRunOriginal)
                {
                    __instance.ClearBuildPreviews();
                }
                lastRunOriginal = true;
                return(true);
            }

            // full hijacking of DetermineBuildPreviews
            lastRunOriginal = false;
            if (VFInput._switchSplitter.onDown)
            {
                __instance.modelOffset++;
                forceRecalculation = true;
            }

            if (VFInput._rotate.onDown)
            {
                __instance.yaw    += 90f;
                __instance.yaw     = Mathf.Repeat(__instance.yaw, 360f);
                __instance.yaw     = Mathf.Round(__instance.yaw / 90f) * 90f;
                forceRecalculation = true;
            }
            if (VFInput._counterRotate.onDown)
            {
                __instance.yaw    -= 90f;
                __instance.yaw     = Mathf.Repeat(__instance.yaw, 360f);
                __instance.yaw     = Mathf.Round(__instance.yaw / 90f) * 90f;
                forceRecalculation = true;
            }

            __instance.yaw = Mathf.Round(__instance.yaw / 90f) * 90f;
            __instance.previewPose.position = Vector3.zero;
            __instance.previewPose.rotation = Quaternion.identity;

            if (lastPosition == __instance.groundSnappedPos && !forceRecalculation)
            {
                // no update necessary
                runUpdate = false;
                return(false);
            }
            lastPosition       = __instance.groundSnappedPos;
            forceRecalculation = false;

            List <BuildPreview> previews = new List <BuildPreview>();

            if (MultiBuild.IsMultiBuildRunning())
            {
                if (!BlueprintManager.hasData)
                {
                    BlueprintManager.data.copiedBuildings.Add(new BuildingCopy()
                    {
                        itemProto  = __instance.handItem,
                        recipeId   = __instance.copyRecipeId,
                        modelIndex = __instance.handPrefabDesc.modelIndex
                    });
                }
                var building = BlueprintManager.data.copiedBuildings[0];// BlueprintManager.data.copiedBuildings.First();

                int snapPath = path;


                var snappedPointCount = __instance.planetAux.SnapLineNonAlloc(MultiBuild.startPos, __instance.groundSnappedPos, ref snapPath, snaps);

                var        desc        = BlueprintManager.GetPrefabDesc(building);
                Collider[] colliders   = new Collider[desc.buildColliders.Length];
                Vector3    previousPos = Vector3.zero;

                var copiesCounter = 0;
                for (int s = 0; s < snappedPointCount; s++)
                {
                    var pos = snaps[s];
                    var rot = Maths.SphericalRotation(snaps[s], __instance.yaw + building.cursorRelativeYaw);

                    if (s > 0)
                    {
                        var sqrDistance = (previousPos - pos).sqrMagnitude;

                        // power towers
                        if (desc.isPowerNode && !desc.isAccumulator && sqrDistance < 12.25f)
                        {
                            continue;
                        }

                        // wind turbines
                        if (desc.windForcedPower && sqrDistance < 110.25f)
                        {
                            continue;
                        }

                        // ray receivers
                        if (desc.gammaRayReceiver && sqrDistance < 110.25f)
                        {
                            continue;
                        }

                        // logistic stations
                        if (desc.isStation && sqrDistance < (desc.isStellarStation ? 841f : 225f))
                        {
                            continue;
                        }

                        // ejector
                        if (desc.isEjector && sqrDistance < 110.25f)
                        {
                            continue;
                        }

                        if (desc.hasBuildCollider)
                        {
                            var foundCollision = false;
                            for (var j = 0; j < desc.buildColliders.Length && !foundCollision; j++)
                            {
                                var colliderData = desc.buildColliders[j];
                                colliderData.pos = pos + rot * colliderData.pos;
                                colliderData.q   = rot * colliderData.q;
                                // check only collision with layer 27 (the layer used by the our own building colliders for the previously 'placed' building)
                                foundCollision = Physics.CheckBox(colliderData.pos, colliderData.ext, colliderData.q, 134217728, QueryTriggerInteraction.Collide);
                            }

                            if (foundCollision)
                            {
                                continue;
                            }
                        }
                    }

                    if (s > 0 && MultiBuild.spacingStore[MultiBuild.spacingIndex] > 0 && copiesCounter % MultiBuild.spacingPeriod == 0)
                    {
                        s += MultiBuild.spacingStore[MultiBuild.spacingIndex];

                        if (s >= snappedPointCount)
                        {
                            break;
                        }
                        pos = snaps[s];
                        rot = Maths.SphericalRotation(snaps[s], __instance.yaw);
                    }

                    copiesCounter++;
                    previousPos = pos;

                    if (desc.hasBuildCollider)
                    {
                        for (var j = 0; j < desc.buildColliders.Length; j++)
                        {
                            // create temporary collider entities for the latest 'positioned' building
                            if (colliders[j] != null)
                            {
                                ColliderPool.PutCollider(colliders[j]);
                            }

                            var colliderData = desc.buildColliders[j];
                            colliderData.pos = pos + rot * colliderData.pos;
                            colliderData.q   = rot * colliderData.q;
                            colliders[j]     = ColliderPool.TakeCollider(colliderData);
                            colliders[j].gameObject.layer = 27;
                        }
                    }

                    previews = previews.Concat(BlueprintManager.Paste(pos, __instance.yaw, MultiBuild.multiBuildInserters)).ToList();
                }

                if (!BlueprintManager.hasData)
                {
                    BlueprintManager.data.copiedBuildings.RemoveAt(0);
                }
                foreach (var collider in colliders)
                {
                    if (collider != null)
                    {
                        ColliderPool.PutCollider(collider);
                    }
                }
            }
            else
            {
                var pasteInserters = MultiBuild.multiBuildInserters || (BlueprintManager.data.copiedBuildings.Count + BlueprintManager.data.copiedBelts.Count > 1);
                previews = BlueprintManager.Paste(__instance.groundSnappedPos, __instance.yaw, pasteInserters);
            }

            // synch previews
            var availableModelPreviews = new Dictionary <int, Queue <int> >();

            foreach (var bp in __instance.buildPreviews)
            {
                if (bp.previewIndex >= 0)
                {
                    int modelId = bp.desc.modelIndex;
                    if (!availableModelPreviews.TryGetValue(modelId, out Queue <int> availableIndexes))
                    {
                        availableIndexes = new Queue <int>();
                        availableModelPreviews.Add(modelId, availableIndexes);
                    }
                    availableIndexes.Enqueue(bp.previewIndex);
                }

                bp.Free();
            }

            __instance.buildPreviews.Clear();

            var restored = 0;

            foreach (var bp in previews)
            {
                int modelId = bp.desc.modelIndex;
                if (availableModelPreviews.TryGetValue(modelId, out Queue <int> availableIndexes) && availableIndexes.Count > 0)
                {
                    restored++;
                    bp.previewIndex = availableIndexes.Dequeue();
                }
                __instance.AddBuildPreview(bp);
            }

            var removed = 0;

            foreach (var availableIndexes in availableModelPreviews.Values)
            {
                foreach (var previewIndex in availableIndexes)
                {
                    if (__instance.previewRenderers[previewIndex] != null)
                    {
                        removed++;
                        UnityEngine.Object.Destroy(__instance.previewRenderers[previewIndex].sharedMaterial);
                        __instance.previewRenderers[previewIndex].gameObject.SetActive(false);
                    }
                }
            }

            return(false);
        }
Пример #7
0
        public static bool PlayerAction_Build_BuildMainLogic_Prefix(ref PlayerAction_Build __instance)
        {
            if (__instance.handPrefabDesc == null ||
                __instance.handPrefabDesc.minerType != EMinerType.None ||
                __instance.player.planetData.type == EPlanetType.Gas ||
                BlueprintManager.data.copiedBuildings.Count > 1
                )
            {
                MultiBuild.multiBuildPossible = false;
            }
            else
            {
                MultiBuild.multiBuildPossible = true;
            }

            if (MultiBuild.itemSpecificSpacing.Value && __instance.handItem != null && MultiBuild.spacingIndex != __instance.handItem.ID)
            {
                MultiBuild.spacingIndex = __instance.handItem.ID;
                if (!MultiBuild.spacingStore.ContainsKey(MultiBuild.spacingIndex))
                {
                    MultiBuild.spacingStore[MultiBuild.spacingIndex] = 0;
                }
            }

            //long dbp, cbc,up,ug;

            runUpdate = true;
            //Stopwatch timer = new Stopwatch();
            //timer.Start();
            __instance.DetermineBuildPreviews();
            //timer.Stop();

            //dbp = timer.ElapsedTicks;

            if (runUpdate)
            {
                //timer.Reset();
                //timer.Start();
                var backupMechaBuildArea = __instance.player.mecha.buildArea;
                if (BlueprintManager.hasData)
                {
                    __instance.player.mecha.buildArea = 10000f;
                }

                if (BlueprintManager.pastedEntities.Count > 1)
                {
                    lastFlag = CheckBuildConditionsFast();
                }
                else
                {
                    lastFlag = __instance.CheckBuildConditions();
                }
                //timer.Stop();
                //cbc = timer.ElapsedTicks;

                //timer.Reset();
                //timer.Start();
                __instance.UpdatePreviews();
                //timer.Stop();
                //up = timer.ElapsedTicks;

                //timer.Reset();
                //timer.Start();
                __instance.UpdateGizmos();
                //timer.Stop();
                //ug = timer.ElapsedTicks;

                __instance.player.mecha.buildArea = backupMechaBuildArea;
                lastCursorText    = __instance.cursorText;
                lastCursorWarning = __instance.cursorWarning;


                //Debug.Log($"dbp: {dbp} | cbc: {cbc} | up: {up} | ug: {ug}");
            }
            else
            {
                __instance.cursorText    = lastCursorText;
                __instance.cursorWarning = lastCursorWarning;
            }

            if (lastFlag)
            {
                __instance.CreatePrebuilds();

                if (__instance.waitConfirm && VFInput._buildConfirm.onDown)
                {
                    __instance.ClearBuildPreviews();
                    BuildLogic.forceRecalculation = true;
                }
            }

            return(false);
        }
Пример #8
0
        public static void DetermineBuildPreviews(PlayerAction_Build _this)
        {
            if (AdvancedBuildDestruct.buildKeyUp)
            {
                AdvancedBuildDestruct.buildKeyUp = false;
                beginPos = _this.groundSnappedPos;
                begin    = !begin;
            }
            _this.waitConfirm = _this.cursorValid;
            int path  = 0;
            int count = 0;

            if (begin)
            {
                count = _this.planetAux.SnapLineNonAlloc(beginPos, _this.groundSnappedPos, ref path, snaps);
            }
            if (VFInput._tabKey.onDown)
            {
                _this.modelOffset++;
            }
            if (VFInput._rotate.onDown)
            {
                _this.yaw += 90f;
                _this.yaw  = Mathf.Repeat(_this.yaw, 360f);
                _this.yaw  = Mathf.Round(_this.yaw / 90f) * 90f;
            }
            if (VFInput._counterRotate.onDown)
            {
                _this.yaw -= 90f;
                _this.yaw  = Mathf.Repeat(_this.yaw, 360f);
                _this.yaw  = Mathf.Round(_this.yaw / 90f) * 90f;
            }
            if (_this.handPrefabDesc.minerType != EMinerType.Vein)
            {
                _this.yaw = Mathf.Round(_this.yaw / 90f) * 90f;
            }
            _this.multiLevelCovering   = false;
            _this.previewPose.position = _this.groundSnappedPos;
            _this.previewPose.rotation = Maths.SphericalRotation(_this.previewPose.position, _this.yaw);

            _this.ClearBuildPreviews();
            if (begin)
            {
                List <Vector3>      posList = new List <Vector3>();
                List <ColliderData> cList   = new List <ColliderData>();
                for (int i = 0; i < count; i++)
                {
                    var desc = _this.handPrefabDesc;
                    if (i > 0)
                    {
                        // 电力设备
                        // Debug.Log("判断电力设备");
                        float x   = posList[posList.Count - 1].x - snaps[i].x;
                        float y   = posList[posList.Count - 1].y - snaps[i].y;
                        float z   = posList[posList.Count - 1].z - snaps[i].z;
                        float dis = x * x + y * y + z * z;
                        if (dis < 12.25f)
                        {
                            continue;
                        }
                        if (desc.isPowerNode && !desc.isAccumulator)
                        {
                            if (desc.windForcedPower && dis < 110.25f)
                            {
                                continue;                                        // 风力发电机
                            }
                            if (_this.handItem.ModelIndex == 73 && dis < 110.25f)
                            {
                                continue;                                                   // 射线接收站
                            }
                        }

                        // 物流站
                        // Debug.Log("判断物流站");
                        if (desc.isStation)
                        {
                            float dis2 = (desc.isStellarStation) ? 841f : 225f;
                            if ((posList[posList.Count - 1] - snaps[i]).sqrMagnitude < dis2)
                            {
                                continue;
                            }
                        }
                        // 发射器
                        // Debug.Log("判断发射器");
                        if (desc.isEjector)
                        {
                            if (dis < 110.25f)
                            {
                                continue;
                            }
                        }
                        // 建造碰撞器
                        // Debug.Log("判断碰撞器");
                        if (desc.hasBuildCollider)
                        {
                            ColliderData c = desc.buildCollider;
                            c.pos = snaps[i] + Maths.SphericalRotation(snaps[i], _this.yaw) * c.pos;
                            c.q   = Maths.SphericalRotation(snaps[i], _this.yaw) * c.q;
                            if (_this.handItem.BuildMode == 1)
                            {
                                float mul = 1f;
                                if (_this.handItem.ModelIndex == 64)
                                {
                                    mul = 1.05f;
                                }
                                if (_this.handItem.ModelIndex == 54 || _this.handItem.ModelIndex == 118)
                                {
                                    if (!CheckBox(cList[cList.Count - 1], c))
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        if (dis < 16)
                                        {
                                            i++;
                                        }
                                    }
                                }
                                else if (!CheckBox(cList[cList.Count - 1], c, mul))
                                {
                                    // Debug.Log("因碰撞器跳过");
                                    continue;
                                }
                            }
                        }
                    }
                    i += AdvancedBuildDestruct.BuildExtraSpacing.Value;
                    _this.AddBuildPreview(BuildPreview.CreateSingle(_this.handItem, _this.handPrefabDesc, true));
                    posList.Add(snaps[i]);
                    if (desc.hasBuildCollider)
                    {
                        ColliderData c = desc.buildCollider;
                        c.pos = snaps[i] + Maths.SphericalRotation(snaps[i], _this.yaw) * c.pos;
                        c.q   = Maths.SphericalRotation(snaps[i], _this.yaw) * c.q;
                        cList.Add(c);
                    }
                }
                for (int i = 0; i < _this.buildPreviews.Count; i++)
                {
                    BuildPreview buildPreview = _this.buildPreviews[i];
                    buildPreview.ResetInfos();
                    buildPreview.item     = _this.handItem;
                    buildPreview.desc     = _this.handPrefabDesc;
                    buildPreview.recipeId = _this.copyRecipeId;
                    buildPreview.filterId = _this.copyFilterId;
                    buildPreview.lpos     = posList[i];
                    buildPreview.lrot     = Maths.SphericalRotation(posList[i], _this.yaw);
                }
            }
            else
            {
                _this.AddBuildPreview(BuildPreview.CreateSingle(_this.handItem, _this.handPrefabDesc, true));
                BuildPreview buildPreview = _this.buildPreviews[0];
                buildPreview.ResetInfos();
                buildPreview.item     = _this.handItem;
                buildPreview.desc     = _this.handPrefabDesc;
                buildPreview.recipeId = _this.copyRecipeId;
                buildPreview.filterId = _this.copyFilterId;
            }
        }
Пример #9
0
            /// <summary>
            /// Orignal PlayerAction_Build::DetermineDestructPreviews
            /// </summary>
            public static void CreateEntityUpgradePreview(
                PlayerAction_Build __instance,
                List <int> idList,
                List <EObjectType> typeList,
                DeterminePreviews.PreviewsFilter filter
                )
            {
                if (!VFInput.onGUI)
                {
                    if (__instance.upgradeLevel == 1)
                    {
                        UICursor.SetCursor(ECursor.Upgrade);
                    }
                    else if (__instance.upgradeLevel == -1)
                    {
                        UICursor.SetCursor(ECursor.Downgrade);
                    }
                }

                __instance.previewPose.position = Vector3.zero;
                __instance.previewPose.rotation = Quaternion.identity;

                __instance.ClearBuildPreviews();
                foreach (int entityId in idList)
                {
                    ItemProto itemProto  = (ItemProto)Traverse.Create(__instance).Method("GetItemProto", entityId).GetValue();
                    Pose      objectPose = (Pose)Traverse.Create(__instance).Method("GetObjectPose", entityId).GetValue();

                    bool flag = false;
                    if (itemProto != null && itemProto.Grade > 0 && itemProto.Upgrades.Length > 0)
                    {
                        flag = true;
                    }

                    if (flag &&
                        filter(itemProto) == false)
                    {
                        __instance.AddBuildPreview(new BuildPreview());

                        BuildPreview buildPreview = __instance.buildPreviews[__instance.buildPreviews.Count - 1];
                        buildPreview.item  = itemProto;
                        buildPreview.desc  = itemProto.prefabDesc;
                        buildPreview.lpos  = objectPose.position;
                        buildPreview.lrot  = objectPose.rotation;
                        buildPreview.objId = entityId;

                        if (buildPreview.desc.lodCount > 0 && buildPreview.desc.lodMeshes[0] != null)
                        {
                            buildPreview.needModel = true;
                        }
                        else
                        {
                            buildPreview.needModel = false;
                        }
                        buildPreview.isConnNode = true;

                        if (buildPreview.desc.isInserter)
                        {
                            Pose objectPose2 = (Pose)Traverse.Create(__instance).Method("GetObjectPose2", buildPreview.objId).GetValue();
                            //Oringal pose objectPose2 = __instance.GetObjectPose2(buildPreview.objId);
                            buildPreview.lpos2 = objectPose2.position;
                            buildPreview.lrot2 = objectPose2.rotation;
                        }
                        if ((double)(buildPreview.lpos - __instance.player.position).sqrMagnitude > (double)__instance.player.mecha.buildArea * (double)__instance.player.mecha.buildArea)
                        {
                            buildPreview.condition   = EBuildCondition.OutOfReach;
                            __instance.cursorText    = "目标超出范围".Translate();
                            __instance.cursorWarning = true;
                        }
                        else
                        {
                            buildPreview.condition = EBuildCondition.Ok;
                            __instance.cursorText  = "升级".Translate() + buildPreview.item.name + "\r\n" + "连锁升级提示".Translate();
                        }
                    }
                }
            }
Пример #10
0
            /// <summary>
            /// Orignal PlayerAction_Build::DetermineDestructPreviews
            /// </summary>
            public static void CreateEntityDestructPreview(
                PlayerAction_Build __instance,
                List <int> idList,
                List <EObjectType> typeList,
                DeterminePreviews.PreviewsFilter filter
                )
            {
                if (!VFInput.onGUI)
                {
                    UICursor.SetCursor(ECursor.Delete);
                }

                __instance.previewPose.position = Vector3.zero;
                __instance.previewPose.rotation = Quaternion.identity;

                __instance.ClearBuildPreviews();

                foreach (int entityId in idList)
                {
                    //int entityId = typeList[index] != EObjectType.Entity ? -entityIdList[index] : entityIdList[index];

                    ItemProto itemProto  = (ItemProto)Traverse.Create(__instance).Method("GetItemProto", entityId).GetValue();
                    Pose      objectPose = (Pose)Traverse.Create(__instance).Method("GetObjectPose", entityId).GetValue();

                    if (itemProto != null &&
                        filter(itemProto) == false)
                    {
                        //Add Build Preview
                        __instance.AddBuildPreview(new BuildPreview());

                        BuildPreview buildPreview = __instance.buildPreviews[__instance.buildPreviews.Count - 1];
                        buildPreview.item  = itemProto;
                        buildPreview.desc  = itemProto.prefabDesc;
                        buildPreview.lpos  = objectPose.position;
                        buildPreview.lrot  = objectPose.rotation;
                        buildPreview.objId = entityId;

                        int num = buildPreview.desc.lodCount <= 0 ? 0 : ((Object)buildPreview.desc.lodMeshes[0] != (Object)null ? 1 : 0);
                        buildPreview.needModel  = num != 0;
                        buildPreview.isConnNode = true;

                        if (buildPreview.desc.isInserter)
                        {
                            Pose objectPose2 = (Pose)Traverse.Create(__instance).Method("GetObjectPose2", buildPreview.objId).GetValue();
                            buildPreview.lpos2 = objectPose2.position;
                            buildPreview.lrot2 = objectPose2.rotation;
                        }

                        PlanetData planetData = __instance.player.planetData;
                        Vector3    vector3_1  = __instance.player.position;

                        if (planetData.type == EPlanetType.Gas)
                        {
                            vector3_1 = vector3_1.normalized;
                            Vector3 vector3_2 = vector3_1 * planetData.realRadius;
                        }
                        else
                        {
                            buildPreview.condition = EBuildCondition.Ok;
                            __instance.cursorText  = "拆除".Translate() + buildPreview.item.name + "\r\n" + "连锁拆除提示".Translate();
                        }

                        if (buildPreview.desc.multiLevel)
                        {
                            int           otherObjId;
                            PlanetFactory factory = Traverse.Create((object)__instance).Field("factory").GetValue <PlanetFactory>();
                            factory.ReadObjectConn(buildPreview.objId, 15, out bool _, out otherObjId, out int _);
                            if ((uint)otherObjId > 0U)
                            {
                                buildPreview.condition = EBuildCondition.Covered;
                                __instance.cursorText  = buildPreview.conditionText;
                            }
                        }
                    }
                }
            }
Пример #11
0
        public static bool PlayerAction_Build_DetermineBuildPreviews_Prefix(ref PlayerAction_Build __instance)
        {
            if (__instance.controller.cmd.mode != 1 ||
                __instance.player.planetData.type == EPlanetType.Gas ||
                !__instance.cursorValid ||
                __instance.groundSnappedPos == Vector3.zero ||
                (__instance.handPrefabDesc != null && __instance.handPrefabDesc.minerType != EMinerType.None)
                )
            {
                if (!lastRunOriginal)
                {
                    __instance.ClearBuildPreviews();
                }
                lastRunOriginal = true;
                return(true);
            }

            __instance.waitConfirm        = __instance.cursorValid;
            __instance.multiLevelCovering = false;
            if (__instance.handPrefabDesc != null && __instance.handPrefabDesc.multiLevel)
            {
                int objectProtoId = __instance.GetObjectProtoId(__instance.castObjId);
                if (objectProtoId == __instance.handItem.ID)
                {
                    __instance.multiLevelCovering = true;
                }
            }

            if (!IsMultiBuildRunning() && (__instance.multiLevelCovering || !BlueprintManager.hasData))
            {
                if (!lastRunOriginal)
                {
                    __instance.ClearBuildPreviews();
                }
                lastRunOriginal = true;
                return(true);
            }

            // full hijacking of DetermineBuildPreviews

            if (VFInput._switchSplitter.onDown)
            {
                __instance.modelOffset++;
                forceRecalculation = true;
            }

            if (VFInput._rotate.onDown)
            {
                __instance.yaw    += 90f;
                __instance.yaw     = Mathf.Repeat(__instance.yaw, 360f);
                __instance.yaw     = Mathf.Round(__instance.yaw / 90f) * 90f;
                forceRecalculation = true;
            }
            if (VFInput._counterRotate.onDown)
            {
                __instance.yaw    -= 90f;
                __instance.yaw     = Mathf.Repeat(__instance.yaw, 360f);
                __instance.yaw     = Mathf.Round(__instance.yaw / 90f) * 90f;
                forceRecalculation = true;
            }

            __instance.yaw = Mathf.Round(__instance.yaw / 90f) * 90f;
            __instance.previewPose.position = Vector3.zero;
            __instance.previewPose.rotation = Quaternion.identity;

            if (lastPosition == __instance.groundSnappedPos && !forceRecalculation)
            {
                // no update necessary
                runUpdate       = false;
                lastRunOriginal = false;
                return(false);
            }
            lastPosition       = __instance.groundSnappedPos;
            forceRecalculation = false;

            if (lastRunOriginal)
            {
                __instance.ClearBuildPreviews();
            }
            BlueprintManager.PreparePaste();
            if (IsMultiBuildRunning())
            {
                if (!BlueprintManager.hasData)
                {
                    BlueprintManager.data.copiedBuildings.Add(new BuildingCopy()
                    {
                        originalId = 0,
                        itemProto  = __instance.handItem,
                        recipeId   = __instance.copyRecipeId,
                        modelIndex = __instance.handPrefabDesc.modelIndex
                    });
                }
                var building = BlueprintManager.data.copiedBuildings[0];// BlueprintManager.data.copiedBuildings.First();

                int snapPath = path;

                var snappedPointCount = __instance.planetAux.SnapLineNonAlloc(startPos, __instance.groundSnappedPos, ref snapPath, snaps);

                var        desc            = BlueprintManager.GetPrefabDesc(building);
                var        pastedPositions = new List <Vector3>();
                Collider[] colliders       = new Collider[desc.buildColliders.Length];

                var copiesCounter = 0;
                for (int s = 0; s < snappedPointCount; s++)
                {
                    var pos = snaps[s];
                    var rot = Maths.SphericalRotation(snaps[s], __instance.yaw + building.cursorRelativeYaw);

                    if (s > 0)
                    {
                        var sqrDistance = (pastedPositions.Last() - pos).sqrMagnitude;

                        // power towers
                        if (desc.isPowerNode && !desc.isAccumulator && sqrDistance < 12.25f)
                        {
                            continue;
                        }

                        // wind turbines
                        if (desc.windForcedPower && sqrDistance < 110.25f)
                        {
                            continue;
                        }

                        // ray receivers
                        if (desc.gammaRayReceiver && sqrDistance < 110.25f)
                        {
                            continue;
                        }

                        // logistic stations
                        if (desc.isStation && sqrDistance < (desc.isStellarStation ? 841f : 225f))
                        {
                            continue;
                        }

                        // ejector
                        if (desc.isEjector && sqrDistance < 110.25f)
                        {
                            continue;
                        }

                        if (desc.hasBuildCollider)
                        {
                            var foundCollision = false;
                            for (var j = 0; j < desc.buildColliders.Length && !foundCollision; j++)
                            {
                                var colliderData = desc.buildColliders[j];
                                colliderData.pos = pos + rot * colliderData.pos;
                                colliderData.q   = rot * colliderData.q;
                                // check only collision with layer 27 (the layer used by the our own building colliders for the previously 'placed' building)
                                foundCollision = Physics.CheckBox(colliderData.pos, colliderData.ext, colliderData.q, 134217728, QueryTriggerInteraction.Collide);
                            }

                            if (foundCollision)
                            {
                                continue;
                            }
                        }
                    }


                    if (s > 0 && spacingStore[spacingIndex] > 0 && copiesCounter % spacingPeriod == 0)
                    {
                        s += spacingStore[spacingIndex];
                        if (s >= snappedPointCount)
                        {
                            break;
                        }
                        pos = snaps[s];
                        rot = Maths.SphericalRotation(snaps[s], __instance.yaw + building.cursorRelativeYaw);
                    }

                    BlueprintManager.Paste(pos, __instance.yaw, false, pastedPositions.Count);
                    pastedPositions.Add(pos);

                    if (desc.hasBuildCollider)
                    {
                        for (var j = 0; j < desc.buildColliders.Length; j++)
                        {
                            // create temporary collider entities for the latest 'positioned' building
                            if (colliders[j] != null)
                            {
                                ColliderPool.PutCollider(colliders[j]);
                            }

                            var colliderData = desc.buildColliders[j];
                            colliderData.pos = pos + rot * colliderData.pos;
                            colliderData.q   = rot * colliderData.q;
                            colliders[j]     = ColliderPool.TakeCollider(colliderData);
                            colliders[j].gameObject.layer = 27;
                        }
                    }
                }
                if (multiBuildInserters)
                {
                    for (var i = 0; i < pastedPositions.Count; i++)
                    {
                        BlueprintManager.PasteInsertersOnly(pastedPositions[i], __instance.yaw, i, true);
                    }
                }

                if (!BlueprintManager.hasData)
                {
                    BlueprintManager.data.copiedBuildings.RemoveAt(0);
                }
                foreach (var collider in colliders)
                {
                    if (collider != null)
                    {
                        ColliderPool.PutCollider(collider);
                    }
                }
            }
            else
            {
                var pasteInserters = multiBuildInserters || (BlueprintManager.data.copiedBuildings.Count + BlueprintManager.data.copiedBelts.Count > 1);
                BlueprintManager.Paste(__instance.groundSnappedPos, __instance.yaw, pasteInserters);
            }
            BlueprintManager.AfterPaste();

            lastRunOriginal = false;
            return(false);
        }
Пример #12
0
        public static bool BuildMainLogic_Prefix(ref PlayerAction_Build __instance)
        {
            if (__instance.handPrefabDesc == null ||
                __instance.handPrefabDesc.minerType != EMinerType.None ||
                __instance.player.planetData.type == EPlanetType.Gas
                )
            {
                MultiBuild.multiBuildPossible = false;
            }
            else
            {
                MultiBuild.multiBuildPossible = true;
            }

            if (MultiBuild.itemSpecificSpacing.Value && __instance.handItem != null && MultiBuild.spacingIndex != __instance.handItem.ID)
            {
                MultiBuild.spacingIndex = __instance.handItem.ID;
                if (!MultiBuild.spacingStore.ContainsKey(MultiBuild.spacingIndex))
                {
                    MultiBuild.spacingStore[MultiBuild.spacingIndex] = 0;
                }
            }

            // As multibuild increase calculation exponentially (collision and rendering must be performed for every entity), we hijack the BuildMainLogic
            // and execute the relevant submethods only when needed
            executeBuildUpdatePreviews = true;

            /* if (MultiBuild.IsMultiBuildRunning())
             * {
             *   if (lastPosition != __instance.groundSnappedPos)
             *   {
             *       lastPosition = __instance.groundSnappedPos;
             *       executeBuildUpdatePreviews = true;
             *   }
             *   else
             *   {
             *       executeBuildUpdatePreviews = false;
             *   }
             * }
             * else
             * {
             *   lastPosition = Vector3.zero;
             * }*/

            // Run the preview methods if we have changed position, if we have received a relevant keyboard input or in any case every MAX_IGNORED_TICKS ticks.
            executeBuildUpdatePreviews = true; // executeBuildUpdatePreviews || VFInput._rotate || VFInput._counterRotate || ignoredTicks >= MultiBuild.MAX_IGNORED_TICKS;

            bool flag;

            if (executeBuildUpdatePreviews)
            {
                __instance.DetermineBuildPreviews();
                flag = __instance.CheckBuildConditions();
                __instance.UpdatePreviews();
                __instance.UpdateGizmos();

                lastCursorText    = __instance.cursorText;
                lastCursorWarning = __instance.cursorWarning;
                lastFlag          = flag;

                ignoredTicks = 0;
            }
            else
            {
                __instance.cursorText    = lastCursorText;
                __instance.cursorWarning = lastCursorWarning;
                flag = lastFlag;
                ignoredTicks++;
            }

            if (flag)
            {
                __instance.CreatePrebuilds();

                if (__instance.waitConfirm && VFInput._buildConfirm.onDown)
                {
                    __instance.ClearBuildPreviews();
                    ignoredTicks = MultiBuild.MAX_IGNORED_TICKS;
                }
            }

            return(false);
        }