private static ActorMeta CreateActorMeta(DiaObject diaObject, ACD acd, int actorSNO, ActorType actorType) { using (new PerformanceLogger("CreateActorMeta")) { ActorMeta actorMeta; // We only care about having accurate information on Units and Gizmos. // Everything else can just return the default. //if (actorType == ActorType.Monster && diaObject is DiaUnit || // actorType == ActorType.Gizmo && diaObject is DiaGizmo || // actorType == ActorType.Player) //{ actorMeta = new ActorMeta(diaObject, acd, actorSNO, actorType); if (Trinity.Settings.Advanced.ExportNewActorMeta && actorMeta.IsValid && !actorMeta.IsPartial) { Logger.Log("Exporting ActorMeta for {0} ({1})", acd.Name, actorSNO); WriteToLog(actorMeta); } //} //else if (actorType == ActorType.Player) //{ // actorMeta = new ActorMeta(diaObject, acd, actorSNO, actorType); //} //else //{ // actorMeta = new ActorMeta(); //} ReferenceActorMeta.Add(actorSNO, actorMeta); return actorMeta; } }
public ActorBase(ACD acd, ActorType type) { _fixedACD = acd; _fixedActor = null; InternalName = CommonData?.Name ?? string.Empty; ActorType = type; }
private static MonsterType RefreshMonsterType(ACD tempCommonData, MonsterType monsterType, bool bAddToDictionary) { SNORecordMonster monsterInfo = tempCommonData.MonsterInfo; if (monsterInfo != null) { // Force Jondar as an undead, since Diablo 3 sticks him as a permanent ally if (c_ActorSNO == 86624) { monsterType = MonsterType.Undead; } else { monsterType = monsterInfo.MonsterType; } // Is this going to be a new dictionary entry, or updating one already existing? if (bAddToDictionary) { dictionaryStoredMonsterTypes.Add(c_ActorSNO, monsterType); } else { dictionaryStoredMonsterTypes[c_ActorSNO] = monsterType; } } else { monsterType = MonsterType.Undead; } return(monsterType); }
private static MonsterAffixes RefreshAffixes(ACD acd) { MonsterAffixes affixFlags; if (!dictGilesMonsterAffixCache.TryGetValue(c_RActorGuid, out affixFlags)) { try { affixFlags = acd.MonsterAffixes; dictGilesMonsterAffixCache.Add(c_RActorGuid, affixFlags); } catch (Exception ex) { affixFlags = MonsterAffixes.None; DbHelper.Log(LogCategory.CacheManagement, "Handled Exception getting affixes for Monster SNO={0} Name={1} RAGuid={2}", c_ActorSNO, c_InternalName, c_RActorGuid); DbHelper.Log(LogCategory.CacheManagement, ex.ToString()); } } c_unit_IsElite = affixFlags.HasFlag(MonsterAffixes.Elite); c_unit_IsRare = affixFlags.HasFlag(MonsterAffixes.Rare); c_unit_IsUnique = affixFlags.HasFlag(MonsterAffixes.Unique); c_unit_IsMinion = affixFlags.HasFlag(MonsterAffixes.Minion); // All-in-one flag for quicker if checks throughout c_IsEliteRareUnique = (c_unit_IsElite || c_unit_IsRare || c_unit_IsUnique || c_unit_IsMinion); return(affixFlags); }
protected override void OnRefresh(int interval) { base.OnRefresh(interval); Nav.D3.Navmesh navmesh_d3 = (m_Navmesh as Nav.D3.Navmesh); if (navmesh_d3.IsPlayerReady()) { try { var playerACDID = m_MemoryContext.DataSegment.ObjectManager.PlayerDataManager[m_MemoryContext.DataSegment.ObjectManager.Player.LocalPlayerIndex].ACDID; ACD player = playerACDID != -1 ? m_MemoryContext.DataSegment.ObjectManager.ACDManager.ActorCommonData[(short)playerACDID] : null; if (player == null) { return; } m_RenderCenter.X = player.Position.X; m_RenderCenter.Y = player.Position.Y; m_Navigator.CurrentPos = new Vec3(player.Position.X, player.Position.Y, player.Position.Z); } catch (Exception) {} } }
/// <summary> /// Refreshes a unit /// </summary> /// <param name="unit"></param> private static void RefreshUnit(CacheUnit unit) { using (new PerformanceLogger("CacheManagement.RefreshUnit")) { try { ACD acd = unit.CommonData; unit.Position = acd.Position; unit.CentreDistance = Vector3.Distance(GilesTrinity.PlayerStatus.CurrentPosition, acd.Position); if (unit.InternalUnit != null) { unit.HitpointsCurrent = unit.InternalUnit.HitpointsCurrent; if (unit.HitpointsCurrent <= 0) { unit.IsDead = true; } unit.IsBurrowed = unit.InternalUnit.IsBurrowed; unit.IsUntargetable = unit.InternalUnit.IsUntargetable; unit.IsInvulnerable = unit.InternalUnit.IsInvulnerable; } unit.CurrentAnimation = acd.CurrentAnimation; if (unit.IsBoss) { unit.MonsterType = acd.MonsterInfo.MonsterType; } } catch { } } }
/// <summary> Query if 'acd' is valid a ACD. </summary> /// <param name="unit"> The unit. </param> /// <returns> true if valid acd, false if not. </returns> public static bool IsAttackable(this DiaUnit unit) { ACD acd = unit.CommonData; if (!unit.IsValid || acd == null || unit.ACDGuid == -1) { return(false); } if (unit.IsFriendly) { return(false); } AnimationState animationState = GetAnimationStateForACD(acd); if (animationState == AnimationState.Dead) { return(false); } bool isAttackble = !unit.IsUntargetable && !unit.IsSlowdownImmune && !unit.IsStunImmune && !unit.IsUninterruptible && !unit.IsRootImmune && !unit.IsBurrowed && !unit.IsHidden && !unit.IsDead; return(isAttackble); }
private static bool TryCreateChest(ACD acd, out IMapMarker item, ref bool interested) { item = null; if (acd.GizmoType == GizmoType.Chest) { interested = true; if (IsValidGizmoChest(acd)) { item = new MapMarkerAcdChest(acd, IsValidGizmoChest); return(true); } } else if (acd.GizmoType == GizmoType.LoreChest) { interested = true; if (IsValidGizmoLoreChest(acd)) { item = new MapMarkerAcdChest(acd, IsValidGizmoLoreChest); return(true); } } else if (acd.GizmoType == GizmoType.Switch) { interested = true; switch ((int)acd.ActorSNO) { case 0x0005900F: // x1_Global_Chest_CursedChest case 0x00059229: // x1_Global_Chest_CursedChest_B item = new MapMarkerAcdCursedChest(acd, IsValidSwitchCursedChest); return(true); } } return(false); }
private static int Validate(ACD acd) { if (acd == null) { throw new ArgumentNullException(nameof(acd)); } return(acd.Address); }
private bool UpdateInventoryItem(TrinityItem item, ACD commonData) { item.OnUpdated(); if (!item.IsValid) { return(false); } return(true); }
// Attributes while flying. //295: PowerImmobilize(-3801) i: 1 f: 0 Value = 1 //842: HasLookOverride(-3254) i: 1 f: 0 Value = 1 //1058: PowerDisabled(-3038)[PowerSnoId: X1_Crusader_FallingSword: 239137] i: 1 f: 0 Value = 1 internal bool CheckVisualEffectNoneForPower(ACD commonData, SNOPower power) { if (commonData.GetAttribute <int>(((int)power << 12) + ((int)ActorAttributeType.PowerBuff0VisualEffectNone & 0xFFF)) == 1) { return(true); } return(false); }
private static AnimationState GetAnimationStateForACD(ACD acd) { if (acd != null && acd.AnimationInfo != null) { return(acd.AnimationInfo.State); } return(AnimationState.Invalid); }
public static int GetTeamId(ACD acd) { if (acd == null) { return(-1); } var overrideId = acd.TeamOverride; return(overrideId == -1 ? acd.TeamId : overrideId); }
private Monster CreateMonsterProxy(ACD acd) { var monster = new Monster { ACD = acd }; monster.Location.World = Game.WorldProxies[acd.SWorldID]; monster.Location.Scene = Game.SceneProxies[acd.SSceneID]; monster.Location.Position = acd.Position; return(monster); }
/// <summary> /// Get an attribute, exceptions get swallowed and default returned /// </summary> /// <typeparam name="T"></typeparam> /// <param name="actorACD">The actor acd.</param> /// <param name="type">The type.</param> /// <returns>T.</returns> public static T GetAttributeOrDefault <T>(this ACD actorACD, ActorAttributeType type) where T : struct { try { actorACD.GetAttribute <T>(type); } catch (Exception ex) { Logger.LogDebug(LogCategory.CacheManagement, "Exception on {0} accessing {1} attribute: {2}", actorACD.Name, type, ex); } return(default(T)); }
public MapMarkerAcd(ACD acd, Func <ACD, bool> isVisible) : base(Validate(acd)) { if (isVisible == null) { throw new ArgumentNullException(nameof(isVisible)); } _acd = acd; _acdId = _acd.ID; _isVisible = isVisible; }
private bool UpdateInventoryItem(TrinityItem item, ACD commonData) { _timer.Start(); item.CommonData = commonData; item.OnUpdated(); if (!item.IsValid) { return(false); } _timer.Stop(); item.UpdateTime = _timer.Elapsed.TotalMilliseconds; return(true); }
private Item CreateItemProxy(ACD acd) { var item = new Item { ACD = acd }; if ((int)acd.ItemLocation == -1) { item.Location.World = Game.WorldProxies[acd.SWorldID]; item.Location.Scene = Game.SceneProxies[acd.SSceneID]; item.Location.Position = acd.Position; } return(item); }
public static ActorMeta GetOrCreateActorMeta(DiaObject diaObject, ACD acd, int actorSNO, ActorType actorType) { using (new PerformanceLogger("GetOrCreateActorMeta")) { ActorMeta actorMeta; if (!ReferenceActorMeta.TryGetValue(actorSNO, out actorMeta)) { actorMeta = CreateActorMeta(diaObject, acd, actorSNO, actorType); } return actorMeta; } }
private static bool TryCreateMonster(ACD acd, out IMapMarker item, ref bool interested) { item = null; if (acd.ActorType == ActorType.Monster) { interested = true; if (IsValidMonster(acd)) { item = new MapMarkerAcdMonster(acd, IsValidMonster); return(true); } } return(false); }
private void Reset() { _minimapItemsDic.Clear(); if (_minimapItems.Count > 0) { Execute.OnUIThread(() => _minimapItems.Clear()); } _acdsObserver = null; _playerAcd = null; _ignoredSnoIds.Clear(); _localData = null; _objectManager = null; _isLocalActorReady = false; _previousFrame = 0; }
public static IMapMarker Create(ACD acd, out bool ignore) { IMapMarker item; bool interested = false; if (TryCreateMonster(acd, out item, ref interested) || TryCreateChest(acd, out item, ref interested) || TryCreateWreckable(acd, out item, ref interested)) { // Successfull! } ignore = !interested; return(item); }
private float GetWeight(DiaUnit u) { ACD commonData = u.CommonData; int key = commonData.DynamicId; if (!_weightCache.ContainsKey(key)) { float weight = GetPredeterminedWeight(u); float distPct = 1 - ((1 / (_killRadiusSqr)) * GetDistance(u, key)); weight *= distPct; weight *= commonData.GetAttribute <float>(ActorAttributeType.HitpointsMaxTotal) / commonData.GetAttribute <float>(ActorAttributeType.HitpointsCur); _weightCache.Add(key, weight); } return(_weightCache[key]); }
private static bool TryCreateWreckable(ACD acd, out IMapMarker item, ref bool interested) { item = null; if (acd.GizmoType == GizmoType.BreakableChest || acd.GizmoType == GizmoType.BreakableDoor || acd.GizmoType == GizmoType.DestroyableObject) { interested = true; if (IsValidGizmoWreckableObject(acd)) { item = new MapMarkerAcdWreckable(acd, IsValidGizmoWreckableObject); return(true); } } return(false); }
private bool IsConsidered(DiaUnit u) { if (u != null && u.IsValid && IsStaticDataValid(u) && u.IsACDBased) { ACD commonData = u.CommonData; int key = commonData.DynamicId; if (!_isConsideredCache.ContainsKey(key)) { _isConsideredCache.Add(key, GetDistance(u, key) <= _killRadiusSqr && IsValid(commonData) && u.InLineOfSight); } return(_isConsideredCache[key]); } return(false); }
private bool IsValid(ACD commonData) { if (!_isValidCache.ContainsKey(commonData.DynamicId)) { _isValidCache.Add(commonData.DynamicId, commonData.GetAttribute <int>(ActorAttributeType.Untargetable) == 0 && commonData.GetAttribute <int>(ActorAttributeType.Burrowed) == 0 && commonData.GetAttribute <int>(ActorAttributeType.SlowdownImmune) == 0 && commonData.GetAttribute <int>(ActorAttributeType.Uninterruptible) == 0 && commonData.GetAttribute <int>(ActorAttributeType.Invulnerable) == 0 && commonData.GetAttribute <int>(ActorAttributeType.StunImmune) == 0 && commonData.GetAttribute <int>(ActorAttributeType.RootImmune) == 0 && commonData.GetAttribute <float>(ActorAttributeType.HitpointsCur) > 0); } return(_isValidCache[commonData.DynamicId]); }
public static void ToScreenCoordinate(ACD target, ACD myself, int screenWidth, int screenHeight, out float RX, out float RY) { try { float X = target.Position.X; float Y = target.Position.Y; float Z = target.Position.Z; float xd = X - myself.Position.X; float yd = Y - myself.Position.Y; float zd = Z - myself.Position.Z; /* * float w = -0.515f * xd - 0.514f * yd - 0.686f * zd + 97.985f; * if (w < 1.0f) w = 1.0f; * float rX = (-1.682f * xd + 1.683f * yd + 0.007045f) / w; * float rY = (-1.540f * xd - 1.539f * yd + 2.307f * zd + 6.161f) / w; */ float w = -0.515f * xd + -0.514f * yd + -0.686f * zd + 97.985f; float rX = (-1.682f * xd + 1.683f * yd + 0.0f * zd + 7.045e-3f) / w; float rY = (-1.54f * xd + -1.539f * yd + 2.307f * zd + 6.161f) / w; //float a = (float)Engine.Current.VideoPreferences.x0C_DisplayMode.x20_Width / (float)Engine.Current.VideoPreferences.x0C_DisplayMode.x24_Height; //float D3ClientWindowApect = a * 600.0f / 800.0f; //int video_width = Engine.Current.VideoPreferences.x0C_DisplayMode.x20_Width; //int video_height = Engine.Current.VideoPreferences.x0C_DisplayMode.x24_Height; int video_width = screenWidth; int video_height = screenHeight; double D3ClientWindowApect = (double)((double)video_width / (double)video_height) / (double)(4.0f / 3.0f); // 4:3 = default aspect ratio rX /= (float)D3ClientWindowApect; RX = (rX + 1.0f) / 2.0f * video_width; RY = (1.0f - rY) / 2.0f * video_height; } catch { RX = 0; RY = 0; } }
public ActorBase(DiaObject fixedActor) { _fixedActor = fixedActor; _fixedACD = fixedActor.CommonData; // TODO: Verify this was never set in Trinity, except for ItemProperties. InternalName = _fixedActor.Name ?? string.Empty; if (CommonData != null) { InternalName = _fixedActor.CommonData?.Name; } // A property that is accessed very often from other properties. In Zeta this one // is hold per frame (which is ok there). But here in Trinity we should keep it // persistent per object. ActorType = _fixedActor.ActorType; }
/// <summary> /// Checks if the mob is Elite or Rare /// </summary> /// <param name="unit">DiaUnit</param> /// <returns>True if Current unit is Elite</returns> public static bool IsElite(this DiaUnit unit) { ACD commonData = unit.CommonData; if (unit.IsValid && commonData != null) { int key = commonData.DynamicId; if (!IsEliteCache.ContainsKey(key)) { MonsterAffixes affixes = commonData.MonsterAffixes; IsEliteCache.Add(key, affixes.HasFlag(MonsterAffixes.Elite) || affixes.HasFlag(MonsterAffixes.Rare) || affixes.HasFlag(MonsterAffixes.Unique) || TreasureGoblin.Contains(unit.ActorSNO)); } return(IsEliteCache[key]); } return(false); }
private float GetPredeterminedWeight(DiaUnit u) { ACD commonData = u.CommonData; int dynId = commonData.DynamicId; if (!_predeterminedWeightCache.ContainsKey(dynId)) { float weight = 1f; weight *= u.IsElite() ? 1.5f : 0.5f; weight *= GetSizeWeight(u); float prioMulti = ProfileManager.CurrentProfile.TargetPriorities.Where(prio => prio.ActorId == u.ActorSNO).Select( prio => prio.Multiplier).FirstOrDefault(); if (prioMulti != 0f) { weight *= prioMulti; } _predeterminedWeightCache.Add(dynId, weight); } return(_predeterminedWeightCache[dynId]); }
public static ActorSeed GetActorSeed(ACD commonData) { if (commonData == null || !commonData.IsValid) { return(null); } var seed = new ActorSeed(); seed.IsAcdBased = true; seed.IsRActorBased = false; seed.ActorSnoId = commonData.ActorSnoId; seed.CommonData = commonData; seed.AcdId = commonData.ACDId; seed.AnnId = commonData.AnnId; seed.ActorType = commonData.ActorType; seed.InternalName = commonData.Name; seed.Position = commonData.Position; seed.FastAttributeGroupId = commonData.FastAttribGroupId; return(seed); }
/// <summary> Query if 'unit' is elite. </summary> /// <param name="unit"> The unit. </param> /// <returns> true if elite, false if not. </returns> private bool IsElite(ACD unit) { if (unit.IsValid) { int key = unit.DynamicId; bool isElite; if (IsEliteCache.TryGetValue(key, out isElite)) { return(isElite); } MonsterAffixes affixes = unit.MonsterAffixes; IsEliteCache.Add(key, affixes.HasFlag(MonsterAffixes.Elite) || affixes.HasFlag(MonsterAffixes.Rare) || affixes.HasFlag(MonsterAffixes.Unique) ); return(IsEliteCache[key]); } return(false); }
private static bool CheckVisualEffectNoneForPower(ACD commonData, SNOPower power) { if (commonData.GetAttribute<int>(((int)power << 12) + ((int)ActorAttributeType.PowerBuff0VisualEffectNone & 0xFFF)) == 1) return true; return false; }
public ActorMeta(DiaObject diaObject, ACD acd, int actorSNO, ActorType actorType) { _isValid = false; _isPartial = false; if (diaObject == null || acd == null) return; // We need to really really really make sure that we only export from valid objects var actorInfo = acd.ActorInfo; var monsterInfo = acd.MonsterInfo; var unit = diaObject as DiaUnit; var gizmo = diaObject as DiaGizmo; var item = diaObject as DiaItem; ActorSNO = actorSNO; ActorType = actorType; try { _isValid = acd.IsValid && !acd.IsDisposed && actorInfo != null && actorInfo.IsValid && !actorInfo.IsDisposed && (actorInfo.SNOMonster == -1 || unit != null && unit.IsValid && monsterInfo.IsValid && !monsterInfo.IsDisposed); } catch (Exception) { } try { _isPartial = (gizmo != null && !gizmo.IsValid) || (unit != null && !unit.IsValid) || (item != null && !item.IsValid); } catch (Exception) { } if (!_isValid) return; if (acd.IsValid && !acd.IsDisposed) { InternalName = Trinity.NameNumberTrimRegex.Replace(acd.Name, ""); } if (actorInfo == null) { _isValid = false; } else { var actorSNOSources = new HashSet<int> { acd.ActorSNO, diaObject.ActorSNO, diaObject.CommonData.ActorSNO, acd.ActorInfo.SNOId, }; if (actorInfo.SNOMonster != -1) actorSNOSources.Add(acd.MonsterInfo.SNOActor); if (actorSNOSources.Any(o => o != actorSNO)) { Logger.Log("Detected ActorSNO Mismatch ({0} / {1} / {2} / {3} / {4} / {5})", actorSNO, acd.ActorSNO, diaObject.ActorSNO, diaObject.CommonData.ActorSNO, acd.ActorInfo.SNOId, acd.MonsterInfo.SNOActor); _isValid = false; } var internalNameSources = new HashSet<string> { Trinity.NameNumberTrimRegex.Replace(diaObject.Name, ""), ((SNOActor) actorSNO).ToString(), ((SNOActor) acd.ActorSNO).ToString(), ((SNOActor) acd.ActorInfo.SNOId).ToString(), }; if (internalNameSources.Any(o => o != InternalName)) { Logger.Log("Detected InternalName Mismatch ({0} / {1} / {2} / {3} / {4})", InternalName, Trinity.NameNumberTrimRegex.Replace(diaObject.Name, ""), ((SNOActor) actorSNO).ToString(), ((SNOActor) acd.ActorSNO).ToString(), ((SNOActor) acd.ActorInfo.SNOId).ToString()); _isValid = false; } if (acd.ActorType != ActorType.Monster && acd.ActorInfo.SNOMonster != -1) { Logger.Log("MonsterSNO on non-monster type."); _isValid = false; } } if (TrinityItemManager.DetermineItemType(InternalName, ItemType.Unknown) != TrinityItemType.Unknown) { _isValid = false; Logger.Log("Detected Item Mis-classified as Gizmo or Monster. InternalName={0} IsGizmo={1} IsUnit={2}", InternalName, gizmo != null, unit != null); } if (actorInfo != null && (int)actorInfo.GizmoType == 5) { _isValid = false; Logger.Log("Detected Invalid GizmoType 5", InternalName, gizmo != null, unit != null); } if (_isValid) { if (actorInfo != null && actorInfo.IsValid && !actorInfo.IsDisposed) { MonsterSNO = actorInfo.SNOMonster; Radius = acd.ActorInfo.Sphere.Radius; PhysMeshSNO = actorInfo.SNOPhysMesh; ApperanceSNO = actorInfo.SNOApperance; AnimSetSNO = actorInfo.SNOAnimSet; IsMerchant = actorInfo.IsMerchant; } if (MonsterSNO != -1 && unit != null && unit.IsValid && monsterInfo.IsValid && !monsterInfo.IsDisposed) { IsMonster = true; MonsterType = monsterInfo.MonsterType; MonsterRace = monsterInfo.MonsterRace; MonsterSize = monsterInfo.MonsterSize; } if (unit != null && unit.IsValid) { IsUnit = true; GizmoType = GizmoType.None; try { IsHostile = unit.IsHostile; } catch (Exception) { } try { IsNPC = unit.IsNPC; } catch (Exception) { } try { PetType = unit.PetType; } catch (Exception) { } try { IsSalvageShortcut = unit.IsSalvageShortcut; } catch (Exception) { } try { HirelingType = unit.HirelingType; } catch (Exception) { } try { IsHelper = unit.IsHelper; } catch (Exception) { } try { IsDefaultHidden = unit.IsHidden; } catch (Exception) { } try { IsQuestGiver = unit.IsQuestGiver; } catch (Exception) { } try { IsSummoned = unit.Summoner != null || unit.SummonedBySNO != -1 || unit.SummonedByACDId != -1; } catch (Exception) { } try { IsSummoner = acd.Name.ToLower().Contains("summoner") || CacheManager.Units.Any(u => u.SummonedByACDId == acd.DynamicId); } catch (Exception) { } } if (gizmo != null && gizmo.IsValid) { IsGizmo = true; try { GizmoType = acd.GizmoType; } catch (Exception) { } try { GizmoIsBarracade = gizmo.IsBarricade; } catch (Exception) { } try { GizmoIsDestructible = gizmo.IsDestructibleObject; } catch (Exception) { } try { GizmoIsDisabledByScript = gizmo.IsGizmoDisabledByScript; } catch (Exception) { } try { GizmoIsPortal = gizmo.IsPortal; } catch (Exception) { } try { GizmoIsTownPortal = gizmo.IsTownPortal; } catch (Exception) { } try { GizmoDefaultCharges = gizmo.GizmoCharges; } catch (Exception) { } try { GizmoDefaultState = gizmo.GizmoState; } catch (Exception) { } try { GizmoGrantsNoXp = gizmo.GrantsNoXp; } catch (Exception) { } try { GizmoDropNoLoot = gizmo.DropsNoLoot; } catch (Exception) { } try { GizmoIsOperatable = gizmo.Operatable; } catch (Exception) { } } } }