示例#1
0
        //Returns clinet progression for Multiplayer
        public static ClientEnemyProgression GetCP(BoltEntity e)
        {
            ClientEnemyProgression cp = null;

            if (!GameSetup.IsMpClient)
            {
                return(GetCP(e.transform));
            }
            if (e == null)
            {
                return(null);
            }
            if (clinetProgressions.ContainsKey(e))
            {
                cp = clinetProgressions[e];
                if (Time.time <= cp.creationTime + ClientEnemyProgression.LifeTime)
                {
                    if (cp.DynamicOutdated)
                    {
                        cp.RequestDynamicUpdate();
                    }
                    return(cp);
                }
            }
            if (Time.time > scanEnemyLastRequestTimestamp + scanEnemyFrequency)
            {
                using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                {
                    using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                    {
                        w.Write(6);
                        w.Write(e.networkId.PackedValue);
                        w.Close();
                    }
                    Network.NetworkManager.SendLine(answerStream.ToArray(), Network.NetworkManager.Target.OnlyServer);
                    answerStream.Close();
                }
                scanEnemyLastRequestTimestamp = Time.time;
            }

            return(cp);
        }
示例#2
0
        private void DrawHealthBar(ref Rect pos)
        {
            ClientEnemyProgression cp = entity != null?EnemyManager.GetCP(entity) : EnemyManager.GetCP(transform);

            float percentageHP = Mathf.Clamp01(cp.Health / cp.MaxHealth);
            float percentageAR = Mathf.Clamp01(1.0f - (cp.ArmorReduction / cp.Armor));
            Rect  bg           = new Rect(pos.x, pos.y, pos.width, 15f * MainMenu.Instance.screenScale);
            Rect  ar           = new Rect(bg);

            ar.width *= percentageAR;
            ar.height = 3f * MainMenu.Instance.screenScale;
            Rect hp = new Rect(bg);

            hp.width  *= percentageHP;
            hp.y      += ar.height;
            hp.height -= ar.height;
            pos.y     += bg.height - 6f * MainMenu.Instance.screenScale;

            GUI.DrawTexture(bg, bgTex);
            GUI.DrawTexture(ar, arTex);
            GUI.DrawTexture(hp, hpTex);
        }
示例#3
0
        //Returns clinet progression for Singleplayer
        public static ClientEnemyProgression GetCP(Transform tr)
        {
            if (spProgression.ContainsKey(tr.root))
            {
                ClientEnemyProgression cp = spProgression[tr.root];
                if (cp.Health <= 0)
                {
                    spProgression.Remove(tr.root);
                    return(null);
                }
                if (Time.time <= cp.creationTime + ClientEnemyProgression.LifeTime)
                {
                    if (cp.DynamicOutdated)
                    {
                        Debug.Log("Outdated dynamic CP");
                        var e = tr.GetComponentInParent <EnemyProgression>();
                        if (e)
                        {
                            cp.UpdateDynamic(e.HP, e.armor, e.armorReduction, e.DamageTotal);
                        }
                    }
                }
                else
                {
                    Debug.Log("Outdated static CP");
                    var e = tr.GetComponentInParent <EnemyProgression>();
                    if (e)
                    {
                        cp.Update(null, e.enemyName, e.level, e.HP, e.DamageTotal, e.maxHealth, e.bounty, e.armor, e.armorReduction, e.Steadfast, e.abilities.Count > 0 ? e.abilities.Select(x => (int)x).ToArray() : new int[0]);
                    }
                }
                return(cp);
            }
            else
            {
                EnemyProgression p = tr.root.GetComponent <EnemyProgression>();
                if (p == null)
                {
                    p = tr.root.GetComponentInChildren <EnemyProgression>();
                }

                if (p != null)
                {
                    ClientEnemyProgression cpr = new ClientEnemyProgression(tr.root);
                    spProgression.Add(tr.root, cpr);
                    return(cpr);
                }
                else
                {
                    {
                        mutantScriptSetup setup = tr.root.GetComponentInChildren <mutantScriptSetup>();
                        if (setup == null)
                        {
                            setup = tr.root.GetComponent <mutantScriptSetup>();
                        }
                        if (setup != null)
                        {
                            p = setup.health.gameObject.AddComponent <EnemyProgression>();
                            if (p != null)
                            {
                                p.HealthScript = setup.health;
                                p.AIScript     = setup.ai;
                                p.entity       = setup.GetComponent <BoltEntity>();
                                p.setup        = setup;
                            }
                        }
                    }
                }
            }
            return(null);
        }