Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions SlipeServer.Console/Logic/ServerTestLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,39 @@ private void SetupTestCommands()
testobj2.AreCollisionsEnabled = true;
};

this.commandService.AddCommand("perennial").Triggered += (source, args) =>
{
new Vehicle(404, args.Player.Position).AssociateWith(server);
};

this.commandService.AddCommand("randomizecolor").Triggered += async (source, args) =>
{
var rnd = new Random();
var veh = args.Player.Vehicle;
if (veh == null)
return;

veh.Colors.Primary = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
veh.Colors.Secondary = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
bool a = false;
if (a)
{
veh.Colors.Color3 = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
veh.Colors.Color4 = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
}
else
{
veh.Colors.Color3 = null;
veh.Colors.Color4 = null;
}
};

this.commandService.AddCommand("vehgreen").Triggered += (source, args) =>
{
var veh = args.Player.Vehicle;
veh.Colors.Primary = Color.GreenYellow;
veh.Colors.Secondary = Color.GreenYellow;
};
}

private void OnPlayerJoin(CustomPlayer player)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void WritePacket_MatchesExpectedByteArray()
true, true, true, (byte)0, 1000, 50, (ElementId)666);
packet.AddVehicle((ElementId)675, (byte)2, null, 0, 0,
null, true, true, new CustomData(), "Test vehicle",
0, new Vector3(-10, 5, 3), Vector3.Zero, 602, 1000, 0, new Color[] {
0, new Vector3(-10, 5, 3), Vector3.Zero, 602, 1000, 0, new Color?[] {
Color.Red, Color.Blue
}, 0, new VehicleDamage()
{
Expand Down
7 changes: 3 additions & 4 deletions SlipeServer.Packets/Definitions/Entities/AddEntityPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public void AddVehicle(
ushort dimension, ElementAttachment? attachment, bool areCollisionsEnabled,
bool isCallPropagationEnabled, CustomData customData, string name,
byte timeContext, Vector3 position, Vector3 rotation, ushort model,
float health, byte blownState, Color[] colors, byte paintJob, VehicleDamage damage,
float health, byte blownState, Color?[] colors, byte paintJob, VehicleDamage damage,
byte variant1, byte variant2, Vector2? turret, ushort? adjustableProperty,
float[] doorRatios, byte[] upgrades, string plateText, byte overrideLights,
bool isLandingGearDown, bool isSirenActive, bool isFuelTankExplodable,
Expand All @@ -301,9 +301,8 @@ public void AddVehicle(

this.builder.WriteCapped((byte)colors.Length - 1, 2);
foreach (var color in colors)
{
this.builder.Write(color);
}
this.builder.Write(color ?? Color.Black);

this.builder.WriteCapped(paintJob, 2);

WriteVehicleDamage(damage.Doors, 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class SetVehicleColorRpcPacket : Packet
public override PacketPriority Priority => PacketPriority.High;

public ElementId ElementId { get; set; }
public Color[] Colors { get; set; }
public Color?[] Colors { get; set; }

public SetVehicleColorRpcPacket(ElementId elementId, Color[] colors)
public SetVehicleColorRpcPacket(ElementId elementId, Color?[] colors)
{
this.ElementId = elementId;
this.Colors = colors;
Expand All @@ -31,9 +31,10 @@ public override byte[] Write()
var builder = new PacketBuilder();
builder.Write((byte)ElementRPCFunction.SET_VEHICLE_COLOR);
builder.Write(this.ElementId);
builder.WriteCapped((byte)this.Colors.Length, 2);
var number = Math.Min((byte)Array.IndexOf(this.Colors, null), this.Colors.Length);
builder.WriteCapped(number, 2);
foreach (var color in this.Colors)
builder.Write(color);
builder.Write(color ?? Color.Black);

return builder.Build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override byte[] Write()
builder.Write(vehicleToSpawn.Rotation);
builder.WriteCapped(vehicleToSpawn.Colors.Length, 2);
foreach (var color in vehicleToSpawn.Colors)
builder.Write(color);
builder.Write(color ?? System.Drawing.Color.White);
}
return builder.Build();
}
Expand Down
2 changes: 1 addition & 1 deletion SlipeServer.Packets/Definitions/Lua/VehicleSpawnInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public class VehicleSpawnInfo
public ushort VehicleId { get; set; }
public Vector3 Position { get; set; }
public Vector3 Rotation { get; set; }
public Color[] Colors { get; set; } = Array.Empty<Color>();
public Color?[] Colors { get; set; } = Array.Empty<Color?>();
}
54 changes: 33 additions & 21 deletions SlipeServer.Server/ElementConcepts/Colors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ public Color Primary
get => this.primary;
set
{
var args = new VehicleColorChangedEventsArgs(this.vehicle, 0, value);
this.primary = value;
ColorChanged?.Invoke(this.vehicle, args);
if(this.primary != value)
{
var args = new VehicleColorChangedEventsArgs(this.vehicle, 0, value);
this.primary = value;
ColorChanged?.Invoke(this.vehicle, args);
}
}
}

Expand All @@ -30,45 +33,54 @@ public Color Secondary
get => this.secondary;
set
{
var args = new VehicleColorChangedEventsArgs(this.vehicle, 1, value);
this.secondary = value;
ColorChanged?.Invoke(this.vehicle, args);
if(this.secondary != value)
{
var args = new VehicleColorChangedEventsArgs(this.vehicle, 1, value);
this.secondary = value;
ColorChanged?.Invoke(this.vehicle, args);
}
}
}

private Color color3;
public Color Color3
private Color? color3;
public Color? Color3
{
get => this.color3;
set
{
var args = new VehicleColorChangedEventsArgs(this.vehicle, 2, value);
this.color3 = value;
ColorChanged?.Invoke(this.vehicle, args);
if(this.color3 != value)
{
var args = new VehicleColorChangedEventsArgs(this.vehicle, 2, value);
this.color3 = value;
ColorChanged?.Invoke(this.vehicle, args);
}
}
}

private Color color4;
public Color Color4
private Color? color4;
public Color? Color4
{
get => this.color4;
set
{
var args = new VehicleColorChangedEventsArgs(this.vehicle, 3, value);
this.color4 = value;
ColorChanged?.Invoke(this.vehicle, args);
if(this.color4 != value)
{
var args = new VehicleColorChangedEventsArgs(this.vehicle, 3, value);
this.color4 = value;
ColorChanged?.Invoke(this.vehicle, args);
}
}
}

public Color[] AsArray() => new Color[] { this.Primary, this.Secondary, this.Color3, this.Color4 };
public Color?[] AsArray() => new Color?[] { this.Primary, this.Secondary, this.Color3, this.Color4 };

public Colors(Vehicle vehicle, Color? primary = null, Color? secondary = null, Color? color3 = null, Color? color4 = null)
{
this.vehicle = vehicle;
this.primary = primary ?? Color.White;
this.secondary = secondary ?? Color.White;
this.color3 = color3 ?? Color.White;
this.color4 = color4 ?? Color.White;
this.primary = primary ?? Color.Black;
this.secondary = secondary ?? Color.Black;
this.color3 = color3;
this.color4 = color4;
}

public event ElementEventHandler<Vehicle, VehicleColorChangedEventsArgs>? ColorChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public sealed class VehicleColorChangedEventsArgs : EventArgs
{
public Vehicle Vehicle { get; }
public byte Index { get; }
public Color NewColor { get; }
public Color? NewColor { get; }

public VehicleColorChangedEventsArgs(Vehicle vehicle, byte index, Color newColor)
public VehicleColorChangedEventsArgs(Vehicle vehicle, byte index, Color? newColor)
{
this.Vehicle = vehicle;
this.Index = index;
Expand Down