예제 #1
0
            public Icon(ItemDef itemDef, GenericNotification genericNotification, int index)
            {
                GameObject gameObject = new GameObject("VoteNotification_Icon");

                gameObject.AddComponent <Image>().sprite = Resources.Load <Sprite>(itemDef.pickupIconPath);

                if (gameObject.GetComponent <CanvasRenderer>() == null)
                {
                    gameObject.AddComponent <CanvasRenderer>();
                }

                if (gameObject.GetComponent <RectTransform>() == null)
                {
                    gameObject.AddComponent <RectTransform>();
                }

                gameObject.transform.SetParent(genericNotification.transform);

                gameObject.transform.position = new Vector3(Screen.width / 2, Screen.height / 2, 0) + new Vector3(-128 + index * 128, 128 + 32, 0);

                gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(64, 64);

                this.image = gameObject;
                // this.ItemDef = itemDef;
                // gameObject.GetComponent<RectTransform>().anchoredPosition = new Vector2(Screen.width / 2f, Screen.height / 2f);
            }
예제 #2
0
        /// <summary>
        /// Handles an event from a container content updated.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="indexOfUpdated">The index that was updated.</param>
        /// <param name="updatedItem">The updated item.</param>
        private void OnContainerContentUpdated(IContainerItem container, byte indexOfUpdated, IItem updatedItem)
        {
            if (updatedItem == null)
            {
                return;
            }

            lock (this.internalDictionariesLock)
            {
                if (!this.containersToCreatureIds.ContainsKey(container.UniqueId))
                {
                    return;
                }

                // The request has to be sent this way since the container id may be different for each player.
                foreach (var(containerId, creatureId) in this.containersToCreatureIds[container.UniqueId].ToList())
                {
                    if (!(this.creatureFinder.FindPlayerById(creatureId) is IPlayer player))
                    {
                        continue;
                    }

                    var notification = new GenericNotification(() => player.YieldSingleItem(), new ContainerUpdateItemPacket(indexOfUpdated, containerId, updatedItem));

                    this.scheduler.ScheduleEvent(notification);
                }
            }
        }
예제 #3
0
 private void Awake()
 {
     this.MainCanvas          = RoR2Application.instance.mainCanvas.transform;
     this.Root                = Instantiate(Resources.Load <GameObject>("Prefabs/NotificationPanel2"));
     this.GenericNotification = this.Root.GetComponent <GenericNotification>();
     this.GenericNotification.transform.SetParent(this.MainCanvas);
     this.GenericNotification.iconImage.enabled = false;
 }
예제 #4
0
        public void PopulateTier(ItemTier tier, bool allAvaiable)
        {
            if (selector == null)
            {
                selector = createSelector();
            }
            setSelectorPos(0);
            //List<ItemIndex> tier1 = ItemCatalog.tier1ItemList;
            List <ItemIndex> tierItems = getAvaiableItems(tier);

            if (allAvaiable)
            {
                switch (tier)
                {
                case ItemTier.Tier1:
                    tierItems = RoR2.ItemCatalog.tier1ItemList;
                    break;

                case ItemTier.Tier2:
                    tierItems = RoR2.ItemCatalog.tier2ItemList;
                    break;

                case ItemTier.Tier3:
                    tierItems = RoR2.ItemCatalog.tier3ItemList;
                    break;

                default:
                    break;
                }
            }

            int line      = 0;
            int itemIndex = 0;

            for (int i = 0; i < tierItems.Count; i++)
            {
                ItemDef item = ItemCatalog.GetItemDef(tierItems[i]);
                if (String.IsNullOrEmpty(item.pickupIconPath))
                {
                    return;
                }

                //GenericNotification.gameObject
                IconCA icon = new IconCA(item, GenericNotification, ItemIconSize);
                iconsCA.Add(icon);

                if (i % ItemsInLine == 0)
                {
                    line++;
                    itemIndex = 0;
                }
                int x = (int)(-GenericNotification.GetComponent <RectTransform>().sizeDelta.x / 2 + 20 + itemIndex++ *ItemIconSize);
                int y = (int)(-25 + (-line + 3) * ItemIconSize);

                icon.SetPos(x, y);
            }
        }
예제 #5
0
 private void Awake()
 {
     go           = Instantiate(Resources.Load <GameObject>("Prefabs/NotificationPanel2"));
     notification = go.GetComponent <GenericNotification>();
     notification.transform.SetParent(RoR2Application.instance.mainCanvas.transform);
     notification.iconImage.enabled = false;
     notification.fadeTime          = 0.5f;
     notification.duration          = 20f;
 }
예제 #6
0
        public IconCA(EquipmentDef itemDef, GenericNotification genericNotification, int size)
        {
            Sprite sprite = Resources.Load <Sprite>(itemDef.pickupIconPath);

            GameObject image = ImageOBJ("Commander_Image");

            image.GetComponent <Image>().sprite = sprite;
            image.transform.SetParent(genericNotification.transform);
            image.transform.position = Vector3.zero;
            image.GetComponent <RectTransform>().sizeDelta = new Vector2(size, size);
            this.image        = image;
            this.EquipmentDef = itemDef;
        }
예제 #7
0
        public void setSelectorPos(int itemIndex)
        {
            if (this.selector == null)
            {
                return;
            }

            int line = (int)Mathf.Floor(itemIndex / ItemsInLine);
            int col  = itemIndex % ItemsInLine;
            //Chat.AddMessage(line + " - " + col);

            int x = (int)(-GenericNotification.GetComponent <RectTransform>().sizeDelta.x / 2 + 20 + col * ItemIconSize);
            int y = (int)(-25 + (-line + 2) * ItemIconSize);

            this.selector.GetComponent <RectTransform>().anchoredPosition = new Vector2(x, y);
        }
예제 #8
0
        public void SetSize(float x, float y)
        {
            RectTransform rectTransform = GenericNotification.GetComponent <RectTransform>();
            Vector2       size          = rectTransform.sizeDelta;

            if (!float.IsNaN(x))
            {
                size.x = x;
            }

            if (!float.IsNaN(y))
            {
                size.y = y;
            }

            rectTransform.sizeDelta = size;
        }
예제 #9
0
        /// <summary>
        /// Notifies the requestor player, if any,of this failure.
        /// </summary>
        protected void NotifyOfFailure()
        {
            if (this.Requestor is Player player)
            {
                IEnumerable <IConnection> FindPlayerConnectionFunc()
                {
                    return(this.ConnectionManager.FindByPlayerId(player.Id).YieldSingleItem());
                }

                var notificationArgs = new GenericNotificationArguments(
                    new PlayerWalkCancelPacket(player.Direction),
                    new TextMessagePacket(MessageType.StatusSmall, this.ErrorMessage ?? "Sorry, not possible."));

                var notification = new GenericNotification(this.Logger, FindPlayerConnectionFunc, notificationArgs);

                this.Game.RequestNofitication(notification);
            }
        }
예제 #10
0
        public void SetSize(float x, float y)
        {
            // TODO(kookehs): Figure out how to auto-resize rect transform.
            RectTransform rectTransform = GenericNotification.GetComponent <RectTransform>();
            Vector2       size          = rectTransform.sizeDelta;

            if (!float.IsNaN(x))
            {
                size.x = x;
            }

            if (!float.IsNaN(y))
            {
                size.y = y;
            }

            rectTransform.sizeDelta = size;
        }
예제 #11
0
        /// <summary>
        /// Performs a container close action for a player.
        /// </summary>
        /// <param name="forCreatureId">The id of the creature for which the container is being closed.</param>
        /// <param name="container">The container being closed.</param>
        /// <param name="atPosition">The position of the container being closed, as seen by the player.</param>
        public void CloseContainer(uint forCreatureId, IContainerItem container, byte atPosition)
        {
            container.ThrowIfNull(nameof(container));

            // Check if this creature doesn't have this container open, or it's no longer at the position specified.
            if (!this.IsContainerOpen(container.UniqueId, forCreatureId, out IEnumerable <byte> openPositions) || !openPositions.Contains(atPosition))
            {
                return;
            }

            this.CloseContainerInternal(forCreatureId, container, atPosition);

            if (this.creatureFinder.FindPlayerById(forCreatureId) is IPlayer player)
            {
                var notification = new GenericNotification(() => player.YieldSingleItem(), new ContainerClosePacket(atPosition));

                this.scheduler.ScheduleEvent(notification);
            }
        }
        private void BuildNotification(PickupIndex pickupIndex, RoR2.UI.PingIndicator pingIndicator)
        {
            LocalUser localUser = LocalUserManager.GetFirstLocalUser();

            if (localUser.currentNetworkUser.userName ==
                Util.GetBestMasterName(pingIndicator.pingOwner.GetComponent <CharacterMaster>()))
            {
                if (localUser.userProfile.HasDiscoveredPickup(pickupIndex))
                {
                    PickupDef pickup = PickupCatalog.GetPickupDef(pickupIndex);

                    ItemDef      item     = ItemCatalog.GetItemDef(pickup.itemIndex);
                    EquipmentDef equip    = EquipmentCatalog.GetEquipmentDef(pickup.equipmentIndex);
                    ArtifactDef  artifact = ArtifactCatalog.GetArtifactDef(pickup.artifactIndex);

                    GenericNotification notification = Object
                                                       .Instantiate(Resources.Load <GameObject>("Prefabs/NotificationPanel2"))
                                                       .GetComponent <GenericNotification>();

                    if (item != null)
                    {
                        notification.SetItem(item);
                    }
                    else if (equip != null)
                    {
                        notification.SetEquipment(equip);
                    }
                    else if (artifact != null)
                    {
                        notification.SetArtifact(artifact);
                    }

                    notification.transform.SetParent(RoR2Application.instance.mainCanvas.transform, false);
                    notification.transform.position = new Vector3(notification.transform.position.x + 2, 95, 0);
                }
            }
        }
예제 #13
0
 public void SetSize(Vector2 size)
 {
     GenericNotification.GetComponent <RectTransform>().sizeDelta = size;
 }
예제 #14
0
        public void Execute()
        {
            if (ApplicationDbContext.options != null && !isRunning)
            {
                isRunning = true;
                ApplicationDbContext appDbContext = new ApplicationDbContext(ApplicationDbContext.options);

                try
                {
                    // Load relevant constants from Configration file (appSettings)
                    int    minQuestionsRecommend = ConfigurationManager.Instance.GetValue("MIN_QUESTIONS_RECOMMEND", Consts.MIN_QUESTIONS_RECOMMEND);
                    double maxQuestionRank       = ConfigurationManager.Instance.GetValue("MAX_QUESTION_RANK", Consts.MAX_QUESTION_RANK);
                    double minDaysAfterRejected  = ConfigurationManager.Instance.GetValue("NUM_DAYS_AFTER_REJECTED", Consts.NUM_DAYS_AFTER_REJECTED);

                    // Load relevant candidates (which enabled to send their resume) and solved at least MIN_QUESTIONS_RECOMMEND
                    IEnumerable <CandidateUser> candidates = appDbContext.Set <CandidateUser>()
                                                             .Include("Questions.Question")
                                                             .Where(c => c.AllowSendResume &&
                                                                    c.Questions.Where(q => q.IsDone).Count() >= minQuestionsRecommend);

                    // Load relevant recruiters (which enabled to receive notifications)
                    Dictionary <string, RecruiterUser> recruiters = appDbContext.Set <RecruiterUser>()
                                                                    .Include(r => r.Identity)
                                                                    .Where(r => r.ReceiveNotifications).ToDictionary(r => r.IdentityId, r => r);

                    // Load only OPEN positions which created by recruiters who enabled notifications
                    IEnumerable <Position> positions = appDbContext.Set <Position>()
                                                       .Include(p => p.PositionSkills)
                                                       .Where(p => p.Status == (int)PositionStatus.Opened && recruiters.ContainsKey(p.CreatedBy));


                    // Load recommendations which is relevant to filter users

                    /*
                     * It is uses in order to prevent from sending recommendations to recruiters
                     * about candidates which sent a recommendation already
                     */
                    var recommendations = appDbContext.Set <RecommendationNotification>()
                                          .Where(r => !(r.Approved == false && r.DateResponded.Value.AddDays(minDaysAfterRejected) < DateTime.Now))
                                          .ToLookup(r => r.PositionId, r => r);


                    foreach (Position position in positions)
                    {
                        IEnumerable <PositionSkill> positionSkills = position.PositionSkills;
                        Dictionary <int, double>    matchingNumbersOfCandidates = new Dictionary <int, double>();

                        foreach (CandidateUser candidate in candidates)
                        {
                            bool skipToNextCandidate = false;
                            //if(recommendations.Contains(position.Id))
                            //{

                            //}
                            foreach (RecommendationNotification recommendation in recommendations[position.Id])
                            {
                                if (recommendation.CandidateId == candidate.Id)
                                {
                                    skipToNextCandidate = true;
                                    break;
                                }
                            }
                            if (skipToNextCandidate)
                            {
                                continue;
                            }

                            double matchingNumber = 0;
                            foreach (PositionSkill positionSkill in positionSkills)
                            {
                                double skillGrade       = 0;
                                double maxTotalRank     = 0;
                                double totalRank        = 0;
                                double sumQuestionsRank = 0;

                                // Load questions which done by the candidate, and has at least one skill of this position
                                var relevantQuestions = candidate.Questions.Where(cq => cq.IsDone && cq.Question.Rank > 0);
                                var questionsWithAtLeastOneRelevantSkill = new List <CandidateQuestion>();

                                foreach (CandidateQuestion cq in relevantQuestions)
                                {
                                    if (Utils.ConvertStringIdsToList(cq.Question.TestedSkills).Contains(positionSkill.Id))
                                    {
                                        questionsWithAtLeastOneRelevantSkill.Add(cq);
                                    }
                                }
                                relevantQuestions = questionsWithAtLeastOneRelevantSkill;

                                maxTotalRank = relevantQuestions.Count() * maxQuestionRank;

                                if (maxTotalRank > 0)
                                {
                                    foreach (var relevantQuestion in relevantQuestions)
                                    {
                                        sumQuestionsRank += relevantQuestion.Question.Rank / maxQuestionRank;
                                        totalRank        += relevantQuestion.Question.Rank;
                                    }

                                    skillGrade      = sumQuestionsRank * (totalRank / maxTotalRank) * positionSkill.SkillWeight;
                                    matchingNumber += skillGrade;
                                }
                            }
                            if (matchingNumber > 0)
                            {
                                matchingNumbersOfCandidates.Add(candidate.Id, matchingNumber);
                            }
                        }

                        // Getting the recommended candidate which his matching number is the heighest
                        double max         = 0;
                        int    candidateId = -1;
                        foreach (var matchingNumber in matchingNumbersOfCandidates)
                        {
                            if (matchingNumber.Value > max)
                            {
                                max         = matchingNumber.Value;
                                candidateId = matchingNumber.Key;
                            }
                        }

                        if (candidateId != -1 && recruiters.ContainsKey(position.CreatedBy))
                        {
                            RecruiterUser relevantRecruiter = recruiters[position.CreatedBy];

                            // Update recommentdation table
                            Notification notificiation = new Notification()
                            {
                                Type        = (int)NotificationType.Recommendation,
                                DateCreated = DateTime.Now,
                                IsViewed    = false,
                                Recipent    = relevantRecruiter.IdentityId,
                            };

                            RecommendationNotification recommendation = new RecommendationNotification()
                            {
                                Approved     = null,
                                Notification = notificiation,
                                CandidateId  = candidateId,
                                PositionId   = position.Id,
                            };
                            var otherDbContext = new ApplicationDbContext(ApplicationDbContext.options);
                            new RecommendationNotificationsRepository(otherDbContext).Add(recommendation);
                            otherDbContext.SaveChanges();


                            var genericNotificationToClient = new GenericNotification()
                            {
                                NotificationId = recommendation.Notification.Id,
                                Type           = recommendation.Notification.Type,
                                DateCreated    = recommendation.Notification.DateCreated,
                                IsViewed       = recommendation.Notification.IsViewed,
                                Approved       = recommendation.Approved,
                                CandidateId    = recommendation.CandidateId,
                            };

                            // Send the recommendation
                            NotificationsHub.Notify(relevantRecruiter.Identity.Email, genericNotificationToClient);
                        }

                        //double maxMatchingNumber = matchingNumbersOfCandidates.Values.Max();
                        //int candidateId = matchingNumbersOfCandidates.Where((key, value) => value == maxMatchingNumber).First().Key;
                    }
                }
                catch (Exception)
                {
                    // TODO: write to log
                }
                finally
                {
                    isRunning = false;
                }
            }
        }
예제 #15
0
        public void PopulateEquipment(bool allAvaiable)
        {
            if (selector == null)
            {
                selector = createSelector();
            }
            setSelectorPos(0);
            //List<ItemIndex> tier1 = ItemCatalog.tier1ItemList;
            List <EquipmentIndex> allEquipments     = RoR2.EquipmentCatalog.equipmentList;
            List <PickupIndex>    avaiableEquipment = Run.instance.availableEquipmentDropList;

            int line      = 0;
            int itemIndex = 0;

            if (allAvaiable)
            {
                for (int i = 0; i < allEquipments.Count; i++)
                {
                    EquipmentDef item = EquipmentCatalog.GetEquipmentDef(allEquipments[i]);
                    if (String.IsNullOrEmpty(item.pickupIconPath))
                    {
                        return;
                    }

                    //GenericNotification.gameObject
                    IconCA icon = new IconCA(item, GenericNotification, ItemIconSize);
                    iconsCA.Add(icon);

                    if (i % ItemsInLine == 0)
                    {
                        line++;
                        itemIndex = 0;
                    }
                    int x = (int)(-GenericNotification.GetComponent <RectTransform>().sizeDelta.x / 2 + 20 + itemIndex++ *ItemIconSize);
                    int y = (int)(-25 + (-line + 3) * ItemIconSize);

                    icon.SetPos(x, y);
                }
            }
            else
            {
                for (int i = 0; i < avaiableEquipment.Count; i++)
                {
                    EquipmentDef item = EquipmentCatalog.GetEquipmentDef(avaiableEquipment[i].equipmentIndex);
                    if (String.IsNullOrEmpty(item.pickupIconPath))
                    {
                        return;
                    }

                    //GenericNotification.gameObject
                    IconCA icon = new IconCA(item, GenericNotification, ItemIconSize);
                    iconsCA.Add(icon);

                    if (i % ItemsInLine == 0)
                    {
                        line++;
                        itemIndex = 0;
                    }
                    int x = (int)(-GenericNotification.GetComponent <RectTransform>().sizeDelta.x / 2 + 20 + itemIndex++ *ItemIconSize);
                    int y = (int)(-25 + (-line + 3) * ItemIconSize);

                    icon.SetPos(x, y);
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Executes the operation's logic.
        /// </summary>
        /// <param name="context">A reference to the operation context.</param>
        protected override void Execute(IElevatedOperationContext context)
        {
            // This will eventually come from the character, or fall back.
            var targetLoginLocation = MapConstants.ThaisTempleMark;

            var creationArguments = new PlayerCreationArguments()
            {
                Client   = this.Client,
                Type     = CreatureType.Player,
                Metadata = this.PlayerMetadata,
            };

            if (!(context.CreatureFactory.CreateCreature(creationArguments) is IPlayer player))
            {
                context.Logger.Warning($"Unable to create player instance for {this.PlayerMetadata.Name}, aborting log in.");

                return;
            }

            if (!context.Map.GetTileAt(targetLoginLocation, out ITile targetTile) || !this.PlaceCreature(context, targetTile, player))
            {
                // Unable to place the player in the map.
                context.Scheduler.ScheduleEvent(
                    new GenericNotification(
                        () => player.YieldSingleItem(),
                        new GameServerDisconnectPacket("Your character could not be placed on the map.\nPlease try again, or contact an administrator if the issue persists.")));

                return;
            }

            var(descriptionMetadata, descriptionBytes) = context.MapDescriptor.DescribeAt(player, player.Location);

            // TODO: In addition, we need to send the player's inventory, the first time login message + outfit window here if applicable.
            // And any VIP records here.
            var notification = new GenericNotification(
                () => player.YieldSingleItem(),
                new PlayerLoginPacket(player.Id, player),
                new MapDescriptionPacket(player.Location, descriptionBytes),
                new MagicEffectPacket(player.Location, AnimatedEffect.BubbleBlue),
                new PlayerStatsPacket(player),
                new PlayerSkillsPacket(player),
                new WorldLightPacket(this.CurrentWorldLightLevel, this.CurrentWorldLightColor),
                new CreatureLightPacket(player),
                new TextMessagePacket(MessageType.StatusDefault, "This is a test message"),
                new PlayerConditionsPacket(player));

            if (descriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToLearnMetadataKeyName, out object creatureIdsToLearnBoxed) &&
                descriptionMetadata.TryGetValue(IMapDescriptor.CreatureIdsToForgetMetadataKeyName, out object creatureIdsToForgetBoxed) &&
                creatureIdsToLearnBoxed is IEnumerable <uint> creatureIdsToLearn && creatureIdsToForgetBoxed is IEnumerable <uint> creatureIdsToForget)
            {
                notification.Sent += (client) =>
                {
                    foreach (var creatureId in creatureIdsToLearn)
                    {
                        client.AddKnownCreature(creatureId);
                    }

                    foreach (var creatureId in creatureIdsToForget)
                    {
                        client.RemoveKnownCreature(creatureId);
                    }
                };
            }

            notification.Send(new NotificationContext(context.Logger, context.MapDescriptor, context.CreatureFinder));
        }
예제 #17
0
        private void GenericNotification_SetItem(On.RoR2.UI.GenericNotification.orig_SetItem orig, GenericNotification self, ItemDef itemDef)
        {
            if (itemDef.itemIndex != catalogIndex)
            {
                orig(self, itemDef);
                return;
            }
            var clearCount = Run.instance.stageClearCount;
            var StageCount = Mathf.Max(clearCount + 1, 1);

            string numberString      = HelperUtil.NumbertoOrdinal(StageCount);
            string numberCapitalized = char.ToUpper(numberString[0]) + numberString.Substring(1);
            string descString        = adjustedDesc[Mathf.Clamp(StageCount, 0, adjustedDesc.Length - 1)];

            //https://www.dotnetperls.com/uppercase-first-letter

            //string output2 = numberCapitalized + " Chamber" +
            //"\nThis " + descString + " artifact indicates mastery of the " + numberString + " chamber."; TODO: REMOVE WHEN KNOW IT WORKS
            string output = string.Format(itemPickupDescToken, numberCapitalized, descString, numberString);

            if (bannedStages.Contains(SceneCatalog.mostRecentSceneDef.baseSceneName))
            {
                output = itemPickupDescBannedToken;
            }

            self.titleText.token       = itemDef.nameToken;
            self.titleTMP.color        = ColorCatalog.GetColor(itemDef.colorIndex);
            self.descriptionText.token = output;

            if (itemDef.pickupIconSprite != null)
            {
                self.iconImage.texture = itemDef.pickupIconTexture;
                //var index = Mathf.Max(clearCount, textures.Count-1);
                //self.iconImage.texture = Resources.Load<Texture>(filePaths[index]);
                //self.iconImage.texture = textures[index];
            }
        }