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

Merge dev into net5.0 #217

Merged
merged 18 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
9b6d291
Add check for being able to repeat.
TheNexusAvenger Jan 16, 2021
5728637
Add displaying repeat missions.
TheNexusAvenger Jan 16, 2021
927a248
Add restarting missions and remove setting cooldown.
TheNexusAvenger Jan 16, 2021
f5debbf
Fix mission id check being incorrect.
TheNexusAvenger Jan 16, 2021
c9bb317
Add missing cooldown times.
TheNexusAvenger Jan 16, 2021
9d554f5
Revert client database changes.
TheNexusAvenger Jan 16, 2021
07efa32
Re-add special case for daily missions with no cooldown.
TheNexusAvenger Jan 16, 2021
f2f9197
Merge branch 'dev' of github.com:UchuServer/Uchu into enhancement/rep…
TheNexusAvenger Feb 20, 2021
f6f8f81
Update changes for player refactor.
TheNexusAvenger Feb 20, 2021
d1e94b9
make it clearer that defaults have to be changed
enteryournamehere Feb 20, 2021
22d131b
ensure at least one script pack dll is specified
enteryournamehere Feb 20, 2021
bdccf86
remove default (invalid) value from script dll config list
enteryournamehere Feb 20, 2021
e7ec353
only add default script dll value on config create
enteryournamehere Feb 21, 2021
2179e3c
improve error handling for script dll config
enteryournamehere Feb 22, 2021
9b16fb4
Merge pull request #173 from UchuServer/enhancement/repeatable-missions
MickVermeulen Feb 22, 2021
269470e
Merge pull request #214 from UchuServer/enhancement/script-dll-config
MickVermeulen Feb 22, 2021
b327a0d
Create dotnet.yml
enteryournamehere Feb 22, 2021
5b56894
Make GH action check out submodules
enteryournamehere Feb 22, 2021
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
28 changes: 28 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: .NET

on:
push:
branches: [ dev, master ]
pull_request:
branches: [ dev, master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout repo and submodules
uses: actions/checkout@v2
with:
submodules: recursive
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
2 changes: 1 addition & 1 deletion Uchu.Core/Config/UchuConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public class ServerDllSource
/// <summary>
/// The path to the Uchu.Instance DLL
/// </summary>
[XmlElement] public string Instance { get; set; } = "Uchu.Instance.dll";
[XmlElement] public string Instance { get; set; } = "Enter path to Uchu.Instance.dll";

/// <summary>
/// The path to the script source DLLs
Expand Down
6 changes: 6 additions & 0 deletions Uchu.Core/Database/UchuContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Uchu.Core.Providers;

namespace Uchu.Core
Expand Down Expand Up @@ -60,6 +61,11 @@ public UchuContext()
}
}

public EntityEntry Entry(object entry)
{
return ContextBase.Entry(entry);
}

public async Task EnsureUpdatedAsync()
{
await ContextBase.EnsureUpdatedAsync().ConfigureAwait(false);
Expand Down
20 changes: 18 additions & 2 deletions Uchu.Master/MasterServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ private static async Task ConfigureAsync()
{
LogQueue.Config = Config = new UchuConfiguration();

Config.DllSource.ScriptDllSource.Add("Enter path to Uchu.StandardScripts.dll");

var backup = File.CreateText("config.default.xml");

serializer.Serialize(backup, Config);
Expand Down Expand Up @@ -265,10 +267,24 @@ private static async Task ConfigureAsync()

if (!File.Exists(DllLocation))
{
Logger.Error("Could not find file specified in DllSource -> Instance in config.xml.");
throw new FileNotFoundException("Could not find Instance file.");
throw new FileNotFoundException("Could not find file specified in <Instance> under <DllSource> in config.xml.");
}

var validScriptPackExists = Config.DllSource.ScriptDllSource.Exists(scriptPackPath =>
{
if (File.Exists(scriptPackPath))
return true;

Logger.Warning($"Could not find script pack at {scriptPackPath}");
return false;
});

if (!validScriptPackExists)
{
throw new FileNotFoundException("No valid <ScriptDllSource> specified under <DllSource> in config.xml.\n"
+ "Without Uchu.StandardScripts.dll, Uchu cannot function correctly.");
}

foreach (var scriptPackPath in Config.DllSource.ScriptDllSource)
{
if (!File.Exists(scriptPackPath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ private async Task<MissionInstance> AddMissionAsync(int missionId, GameObject ga
/// <param name="mission"></param>
/// <returns><c>true</c> if the player can accept this mission, <c>false</c> otherwise</returns>
public bool CanAccept(MissionInstance mission) =>
(mission.Repeatable || !HasMission(mission.MissionId))
(mission.CanRepeat || !HasMission(mission.MissionId))
&& MissionParser.CheckPrerequiredMissions(mission.PrerequisiteMissions, AllMissions);

/// <summary>
Expand Down Expand Up @@ -373,6 +373,13 @@ private async Task RespondToMissionAsync(int missionId, GameObject missionGiver,
return;
}

// Repeat the mission if it is repeatable, such as a daily mission.
if (mission.CanRepeat)
{
await mission.RestartAsync();
return;
}

// Player is responding to an active mission.
if (!mission.Completed)
{
Expand Down
19 changes: 8 additions & 11 deletions Uchu.World/Objects/Components/Server/MissionGiverComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
using System.Linq;
using Uchu.Core;
using Uchu.Core.Client;
using Uchu.Core.Resources;
using Uchu.World.Client;
using Uchu.World.Systems.Missions;

namespace Uchu.World
{
Expand Down Expand Up @@ -94,7 +92,7 @@ public void HandleInteraction(Player player)
var playerMission = missionInventory.GetMission(questId);

// If the player is ready to hand this mission in, allow them to complete the mission
if (playerMission != default && (component.AcceptsMission ?? false) && playerMission.State == MissionState.ReadyToComplete)
if (playerMission != default && (component.AcceptsMission ?? false) && (playerMission.State == MissionState.ReadyToComplete || playerMission.State == MissionState.CompletedReadyToComplete))
{
missionInventory.MessageOfferMission(questId, GameObject);
return;
Expand All @@ -118,17 +116,15 @@ public void HandleInteraction(Player player)
return;
case MissionState.CompletedActive:
// If this is an active mission show the offer popup again for information
player.GetComponent<MissionInventoryComponent>().MessageOfferMission(
playerMission.MissionId,
GameObject
);
continue;
missionInventory.MessageOfferMission(playerMission.MissionId, GameObject);
return;
case MissionState.ReadyToComplete:
case MissionState.CompletedReadyToComplete:
case MissionState.Unavailable:
case MissionState.Completed:
case MissionState.CompletedReadyToComplete:
// Any other missions are skipped
continue;
// Allow the mission if it is repeatable and the cooldown period has passed.
if (!playerMission.CanRepeat) continue;
break;
default:
throw new ArgumentOutOfRangeException(
nameof(playerMission.State), $"{playerMission.State} is not a valid {nameof(MissionState)}"
Expand All @@ -143,6 +139,7 @@ public void HandleInteraction(Player player)

// Set the mission as the mission to offer.
// The mission is not offered directly in cases where an Available mission comes up before a ReadyToComplete mission.
if (questIdToOffer != default) continue;
questIdToOffer = questId;
}

Expand Down
50 changes: 49 additions & 1 deletion Uchu.World/Systems/Missions/MissionInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ public class MissionInstance
public int RewardItem4RepeatableCount { get; private set; }
#endregion template

/// <summary>
/// Whether the mission is part of mission of the day
/// </summary>
public bool InMissionOfTheDay { get; private set; }

/// <summary>
/// Cooldown time for repeating the mission.
/// </summary>
public long CooldownTime { get; private set; }

#region instance
/// <summary>
/// The player that started this mission
Expand Down Expand Up @@ -229,6 +239,12 @@ public class MissionInstance
/// <returns><c>true</c> if completed, <c>false</c> otherwise</returns>
public bool Completed => Tasks.All(t => t.Completed);

/// <summary>
/// Checks if this mission is can be repeated and the cooldown time is satisfied.
/// </summary>
/// <returns><c>true</c> if can be repeated right now, <c>false</c> otherwise</returns>
public bool CanRepeat => IsMission && State == MissionState.Completed && (Repeatable || InMissionOfTheDay) && (LastCompletion == default || LastCompletion + (CooldownTime * 60) <= DateTimeOffset.Now.ToUnixTimeSeconds());

#endregion properties
static MissionInstance()
{
Expand Down Expand Up @@ -291,6 +307,14 @@ private async Task LoadTemplateAsync()
RewardCurrency = mission.Rewardcurrency ?? 0;
RewardCurrencyRepeatable = mission.Rewardcurrencyrepeatable ?? 0;
RewardScore = mission.LegoScore ?? 0;
Repeatable = mission.Repeatable ?? false;
InMissionOfTheDay = mission.InMOTD ?? false;
CooldownTime = mission.CooldownTime ?? 0;
if (InMissionOfTheDay && CooldownTime == 0)
{
// Prevents infinite loop of getting and completing daily quest. ~22 hour timer is used by other daily quests.
CooldownTime = 1300;
}

// Emotes
RewardEmote1 = mission.Rewardemote ?? -1;
Expand Down Expand Up @@ -396,6 +420,28 @@ public async Task StartAsync()

State = MissionState.Active;

await NotifyClientStartAsync();
}

/// <summary>
/// Restarts this mission instance and notifies the client
/// </summary>
public async Task RestartAsync()
{
State = MissionState.CompletedActive;
foreach (var missionTask in Tasks)
{
missionTask.Restart();
}

await NotifyClientStartAsync();
}

/// <summary>
/// Notifies the client of starting the mission
/// </summary>
private async Task NotifyClientStartAsync()
{
MessageNotifyMission();
MessageMissionTypeState(MissionLockState.New);

Expand Down Expand Up @@ -582,7 +628,9 @@ public async Task SoftCompleteAsync()
{
if (IsMission)
{
UpdateMissionState(MissionState.ReadyToComplete);
UpdateMissionState(State == MissionState.CompletedActive
? MissionState.CompletedReadyToComplete
: MissionState.ReadyToComplete);
return;
}

Expand Down
8 changes: 8 additions & 0 deletions Uchu.World/Systems/Missions/MissionTaskInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,13 @@ protected async Task CheckMissionCompletedAsync()
if (Mission.Completed)
await Mission.SoftCompleteAsync();
}

/// <summary>
/// Restarts the task status.
/// </summary>
public void Restart()
{
this.Progress = new List<float>();
}
}
}