Guest User

TCT Jack'sDAMP Error

a guest
Mar 26th, 2017
203
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace Turbo.Plugins.Jack.Monsters
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using Turbo.Plugins.Default;
  7.  
  8. public delegate string AffixNameFunc(ISnoMonsterAffix affix);
  9.  
  10. public class DangerousAffixMonsterDefinition
  11. {
  12. public MonsterAffix Affix { get; private set; }
  13. public int Priority { get; set; }
  14.  
  15. public string AffixName { get; set; }
  16. public AffixNameFunc AffixNameFunc { get; set; }
  17.  
  18. public WorldDecoratorCollection EliteDecorators { get; set; }
  19. public IFont EliteLabelFont { get; set; }
  20.  
  21. public WorldDecoratorCollection MinionDecorators { get; set; }
  22. public IFont MinionLabelFont { get; set; }
  23. public bool ShowMinionDecorators { get; set; }
  24. public bool ShowMinionAffixesNames { get; set; }
  25.  
  26. public DangerousAffixMonsterDefinition(MonsterAffix affix)
  27. {
  28. Affix = affix;
  29. AffixNameFunc = (a) => string.Empty;
  30. }
  31. }
  32.  
  33. public class DangerousAffixMonsterPlugin : BasePlugin, IInGameWorldPainter
  34. {
  35. public Dictionary<MonsterAffix, DangerousAffixMonsterDefinition> Affixes { get; set; }
  36.  
  37. public IShapePainter DefaultMapShapePainter { get; set; }
  38. public StandardPingRadiusTransformator DefaultRadiusTransformator { get; set; }
  39. public IBrush DefaultBackgroundBrush { get; set; }
  40. public IBrush DefaultForegroundBrush { get; set; }
  41. public IFont DefaultEliteAffixesFont { get; set; }
  42. public IFont DefaultMinionAffixesFont { get; set; }
  43.  
  44. private const float _bgEliteRadius = 8;
  45. private const float _fgEliteRadius = 4;
  46. private const float _bgMinionRadius = 6;
  47. private const float _fgMinionRadius = 2;
  48.  
  49. public DangerousAffixMonsterPlugin()
  50. {
  51. Enabled = true;
  52. Order = 20100;
  53. }
  54.  
  55. public override void Load(IController hud)
  56. {
  57. base.Load(hud);
  58.  
  59. Affixes = new Dictionary<MonsterAffix, DangerousAffixMonsterDefinition>();
  60.  
  61. DefaultMapShapePainter = new CircleShapePainter(Hud);
  62. DefaultRadiusTransformator = new StandardPingRadiusTransformator(Hud, 500);
  63. DefaultBackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0);
  64. DefaultForegroundBrush = Hud.Render.CreateBrush(255, 255, 0, 0, 0);
  65. DefaultEliteAffixesFont = Hud.Render.CreateFont("tahoma", 10f, 200, 255, 255, 0, false, false, 128, 0, 0, 0, true);
  66. DefaultMinionAffixesFont = Hud.Render.CreateFont("tahoma", 7f, 200, 255, 255, 0, false, false, 128, 0, 0, 0, true);
  67.  
  68. //foreach (MonsterAffix affix in Enum.GetValues(typeof(MonsterAffix))) { DefineDangerousAffix(affix, (a) => a.NameLocalized.Substring(0, 2)); }
  69. }
  70.  
  71. public void PaintWorld(WorldLayer layer)
  72. {
  73. var monsters = Hud.Game.AliveMonsters.Where(m => m.Rarity == ActorRarity.Champion || m.Rarity == ActorRarity.Rare || m.Rarity == ActorRarity.RareMinion);
  74. foreach (var monster in monsters)
  75. {
  76. var dangerousAffixes = monster.AffixSnoList
  77. .Join(Affixes,
  78. snoAffix => snoAffix.Affix,
  79. dangerous => dangerous.Key,
  80. (snoAffix, dangerous) => dangerous.Value)
  81. .ToList();
  82.  
  83. if (dangerousAffixes.Count == 0) continue;
  84.  
  85. dangerousAffixes.Sort((a, b) => -a.Priority.CompareTo(b.Priority));
  86.  
  87. switch (monster.Rarity)
  88. {
  89. case ActorRarity.Champion:
  90. case ActorRarity.Rare:
  91. dangerousAffixes.First().EliteDecorators.Paint(layer, monster, monster.FloorCoordinate, null);
  92.  
  93. if (dangerousAffixes.Count == 1)
  94. DrawAffixName(monster, dangerousAffixes.First());
  95. else if (dangerousAffixes.Count > 1)
  96. DrawAffixNames(monster, dangerousAffixes, GetCombinedLabelsText(monster, dangerousAffixes));
  97. break;
  98.  
  99. case ActorRarity.RareMinion:
  100. var minionAffix = dangerousAffixes.FirstOrDefault(a => a.ShowMinionDecorators);
  101.  
  102. if (minionAffix != null)
  103. minionAffix.MinionDecorators.Paint(layer, monster, monster.FloorCoordinate, null);
  104.  
  105. dangerousAffixes = dangerousAffixes.Where(a => a.ShowMinionAffixesNames).ToList();
  106.  
  107. if (dangerousAffixes.Count == 1)
  108. DrawAffixName(monster, dangerousAffixes.First());
  109. else if (dangerousAffixes.Count > 1)
  110. DrawAffixNames(monster, dangerousAffixes, GetCombinedLabelsText(monster, dangerousAffixes));
  111. break;
  112. }
  113. }
  114. }
  115.  
  116. // TODO : refactor these monstruous signatures.. ><
  117. public DangerousAffixMonsterDefinition DefineDangerousAffix(MonsterAffix affix, string affixName, int priority = 0,
  118. IFont eliteFont = null, IFont minionFont = null, bool showMinionDecorators = false, bool showMinionAffixesNames = false,
  119. float bgEliteRadius = _bgEliteRadius, float fgEliteRadius = _fgEliteRadius, float bgMinionRadius = _bgMinionRadius, float fgMinionRadius = _fgMinionRadius,
  120. IBrush bgBrush = null, IShapePainter bgShapePainter = null, bool bgPing = false, IRadiusTransformator bgRadiusTransformator = null,
  121. IBrush fgBrush = null, IShapePainter fgShapePainter = null, bool fgPing = false, IRadiusTransformator fgRadiusTransformator = null)
  122. {
  123. AffixNameFunc affixNameFunc;
  124. if (affixName == null)
  125. affixNameFunc = (a) => string.Empty;
  126. else
  127. affixNameFunc = (a) => affixName;
  128.  
  129. return DefineDangerousAffix(affix, affixNameFunc, priority,
  130. eliteFont, minionFont, showMinionDecorators, showMinionAffixesNames,
  131. bgEliteRadius, fgEliteRadius, bgMinionRadius, fgMinionRadius,
  132. bgBrush, bgShapePainter, bgPing, bgRadiusTransformator,
  133. fgBrush, fgShapePainter, fgPing, fgRadiusTransformator);
  134. }
  135.  
  136. public DangerousAffixMonsterDefinition DefineDangerousAffix(MonsterAffix affix, AffixNameFunc affixNameFunc, int priority = 0,
  137. IFont eliteFont = null, IFont minionFont = null, bool showMinionDecorators = false, bool showMinionAffixesNames = false,
  138. float bgEliteRadius = _bgEliteRadius, float fgEliteRadius = _fgEliteRadius, float bgMinionRadius = _bgMinionRadius, float fgMinionRadius = _fgMinionRadius,
  139. IBrush bgBrush = null, IShapePainter bgShapePainter = null, bool bgPing = false, IRadiusTransformator bgRadiusTransformator = null,
  140. IBrush fgBrush = null, IShapePainter fgShapePainter = null, bool fgPing = false, IRadiusTransformator fgRadiusTransformator = null)
  141. {
  142. bgBrush = bgBrush ?? DefaultBackgroundBrush;
  143. fgBrush = fgBrush ?? DefaultForegroundBrush;
  144. bgShapePainter = bgShapePainter ?? DefaultMapShapePainter;
  145. fgShapePainter = fgShapePainter ?? DefaultMapShapePainter;
  146. eliteFont = eliteFont ?? DefaultEliteAffixesFont;
  147. minionFont = minionFont ?? DefaultMinionAffixesFont;
  148.  
  149. if (bgPing)
  150. bgRadiusTransformator = bgRadiusTransformator ?? DefaultRadiusTransformator;
  151. else
  152. bgRadiusTransformator = null;
  153.  
  154. if (fgPing)
  155. fgRadiusTransformator = fgRadiusTransformator ?? DefaultRadiusTransformator;
  156. else
  157. fgRadiusTransformator = null;
  158.  
  159. var affixDef = new DangerousAffixMonsterDefinition(affix)
  160. {
  161. EliteDecorators = CreateDecorators(bgEliteRadius, fgEliteRadius, bgBrush, fgBrush, bgShapePainter, fgShapePainter, bgRadiusTransformator, fgRadiusTransformator),
  162. MinionDecorators = CreateDecorators(bgMinionRadius, fgMinionRadius, bgBrush, fgBrush, bgShapePainter, fgShapePainter, bgRadiusTransformator, fgRadiusTransformator),
  163. EliteLabelFont = eliteFont,
  164. MinionLabelFont = minionFont,
  165. ShowMinionDecorators = showMinionDecorators,
  166. ShowMinionAffixesNames = showMinionAffixesNames,
  167. AffixNameFunc = affixNameFunc,
  168. Priority = priority,
  169.  
  170. };
  171.  
  172. affixDef.MinionDecorators.ToggleDecorators<MapShapeDecorator>(showMinionDecorators);
  173. affixDef.MinionDecorators.ToggleDecorators<MapLabelDecorator>(showMinionAffixesNames);
  174.  
  175. Affixes[affix] = affixDef;
  176. return affixDef;
  177. }
  178.  
  179. private WorldDecoratorCollection CreateDecorators(float bgRadius, float fgRadius, IBrush bgBrush, IBrush fgBrush,
  180. IShapePainter bgShapePainter, IShapePainter fgShapePainter, IRadiusTransformator bgRadiusTransformator, IRadiusTransformator fgRadiusTransformator)
  181. {
  182. return new WorldDecoratorCollection(
  183. new MapShapeDecorator(Hud)
  184. {
  185. Brush = bgBrush,
  186. Radius = bgRadius,
  187. ShapePainter = bgShapePainter,
  188. RadiusTransformator = bgRadiusTransformator,
  189. },
  190. new MapShapeDecorator(Hud)
  191. {
  192. Brush = fgBrush,
  193. Radius = fgRadius,
  194. ShapePainter = fgShapePainter,
  195. RadiusTransformator = fgRadiusTransformator,
  196. }
  197. );
  198. }
  199.  
  200. public void DrawAffixName(IMonster monster, DangerousAffixMonsterDefinition affix)
  201. {
  202. var font = monster.Rarity == ActorRarity.RareMinion ? affix.MinionLabelFont : affix.EliteLabelFont;
  203. var text = affix.AffixName ?? (affix.AffixName = affix.AffixNameFunc.Invoke(monster.AffixSnoList.First(snoa => snoa.Affix == affix.Affix)));
  204. var layout = font.GetTextLayout(text);
  205. float mapX, mapY;
  206. Hud.Render.GetMinimapCoordinates(monster.FloorCoordinate.X, monster.FloorCoordinate.Y, out mapX, out mapY);
  207.  
  208. font.DrawText(layout, mapX - layout.Metrics.Width / 2, mapY);
  209. }
  210.  
  211. public void DrawAffixNames(IMonster monster, IList<DangerousAffixMonsterDefinition> affixes, string combinedNames)
  212. {
  213. // get an estimation of combined labels size
  214. var first = affixes.FirstOrDefault();
  215. if (first == null) return;
  216.  
  217. var firstFont = (monster.Rarity == ActorRarity.RareMinion ? first.MinionLabelFont : first.EliteLabelFont);
  218. var combinedLayout = firstFont.GetTextLayout(combinedNames);
  219. var spacerLayout = firstFont.GetTextLayout(":");
  220. var offsetX = -combinedLayout.Metrics.Width / 2;
  221.  
  222. foreach (var affix in affixes)
  223. {
  224. var font = monster.Rarity == ActorRarity.RareMinion ? affix.MinionLabelFont : affix.EliteLabelFont;
  225. var text = affix.AffixName ?? (affix.AffixName = affix.AffixNameFunc.Invoke(monster.AffixSnoList.First(snoa => snoa.Affix == affix.Affix)));
  226.  
  227. if (string.IsNullOrWhiteSpace(text)) continue;
  228.  
  229. var layout = font.GetTextLayout(text);
  230. float mapX, mapY;
  231. Hud.Render.GetMinimapCoordinates(monster.FloorCoordinate.X, monster.FloorCoordinate.Y, out mapX, out mapY);
  232.  
  233. font.DrawText(layout, mapX + offsetX, mapY);
  234. offsetX += layout.Metrics.Width + spacerLayout.Metrics.Width;
  235. }
  236. }
  237.  
  238. private static string GetCombinedLabelsText(IMonster monster, IEnumerable<DangerousAffixMonsterDefinition> affixes)
  239. {
  240. return string.Join(":", affixes.Select(a => a.AffixName ?? (a.AffixName = a.AffixNameFunc.Invoke(monster.AffixSnoList.First(snoa => snoa.Affix == a.Affix)))));
  241. }
  242. }
  243. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×