public void Execute(ReplyContext context, object config)
        {
            var adoptedHero = BLTAdoptAHeroCampaignBehavior.Current.GetAdoptedHero(context.UserName);

            if (adoptedHero == null)
            {
                ActionManager.SendReply(context, AdoptAHero.NoHeroMessage);
                return;
            }

            ExecuteInternal(adoptedHero, context, config, s =>
            {
                if (!string.IsNullOrEmpty(s))
                {
                    ActionManager.SendReply(context, s);
                }
            },
                            s =>
            {
                if (!string.IsNullOrEmpty(s))
                {
                    ActionManager.SendReply(context, s);
                }
            });
        }
Exemplo n.º 2
0
        protected override void ExecuteInternal(Hero adoptedHero, ReplyContext context, object config,
                                                Action <string> onSuccess, Action <string> onFailure)
        {
            var heroClass = adoptedHero.GetClass();

            if (heroClass == null)
            {
                onFailure($"You don't have a class, so no powers are available!");
                return;
            }

            (bool canActivate, string failReason) = heroClass.ActivePower.CanActivate(adoptedHero);
            if (!canActivate)
            {
                onFailure($"You cannot activate your powers now: {failReason}!");
                return;
            }

            if (heroClass.ActivePower.IsActive(adoptedHero))
            {
                onFailure($"Your powers are already active!");
                return;
            }

            (bool allowed, string message) = heroClass.ActivePower.Activate(adoptedHero, context);

            if (allowed)
            {
                onSuccess(message);
            }
            else
            {
                onFailure(message);
            }
        }
        // protected override Type ConfigType => typeof(SettingsBase);

        protected override void ExecuteInternal(ReplyContext context, object config,
                                                Action <string> onSuccess,
                                                Action <string> onFailure)
        {
            var settings    = (SettingsBase)config;
            var adoptedHero = BLTAdoptAHeroCampaignBehavior.Current.GetAdoptedHero(context.UserName);

            if (adoptedHero == null)
            {
                onFailure(AdoptAHero.NoHeroMessage);
                return;
            }

            int availableGold = BLTAdoptAHeroCampaignBehavior.Current.GetHeroGold(adoptedHero);

            if (availableGold < settings.GoldCost)
            {
                onFailure(Naming.NotEnoughGold(settings.GoldCost, availableGold));
                return;
            }

            int amount = MBRandom.RandomInt(settings.AmountLow, settings.AmountHigh);

            (bool success, string description) = Improve(context.UserName, adoptedHero, amount, settings, context.Args);
            if (success)
            {
                onSuccess(description);
                BLTAdoptAHeroCampaignBehavior.Current.ChangeHeroGold(adoptedHero, -settings.GoldCost);
            }
            else
            {
                onFailure(description);
            }
        }
Exemplo n.º 4
0
        protected override void ExecuteInternal(ReplyContext context, object config, Action <string> onSuccess, Action <string> onFailure)
        {
            var settings = (Config)config;

            var adoptedHero = BLTAdoptAHeroCampaignBehavior.Current.GetAdoptedHero(context.UserName);

            if (settings.FromAdoptedHero)
            {
                if (adoptedHero == null)
                {
                    onFailure(AdoptAHero.NoHeroMessage);
                    return;
                }

                int availableGold = BLTAdoptAHeroCampaignBehavior.Current.GetHeroGold(adoptedHero);
                if (availableGold < settings.GoldAmountToGive)
                {
                    onFailure(Naming.NotEnoughGold(settings.GoldAmountToGive, availableGold));
                    return;
                }
                BLTAdoptAHeroCampaignBehavior.Current.ChangeHeroGold(adoptedHero, -settings.GoldAmountToGive);
            }
            Log.ShowInformation($"{context.UserName} gives you {settings.GoldAmountToGive} gold" +
                                (string.IsNullOrEmpty(context.Args) ? "" : $": \"{context.Args}\""), adoptedHero?.CharacterObject, settings.AlertSound);

            Hero.MainHero.ChangeHeroGold(settings.GoldAmountToGive);

            onSuccess($"Sent {settings.GoldAmountToGive}{Naming.Gold} to {Hero.MainHero.Name}");
        }
Exemplo n.º 5
0
        public void Execute(ReplyContext context, object config)
        {
            var adoptedHero = BLTAdoptAHeroCampaignBehavior.Current.GetAdoptedHero(context.UserName);

            if (adoptedHero == null)
            {
                ActionManager.SendReply(context, AdoptAHero.NoHeroMessage);
                return;
            }

            var nameableItems = BLTAdoptAHeroCampaignBehavior.Current.GetCustomItems(adoptedHero)
                                .Where(e => BLTCustomItemsCampaignBehavior.Current.ItemCanBeNamed(e.ItemModifier))
                                .ToList()
            ;

            if (!nameableItems.Any())
            {
                ActionManager.SendReply(context, $"You have no nameable items");
                return;
            }

            if (string.IsNullOrEmpty(context.Args))
            {
                ActionManager.SendReply(context, $"You will rename your {nameableItems.First().GetModifiedItemName()}");
                return;
            }

            string previousName = nameableItems.First().GetModifiedItemName().ToString();

            BLTCustomItemsCampaignBehavior.Current.NameItem(nameableItems.First().ItemModifier, context.Args);
            ActionManager.SendReply(context, $"{previousName} renamed to {context.Args}");
        }
Exemplo n.º 6
0
 public void Execute(ReplyContext context, object config)
 {
     if (!string.IsNullOrEmpty(context.Args) && Agent.Main != null)
     {
         Mission.Current.MakeSound(SoundEvent.GetEventIdFromString(context.Args), Agent.Main.AgentVisuals.GetGlobalFrame().origin, false, true, Agent.Main.Index, -1);
     }
 }
Exemplo n.º 7
0
        protected override void ExecuteInternal(ReplyContext context, object config, Action <string> onSuccess, Action <string> onFailure)
        {
            var settings = (Settings)config;

            var adoptedHero = BLTAdoptAHeroCampaignBehavior.Current.GetAdoptedHero(context.UserName);

            if (adoptedHero == null)
            {
                onFailure(AdoptAHero.NoHeroMessage);
                return;
            }

            int availableGold = BLTAdoptAHeroCampaignBehavior.Current.GetHeroGold(adoptedHero);

            if (availableGold < settings.GoldCost)
            {
                onFailure(Naming.NotEnoughGold(settings.GoldCost, availableGold));
                return;
            }

            (bool success, string reply) = BLTTournamentQueueBehavior.Current.AddToQueue(adoptedHero, context.IsSubscriber, settings.GoldCost);
            if (!success)
            {
                onFailure(reply);
            }
            else
            {
                BLTAdoptAHeroCampaignBehavior.Current.ChangeHeroGold(adoptedHero, -settings.GoldCost);
                onSuccess(reply);
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReplyEventArgs"/> class.
 /// </summary>
 /// <param name="reply">The reply.</param>
 /// <param name="message">The message.</param>
 /// <param name="replyContext">The reply context.</param>
 /// <param name="conversationReplyCount">The conversation reply count.</param>
 /// <param name="messageHandler">The message handler.</param>
 public ReplyEventArgs(Reply reply, Message message, ReplyContext replyContext, int conversationReplyCount, MessageHandler messageHandler)
 {
     this.Reply                  = reply;
     this.Message                = message;
     this.ReplyContext           = replyContext;
     this.ConversationReplyCount = conversationReplyCount;
     this.MessageHandler         = messageHandler;
 }
Exemplo n.º 9
0
        protected override void ExecuteInternal(Hero adoptedHero, ReplyContext context, object config,
                                                Action <string> onSuccess, Action <string> onFailure)
        {
            var customItems =
                BLTAdoptAHeroCampaignBehavior.Current.GetCustomItems(adoptedHero).ToList();

            if (!customItems.Any())
            {
                ActionManager.SendReply(context, $"You have no items to give");
                return;
            }

            if (string.IsNullOrWhiteSpace(context.Args))
            {
                ActionManager.SendReply(context,
                                        $"Usage: !{((Command)context.Source).Name} (recipient) (partial item name)");
                return;
            }

            var argParts = context.Args.Trim().Split(' ').ToList();

            if (argParts.Count == 1)
            {
                ActionManager.SendReply(context,
                                        $"Usage: !{((Command)context.Source).Name} (recipient) (partial item name)");
                return;
            }

            var targetHero = BLTAdoptAHeroCampaignBehavior.Current.GetAdoptedHero(argParts[0]);

            if (targetHero == null)
            {
                ActionManager.SendReply(context, $"Couldn't find recipient \"{argParts[0]}\"");
                return;
            }

            string itemName      = context.Args.Substring(argParts[0].Length + 1).Trim();
            var    matchingItems = customItems.Where(i => i.GetModifiedItemName()
                                                     .ToString().IndexOf(itemName, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                   .ToList();

            if (matchingItems.Count == 0)
            {
                ActionManager.SendReply(context, $"No items found matching \"{itemName}\"");
                return;
            }
            if (matchingItems.Count > 1)
            {
                ActionManager.SendReply(context, $"{matchingItems.Count} items found matching \"{itemName}\", be more specific");
                return;
            }
            var item = matchingItems.First();

            BLTAdoptAHeroCampaignBehavior.Current.TransferCustomItem(adoptedHero, targetHero, item, 0);

            ActionManager.SendNonReply(context, $"\"{item.GetModifiedItemName()}\" was transferred from @{adoptedHero.FirstName} to @{targetHero}");
        }
Exemplo n.º 10
0
        public SeguradoTest()
        {
            _context = new ReplyContext(new DbContextOptionsBuilder <ReplyContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
            _context.Segurado.AddRange(SeguradoMock.Dados());
            _context.SaveChanges();

            _seguradoRepository         = new SeguradoRepository(_context);
            _seguradoApplicationService = new SeguradoApplicationService(_seguradoRepository);
            _valorAleatorio             = new Random();
        }
Exemplo n.º 11
0
 /// <summary>
 /// Raises the replied event.
 /// </summary>
 /// <param name="reply">The reply.</param>
 /// <param name="message">The message.</param>
 /// <param name="replyContext">The reply context.</param>
 /// <param name="messageHandler">The message handler.</param>
 private void RaiseReplied(Reply reply, Message message, ReplyContext replyContext, MessageHandler messageHandler)
 {
     if (this.Replied != null && reply != null && reply.Messages != null && reply.Messages.Count > 0)
     {
         this.ConversationReplyCount++;
         this.Replied(this, new ReplyEventArgs(reply, message, replyContext, this.ConversationReplyCount, messageHandler));
         Debug.WriteLine("Bot says: ");
         Debug.WriteLine(reply);
     }
 }
Exemplo n.º 12
0
        protected override void ExecuteInternal(ReplyContext context, object config, Action <string> onSuccess, Action <string> onFailure)
        {
            var adoptedHero = BLTAdoptAHeroCampaignBehavior.Current.GetAdoptedHero(context.UserName);

            if (adoptedHero == null)
            {
                onFailure(AdoptAHero.NoHeroMessage);
                return;
            }
            ExecuteInternal(adoptedHero, context, config, onSuccess, onFailure);
        }
Exemplo n.º 13
0
 public ArticleServiceImpl(ArticleContext articleContext, ClassificationContext classificationContext
                           , CommentContext commentContext, TagContext tagContext
                           , UserContext userContext
                           , ReplyContext replyContext)
 {
     _articleContext        = articleContext;
     _classificationContext = classificationContext;
     _commentContext        = commentContext;
     _tagContext            = tagContext;
     _userContext           = userContext;
     _replyContext          = replyContext;
 }
Exemplo n.º 14
0
        void IRewardHandler.Enqueue(ReplyContext context, object config)
        {
            var settings    = (Settings)config;
            var adoptedHero = BLTAdoptAHeroCampaignBehavior.Current.GetAdoptedHero(context.UserName);

            if (adoptedHero == null)
            {
                ActionManager.NotifyCancelled(context, AdoptAHero.NoHeroMessage);
                return;
            }
            int newGold = BLTAdoptAHeroCampaignBehavior.Current.ChangeHeroGold(adoptedHero, settings.Amount);

            ActionManager.NotifyComplete(context, $"{Naming.Inc}{settings.Amount}{Naming.Gold}{Naming.To}{newGold}{Naming.Gold}");
        }
Exemplo n.º 15
0
        public void Execute(ReplyContext context, object config)
        {
            var adoptedHero = BLTAdoptAHeroCampaignBehavior.Current.GetAdoptedHero(context.UserName);

            if (adoptedHero == null)
            {
                ActionManager.SendReply(context, AdoptAHero.NoHeroMessage);
                return;
            }

            string[] parts = context.Args?.Split(' ');
            if (parts?.Length != 2)
            {
                ActionManager.SendReply(context, $"Usage: !{((Command)context.Source).Name} team gold");
                return;
            }

            int gold    = BLTAdoptAHeroCampaignBehavior.Current.GetHeroGold(adoptedHero);
            int nameIdx = -1;

            if (parts[0].ToLower() == "all" || int.TryParse(parts[0], out gold))
            {
                nameIdx = 1;
            }
            else if (parts[1].ToLower() == "all" || int.TryParse(parts[1], out gold))
            {
                nameIdx = 0;
            }
            if (gold <= 0 || nameIdx == -1)
            {
                ActionManager.SendReply(context, $"Invalid gold argument");
                return;
            }

            string team = parts[nameIdx].ToLower();

            (bool success, string failReason) = BLTTournamentBetMissionBehavior.Current?.PlaceBet(adoptedHero, team, gold)
                                                ?? (false, "Betting not active");
            if (!success)
            {
                ActionManager.SendReply(context, failReason);
            }
            else
            {
                ActionManager.SendReply(context, $"Bet {gold}{Naming.Gold} on {team}");
            }
        }
Exemplo n.º 16
0
        protected override void ExecuteInternal(ReplyContext context, object config, Action <string> onSuccess, Action <string> onFailure)
        {
            var settings = (Config)config;

            if (string.IsNullOrEmpty(context.Args))
            {
                onFailure("No message provided!");
                return;
            }

            var adoptedHero = BLTAdoptAHeroCampaignBehavior.Current.GetAdoptedHero(context.UserName);

            Log.ShowInformation((adoptedHero == null ? $"{context.UserName}: " : "") + context.Args,
                                adoptedHero?.CharacterObject, settings.AlertSound);

            onSuccess("Sent");
        }
Exemplo n.º 17
0
 public void Execute(ReplyContext context, object config)
 {
     if (Agent.Main == null)
     {
         return;
     }
     if (active != null)
     {
         CharacterEffect.RemoveAgentEffects(active);
         active = null;
     }
     if (!string.IsNullOrEmpty(context.Args))
     {
         active = CharacterEffect.CreateAgentEffects(Agent.Main, context.Args,
                                                     MatrixFrame.Identity.Strafe(0.1f),
                                                     Game.Current.HumanMonster.HeadLookDirectionBoneIndex);
     }
 }
 void ICommandHandler.Execute(ReplyContext context, object config)
 {
     ExecuteInternal(context, config,
                     s =>
     {
         if (!string.IsNullOrEmpty(s))
         {
             ActionManager.SendReply(context, s);
         }
     },
                     s =>
     {
         if (!string.IsNullOrEmpty(s))
         {
             ActionManager.SendReply(context, s);
         }
     });
 }
Exemplo n.º 19
0
        private void ReplyComplete(IAsyncResult result)
        {
            ReplyContext replyContext = (ReplyContext)result.AsyncState;

            Contract.Assert(replyContext != null);

            try
            {
                replyContext.RequestContext.EndReply(result);
            }
            catch { }
            finally
            {
                Interlocked.Decrement(ref _requestsOutstanding);
                BeginNextRequest(replyContext.ChannelContext);
                replyContext.Dispose();
            }
        }
        private static void BeginReply(ReplyContext replyContext)
        {
            Contract.Assert(replyContext != null);

            try
            {
                IAsyncResult result = replyContext.RequestContext.BeginReply(replyContext.Reply, _onReplyComplete, replyContext);
                if (result.CompletedSynchronously)
                {
                    ReplyComplete(result);
                }
            }
            catch
            {
                BeginReceiveRequestContext(replyContext.ChannelContext);
                replyContext.Dispose();
            }
        }
        private static void ReplyComplete(IAsyncResult result)
        {
            ReplyContext replyContext = (ReplyContext)result.AsyncState;

            Contract.Assert(replyContext != null);

            try
            {
                replyContext.RequestContext.EndReply(result);
            }
            catch
            {
            }
            finally
            {
                BeginReceiveRequestContext(replyContext.ChannelContext);
                replyContext.Dispose();
            }
        }
Exemplo n.º 22
0
        private void BeginReply(ReplyContext replyContext)
        {
            Contract.Assert(replyContext != null);

            try
            {
                IAsyncResult result = replyContext.RequestContext.BeginReply(replyContext.Reply, _onReplyComplete, replyContext);
                if (result.CompletedSynchronously)
                {
                    ReplyComplete(result);
                }
            }
            catch
            {
                Interlocked.Decrement(ref _requestsOutstanding);
                BeginNextRequest(replyContext.ChannelContext);
                replyContext.Dispose();
            }
        }
Exemplo n.º 23
0
        protected override void ExecuteInternal(Hero adoptedHero, ReplyContext context, object config,
                                                Action <string> onSuccess, Action <string> onFailure)
        {
            if (string.IsNullOrWhiteSpace(context.Args))
            {
                ActionManager.SendReply(context,
                                        $"Usage: !{((Command)context.Source).Name} (bid amount)");
                return;
            }

            if (!int.TryParse(context.Args, out int bid) || bid < 0)
            {
                ActionManager.SendReply(context, $"Invalid bid amount");
                return;
            }

            (bool _, string description) = BLTAdoptAHeroCampaignBehavior.Current.AuctionBid(adoptedHero, bid);

            ActionManager.SendReply(context, description);
        }
Exemplo n.º 24
0
        protected override void ExecuteInternal(Hero adoptedHero, ReplyContext context, object config,
                                                Action <string> onSuccess, Action <string> onFailure)
        {
            var customItems =
                BLTAdoptAHeroCampaignBehavior.Current.GetCustomItems(adoptedHero).ToList();

            if (!customItems.Any())
            {
                ActionManager.SendReply(context, $"You have no items to discard");
                return;
            }

            if (string.IsNullOrWhiteSpace(context.Args))
            {
                ActionManager.SendReply(context,
                                        $"Usage: !{((Command)context.Source).Name} (partial item name)");
                return;
            }

            var matchingItems = customItems.Where(i => i.GetModifiedItemName()
                                                  .ToString().IndexOf(context.Args, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                .ToList();

            if (matchingItems.Count == 0)
            {
                ActionManager.SendReply(context, $"No items found matching \"{context.Args}\"");
                return;
            }
            if (matchingItems.Count > 1)
            {
                ActionManager.SendReply(context, $"{matchingItems.Count} items found matching \"{context.Args}\", be more specific");
                return;
            }
            var item = matchingItems.First();

            BLTAdoptAHeroCampaignBehavior.Current.DiscardCustomItem(adoptedHero, item);

            ActionManager.SendReply(context, $"\"{item.GetModifiedItemName()}\" was discarded");
        }
Exemplo n.º 25
0
        protected override void ExecuteInternal(ReplyContext context, object config, Action <string> onSuccess, Action <string> onFailure)
        {
            if (context.Args != "yes")
            {
                onFailure($"You must enter 'yes' at the prompt to retire your hero");
                return;
            }
            var adoptedHero = BLTAdoptAHeroCampaignBehavior.Current.GetAdoptedHero(context.UserName);

            if (adoptedHero == null)
            {
                onFailure(AdoptAHero.NoHeroMessage);
                return;
            }
            if (Mission.Current != null)
            {
                onFailure($"You cannot retire your hero, as a mission is active!");
                return;
            }
            Log.ShowInformation($"{adoptedHero.Name} has retired!", adoptedHero.CharacterObject, Log.Sound.Horns3);
            BLTAdoptAHeroCampaignBehavior.Current.RetireHero(adoptedHero);
        }
Exemplo n.º 26
0
        void ICommandHandler.Execute(ReplyContext context, object config)
        {
            var settings    = config as Settings ?? new Settings();
            var adoptedHero = BLTAdoptAHeroCampaignBehavior.Current.GetAdoptedHero(context.UserName);
            var infoStrings = new List <string>();

            if (adoptedHero == null)
            {
                infoStrings.Add(AdoptAHero.NoHeroMessage);
            }
            else
            {
                if (settings.ShowGold)
                {
                    int gold = BLTAdoptAHeroCampaignBehavior.Current.GetHeroGold(adoptedHero);
                    infoStrings.Add($"{gold}{Naming.Gold}");
                }

                if (settings.ShowGeneral)
                {
                    var cl = BLTAdoptAHeroCampaignBehavior.Current.GetClass(adoptedHero);
                    infoStrings.Add($"{cl?.Name ?? "No Class"}");
                    if (adoptedHero.Clan != null)
                    {
                        infoStrings.Add($"Clan {adoptedHero.Clan.Name}");
                    }
                    infoStrings.Add($"{adoptedHero.Culture}");
                    infoStrings.Add($"{adoptedHero.Age:0} yrs");
                    infoStrings.Add($"{adoptedHero.HitPoints} / {adoptedHero.CharacterObject.MaxHitPoints()} HP");
                    if (adoptedHero.LastSeenPlace != null)
                    {
                        infoStrings.Add($"Last seen near {adoptedHero.LastSeenPlace.Name}");
                    }
                }

                if (settings.ShowTopSkills)
                {
                    infoStrings.Add($"[LVL] {adoptedHero.Level}");
                    infoStrings.Add("[SKILLS] " + string.Join("■",
                                                              HeroHelpers.AllSkillObjects
                                                              .Where(s => adoptedHero.GetSkillValue(s) >= settings.MinSkillToShow)
                                                              .OrderByDescending(s => adoptedHero.GetSkillValue(s))
                                                              .Select(skill => $"{SkillXP.GetShortSkillName(skill)} {adoptedHero.GetSkillValue(skill)} " +
                                                                      $"[f{adoptedHero.HeroDeveloper.GetFocus(skill)}]")
                                                              ));
                }

                if (settings.ShowAttributes)
                {
                    infoStrings.Add("[ATTR] " + string.Join("■", HeroHelpers.AllAttributes
                                                            .Select(a
                                                                    => $"{HeroHelpers.GetShortAttributeName(a)} {adoptedHero.GetAttributeValue(a)}")));
                }

                if (settings.ShowEquipment)
                {
                    infoStrings.Add(
                        $"[TIER] {BLTAdoptAHeroCampaignBehavior.Current.GetEquipmentTier(adoptedHero) + 1}");
                    var cl = BLTAdoptAHeroCampaignBehavior.Current.GetEquipmentClass(adoptedHero);
                    infoStrings.Add($"{cl?.Name ?? "No Equip Class"}");
                }

                if (settings.ShowInventory)
                {
                    infoStrings.Add("[BATTLE] " + string.Join("■", adoptedHero.BattleEquipment
                                                              .YieldFilledEquipmentSlots().Select(e => e.element)
                                                              .Select(e => $"{e.GetModifiedItemName()}")
                                                              ));
                }

                if (settings.ShowCivilianInventory)
                {
                    infoStrings.Add("[CIV] " + string.Join("■", adoptedHero.CivilianEquipment
                                                           .YieldFilledEquipmentSlots().Select(e => e.element)
                                                           .Select(e => $"{e.GetModifiedItemName()}")
                                                           ));
                }

                if (settings.ShowStorage)
                {
                    var customItems
                        = BLTAdoptAHeroCampaignBehavior.Current.GetCustomItems(adoptedHero);
                    infoStrings.Add("[STORED] " + (customItems.Any() ? string.Join("■", customItems
                                                                                   .Select(e => e.GetModifiedItemName())) : "(nothing)"));
                }

                if (settings.ShowRetinue)
                {
                    var retinue
                        = BLTAdoptAHeroCampaignBehavior.Current.GetRetinue(adoptedHero).ToList();
                    if (retinue.Count > 0)
                    {
                        double tier = retinue.Average(r => r.Tier);
                        infoStrings.Add($"[RETINUE] {retinue.Count} (avg Tier {tier:0.#})");
                    }
                    else
                    {
                        infoStrings.Add($"[RETINUE] None");
                    }
                }

                if (settings.ShowRetinueList)
                {
                    var retinue = BLTAdoptAHeroCampaignBehavior.Current
                                  .GetRetinue(adoptedHero)
                                  .GroupBy(r => r)
                                  .OrderBy(r => r.Key.Tier)
                                  .ToList();
                    foreach (var r in retinue)
                    {
                        infoStrings.Add(r.Count() > 1 ? $"{r.Key.Name} x {r.Count()}" : $"{r.Key.Name}");
                    }
                }

                if (settings.ShowAchievements)
                {
                    var achievements = BLTAdoptAHeroCampaignBehavior.Current
                                       .GetAchievements(adoptedHero)
                                       .ToList();
                    if (achievements.Any())
                    {
                        infoStrings.Add($"[ACHIEV] " + string.Join("■", achievements
                                                                   .Select(e => e.Name)));
                    }
                    else
                    {
                        infoStrings.Add($"[ACHIEV] None");
                    }
                }

                if (settings.ShowTrackedStats)
                {
                    var achievementList = new List <(string shortName, AchievementStatsData.Statistic id)>
                    {
                        ("K", AchievementStatsData.Statistic.TotalKills),
                        ("D", AchievementStatsData.Statistic.TotalDeaths),
                        ("KVwr", AchievementStatsData.Statistic.TotalViewerKills),
                        ("KStrmr", AchievementStatsData.Statistic.TotalStreamerKills),
                        ("Battles", AchievementStatsData.Statistic.Battles),
                        ("Sums", AchievementStatsData.Statistic.Summons),
                        ("CSums", AchievementStatsData.Statistic.ConsecutiveSummons),
                        ("Atks", AchievementStatsData.Statistic.Attacks),
                        ("CAtks", AchievementStatsData.Statistic.ConsecutiveAttacks),
                        ("TourRndW", AchievementStatsData.Statistic.TotalTournamentRoundWins),
                        ("TourRndL", AchievementStatsData.Statistic.TotalTournamentRoundLosses),
                        ("TourW", AchievementStatsData.Statistic.TotalTournamentFinalWins),
                    };
                    infoStrings.Add($"[STATS] " + string.Join("■",
                                                              achievementList.Select(a =>
                                                                                     $"{a.shortName}:" +
                                                                                     $"{BLTAdoptAHeroCampaignBehavior.Current.GetAchievementTotalStat(adoptedHero, a.id)}" +
                                                                                     $"({BLTAdoptAHeroCampaignBehavior.Current.GetAchievementClassStat(adoptedHero, a.id)})"
                                                                                     )));
                }

                if (settings.ShowPowers)
                {
                    var heroClass = adoptedHero.GetClass();
                    if (heroClass != null)
                    {
                        var activePowers
                            = heroClass.ActivePower.GetUnlockedPowers(adoptedHero).OfType <HeroPowerDefBase>();
                        infoStrings.Add("[ACTIVE] " +
                                        string.Join("■", activePowers.Select(p => p.Name)));

                        var passivePowers
                            = heroClass.PassivePower.GetUnlockedPowers(adoptedHero).OfType <HeroPowerDefBase>();
                        infoStrings.Add("[PASSIVE] " +
                                        string.Join("■", passivePowers.Select(p => p.Name)));
                    }
                }
            }
            ActionManager.SendReply(context, infoStrings.ToArray());
        }
 protected abstract void ExecuteInternal(Hero adoptedHero, ReplyContext context, object config,
                                         Action <string> onSuccess, Action <string> onFailure);
        private static void BeginReply(ReplyContext replyContext)
        {
            Contract.Assert(replyContext != null);

            try
            {
                IAsyncResult result = replyContext.RequestContext.BeginReply(replyContext.Reply, _onReplyComplete, replyContext);
                if (result.CompletedSynchronously)
                {
                    ReplyComplete(result);
                }
            }
            catch
            {
                BeginReceiveRequestContext(replyContext.ChannelContext);
                replyContext.Dispose();
            }
        }
Exemplo n.º 29
0
        private void BeginReply(ReplyContext replyContext)
        {
            Contract.Assert(replyContext != null);

            try
            {
                IAsyncResult result = replyContext.RequestContext.BeginReply(replyContext.Reply, _onReplyComplete, replyContext);
                if (result.CompletedSynchronously)
                {
                    ReplyComplete(result);
                }
            }
            catch
            {
                Interlocked.Decrement(ref _requestsOutstanding);
                BeginNextRequest(replyContext.ChannelContext);
                replyContext.Dispose();
            }
        }
Exemplo n.º 30
0
 public Repository(ReplyContext context)
 {
     _context = context;
     _entity  = _context.Set <TEntity>();
 }
Exemplo n.º 31
0
        protected override void ExecuteInternal(ReplyContext context, object baseConfig,
                                                Action <string> onSuccess, Action <string> onFailure)
        {
            if (Mission.Current == null)
            {
                onFailure($"No mission is active!");
                return;
            }

            if (BLTBuffetModule.EffectsConfig.DisableEffectsInTournaments &&
                MissionHelpers.InTournament())
            {
                onFailure($"Not allowed during tournament!");
                return;
            }

            if (!Mission.Current.IsLoadingFinished ||
                Mission.Current.CurrentState != Mission.State.Continuing ||
                Mission.Current?.GetMissionBehaviour <TournamentFightMissionController>() != null && Mission.Current.Mode != MissionMode.Battle)
            {
                onFailure($"The mission has not started yet!");
                return;
            }

            if (Mission.Current.IsMissionEnding || Mission.Current.MissionResult?.BattleResolved == true)
            {
                onFailure($"The mission is ending!");
                return;
            }

            var effectsBehaviour = BLTEffectsBehaviour.Get();

            var config = (Config)baseConfig;

            bool GeneralAgentFilter(Agent agent)
            => agent.IsHuman && (!config.TargetOnFootOnly || agent.HasMount == false) && !effectsBehaviour.Contains(agent, config);

            var target = config.Target switch
            {
                Target.Player => Agent.Main,
                Target.AdoptedHero => Mission.Current.Agents.FirstOrDefault(a => a.IsAdoptedBy(context.UserName)),
                Target.Any => Mission.Current.Agents.Where(GeneralAgentFilter).Where(a => !a.IsAdopted()).SelectRandom(),
                Target.EnemyTeam => Mission.Current.Agents.Where(GeneralAgentFilter)
                .Where(a => a.Team?.IsValid == true &&
                       Mission.Current.PlayerTeam?.IsValid == true &&
                       !a.Team.IsFriendOf(Mission.Current.PlayerTeam) &&
                       !a.IsAdopted())
                .SelectRandom(),
                Target.PlayerTeam => Mission.Current.Agents.Where(GeneralAgentFilter)
                .Where(a => a.Team?.IsPlayerTeam == true && !a.IsAdopted())
                .SelectRandom(),
                Target.AllyTeam => Mission.Current.Agents.Where(GeneralAgentFilter)
                .Where(a => a.Team?.IsPlayerAlly == false && !a.IsAdopted())
                .SelectRandom(),
                _ => null
            };

            if (target == null || target.AgentVisuals == null)
            {
                onFailure($"Couldn't find the target!");
                return;
            }

            if (string.IsNullOrEmpty(config.Name))
            {
                onFailure($"CharacterEffect {context.Source} configuration error: Name is missing!");
                return;
            }

            if (effectsBehaviour.Contains(target, config))
            {
                onFailure($"{target.Name} already affected by {config.Name}!");
                return;
            }

            if (config.TargetOnFootOnly && target.HasMount)
            {
                onFailure($"{target.Name} is mounted so cannot be affected by {config.Name}!");
                return;
            }

            var effectState = effectsBehaviour.Add(target, config);

            foreach (var pfx in config.ParticleEffects ?? Enumerable.Empty <ParticleEffectDef>())
            {
                var pfxState = new CharacterEffectState.PfxState();
                switch (pfx.AttachPoint)
                {
                case ParticleEffectDef.AttachPointEnum.OnWeapon:
                    pfxState.weaponEffects = CreateWeaponEffects(target, pfx.Name);
                    break;

                case ParticleEffectDef.AttachPointEnum.OnHands:
                    pfxState.boneAttachments = CreateAgentEffects(target,
                                                                  pfx.Name,
                                                                  MatrixFrame.Identity,
                                                                  Game.Current.HumanMonster.MainHandItemBoneIndex,
                                                                  Game.Current.HumanMonster.OffHandItemBoneIndex);
                    break;

                case ParticleEffectDef.AttachPointEnum.OnHead:
                    pfxState.boneAttachments = CreateAgentEffects(target,
                                                                  pfx.Name,
                                                                  MatrixFrame.Identity.Strafe(0.1f),
                                                                  Game.Current.HumanMonster.HeadLookDirectionBoneIndex);
                    break;

                case ParticleEffectDef.AttachPointEnum.OnBody:
                    pfxState.boneAttachments = CreateAgentEffects(target, pfx.Name, MatrixFrame.Identity.Elevate(0.1f));
                    break;

                default:
                    Log.Error($"{config.Name}: No location specified for particle Id {pfx.Name} in CharacterEffect");
                    break;
                }
                effectState.state.Add(pfxState);
            }

            // if (config.Properties != null && target.AgentDrivenProperties != null)
            // {
            //     ApplyPropertyModifiers(target, config);
            // }

            // if (config.Light != null)
            // {
            //     effectState.light = CreateLight(target, config.Light.Radius, config.Light.Intensity, config.Light.ColorParsed);
            // }

            if (config.RemoveArmor)
            {
                foreach (var(_, index) in target.SpawnEquipment.YieldArmorSlots())
                {
                    target.SpawnEquipment[index] = EquipmentElement.Invalid;
                }
                target.UpdateSpawnEquipmentAndRefreshVisuals(target.SpawnEquipment);
            }

            if (!string.IsNullOrEmpty(config.ActivateParticleEffect))
            {
                Mission.Current.Scene.CreateBurstParticle(ParticleSystemManager.GetRuntimeIdByName(config.ActivateParticleEffect), target.AgentVisuals.GetGlobalFrame());
            }
            if (!string.IsNullOrEmpty(config.ActivateSound))
            {
                Mission.Current.MakeSound(SoundEvent.GetEventIdFromString(config.ActivateSound), target.AgentVisuals.GetGlobalFrame().origin, false, true, target.Index, -1);
            }

            Log.LogFeedEvent($"{config.Name} is active on {target.Name}!");

            onSuccess($"{config.Name} is active on {target.Name}!");
        }
Exemplo n.º 32
0
        protected override void ExecuteInternal(Hero adoptedHero, ReplyContext context, object config,
                                                Action <string> onSuccess, Action <string> onFailure)
        {
            var settings = (Settings)config;

            if (BLTAdoptAHeroCampaignBehavior.Current.AuctionInProgress)
            {
                ActionManager.SendReply(context, $"Another auction is already in progress");
                return;
            }

            var auctionItems =
                BLTAdoptAHeroCampaignBehavior.Current.GetCustomItems(adoptedHero).ToList();

            if (!auctionItems.Any())
            {
                ActionManager.SendReply(context, $"You have no items to auction");
                return;
            }

            if (string.IsNullOrWhiteSpace(context.Args))
            {
                ActionManager.SendReply(context,
                                        $"Usage: !{((Command)context.Source).Name} (reserve price) (partial item name)");
                return;
            }

            var argParts = context.Args.Trim().Split(' ').ToList();

            if (argParts.Count == 1)
            {
                ActionManager.SendReply(context,
                                        $"Usage: !{((Command)context.Source).Name} (reserve price) (partial item name)");
                return;
            }

            if (!int.TryParse(argParts[0], out int reservePrice) || reservePrice < 0)
            {
                ActionManager.SendReply(context, $"Invalid reserve price \"{argParts[0]}\"");
                return;
            }

            string itemName      = context.Args.Substring(argParts[0].Length + 1).Trim();
            var    matchingItems = auctionItems.Where(i => i.GetModifiedItemName()
                                                      .ToString().IndexOf(itemName, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                   .ToList();

            if (matchingItems.Count == 0)
            {
                ActionManager.SendReply(context, $"No items found matching \"{itemName}\"");
                return;
            }
            if (matchingItems.Count > 1)
            {
                ActionManager.SendReply(context, $"{matchingItems.Count} items found matching \"{itemName}\", be more specific");
                return;
            }

            var item = matchingItems.First();

            BLTAdoptAHeroCampaignBehavior.Current.StartItemAuction(item, adoptedHero, reservePrice,
                                                                   settings.AuctionDurationInSeconds, settings.AuctionReminderIntervalInSeconds,
                                                                   s => ActionManager.SendNonReply(context, s));

            ActionManager.SendNonReply(context,
                                       $"Auction of \"{item.GetModifiedItemName()}\" is OPEN! Reserve price is {reservePrice}{Naming.Gold}, " +
                                       $"bidding closes in {settings.AuctionDurationInSeconds} seconds.");
        }