1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-17 23:57:14 +02:00

Remove all method.

This commit is contained in:
Sandu Liviu Catalin
2021-02-05 14:19:15 +02:00
parent e4d4b09f52
commit 66dca8785c
4 changed files with 90 additions and 6 deletions

View File

@ -262,6 +262,41 @@ void PvUnit::ModifyPrivilege(StackStrF & tag, SQInteger value)
ModifyPrivilege(ValidManager().GetValidEntryWithTag(tag.CacheHash())->mID, value);
}
// ------------------------------------------------------------------------------------------------
void PvUnit::RemoveAllPrivileges()
{
// Discard all privileges but not before gaining ownership of them
PvStatusList list = std::move(mPrivileges);
// Go over all entries and see if this unit will gain or loose any privileges from this change
for (const auto & e : list)
{
// Get the value that we have now after the change
SQInteger current = GetEntryValue(e.first);
// Were they literally the same?
if (current == e.second)
{
continue; // Don't even bother
}
// Retrieve the associated entry
PvEntry & entry = ValidManager().ValidEntry(e.first);
// Is there someone that can identify this change?
if (!entry.mOnModify.IsNull())
{
LightObj r = entry.mOnModify.Eval(current, e.second);
// Was this considered a change?
if (!r.IsNull())
{
DoChanged(e.first, r.Cast< bool >(), e.second);
}
}
else
{
// By default we use > comparison to decide upgrades
DoChanged(e.first, e.second > current, e.second);
}
}
}
// ------------------------------------------------------------------------------------------------
void PvUnit::AssignClass(const std::shared_ptr< PvClass > & cls)
{
@ -388,11 +423,12 @@ void Register_Privilege_Unit(HSQUIRRELVM vm, Table & ns)
// Member Methods
.Func(_SC("Can"), &SqPvUnit::Can)
.Func(_SC("Assign"), &SqPvUnit::AssignPrivilegeWithID)
.Func(_SC("AssignWithTag"), &SqPvUnit::AssignPrivilegeWithTag)
.FmtFunc(_SC("AssignWithTag"), &SqPvUnit::AssignPrivilegeWithTag)
.Func(_SC("Remove"), &SqPvUnit::RemovePrivilegeWithID)
.Func(_SC("RemoveWithTag"), &SqPvUnit::RemovePrivilegeWithTag)
.FmtFunc(_SC("RemoveWithTag"), &SqPvUnit::RemovePrivilegeWithTag)
.Func(_SC("Modify"), &SqPvUnit::ModifyPrivilegeWithID)
.Func(_SC("ModifyWithTag"), &SqPvUnit::ModifyPrivilegeWithTag)
.FmtFunc(_SC("ModifyWithTag"), &SqPvUnit::ModifyPrivilegeWithTag)
.Func(_SC("RemoveAll"), &SqPvUnit::RemoveAllPrivileges)
);
}