Initial commit

This commit is contained in:
Valentin Brandl
2020-03-30 18:33:48 +02:00
commit 7cc380a042
194 changed files with 20062 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,132 @@
local Graph = {
getColor = function(self, value, trace)
local colorIndex = math.ceil((value - self.min[trace]) / ((self.max[trace] - self.min[trace]) / #self.gradient[trace]))
if colorIndex == 0 then colorIndex = 1 end
if self.target.isColor() then
return self.gradient[trace][colorIndex]
else
return colors.white
end
end,
draw = function(self)
--get the updates first.
for i=1, #self.update do
self.history[i][#self.history[i] + 1] = self.update[i]()
end
if self.target.setTextScale then self.target.setTextScale(0.5) end
self.target.setBackgroundColor(colors.black)
self.target.setTextColor(colors.white)
self.target.clear()
local newMax, newMin = self.max[1], self.min[1]
--draw traces
for trace=1,#self.update do
if self.history[trace][#self.history[trace]] > self.max[trace] then
if self.sharedBounds and self.history[trace][#self.history[trace]] > newMax then
newMax = self.history[trace][#self.history[trace]]
else
self.max[trace] = self.history[trace][#self.history[trace]]
end
elseif self.history[trace][#self.history[trace]] < self.min[trace] then
if self.sharedBounds and self.history[trace][#self.history[trace]] < newMin then
newMin = self.history[trace][#self.history[trace]]
else
self.min[trace] = self.history[trace][#self.history[trace]]
end
end
local xLim, yLim = self.target.getSize()
if #self.history[trace] > xLim then table.remove(self.history[trace], 1) end
--we set up our value string for numeric value readout here, but draw it later so it doesn't interfere with the full-screen trace.
for i=1, #self.history[trace] do
self.target.setCursorPos(i, yLim - math.ceil((yLim - 1) * (self.history[trace][i] - self.min[trace]) / (self.max[trace] - self.min[trace])))
self.target.setBackgroundColor(self:getColor(self.history[trace][i], trace))
self.target.write(" ")
self.target.setBackgroundColor(colors.black)
end
end
--adjust min-max for next round.
if self.sharedBounds then
for i=1, #self.update do
self.max[i] = newMax
self.min[i] = newMin
end
end
--draw trace labels.
for trace = 1, #self.update do
local valueString, cStart, cEnd = ""
if self.valueText[trace] then
valueString = self.valueText[trace]..": "
cStart = #valueString + 1
valueString = valueString..tostring(self.history[trace][#self.history[trace]])
cEnd = #valueString
valueString = valueString.." / "..self.max[trace]
end
local xLim, yLim = self.target.getSize()
if trace + 1 <= yLim then
self.target.setCursorPos(2, trace + 1)
for i=1, #valueString do
if i >= cStart and i <= cEnd then
self.target.setTextColor(self:getColor(self.history[trace][#self.history[trace]], trace))
end
self.target.write(string.sub(valueString, i, i))
self.target.setTextColor(colors.white)
end
end
end
end,
tostring = function(self)
local valueString = ""
if self.valueText[1] then
valueString = self.valueText[1]..": "
end
valueString = valueString..tostring(self.history[1][#self.history[1]]).." / "..self.max[1]
return valueString
end,
}
local gmetatable = {
__index = Graph,
__tostring = function(g) return g:tostring() end,
}
function new(target, updateFunction, valueText, gradientTable, min, max, sharedBounds)
if not target then return nil, "Must specify output target!" end
if not updateFunction then return nil, "Must specify update function!" end
local g = {
min = type(min) == "table" and min or {},
max = type(max) == "table" and max or {},
target = target,
update = type(updateFunction) == "table" and updateFunction or {updateFunction},
history = {},
gradient = {},
valueText = type(valueText) == "table" and valueText or {valueText},
sharedBounds = shareBounds or false
}
for i=1, #g.update do
g.history[i] = {}
end
if type(min) ~= "table" then
local setMin = min or 0
for i=1, #g.update do
g.min[i] = setMin
end
end
if type(max) ~= "table" then
local setMax = max or 1
for i=1, #g.update do
g.max[i] = setMax
end
end
if gradientTable and type(gradientTable) == "table" and type(gradientTable[1]) == "table" then
g.gradient = gradientTable
elseif gradientTable and type(gradientTable) == "table" then
for i=1, #g.update do
g.gradient[i] = gradientTable
end
else
for i=1, #g.update do
g.gradient[i] = {colors.red, colors.orange, colors.yellow, colors.lime, colors.green}
end
end
setmetatable(g, gmetatable)
return g
end

View File

@@ -0,0 +1,45 @@
local function waitForResponse( _id )
while true do
local event = {os.pullEvent()}
if event[2] == _id then
if event[1] == "ocs_success" then
return event[3]
elseif event[1] == "ocs_error" then
error(event[3],2)
end
end
end
end
function wrap(side)
local wrappedTable = {}
if peripheral.getType(side) == "sensor" then
local periph = peripheral.wrap(side)
for k,v in pairs(periph) do
if type(k) == "string" and type(v) == "function" then
wrappedTable[k] = function(...)
local id = periph[k](...)
if id == -1 then
return false
end
return waitForResponse(id)
end
end
end
return wrappedTable
else
return nil, "not a sensor"
end
end
function call(side, ...)
if peripheral.getType(side) == "sensor" then
local id = peripheral.call(side, ...)
if id == -1 then
return false
end
return waitForResponse(id)
else
return nil, "not a sensor"
end
end

View File

@@ -0,0 +1,285 @@
local sideNames = rs.getSides()
local sensorSides = {}
local sideSelection, targetSelection, targetOffset, detailOffset = 1, 1, 1, 1
local detailLines, targetNameMenuTable
local graphing, graphSide, graphTarget, graphMatch, graphInstance = false
os.loadAPI("ocs/apis/graph")
os.loadAPI("ocs/apis/sensor")
local function checkSensors()
for _,side in ipairs(sideNames) do
if peripheral.getType(side) == "sensor" then
sensorSides[side] = true
else
sensorSides[side] = false
end
end
end
local function writeEntry(menuTable, index, cursorPos)
if cursorPos == index then
term.setBackgroundColor(term.isColor() and colors.blue or colors.white)
term.setTextColor(term.isColor() and colors.white or colors.black)
term.write(string.sub(menuTable[index], 1, 16))
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
else
term.write(string.sub(menuTable[index], 1, 16))
end
end
local function toLines(currTable, linesTable, trackingTable, depth)
for k,v in pairs(currTable) do
if type(v) == "table" then
table.insert(linesTable, string.rep(" ", depth)..tostring(k)..":")
if trackingTable[v] then
table.insert(linesTable, string.rep(" ", depth + 1).."<Cyclic Reference: "..trackingTable[v]..">")
else
trackingTable[v] = #linesTable
toLines(v, linesTable, trackingTable, depth + 1)
end
else
table.insert(linesTable, string.rep(" ", depth)..tostring(k).."> "..tostring(v))
end
end
end
local function drawDividerDown(startY)
local w, h = term.getSize()
for i=startY, h do
term.setCursorPos(17, i)
term.write("|")
end
end
local function redraw()
w, h = term.getSize()
--pre-fetch sensor targets and detailed target information.
local targetNames = nil
detailLines = {}
checkSensors()
if sensorSides[sideNames[sideSelection]] then
targetNames = sensor.call(sideNames[sideSelection], "getSensorName") and sensor.call(sideNames[sideSelection], "getTargets")
targetNameMenuTable = {}
if targetNames then
for k,v in pairs(targetNames) do
table.insert(targetNameMenuTable, k)
end
table.sort(targetNameMenuTable)
if #targetNameMenuTable > 0 then
toLines(sensor.call(sideNames[sideSelection], "getTargetDetails", targetNameMenuTable[targetSelection]), detailLines, {}, 0)
end
end
end
--now draw the screen.
term.clear()
term.setCursorPos(1, 1)
term.write("=Sensor Info Viewer="..string.rep("=", w - 20))
term.setCursorPos(1, 2)
for n,side in ipairs(sideNames) do
if n == sideSelection then
term.setBackgroundColor(term.isColor() and colors.blue or colors.white)
term.setTextColor(term.isColor() and colors.white or colors.black)
term.write(side)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.write(" ")
else
term.write(side.." ")
end
end
term.setCursorPos(1, 3)
term.write("-Targets--------+-Info-"..string.rep("-", w - 23))
if targetNames then
--make sure we have valid targets, even if we have a valid sensor.
if #targetNameMenuTable > 0 then
term.setCursorPos(1, 4)
if targetOffset > 1 then
term.write("/\\")
else
writeEntry(targetNameMenuTable, 1, targetSelection)
end
--h-5 to leave room for top and bottom entries.
for i=1, math.min(h - 5, #targetNameMenuTable - 1) do
term.setCursorPos(1, i + 4)
writeEntry(targetNameMenuTable, targetOffset + i, targetSelection)
end
if #targetNameMenuTable >= h then
term.setCursorPos(1, h)
if #targetNameMenuTable > targetOffset + h - 4 then
term.write("\\/")
else
writeEntry(targetNameMenuTable, #targetNameMenuTable, targetSelection)
end
end
--detailed info.
for i=1, math.min(h - 3, #detailLines - ((detailOffset - 1) * (h - 3))) do
term.setCursorPos(17, i + 3)
term.write("|"..string.sub(detailLines[(detailOffset - 1) * (h - 3) + i], 1, w - 17))
end
local currX, currY = term.getCursorPos()
drawDividerDown(currY + 1)
else
term.setCursorPos(1, 4)
term.write("No targets found|")
drawDividerDown(5)
end
else
if peripheral.getType(sideNames[sideSelection]) == "sensor" then
term.setCursorPos(1, 4)
term.write("No sensor card |")
drawDividerDown(5)
else
term.setCursorPos(1, 4)
term.write("No sensor found |")
drawDividerDown(5)
end
end
term.setCursorPos(1, h)
end
local function findGraphMatch(currTable, target, matchCount, trackingTable)
for k, v in pairs(currTable) do
if type(v) == "table" then
if trackingTable[v] then return false end
trackingTable[v] = true
ret, path, count = findGraphMatch(v, target, matchCount, trackingTable)
if ret and path then
return ret, tostring(k).."-"..path
elseif count then
matchCount = count
end
elseif type(v) == "number" then
matchCount = matchCount + 1
if matchCount == target then return v, tostring(k) end
end
end
return false, nil, matchCount
end
local function createGraph(targetNum)
local monSide = ""
for k, side in ipairs(rs.getSides()) do
if peripheral.getType(side) == "monitor" then
monSide = side
break
end
end
if monSide and targetNum >= 1 and findGraphMatch(sensor.call(graphSide, "getTargetDetails", graphTarget), targetNum, 0, {}) then
graphMatch = targetNum
local val, name = findGraphMatch(sensor.call(graphSide, "getTargetDetails", graphTarget), targetNum, 0, {})
local updateFunc = function() return (findGraphMatch(sensor.call(graphSide, "getTargetDetails", graphTarget), graphMatch, 0, {})) end
graphInst = graph.new(peripheral.wrap(monSide), updateFunc, name)
return graphInst
end
end
while true do
redraw()
local e, p1 = os.pullEvent()
if e == "key" then
local w, h = term.getSize()
if p1 == 203 then
--left, selects previous side
if sideSelection > 1 then
sideSelection = sideSelection - 1
targetSelection = 1
targetOffset = 1
detailOffset = 1
detailLines = nil
end
elseif p1 == 205 then
--right, selects next side
if sideSelection < 6 then
sideSelection = sideSelection + 1
targetSelection = 1
targetOffset = 1
detailOffset = 1
detailLines = nil
end
elseif p1 == 200 then
--up, selects previous target, adjusting offset if necessary.
if targetSelection > 1 then
if targetSelection - targetOffset + 1 == 2 and targetOffset > 1 then
targetOffset = targetOffset - 1
end
targetSelection = targetSelection - 1
detailOffset = 1
detailLines = nil
end
elseif p1 == 208 then
--down, selects next target, adjusting offset if necessary.
if targetNameMenuTable and targetSelection < #targetNameMenuTable then
if targetSelection - targetOffset + 1 == h - 4 and targetSelection ~= #targetNameMenuTable - 1 then
targetOffset = targetOffset + 1
end
targetSelection = targetSelection + 1
detailOffset = 1
detailLines = nil
end
elseif p1 == 201 then
--pgup, moves detail
if detailOffset > 1 then
detailOffset = detailOffset - 1
end
elseif p1 == 209 then
--pgdown, moves detail
local w, h = term.getSize()
if detailLines and detailOffset < math.ceil(#detailLines / (h - 3)) then
detailOffset = detailOffset + 1
end
--and now, since redraw() will eat char events with the change to sensor.call:
elseif p1 == 31 then --s
if detailLines then
local fileHandle = io.open("sensorDetailed-"..sideNames[sideSelection].."-"..targetNameMenuTable[targetSelection], "w")
if fileHandle then
for k, v in ipairs(detailLines) do
fileHandle:write(v.."\n")
end
fileHandle:close()
end
end
elseif p1 == 16 then --q
sleep(0)
return
elseif p1 == 34 then --g
if graph then
graphing = not graphing
if not graphing then
graphSide = nil
graphTarget = nil
graphUpdate = nil
else
graphSide = sideNames[sideSelection]
graphTarget = targetNameMenuTable[targetSelection]
graphInstance = createGraph(1)
graphUpdate = os.startTimer(0.5)
end
end
elseif p1 == 49 then --n
if graphing then
local newGraph = createGraph(graphMatch + 1)
if newGraph then
graphInstance = newGraph
graphUpdate = os.startTimer(0.5)
end
end
elseif p1 == 25 then --p
if graphing then
local newGraph = createGraph(graphMatch - 1)
if newGraph then
graphInstance = newGraph
graphUpdate = os.startTimer(0.5)
end
end
end
elseif e == "timer" then
if p1 == graphUpdate then
graphInstance:draw()
graphUpdate = os.startTimer(0.5)
end
end
end

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Server/mods/Weaponmod.zip Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,146 @@
#Balkon's WeaponMod 1.4.6 v1.10.3
#Properties file
#Set the following values to "true" to use them in your game,
#and "false" if you don't want them.
#If you disable the knife, you disable the bayonet too.
cannon-block-damage=true
dynamite-block-damage=true
can-throw-knife=true
can-throw-spear=true
#Turn this to "owner" to allow only the thrower/shooter of the projectile to pick the item up. If set to "all" everyone can pick the item up. Only affects projectiles that can be picked up.
#projectile-accessibility=owner
projectile-accessibility=all
spear=true
halberd=true
battleaxe=true
warhammer=true
knife=true
javelin=true
musket=true
crossbow=true
blowgun=true
dynamite=true
flail=true
firerod=true
cannon=true
blunderbuss=true
dummy=true
boomerang=true
#Entity ID's
#Since v9.0 you cannot leave the entity ID's 0 anymore.
#Client- and server-side entity ID's MUST be equal.
spear-entity=2300
knife-entity=2301
flail-entity=2302
dynamite-entity=2303
javelin-entity=2304
bullet-entity=2305
dart-entity=2306
bolt-entity=2307
cannon-entity=2308
cannonball-entity=2309
shot-entity=2310
dummy-entity=2311
boomerang-entity=2312
#Item ID's
#Since v9.0 you cannot leave the item ID's 0 anymore.
#Client- and server-side item ID's MUST be equal.
#Spear
wood-spear-id=11520
stone-spear-id=11521
iron-spear-id=11522
diamond-spear-id=11523
gold-spear-id=11524
#Halberd
wood-halberd-id=11525
stone-halberd-id=11526
iron-halberd-id=11527
diamond-halberd-id=11528
gold-halberd-id=11529
#Battleaxe
wood-battleaxe-id=11530
stone-battleaxe-id=11531
iron-battleaxe-id=11532
diamond-battleaxe-id=11533
gold-battleaxe-id=11534
#Warhammer
wood-warhammer-id=11535
stone-warhammer-id=11536
iron-warhammer-id=11537
diamond-warhammer-id=11538
gold-warhammer-id=11539
#Knife
wood-knife-id=11540
stone-knife-id=11541
iron-knife-id=11542
diamond-knife-id=11543
gold-knife-id=11544
#Flail
wood-flail-id=11545
stone-flail-id=11546
iron-flail-id=11547
diamond-flail-id=11548
gold-flail-id=11549
#Javelin
javelin-id=11550
#Musket
musket-id=11551
musketbayonet-id=11552
musket-ironpart-id=11553
bullet-id=11554
#Crossbow
crossbow-id=11555
bolt-id=11556
#Blowgun
blowgun-id=11557
dart-id=11558
#Dynamite
dynamite-id=11559
#Fire Rod
firerod-id=11560
#Cannon
cannon-id=11561
cannonball-id=11562
#Blunderbuss
blunderbuss-id=11563
shot-id=11564
blunder-ironpart-id=11565
#Training Dummy
dummy-id=11566
#Overall
gun-stock-id=11567
#Boomerang
wood-boomerang-id=11568
stone-boomerang-id=11569
iron-boomerang-id=11570
diamond-boomerang-id=11571
gold-boomerang-id=11572
#Reload durations
musket-reloadtime=30
blunderbuss-reloadtime=20
crossbow-reloadtime=15
blowgun-reloadtime=10