forked from mirrors/NBTExplorer
Re-exposed access to player manager. New example: GiveItem
This commit is contained in:
parent
6e40d89c35
commit
cfe59afc9e
7 changed files with 185 additions and 16 deletions
|
@ -11,8 +11,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GiveItem", "GiveItem\GiveIt
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoveSpawn", "MoveSpawn\MoveSpawn.csproj", "{15C04C0C-FD50-47E9-B62C-AA0A814189ED}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Skyscraper", "Skyscraper\Skyscraper.csproj", "{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Relight", "Relight\Relight.csproj", "{EBDD447B-01FA-4A29-B4AB-380EC4379B5F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maze", "Maze\Maze.csproj", "{62D70576-FE3A-4530-B283-889C14B52E9E}"
|
||||
|
@ -81,16 +79,6 @@ Global
|
|||
{15C04C0C-FD50-47E9-B62C-AA0A814189ED}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{15C04C0C-FD50-47E9-B62C-AA0A814189ED}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{15C04C0C-FD50-47E9-B62C-AA0A814189ED}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{83F55F54-7253-4B4D-BC37-E9D1CB63E0B8}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EBDD447B-01FA-4A29-B4AB-380EC4379B5F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
|
|
56
Substrate/SubstrateCS/Examples/GiveItem/GiveItem.csproj
Normal file
56
Substrate/SubstrateCS/Examples/GiveItem/GiveItem.csproj
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{426B01F4-B0C0-488E-8A5A-5531C8DFA98C}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>GiveItem</RootNamespace>
|
||||
<AssemblyName>GiveItem</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Substrate">
|
||||
<HintPath>..\..\bin\Release\Substrate.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
53
Substrate/SubstrateCS/Examples/GiveItem/Program.cs
Normal file
53
Substrate/SubstrateCS/Examples/GiveItem/Program.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using Substrate;
|
||||
|
||||
// This example will insert x amount of an item into a player's
|
||||
// inventory in an SMP server (where there is a player directory)
|
||||
|
||||
namespace GiveItem
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main (string[] args)
|
||||
{
|
||||
if (args.Length != 4) {
|
||||
Console.WriteLine("Usage: GiveItem <world> <player> <item-id> <cnt>");
|
||||
return;
|
||||
}
|
||||
|
||||
string dest = args[0];
|
||||
string player = args[1];
|
||||
int itemid = Convert.ToInt32(args[2]);
|
||||
int count = Convert.ToInt32(args[3]);
|
||||
|
||||
// Open the world and grab its player manager
|
||||
BetaWorld world = BetaWorld.Open(dest);
|
||||
PlayerManager pm = world.GetPlayerManager();
|
||||
|
||||
// Check that the named player exists
|
||||
if (!pm.PlayerExists(player)) {
|
||||
Console.WriteLine("No such player {0}!", player);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get player (returned object is independent of the playermanager)
|
||||
Player p = pm.GetPlayer(player);
|
||||
|
||||
// Find first slot to place item
|
||||
for (int i = 0; i < p.Items.Capacity; i++) {
|
||||
if (!p.Items.ItemExists(i)) {
|
||||
// Create the item and set its stack count
|
||||
Item item = new Item(itemid);
|
||||
item.Count = count;
|
||||
p.Items[i] = item;
|
||||
|
||||
// Don't keep adding items
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Save the player
|
||||
pm.SetPlayer(player, p);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("GiveItem")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("GiveItem")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("f1f9e364-dc96-4cce-b23d-42bc1234322d")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -16,6 +16,10 @@ namespace Substrate
|
|||
public PlayerFile (string path, string name)
|
||||
: base("")
|
||||
{
|
||||
if (!Directory.Exists(path)) {
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
string file = name + ".dat";
|
||||
_filename = Path.Combine(path, file);
|
||||
}
|
||||
|
|
|
@ -25,25 +25,25 @@ namespace Substrate.TileEntities
|
|||
public string Text1
|
||||
{
|
||||
get { return _text1; }
|
||||
set { _text1 = value.Substring(0, 12); }
|
||||
set { _text1 = value.Substring(0, 14); }
|
||||
}
|
||||
|
||||
public string Text2
|
||||
{
|
||||
get { return _text2; }
|
||||
set { _text2 = value.Substring(0, 12); }
|
||||
set { _text2 = value.Substring(0, 14); }
|
||||
}
|
||||
|
||||
public string Text3
|
||||
{
|
||||
get { return _text3; }
|
||||
set { _text3 = value.Substring(0, 12); }
|
||||
set { _text3 = value.Substring(0, 14); }
|
||||
}
|
||||
|
||||
public string Text4
|
||||
{
|
||||
get { return _text4; }
|
||||
set { _text4 = value.Substring(0, 12); }
|
||||
set { _text4 = value.Substring(0, 14); }
|
||||
}
|
||||
|
||||
public TileEntitySign ()
|
||||
|
|
|
@ -26,10 +26,13 @@ namespace Substrate
|
|||
|
||||
IChunkManager GetChunkManager ();
|
||||
IChunkManager GetChunkManager (int dim);
|
||||
|
||||
PlayerManager GetPlayerManager ();
|
||||
}
|
||||
|
||||
public class AlphaWorld : INBTWorld
|
||||
{
|
||||
private const string _PLAYER_DIR = "players";
|
||||
protected string _path;
|
||||
protected string _levelFile = "level.dat";
|
||||
|
||||
|
@ -38,6 +41,8 @@ namespace Substrate
|
|||
private Dictionary<int, ChunkFileManager> _chunkMgrs;
|
||||
private Dictionary<int, BlockManager> _blockMgrs;
|
||||
|
||||
private PlayerManager _playerMan;
|
||||
|
||||
private AlphaWorld ()
|
||||
{
|
||||
_chunkMgrs = new Dictionary<int, ChunkFileManager>();
|
||||
|
@ -76,6 +81,18 @@ namespace Substrate
|
|||
return _chunkMgrs[dim];
|
||||
}
|
||||
|
||||
public PlayerManager GetPlayerManager ()
|
||||
{
|
||||
if (_playerMan != null) {
|
||||
return _playerMan;
|
||||
}
|
||||
|
||||
string path = Path.Combine(_path, _PLAYER_DIR);
|
||||
|
||||
_playerMan = new PlayerManager(path);
|
||||
return _playerMan;
|
||||
}
|
||||
|
||||
public static AlphaWorld Open (string path)
|
||||
{
|
||||
return new AlphaWorld().OpenWorld(path) as AlphaWorld;
|
||||
|
@ -205,6 +222,7 @@ namespace Substrate
|
|||
|
||||
public class BetaWorld : INBTWorld {
|
||||
private const string _REGION_DIR = "region";
|
||||
private const string _PLAYER_DIR = "players";
|
||||
protected string _path;
|
||||
protected string _levelFile = "level.dat";
|
||||
|
||||
|
@ -214,6 +232,8 @@ namespace Substrate
|
|||
private Dictionary<int, ChunkManager> _chunkMgrs;
|
||||
private Dictionary<int, BlockManager> _blockMgrs;
|
||||
|
||||
private PlayerManager _playerMan;
|
||||
|
||||
private BetaWorld ()
|
||||
{
|
||||
_regionMgrs = new Dictionary<int, RegionManager>();
|
||||
|
@ -269,6 +289,18 @@ namespace Substrate
|
|||
return _regionMgrs[dim];
|
||||
}
|
||||
|
||||
public PlayerManager GetPlayerManager ()
|
||||
{
|
||||
if (_playerMan != null) {
|
||||
return _playerMan;
|
||||
}
|
||||
|
||||
string path = Path.Combine(_path, _PLAYER_DIR);
|
||||
|
||||
_playerMan = new PlayerManager(path);
|
||||
return _playerMan;
|
||||
}
|
||||
|
||||
public static BetaWorld Open (string path)
|
||||
{
|
||||
return new BetaWorld().OpenWorld(path) as BetaWorld;
|
||||
|
|
Loading…
Reference in a new issue