BorisKotlyar

ExampleStatModifier

Nov 16th, 2023
704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using Game.Entity;
  2. using Game.Scripts.Core.Entity.Stats;
  3.  
  4. namespace Game.Scripts.Battle.Units
  5. {
  6.     public class StatModifier
  7.     {
  8.         public string Guid;
  9.         public float Value;
  10.         public int Order;
  11.     }
  12.    
  13.     public class UnitBuffExample
  14.     {
  15.         private readonly EntityStatsStorage _statsStorage;
  16.  
  17.         private SceneUnit _sceneUnit;
  18.         private StatModifier _modifier;
  19.        
  20.         public UnitBuffExample(EntityStatsStorage statsStorage)
  21.         {
  22.             _statsStorage = statsStorage;
  23.         }
  24.        
  25.         public void Init(IEntity parentEntity)
  26.         {
  27.             _sceneUnit = parentEntity as SceneUnit;
  28.             if (_sceneUnit == null)
  29.                 return;
  30.            
  31.             var entityStats = _statsStorage.Get(_sceneUnit.Guid);
  32.             var hpStat = entityStats.Get<float>("HP");
  33.  
  34.             _modifier = new StatModifier
  35.             {
  36.                 Guid = System.Guid.NewGuid().ToString(),
  37.                 Value = 10f,
  38.                 Order = 0
  39.             };
  40.  
  41.             hpStat.ApplyModifier(_modifier);
  42.         }
  43.  
  44.         public void Dispose()
  45.         {
  46.             var entityStats = _statsStorage.Get(_sceneUnit.Guid);
  47.             var hpStat = entityStats.Get<float>("HP");
  48.             hpStat.RemoveModifier(_modifier);
  49.         }
  50.     }
  51. }
Tags: stats
Advertisement
Add Comment
Please, Sign In to add comment