Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Match Day and Campus DLCs #326

Merged
merged 7 commits into from
Sep 5, 2023
Merged
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
5 changes: 5 additions & 0 deletions src/api/CSM.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<Compile Include="Networking\Status\ServerStatus.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Threading.dll">
<Version>1.0.2856.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Include="protobuf-net">
<SpecificVersion>False</SpecificVersion>
Expand Down
20 changes: 19 additions & 1 deletion src/api/Helpers/IgnoreHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace CSM.API.Helpers
{
Expand All @@ -9,7 +11,13 @@ namespace CSM.API.Helpers
/// </summary>
public class IgnoreHelper
{
public static IgnoreHelper Instance = new IgnoreHelper();
public static IgnoreHelper Instance
{
get => _instance.Value;
set => _instance.Value = value;
}

private static readonly ThreadLocal<IgnoreHelper> _instance = new ThreadLocal<IgnoreHelper>(() => new IgnoreHelper());

private int _ignoreAll = 0;
private readonly HashSet<string> _exceptions = new HashSet<string>();
Expand Down Expand Up @@ -72,5 +80,15 @@ public bool IsIgnored(string action)
{
return IsIgnored() && !_exceptions.Contains(action);
}

/// <summary>
/// Reset ignore state.
/// </summary>
public void ResetIgnore()
{
Log.Debug($"Resetting {_ignoreAll} levels of ignoring: {string.Join(", ", _exceptions.ToArray())}");
_ignoreAll = 0;
_exceptions.Clear();
}
}
}
10 changes: 10 additions & 0 deletions src/api/Helpers/ReflectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ public static object GetAttr(object obj, string attribute)
return obj.GetType().GetField(attribute, AllAccessFlags)?.GetValue(obj);
}

public static T GetAttr<T>(Type type, string attribute)
{
return (T) GetAttr(type, attribute);
}

public static object GetAttr(Type type, string attribute)
{
return type.GetField(attribute, AllAccessFlags)?.GetValue(null);
}

public static T GetProp<T>(object obj, string property)
{
return (T) GetProp(obj, property);
Expand Down
25 changes: 21 additions & 4 deletions src/basegame/CSM.BaseGame.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@
<Compile Include="Commands\Data\Buildings\BuildingToolCreateCommand.cs" />
<Compile Include="Commands\Data\Buildings\BuildingUpgradeCommand.cs" />
<Compile Include="Commands\Data\Buildings\ServiceBuildingChangeVehicleCommand.cs" />
<Compile Include="Commands\Data\Campus\BuyResearchGrantCommand.cs" />
<Compile Include="Commands\Data\Campus\OnAcademicYearEndCommand.cs" />
<Compile Include="Commands\Data\Campus\SetAcademicStaffCountCommand.cs" />
<Compile Include="Commands\Data\Campus\SetCheerleadingBudgetCommand.cs" />
<Compile Include="Commands\Data\Campus\SetCoachesCountCommand.cs" />
<Compile Include="Commands\Data\Campus\SetTicketPriceCommand.cs" />
<Compile Include="Commands\Data\Campus\SetVarsityColorCommand.cs" />
<Compile Include="Commands\Data\Campus\SetVarsityIdentityCommand.cs" />
<Compile Include="Commands\Data\Districts\DistrictAreaModifyCommand.cs" />
<Compile Include="Commands\Data\Districts\DistrictChangeStyleCommand.cs" />
<Compile Include="Commands\Data\Districts\DistrictCityPolicyCommand.cs" />
<Compile Include="Commands\Data\Districts\DistrictCityPolicyUnsetCommand.cs" />
<Compile Include="Commands\Data\Districts\DistrictCreateCommand.cs" />
Expand All @@ -95,6 +104,7 @@
<Compile Include="Commands\Data\Economy\EconomyTakeLoanCommand.cs" />
<Compile Include="Commands\Data\Events\EventActivateCommand.cs" />
<Compile Include="Commands\Data\Events\EventColorChangedCommand.cs" />
<Compile Include="Commands\Data\Events\EventSetResultCommand.cs" />
<Compile Include="Commands\Data\Events\EventSetSecurityBudgetCommand.cs" />
<Compile Include="Commands\Data\Events\EventSetTicketPriceCommand.cs" />
<Compile Include="Commands\Data\Names\ChangeCityNameCommand.cs" />
Expand Down Expand Up @@ -149,7 +159,16 @@
<Compile Include="Commands\Handler\Buildings\BuildingToolCreateHandler.cs" />
<Compile Include="Commands\Handler\Buildings\BuildingUpgradeHandler.cs" />
<Compile Include="Commands\Handler\Buildings\TransportLineChangeVehicleHandler.cs" />
<Compile Include="Commands\Handler\Campus\BuyResearchGrantHandler.cs" />
<Compile Include="Commands\Handler\Campus\OnAcademicYearEndHandler.cs" />
<Compile Include="Commands\Handler\Campus\SetAcademicStaffCountHandler.cs" />
<Compile Include="Commands\Handler\Campus\SetCheerleadingBudgetHandler.cs" />
<Compile Include="Commands\Handler\Campus\SetCoachesCountHandler.cs" />
<Compile Include="Commands\Handler\Campus\SetTicketPriceHandler.cs" />
<Compile Include="Commands\Handler\Campus\SetVarsityColorHandler.cs" />
<Compile Include="Commands\Handler\Campus\SetVarsityIdentityHandler.cs" />
<Compile Include="Commands\Handler\Districts\DistrictAreaModifyHandler.cs" />
<Compile Include="Commands\Handler\Districts\DistrictChangeStyleHandler.cs" />
<Compile Include="Commands\Handler\Districts\DistrictCityPolicyHandler.cs" />
<Compile Include="Commands\Handler\Districts\DistrictCityPolicyUnsetHandler.cs" />
<Compile Include="Commands\Handler\Districts\DistrictCreateHandler.cs" />
Expand All @@ -165,6 +184,7 @@
<Compile Include="Commands\Handler\Economy\EconomyTakeLoanHandler.cs" />
<Compile Include="Commands\Handler\Events\EventActivateHandler.cs" />
<Compile Include="Commands\Handler\Events\EventColorChangedHandler.cs" />
<Compile Include="Commands\Handler\Events\EventSetResultHandler.cs" />
<Compile Include="Commands\Handler\Events\EventSetSecurityBudgetHandler.cs" />
<Compile Include="Commands\Handler\Events\EventSetTicketPriceHandler.cs" />
<Compile Include="Commands\Handler\Names\ChangeCityNameHandler.cs" />
Expand Down Expand Up @@ -213,6 +233,7 @@
<Compile Include="Helpers\ToolSimulator.cs" />
<Compile Include="Injections\ArrayHandler.cs" />
<Compile Include="Injections\BuildingHandler.cs" />
<Compile Include="Injections\CampusHandler.cs" />
<Compile Include="Injections\DistrictHandler.cs" />
<Compile Include="Injections\EconomyHandler.cs" />
<Compile Include="Injections\EventHandler.cs" />
Expand Down Expand Up @@ -256,9 +277,5 @@
<Name>CSM.API</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Commands\Data" />
<Folder Include="Commands\Handler" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
26 changes: 26 additions & 0 deletions src/basegame/Commands/Data/Campus/BuyResearchGrantCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CSM.API.Commands;
using ProtoBuf;

namespace CSM.BaseGame.Commands.Data.Campus
{
/// <summary>
/// Called when a new research grant is bought for a campus.
/// </summary>
/// Sent by:
/// - CampusHandler
[ProtoContract]
public class BuyResearchGrantCommand : CommandBase
{
/// <summary>
/// The park id of the campus.
/// </summary>
[ProtoMember(1)]
public byte Campus { get; set; }

/// <summary>
/// The type of the research grant.
/// </summary>
[ProtoMember(2)]
public byte GrantType { get; set; }
}
}
50 changes: 50 additions & 0 deletions src/basegame/Commands/Data/Campus/OnAcademicYearEndCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using CSM.API.Commands;
using ProtoBuf;

namespace CSM.BaseGame.Commands.Data.Campus
{
/// <summary>
/// Called when the academic year of a campus area ends.
/// </summary>
/// Sent by:
/// - CampusHandler
[ProtoContract]
public class OnAcademicYearEndCommand : CommandBase
{
/// <summary>
/// The park id of the campus area.
/// </summary>
[ProtoMember(1)]
public byte ParkId { get; set; }

/// <summary>
/// Information regarding the academic works.
/// </summary>
[ProtoMember(2)]
public AcademicWorksData AcademicWorksData { get; set; }

/// <summary>
/// Statistical data of the campus area used in the academic year info panel.
/// </summary>
[ProtoMember(3)]
public DistrictYearReportData[] LedgerReports { get; set; }

/// <summary>
/// The new dynamic attractiveness modifier.
/// </summary>
[ProtoMember(4)]
public int DynamicAttractiveness { get; set; }

/// <summary>
/// The park level of the previous year.
/// </summary>
[ProtoMember(5)]
public DistrictPark.ParkLevel OldParkLevel { get; set; }

/// <summary>
/// The park level in the following year.
/// </summary>
[ProtoMember(6)]
public DistrictPark.ParkLevel NewParkLevel { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/basegame/Commands/Data/Campus/SetAcademicStaffCountCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CSM.API.Commands;
using ProtoBuf;

namespace CSM.BaseGame.Commands.Data.Campus
{
/// <summary>
/// Called when the count of academic staff is set for a campus.
/// </summary>
/// Sent by:
/// - CampusHandler
[ProtoContract]
public class SetAcademicStaffCountCommand : CommandBase
{
/// <summary>
/// The park id of the campus.
/// </summary>
[ProtoMember(1)]
public byte Campus { get; set; }

/// <summary>
/// The new amount of staff.
/// </summary>
[ProtoMember(2)]
public byte Count { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/basegame/Commands/Data/Campus/SetCheerleadingBudgetCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CSM.API.Commands;
using ProtoBuf;

namespace CSM.BaseGame.Commands.Data.Campus
{
/// <summary>
/// Called when the cheerleading budget of a campus is changed.
/// </summary>
/// Sent by:
/// - CampusHandler
[ProtoContract]
public class SetCheerleadingBudgetCommand : CommandBase
{
/// <summary>
/// The park id of the campus.
/// </summary>
[ProtoMember(1)]
public byte Campus { get; set; }

/// <summary>
/// The new cheerleading budget.
/// </summary>
[ProtoMember(2)]
public int Budget { get; set; }
}
}
33 changes: 33 additions & 0 deletions src/basegame/Commands/Data/Campus/SetCoachesCountCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using CSM.API.Commands;
using ProtoBuf;

namespace CSM.BaseGame.Commands.Data.Campus
{
/// <summary>
/// Called when the count of varsity coaches is set for a campus.
/// </summary>
/// Sent by:
/// - CampusHandler
[ProtoContract]
public class SetCoachesCountCommand : CommandBase
{
/// <summary>
/// The park id of the campus.
/// </summary>
[ProtoMember(1)]
public byte Campus { get; set; }

/// <summary>
/// The new amount of staff.
/// </summary>
[ProtoMember(2)]
public byte Count { get; set; }

/// <summary>
/// The timestamps when the new coaches were hired.
/// </summary>
[ProtoMember(3)]
public DateTime[] CoachHireTimes { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/basegame/Commands/Data/Campus/SetTicketPriceCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CSM.API.Commands;
using ProtoBuf;

namespace CSM.BaseGame.Commands.Data.Campus
{
/// <summary>
/// Called when the ticket price for varsity sports is set on a campus.
/// </summary>
/// Sent by:
/// - CampusHandler
[ProtoContract]
public class SetTicketPriceCommand : CommandBase
{
/// <summary>
/// The park id of the campus.
/// </summary>
[ProtoMember(1)]
public byte Campus { get; set; }

/// <summary>
/// The new ticket price.
/// </summary>
[ProtoMember(2)]
public ushort Price { get; set; }
}
}
27 changes: 27 additions & 0 deletions src/basegame/Commands/Data/Campus/SetVarsityColorCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using CSM.API.Commands;
using ProtoBuf;
using UnityEngine;

namespace CSM.BaseGame.Commands.Data.Campus
{
/// <summary>
/// Called when the color of the varsity sports is set for a campus.
/// </summary>
/// Sent by:
/// - CampusHandler
[ProtoContract]
public class SetVarsityColorCommand : CommandBase
{
/// <summary>
/// The park id of the campus.
/// </summary>
[ProtoMember(1)]
public byte Campus { get; set; }

/// <summary>
/// The new varsity color.
/// </summary>
[ProtoMember(2)]
public Color Color { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/basegame/Commands/Data/Campus/SetVarsityIdentityCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CSM.API.Commands;
using ProtoBuf;

namespace CSM.BaseGame.Commands.Data.Campus
{
/// <summary>
/// Called when the identity of the varsity sports is set for a campus.
/// </summary>
/// Sent by:
/// - CampusHandler
[ProtoContract]
public class SetVarsityIdentityCommand : CommandBase
{
/// <summary>
/// The park id of the campus.
/// </summary>
[ProtoMember(1)]
public byte Campus { get; set; }

/// <summary>
/// The new varsity identity.
/// </summary>
[ProtoMember(2)]
public int Identity { get; set; }
}
}
Loading