* basic implementation

* minor fixes

* objectives temp commit

* proper onstart bind

* changes all conditions to be bound to a mind-instance

* oops

* oops v2

* adds possiblity to enable duplicate assignment of objective
equal objectives are unable to be added

* minor fixes, adds greentext

* refactors incompatability to be defined by requirements

* fixes a wrong whitespace

* minor fix

* addressed reviews v1

* address reviews v2

Co-authored-by: Exp <theexp111@gmail.com>

* final sweep

* adds/refactors traitor&sss cvars

* Update Content.Server/Mobs/Mind.cs

* never trust github web

* adds datasets & makes codewords use them

* addresses exp's reviews

* addressed zumos reviews

Co-authored-by: Paul <ritter.paul1+git@googlemail.com>
Co-authored-by: Exp <theexp111@gmail.com>
This commit is contained in:
Paul Ritter
2020-12-01 17:05:19 +01:00
committed by GitHub
parent 602f37e70c
commit f7c09fbd7e
28 changed files with 1875 additions and 107 deletions

View File

@@ -1,7 +1,9 @@
#nullable enable
using System;
using Content.Server.GameObjects.Components.ContainerExt;
using Content.Server.Mobs;
using Content.Server.Objectives.Interfaces;
using JetBrains.Annotations;
using Robust.Server.GameObjects.Components.Container;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -13,45 +15,79 @@ using Robust.Shared.Utility;
namespace Content.Server.Objectives.Conditions
{
[UsedImplicitly]
public class StealCondition : IObjectiveCondition
{
public string PrototypeId { get; private set; } = default!;
public int Amount { get; private set; }
private Mind? _mind;
private string _prototypeId = default!;
private int _amount;
public IObjectiveCondition GetAssigned(Mind mind)
{
return new StealCondition
{
_mind = mind,
_prototypeId = _prototypeId,
_amount = _amount
};
}
public void ExposeData(ObjectSerializer serializer)
{
serializer.DataField(this, x => x.PrototypeId, "prototype", "");
serializer.DataField(this, x => x.Amount, "amount", 1);
serializer.DataField(ref _prototypeId, "prototype", "");
serializer.DataField(ref _amount, "amount", 1);
if (Amount < 1)
if (_amount < 1)
{
Logger.Error("StealCondition has an amount less than 1 ({0})", Amount);
Logger.Error("StealCondition has an amount less than 1 ({0})", _amount);
}
}
private string PrototypeName =>
IoCManager.Resolve<IPrototypeManager>().TryIndex<EntityPrototype>(PrototypeId, out var prototype)
IoCManager.Resolve<IPrototypeManager>().TryIndex<EntityPrototype>(_prototypeId, out var prototype)
? prototype.Name
: "[CANNOT FIND NAME]";
public string GetTitle() => Loc.GetString("Steal {0} {1}", Amount > 1 ? $"{Amount}x" : "", Loc.GetString(PrototypeName));
public string Title => Loc.GetString("Steal {0}{1}", _amount > 1 ? $"{_amount}x " : "", Loc.GetString(PrototypeName));
public string GetDescription() => Loc.GetString("We need you to steal {0}. Don't get caught.", Loc.GetString(PrototypeName));
public string Description => Loc.GetString("We need you to steal {0}. Don't get caught.", Loc.GetString(PrototypeName));
public SpriteSpecifier GetIcon()
public SpriteSpecifier Icon => new SpriteSpecifier.EntityPrototype(_prototypeId);
public float Progress
{
return new SpriteSpecifier.EntityPrototype(PrototypeId);
get
{
if (_mind?.OwnedEntity == null) return 0f;
if (!_mind.OwnedEntity.TryGetComponent<ContainerManagerComponent>(out var containerManagerComponent)) return 0f;
float count = containerManagerComponent.CountPrototypeOccurencesRecursive(_prototypeId);
return count/_amount;
}
}
public float GetProgress(Mind? mind)
{
if (mind?.OwnedEntity == null) return 0f;
if (!mind.OwnedEntity.TryGetComponent<ContainerManagerComponent>(out var containerManagerComponent)) return 0f;
float count = containerManagerComponent.CountPrototypeOccurencesRecursive(PrototypeId);
return count/Amount;
public float Difficulty => 1f;
public bool Equals(IObjectiveCondition? other)
{
return other is StealCondition stealCondition &&
Equals(_mind, stealCondition._mind) &&
_prototypeId == stealCondition._prototypeId && _amount == stealCondition._amount;
}
public float GetDifficulty() => 1f;
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((StealCondition) obj);
}
public override int GetHashCode()
{
return HashCode.Combine(_mind, _prototypeId, _amount);
}
}
}