mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 18:27:24 +01:00
Add ReapplyState & ReapplyStateName with Helpers.
This commit is contained in:
parent
0a9693daea
commit
20914bc064
1 changed files with 60 additions and 0 deletions
|
|
@ -123,6 +123,48 @@ public sealed class StateApi : IGlamourerApiState, IApiService, IDisposable
|
||||||
return ApiHelpers.Return(GlamourerApiEc.Success, args);
|
return ApiHelpers.Return(GlamourerApiEc.Success, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GlamourerApiEc ReapplyState(int objectIndex, uint key, ApplyFlag flags)
|
||||||
|
{
|
||||||
|
var args = ApiHelpers.Args("Index", objectIndex, "Key", key, "Flags", flags);
|
||||||
|
if (_helpers.FindExistingState(objectIndex, out var state) != GlamourerApiEc.Success)
|
||||||
|
return ApiHelpers.Return(GlamourerApiEc.ActorNotFound, args);
|
||||||
|
|
||||||
|
if (state == null)
|
||||||
|
return ApiHelpers.Return(GlamourerApiEc.NothingDone, args);
|
||||||
|
|
||||||
|
if (!state.CanUnlock(key))
|
||||||
|
return ApiHelpers.Return(GlamourerApiEc.InvalidKey, args);
|
||||||
|
|
||||||
|
Reapply(_objects.Objects[objectIndex], state, key, flags);
|
||||||
|
return ApiHelpers.Return(GlamourerApiEc.Success, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlamourerApiEc ReapplyStateName(string playerName, uint key, ApplyFlag flags)
|
||||||
|
{
|
||||||
|
var args = ApiHelpers.Args("Name", playerName, "Key", key, "Flags", flags);
|
||||||
|
var states = _helpers.FindExistingStates(playerName);
|
||||||
|
|
||||||
|
var any = false;
|
||||||
|
var anyReapplied = false;
|
||||||
|
foreach (var state in states)
|
||||||
|
{
|
||||||
|
any = true;
|
||||||
|
if (!state.CanUnlock(key))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
anyReapplied = true;
|
||||||
|
anyReapplied |= Reapply(state, key, flags) is GlamourerApiEc.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (any)
|
||||||
|
ApiHelpers.Return(GlamourerApiEc.NothingDone, args);
|
||||||
|
|
||||||
|
if (!anyReapplied)
|
||||||
|
return ApiHelpers.Return(GlamourerApiEc.InvalidKey, args);
|
||||||
|
|
||||||
|
return ApiHelpers.Return(GlamourerApiEc.Success, args);
|
||||||
|
}
|
||||||
|
|
||||||
public GlamourerApiEc RevertState(int objectIndex, uint key, ApplyFlag flags)
|
public GlamourerApiEc RevertState(int objectIndex, uint key, ApplyFlag flags)
|
||||||
{
|
{
|
||||||
var args = ApiHelpers.Args("Index", objectIndex, "Key", key, "Flags", flags);
|
var args = ApiHelpers.Args("Index", objectIndex, "Key", key, "Flags", flags);
|
||||||
|
|
@ -265,6 +307,24 @@ public sealed class StateApi : IGlamourerApiState, IApiService, IDisposable
|
||||||
ApiHelpers.Lock(state, key, flags);
|
ApiHelpers.Lock(state, key, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private GlamourerApiEc Reapply(ActorState state, uint key, ApplyFlag flags)
|
||||||
|
{
|
||||||
|
if (!_objects.TryGetValue(state.Identifier, out var actors) || !actors.Valid)
|
||||||
|
return GlamourerApiEc.ActorNotFound;
|
||||||
|
|
||||||
|
foreach (var actor in actors.Objects)
|
||||||
|
Reapply(actor, state, key, flags);
|
||||||
|
|
||||||
|
return GlamourerApiEc.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Reapply(Actor actor, ActorState state, uint key, ApplyFlag flags)
|
||||||
|
{
|
||||||
|
var source = (flags & ApplyFlag.Once) != 0 ? StateSource.IpcManual : StateSource.IpcFixed;
|
||||||
|
_stateManager.ReapplyState(actor, state, false, source, true);
|
||||||
|
ApiHelpers.Lock(state, key, flags);
|
||||||
|
}
|
||||||
|
|
||||||
private void Revert(ActorState state, uint key, ApplyFlag flags)
|
private void Revert(ActorState state, uint key, ApplyFlag flags)
|
||||||
{
|
{
|
||||||
var source = (flags & ApplyFlag.Once) != 0 ? StateSource.IpcManual : StateSource.IpcFixed;
|
var source = (flags & ApplyFlag.Once) != 0 ? StateSource.IpcManual : StateSource.IpcFixed;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue