private IMobObject Closest(Vector3 <float> center, List <IMobObject> mobs) { var dist = 0.0f; IMobObject closest = null; foreach (var m in mobs) { var cdist = m.ThreadSafeLocation.SimpleDistance(center); if (closest == null || cdist < dist) { dist = cdist; closest = m; } } return(closest); }
/// <summary> /// Initializes a new instance of the <see cref="Ennui.Api.Direct.Object.MobObject+MobHarvestableDrop"/> class. /// </summary> /// <param name="parent">The mob that has this drop.</param> /// <param name="drop">The drop config.</param> public MobHarvestableDrop(IApi api, IMobObject parent, IHarvestableDropConfig dropConfig) { this.api = api; this.parent = parent; this.dropConfig = dropConfig; }
private bool FindResource(Vector3 <float> center) { context.State = "Finding resource..."; Reset(); var territoryAreas = new List <Area>(); var graph = Graphs.LookupByDisplayName(Game.ClusterName); foreach (var t in graph.Territories) { var tCenter = t.Center; var tSize = t.Size; var tCenter3d = new Vector3f(tCenter.X, 0, tCenter.Y); var tBegin = tCenter3d.Translate(0 - (tSize.X / 2), -100, 0 - (tSize.Y / 2)); var tEnd = tCenter3d.Translate(tSize.X / 2, 100, tSize.Y / 2); var tArea = new Area(tBegin, tEnd); territoryAreas.Add(tArea); } if (config.AttackMobs) { var lpo = Players.LocalPlayer; if (lpo != null && config.IgnoreMobsOnLowHealth && lpo.HealthPercentage > config.IgnoreMobHealthPercent) { var resourceMobs = new List <IMobObject>(); foreach (var ent in Entities.MobChain.ExcludeByArea(territoryAreas.ToArray()).ExcludeWithIds(blacklist.ToArray()).AsList) { var drops = ent.HarvestableDropChain.FilterByTypeSet(SafeTypeSet.BatchConvert(config.TypeSetsToUse)).AsList; Logging.Log(drops.ToString()); if (drops.Count > 0) { resourceMobs.Add(ent); } } if (resourceMobs.Count > 0) { mobTarget = Closest(center, resourceMobs); } } } harvestableTarget = Objects .HarvestableChain .FilterDepleted() .ExcludeWithIds(blacklist.ToArray()) .ExcludeByArea(territoryAreas.ToArray()) .FilterByTypeSet(SafeTypeSet.BatchConvert(config.TypeSetsToUse)) .FilterWithSetupState(HarvestableSetupState.Invalid) .FilterWithSetupState(HarvestableSetupState.Owned) .Closest(center); if (mobTarget != null && harvestableTarget != null) { var mobDist = mobTarget.ThreadSafeLocation.SimpleDistance(center); var resDist = harvestableTarget.ThreadSafeLocation.SimpleDistance(center); if (mobDist < resDist) { harvestableTarget = null; } else { mobTarget = null; } } return(harvestableTarget != null || mobTarget != null); }
private void Reset() { harvestableTarget = null; mobTarget = null; gatherAttempts = 0; }
public ObjectHarvestable(IMobObject mobObject) { ScreenX = Convert.ToInt32(mobObject.ScreenLocation.X); ScreenY = Convert.ToInt32(mobObject.ScreenLocation.Y); Type = ResourceType.Hide; }