Example #1
0
        private void UpdateTarget()
        {
            var target = m_LinkedCharacter.TargetingSystem.LockedCharacter;

            if (target.UID != m_lastTargetUID)
            {
                m_lastTargetUID = target.UID;
                UpdateOnTargetChange();
            }

            var m_hideUI        = (bool)At.GetValue(typeof(Global), Global.Instance, "m_hideUI");
            var m_playerShowHUD = (bool[])At.GetValue(typeof(OptionManager), null, "m_playerShowHUD");

            if (m_hideUI || !m_playerShowHUD[this.Split_ID])
            {
                DisableHolders();
            }
            else
            {
                UpdateTargetHUD(target);

                if ((bool)CombatHUD.config.GetValue(Settings.EnemyInfobox))
                {
                    UpdateInfobox(target);
                }

                EnableHolders();
            }
        }
Example #2
0
        public static bool Prefix(Weapon __instance, RaycastHit _hit, Vector3 _dir)
        {
            Hitbox hitbox            = _hit.collider.GetComponent <Hitbox>();
            var    owner             = __instance.OwnerCharacter;
            var    target            = hitbox.OwnerChar;
            var    m_alreadyHitChars = At.GetValue(typeof(Weapon), __instance, "m_alreadyHitChars") as List <Character>;

            if (!m_alreadyHitChars.Contains(target) && HookUtil.IsElligable(__instance, owner, target))
            {
                bool  blocked = false;
                float num     = Vector3.Angle(hitbox.OwnerChar.transform.forward, owner.transform.position - hitbox.OwnerChar.transform.position);

                if (!__instance.Unblockable && hitbox.OwnerChar.Blocking && num < (float)(hitbox.OwnerChar.ShieldEquipped ? Weapon.SHIELD_BLOCK_ANGLE : Weapon.BLOCK_ANGLE))
                {
                    blocked = true;
                }
                if (!blocked)
                {
                    var getID = At.GetValue(typeof(Weapon), __instance, "m_attackID");
                    if (getID is int attackID && attackID >= 0)
                    {
                        DamageList damages = __instance.GetDamage(attackID).Clone();

                        target.Stats.GetMitigatedDamage(null, ref damages);

                        DamageLabels.AddDamageLabel(damages, _hit.point, target);
                    }
                }
            }

            return(true);
        }
Example #3
0
        public static bool Prefix(Weapon __instance, Character _hitCharacter, Vector3 _hitPos, Vector3 _dir, bool _blocked)
        {
            Character selfChar = At.GetValue(typeof(Item), __instance as Item, "m_ownerCharacter") as Character;

            if (At.GetValue(typeof(Weapon), __instance as Weapon, "m_alreadyHitChars") is List <Character> alreadyhit)
            {
                bool eligible = _hitCharacter && (_hitCharacter != selfChar) && (__instance.CanHitEveryoneButOwner || selfChar.TargetingSystem.IsTargetable(_hitCharacter));

                if (eligible && !alreadyhit.Contains((Character)_hitCharacter))
                {
                    if (!_blocked)
                    {
                        DamageList damages = __instance.GetDamage(0);
                        _hitCharacter.Stats.GetMitigatedDamage(null, ref damages);

                        DamageLabels.AddDamageLabel(damages, _hitPos, _hitCharacter);
                    }
                    else
                    {
                        // Attack was blocked.
                    }
                }
            }

            return(true);
        }
Example #4
0
        private void UpdateVitalText(Character player)
        {
            CharacterBarListener manager = player.CharacterUI.transform.Find("Canvas/GameplayPanels/HUD/MainCharacterBars").GetComponent <CharacterBarListener>();

            if (manager == null)
            {
                return;
            }                                // OLogger.Error("BarManager is null"); return; }

            if (At.GetValue(typeof(CharacterBarListener), manager, "m_healthBar") is Bar healthBar &&
                At.GetValue(typeof(Bar), healthBar, "m_lblValue") is Text healthText &&
                At.GetValue(typeof(CharacterBarListener), manager, "m_manaBar") is Bar manaBar &&
                At.GetValue(typeof(Bar), manaBar, "m_lblValue") is Text manaText &&
                At.GetValue(typeof(CharacterBarListener), manager, "m_staminaBar") is Bar stamBar &&
                At.GetValue(typeof(Bar), stamBar, "m_lblValue") is Text stamText)
            {
                healthText.fontSize = 14;
                manaText.fontSize   = 14;
                stamText.fontSize   = 14;

                healthBar.TextValueDisplayed = (bool)CombatHUD.config.GetValue(Settings.PlayerVitals);
                manaBar.TextValueDisplayed   = (bool)CombatHUD.config.GetValue(Settings.PlayerVitals);
                stamBar.TextValueDisplayed   = (bool)CombatHUD.config.GetValue(Settings.PlayerVitals);
            }
        }
Example #5
0
        public static void Postfix(PunctualDamage __instance, Character _targetCharacter)
        {
            if (_targetCharacter.Alive)
            {
                if (At.GetValue(typeof(PunctualDamage), __instance, "m_tempList") is DamageList damagelist)
                {
                    DamageList damages = damagelist.Clone();
                    _targetCharacter.Stats.GetMitigatedDamage(null, ref damages);

                    DamageLabels.AddDamageLabel(damages, _targetCharacter.CenterPosition, _targetCharacter);
                }
            }
        }
Example #6
0
        private void UpdateOnTargetChange()
        {
            var target = m_LinkedCharacter.TargetingSystem.LockedCharacter;

            m_infoboxName.text = target.Name;

            // only update status immunities when we change targets.
            List <string> immunityTags = new List <string>();

            var statusNaturalImmunities = At.GetValue(typeof(CharacterStats), target.Stats, "m_statusEffectsNaturalImmunity") as TagSourceSelector[];

            foreach (TagSourceSelector tagSelector in statusNaturalImmunities)
            {
                immunityTags.Add(tagSelector.Tag.TagName);
            }

            var statusImmunities = At.GetValue(typeof(CharacterStats), target.Stats, "m_statusEffectsImmunity") as Dictionary <Tag, List <string> >;

            foreach (KeyValuePair <Tag, List <string> > entry in statusImmunities)
            {
                if (entry.Value.Count > 0)
                {
                    immunityTags.Add(entry.Key.TagName);
                }
            }

            if (immunityTags.Count > 0)
            {
                m_infoboxNoImmuneText.gameObject.SetActive(false);
                float offset = 0f;
                var   pos    = m_infoboxNoImmuneText.rectTransform.position;

                if (immunityTags.Contains("Bleeding"))
                {
                    m_infoboxBleedingSprite.gameObject.SetActive(true);
                    m_infoboxBleedingSprite.rectTransform.position = new Vector3(pos.x, pos.y - 2f, 0);
                    offset += CombatHUD.Rel(22f);
                }
                else
                {
                    m_infoboxBleedingSprite.gameObject.SetActive(false);
                }
                if (immunityTags.Contains("Burning"))
                {
                    m_infoboxBurningSprite.gameObject.SetActive(true);
                    m_infoboxBurningSprite.rectTransform.position = new Vector3(pos.x + offset, pos.y - 2f, 0);
                    offset += CombatHUD.Rel(22f);
                }
                else
                {
                    m_infoboxBurningSprite.gameObject.SetActive(false);
                }
                if (immunityTags.Contains("Poison"))
                {
                    m_infoboxPoisonSprite.gameObject.SetActive(true);
                    m_infoboxPoisonSprite.rectTransform.position = new Vector3(pos.x + offset, pos.y - 2f, 0);
                }
                else
                {
                    m_infoboxPoisonSprite.gameObject.SetActive(false);
                }
            }
            else
            {
                m_infoboxNoImmuneText.gameObject.SetActive(true);

                m_infoboxBurningSprite.gameObject.SetActive(false);
                m_infoboxBleedingSprite.gameObject.SetActive(false);
                m_infoboxPoisonSprite.gameObject.SetActive(false);
            }
        }
Example #7
0
        private void UpdateStatuses(Character target)
        {
            // update status icons
            float offset         = 0f;
            float offsetInterval = CombatHUD.Rel(30f, true);

            var barPos = RectTransformUtility.WorldToScreenPoint(m_LinkedCharacter.CharacterCamera.CameraScript, target.UIBarPosition);
            var pos    = barPos + new Vector2(CombatHUD.Rel(225f), 0);

            for (int i = 0; i < m_StatusHolder.transform.childCount; i++)
            {
                var    obj        = m_StatusHolder.transform.GetChild(i).gameObject;
                string identifier = obj.name;
                var    status     = target.StatusEffectMngr.Statuses.Find(x => x.IdentifierName == identifier);

                if (!status)
                {
                    obj.SetActive(false);
                }
                else
                {
                    var parentRect = obj.GetComponent <RectTransform>();
                    parentRect.position = new Vector3(pos.x, pos.y + offset);

                    var text = parentRect.transform.Find("Text").GetComponent <Text>();

                    if ((bool)CombatHUD.config.GetValue(Settings.EnemyStatusTimers))
                    {
                        TimeSpan t = TimeSpan.FromSeconds(status.RemainingLifespan);
                        var      s = string.Format("{0}:{1}", t.Minutes, t.Seconds.ToString("00"));
                        text.text  = s;
                        text.color = Color.white;

                        if (!text.gameObject.activeSelf)
                        {
                            text.gameObject.SetActive(true);
                        }
                        if (!obj.activeSelf)
                        {
                            obj.SetActive(true);
                        }

                        offset -= offsetInterval;
                    }
                    else if (text.gameObject.activeSelf)
                    {
                        text.gameObject.SetActive(false);
                    }
                }
            }

            // buildups
            if ((bool)CombatHUD.config.GetValue(Settings.EnemyBuildup))
            {
                var         m_statusBuildup = At.GetValue(typeof(StatusEffectManager), target.StatusEffectMngr, "m_statusBuildUp") as IDictionary;
                IDictionary dict            = m_statusBuildup as IDictionary;
                FieldInfo   buildupField    = m_statusBuildup.GetType().GetGenericArguments()[1].GetField("BuildUp");

                foreach (string name in dict.Keys)
                {
                    //GameObject holder = null;
                    if (m_StatusHolder.transform.Find(name) is Transform t)
                    {
                        var holder = t.gameObject;
                        if (holder.activeSelf)
                        {
                            // status is already active (ie. its 100%)
                            continue;
                        }

                        float value = (float)buildupField.GetValue(dict[name]);

                        if (value > 0 && value < 100)
                        {
                            var parentRect = holder.GetComponent <RectTransform>();
                            parentRect.position = new Vector3(pos.x, pos.y + offset);
                            offset -= offsetInterval;

                            var text = holder.GetComponentInChildren <Text>();
                            text.text  = Math.Round(value) + "%";
                            text.color = new Color(1.0f, 0.5f, 0.5f, value * 0.01f + 0.25f);

                            if (!holder.activeSelf)
                            {
                                holder.SetActive(true);
                            }
                        }
                    }
                }
            }
        }
        internal void Update()
        {
            //cleanup dead labels first
            var maxLifespan = (float)CombatHUD.config.GetValue(Settings.LabelLifespan);

            for (int z = 0; z < ActiveLabels.Count; z++)
            {
                if (Time.time - ActiveLabels[z].CreationTime > maxLifespan || !ActiveLabels[z].Target)
                {
                    ActiveLabels.RemoveAt(z);
                    z--;
                }
            }

            float ceiling = (float)CombatHUD.config.GetValue(Settings.DamageCeiling);
            int   minsize = (int)(float)CombatHUD.config.GetValue(Settings.MinFontSize);
            int   maxsize = (int)(float)CombatHUD.config.GetValue(Settings.MaxFontSize);

            if (maxsize < minsize)
            {
                maxsize = minsize;
            }

            var m_hideUI        = (bool)At.GetValue(typeof(Global), Global.Instance, "m_hideUI");
            var m_playerShowHUD = (bool[])At.GetValue(typeof(OptionManager), null, "m_playerShowHUD");

            for (int i = 0; i < SplitScreenManager.Instance.LocalPlayerCount; i++)
            {
                var player = SplitScreenManager.Instance.LocalPlayers[i];

                if (!player.AssignedCharacter)
                {
                    continue;
                }

                // dont show damage labels if player is in menu
                bool disable = false;
                if (m_hideUI || !m_playerShowHUD[i] || MenuManager.Instance.IsMapDisplayed ||
                    (player.AssignedCharacter.CharacterUI.GetCurrentMenu() is MenuPanel panel && panel.IsDisplayed))
                {
                    disable = true;
                }

                var camera = player.CameraScript;
                int offset = i * 30;

                for (int j = 0 + offset; j < LabelHolders.Count; j++)
                {
                    if (disable || j - offset >= ActiveLabels.Count)
                    {
                        if (LabelHolders[j].activeSelf)
                        {
                            LabelHolders[j].SetActive(false);
                        }
                    }
                    else
                    {
                        var labelInfo   = ActiveLabels[j - offset];
                        var labelHolder = LabelHolders[j];

                        var pos = (bool)CombatHUD.config.GetValue(Settings.LabelsStayAtHitPos) ? labelInfo.HitWorldPos : labelInfo.Target.CenterPosition;

                        float damageStrength = (float)((decimal)labelInfo.Damage / (decimal)ceiling); // set damage "strength"
                        float time           = Time.time - labelInfo.CreationTime;
                        var   timeOffset     = Mathf.Lerp(0.3f, 0.07f, damageStrength) * time;

                        var   screenPos = camera.WorldToViewportPoint(pos + new Vector3(0, timeOffset));
                        float distance  = Vector3.Distance(player.AssignedCharacter.transform.position, pos);

                        if (IsScreenPosVisible(ref screenPos, i) && distance < (float)CombatHUD.config.GetValue(Settings.MaxDistance))
                        {
                            screenPos += new Vector3
                                         (
                                CombatHUD.Rel(labelInfo.ranXpos),
                                CombatHUD.Rel(labelInfo.ranYpos, true)
                                         );

                            labelHolder.GetComponent <RectTransform>().position = screenPos;

                            var text = labelHolder.GetComponent <Text>();
                            text.text     = Math.Round(labelInfo.Damage).ToString();
                            text.fontSize = (int)Mathf.Lerp(minsize, maxsize, damageStrength);
                            text.color    = labelInfo.TextColor;

                            if (!LabelHolders[j].activeSelf)
                            {
                                LabelHolders[j].SetActive(true);
                            }
                        }
                        else if (LabelHolders[j].activeSelf)
                        {
                            LabelHolders[j].SetActive(false);
                        }
                    }
                }
            }
        }
Example #9
0
        internal void Update()
        {
            if (NetworkLevelLoader.Instance.IsGameplayLoading || NetworkLevelLoader.Instance.IsGameplayPaused)
            {
                if (!wasInMenu)
                {
                    for (int i = 0; i < m_labelHolders.Count; i++)
                    {
                        if (m_labelHolders[i].activeSelf)
                        {
                            m_labelHolders[i].SetActive(false);
                        }
                    }
                    wasInMenu = true;
                }

                return;
            }

            wasInMenu = false;

            List <StatusEffectInfo> statusInfos = new List <StatusEffectInfo>();

            var m_hideUI        = (bool)At.GetValue(typeof(Global), Global.Instance, "m_hideUI");
            var m_playerShowHUD = (bool[])At.GetValue(typeof(OptionManager), null, "m_playerShowHUD");

            for (int i = 0; i < SplitScreenManager.Instance.LocalPlayers.Count; i++)
            {
                var player = SplitScreenManager.Instance.LocalPlayers[i].AssignedCharacter;

                if (player == null || !m_playerShowHUD[i] || m_hideUI)
                {
                    continue;
                }

                UpdateVitalText(player);

                if ((bool)CombatHUD.config.GetValue(Settings.PlayerStatusTimers))
                {
                    try
                    {
                        UpdatePlayerStatuses(i, ref statusInfos);
                    }
                    catch //(Exception e)
                    {
                        //Debug.LogError("Error updating statuses: " + e.Message);
                    }
                }
            }

            // update text holders
            for (int i = 0; i < m_labelHolders.Count; i++)
            {
                if (i >= statusInfos.Count || !(bool)CombatHUD.config.GetValue(Settings.PlayerStatusTimers))
                {
                    if (m_labelHolders[i].activeSelf)
                    {
                        m_labelHolders[i].SetActive(false);
                    }
                }
                else
                {
                    var text = m_labelHolders[i].GetComponent <Text>();

                    var iconRect  = statusInfos[i].LinkedIcon.RectTransform;
                    var posOffset = new Vector3(0, CombatHUD.Rel(25f, true), 0);
                    text.GetComponent <RectTransform>().position = iconRect.position + posOffset;

                    TimeSpan t = TimeSpan.FromSeconds(statusInfos[i].TimeRemaining);
                    text.text = t.Minutes + ":" + t.Seconds.ToString("00");

                    if (statusInfos[i].TimeRemaining < 15)
                    {
                        text.color = Color.red;
                    }
                    else
                    {
                        text.color = Color.white;
                    }
                    if (!m_labelHolders[i].activeSelf)
                    {
                        m_labelHolders[i].SetActive(true);
                    }
                }
            }
        }
Example #10
0
        private void UpdatePlayerStatuses(int splitID, ref List <StatusEffectInfo> statusInfos)
        {
            var player = SplitScreenManager.Instance.LocalPlayers[splitID];

            if (player == null || player.AssignedCharacter == null)
            {
                return;
            }

            var effectsManager = player.AssignedCharacter.StatusEffectMngr;
            var panel          = player.CharUI.GetComponentInChildren <StatusEffectPanel>();

            if (!panel || !effectsManager)
            {
                Debug.LogError("Could not find status effect managers for " + player.AssignedCharacter.Name);
                return;
            }

            var activeIcons = At.GetValue(typeof(StatusEffectPanel), panel, "m_statusIcons") as Dictionary <string, StatusEffectIcon>;

            foreach (KeyValuePair <string, StatusEffectIcon> entry in activeIcons)
            {
                if (!entry.Value.gameObject.activeSelf)
                {
                    continue;
                }

                float remainingLifespan = 0f;

                StatusEffect status = effectsManager.Statuses.Find(s => s.IdentifierName == entry.Key);
                if (status)
                {
                    remainingLifespan = status.RemainingLifespan;
                }
                else
                {
                    // some statuses use an identifier tag instead of their own status name for the icon...
                    switch (entry.Key.ToLower())
                    {
                    case "imbuemainweapon":
                        remainingLifespan = (panel as UIElement).LocalCharacter.CurrentWeapon.FirstImbue.RemainingLifespan;
                        break;

                    case "imbueoffweapon":
                        remainingLifespan = (panel as UIElement).LocalCharacter.LeftHandWeapon.FirstImbue.RemainingLifespan;
                        break;

                    case "summonweapon":
                        remainingLifespan = (panel as UIElement).LocalCharacter.CurrentWeapon.SummonedEquipment.RemainingLifespan;
                        break;

                    case "summonghost":
                        remainingLifespan = (panel as UIElement).LocalCharacter.CurrentSummon.RemainingLifespan;
                        break;

                    case "129":     // marsh poison uses "129" for its tag, I think that's its effect preset ID?
                        if (effectsManager.Statuses.Find(z => z.IdentifierName.Equals("Hallowed Marsh Poison Lvl1")) is StatusEffect marshpoison)
                        {
                            remainingLifespan = marshpoison.RemainingLifespan;
                        }
                        break;

                    default:
                        //Debug.Log("[CombatHUD] Unhandled Status Identifier! Key: " + entry.Key);
                        continue;
                    }
                }

                if (remainingLifespan > 0f && entry.Value != null)
                {
                    statusInfos.Add(new StatusEffectInfo
                    {
                        TimeRemaining = remainingLifespan,
                        LinkedIcon    = entry.Value
                    });
                }
            }
        }