forked from Bastion/Bastion
				
			
							parent
							
								
									7e0327bb78
								
							
						
					
					
						commit
						29e19b931f
					
				| @ -0,0 +1,153 @@ | |||||||
|  | local Tinkr, Bastion = ... | ||||||
|  | 
 | ||||||
|  | local List = {} | ||||||
|  | List.__index = List | ||||||
|  | 
 | ||||||
|  | function List:New() | ||||||
|  |     local self = setmetatable({}, List) | ||||||
|  |     self._list = {} | ||||||
|  |     return self | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:push(value) | ||||||
|  |     table.insert(self._list, value) | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:pop() | ||||||
|  |     return table.remove(self._list) | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:peek() | ||||||
|  |     return self._list[#self._list] | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:count() | ||||||
|  |     return #self._list | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:clear() | ||||||
|  |     self._list = {} | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:contains(value) | ||||||
|  |     for _, v in ipairs(self._list) do | ||||||
|  |         if v == value then | ||||||
|  |             return true | ||||||
|  |         end | ||||||
|  |     end | ||||||
|  |     return false | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:remove(value) | ||||||
|  |     for i, v in ipairs(self._list) do | ||||||
|  |         if v == value then | ||||||
|  |             table.remove(self._list, i) | ||||||
|  |             return true | ||||||
|  |         end | ||||||
|  |     end | ||||||
|  |     return false | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:each(callback) | ||||||
|  |     for _, v in ipairs(self._list) do | ||||||
|  |         if callback(v) then | ||||||
|  |             break | ||||||
|  |         end | ||||||
|  |     end | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:map(callback) | ||||||
|  |     local newList = List.new() | ||||||
|  |     for _, v in ipairs(self._list) do | ||||||
|  |         newList:push(callback(v)) | ||||||
|  |     end | ||||||
|  |     return newList | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:filter(callback) | ||||||
|  |     local newList = List.new() | ||||||
|  |     for _, v in ipairs(self._list) do | ||||||
|  |         if callback(v) then | ||||||
|  |             newList:push(v) | ||||||
|  |         end | ||||||
|  |     end | ||||||
|  |     return newList | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:reduce(callback, initialValue) | ||||||
|  |     local result = initialValue | ||||||
|  |     for _, v in ipairs(self._list) do | ||||||
|  |         result = callback(result, v) | ||||||
|  |     end | ||||||
|  |     return result | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:find(callback) | ||||||
|  |     for _, v in ipairs(self._list) do | ||||||
|  |         if callback(v) then | ||||||
|  |             return v | ||||||
|  |         end | ||||||
|  |     end | ||||||
|  |     return nil | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:findIndex(callback) | ||||||
|  |     for i, v in ipairs(self._list) do | ||||||
|  |         if callback(v) then | ||||||
|  |             return i | ||||||
|  |         end | ||||||
|  |     end | ||||||
|  |     return nil | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:sort(callback) | ||||||
|  |     table.sort(self._list, callback) | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:reverse() | ||||||
|  |     local newList = List.new() | ||||||
|  |     for i = #self._list, 1, -1 do | ||||||
|  |         newList:push(self._list[i]) | ||||||
|  |     end | ||||||
|  |     return newList | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:clone() | ||||||
|  |     local newList = List.new() | ||||||
|  |     for _, v in ipairs(self._list) do | ||||||
|  |         newList:push(v) | ||||||
|  |     end | ||||||
|  |     return newList | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:concat(list) | ||||||
|  |     local newList = List.new() | ||||||
|  |     for _, v in ipairs(self._list) do | ||||||
|  |         newList:push(v) | ||||||
|  |     end | ||||||
|  |     for _, v in ipairs(list._list) do | ||||||
|  |         newList:push(v) | ||||||
|  |     end | ||||||
|  |     return newList | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:join(separator) | ||||||
|  |     local result = "" | ||||||
|  |     for i, v in ipairs(self._list) do | ||||||
|  |         result = result .. v | ||||||
|  |         if i < #self._list then | ||||||
|  |             result = result .. separator | ||||||
|  |         end | ||||||
|  |     end | ||||||
|  |     return result | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:toString() | ||||||
|  |     return self:join(", ") | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function List:__tostring() | ||||||
|  |     return self:toString() | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | return List | ||||||
| @ -0,0 +1,50 @@ | |||||||
|  | local Tinkr, Bastion = ... | ||||||
|  | 
 | ||||||
|  | local ObjectManager = {} | ||||||
|  | ObjectManager.__index = ObjectManager | ||||||
|  | 
 | ||||||
|  | function ObjectManager:New() | ||||||
|  |     local self = setmetatable({}, ObjectManager) | ||||||
|  | 
 | ||||||
|  |     self._objects = {} | ||||||
|  | 
 | ||||||
|  |     self.enemies = Bastion.List:New() | ||||||
|  |     self.friends = Bastion.List:New() | ||||||
|  |     self.activeEnemies = Bastion.List:New() | ||||||
|  |     self.explosives = Bastion.List:New() | ||||||
|  | 
 | ||||||
|  |     return self | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | function ObjectManager:Refresh() | ||||||
|  |     self.enemies:clear() | ||||||
|  |     self.friends:clear() | ||||||
|  |     self.activeEnemies:clear() | ||||||
|  |     self.explosives:clear() | ||||||
|  | 
 | ||||||
|  |     local objects = Objects() | ||||||
|  | 
 | ||||||
|  |     for _, object in pairs(objects) do | ||||||
|  |         if ObjectType(object) == 5 or ObjectType(object) == 6 then | ||||||
|  |             local unit = Bastion.UnitManager:GetObject(ObjectGUID(object)) | ||||||
|  |             if not unit then | ||||||
|  |                 unit = Bastion.Unit:New(object) | ||||||
|  |                 Bastion.UnitManager:SetObject(unit) | ||||||
|  |             end | ||||||
|  | 
 | ||||||
|  |             if unit:GetID() == 120651 then | ||||||
|  |                 self.explosives:push(unit) | ||||||
|  |             elseif unit:IsPlayer() and unit:IsInParty() then | ||||||
|  |                 self.friends:push(unit) | ||||||
|  |             elseif unit:IsEnemy() then | ||||||
|  |                 self.enemies:push(unit) | ||||||
|  | 
 | ||||||
|  |                 if unit:IsAffectingCombat() then | ||||||
|  |                     self.activeEnemies:push(unit) | ||||||
|  |                 end | ||||||
|  |             end | ||||||
|  |         end | ||||||
|  |     end | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | return ObjectManager | ||||||
					Loading…
					
					
				
		Reference in new issue