Mercurial > wow > breuesk
changeset 17:71fc79846a5d
nuke db without having to exit game
printouts for more things
populate random is working
killing bugs
author | John@Doomsday |
---|---|
date | Fri, 09 Mar 2012 13:26:56 -0500 |
parents | 16b7e6390f42 |
children | bf3e94bc3bf5 |
files | Core.lua Lists.lua |
diffstat | 2 files changed, 82 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/Core.lua Thu Mar 08 12:49:17 2012 -0500 +++ b/Core.lua Fri Mar 09 13:26:56 2012 -0500 @@ -113,7 +113,6 @@ return end local person = FixPersonName(param[2]) - bsk:Print(string.format("Fixed player name %s to %s",param[2],person)) bsk:SuicidePerson(person,param[3]) elseif param[1] == "lists" then if param[2] == nil or param[2] == "" then @@ -136,6 +135,8 @@ return end bsk:TrimLists(param[2]) + elseif param[1] == "selfdestruct" then + bsk:SelfDestruct() end --if self.frame == nil then
--- a/Lists.lua Thu Mar 08 12:49:17 2012 -0500 +++ b/Lists.lua Fri Mar 09 13:26:56 2012 -0500 @@ -9,9 +9,9 @@ -- TODO: rename player -- TODO: list trimming --- TODO: lists allow double-add -- TODO: collapse slists into delimited strings for space - +-- TODO: list-of-lists must not use int indices. those will lead to peril. +-- holy crap long notes {{{ -- notes on list storage: -- Using names as keys as I do now is atrocious. -- It prevents insertions (twss) to the middle of the list because then it acts @@ -56,8 +56,11 @@ -- distribution at that point. -- * actually, fuck it. I'll give them an unlock command and -- let them screw over their lists :) +--}}} +-- there are some dep chains here. for instance, to have a raidIdP value, a +-- person must have a bsk.persons value which leads to a personName2id which +-- leads to a raidIdP --- todo: list-of-lists must not use int indices. those will lead to peril. bsk.lists = {} bsk.persons = {} @@ -71,6 +74,17 @@ local sformat = string.format local getn = table.getn +function bsk:SelfDestruct() + bsk.lists = {} + bsk.persons = {} + bsk.db.profile.persons = {} + bsk.db.profile.changes = {} + bsk.db.profile.listBase = {} + raidNameP = {} + raidIdP = {} + reserveIdP = {} + personName2id = {} +end function bsk:tcopy(to, from) for k,v in pairs(from) do if(type(v)=="table") then @@ -128,6 +142,16 @@ end end +function bsk:PrintRaidAndReserve() + bsk:Print("RaidNameP") + bsk:PrintTable(raidNameP) + bsk:Print("RaidIdP") + bsk:PrintTable(raidIdP) + bsk:Print("ReserveP") + bsk:PrintTable(reserveIdP) + bsk:Print("personName2id") + bsk:PrintTable(personName2id) +end --}}} function bsk:UpdatePersonsReverse() @@ -282,7 +306,7 @@ id = id:gsub("^0*(.*)","%1") -- nom all leading zeroes remaining if persons[id] and persons[id] ~= name then - self:Print(sformat("Namechange detected for %s - new is %s, please rename the existing entry", persons[id], name)) + self:Print(sformat("Namechange detected for %s - new is %s, please rename the existing entry", persons[id].main, name)) return end if persons[id] ~= nil then @@ -336,7 +360,7 @@ local id = personName2id[name] if bsk:IdIsInList(id,bsk.lists[listIndex]) then bsk:Print(sformat("Person %s is already on the reqeuested list",name)) - return + return false end bsk:Print(sformat("Adding %s (%s) to list %s (%s)", name, id, listName, listIndex)) local change = {action="AddToListEnd",arg={id=id,listIndex=listIndex}} @@ -364,11 +388,11 @@ self:Print("Cannot add person to list by random roll because an add-to-end operation has already occurred") return false end + local id = personName2id[name] if bsk:IdIsInList(id,bsk.lists[listIndex]) then bsk:Print(sformat("Person %s is already on the reqeuested list",name)) - return + return false end - local id = personName2id[name] local roll = math.random() bsk:Print(sformat("Adding %s (%s) to list %s (%s) with roll (%f)", name, id, listName, listIndex, roll)) local change = {action="AddToListRand",arg={id=id,listIndex=listIndex,roll=roll}} @@ -393,14 +417,15 @@ -- the goal here is to rotate the suicide list by 1 -- then we can just mash it on top of the intersection between the original -- list and the working copy + local replacement = shallowCopy(change.arg.affect) local temp = table.remove(replacement,1) -- pop tinsert(replacement,temp) -- push_back --bsk:Print(sformat("Before suicide of %s on list %s",slist[1],list.name)) --bsk:PrintTable(list) for i = 1, #list do - if list[i].id == affect[1] then - table.remove(affect,1) + if list[i].id == affected[1] then + table.remove(affected,1) list[i].id = replacement[1] table.remove(replacement,1) end @@ -409,14 +434,13 @@ return true end -function bsk:SuicidePerson(name,list) +function bsk:SuicidePerson(name,listName) -- require admin bsk:PopulateRaidList() local listIndex = bsk:GetListIndex(listName) local id = personName2id[name] local affect=bsk:GetSuicideList(id,bsk.lists[listIndex]) local change = {action="SuicidePerson",arg={affect=affect,listIndex=listIndex}} - bsk:PrintTable(change) bsk:StartChange(change) if bsk:DoSuicidePerson(change) then bsk:CommitChange(change) @@ -426,7 +450,6 @@ function bsk:TrimLists(time) if not bsk:CheckListCausality() then self:Print("Unable to trim lists due to violated causality") - return false end @@ -459,32 +482,47 @@ end --}}} --- Higher order actions (ie calls other Doers){{{ +-- Higher order actions (ie calls other standard actions){{{ function bsk:AddMissingPersons() bsk:PopulateRaidList() local t = {} - for i,_ in pairs(bsk.persons) do - t[i] = true + for id,_ in pairs(bsk.persons) do + t[id] = true end - for i,_ in pairs(raidNameP) do - if t[i] == nil then - bsk:Print(sformat("Person %s is missing from the persons list - adding",i)) - bsk:AddPerson(i) + for name,_ in pairs(raidNameP) do + if personName2id[name] == nil then + bsk:Print(sformat("Person %s is missing from the persons list - adding",name)) + bsk:AddPerson(name) end end -- TODO: batch into a single op - no need to spam 25 messages in a row end -function bsk:PopulateListRandom(index) - -- difference (raid+reserve)^list, then random shuffle that, then add +function bsk:PopulateListRandom(listIndex) + -- difference (raid+reserve)-list, then random shuffle that, then add bsk:PopulateRaidList() - local list = bsk.lists[index] + local list = bsk.lists[listIndex] - local t = {} - --for i = 1,#list do - -- if not (raidNameP(list[i]) or reserveIdP(list[i])) then - -- tinsert(t,) - -- end - --end + local t = {} -- after loops, contains intersection of IDs present between raid and reserve + for i,v in pairs(raidIdP) do + if v then t[i] = true end + end + for i,v in pairs(reserveIdP) do + if v then t[i] = true end + end + + -- now remove from t all of the people already present on the list + for i = 1,#list do + if t[list[i].id] then + t[list[i].id] = false + end + end + + -- add all remaining + for i,v in pairs(t) do + if v then + bsk:AddPersonToListRandom(bsk.persons[i].main,list.name) -- TODO: APTLR keys off of string names. probably need to change this. + end + end end --}}} -- "Soft" actions- ie things that cause nonpermanent state {{{ @@ -507,7 +545,7 @@ --}}} --- The following code is from Xinhuan (wowace forum member) +-- The following (adapted) code is from Xinhuan (wowace forum member) -- Pre-create the unitID strings we will use local pID = {} local rID = {} @@ -520,32 +558,31 @@ function bsk:PopulateRaidList() local inParty = GetNumPartyMembers() local inRaid = GetNumRaidMembers() - local add = function(name) raidNameP[name]=true; if personName2id[id] == nil then end end + local add = function(unitNameArg) + local name = UnitName(unitNameArg) + raidNameP[name]=true + if personName2id[name] ~= nil then + raidIdP[personName2id[name]]=true + end + end wipe(raidNameP) wipe(raidIdP) if inRaid > 0 then for i = 1, inRaid do - local name = UnitName(rID[i]) - raidNameP[name]=true - raidIdP[personName2id[name]]=true + add(rID[i]) end elseif inParty > 0 then for i = 1, inParty do - local name = UnitName(pID[i]) - raidNameP[name]=true - raidIdP[personName2id[name]]=true + add(pID[i]) end -- Now add yourself as the last party member - local name = UnitName("player") - raidNameP[name]=true - raidIdP[personName2id[name]]=true + add("player") else -- You're alone - local name = UnitName("player") - raidNameP[name]=true - raidIdP[personName2id[name]]=true + add("player") end + bsk:PrintTable(raidNameP) end -- undo rules! @@ -608,7 +645,7 @@ return i end end - assert(false) + return nil end local shuffleArray = function(array)