Quantcast

Added !roll pass command to pass on rolls that have been issued with !roll [start].

F16Gaming [03-21-12 - 19:26]
Added !roll pass command to pass on rolls that have been issued with !roll [start].
Filename
CommandManager.lua
PlayerManager.lua
RollManager.lua
diff --git a/CommandManager.lua b/CommandManager.lua
index 1a4d7b5..092b853 100644
--- a/CommandManager.lua
+++ b/CommandManager.lua
@@ -175,6 +175,22 @@ CM:Register({"version", "ver", "v"}, PM.Access.Groups.User.Level, function(args,
 	return C.Version
 end, "Print the version of Command")

+CM:Register({"lock", "lockdown"}, PM.Access.Groups.Admin.Level, function(args, sender, isChat)
+	if #args <= 0 then
+		return false, "Too few arguments. Usage: lock <player>"
+	end
+	local player = PM:GetOrCreatePlayer(args[1])
+	return PM:SetLocked(player, true)
+end, "Lock a player.")
+
+CM:Register({"unlock", "open"}, PM.Access.Groups.Admin.Level, function(args, sender, isChat)
+	if #args <= 0 then
+		return false, "Too few arguments. Usage: lock <player>"
+	end
+	local player = PM:GetOrCreatePlayer(args[1])
+	return PM:SetLocked(player, false)
+end, "Unlock a player.")
+
 CM:Register({"getaccess"}, PM.Access.Groups.User.Level, function(args, sender, isChat)
 	if #args <= 0 then
 		return false, "Too few arguments. Usage: getaccess <player>"
@@ -529,6 +545,8 @@ CM:Register({"roll", "r"}, PM.Access.Groups.Op.Level, function(args, sender, isC
 			end
 		end
 		return RM:StartRoll(sender.Info.Name, item, time)
+	elseif args[1] == "pass" then
+		return RM:PassRoll(sender.Info.Name)
 	elseif args[1] == "stop" then
 		return RM:StopRoll()
 	elseif args[1] == "time" then
@@ -539,7 +557,11 @@ CM:Register({"roll", "r"}, PM.Access.Groups.Op.Level, function(args, sender, isC
 			min = tonumber(args[2])
 			max = tonumber(args[3])
 		end
-		return RM:DoRoll(min, max)
+		if not min and (args[2] == "pass" or args[2] == "p" or args[2] == "skip") then
+			return RM:PassRoll()
+		else
+			return RM:DoRoll(min, max)
+		end
 	elseif args[1] == "set" then
 		if #args < 3 then
 			return false, "Usage: roll set <min||max> <amount>"
diff --git a/PlayerManager.lua b/PlayerManager.lua
index cca6082..22cd028 100644
--- a/PlayerManager.lua
+++ b/PlayerManager.lua
@@ -90,7 +90,8 @@ local Player = {
 		Deny = {}
 	},
 	Settings = {
-		Invite = true
+		Invite = true,
+		Locked = false
 	}
 }

@@ -258,6 +259,7 @@ end
 --
 function PM:PlayerAccessRemove(player, command)
 	if not command then return false, "No command specified" end
+	if self:IsLocked(player) then return false, "Target player is locked and cannot be modified." end
 	for i,v in pairs(player.Access.Allow) do
 		if v == command then table.remove(player.Access.Allow, i) end
 	end
@@ -277,6 +279,7 @@ end
 --
 function PM:PlayerAccess(player, command, allow)
 	if not command then return false, "No command specified" end
+	if self:IsLocked(player) then return false, "Target player is locked and cannot be modified." end
 	local mode = "allowed"
 	if allow then
 		if CET:HasValue(player.Access.Deny, command) then
@@ -313,6 +316,36 @@ function PM:UpdatePlayer(player)
 	log:Normal(("Updated player %q."):format(player.Info.Name))
 end

+--- Check if provided player is locked.
+-- @param player Player object to check.
+--
+function PM:IsLocked(player)
+	if type(player) == "table" then
+		if player.Settings then
+			return player.Settings.Locked
+		else
+			return false
+		end
+	elseif type(player) == "string" then
+		return self:IsLocked(self:GetOrCreatePlayer(player))
+	end
+	return true
+end
+
+--- Set lock status on a player.
+-- @param player Player object to change.
+-- @param locked True for locked, False for unlocked.
+--
+function PM:SetLocked(player, locked)
+	if type(player) ~= "table" then
+		player = self:GetOrCreatePlayer(tostring(player))
+	end
+	player.Settings.Locked = locked
+	local mode = "locked"
+	if not locked then mode = "unlocked" end
+	return ("Player %s has been %s."):format(player.Info.Name, mode)
+end
+
 --- Check if supplied player is on the player's friends list.
 -- @param player Player object of the player to check.
 -- @return True if friend, false otherwise.
@@ -417,6 +450,7 @@ function PM:SetAccessGroup(player, group)
 	if not CET:HasKey(self.Access.Groups, group) then
 		return false, ("No such access group: %q"):format(group)
 	end
+	if self:IsLocked(player) then return false, "Target player is locked and cannot be modified." end
 	player.Info.Group = group
 	self:UpdatePlayer(player)
 	return ("Set the access level of %q to %d (%s)"):format(player.Info.Name, PM:GetAccess(player), player.Info.Group)
@@ -568,6 +602,7 @@ function PM:PromoteToLeader(player)
 		return false, ("%s is not in the group."):format(player.Info.Name)
 	end
 	if GT:IsGroupLeader() then
+		if self:IsLocked(player) then return false, "Target player is locked and cannot be modified." end
 		PromoteToLeader(player.Info.Name)
 		return ("Promoted %s to group leader."):format(player.Info.Name)
 	else
@@ -592,6 +627,7 @@ function PM:PromoteToAssistant(player)
 		return false, "Cannot promote to assistant when not in a raid."
 	end
 	if GT:IsGroupLeader() then
+		if self:IsLocked(player) then return false, "Target player is locked and cannot be modified." end
 		PromoteToAssistant(player.Info.Name)
 		return ("Promoted %s to assistant."):format(player.Info.Name)
 	else
@@ -611,6 +647,7 @@ function PM:DemoteAssistant(player)
 		return false, "Cannot demote when not in a raid."
 	end
 	if GT:IsGroupLeader() then
+		if self:IsLocked(player) then return false, "Target player is locked and cannot be modified." end
 		DemoteAssistant(player.Info.Name)
 		return ("Demoted %s."):format(player.Info.Name)
 	else
diff --git a/RollManager.lua b/RollManager.lua
index 5d56e6b..c6c1c5c 100644
--- a/RollManager.lua
+++ b/RollManager.lua
@@ -142,10 +142,10 @@ function RM:StartRoll(sender, item, time)
 	if item then
 		self.Item = item
 		RollTimer.Frame:SetScript("OnUpdate", RollTimerUpdate)
-		return ("%s started a roll for %s, ends in %d seconds! Type /roll %d %d"):format(self.Sender, self.Item, time, self.Settings.MIN_ROLL, self.Settings.MAX_ROLL)
+		return ("%s started a roll for %s, ends in %d seconds! Type /roll %d %d. Type !roll pass to pass."):format(self.Sender, self.Item, time, self.Settings.MIN_ROLL, self.Settings.MAX_ROLL)
 	else
 		RollTimer.Frame:SetScript("OnUpdate", RollTimerUpdate)
-		return ("%s started a roll, ends in %d seconds! Type /roll %d %d"):format(self.Sender, time, self.Settings.MIN_ROLL, self.Settings.MAX_ROLL)
+		return ("%s started a roll, ends in %d seconds! Type /roll %d %d. Type !roll pass to pass."):format(self.Sender, time, self.Settings.MIN_ROLL, self.Settings.MAX_ROLL)
 	end
 	-- We shouldn't reach this place
 	self.Running = false
@@ -187,6 +187,17 @@ function RM:AddRoll(name, roll)
 	if RollCount >= self.NumGroupMembers then RM:StopRoll(true) end
 end

+function RM:PassRoll(name)
+	name = name or UnitName("player")
+	if CET:HasKey(Rollers, name) then
+		return false, ("%s has already rolled (%d)"):format(name, Rollers[name])
+	end
+	Rollers[name] = -1
+	RollCount = RollCount + 1
+	if RollCount >= self.NumGroupMembers then RM:StopRoll(true) end
+	return ("%s has passed on the roll."):format(name)
+end
+
 function RM:GetTime()
 	if self.Running then
 		return ("%d seconds remaining!"):format(max(ceil(RollTimer.Time - RollTimer.Current), 0))
@@ -214,7 +225,6 @@ function RM:AnnounceResult(expire)
 			roll = tonumber(v)
 			name = k
 			wipe(additional)
-			numAdditional = 0
 		elseif tonumber(v) == roll then
 			additional[k] = tonumber(v)
 			numAdditional = numAdditional + 1