forked from Exiled-Official/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 67
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
feat: Objective wrappers #316
Open
VALERA771
wants to merge
8
commits into
ExMod-Team:dev
Choose a base branch
from
VALERA771:objective
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fee208e
objective wrappers
VALERA771 09bc80f
oh uh
VALERA771 4927d9f
Merge branch 'scpsl14' into objective
VALERA771 384af53
Merge branch 'dev' into objective
VALERA771 d62f3fe
feat: completing objective event
VALERA771 f35ee13
refactor: very important things
VALERA771 913843b
feat: update docs, new objective
VALERA771 d06d65e
fix: fix
VALERA771 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="ObjectiveType.cs" company="ExMod Team"> | ||
// Copyright (c) ExMod Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.API.Enums | ||
{ | ||
/// <summary> | ||
/// An enum representing the different types of objectives. | ||
/// </summary> | ||
/// <seealso cref="Exiled.API.Features.Objectives.Objective" /> | ||
public enum ObjectiveType | ||
{ | ||
/// <summary> | ||
/// Unknown objective. | ||
/// </summary> | ||
None, | ||
|
||
/// <summary> | ||
/// Objective that is completed when SCP item is picked up. | ||
/// </summary> | ||
ScpItemPickup, | ||
|
||
/// <summary> | ||
/// Objective that is completed when enemy military is damaged. | ||
/// </summary> | ||
HumanDamage, | ||
|
||
/// <summary> | ||
/// Objective that is completed when enemy military is killed. | ||
/// </summary> | ||
HumanKill, | ||
|
||
/// <summary> | ||
/// Objective that is completed when generator is activated. | ||
/// </summary> | ||
GeneratorActivation, | ||
|
||
/// <summary> | ||
/// Objective that is completed when player escapes. | ||
/// </summary> | ||
Escape, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="EscapeObjective.cs" company="ExMod Team"> | ||
// Copyright (c) ExMod Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.API.Features.Objectives | ||
{ | ||
using Exiled.API.Enums; | ||
using Exiled.API.Interfaces; | ||
using PlayerRoles; | ||
using Respawning.Objectives; | ||
|
||
using BaseObjective = Respawning.Objectives.EscapeObjective; | ||
|
||
/// <summary> | ||
/// Represents an objective that is completed when a player escapes. | ||
/// </summary> | ||
public class EscapeObjective : HumanObjective<EscapeObjectiveFootprint>, IWrapper<BaseObjective> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EscapeObjective"/> class. | ||
/// </summary> | ||
/// <param name="objectiveFootprintBase">A <see cref="BaseObjective"/> instance.</param> | ||
internal EscapeObjective(BaseObjective objectiveFootprintBase) | ||
: base(objectiveFootprintBase) | ||
{ | ||
Base = objectiveFootprintBase; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public new BaseObjective Base { get; } | ||
|
||
/// <inheritdoc /> | ||
public override ObjectiveType Type { get; } = ObjectiveType.Escape; | ||
|
||
/// <summary> | ||
/// Fakes player's escape and tries to achieve this objective. | ||
/// </summary> | ||
/// <param name="player">Target that has escaped.</param> | ||
/// <param name="newRole">Role that target will get after escaping.</param> | ||
public void Escape(Player player, RoleTypeId newRole = RoleTypeId.None) | ||
{ | ||
if (newRole == RoleTypeId.None) | ||
{ | ||
if (player.Role == RoleTypeId.ClassD) | ||
newRole = RoleTypeId.ChaosConscript; | ||
else if (player.Role == RoleTypeId.Scientist) | ||
newRole = RoleTypeId.NtfSpecialist; | ||
else | ||
newRole = player.Role; | ||
} | ||
|
||
Base.OnServerRoleSet(player.ReferenceHub, newRole, RoleChangeReason.Escaped); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
EXILED/Exiled.API/Features/Objectives/GeneratorActivatedObjective.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="GeneratorActivatedObjective.cs" company="ExMod Team"> | ||
// Copyright (c) ExMod Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.API.Features.Objectives | ||
{ | ||
using Exiled.API.Enums; | ||
using Exiled.API.Interfaces; | ||
using Respawning.Objectives; | ||
|
||
using BaseObjective = Respawning.Objectives.GeneratorActivatedObjective; | ||
|
||
/// <summary> | ||
/// Represents an objective that is completed when a generator is activated. | ||
/// </summary> | ||
public class GeneratorActivatedObjective : HumanObjective<GeneratorObjectiveFootprint>, IWrapper<BaseObjective> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="GeneratorActivatedObjective"/> class. | ||
/// </summary> | ||
/// <param name="objectiveFootprintBase">A <see cref="BaseObjective"/> instance.</param> | ||
public GeneratorActivatedObjective(BaseObjective objectiveFootprintBase) | ||
: base(objectiveFootprintBase) | ||
{ | ||
Base = objectiveFootprintBase; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public new BaseObjective Base { get; } | ||
|
||
/// <inheritdoc/> | ||
public override ObjectiveType Type { get; } = ObjectiveType.GeneratorActivation; | ||
|
||
/// <summary> | ||
/// Fakes generator activation and tries to achieve this objective. | ||
/// </summary> | ||
/// <param name="generator">Generator that is activated.</param> | ||
/// <param name="player">Player that activated the generator.</param> | ||
public void Activate(Generator generator, Player player = null) => Base.OnGeneratorEngaged(generator.Base, (player ?? Server.Host).Footprint); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
EXILED/Exiled.API/Features/Objectives/HumanDamageObjective.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="HumanDamageObjective.cs" company="ExMod Team"> | ||
// Copyright (c) ExMod Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.API.Features.Objectives | ||
{ | ||
using Exiled.API.Enums; | ||
using Exiled.API.Features.DamageHandlers; | ||
using Exiled.API.Interfaces; | ||
using Respawning.Objectives; | ||
|
||
using BaseObjective = Respawning.Objectives.HumanDamageObjective; | ||
|
||
/// <summary> | ||
/// A wrapper for the human damage objective. | ||
/// </summary> | ||
public class HumanDamageObjective : HumanObjective<DamageObjectiveFootprint>, IWrapper<BaseObjective> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="HumanDamageObjective"/> class. | ||
/// </summary> | ||
/// <param name="objectiveFootprintBase"><inheritdoc cref="Base"/></param> | ||
internal HumanDamageObjective(BaseObjective objectiveFootprintBase) | ||
: base(objectiveFootprintBase) | ||
{ | ||
Base = objectiveFootprintBase; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public new BaseObjective Base { get; } | ||
|
||
/// <inheritdoc/> | ||
public override ObjectiveType Type { get; } = ObjectiveType.HumanDamage; | ||
|
||
/// <summary> | ||
/// Fakes player's damage and tries to achieve this objective. | ||
/// </summary> | ||
/// <param name="attacker">Attacker.</param> | ||
/// <param name="target">Target to damage.</param> | ||
/// <param name="amount">Amount of damage.</param> | ||
/// <param name="type">Type of damage.</param> | ||
public void Damage(Player attacker, Player target, float amount, DamageType type = DamageType.Unknown) | ||
=> Damage(new CustomDamageHandler(target, attacker, amount, type, string.Empty)); | ||
|
||
/// <summary> | ||
/// Fakes player's damage and tries to achieve this objective. | ||
/// </summary> | ||
/// <param name="damageHandler">An <see cref="AttackerDamageHandler"/> instance.</param> | ||
public void Damage(AttackerDamageHandler damageHandler) => Base.OnPlayerDamaged(damageHandler.Attacker.ReferenceHub, damageHandler.Base); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
EXILED/Exiled.API/Features/Objectives/HumanKillObjective.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="HumanKillObjective.cs" company="ExMod Team"> | ||
// Copyright (c) ExMod Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.API.Features.Objectives | ||
{ | ||
using Exiled.API.Enums; | ||
using Exiled.API.Features.DamageHandlers; | ||
using Exiled.API.Interfaces; | ||
using PlayerRoles; | ||
using Respawning.Objectives; | ||
|
||
using BaseObjective = Respawning.Objectives.HumanKillObjective; | ||
|
||
/// <summary> | ||
/// A wrapper for Human kill objective. | ||
/// </summary> | ||
public class HumanKillObjective : HumanObjective<KillObjectiveFootprint>, IWrapper<BaseObjective> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="HumanKillObjective"/> class. | ||
/// </summary> | ||
/// <param name="objectiveFootprintBase"><inheritdoc cref="Base"/></param> | ||
internal HumanKillObjective(BaseObjective objectiveFootprintBase) | ||
: base(objectiveFootprintBase) | ||
{ | ||
Base = objectiveFootprintBase; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public new BaseObjective Base { get; } | ||
|
||
/// <inheritdoc/> | ||
public override ObjectiveType Type { get; } = ObjectiveType.HumanKill; | ||
|
||
/// <summary> | ||
/// Checks if the role is an enemy role. | ||
/// </summary> | ||
/// <param name="target">Target role.</param> | ||
/// <param name="player">Attacker.</param> | ||
/// <returns><c>true</c> if role is an enemy role, <c>false</c> otherwise.</returns> | ||
public bool IsValidEnemy(RoleTypeId target, Player player) => Base.IsValidEnemy(target, player.ReferenceHub); | ||
|
||
/// <summary> | ||
/// Checks if the player is an enemy. | ||
/// </summary> | ||
/// <param name="target">Target player.</param> | ||
/// <param name="player">Attacker.</param> | ||
/// <returns><c>true</c> if player is an enemy, <c>false</c> otherwise.</returns> | ||
public bool IsValidEnemy(Player target, Player player) => IsValidEnemy(target.Role, player); | ||
|
||
/// <summary> | ||
/// Fakes player's kill and tries to achieve this objective. | ||
/// </summary> | ||
/// <param name="damageHandler">An <see cref="AttackerDamageHandler"/> instance.</param> | ||
public void Kill(AttackerDamageHandler damageHandler) => Base.OnKill(damageHandler.Target.ReferenceHub, damageHandler.Base); | ||
|
||
/// <summary> | ||
/// Fakes player's kill and tries to achieve this objective. | ||
/// </summary> | ||
/// <param name="target">Target player.</param> | ||
/// <param name="attacker">Attacker.</param> | ||
/// <param name="damageType">Damage type.</param> | ||
public void Kill(Player target, Player attacker, DamageType damageType = DamageType.Unknown) => Kill(new CustomDamageHandler(target, attacker, -1, damageType)); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
EXILED/Exiled.API/Features/Objectives/HumanObjective.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="HumanObjective.cs" company="ExMod Team"> | ||
// Copyright (c) ExMod Team. All rights reserved. | ||
// Licensed under the CC BY-SA 3.0 license. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
namespace Exiled.API.Features.Objectives | ||
{ | ||
using Exiled.API.Interfaces; | ||
using Respawning.Objectives; | ||
|
||
/// <summary> | ||
/// Represents a human objective. | ||
/// </summary> | ||
/// <typeparam name="T">An objective footprint type.</typeparam> | ||
public class HumanObjective<T> : Objective, IWrapper<HumanObjectiveBase<T>> | ||
where T : ObjectiveFootprintBase, new() | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="HumanObjective{T}"/> class. | ||
/// </summary> | ||
/// <param name="objectiveFootprintBase">A <see cref="HumanObjectiveBase{T}"/> instance.</param> | ||
internal HumanObjective(HumanObjectiveBase<T> objectiveFootprintBase) | ||
: base(objectiveFootprintBase) | ||
{ | ||
Base = objectiveFootprintBase; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public new HumanObjectiveBase<T> Base { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the objective footprint. | ||
/// </summary> | ||
/// <remarks>Can be <c>null</c>. It's being set by game only before achieving.</remarks> | ||
public T ObjectiveFootprint | ||
{ | ||
get => (T)Base.ObjectiveFootprint; | ||
set => Base.ObjectiveFootprint = value; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the time reward. | ||
/// </summary> | ||
/// <remarks> | ||
/// Can be <c>0</c> if <see cref="ObjectiveFootprint"/> is <c>null</c>. | ||
/// Setter affects only client notification. | ||
/// </remarks> | ||
public float TimeReward | ||
{ | ||
get => ObjectiveFootprint?.TimeReward ?? 0; | ||
set | ||
{ | ||
ObjectiveFootprint ??= new T(); | ||
ObjectiveFootprint.TimeReward = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the influence reward. | ||
/// </summary> | ||
/// <remarks> | ||
/// Can be <c>0</c> if <see cref="ObjectiveFootprint"/> is <c>null</c>. | ||
/// Setter affects only client notification. | ||
/// </remarks> | ||
public float InfluenceReward | ||
{ | ||
get => ObjectiveFootprint?.InfluenceReward ?? 0; | ||
set | ||
{ | ||
ObjectiveFootprint ??= new T(); | ||
ObjectiveFootprint.InfluenceReward = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the achiever. | ||
/// </summary> | ||
/// <remarks> | ||
/// Can be <c>null</c> if <see cref="ObjectiveFootprint"/> is <c>null</c>. | ||
/// Setter affects only client notification. | ||
/// </remarks> | ||
public Player Achiever | ||
{ | ||
get => ObjectiveFootprint == null ? null : Player.Get(ObjectiveFootprint.AchievingPlayer.Nickname); | ||
set | ||
{ | ||
ObjectiveFootprint ??= new T(); | ||
ObjectiveFootprint.AchievingPlayer = new(value.Footprint); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Achieves the objective. | ||
/// </summary> | ||
/// <param name="objectiveFootprint">An objective footprint instance.</param> | ||
public void Achieve(T objectiveFootprint) | ||
{ | ||
ObjectiveFootprint = objectiveFootprint; | ||
Achieve(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this it's not logical for what name you gave as argument newRole