local PlayerNIB = {}
local OverlayParam, EventManager, TableUtil = ...
local EVENT_TYPES = EventManager.FE.FIFA.EventTypes
local STATE_INACTIVE = "HIDE"
local STATE_UPDATE = "UPDATE"
local STATE_ACTIVE = "SHOW"
local SIDE_HOME = 0
local SIDE_AWAY = 1
local BND_ALPHA = "bnd_alpha"
local BND_STAMINA = "bnd_stamina"
local BND_PLAYER_INFO = "bnd_player_info"
local BND_ACTIVE = "bnd_active"
local bndHomeCrest = "bnd_home_team_crest"
local bndAwayCrest = "bnd_away_team_crest"
local bndRainVisible = "bnd_rain_visible"
local bndWeather = "bnd_weather_type"
-- ID
EnglandTeams = { 1, 2, 5, 7, 9, 10, 11, 13, 17, 18, 19, 95, 8, 14, 110, 144, 1799,
1808, 1943, 1925 }
FrenceTeams = { 64, 65, 66, 69, 70, 71, 72, 73,
74,217,219,294,379,1530,1809,1815,57,76,378,614 }
GermanyTeams = { 21,22,23,31,32,34,36,38,166,169,175,1824,10029,100409,
112172,25,1831,160 }
SpainTeams =
{ 240,241,243,448,449,450,452,457,453,461,462,468,480,481,483,479,1860,1861,110062,
1968 }
ItalyTeams =
{ 39,45,44,46,47,48,52,54,55,189,206,1746,1837,110374,111974,111811,110373,347,1107
41,111434 }
InternationalTeams =
{ 974,1318,1319,1322,1325,1328,1330,1331,1334,1335,1337,1338,1341,1343,1352,1353,13
54,1355,1356,1359,1360,1361,1362,1363,1364,1365,1366,1367,1369,1370,1375,1377,1383,
1386,1387,1391,1393,1395,1411,1413,1415,1667,1886,105013,105022,105035,110082,11110
8,111111,111112,111114,111115,111130,111448,111455,111459,111462,111465,111466,1114
73,111485,111489,111510,111527,111545,111550 }
ItalyBTeams =
{ 50,190,199,203,205,570,1744,1837,1843,1745,1842,1847,1848,110738,111993,111434,11
2026,112168,112494,112791 }
SpainBTeams =
{ 260,244,456,459,462,463,467,468,452,573,1854,2023,10846,100888,110069,110827,1108
31,110839,100851,110902,113981,114554 }
IndonesiaTeams = { 155600, 155601, 155602, 155603, 155604, 155605, 155606, 155607,
155608, 155609 }
ScotlandTeams = { 77,78,80,81,82,83,86,631,181,621,100804,100805 }
SaudiArabiaTeams =
{ 605,607,111674,112096,112139,112390,112392,112393,112408,112572,112883,112990,113
057,113058,113217,113345 }
UnitedStatesTeams =
{ 687,688,689,691,693,694,695,696,697,698,101112,111065,111138,111139,111144,111651
,111928,111140,112134,112606,112828,112885,112893,112996,113149,114161,114162,11464
0 }
ChinaPRTeams =
{ 110955,111724,111768,111769,111773,111774,111779,111839,112163,112378,112429,1125
40,112541,112978,112985,114628,116360,116361}
PortugalTeams =
{ 234,236,237,518,744,1438,1887,1896,1892,1893,1898,10031,1888,10020,111539,11898,1
12809,112513,114510 }
EnglandBTeams =
{ 3,8,12,15,17,88,95,97,106,109,1792,1793,1795,1797,1800,1801,1806,1917,1919,1926,1
939,1952,1960,1961}
FrenceBTeams =
{ 57,58,59,62,210,224,226,294,614,1805,1813,1814,1816,1819,1530,110569,111817,11032
1,110456,115494,111659,112552 }
Germany2Teams =
{ 27,29,34,159,165,166,171,485,543,576,1832,10030,110178,110329,110500,110588,11063
6 }
NetherlandsTeams =
{ 245,246,247,634,645,647,1903,1905,1906,1908,1909,1910,1913,1915,1971,100628,10063
2,100646 }
BelgiumTeams =
{ 232,229,230,231,670,674,673,680,681,682,2013,2014,1750,15005,100081,100087,110724
,112695 }
ArgentinaTeams =
{ 1013,1876,1877,110093,110394,110395,110396,110404,110406,110580,110581,101083,101
084,101085,101088,111019,111706,111707,111708,111710,111711,111715,111716,112670,11
2689,112713,112965,113044 }
SwitzerlandTeams = { 322,324,894,896,897,898,900,1713,10032,110770 }
NorwayTeams =
{ 298,299,300,417,418,918,920,922,1456,1463,1755,1756,1757,112199,113459,115489 }
BrazilTeams =
{ 383,517,568,567,598,1035,1039,1041,1043,1048,1053,1629,111041,111042,111044,11105
2,111976,112119,112472,115530 }
TurkeyTeams =
{ 325,326,327,436,741,746,101007,101014,101016,101020,101028,101033,101041,110776,1
11117,111339,112120,113142,113796 }
AustraliaTeams =
{ 111393,111395,111396,111397,111398,111399,111400,111766,112224,112427,114023,1146
04 }
AustriaTeams = { 191,209,252,254,256,780,1787,2017,15009,15040,111822 }
GermanyTeamsData = {
{ teamid = 21, homeColor = "0xB80018", awayColor = "0xE0E0E0", homeFontColor =
"0xE0E0E0", awayFontColor = "0xB80018" },
{ teamid = 22, homeColor = "0xF8D000", awayColor ="0x101010",homeFontColor =
"0x101010", awayFontColor = "0xF8D000"},
{ teamid = 23, homeColor = "0xE0E0E0", awayColor ="0x30B060",homeFontColor =
"0x30B060", awayFontColor = "0xE0E0E0"},
{ teamid = 31, homeColor = "0xE0E0E0", awayColor = "0xE01820",homeFontColor =
"0xE01820", awayFontColor = "0xE0E0E0" },
{ teamid = 32, homeColor = "0xB81020", awayColor = "0x101010",homeFontColor =
"0xE0E0E0", awayFontColor = "0xE0E0E0"},
{ teamid = 34, homeColor = "0x2838A0", awayColor = "0xD8D8D8",homeFontColor =
"0xE0E0E0", awayFontColor = "0x2838A0"},
{ teamid = 36, homeColor = "0xd3d4d3", awayColor ="0xc62432",homeFontColor
="0xc62432" , awayFontColor = "0xd3d4d3"},
{ teamid = 38, homeColor = "0x289880", awayColor ="0xE1B5AD",homeFontColor
="0xE0E0E0" , awayFontColor = "0x289880"},
{ teamid = 166, homeColor = "0x284090" , awayColor ="0x182038",homeFontColor =
"0xE0E0E0", awayFontColor = "0xE0E0E0"},
{ teamid = 169, homeColor = "0xD01818", awayColor = "0xD8D8D8",homeFontColor =
"0xD8D8D8", awayFontColor = "0xD01818"},
{ teamid = 175, homeColor = "0x50A830", awayColor ="0x383C3D",homeFontColor =
"0xE0E0E0", awayFontColor = "0x50A830"},
{ teamid = 1824, homeColor = "0xd1d1d0" , awayColor = "0x363535",homeFontColor
="0x363535" , awayFontColor ="0xd1d1d0" },
{ teamid = 10029, homeColor ="0x204390" , awayColor = "0xcec29a",homeFontColor =
"0xcec29a", awayFontColor = "0xcec29a"},
{ teamid = 100409, homeColor = "0xaa2327", awayColor ="0xd2d1d0",homeFontColor =
"0xd2d1d0", awayFontColor = "0xaa2327"},
{ teamid = 112172, homeColor = "0xf9f8f8", awayColor ="0xa51b21",homeFontColor =
"0xa51b21", awayFontColor = "0xf9f8f8"},
{ teamid = 25, homeColor = "0x9c2225", awayColor ="0x3e4041",homeFontColor =
"0xE0E0E0", awayFontColor = "0xE0E0E0"},
{ teamid = 1831, homeColor ="0xbc1e20" , awayColor ="0xd5cbbb",homeFontColor =
"0xd5cbbb", awayFontColor ="0xbc1e20" },
{ teamid = 160, homeColor ="0x1d3552" , awayColor ="0x65a7d4",homeFontColor =
"0xE0E0E0", awayFontColor ="0x202838" }
}
EAFC = {
bnd_crestBg_left = -347,
bnd_crestBg_bottom = 15,
bnd_crest_bottom = 16,
bnd_crest_height = 30,
bnd_crest_width = 30,
bnd_crestBg_width = 36,
bnd_crestBg_height = 33,
bnd_crestBg_alpha = 1,
bnd_crest_bg = "0x00FF7E",
bnd_away_crest_bg = "0x00FF7E",
bnd_bg = "0x1E1E1E",
bnd_stamina_inner_bg = "0x1E1E1E",
bnd_stamina_outside_bg = "0x00FF7E",
bnd_stamina_width = 213,
bnd_stamina_short_width = 0,
bnd_stamina_bottom = 46,
bnd_player_number = "",
bnd_player_name = "",
bnd_player_info_left = -223,
bnd_player_number_color = "0x00FF7E",
bnd_player_name_color = "0xffffff"
}
InternationalLeague = {
bnd_crestBg_left = -347,
bnd_crestBg_bottom = 15,
bnd_crest_bottom = 16,
bnd_crest_height = 30,
bnd_crest_width = 30,
bnd_crestBg_width = 36,
bnd_crestBg_height = 33,
bnd_crestBg_alpha = 1,
bnd_crest_bg = "0x13C29F",
bnd_away_crest_bg = "0x13C29F",
bnd_bg = "0x3D021D",
bnd_stamina_inner_bg = "0x3D021D",
bnd_stamina_outside_bg = "0x13C29F",
bnd_stamina_width = 213,
bnd_stamina_short_width = 0,
bnd_stamina_bottom = 46,
bnd_player_number = "",
bnd_player_name = "",
bnd_player_info_left = -223,
bnd_player_number_color = "0x13C29F",
bnd_player_name_color = "0xffffff"
}
SaudiArabiaLeague = {
bnd_crestBg_left = -347,
bnd_crestBg_bottom = 15,
bnd_crest_bottom = 16,
bnd_crest_height = 30,
bnd_crest_width = 30,
bnd_crestBg_width = 36,
bnd_crestBg_height = 33,
bnd_crestBg_alpha = 1,
bnd_crest_bg = "0xffffff",
bnd_away_crest_bg = "0xffffff",
bnd_bg = "0x2A1D52",
bnd_stamina_inner_bg = "0x4DE8EF",
bnd_stamina_outside_bg = "0xffffff",
bnd_stamina_width = 213,
bnd_stamina_short_width = 0,
bnd_stamina_bottom = 46,
bnd_player_number = "",
bnd_player_name = "",
bnd_player_info_left = -223,
bnd_player_number_color = "0xffffff",
bnd_player_name_color = "0xffffff"
}
IndonesiaLeague = {
bnd_crestBg_left = -347,
bnd_crestBg_bottom = 15,
bnd_crest_bottom = 16,
bnd_crest_height = 30,
bnd_crest_width = 30,
bnd_crestBg_width = 36,
bnd_crestBg_height = 33,
bnd_crestBg_alpha = 1,
bnd_crest_bg = "0x831B39",
bnd_away_crest_bg = "0x831B39",
bnd_bg = "0x130306",
bnd_stamina_inner_bg = "0x4DE8EF",
bnd_stamina_outside_bg = "0xffffff",
bnd_stamina_width = 213,
bnd_stamina_short_width = 0,
bnd_stamina_bottom = 46,
bnd_player_number = "",
bnd_player_name = "",
bnd_player_info_left = -223,
bnd_player_number_color = "0xffffff",
bnd_player_name_color = "0xffffff"
}
EnglandLeague = {
bnd_crestBg_left = -347,
bnd_crestBg_bottom = 15,
bnd_crest_bottom = 16,
bnd_crest_height = 30,
bnd_crest_width = 30,
bnd_crestBg_width = 33,
bnd_crestBg_height = 33,
bnd_crestBg_alpha = 1,
bnd_crest_bg = "0xffffff",
bnd_away_crest_bg = "0xffffff",
bnd_bg = "0x37003B",
bnd_stamina_inner_bg = "0x090109",
bnd_stamina_outside_bg = "0x4DE8EF",
bnd_stamina_width = 213,
bnd_stamina_short_width = 0,
bnd_stamina_bottom = 45,
bnd_player_number = "",
bnd_player_name = "",
bnd_player_info_left = -223,
bnd_player_number_color = "0xffffff",
bnd_player_name_color = "0xffffff"
}
ItalyLeague = {
bnd_crestBg_left = -347,
bnd_crestBg_bottom = 15,
bnd_crest_bottom = 16,
bnd_crest_height = 30,
bnd_crest_width = 30,
bnd_crestBg_width = 33,
bnd_crestBg_height = 33,
bnd_crestBg_alpha = 1,
bnd_crest_bg = "0xffffff",
bnd_away_crest_bg = "0xffffff",
bnd_bg = "0x586cf8",
bnd_stamina_inner_bg = "0x64a4ed",
bnd_stamina_outside_bg = "0x525534",
bnd_stamina_width = 213,
bnd_stamina_short_width = 0,
bnd_stamina_bottom = 45,
bnd_player_number = "",
bnd_player_name = "",
bnd_player_info_left = -223,
bnd_player_number_color = "0xffffff",
bnd_player_name_color = "0xffffff"
}
SpainLeague = {
bnd_crestBg_left = -346,
bnd_crest_height = 33,
bnd_crest_width = 33,
bnd_crestBg_width = 38,
bnd_crestBg_height = 38,
bnd_crestBg_bottom = 12.5,
bnd_crest_bottom = 14.5,
bnd_crestBg_alpha = 1,
bnd_crest_bg = "0x080e12",
bnd_away_crest_bg = "0x080e12",
bnd_bg = "0x15251b",
bnd_stamina_inner_bg = "0x1fa5b3",
bnd_stamina_outside_bg = "0xdeffff",
bnd_stamina_width = 204,
bnd_stamina_short_width = 0,
bnd_stamina_bottom = 44,
bnd_player_number = "",
bnd_player_name = "",
bnd_player_info_left = -223,
bnd_player_number_color = "0xffffff",
bnd_player_name_color = "0xffffff"
}
FranceLeague = {
bnd_crestBg_left = -325,
bnd_crest_height = 45,
bnd_crest_width = 45,
bnd_crestBg_width = 38,
bnd_crestBg_height = 38,
bnd_crestBg_bottom = 12.5,
bnd_crest_bottom = 10,
bnd_crestBg_alpha = 0,
bnd_crest_bg = "0x080e12",
bnd_away_crest_bg = "0x080e12",
bnd_bg = "0x091b3f",
bnd_stamina_inner_bg = "0x0da0cc",
bnd_stamina_outside_bg = "0xffffff",
bnd_stamina_width = 160,
bnd_stamina_short_width = 0,
bnd_stamina_bottom = 44,
bnd_player_number = "",
bnd_player_name = "",
bnd_player_info_left = -200,
bnd_player_number_color = "0xffffff",
bnd_player_name_color = "0xffffff"
}
GermanyLeague = {
bnd_crestBg_left = -347,
bnd_crestBg_bottom = 15,
bnd_crest_bottom = 16,
bnd_crest_height = 30,
bnd_crest_width = 30,
bnd_crestBg_width = 36,
bnd_crestBg_height = 33,
bnd_crestBg_alpha = 1,
bnd_crest_bg = "",
bnd_away_crest_bg = "",
bnd_bg = "0xdedade",
bnd_stamina_inner_bg = "0x2b8ebf",
bnd_stamina_outside_bg = "0xb9d2e2",
bnd_stamina_width = 208,
bnd_stamina_short_width = 0,
bnd_stamina_bottom = 44,
bnd_player_number = "",
bnd_player_name = "",
bnd_player_info_left = -223,
bnd_player_number_color = "0x130f13",
bnd_player_name_color = "0x130f13"
}
function PlayerNIB:new(init)
local o = init or {}
setmetatable(o, self)
self.__index = self
o.services = {
GameStateService = o.api("GameStateService"),
matchInfo = o.api("MatchInfoService"),
userPlate = o.api("UserPlateService"),
settingsService = o.api("SettingsService"),
gameSetupService = o.api("GameSetupService"),
EventManagerService = o.api("EventManagerService")
}
o.side = o.data and o.data.side or SIDE_HOME
o.currentLeague = {}
o.TeamsData = o.services.matchInfo.GetMatchTeams()
if o:isInTable(o.TeamsData[1], EnglandTeams) and o:isInTable(o.TeamsData[2],
EnglandTeams) then
o.currentLeague = EnglandLeague
elseif o:isInTable(o.TeamsData[1], FrenceTeams) and o:isInTable(o.TeamsData[2],
FrenceTeams) then
o.currentLeague = FranceLeague
elseif o:isInTable(o.TeamsData[1], InternationalTeams) and
o:isInTable(o.TeamsData[2], InternationalTeams) then
o.currentLeague = InternationalLeague
elseif o:isInTable(o.TeamsData[1], SaudiArabiaTeams) and
o:isInTable(o.TeamsData[2], SaudiArabiaTeams) then
o.currentLeague = SaudiArabiaLeague
elseif o:isInTable(o.TeamsData[1], IndonesiaTeams) and
o:isInTable(o.TeamsData[2], IndonesiaTeams) then
o.currentLeague = IndonesiaLeague
elseif o:isInTable(o.TeamsData[1], GermanyTeams) and o:isInTable(o.TeamsData[2],
GermanyTeams) then
o.currentLeague = GermanyLeague
local homeColorList = o:getTeamHomeColor(o.TeamsData[1].assetId,
GermanyTeamsData)
local awayColorList = o:getTeamAwayColor(o.TeamsData[2].assetId,
GermanyTeamsData)
o.currentLeague.bnd_crest_bg = homeColorList[1]
o.currentLeague.bnd_away_crest_bg = awayColorList[1]
elseif o:isInTable(o.TeamsData[1], SpainTeams) and o:isInTable(o.TeamsData[2],
SpainTeams) then
o.currentLeague = SpainLeague
elseif o:isInTable(o.TeamsData[1], ItalyTeams) and o:isInTable(o.TeamsData[2],
ItalyTeams) then
o.currentLeague = ItalyLeague
else
o.currentLeague = EAFC
end
o.im.Subscribe(BND_ACTIVE, function()
o:_publishActivity()
end
)
o.im.Subscribe(BND_ALPHA, function()
o:_publishAlpha()
end
)
o.im.Subscribe(BND_PLAYER_INFO, function()
o:_publishPlayerInfo()
end
)
o.im.Subscribe(BND_STAMINA, function()
o:_publishStamina()
end
)
for k,v in pairs(o.currentLeague) do
o.im.Subscribe(k, function()
if k == "bnd_stamina_width" or k == "bnd_stamina_short_width" then
o:_publishStamina()
elseif k == "bnd_player_number" or k == "bnd_player_name" then
o:_publishPlayerInfo()
else
o.im.Publish(k, v)
end
end)
end
weatherType = {
name = "$Weather",
id = 0
}
random = math.random()
o.im.Subscribe(bndRainVisible, function()
if random <= 0.8 and random > 0.6 then
o.im.Publish(bndRainVisible, true)
else
o.im.Publish(bndRainVisible, false)
end
end
)
o.im.Subscribe(bndWeather, function()
if random <= 0.2 then
-- Foggy 1
weatherType.id = 0
o.im.Publish(bndWeather, weatherType)
elseif random <= 0.4 and random > 0.2 then
-- Foggy 2
weatherType.id = 1
o.im.Publish(bndWeather, weatherType)
elseif random <= 0.6 and random > 0.4 then
-- cool
weatherType.id = 2
o.im.Publish(bndWeather, weatherType)
elseif random <= 0.8 and random > 0.6 then
-- cloudy
weatherType.id = 3
o.im.Publish(bndWeather, weatherType)
else
-- default
weatherType.id = 4
o.im.Publish(bndWeather, weatherType)
end
o.im.Publish(bndWeather, weatherType)
end
)
o.isUserHome = o.services.gameSetupService.IsHostTeam()
homeCrest = {
name = "$Crest",
id = o.TeamsData[1].assetId
}
awaycrest = {
name = "$Crest",
id = o.TeamsData[2].assetId
}
o.im.Subscribe(bndHomeCrest, function()
o.im.Publish(bndHomeCrest, homeCrest)
end)
o.im.Subscribe(bndAwayCrest, function()
o.im.Publish(bndAwayCrest, awaycrest)
end)
o:setState(STATE_INACTIVE)
o.eventHandlerID = o.services.EventManagerService.RegisterHandler(function(...)
o:_handleEvent(...)
end
)
return o
end
function PlayerNIB:setState(state)
self.state = state or STATE_INACTIVE
self:_publishActivity()
end
function PlayerNIB:getPlayerInfo(params)
return {
name = params[9],
number = params[12]
}
end
function PlayerNIB:getStamina(params)
return {
stamina = tonumber(params[1]),
shortStamina = tonumber(params[2])
}
end
function PlayerNIB:_onPlayerNIBUpdate(subtype, hideshow, subtypestr, msg)
self:setState(hideshow)
if self.state ~= STATE_INACTIVE and msg ~= nil and msg ~= "" then
local params = OverlayParam.split(msg, "|")
if table.getn(params) == 1 then
if tonumber(params[1]) ~= nil then
local alpha = tonumber(params[1]) / 100
self:_publishAlpha(alpha)
end
elseif table.getn(params) == 2 then
elseif table.getn(params) == 3 then
elseif table.getn(params) == 8 then
self.stamina = self:getStamina(params)
self:_publishStamina()
elseif table.getn(params) == 10 then
self.stamina = self:getStamina(params)
self:_publishStamina()
elseif table.getn(params) == 16 then
self.playerInfo = self:getPlayerInfo(params)
self.stamina = self:getStamina(params)
self:_publishPlayerInfo()
self:_publishStamina()
elseif table.getn(params) == 17 then
self.playerInfo = self:getPlayerInfo(params)
self.stamina = self:getStamina(params)
self:_publishPlayerInfo()
self:_publishStamina()
end
end
end
function PlayerNIB:_publishActivity()
self.im.Publish(BND_ACTIVE, self.state ~= STATE_INACTIVE)
end
function PlayerNIB:_publishAlpha(alpha)
self.im.Publish(BND_ALPHA, alpha or 1)
end
function PlayerNIB:_publishPlayerInfo()
if self.playerInfo == nil then
return
end
self.im.Publish(BND_PLAYER_INFO, self.playerInfo)
self.im.Publish("bnd_player_number", tostring(self.playerInfo["number"]))
self.im.Publish("bnd_player_name", self.playerInfo["name"])
end
function PlayerNIB:_publishStamina()
if self.stamina == nil then
return
end
self.im.Publish(BND_STAMINA, self.stamina)
self.im.Publish("bnd_stamina_width", self.currentLeague.bnd_stamina_width)
local r0 = self.stamina["shortStamina"] / self.stamina["stamina"]
local r1 = self.currentLeague.bnd_stamina_width * r0
self.im.Publish("bnd_stamina_short_width", r1)
end
function PlayerNIB:_handleEvent(eventType, data)
if eventType == EVENT_TYPES.OverlayTypeNIBBL and self.side == SIDE_HOME or
eventType == EVENT_TYPES.OverlayTypeNIBBR and self.side == SIDE_AWAY then
self:_onPlayerNIBUpdate(data.subtype, data.hideshow, data.subtypestr, data.msg)
end
end
function PlayerNIB:isInTable(value, tbl)
for k,v in pairs(tbl) do
if v == value.assetId then
return true
end
end
return false
end
function PlayerNIB:getTeamHomeColor(teamid, tbl)
local result = {}
for k,v in pairs(tbl) do
if v.teamid == teamid then
result[1] = v.homeColor
result[2] = v.homeFontColor
end
end
return result
end
function PlayerNIB:getTeamAwayColor(teamid, tbl)
local result = {}
for k,v in pairs(tbl) do
if v.teamid == teamid then
result[1] = v.awayColor
result[2] = v.awayFontColor
end
end
return result
end
function PlayerNIB:finalize()
self.im.Unsubscribe(BND_ACTIVE)
self.im.Unsubscribe(BND_ALPHA)
self.im.Unsubscribe(BND_PLAYER_INFO)
self.im.Unsubscribe(BND_STAMINA)
self.im.Unsubscribe(bndHomeCrest)
self.im.Unsubscribe(bndAwayCrest)
self.im.Unsubscribe(bndRainVisible)
self.im.Unsubscribe(bndWeather)
for k,v in pairs(EnglandLeague) do
self.im.Unsubscribe(k)
end
self.services.EventManagerService.UnregisterHandler(self.eventHandlerID)
end
return PlayerNIB