コード例 #1
0
        public static void OnDismantle(BuildTool_Dismantle __instance)
        {
            if (UndoManager.IgnoreAllEvents.Value)
            {
                return;
            }
            if (NebulaModAPI.IsMultiplayerActive)
            {
                if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
                {
                    return;
                }
            }

            List <int> objectIds = __instance.DetermineDismantle().ToList();

            if (objectIds.Count <= 0)
            {
                return;
            }

            BlueprintData blueprint = UndoUtils.GenerateBlueprint(objectIds, out Vector3 position);

            if (blueprint.buildings.Length > 0 && !position.Equals(Vector3.zero))
            {
                PlayerUndo data = UndoManager.GetCurrentPlayerData();
                data.AddUndoItem(new UndoDismantle(data, objectIds, blueprint, new[] { position }, 0));
            }
        }
コード例 #2
0
ファイル: BuildTools_Patch.cs プロジェクト: kremnev8/DSP-Mods
        public static void OnPaste(BuildTool_BlueprintPaste __instance)
        {
            if (UndoManager.IgnoreAllEvents.Value)
            {
                return;
            }
            if (NebulaModAPI.IsMultiplayerActive)
            {
                if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
                {
                    return;
                }
            }

            List <int> objectIds = new List <int>(__instance.bpCursor);

            for (int l = 0; l < __instance.bpCursor; l++)
            {
                BuildPreview preview = __instance.bpPool[l];
                objectIds.Add(preview.objId);
            }

            Vector3[] dots = new Vector3[__instance.dotsCursor];
            Array.Copy(__instance.dotsSnapped, dots, __instance.dotsCursor);

            PlayerUndo    data = UndoManager.GetCurrentPlayerData();
            UndoBlueprint undo = new UndoBlueprint(data, objectIds, __instance.blueprint, dots, __instance.yaw);

            data.AddUndoItem(undo);
        }
コード例 #3
0
ファイル: BuildTools_Patch.cs プロジェクト: kremnev8/DSP-Mods
        public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            CodeMatcher matcher = new CodeMatcher(instructions)
                                  .End().MatchBack(false,
                                                   new CodeMatch(OpCodes.Ldarg_0),
                                                   new CodeMatch(OpCodes.Call, AccessTools.PropertyGetter(typeof(BuildTool), nameof(BuildTool.buildPreviews))),
                                                   new CodeMatch(OpCodes.Callvirt))
                                  .Advance(1)
                                  .InsertAndAdvance(Transpilers.EmitDelegate <Action <BuildTool_Inserter> >(tool =>
            {
                if (UndoManager.IgnoreAllEvents.Value)
                {
                    return;
                }
                if (NebulaModAPI.IsMultiplayerActive)
                {
                    if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
                    {
                        return;
                    }
                }

                IEnumerable <int> objectIds = tool.buildPreviews.Select(preview => preview.objId);

                PlayerUndo data = UndoManager.GetCurrentPlayerData();
                data.AddUndoItem(new UndoBuild(data, objectIds));
            }))
                                  .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0));

            return(matcher.InstructionEnumeration());
        }
コード例 #4
0
ファイル: BuildTools_Patch.cs プロジェクト: kremnev8/DSP-Mods
        public static void OnPathAddonBuilt(BuildTool_PathAddon __instance)
        {
            if (UndoManager.IgnoreAllEvents.Value)
            {
                return;
            }
            if (NebulaModAPI.IsMultiplayerActive)
            {
                if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
                {
                    return;
                }
            }

            PlayerUndo data = UndoManager.GetCurrentPlayerData();

            data.AddUndoItem(new UndoPathAddon(data, __instance.handbp.objId));
        }
コード例 #5
0
        public static void OnDoUpgragePost()
        {
            if (NebulaModAPI.IsMultiplayerActive)
            {
                IMultiplayerSession session = NebulaModAPI.MultiplayerSession;
                if (session.LocalPlayer.IsClient)
                {
                    session.Network.SendPacket(new ClearUndoRequestPacket(session.LocalPlayer.Id));
                    UIRealtimeTip.Popup("UndoClearedMessage".Translate(), false);
                    VFAudio.Create("cancel-0", null, Vector3.zero, true, 4);
                    return;
                }
            }

            PlayerUndo data = UndoManager.GetPlayerData(UndoManager.GetLocalUserId());

            data.ResetUndo();
        }
コード例 #6
0
ファイル: BuildTools_Patch.cs プロジェクト: kremnev8/DSP-Mods
        public static void OnClickBuilt(BuildTool_Click __instance)
        {
            if (UndoManager.IgnoreAllEvents.Value)
            {
                return;
            }
            if (NebulaModAPI.IsMultiplayerActive)
            {
                if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
                {
                    return;
                }
            }

            IEnumerable <int> objectIds = __instance.buildPreviews.Select(preview => preview.objId);

            PlayerUndo data = UndoManager.GetCurrentPlayerData();

            data.AddUndoItem(new UndoBuild(data, objectIds));
        }
コード例 #7
0
        public static void OnUpgradePost(BuildTool_Upgrade __instance)
        {
            if (UndoManager.IgnoreAllEvents.Value)
            {
                return;
            }

            if (NebulaModAPI.IsMultiplayerActive)
            {
                if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient)
                {
                    return;
                }
            }

            RecordUpgrades = false;

            if (upgradeList.Count > 0)
            {
                PlayerUndo data = UndoManager.GetCurrentPlayerData();
                data.AddUndoItem(new UndoUpgrade(data, upgradeList));
            }
        }
コード例 #8
0
 public UndoBlueprint(PlayerUndo undoData, IEnumerable <int> objectIds, BlueprintData blueprint, Vector3[] dotsSnapped, float yaw) : base(undoData, objectIds)
 {
     this.blueprint   = blueprint;
     this.dotsSnapped = dotsSnapped;
     this.yaw         = yaw;
 }
コード例 #9
0
 public UndoBuild(PlayerUndo undoData, IEnumerable <int> objectIds) : base(undoData)
 {
     this.objectIds = new List <int>(objectIds);
 }
コード例 #10
0
 public UndoBuild(PlayerUndo undoData, int objectId) : base(undoData)
 {
     objectIds = new List <int> {
         objectId
     };
 }
コード例 #11
0
 public UndoPathAddon(PlayerUndo undoData, int objectId) : base(undoData, objectId)
 {
 }
コード例 #12
0
 private UndoPathAddon(PlayerUndo undoData, IEnumerable <int> objectIds) : base(undoData, objectIds)
 {
 }
コード例 #13
0
ファイル: UndoDismantle.cs プロジェクト: kremnev8/DSP-Mods
 public UndoDismantle(PlayerUndo undoData, IEnumerable <int> objectIds, BlueprintData blueprint, Vector3[] dotsSnapped, float yaw)
     : base(undoData, objectIds, blueprint, dotsSnapped, yaw)
 {
 }
コード例 #14
0
ファイル: UndoUpgrade.cs プロジェクト: kremnev8/DSP-Mods
 public UndoUpgrade(PlayerUndo undoData, IEnumerable <UpgradeData> targets) : base(undoData)
 {
     this.targets = new List <UpgradeData>(targets);
 }