Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

Commit

Permalink
VehicleHandler #12 - Fixing few ConsoleOutput bugs, Removing Comand m…
Browse files Browse the repository at this point in the history
…anager test function, Removing last Mapping tests
  • Loading branch information
Ruffo324 committed Jan 17, 2018
1 parent 372bd6e commit 36a3741
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 192 deletions.
15 changes: 9 additions & 6 deletions EvoMp/EvoMp.Core.ConsoleHandler/Server/ConsoleOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ public static void WriteLine(ConsoleType consoleType, string message, bool noWor
string messageStartColorCode = "";

// Search for message starting color code. Used to add same color code to splitted lines
List<string> messageColorCodes = ColorUtils.ParseColorCodesSimple(messages[0]);
if (messageColorCodes.Any())
messageStartColorCode = "~" + messageColorCodes[0] + "~";
if (messages.Any())
{
List<string> messageColorCodes = ColorUtils.ParseColorCodesSimple(messages[0]);
if (messageColorCodes.Any())
messageStartColorCode = "~" + messageColorCodes[0] + "~";
}

// Cut messages to fit in the console
for (int i = 0; i < messages.Length; i++)
Expand Down Expand Up @@ -331,9 +334,9 @@ private static void InternalWrite(ConsoleType consoleType, string message, bool
// Append message to complete message
writeMessage += message;

string fillUpString =
"".PadRight(ConsoleHandler.WindowWidth -
ColorUtils.CleanUp(writeMessage + suffix).Replace("\n", "").Length);
int fillUpLength = ConsoleHandler.WindowWidth -
ColorUtils.CleanUp(writeMessage + suffix).Replace("\n", "").Length;
string fillUpString = "".PadRight(fillUpLength > 0 ? fillUpLength : 0);

// Add suffixs and possible linebreak
writeMessage += "~;~" + fillUpString + suffix;
Expand Down
5 changes: 0 additions & 5 deletions EvoMp/EvoMp.Core.Module/EvoMp.Core.Module.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoMapper, Version=6.2.2.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.6.2.2\lib\net45\AutoMapper.dll</HintPath>
</Reference>
<Reference Include="BCrypt.Net, Version=0.1.5073.29922, Culture=neutral, PublicKeyToken=6bcd409ee6bc9292, processorArchitecture=MSIL">
<HintPath>..\packages\BCrypt-Official.0.1.109\lib\BCrypt.Net.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -80,8 +77,6 @@
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>
<ItemGroup>
<Compile Include="Server\Entity\BaseEntityDto.cs" />
<Compile Include="Server\Entity\BaseEntityMap.cs" />
<Compile Include="Server\ModuleProperties.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Server\Shared.cs" />
Expand Down
15 changes: 0 additions & 15 deletions EvoMp/EvoMp.Core.Module/Server/Entity/BaseEntityDto.cs

This file was deleted.

16 changes: 0 additions & 16 deletions EvoMp/EvoMp.Core.Module/Server/Entity/BaseEntityMap.cs

This file was deleted.

1 change: 0 additions & 1 deletion EvoMp/EvoMp.Core.Module/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="6.2.2" targetFramework="net461" />
<package id="BCrypt-Official" version="0.1.109" targetFramework="net461" />
<package id="EntityFramework" version="6.2.0" targetFramework="net461" />
<package id="grandtheftmultiplayer.api" version="0.1.640.64" targetFramework="net461" />
Expand Down
3 changes: 1 addition & 2 deletions EvoMp/EvoMp.Module.TestModule/EvoMp.Module.TestModule.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@
<Compile Include="Server\ITestModule.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Server\TestModule.cs" />
<Compile Include="Server\TestInitialized.cs" />
<Compile Include="Server\TestNotInitializedClass.cs" />
<Compile Include="Server\CommandTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EvoMp.Core.Module\EvoMp.Core.Module.csproj">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using EvoMp.Module.CommandHandler.Server.Attributes;
using EvoMp.Core.Module.Server;
using EvoMp.Module.CommandHandler.Server.Attributes;
using GrandTheftMultiplayer.Server.Elements;

namespace EvoMp.Module.TestModule.Server
{
public class TestInitialized
public class CommandTests
{
[PlayerCommand("/testDoubleCommandName")]
public void TestDoubleCommandName(Client sender)
Expand All @@ -24,5 +25,11 @@ public void TestDoubleCommandAlias(Client sender)
public void TestDoubleCommandAlias2(Client sender)
{
}

[PlayerCommand("/staticTest")]
public static void StaticTestFunction(Client sender)
{
Shared.Api.sendChatMessageToPlayer(sender, "Static command entered!");
}
}
}
}
50 changes: 40 additions & 10 deletions EvoMp/EvoMp.Module.TestModule/Server/TestModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class TestModule : ITestModule
{
private readonly API _api;
private readonly IVehicleHandler _vehicleHandler;
public TestInitialized TestInitialized = new TestInitialized();
public CommandTests TestInitialized = new CommandTests();

public TestModule(API api, ICommandHandler commandHandler, IVehicleHandler vehicleHandler)
{
Expand All @@ -24,26 +24,56 @@ public TestModule(API api, ICommandHandler commandHandler, IVehicleHandler vehic
public void TestCommand(Client sender)
{
_api.sendChatMessageToPlayer(sender, "Test command runned.");
_api.setEntityInvincible(sender, false);
_api.freezePlayer(sender, false);
_api.setEntityTransparency(sender, 255);
_api.setEntityCollisionless(sender, false);
}


[PlayerCommand("/v")]
public void TestVehicleCommand(Client sender, string vehicleName)
{
VehicleHash possibleVehicleHash = (VehicleHash) (-1);

// Name like
foreach (VehicleHash vehicleHash in Enum.GetValues(typeof(VehicleHash)))
if (vehicleName.ToLower() == $"{vehicleHash}".ToLower())
{
NetHandle newVehicle = _api.createVehicle(vehicleHash, sender.position, sender.rotation, 0, 0,
sender.dimension);
_api.setPlayerIntoVehicle(sender, newVehicle, -1);
_api.sendChatMessageToPlayer(sender, $"Vehicle ~o~{vehicleHash}~w~ created.");
possibleVehicleHash = vehicleHash;
break;
}

//Name starts with
if (possibleVehicleHash == (VehicleHash) (-1))
foreach (VehicleHash vehicleHash in Enum.GetValues(typeof(VehicleHash)))
if ($"{vehicleHash}".ToLower().StartsWith(vehicleName.ToLower()))
{
possibleVehicleHash = vehicleHash;
break;
}

// Create new Database vehicle entry
//ExtendedVehicle newTestVehicle = new ExtendedVehicle(vehicleHash, sender.position, sender.rotation);
// save enw Database vehcile entry
//newTestVehicle.Save();
}
//Name contains
if (possibleVehicleHash == (VehicleHash) (-1))
foreach (VehicleHash vehicleHash in Enum.GetValues(typeof(VehicleHash)))
if ($"{vehicleHash}".ToLower().Contains(vehicleName.ToLower()))
{
possibleVehicleHash = vehicleHash;
break;
}

// No vehicle found -> message & return
if (possibleVehicleHash == (VehicleHash) (-1))
{
_api.sendChatMessageToPlayer(sender, $"There is no vehicle like~o~{vehicleName}~w~ .");
return;
}

// Create new vehicle
NetHandle newVehicle = _api.createVehicle(possibleVehicleHash, sender.position, sender.rotation, 0, 0,
sender.dimension);
_api.setPlayerIntoVehicle(sender, newVehicle, -1);
_api.sendChatMessageToPlayer(sender, $"Vehicle ~o~{possibleVehicleHash}~w~ created.");
}
}
}
20 changes: 0 additions & 20 deletions EvoMp/EvoMp.Module.TestModule/Server/TestNotInitializedClass.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoMapper, Version=6.2.2.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.6.2.2\lib\net45\AutoMapper.dll</HintPath>
</Reference>
<Reference Include="BCrypt.Net, Version=0.1.5073.29922, Culture=neutral, PublicKeyToken=6bcd409ee6bc9292, processorArchitecture=MSIL">
<HintPath>..\packages\BCrypt-Official.0.1.109\lib\BCrypt.Net.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -65,7 +62,6 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Server\Entity\Mapping.cs" />
<Compile Include="Server\Entity\VehicleMap.cs" />
<Compile Include="Server\Entity\VehicleDto.cs" />
<Compile Include="Server\Entity\VehicleContext.cs" />
<Compile Include="Server\Entity\VehicleRepository.cs" />
Expand Down
51 changes: 26 additions & 25 deletions EvoMp/EvoMp.Module.VehicleHandler/Server/Entity/Mapping.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
using AutoMapper;
using GrandTheftMultiplayer.Shared.Math;

namespace EvoMp.Module.VehicleHandler.Server.Entity
{
public class Mapping : Profile
public class Mapping
{
public Mapping()
{
#region Vehicle Position & Rotation
// VehicleMap to VehicleDto
CreateMap<VehicleMap, VehicleDto>()
.ForMember(dest => dest.Position,
mapExpession => mapExpession.MapFrom(source => new Vector3(source.X, source.Y, source.Z)))
.ForMember(destination => destination.Rotation,
mapExpression => mapExpression.MapFrom(source => new Vector3(source.Xr, source.Yr, source.Zr)));

// VehicleDto to VehicleMap
CreateMap<VehicleDto, VehicleMap>()
.ForMember(destination => destination.X,
mapExpression => mapExpression.MapFrom(source => source.Position.X))
.ForMember(destination => destination.Y,
mapExpression => mapExpression.MapFrom(source => source.Position.Y))
.ForMember(destination => destination.Z,
mapExpression => mapExpression.MapFrom(source => source.Position.Z))
.ForMember(destination => destination.Xr,
mapExpression => mapExpression.MapFrom(source => source.Rotation.X))
.ForMember(destination => destination.Yr,
mapExpression => mapExpression.MapFrom(source => source.Rotation.Y))
.ForMember(destination => destination.Zr,
mapExpression => mapExpression.MapFrom(source => source.Rotation.Z));
#endregion //Vehicle Position & Rotation
//TODO: Remove if new solution works
/* #region Vehicle Position & Rotation
// VehicleMap to VehicleDto
CreateMap<VehicleMap, VehicleDto>()
.ForMember(dest => dest.Position,
mapExpession => mapExpession.MapFrom(source => new Vector3(source.X, source.Y, source.Z)))
.ForMember(destination => destination.Rotation,
mapExpression => mapExpression.MapFrom(source => new Vector3(source.Xr, source.Yr, source.Zr)));
// VehicleDto to VehicleMap
CreateMap<VehicleDto, VehicleMap>()
.ForMember(destination => destination.X,
mapExpression => mapExpression.MapFrom(source => source.Position.X))
.ForMember(destination => destination.Y,
mapExpression => mapExpression.MapFrom(source => source.Position.Y))
.ForMember(destination => destination.Z,
mapExpression => mapExpression.MapFrom(source => source.Position.Z))
.ForMember(destination => destination.Xr,
mapExpression => mapExpression.MapFrom(source => source.Rotation.X))
.ForMember(destination => destination.Yr,
mapExpression => mapExpression.MapFrom(source => source.Rotation.Y))
.ForMember(destination => destination.Zr,
mapExpression => mapExpression.MapFrom(source => source.Rotation.Z));
#endregion //Vehicle Position & Rotation
*/
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public VehicleContext() : base(Environment.GetEnvironmentVariable("NameOrConnect
}

// Tables
public DbSet<VehicleMap> Vehicles { get; set; }
public DbSet<VehicleDto> Vehicles { get; set; }

public void Init()
{
Expand Down
28 changes: 22 additions & 6 deletions EvoMp/EvoMp.Module.VehicleHandler/Server/Entity/VehicleDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,58 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using EvoMp.Core.Module.Server.Entity;
using EvoMp.Module.VehicleHandler.Server.Enum;
using GrandTheftMultiplayer.Shared;
using GrandTheftMultiplayer.Shared.Math;

namespace EvoMp.Module.VehicleHandler.Server.Entity
{
public class VehicleDto : BaseEntityDto
[Table("Vehicles")]
public class VehicleDto
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
[Required]
[Column("VehicleId")]
public int VehicleId { get; set; }

[Required]
[Column("VehicleHash")]
public VehicleHash VehicleHash { get; set; }

public Vector3 Position { get; set; }

public Vector3 Rotation { get; set; }

//public Vector3 Position { get; set; }
//public Vector3 Rotation { get; set; }
//public string PrimaryColorID { get; set; }
//public string SecondaryColorID { get; set; }

[Column("NumberplateValue")]
public string NumberplateValue { get; set; }

[Column("VehicleState")]
public VehicleState VehicleState { get; set; }

[Column("KmStand")]
public double KmStand { get; set; }

[Column("Fuel")]
public double Fuel { get; set; }

[Column("Dimension")]
public int Dimension { get; set; }

[Column("Health")]
public double Health { get; set; }

[Column("Locked")]
public bool Locked { get; set; }

[Column("EngineState")]
public EngineState EngineState { get; set; }

[Column("SirenState")]
public SirenState SirenState { get; set; }

[Column("SpecialLightState")]
public SpecialLightState SpecialLightState { get; set; }
}
}
Loading

0 comments on commit 36a3741

Please sign in to comment.