Exemplo n.º 1
0
 public override async Task<bool> OnInviteRequest(Message sender, EventData e)
 {
     if (e.IsFollowerEvent)
     {
         Log.Info("My minion {0} is requesting a party invite!", sender.HeroName);
         await Party.InviteFollower(sender);
     }
     return true;
 }
Exemplo n.º 2
0
 public virtual async Task<bool> OnWorldAreaChanged(Message sender, EventData e)
 {
     return false;
 }
Exemplo n.º 3
0
 public virtual async Task<bool> OnEngagedElite(Message sender, EventData e)
 {            
     return false;
 }
Exemplo n.º 4
0
 public override async Task<bool> OnEngagedElite(Message sender, EventData e)
 {
     if (e.IsLeaderEvent)
     {
         Log.Info("Leader ({0}) is attacking a Unique! {1} at {2} DistanceFromMe={3}",
             Common.CleanString(sender.HeroName),
             Common.CleanString(sender.CurrentTarget.Name),
             sender.Position.ToString(),
             ZetaDia.Me.Position.Distance(sender.CurrentTarget.Position));
     }
     return false;
 }
Exemplo n.º 5
0
 public override async Task<bool> OnEngagedElite(Message sender, EventData e)
 {
     if (e.IsFollowerEvent)
     {
         Log.Info("My minion {0} is attacking a Unique! {1} at {2} DistanceFromMe={3}",
             sender.HeroName, sender.CurrentTarget.Name, sender.Position, ZetaDia.Me.Position.Distance(sender.CurrentTarget.Position));
     }
     return true;
 }
Exemplo n.º 6
0
 public EventDispatcher(AsyncEvent<Message, EventData> e, EventData eventData, Message senderMessage)
 {
     AsyncEvent = e;
     EventData = eventData;
     SenderMessage = senderMessage;
 }
Exemplo n.º 7
0
 public virtual async Task<bool> OnLeavingGame(Message sender, EventData e)
 {
     return false;
 }
Exemplo n.º 8
0
 public virtual async Task<bool> OnUsedPortal(Message sender, EventData e)
 {
     return false;
 }
Exemplo n.º 9
0
        public static void Add(EventData e)
        {
            if (e == null)
                return;

            lock (Synchronizer)
            {
                if (e.Time < _lastClearedEvents)
                    return;

                if (Events.Contains(e))
                    return;

                Log.Debug("Added event {0} from {1} to EventManager", e.Type, e.OwnerHeroName);
                Events.Add(e);
            }
        }
Exemplo n.º 10
0
 private static void Queue(AsyncEvent<Message, EventData> e, EventData data, Message m)
 {
     if (e != null)
         EventQueue.Enqueue(new EventDispatcher(e, data, m));
 }
Exemplo n.º 11
0
 public static bool HasFired(EventData e)
 {
     return _hasFiredIds.ContainsKey(e.Id);
 }
Exemplo n.º 12
0
 private static bool TryGetMessageForId(EventData e, out Message m)
 {
     if (e.OwnerId == Player.BattleTagHash)
     {
         m = Player.CurrentMessage;
     }
     else if (e.OwnerId == AutoFollow.CurrentLeader.OwnerId)
     {
         m = AutoFollow.CurrentLeader;
     }
     else
     {
         m = AutoFollow.CurrentParty.FirstOrDefault(message => message.OwnerId == e.OwnerId);                
     }            
     return m != null;
 }
Exemplo n.º 13
0
 private static void FireEventByType(EventData e, Message m)
 {
     // These events are async so we can't just fire them here.
     // They need to be awaited within a bot hook.
     switch (e.Type)
     {
         case EventType.GreaterRiftStarted:
             Queue(GreaterRiftStarted, e, m);
             break;
         case EventType.NormalRiftStarted:
             Queue(NormalRiftStarted, e, m);
             break;
         case EventType.InTrouble:
             Queue(InTrouble, e, m);
             break;
         case EventType.JoinedParty:
             Queue(JoinedParty, e, m);
             break;
         case EventType.LeftParty:
             Queue(LeftParty, e, m);
             break;
         case EventType.LeftGame:
             Queue(LeftGame, e, m);
             break;
         case EventType.JoinedGame:
             Queue(JoinedGame, e, m);
             break;
         case EventType.LevelAreaChanged:
             Queue(LevelAreaChanged, e, m);
             break;
         case EventType.WorldAreaChanged:
             Queue(WorldAreaChanged, e, m);
             break;
         case EventType.ObjectiveFound:
             Queue(ObjectiveFound, e, m);
             break;
         case EventType.EngagedElite:
             Queue(EngagedElite, e, m);
             break;
         case EventType.UsedPortal:
             Queue(UsedPortal, e, m);
             break;
         case EventType.Died:
             Queue(Died, e, m);
             break;
         case EventType.InviteRequest:
             Queue(InviteRequest, e, m);
             break;
         case EventType.LeavingGame:
             Queue(LeavingGame, e, m);
             break;
         case EventType.GoingToTown:
             Queue(GoingToTown, e, m);
             break;
         case EventType.StartingTownRun:
             Queue(StartingTownRun, e, m);
             break;
         case EventType.GemUpgraded:
             Queue(GemUpgraded, e, m);
             break;
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Fire an event
        /// </summary>
        /// <param name="e">event data to send</param>
        /// <param name="debounceTime">duration to block subequent events of this type.</param>
        public static void FireEvent(EventData e, TimeSpan debounceTime = default(TimeSpan))
        {
            if (debounceTime == default(TimeSpan))
                debounceTime = TimeSpan.FromSeconds(1);

            var lastFiredType = LastFiredEventStore[e.Type];
            var timeSinceLastFiredType = DateTime.UtcNow.Subtract(lastFiredType);
            if (timeSinceLastFiredType < debounceTime)
            {
                //Log.Debug("Debouncing event. LastFired={0}s DebounceTime={1} Remaining={2}",
                //    timeSinceLastFiredType.TotalSeconds, debounceTime.TotalSeconds, (debounceTime - timeSinceLastFiredType).TotalSeconds);

                return;
            }         

            LastFiredEventStore[e.Type] = DateTime.UtcNow;

            Log.Debug("New Event {0} EventId={1}", e.ToString(), e.GetHashCode());

            Message m;
            if (!TryGetMessageForId(e, out m))
            {
                Log.Debug("Unable to find message for the event. Owner='{0}'", e.OwnerId);
                return;
            }

            if (e.IsMyEvent)
            {
                
            }
            else if (e.IsLeaderEvent)
            {
                if (Settings.Misc.DebugLogging)
                    Log.Warn("Firing {0} EventId={1}", e.ToString(), e.GetHashCode());
            }
            else
            {
                if (Settings.Misc.DebugLogging)
                    Log.Info("Firing {0} EventId={1}", e.ToString(), e.GetHashCode());
            }

            if (!e.IsMyEvent)
            {
                FireEventByType(e, m);
            }

            lock (Synchronizer)
            {
                _hasFiredIds.Add(e.Id, DateTime.UtcNow);

                if (!Events.Contains(e))
                    Add(e);
            }

            if (e.BreakExecution)
            {
                Log.Debug("Execution break was requested");
                IsExecutionBreakRequested = true;
            }

        }
Exemplo n.º 15
0
 public override async Task<bool> OnInviteRequest(Message sender, EventData e)
 {
     if (e.IsFollowerEvent)
     {
         Log.Info("My minion {0} is requesting a party invite!", sender.HeroName);
         await Party.InviteFollower(sender);
         
         if(DateTime.UtcNow.Subtract(Coordination.StartAllowedTime).TotalSeconds <= 30)
             Coordination.StartAllowedTime = DateTime.UtcNow.Add(TimeSpan.FromSeconds(30));
     }
     return true;
 }
Exemplo n.º 16
0
 public virtual async Task<bool> OnPlayerDied(Message sender, EventData e)
 {
     return false;
 }
Exemplo n.º 17
0
 public virtual async Task<bool> OnInTrouble(Message sender, EventData e)
 {
     return false;
 }
Exemplo n.º 18
0
        //public async Task<bool> AttackWithPlayer(Message player)
        //{
        //    if (player.IsInCombat && player.CurrentTarget != null && player.Distance < 150f && 
        //        player.CurrentTarget.Distance < 150f && ZetaDia.Me.IsInCombat && Data.Monsters.Count(m => m.Distance <= 30f) < 10)
        //    {
        //        Log.Info("Moving to attack {0}'s target - {1} Distance={2}", 
        //            player.HeroName, player.CurrentTarget.Name, player.CurrentTarget.Distance);

        //        if(await Movement.MoveTo(() => AutoFollow.GetUpdatedMessage(player).CurrentTarget, player.CurrentTarget.Name, 10f, () => ZetaDia.Me.IsInCombat || !ZetaDia.Me.Movement.IsMoving))
        //            return true;                
        //    }
        //    return false;
        //}

        public override async Task<bool> OnUsedPortal(Message sender, EventData e)
        {
            if (Player.IsIsInGreaterRift)
            {
                return false;
            }
            if (e.IsLeaderEvent)
            {
                var portal = e.NewValue as Interactable;
                if (portal == null)
                {
                    Log.Debug("The portal details weren't provided in event. :(");
                    return false;
                }

                if (portal.WorldSnoId != Player.CurrentWorldSnoId)
                {
                    Log.Debug("Portal is in a different world.");
                    return false;
                }

                Log.Info("Leader ({0}) used a portal ({1})", sender.HeroName, portal.InternalName);
                await Coroutine.Sleep(2000);

                if (AutoFollow.CurrentLeader.IsInSameWorld)
                {
                    Log.Debug("Leader is in same world.");
                    return false;
                }
                
                var positionMatch = Data.Portals.FirstOrDefault(p => (int)p.Position.X == (int)portal.ActorPosition.X && (int)p.Position.Y == (int)portal.ActorPosition.Y);
                if (positionMatch != null)
                {
                    Log.Info("Portal found by position, lets use it!");
                    await Movement.MoveToAndInteract(positionMatch);
                    return true;
                }

                var nameMatch = Data.Portals.FirstOrDefault(p => p.CommonData.Name.Contains(portal.BaseInternalName));
                if (nameMatch != null)
                {
                    Log.Info("Portal found by name, lets use it!");
                    await Movement.MoveToAndInteract(nameMatch);
                    return true;
                }

                var closestPortal = Data.Portals.OrderBy(p => p.Position.Distance(Player.Position)).FirstOrDefault();
                if (closestPortal != null)
                {
                    Log.Info("Trying our luck with this nearby portal...");
                    await Movement.MoveToAndInteract(closestPortal);
                    return true;
                }

                Log.Info("Unable to find the portal we need to clicky :(");
            }
            return false;
        }
Exemplo n.º 19
0
 public virtual async Task<bool> OnInviteRequest(Message sender, EventData e)
 {
     return false;
 }
Exemplo n.º 20
0
 public override async Task<bool> OnWorldAreaChanged(Message sender, EventData e)
 {
     if (e.IsLeaderEvent)
     {
         Log.Info("Leader ({0}) changed world from {1} to {2}", 
             sender.HeroName, e.OldValue, e.NewValue);
     }
     return false;
 }
Exemplo n.º 21
0
 public virtual async Task<bool> OnGemUpgraded(Message sender, EventData e)
 {
     return false;
 }
Exemplo n.º 22
0
        public override async Task<bool> OnLeavingGame(Message sender, EventData e)
        {
            if (e.IsLeaderEvent && Player.IsInGame)
            {
                Log.Info("Leader ({0}) is leaving game, lets leave too!",
                    sender.HeroName, e.OldValue, e.NewValue);

                await Party.LeaveGame();
                await Coroutine.Sleep(1000);
                return true;
            }
            return false;
        }
Exemplo n.º 23
0
 public override async Task<bool> OnGemUpgraded(Message sender, EventData e)
 {
     Log.Info("we are in the function of OnGemUpgraded");
     return false;
 }
Exemplo n.º 24
0
 public override async Task<bool> OnInTrouble(Message sender, EventData e)
 {
     if (e.IsFollowerEvent && !Data.Monsters.Any(m => m.Distance <= 80f) && sender.IsInSameWorld)
     {
         Log.Info("My minion needs help! Teleporting to {0}. Distance={1}", sender.HeroName, sender.Distance);
         await Coordination.TeleportToPlayer(sender);
     }
     return false;
 }