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

Assign/Remove/Modify methods.

This commit is contained in:
Sandu Liviu Catalin
2021-02-05 14:06:13 +02:00
parent 90597e4287
commit 4da00718f7
4 changed files with 132 additions and 31 deletions

View File

@ -161,7 +161,7 @@ void PvUnit::DoChanged(SQInteger id, bool status, SQInteger value) const
}
// ------------------------------------------------------------------------------------------------
void PvUnit::AssignStatus(SQInteger id, SQInteger value)
void PvUnit::AssignPrivilege(SQInteger id, SQInteger value)
{
// Find the current status of this entry
SQInteger current = GetEntryValue(id);
@ -182,7 +182,7 @@ void PvUnit::AssignStatus(SQInteger id, SQInteger value)
}
// ------------------------------------------------------------------------------------------------
void PvUnit::RemoveStatus(SQInteger id)
void PvUnit::RemovePrivilege(SQInteger id)
{
// Look for the status of this value
auto itr = mPrivileges.find(id);
@ -212,7 +212,7 @@ void PvUnit::RemoveStatus(SQInteger id)
}
// ------------------------------------------------------------------------------------------------
void PvUnit::ModifyStatus(SQInteger id, SQInteger value)
void PvUnit::ModifyPrivilege(SQInteger id, SQInteger value)
{
// Find the current status of this entry
SQInteger current = GetEntryValue(id);
@ -244,6 +244,24 @@ void PvUnit::ModifyStatus(SQInteger id, SQInteger value)
}
}
// ------------------------------------------------------------------------------------------------
void PvUnit::AssignPrivilege(StackStrF & tag, SQInteger value)
{
AssignPrivilege(ValidManager().GetValidEntryWithTag(tag.CacheHash())->mID, value);
}
// ------------------------------------------------------------------------------------------------
void PvUnit::RemovePrivilege(StackStrF & tag)
{
RemovePrivilege(ValidManager().GetValidEntryWithTag(tag.CacheHash())->mID);
}
// ------------------------------------------------------------------------------------------------
void PvUnit::ModifyPrivilege(StackStrF & tag, SQInteger value)
{
ModifyPrivilege(ValidManager().GetValidEntryWithTag(tag.CacheHash())->mID, value);
}
// ------------------------------------------------------------------------------------------------
void PvUnit::AssignClass(const std::shared_ptr< PvClass > & cls)
{
@ -265,13 +283,13 @@ void PvUnit::AssignClass(const std::shared_ptr< PvClass > & cls)
// ------------------------------------------------------------------------------------------------
bool PvUnit::Can(SQInteger id) const
{
// Get the current status of the specified entry
SQInteger current = GetEntryValue(id);
// Retrieve the function responsible for the query event
const Function & query = GetOnQuery(id);
// Is there someone that can arbitrate this request?
if (!query.IsNull())
{
// Get the current status of the specified entry
SQInteger current = GetEntryValue(id);
// Attempt arbitration
LightObj r = query.Eval(current);
// If NULL or false the request was denied
@ -280,6 +298,11 @@ bool PvUnit::Can(SQInteger id) const
return true; // Request allowed
}
}
// We use the >= comparison to settle arbitration
else if (current >= ValidManager().ValidEntry(id).mDefault)
{
return true;
}
// Request failed, no arbitration
return false;
}
@ -364,6 +387,12 @@ void Register_Privilege_Unit(HSQUIRRELVM vm, Table & ns)
.CbFunc(_SC("OnGained"), &SqPvUnit::SetOnGained)
// Member Methods
.Func(_SC("Can"), &SqPvUnit::Can)
.Func(_SC("Assign"), &SqPvUnit::AssignPrivilegeWithID)
.Func(_SC("AssignWithTag"), &SqPvUnit::AssignPrivilegeWithTag)
.Func(_SC("Remove"), &SqPvUnit::RemovePrivilegeWithID)
.Func(_SC("RemoveWithTag"), &SqPvUnit::RemovePrivilegeWithTag)
.Func(_SC("Modify"), &SqPvUnit::ModifyPrivilegeWithID)
.Func(_SC("ModifyWithTag"), &SqPvUnit::ModifyPrivilegeWithTag)
);
}