Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.

Commit 283714d

Browse files
committed
Update to 0.5.2.1
1 parent b861166 commit 283714d

File tree

6 files changed

+32
-102
lines changed

6 files changed

+32
-102
lines changed
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using FacilityManager;
22
using FacilityManager.Behaviours;
33
using FacilityManager.Server;
4+
using MoreCommands_Plugin.Items;
45

56
namespace MoreCommands_Plugin.Commands
67
{
@@ -17,21 +18,19 @@ public override void Execute(CommandContext commandContext, CommandReader reader
1718
}
1819

1920
Player player = Context.PlayerSpawner.GetPlayer(commandContext.Sender);
20-
if (player.TryGetComponent(out HumanPlayer humanPlayer))
21+
if (!player.TryGetComponent(out HumanPlayer humanPlayer))
2122
{
22-
if (humanPlayer.Inventory.HasFreeSpace == false)
23-
commandContext.ResponseError("You don't have free space in inventory.\n");
24-
25-
ItemData itemData = new ItemData();
26-
itemData.SetInt("item_to_spawn", itemId);
23+
commandContext.ResponseError("Your player object doesn't have inventory.\n");
24+
}
2725

28-
humanPlayer.Inventory.AddItem(Context.ItemRegistry.GetItemInfo(2), itemData);
29-
commandContext.Response("Item spawner was added to your inventory.\n");
26+
if (!humanPlayer.Inventory.HasFreeSpace)
27+
commandContext.ResponseError("You don't have free space in inventory.\n");
3028

31-
return;
32-
}
29+
var metadata = new ModifiedKeycardMetadata();
30+
metadata.ItemToSpawn = itemId;
3331

34-
commandContext.ResponseError("Your player object doesn't have inventory.\n");
32+
humanPlayer.Inventory.AddItem(Context.ItemRegistry.GetItemInfo(2), metadata);
33+
commandContext.Response("Item spawner was added to your inventory.\n");
3534
}
3635
}
3736
}

MoreCommands-Plugin/Commands/SetLightColorCommand.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

MoreCommands-Plugin/Commands/SpawnItemCommand.cs

Lines changed: 0 additions & 46 deletions
This file was deleted.

MoreCommands-Plugin/Items/ModifiedKeycard.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
namespace MoreCommands_Plugin.Items
88
{
9+
public class ModifiedKeycardMetadata : ItemMetadata
10+
{
11+
public bool IsItemDefined => ItemToSpawn != -1;
12+
13+
public int ItemToSpawn = -1;
14+
}
15+
916
public class ModifiedKeycard : Keycard
1017
{
1118
public ModifiedKeycard(short varaintId) : base(varaintId)
@@ -15,13 +22,20 @@ public ModifiedKeycard(short varaintId) : base(varaintId)
1522
public override void OnUse(HumanPlayer player, ItemUseType useType)
1623
{
1724
base.OnUse(player, useType);
18-
ItemData itemData = GetItemData(player);
25+
var metadata = GetMetadata<ModifiedKeycardMetadata>(player);
1926

20-
if (itemData.GetInt("item_to_spawn", -1) == -1) return;
21-
GameObject prefab = Context.ItemRegistry.GetItemInfo(itemData.GetInt("item_to_spawn")).Prefab;
27+
if (metadata.IsItemDefined)
28+
{
29+
GameObject prefab = Context.ItemRegistry.GetItemInfo(metadata.ItemToSpawn).Prefab;
2230

23-
GameObject spawnedObject = Object.Instantiate(prefab, player.transform.position + Vector3.up, Quaternion.identity);
24-
NetworkServer.Spawn(spawnedObject);
31+
GameObject spawnedObject = Object.Instantiate(prefab, player.transform.position + Vector3.up, Quaternion.identity);
32+
NetworkServer.Spawn(spawnedObject);
33+
}
34+
}
35+
36+
public override ItemMetadata CreateMetadata()
37+
{
38+
return new ModifiedKeycardMetadata();
2539
}
2640
}
2741
}

MoreCommands-Plugin/MoreCommands-Plugin.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@
5555
<Compile Include="Commands\CloseDoorsCommand.cs" />
5656
<Compile Include="Commands\GiveItemSpawnerCommand.cs" />
5757
<Compile Include="Commands\OpenDoorsCommand.cs" />
58-
<Compile Include="Commands\SetLightColorCommand.cs" />
59-
<Compile Include="Commands\SpawnItemCommand.cs" />
6058
<Compile Include="Items\ModifiedKeycard.cs" />
6159
<Compile Include="MoreCommandsPlugin.cs" />
6260
<Compile Include="Properties\AssemblyInfo.cs" />

MoreCommands-Plugin/MoreCommandsPlugin.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@ public override PluginInfo GetInfo()
2020

2121
public override void Initialize(GameContext context)
2222
{
23-
var commandRegistry = context.GetController<CommandRegistry>();
23+
var commandRegistry = context.Get<CommandRegistry>();
2424

2525
commandRegistry.Register("addspeed", new AddSpeedCommand());
2626
commandRegistry.Register("addjump", new AddJumpHeightCommand());
2727
commandRegistry.Register("opendoors", new OpenDoorsCommand());
2828
commandRegistry.Register("closedoors", new CloseDoorsCommand());
2929
commandRegistry.Register("itemspawner", new GiveItemSpawnerCommand());
30-
commandRegistry.Register("spawnitem", new SpawnItemCommand());
31-
commandRegistry.Register("lightcolor", new SetLightColorCommand());
3230

33-
var itemRegistry = context.GetController<ItemRegistry>();
34-
itemRegistry.RegisterItem(2, new ModifiedKeycard(2));
31+
var itemRegistry = context.Get<ItemRegistry>();
32+
itemRegistry.RegisterItem(2, new ModifiedKeycard(1));
3533
}
3634
}
3735
}

0 commit comments

Comments
 (0)