mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-01 18:23:32 +00:00
Added spell channeling support
This commit is contained in:
parent
7341613f21
commit
3b28170217
@ -17,8 +17,9 @@ namespace Artemis.Modules.Games.WoW.Models
|
||||
public DateTime EndTime { get; set; }
|
||||
public bool NonInterruptible { get; set; }
|
||||
public float Progress { get; set; }
|
||||
public bool IsChannel { get; set; }
|
||||
|
||||
public void ApplyJson(JToken spellJson)
|
||||
public void ApplyJson(JToken spellJson, bool isChannel)
|
||||
{
|
||||
var castMs = spellJson["e"].Value<int>() - spellJson["s"].Value<int>();
|
||||
var tickCount = Environment.TickCount;
|
||||
@ -29,6 +30,7 @@ namespace Artemis.Modules.Games.WoW.Models
|
||||
StartTime = new DateTime(DateTime.Now.Ticks + difference);
|
||||
EndTime = StartTime.AddMilliseconds(castMs);
|
||||
NonInterruptible = spellJson["ni"].Value<bool>();
|
||||
IsChannel = isChannel;
|
||||
}
|
||||
|
||||
public void UpdateProgress()
|
||||
@ -39,8 +41,12 @@ namespace Artemis.Modules.Games.WoW.Models
|
||||
var elapsed = DateTime.Now - StartTime;
|
||||
var total = EndTime - StartTime;
|
||||
|
||||
Progress = (float) (elapsed.TotalMilliseconds / total.TotalMilliseconds);
|
||||
if (Progress > 1)
|
||||
if (IsChannel)
|
||||
Progress = 1 - (float) (elapsed.TotalMilliseconds / total.TotalMilliseconds);
|
||||
else
|
||||
Progress = (float) (elapsed.TotalMilliseconds / total.TotalMilliseconds);
|
||||
|
||||
if (Progress > 1 || Progress < 0)
|
||||
Clear();
|
||||
}
|
||||
|
||||
@ -52,6 +58,7 @@ namespace Artemis.Modules.Games.WoW.Models
|
||||
EndTime = DateTime.MinValue;
|
||||
NonInterruptible = false;
|
||||
Progress = 0;
|
||||
IsChannel = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ Artemis = LibStub("AceAddon-3.0"):NewAddon("Artemis", "AceConsole-3.0", "AceEven
|
||||
json = LibStub("json")
|
||||
local debugging = false
|
||||
local lastLine = {}
|
||||
local channeling = {}
|
||||
local unitUpdates = {}
|
||||
local lastTransmitMessage
|
||||
local lastTransmitTime
|
||||
@ -9,11 +10,14 @@ local lastBuffs = "";
|
||||
local lastDebuffs = "";
|
||||
local prefixCounts = {}
|
||||
|
||||
channeling["player"] = false
|
||||
channeling["target"] = false
|
||||
|
||||
function Artemis:OnEnable()
|
||||
Artemis:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
Artemis:RegisterEvent("PLAYER_LEVEL_UP")
|
||||
Artemis:RegisterEvent("ACHIEVEMENT_EARNED")
|
||||
Artemis:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
|
||||
Artemis:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
|
||||
Artemis:RegisterEvent("UNIT_TARGET")
|
||||
Artemis:RegisterEvent("UNIT_HEALTH")
|
||||
Artemis:RegisterEvent("UNIT_POWER")
|
||||
@ -21,6 +25,10 @@ function Artemis:OnEnable()
|
||||
Artemis:RegisterEvent("UNIT_SPELLCAST_START")
|
||||
Artemis:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
|
||||
Artemis:RegisterEvent("UNIT_SPELLCAST_FAILED")
|
||||
Artemis:RegisterEvent("UNIT_SPELLCAST_DELAYED")
|
||||
Artemis:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
|
||||
Artemis:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
|
||||
Artemis:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE")
|
||||
Artemis:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
|
||||
Artemis:RegisterEvent("ZONE_CHANGED")
|
||||
Artemis:RegisterEvent("ZONE_CHANGED_NEW_AREA")
|
||||
@ -63,10 +71,10 @@ function Artemis:Transmit(prefix, data, prio)
|
||||
lastTransmitTime = GetTime()
|
||||
|
||||
if debugging == true then
|
||||
if prefixCounts[prefix] == nill then
|
||||
prefixCounts[prefix] = 0
|
||||
end
|
||||
prefixCounts[prefix] = prefixCounts[prefix] + 1
|
||||
if prefixCounts[prefix] == nill then
|
||||
prefixCounts[prefix] = 0
|
||||
end
|
||||
prefixCounts[prefix] = prefixCounts[prefix] + 1
|
||||
end
|
||||
|
||||
if debugging == true then
|
||||
@ -110,14 +118,14 @@ function Artemis:GetUnitDetails(unit)
|
||||
end
|
||||
|
||||
function Artemis:GetPlayerDetails()
|
||||
local details = Artemis:GetUnitDetails("player")
|
||||
local details = Artemis:GetUnitDetails("player")
|
||||
local id, name, _, _, role = GetSpecializationInfo(GetSpecialization())
|
||||
|
||||
details.realm = GetRealmName()
|
||||
details.realm = GetRealmName()
|
||||
details.achievementPoints = GetTotalAchievementPoints(false)
|
||||
details.s = {id = id, n = name, r = role}
|
||||
details.s = {id = id, n = name, r = role}
|
||||
|
||||
return details
|
||||
return details
|
||||
end
|
||||
|
||||
function Artemis:GetUnitAuras(unit, filter)
|
||||
@ -166,6 +174,7 @@ function Artemis:UNIT_TARGET(...)
|
||||
end
|
||||
|
||||
local details = Artemis:GetUnitDetails("target")
|
||||
channeling["target"] = false
|
||||
|
||||
Artemis:Transmit("target", details)
|
||||
Artemis:TransmitUnitState("target", true);
|
||||
@ -198,17 +207,17 @@ function Artemis:UNIT_AURA(...)
|
||||
local buffs = Artemis:GetUnitAuras(source, "PLAYER|HELPFUL")
|
||||
local debuffs = Artemis:GetUnitAuras(source, "PLAYER|HARMFUL")
|
||||
|
||||
local newBuffs = json.encode(buffs)
|
||||
local newDebuffs = json.encode(debuffs)
|
||||
local newBuffs = json.encode(buffs)
|
||||
local newDebuffs = json.encode(debuffs)
|
||||
|
||||
if not (lastBuffs == newBuffs) then
|
||||
Artemis:Transmit("buffs", buffs)
|
||||
end
|
||||
if not (lastDebuffs == newDebuffs) then
|
||||
Artemis:Transmit("debuffs", debuffs)
|
||||
end
|
||||
Artemis:Transmit("buffs", buffs)
|
||||
end
|
||||
if not (lastDebuffs == newDebuffs) then
|
||||
Artemis:Transmit("debuffs", debuffs)
|
||||
end
|
||||
|
||||
lastBuffs = newBuffs
|
||||
lastBuffs = newBuffs
|
||||
lastDebuffs = newDebuffs
|
||||
end
|
||||
|
||||
@ -232,6 +241,9 @@ function Artemis:UNIT_SPELLCAST_SUCCEEDED (...)
|
||||
if not (unitID == "player") and not (unitID == "target") then
|
||||
return
|
||||
end
|
||||
if channeling[unitID] == true then
|
||||
return
|
||||
end
|
||||
-- Many spells are irrelevant system spells, don't transmit these
|
||||
if unitID == "player" and not (IsPlayerSpell(spellID)) then
|
||||
return
|
||||
@ -270,6 +282,18 @@ function Artemis:UNIT_SPELLCAST_FAILED (...)
|
||||
Artemis:Transmit("spellCastFailed", unitID, "ALERT")
|
||||
end
|
||||
|
||||
-- Detect falure of non instant casts
|
||||
function Artemis:UNIT_SPELLCAST_DELAYED (...)
|
||||
local _, unitID, spell, rank, lineID, spellID = ...
|
||||
if not (unitID == "player") and not (unitID == "target") then
|
||||
return
|
||||
end
|
||||
local name, _, _, _, startTime, endTime, _, _, notInterruptible = UnitCastingInfo(unitID)
|
||||
local table = {uid = unitID, n = name, sid = spellID, s = startTime, e = endTime, ni = notInterruptible}
|
||||
|
||||
Artemis:Transmit("spellCast", table, "ALERT")
|
||||
end
|
||||
|
||||
-- Detect cancellation of non instant casts
|
||||
function Artemis:UNIT_SPELLCAST_INTERRUPTED (...)
|
||||
local source, unitID, _, _, lineID = ...
|
||||
@ -285,6 +309,43 @@ function Artemis:UNIT_SPELLCAST_INTERRUPTED (...)
|
||||
Artemis:Transmit("spellCastInterrupted", unitID, "ALERT")
|
||||
end
|
||||
|
||||
-- Detect spell channels
|
||||
function Artemis:UNIT_SPELLCAST_CHANNEL_START(...)
|
||||
local _, unitID, spell, rank, lineID, spellID = ...
|
||||
if not (unitID == "player") and not (unitID == "target") then
|
||||
return
|
||||
end
|
||||
channeling[unitID] = true
|
||||
|
||||
local name, _, _, _, startTime, endTime, _, notInterruptible = UnitChannelInfo(unitID)
|
||||
local table = {uid = unitID, n = name, sid = spellID, s = startTime, e = endTime, ni = notInterruptible}
|
||||
|
||||
Artemis:Transmit("spellChannel", table, "ALERT")
|
||||
end
|
||||
|
||||
function Artemis:UNIT_SPELLCAST_CHANNEL_UPDATE (...)
|
||||
local _, unitID, spell, rank, lineID, spellID = ...
|
||||
if not (unitID == "player") and not (unitID == "target") then
|
||||
return
|
||||
end
|
||||
local name, _, _, _, startTime, endTime, _, notInterruptible = UnitChannelInfo(unitID)
|
||||
local table = {uid = unitID, n = name, sid = spellID, s = startTime, e = endTime, ni = notInterruptible}
|
||||
|
||||
Artemis:Transmit("spellChannel", table, "ALERT")
|
||||
end
|
||||
|
||||
-- Detect cancellation of channels
|
||||
function Artemis:UNIT_SPELLCAST_CHANNEL_STOP (...)
|
||||
local source, unitID, _, _, lineID = ...
|
||||
if not (unitID == "player") and not (unitID == "target") then
|
||||
return
|
||||
end
|
||||
|
||||
channeling[unitID] = false
|
||||
|
||||
Artemis:Transmit("spellChannelInterrupted", unitID, "ALERT")
|
||||
end
|
||||
|
||||
function Artemis:ZONE_CHANGED_NEW_AREA (...)
|
||||
local pvpType, isSubZonePVP, factionName = GetZonePVPInfo()
|
||||
|
||||
|
||||
@ -75,7 +75,7 @@ namespace Artemis.Modules.Games.WoW
|
||||
ParseAuras(json, dataModel, false);
|
||||
break;
|
||||
case "spellCast":
|
||||
ParseSpellCast(json, dataModel);
|
||||
ParseSpellCast(json, dataModel, false);
|
||||
break;
|
||||
case "instantSpellCast":
|
||||
ParseInstantSpellCast(json, dataModel);
|
||||
@ -86,6 +86,12 @@ namespace Artemis.Modules.Games.WoW
|
||||
case "spellCastInterrupted":
|
||||
ParseSpellCastInterrupted(data, dataModel);
|
||||
break;
|
||||
case "spellChannel":
|
||||
ParseSpellCast(json, dataModel, true);
|
||||
break;
|
||||
case "spellChannelInterrupted":
|
||||
ParseSpellCastInterrupted(data, dataModel);
|
||||
break;
|
||||
default:
|
||||
Logger.Warn("The WoW addon sent an unknown command: {0}", command);
|
||||
break;
|
||||
@ -118,12 +124,12 @@ namespace Artemis.Modules.Games.WoW
|
||||
dataModel.Player.ApplyAuraJson(json, buffs);
|
||||
}
|
||||
|
||||
private void ParseSpellCast(JToken json, WoWDataModel dataModel)
|
||||
private void ParseSpellCast(JToken json, WoWDataModel dataModel, bool isChannel)
|
||||
{
|
||||
if (json["uid"].Value<string>() == "player")
|
||||
dataModel.Player.CastBar.ApplyJson(json);
|
||||
dataModel.Player.CastBar.ApplyJson(json, isChannel);
|
||||
else if (json["uid"].Value<string>() == "target")
|
||||
dataModel.Target.CastBar.ApplyJson(json);
|
||||
dataModel.Target.CastBar.ApplyJson(json, isChannel);
|
||||
}
|
||||
|
||||
private void ParseInstantSpellCast(JToken json, WoWDataModel dataModel)
|
||||
|
||||
@ -84,6 +84,8 @@ namespace Artemis.Modules.Games.WoW
|
||||
|
||||
// Split the string at the prefix
|
||||
var parts = str.Split(new[] {"(artemis)"}, StringSplitOptions.None);
|
||||
if (parts.Length < 2)
|
||||
return;
|
||||
var msg = parts[1];
|
||||
// Start escape char
|
||||
if (msg.StartsWith(MsgStart))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user