mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Implemented CS:GO headshot and kill event
Implemented CS:GO active weapon Implemented events delay Fixed event triggers Fixed event time reset
This commit is contained in:
parent
84861a9f64
commit
54ff3a05ef
@ -1,4 +1,5 @@
|
|||||||
using Artemis.Models.Interfaces;
|
using Artemis.Models.Interfaces;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Artemis.Modules.Games.CounterStrike
|
namespace Artemis.Modules.Games.CounterStrike
|
||||||
{
|
{
|
||||||
@ -47,6 +48,10 @@ namespace Artemis.Modules.Games.CounterStrike
|
|||||||
|
|
||||||
public class State
|
public class State
|
||||||
{
|
{
|
||||||
|
[JsonIgnore]
|
||||||
|
public bool made_kill { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public bool made_headshot { get; set; }
|
||||||
public int health { get; set; }
|
public int health { get; set; }
|
||||||
public int armor { get; set; }
|
public int armor { get; set; }
|
||||||
public bool helmet { get; set; }
|
public bool helmet { get; set; }
|
||||||
@ -58,15 +63,8 @@ namespace Artemis.Modules.Games.CounterStrike
|
|||||||
public int round_killhs { get; set; }
|
public int round_killhs { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Weapon0
|
|
||||||
{
|
|
||||||
public string name { get; set; }
|
|
||||||
public string paintkit { get; set; }
|
|
||||||
public string type { get; set; }
|
|
||||||
public string state { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Weapon1
|
public class Weapon
|
||||||
{
|
{
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
||||||
public string paintkit { get; set; }
|
public string paintkit { get; set; }
|
||||||
@ -77,19 +75,12 @@ namespace Artemis.Modules.Games.CounterStrike
|
|||||||
public string state { get; set; }
|
public string state { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Weapon2
|
|
||||||
{
|
|
||||||
public string name { get; set; }
|
|
||||||
public string paintkit { get; set; }
|
|
||||||
public string type { get; set; }
|
|
||||||
public string state { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Weapons
|
public class Weapons
|
||||||
{
|
{
|
||||||
public Weapon0 weapon_0 { get; set; }
|
public Weapon active_weapon { get; set; }
|
||||||
public Weapon1 weapon_1 { get; set; }
|
public Weapon weapon_0 { get; set; }
|
||||||
public Weapon2 weapon_2 { get; set; }
|
public Weapon weapon_1 { get; set; }
|
||||||
|
public Weapon weapon_2 { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MatchStats
|
public class MatchStats
|
||||||
|
|||||||
@ -12,6 +12,11 @@ namespace Artemis.Modules.Games.CounterStrike
|
|||||||
{
|
{
|
||||||
public class CounterStrikeModel : GameModel
|
public class CounterStrikeModel : GameModel
|
||||||
{
|
{
|
||||||
|
private DateTime _lastHeadshot;
|
||||||
|
private int _lastHeadshots;
|
||||||
|
private DateTime _lastKill;
|
||||||
|
private int _lastKills;
|
||||||
|
|
||||||
public CounterStrikeModel(MainManager mainManager)
|
public CounterStrikeModel(MainManager mainManager)
|
||||||
: base(mainManager, SettingsProvider.Load<CounterStrikeSettings>(), new CounterStrikeDataModel())
|
: base(mainManager, SettingsProvider.Load<CounterStrikeSettings>(), new CounterStrikeDataModel())
|
||||||
{
|
{
|
||||||
@ -42,7 +47,46 @@ namespace Artemis.Modules.Games.CounterStrike
|
|||||||
|
|
||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
// TODO: Set up active weapon in the datamodel
|
if (DataModel == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var dm = (CounterStrikeDataModel) DataModel;
|
||||||
|
if (dm.player != null)
|
||||||
|
{
|
||||||
|
// Detect active weapon
|
||||||
|
if (dm.player.weapons.weapon_0?.state == "active")
|
||||||
|
dm.player.weapons.active_weapon = dm.player.weapons.weapon_0;
|
||||||
|
else if (dm.player.weapons.weapon_1?.state == "active")
|
||||||
|
dm.player.weapons.active_weapon = dm.player.weapons.weapon_1;
|
||||||
|
else if (dm.player.weapons.weapon_2?.state == "active")
|
||||||
|
dm.player.weapons.active_weapon = dm.player.weapons.weapon_2;
|
||||||
|
|
||||||
|
// Detect a kill
|
||||||
|
if (dm.player.state.round_kills > _lastKills)
|
||||||
|
{
|
||||||
|
dm.player.state.made_kill = true;
|
||||||
|
_lastKill = DateTime.Now;
|
||||||
|
}
|
||||||
|
else if (dm.player.state.made_kill && (DateTime.Now - _lastKill > TimeSpan.FromMilliseconds(500)))
|
||||||
|
dm.player.state.made_kill = false;
|
||||||
|
_lastKills = dm.player.state.round_kills;
|
||||||
|
|
||||||
|
// Detect a headshot
|
||||||
|
if (dm.player.state.round_killhs > _lastHeadshots)
|
||||||
|
{
|
||||||
|
dm.player.state.made_headshot = true;
|
||||||
|
_lastHeadshot = DateTime.Now;
|
||||||
|
}
|
||||||
|
else if (dm.player.state.made_headshot && (DateTime.Now - _lastHeadshot > TimeSpan.FromMilliseconds(500)))
|
||||||
|
dm.player.state.made_headshot = false;
|
||||||
|
_lastHeadshots = dm.player.state.round_killhs;
|
||||||
|
|
||||||
|
// Detect a round win
|
||||||
|
|
||||||
|
// Detect a round loss
|
||||||
|
}
|
||||||
|
|
||||||
|
DataModel = dm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleGameData(object sender, GameDataReceivedEventArgs e)
|
public void HandleGameData(object sender, GameDataReceivedEventArgs e)
|
||||||
@ -56,7 +100,9 @@ namespace Artemis.Modules.Games.CounterStrike
|
|||||||
// Parse the JSON
|
// Parse the JSON
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DataModel = JsonConvert.DeserializeObject<CounterStrikeDataModel>(jsonString);
|
if (DataModel == null)
|
||||||
|
DataModel = new CounterStrikeDataModel();
|
||||||
|
JsonConvert.PopulateObject(jsonString, DataModel);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -9,13 +9,16 @@ namespace Artemis.Profiles.Layers.Conditions
|
|||||||
{
|
{
|
||||||
public bool ConditionsMet(LayerModel layer, IDataModel dataModel)
|
public bool ConditionsMet(LayerModel layer, IDataModel dataModel)
|
||||||
{
|
{
|
||||||
var conditionsMet = layer.Properties.Conditions.All(cm => cm.ConditionMet(dataModel));
|
lock (layer.Properties.Conditions)
|
||||||
layer.EventProperties.Update(layer, conditionsMet);
|
{
|
||||||
|
var conditionsMet = layer.Properties.Conditions.All(cm => cm.ConditionMet(dataModel));
|
||||||
|
layer.EventProperties.Update(layer, conditionsMet);
|
||||||
|
|
||||||
if (conditionsMet && layer.EventProperties.MustTrigger)
|
if (conditionsMet && layer.EventProperties.CanTrigger)
|
||||||
layer.EventProperties.TriggerEvent(layer);
|
layer.EventProperties.TriggerEvent(layer);
|
||||||
|
|
||||||
return conditionsMet && layer.EventProperties.MustDraw;
|
return layer.EventProperties.MustDraw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Layers.Models
|
namespace Artemis.Profiles.Layers.Models
|
||||||
@ -10,10 +12,10 @@ namespace Artemis.Profiles.Layers.Models
|
|||||||
public TimeSpan TriggerDelay { get; set; }
|
public TimeSpan TriggerDelay { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public bool MustTrigger { get; set; }
|
public bool CanTrigger { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public DateTime AnimationStart { get; set; }
|
public DateTime EventTriggerTime { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public bool MustDraw { get; set; }
|
public bool MustDraw { get; set; }
|
||||||
@ -21,23 +23,70 @@ namespace Artemis.Profiles.Layers.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resets the event's properties and triggers it
|
/// Resets the event's properties and triggers it
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract void TriggerEvent(LayerModel layer);
|
public virtual void TriggerEvent(LayerModel layer)
|
||||||
|
{
|
||||||
|
if (!CanTrigger)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (TriggerDelay > TimeSpan.Zero)
|
||||||
|
{
|
||||||
|
if (EventCanTriggerTime == DateTime.MinValue)
|
||||||
|
EventCanTriggerTime = DateTime.Now;
|
||||||
|
|
||||||
|
if (DateTime.Now - EventCanTriggerTime < TriggerDelay)
|
||||||
|
return;
|
||||||
|
|
||||||
|
EventCanTriggerTime = DateTime.MinValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
CanTrigger = false;
|
||||||
|
MustDraw = true;
|
||||||
|
EventTriggerTime = DateTime.Now;
|
||||||
|
layer.Properties.AnimationProgress = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DateTime EventCanTriggerTime { get; set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets whether the event should stop
|
/// Gets whether the event should stop
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="layer"></param>
|
/// <param name="layer"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public abstract bool MustStop(LayerModel layer);
|
public virtual bool MustStop(LayerModel layer)
|
||||||
|
{
|
||||||
|
if (ExpirationType == ExpirationType.Time)
|
||||||
|
{
|
||||||
|
if (EventTriggerTime == DateTime.MinValue)
|
||||||
|
return false;
|
||||||
|
return DateTime.Now - EventTriggerTime > Length;
|
||||||
|
}
|
||||||
|
if (ExpirationType == ExpirationType.Animation)
|
||||||
|
return (layer.LayerAnimation == null) || layer.LayerAnimation.MustExpire(layer);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Called every frame, if parent conditions met.
|
// Called every frame, if parent conditions met.
|
||||||
public void Update(LayerModel layerModel, bool conditionsMet)
|
public void Update(LayerModel layerModel, bool conditionsMet)
|
||||||
{
|
{
|
||||||
if (MustStop(layerModel))
|
if (EventCanTriggerTime > DateTime.MinValue && (DateTime.Now - EventCanTriggerTime > TriggerDelay))
|
||||||
|
{
|
||||||
|
CanTrigger = true;
|
||||||
|
TriggerEvent(layerModel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MustDraw && MustStop(layerModel))
|
||||||
MustDraw = false;
|
MustDraw = false;
|
||||||
|
|
||||||
if (!conditionsMet)
|
if (!conditionsMet)
|
||||||
MustTrigger = true;
|
CanTrigger = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected bool DelayExpired()
|
||||||
|
{
|
||||||
|
return EventCanTriggerTime > DateTime.MinValue && DateTime.Now - EventCanTriggerTime >= TriggerDelay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using Artemis.Profiles.Layers.Types.Keyboard;
|
|
||||||
using Artemis.Profiles.Layers.Types.KeyboardGif;
|
using Artemis.Profiles.Layers.Types.KeyboardGif;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Layers.Models
|
namespace Artemis.Profiles.Layers.Models
|
||||||
@ -8,40 +7,23 @@ namespace Artemis.Profiles.Layers.Models
|
|||||||
{
|
{
|
||||||
public override void TriggerEvent(LayerModel layer)
|
public override void TriggerEvent(LayerModel layer)
|
||||||
{
|
{
|
||||||
var keyboardProperties = layer.Properties as KeyboardPropertiesModel;
|
if (CanTrigger && DelayExpired())
|
||||||
if (keyboardProperties == null)
|
{
|
||||||
throw new ArgumentException("Layer's properties cannot be null " +
|
if (layer.GifImage != null)
|
||||||
"and must be of type KeyboardPropertiesModel");
|
layer.GifImage.CurrentFrame = 0;
|
||||||
if (!MustTrigger)
|
}
|
||||||
return;
|
|
||||||
|
|
||||||
MustTrigger = false;
|
base.TriggerEvent(layer);
|
||||||
MustDraw = true;
|
|
||||||
keyboardProperties.AnimationProgress = 0.0;
|
|
||||||
if (layer.GifImage != null)
|
|
||||||
layer.GifImage.CurrentFrame = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool MustStop(LayerModel layer)
|
public override bool MustStop(LayerModel layer)
|
||||||
{
|
{
|
||||||
var keyboardProperties = layer.Properties as KeyboardPropertiesModel;
|
if (ExpirationType != ExpirationType.Animation)
|
||||||
if (keyboardProperties == null)
|
return base.MustStop(layer);
|
||||||
throw new ArgumentException("Layer's properties cannot be null " +
|
|
||||||
"and must be of type KeyboardPropertiesModel");
|
|
||||||
|
|
||||||
switch (ExpirationType)
|
if (layer.LayerType is KeyboardGifType)
|
||||||
{
|
return layer.GifImage?.CurrentFrame >= layer.GifImage?.FrameCount - 1;
|
||||||
case ExpirationType.Time:
|
return (layer.LayerAnimation == null) || layer.LayerAnimation.MustExpire(layer);
|
||||||
if (AnimationStart == DateTime.MinValue)
|
|
||||||
return false;
|
|
||||||
return DateTime.Now - Length > AnimationStart;
|
|
||||||
case ExpirationType.Animation:
|
|
||||||
if (layer.LayerType is KeyboardGifType)
|
|
||||||
return layer.GifImage?.CurrentFrame >= layer.GifImage?.FrameCount - 1;
|
|
||||||
return layer.LayerAnimation == null || layer.LayerAnimation.MustExpire(layer);
|
|
||||||
default:
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -242,5 +242,13 @@ namespace Artemis.Profiles.Layers.Models
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public void SetupCondition()
|
||||||
|
{
|
||||||
|
if (IsEvent && !(LayerCondition is EventCondition))
|
||||||
|
LayerCondition = new EventCondition();
|
||||||
|
else if (!IsEvent && !(LayerCondition is DataModelCondition))
|
||||||
|
LayerCondition = new DataModelCondition();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5,6 +5,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Artemis.Models.Interfaces;
|
using Artemis.Models.Interfaces;
|
||||||
using Artemis.Profiles.Layers.Abstract;
|
using Artemis.Profiles.Layers.Abstract;
|
||||||
|
using Artemis.Profiles.Layers.Conditions;
|
||||||
using Artemis.Profiles.Layers.Interfaces;
|
using Artemis.Profiles.Layers.Interfaces;
|
||||||
using Artemis.Profiles.Layers.Models;
|
using Artemis.Profiles.Layers.Models;
|
||||||
using Artemis.Profiles.Layers.Types.Keyboard;
|
using Artemis.Profiles.Layers.Types.Keyboard;
|
||||||
@ -175,7 +176,9 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
// TODO: EventPropVM must have layer too
|
// TODO: EventPropVM must have layer too
|
||||||
if (EventPropertiesViewModel != null)
|
if (EventPropertiesViewModel != null)
|
||||||
Layer.EventProperties = EventPropertiesViewModel.GetAppliedProperties();
|
Layer.EventProperties = EventPropertiesViewModel.GetAppliedProperties();
|
||||||
|
|
||||||
|
Layer.SetupCondition();
|
||||||
|
|
||||||
// Don't bother checking for a GIF path unless the type is GIF
|
// Don't bother checking for a GIF path unless the type is GIF
|
||||||
if (!(Layer.LayerType is KeyboardGifType))
|
if (!(Layer.LayerType is KeyboardGifType))
|
||||||
return;
|
return;
|
||||||
@ -215,6 +218,11 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
// that would upset the child layers' relations (sounds like Dr. Phil amirite?)
|
// that would upset the child layers' relations (sounds like Dr. Phil amirite?)
|
||||||
var currentObj = Clone(Layer);
|
var currentObj = Clone(Layer);
|
||||||
currentObj.Children.Clear();
|
currentObj.Children.Clear();
|
||||||
|
|
||||||
|
// Apply the IsEvent boolean
|
||||||
|
currentObj.SetupCondition();
|
||||||
|
ProposedLayer.SetupCondition();
|
||||||
|
|
||||||
var current = JsonConvert.SerializeObject(currentObj, Formatting.Indented);
|
var current = JsonConvert.SerializeObject(currentObj, Formatting.Indented);
|
||||||
var proposed = JsonConvert.SerializeObject(ProposedLayer, Formatting.Indented);
|
var proposed = JsonConvert.SerializeObject(ProposedLayer, Formatting.Indented);
|
||||||
|
|
||||||
|
|||||||
@ -546,8 +546,13 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var newProfile = GeneralHelpers.Clone(SelectedProfile);
|
var newProfile = GeneralHelpers.Clone(SelectedProfile);
|
||||||
newProfile.Name =
|
newProfile.Name = await DialogService
|
||||||
await DialogService.ShowInputDialog("Duplicate profile", "Please enter a unique profile name");
|
.ShowInputDialog("Duplicate profile", "Please enter a unique profile name");
|
||||||
|
|
||||||
|
// Null when the user cancelled
|
||||||
|
if (string.IsNullOrEmpty(newProfile.Name))
|
||||||
|
return;
|
||||||
|
|
||||||
// Verify the name
|
// Verify the name
|
||||||
while (ProfileProvider.GetAll().Contains(newProfile))
|
while (ProfileProvider.GetAll().Contains(newProfile))
|
||||||
{
|
{
|
||||||
@ -555,7 +560,7 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
await DialogService.ShowInputDialog("Name already in use", "Please enter a unique profile name");
|
await DialogService.ShowInputDialog("Name already in use", "Please enter a unique profile name");
|
||||||
|
|
||||||
// Null when the user cancelled
|
// Null when the user cancelled
|
||||||
if (string.IsNullOrEmpty(SelectedProfile.Name))
|
if (string.IsNullOrEmpty(newProfile.Name))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user