-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPlacementBoardRelocatable.cs
More file actions
45 lines (38 loc) · 1.5 KB
/
IPlacementBoardRelocatable.cs
File metadata and controls
45 lines (38 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using Assets.Scripts.Inventory;
using Assets.Scripts.Objects;
namespace LibConstruct;
public interface IPlacementBoardRelocatable : IPlacementBoardStructure, IReferencable
{
public Thing GetAsThing { get; } // from Thing
public Structure AsStructure { get; } // from Thing
// called when this structure is relocated
public void OnStructureRelocated();
}
public static class BoardRelocateHooks
{
// called like:
// if (attack.SourceItem is MyRelocateTool myTool)
// return BoardRelocateHooks.StructureAttackWith(this, attack, doAction, BoardRelocateHooks.NormalToolRelocateContinue(myTool));
public static Thing.DelayedActionInstance StructureAttackWith(IPlacementBoardRelocatable structure, Attack attack, bool doAction, Func<bool> continueRelocating = null)
{
// mark the current attack as a relocate start attack so we process it on the client
InventoryManagerPatch.IsRelocateAttack = true;
var action = new Thing.DelayedActionInstance
{
Duration = 0f,
ActionMessage = CustomGameStrings.BoardStructureRelocateAction,
};
if (doAction && PlacementBoard.RelocateMouseReleased)
PlacementBoard.StartRelocate(structure, continueRelocating);
return action.Succeed();
}
public static Func<bool> NormalToolRelocateContinue(DynamicThing tool)
{
return () =>
tool &&
InventoryManager.ActiveHandSlot.Get() == tool &&
InventoryManager.CurrentMode == InventoryManager.Mode.Normal &&
!KeyManager.GetMouseDown("Secondary");
}
}