Skip to content

Commit

Permalink
Started work on the mod
Browse files Browse the repository at this point in the history
Working on new mod to allow for land claiming whilst being open
compatible with other mods using interfaces
  • Loading branch information
NimbusFox committed Feb 24, 2018
1 parent de30b06 commit 0162afb
Show file tree
Hide file tree
Showing 17 changed files with 510 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Staxel-FoxCore"]
path = Staxel-FoxCore
url = https://github.com/NimbusFox/Staxel-FoxCore.git
14 changes: 14 additions & 0 deletions NimbusFox.LandClaim.Interfaces/ILandClaim.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Plukit.Base;
using Staxel.Logic;

namespace NimbusFox.LandClaim.Interfaces {
public interface ILandClaim {
void AddPos1(Entity entity, Vector3D position);
void AddPos2(Entity entity, Vector3D position);
void Confirm(Entity entity);
void Clear(Entity entity);
void Purge(Entity entity);
void ToggleAdmin(Entity entity);
bool IsInArea(Entity entity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{929DA8AE-B4CA-4294-B66D-23656978EB1D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NimbusFox.LandClaim.Interfaces</RootNamespace>
<AssemblyName>NimbusFox.LandClaim.Interfaces</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL" />
<Reference Include="Plukit.Base">
<HintPath>..\..\..\Steam\steamapps\common\Staxel\bin\Plukit.Base.dll</HintPath>
</Reference>
<Reference Include="Staxel">
<HintPath>..\..\..\Steam\steamapps\common\Staxel\bin\Staxel.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ILandClaim.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Staxel-FoxCore\NimbusFox.FoxCore.csproj">
<Project>{8b473a82-8c34-44ea-b13d-39d0418e021f}</Project>
<Name>NimbusFox.FoxCore</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Classes\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
36 changes: 36 additions & 0 deletions NimbusFox.LandClaim.Interfaces/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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("NimbusFox.LandClaim.Interfaces")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NimbusFox.LandClaim.Interfaces")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[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("929da8ae-b4ca-4294-b66d-23656978eb1d")]

// 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")]
12 changes: 12 additions & 0 deletions NimbusFox.LandClaim.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ VisualStudioVersion = 15.0.27130.2036
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NimbusFox.LandClaim", "NimbusFox.LandClaim\NimbusFox.LandClaim.csproj", "{7959CC4B-9400-4B14-ACCE-9E1527EBBBE8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NimbusFox.LandClaim.Interfaces", "NimbusFox.LandClaim.Interfaces\NimbusFox.LandClaim.Interfaces.csproj", "{929DA8AE-B4CA-4294-B66D-23656978EB1D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NimbusFox.FoxCore", "Staxel-FoxCore\NimbusFox.FoxCore.csproj", "{8B473A82-8C34-44EA-B13D-39D0418E021F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +19,14 @@ Global
{7959CC4B-9400-4B14-ACCE-9E1527EBBBE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7959CC4B-9400-4B14-ACCE-9E1527EBBBE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7959CC4B-9400-4B14-ACCE-9E1527EBBBE8}.Release|Any CPU.Build.0 = Release|Any CPU
{929DA8AE-B4CA-4294-B66D-23656978EB1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{929DA8AE-B4CA-4294-B66D-23656978EB1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{929DA8AE-B4CA-4294-B66D-23656978EB1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{929DA8AE-B4CA-4294-B66D-23656978EB1D}.Release|Any CPU.Build.0 = Release|Any CPU
{8B473A82-8C34-44EA-B13D-39D0418E021F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B473A82-8C34-44EA-B13D-39D0418E021F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B473A82-8C34-44EA-B13D-39D0418E021F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B473A82-8C34-44EA-B13D-39D0418E021F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
12 changes: 0 additions & 12 deletions NimbusFox.LandClaim/Class1.cs

This file was deleted.

20 changes: 20 additions & 0 deletions NimbusFox.LandClaim/Classes/ClaimAreaV1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NimbusFox.FoxCore.Classes;

namespace NimbusFox.LandClaim.Classes {
public class ClaimAreaV1 {
public string OwnerUid { get; set; }
public string OwnerName { get; set; }
public VectorSquareI Area { get; set; }
public List<string> Guests { get; set; }
public bool IsAdminArea { get; set; }

public ClaimAreaV1() {
Guests = new List<string>();
}
}
}
21 changes: 21 additions & 0 deletions NimbusFox.LandClaim/Classes/ClaimDataV1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NimbusFox.FoxCore.Classes;
using Staxel.Logic;

namespace NimbusFox.LandClaim.Classes {
public class ClaimDataV1 {
public List<ClaimAreaV1> ClaimedAreas { get; set; }

public ClaimDataV1() {
ClaimedAreas = new List<ClaimAreaV1>();
}

public List<ClaimAreaV1> CloneClaimedAreas() {
return new List<ClaimAreaV1>(ClaimedAreas);
}
}
}
13 changes: 13 additions & 0 deletions NimbusFox.LandClaim/Classes/Positions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Plukit.Base;

namespace NimbusFox.LandClaim.Classes {
public class Positions {
public Vector3D Start { get; set; }
public Vector3D End { get; set; }
}
}
17 changes: 17 additions & 0 deletions NimbusFox.LandClaim/Classes/TempData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NimbusFox.FoxCore.Classes;
using Staxel.Logic;

namespace NimbusFox.LandClaim.Classes {
public class TempData {
public Dictionary<Entity, Positions> ClaimMarkers = new Dictionary<Entity, Positions>();

public Dictionary<Entity, Positions> CloneMarkers() {
return new Dictionary<Entity, Positions>(ClaimMarkers);
}
}
}
109 changes: 109 additions & 0 deletions NimbusFox.LandClaim/LandManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using NimbusFox.FoxCore;
using NimbusFox.LandClaim.Classes;
using NimbusFox.LandClaim.Interfaces;
using Plukit.Base;
using Staxel.Logic;

namespace NimbusFox.LandClaim {
public class LandManager : ILandClaim {
internal static FxCore FoxCore { get; } = new FxCore("NimbusFox", "LandClaim", "v0.1");
internal static TempData TempData { get; set; }
internal static ClaimDataV1 ClaimData { get; set; }
private const string ClaimFile = "LC.db";

internal static void Init() {
TempData = new TempData();

if (!FoxCore.FileManager.FileExists(ClaimFile)) {
ClaimData = new ClaimDataV1();
Flush();
} else {
var data = FoxCore.FileManager.ReadFile<object>(ClaimFile);

ClaimData = JsonConvert.DeserializeObject<ClaimDataV1>(JsonConvert.SerializeObject(data));
}
}

private static void Flush() {
FoxCore.FileManager.WriteFile(ClaimFile, ClaimData);
}

internal static void CheckPlayerMarkers(Entity entity) {
if (entity != null) {
if (!TempData.CloneMarkers().ContainsKey(entity)) {
TempData.ClaimMarkers.Add(entity, new Positions());
}
}
}

internal static void _AddPos1(Entity entity, Vector3D position) {
CheckPlayerMarkers(entity);

TempData.ClaimMarkers[entity].Start = position;
}

public void AddPos1(Entity entity, Vector3D position) {
_AddPos1(entity, position);
}

internal static void _AddPos2(Entity entity, Vector3D position) {
CheckPlayerMarkers(entity);

TempData.ClaimMarkers[entity].End = position;
}

public void AddPos2(Entity entity, Vector3D position) {
_AddPos2(entity, position);
}

internal static void _Confirm(Entity entity) {
Flush();
}

public void Confirm(Entity entity) {
_Confirm(entity);
}

internal static void _Clear(Entity entity) {
if (TempData.CloneMarkers().Any(x => x.Key == entity)) {
TempData.ClaimMarkers.Remove(entity);
}
}

public void Clear(Entity entity) {
_Clear(entity);
}

internal static void _Purge(Entity entity) {
var target = ClaimData.CloneClaimedAreas().FirstOrDefault(x => x.OwnerUid == entity.PlayerEntityLogic.Uid());
if (target != null) {
ClaimData.ClaimedAreas.Remove(target);
Flush();
}
}

public void Purge(Entity entity) {
_Purge(entity);
}

public void ToggleAdmin(Entity entity) { }

internal static bool _IsInArea(Entity entity) {
return ClaimData.ClaimedAreas.Any(x => x.Area.IsInside(entity.Physics.Position));
}

public bool IsInArea(Entity entity) {
return _IsInArea(entity);
}

internal static ClaimAreaV1 GetArea(Entity entity) {
return ClaimData.CloneClaimedAreas().FirstOrDefault(x => _IsInArea(entity));
}
}
}
Loading

0 comments on commit 0162afb

Please sign in to comment.