Skip to content

Commit

Permalink
FunkMan v0.6.2
Browse files Browse the repository at this point in the history
- Fixed bug that 2.5 PTS (bolter) image in LSO embed is shown as 4 PTS
- Added Points25.png image for bolters
- Improved FunkSock command get key
- Added Test mission
  • Loading branch information
funkyfranky committed Oct 17, 2022
1 parent 9dee014 commit 1175f97
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 21 deletions.
2 changes: 1 addition & 1 deletion funkman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

__author__ = "funkyfranky"
__version__ = "0.6.1"
__version__ = "0.6.2"

#print("__init__ main")

Expand Down
12 changes: 8 additions & 4 deletions funkman/funkbot/funkbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def SendFig(self, fig, ChannelID: int):
def SendLSOEmbed(self, result, ChannelID: int):

# Info message.
print("Creating LSO Embed")
#print("Creating LSO Embed")

# Get date from result.
actype=_GetVal(result, "airframe", "Unkown")
Expand All @@ -187,8 +187,8 @@ def SendLSOEmbed(self, result, ChannelID: int):

color=0x00ff00
urlIm="https://i.imgur.com/1bWgcV7.png"
if type(points)==int:
if points==0:#
if type(points)!=str:
if points==0:
color=0x000000 #black
urlIm="https://i.imgur.com/rZpu9c0.png"
elif points==1:
Expand All @@ -197,6 +197,9 @@ def SendLSOEmbed(self, result, ChannelID: int):
elif points==2:
color=0xFFA500 #orange
urlIm="https://i.imgur.com/EjviMBk.png"
elif points==2.5:
color=0xB47E59 #brown
urlIm="https://i.imgur.com/nYWrL4Z.png"
elif points==3:
color=0xFFFF00 #yellow
urlIm="https://i.imgur.com/wH0Gjqx.png"
Expand Down Expand Up @@ -225,7 +228,8 @@ def SendLSOEmbed(self, result, ChannelID: int):
embed.add_field(name="Points", value=points, inline=True)
embed.add_field(name="Details", value=details, inline=True)
embed.add_field(name="Groove", value=Tgroove, inline=True)
embed.add_field(name="Wire", value=wire, inline=True)
if wire!="?":
embed.add_field(name="Wire", value=wire, inline=True)
embed.add_field(name="Case", value=case, inline=True)
embed.add_field(name="Wind", value=windondeck, inline=True)
embed.add_field(name="Aircraft", value=actype, inline=True)
Expand Down
37 changes: 22 additions & 15 deletions funkman/funksock/funksock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from ..funkplot.funkplot import FunkPlot
from ..funkbot.funkbot import FunkBot
from ..utils.utils import _GetVal

class FunkHandler(socketserver.BaseRequestHandler):
"""
Expand All @@ -27,7 +26,7 @@ def handle(self):
data = self.request[0].strip()

# Debug message.
print(f"New message from server {self.client_address[0]}")
#print(f"New message from server {self.client_address[0]}")

# Table data.
table=json.loads(data)
Expand Down Expand Up @@ -99,7 +98,7 @@ def Start(self):
os._exit(0)


def EvalData(self, table):
def EvalData(self, table: dict):
"""Evaluate data received from socket. You might want to overwrite this function."""

# Debug info.
Expand All @@ -114,38 +113,46 @@ def EvalData(self, table):
straferesult="moose_strafe_result"
lsograde="moose_lso_grade"

table.get

# Treat different cases.
if key in table or key=="sever_name":
if key in table:

command=table.get(key, "")
server=table.get("server_name", "unknown")

# Debug info
print(f"Got {command} from server {server}!")

if table[key]==textmessage:
print("Got text message!")
if command==textmessage:
#print("Got text message!")

# Extract text.
text=table["text"]
text=table.get("text", " ")

# Send text to Discord.
self.funkbot.SendText(text, self.channelIDmessage)

if table[key]==bombresult:
print("Got bomb result!")
elif command==bombresult:
#print("Got bomb result!")

# Create bomb run figure.
fig, ax=self.funkplot.PlotBombRun(table)

# Send figure to Discord.
self.funkbot.SendFig(fig, self.channelIDrange)

elif table[key]==straferesult:
print("Got strafe result!")
elif command==straferesult:
#print("Got strafe result!")

# Create strafe run figure.
fig, ax=self.funkplot.PlotStrafeRun(table)

# Send figure to discord.
self.funkbot.SendFig(fig, self.channelIDrange)

elif table[key]==lsograde:
print("Got trap sheet!")
elif command==lsograde:
#print("Got trap sheet!")

# Send LSO grade.
self.funkbot.SendLSOEmbed(table, self.channelIDairboss)
Expand All @@ -157,7 +164,7 @@ def EvalData(self, table):
self.funkbot.SendFig(fig, self.channelIDairboss)

else:
print("ERROR: Unknown data type in table!")
print(f"WARNING: Unknown command in table: {command}")
else:
print("ERROR: dataType not key in table!")
print("WARNING: not key command in table!")
print(table)
Binary file added funkpics/Points25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
author="funkyfranky",
description="Interface between DCS/MOOSE and Discord via an UDP socket.",
name="funkman",
version="0.6.1",
version="0.6.2",
packages=find_packages(include=["funkman", "funkman.*"]),
install_requires=[
'discord>=1.7.3',
Expand Down
176 changes: 176 additions & 0 deletions testfiles/FunkMan Test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Settings
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

local socket=SOCKET:New(10042) --Utilities.Socket#SOCKET
socket:SendText("Hello World!")

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Bombing Ranges
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


-- Some range
local range=RANGE:New("Practice Range") --Functional.Range#RANGE

-- Enable funkman
range:SetFunkManOn()


--- Function called when a weapon impacts at the Range.
function range:OnAfterImpact(From, Event, To, Result, Player)
local player=Player --Functional.Range#RANGE.PlayerData
local result=Result --Functional.Range#RANGE.BombResult
local Text=string.format("Player %s dropped ordnance at range %s in airframe %s", player.playername, result.rangename, result.airframe)
env.info(Text)
end

--- Function called when a player finished a straing run.
function range:OnAfterStrafeResult(From, Event, To, Player, Result)
local player=Player --Functional.Range#RANGE.PlayerData
local result=Result --Functional.Range#RANGE.BombResult
local Text=string.format("Player %s strafed at range %s in airframe %s", player.playername, result.rangename, result.airframe)
env.info(Text)
end

local function testBomb()

local result = {} -- --Functional.Range#RANGE.BombResult
result.command = SOCKET.DataType.BOMBRESULT
result.name = "My Target"
result.distance = math.random(1,150)
result.radial = math.random(1,360)
result.weapon = "Mk 82"
result.quality = "INEFFECTIVE"
result.player = "funkyfranky"
result.time = timer.getAbsTime()
result.clock = UTILS.SecondsToClock(result.time, true)
result.midate=UTILS.GetDCSMissionDate()
result.airframe = "F/A 18 Hornet"
result.roundsFired = 0 -- Rangeboss Edit
result.roundsHit = 0 -- Rangeboss Edit
result.roundsQuality = "N/A" -- Rangeboss Edit
result.rangename = "My Test Range"
result.attackHdg = math.random(360)
result.attackAlt = math.random(5000, 10000)
result.attackVel = math.random(300, 500)
result.theatre = env.mission.theatre

env.info("FF Test bomb! Expect impact in 1 seconds..")

local player={}--Functional.Range#RANGE.PlayerData
player.playername="funkyfranky"
player.airframe="F/A 18 Hornet"
player.unitname="My Unit"

range:__Impact(1, result, player)

end

testBomb()

local function testStrafe()

local result = {} -- --Functional.Range#RANGE.BombResult
result.command = SOCKET.DataType.STRAFERESULT
result.name = "My Target"
result.roundsFired=math.random(10, 300)
result.roundsHit=math.random(result.roundsFired)
result.strafeAccuracy=result.roundsHit/result.roundsFired*100
result.roundsQuality = "Some Quality"
result.player = "funkyfranky"
result.time = timer.getAbsTime()
result.clock = UTILS.SecondsToClock(result.time, true)
result.midate=UTILS.GetDCSMissionDate()
result.airframe = "F/A 18 Hornet"
result.rangename = "My Test Range"
result.theatre = env.mission.theatre

env.info("FF Test bomb! Expect impact in 1 seconds..")

local player={}--Functional.Range#RANGE.PlayerData
player.playername="funkyfranky"
player.airframe="F/A 18 Hornet"
player.unitname="My Unit"

range:__StrafeResult(1, player, result)

end

testStrafe()

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- AIRBOSS
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

-- Create AIRBOSS object.
local airboss=AIRBOSS:New("CVN-74")

-- Enable FunkMan.
airboss:SetFunkManOn()

-- Start airboss class.
airboss:Start()

--- Function called when a player receives and LSO grade.
function airboss:OnAfterLSOGrade(From, Event, To, PlayerData, Grade)
local playerData=PlayerData--Ops.Airboss#AIRBOSS.PlayerData
local grade=Grade --Ops.Airboss#AIRBOSS.LSOGrade
env.info("FF LSO grade incoming!")
end


local function testtrap()

local playerData = {} --Ops.Airboss#AIRBOSS.PlayerData

playerData.name="funkyfranky"
playerData.airframe="FA-18C_hornet"
playerData.callsign="My Callsign"
playerData.Tgroove=15
playerData.trapsheet={}
playerData.wire=3
playerData.case=1
playerData.flag=1

env.info("Trap sheet data")
for i=1,150 do
local ts={} --Ops.Airboss#AIRBOSS.GrooveData
ts.Alt=170-i
ts.AoA=math.random(7,10)
ts.Gamma=50-i/10
ts.Grade="Ok"
ts.GSE=1.0
ts.LUE=0.0+i/10
ts.Z=200+i/2
ts.X=-2700+i*25
--BASE:I(ts)
table.insert(playerData.trapsheet, ts)
end

local grade={} --Ops.Airboss#AIRBOSS.LSOgrade
grade.airframe="FA-18C_hornet"
grade.carriername="USS Stennis"
grade.carriertype="CVN-74"
grade.theatre=env.mission.theatre
grade.carrierrwy=-9
grade.case=1
grade.points=2.5
grade.details="(LUL)X (F)IM LOLULIC LOLULAR"
grade.grade="(OK)"
grade.finalscore=2
grade.Tgroove=15.1042432342334
grade.midate=UTILS.GetDCSMissionDate()
grade.mitime=UTILS.SecondsToClock(timer.getAbsTime(), true)
grade.wire=3
grade.wind=25.343421

playerData.grade=grade

env.info("FF Sending AIRBOSS LSO grade in 3 seconds!")

airboss:__LSOGrade(3, playerData, grade)

end

testtrap()
Binary file added testfiles/FunkMan Test.miz
Binary file not shown.

0 comments on commit 1175f97

Please sign in to comment.