Beispiel #1
0
 public static void Effect()
 {
     if (!active)
     {
         return;
     }
     LocalPlayer.Stats.Energy  = ModdedPlayer.Stats.TotalMaxEnergy;
     LocalPlayer.Stats.Stamina = LocalPlayer.Stats.Energy;
     if (ModdedPlayer.Stats.i_setcount_BerserkSet >= 4)
     {
         float timeSpan = Time.time - castTimestamp;
         int   bonus    = Mathf.CeilToInt(timeSpan);
         if (bonus > setbonusAmount)
         {
             setbonusAmount = bonus;
             float buff = 0.35f * bonus + 1;
             BuffDB.ForceEndBuff(106);
             BuffDB.AddBuff(9, 106, buff, 3f);
             if (ModdedPlayer.Stats.i_setcount_BerserkSet >= 5)
             {
                 if (bonus <= 15)
                 {
                     BuffDB.ForceEndBuff(107);
                 }
                 BuffDB.AddBuff(14, 107, 0.3f * bonus, ModdedPlayer.Stats.spell_berserkDuration - bonus);
             }
         }
     }
 }
Beispiel #2
0
        private static void PurgeLocalPlayer(bool heal, bool bonusDamage)
        {
            int[] keys = BuffDB.activeBuffs.Keys.ToArray();
            int   a    = heal ? 1 : 0;

            for (int i = 0; i < keys.Length; i++)
            {
                if (BuffDB.activeBuffs[keys[i]].isNegative)
                {
                    BuffDB.activeBuffs[keys[i]].ForceEndBuff(keys[i]);
                }
            }

            ModdedPlayer.instance.StunDuration = 0;
            ModdedPlayer.instance.RootDuration = 0;
            BuffDB.AddBuff(7, 98, 1, 3f);

            if (heal)
            {
                float healAmount = (ModdedPlayer.Stats.TotalMaxHealth - LocalPlayer.Stats.Health);
                if (bonusDamage)
                {
                    float buffAmount = 1 + (healAmount / ModdedPlayer.Stats.TotalMaxHealth) * 3;
                    BuffDB.AddBuff(9, 90, buffAmount, 6.5f);
                }
                healAmount *= 0.4f * ModdedPlayer.Stats.allRecoveryMult;
                LocalPlayer.Stats.Health       += healAmount;
                LocalPlayer.Stats.HealthTarget += healAmount;
                LocalPlayer.Stats.Energy       += (ModdedPlayer.Stats.TotalMaxEnergy - LocalPlayer.Stats.Energy) * 0.5f;
            }
        }
Beispiel #3
0
        private void Update()
        {
            if (gameObject.layer != DesiredLayer)
            {
                gameObject.layer = DesiredLayer;
            }

            if (effectReady)
            {
                lifetime += Time.deltaTime;
                if (duration < lifetime)
                {
                    Pause();
                }

                if ((LocalPlayer.Transform.position - transform.position).sqrMagnitude < effectRadius * effectRadius)
                {
                    if (fromEnemy)
                    {
                        LocalPlayer.Stats.HealthChange(-damageAmount * Time.deltaTime * (ModdedPlayer.Stats.magicDamageTaken) * ModdedPlayer.Stats.allDamageTaken);
                        BuffDB.AddBuff(1, 5, slowAmount, 20);
                        LocalPlayer.Stats.Burn();
                    }
                    else
                    {
                        LocalPlayer.Stats.Health       += healAmount * Time.deltaTime;
                        LocalPlayer.Stats.HealthTarget += healAmount * 1.5f * Time.deltaTime;
                        BuffDB.AddBuff(5, 6, boostAmount, 30);
                        BuffDB.AddBuff(26, 94, 0.5f, 10);
                    }
                }
            }
        }
Beispiel #4
0
        private void OnTriggerEnter(Collider other)
        {
            float distance = Vector3.Distance(LocalPlayer.Transform.position, this.transform.position);

            if (distance < 100)
            {
                soundEmitter.PlayExplosionSound();
                LocalPlayer.HitReactions.enableFootShake(1, Math.Min(30 / distance, 0.5f));
            }
            if (other.CompareTag("suitCase") || other.CompareTag("metalProp") || other.CompareTag("animalCollide") ||
                other.CompareTag("Fish") || other.CompareTag("Tree") || other.CompareTag("MidTree") ||
                other.CompareTag("suitCase") || other.CompareTag("SmallTree"))
            {
                other.SendMessage("Hit", Damage, SendMessageOptions.DontRequireReceiver);
                other.SendMessage("Explosion", 0.1f, SendMessageOptions.DontRequireReceiver);
            }
            else if (other.transform.root == LocalPlayer.Transform.root)
            {
                LocalPlayer.Stats.Hit(Damage, false, PlayerStats.DamageType.Fire);
                ModdedPlayer.instance.Stun(3f);
                BuffDB.AddBuff(21, 69, Damage / 3, 60);
                other.SendMessage("Burn", SendMessageOptions.DontRequireReceiver);
            }
            else if (other.CompareTag("BreakableWood") || other.CompareTag("BreakableRock") || other.CompareTag("BreakableRock") || other.CompareTag("structure"))
            {
                other.SendMessage("Hit", Damage, SendMessageOptions.DontRequireReceiver);
                other.SendMessage("LocalizedHit", new LocalizedHitData(transform.position, Damage), SendMessageOptions.DontRequireReceiver);
            }
        }
 public IEnumerator DoAction()
 {
     while (true)
     {
         RaycastHit[] hits = Physics.BoxCastAll(transform.position, Vector3.one * 0.5f, transform.forward, transform.rotation, 50);
         foreach (RaycastHit hit in hits)
         {
             if (hit.transform != null)
             {
                 if (hit.transform.CompareTag("Player") || hit.transform.CompareTag("PlayerNet"))
                 {
                     if (hit.transform.root == LocalPlayer.Transform.root)
                     {
                         LocalPlayer.Stats.Hit((int)(dmg * 0.3f * (1 - ModdedPlayer.instance.MagicResistance)), false, PlayerStats.DamageType.Fire);
                         BuffDB.AddBuff(10, 67, 0.5f, 15);
                         BuffDB.AddBuff(2, 66, 0.5f, 15);
                         BuffDB.AddBuff(3, 68, dmg / 13, 5);
                         hit.transform.SendMessage("Burn", SendMessageOptions.DontRequireReceiver);
                     }
                 }
                 else if (hit.transform.CompareTag("structure"))// && (!BoltNetwork.isRunning || BoltNetwork.isServer || !BoltNetwork.isClient || !PlayerPreferences.NoDestructionRemote))
                 {
                     hit.transform.SendMessage("Hit", dmg / 2, SendMessageOptions.DontRequireReceiver);
                     hit.transform.SendMessage("LocalizedHit", new LocalizedHitData(hit.point, dmg / 2), SendMessageOptions.DontRequireReceiver);
                 }
             }
         }
         yield return(new WaitForSeconds(0.1f));
     }
 }
Beispiel #6
0
        private void SendHitFromEnemy()
        {
            float sqrMagnitude = (LocalPlayer.Transform.position - transform.position).sqrMagnitude;

            if (sqrMagnitude < radius * radius)
            {
                int dmg = (int)(damage * (1 - ModdedPlayer.Stats.magicDamageTaken));

                if (isArcane)
                {
                    //negative armor
                    BuffDB.AddBuff(21, 63, -dmg * 2, 30);
                    BuffDB.AddBuff(1, 64, 0.2f, 10);
                    BuffDB.AddBuff(2, 65, 0.2f, 10);
                    dmg *= 2;
                }
                else
                {
                    BuffDB.AddBuff(1, 64, 0.7f, 6);
                    BuffDB.AddBuff(2, 65, 0.7f, 6);
                    LocalPlayer.Stats.Burn();
                }
                LocalPlayer.Stats.Hit((int)(dmg * (1 - ModdedPlayer.Stats.magicDamageTaken)), false, PlayerStats.DamageType.Drowning);
            }
        }
        protected override void CheckDeath()
        {
            if (Cheats.GodMode)
            {
                return;
            }
            if (this.Health <= 0f && !this.Dead)
            {
                COTFEvents.Instance.OnTakeLethalDamage.Invoke();
            }
            if (this.Health <= 0f && !this.Dead)
            {
                if (ModdedPlayer.Stats.perk_nearDeathExperienceUnlocked && !ModdedPlayer.Stats.perk_nearDeathExperienceTriggered)
                {
                    Health = ModdedPlayer.Stats.TotalMaxHealth;
                    BuffDB.AddBuff(20, 61, 0, 600);
                    BuffDB.AddBuff(6, 82, 1, 10);
                    BuffDB.AddBuff(26, 83, 0.1f, 10);                           //90% damage reduction
                    BuffDB.AddBuff(25, 99, 35, 10);                             //+35 hp/s
                    BuffDB.AddBuff(11, 100, 10, 10);                            //+10 ep/s
                    return;
                }



                if (LocalPlayer.AnimControl.swimming)
                {
                    COTFEvents.Instance.OnDeath.Invoke();
                    switch (ModSettings.dropsOnDeath)
                    {
                    case ModSettings.DropsOnDeathMode.All:
                        Inventory.Instance.DropAll();
                        break;

                    case ModSettings.DropsOnDeathMode.Equipped:
                        Inventory.Instance.DropEquipped();
                        break;

                    case ModSettings.DropsOnDeathMode.NonEquipped:
                        Inventory.Instance.DropNonEquipped();
                        break;
                    }
                    this.DeathInWater(0);
                    return;
                }

                this.Dead           = true;
                this.Player.enabled = false;
                if (ModSettings.killOnDowned)
                {
                    TheForest.Save.PlayerRespawnMP.KillPlayer();
                }
                else
                {
                    this.FallDownDead();
                }
            }
        }
Beispiel #8
0
 public static void OnDisable()
 {
     active = false;
     ModdedPlayer.Stats.attackSpeed.Divide(1.25f);
     ModdedPlayer.Stats.allDamage.Divide(1.25f);
     ModdedPlayer.Stats.movementSpeed.Divide(1.35f);
     ModdedPlayer.Stats.allDamageTaken.Divide(5f);
     BuffDB.AddBuff(18, 51, LocalPlayer.Stats.Energy, 15);
 }
 public static void OnDisable()
 {
     active = false;
     ModdedPlayer.instance.AttackSpeedMult  /= 1.2f;
     ModdedPlayer.instance.DamageOutputMult /= 1.2f;
     ModdedPlayer.instance.MoveSpeedMult    /= 1.3f;
     ModdedPlayer.instance.DamageReduction  /= 2f;
     BuffDB.AddBuff(18, 51, LocalPlayer.Stats.Energy, 20);
 }
        protected override void fireProjectile()
        {
            if (ModdedPlayer.instance.IsSmokeysQuiver)
            {
                BuffDB.AddBuff(14, 81, 2.5f, 8);
            }

            StartCoroutine(RCoroutines.i.AsyncCrossbowFire(_ammoId, _ammoSpawnPosGo, _boltProjectile, this));
        }
Beispiel #11
0
 private void Update()
 {
     transform.position = followTarget.position;                                                 //copies position of the caster
     transform.Rotate(Vector3.up * 720 * Time.deltaTime, Space.World);                           //rotates
     if ((LocalPlayer.Transform.position - transform.position).sqrMagnitude < _radius * _radius) //if player is in range, slows him
     {
         BuffDB.AddBuff(1, 30, 0.6f, 5);
         BuffDB.AddBuff(2, 31, 0.6f, 5);
     }
 }
        protected override void fireProjectile()
        {
            if (ModdedPlayer.Stats.i_SmokeyCrossbowQuiver.value)
            {
                BuffDB.AddBuff(14, 81, 2.5f, 8);
            }
            COTFEvents.Instance.OnAttackRanged.Invoke();
            COTFEvents.Instance.OnAttackRangedCrossbow.Invoke();

            StartCoroutine(RCoroutines.i.AsyncCrossbowFire(_ammoId, _ammoSpawnPosGo, _boltProjectile, this));
        }
Beispiel #13
0
 private void Update()
 {
     if ((LocalPlayer.Transform.position - transform.position).sqrMagnitude < radius * radius)
     {
         LocalPlayer.Stats.HealthTarget += healing * Time.deltaTime;
         LocalPlayer.Stats.Health       += healing * Time.deltaTime;
         if (GrantImmunity)
         {
             BuffDB.AddBuff(4, 40, 0, 0.1f);
         }
     }
 }
Beispiel #14
0
 public static void GiveEffect(float speed, float damage, bool giveEffect2, bool giveEffect3, int ArmorAmount = 1)
 {
     BuffDB.AddBuff(5, 45, speed, 120);
     BuffDB.AddBuff(14, 46, speed, 120);
     if (giveEffect2)
     {
         BuffDB.AddBuff(9, 47, damage, 120);
     }
     if (giveEffect3)
     {
         BuffDB.AddBuff(15, 48, ArmorAmount, 120);
     }
 }
Beispiel #15
0
 public static void GiveEffect(bool giveEffect2, bool giveEffect3, int ArmorAmount = 1)
 {
     BuffDB.AddBuff(5, 45, 1.25f, 120);
     BuffDB.AddBuff(14, 46, 1.25f, 120);
     if (giveEffect2)
     {
         BuffDB.AddBuff(9, 47, 1.25f, 120);
     }
     if (giveEffect3)
     {
         BuffDB.AddBuff(15, 48, ArmorAmount, 120);
     }
 }
Beispiel #16
0
 private void Update()
 {
     if (IsOn)
     {
         SpellCaster.RemoveStamina(Cost * Time.deltaTime);
         if (LocalPlayer.Stats.Stamina < 10)
         {
             Toggle();
         }
         if (GiveDamageBuff)
         {
             BuffDB.AddBuff(13, 44, 1.1f, 0.1f);
         }
     }
 }
        public override void Hit(int damage, bool ignoreArmor, DamageType type)
        {
            var hitEventContext = new COTFEvents.GotHitParams(damage, ignoreArmor);

            COTFEvents.Instance.OnGetHit.Invoke(hitEventContext);
            if (type == DamageType.Physical)
            {
                COTFEvents.Instance.OnGetHitPhysical.Invoke(hitEventContext);

                if (UnityEngine.Random.value > ModdedPlayer.Stats.getHitChance)
                {
                    COTFEvents.Instance.OnDodge.Invoke();
                    if (ModdedPlayer.Stats.i_isWindArmor)
                    {
                        //grant buffs;
                        BuffDB.AddBuff(5, 84, 1.2f, 30);
                        BuffDB.AddBuff(9, 85, 1.35f, 10);
                        BuffDB.AddBuff(15, 86, 2000, 10);
                        HealthTarget += ModdedPlayer.Stats.TotalMaxHealth * 0.05f;
                    }
                    Sfx.PlayWhoosh();
                    return;
                }
            }
            else
            {
                COTFEvents.Instance.OnGetHitNonPhysical.Invoke(hitEventContext);
            }
            float f = damage * ModdedPlayer.Stats.allDamageTaken;

            if (!ignoreArmor)
            {
                f *= 1 - ModReferences.DamageReduction(Mathf.Max(0, ModdedPlayer.Stats.armor - (int)ModdedPlayer.instance.lostArmor));
            }
            if (type == DamageType.Fire)
            {
                f *= 0.01f * ModdedPlayer.Stats.TotalMaxHealth;
                f *= UnityEngine.Random.Range(0.9f, 1.4f);
                //f *= 1-ModdedPlayer.Stats.magicDamageTaken;
                f *= ModdedPlayer.Stats.fireDamageTaken;
            }
            if (ModdedPlayer.Stats.i_KingQruiesSword)
            {
                BuffDB.AddBuff(22, 80, f, 1);
            }
            CotfUtils.Log("Tanked damage: " + f, true);
            base.Hit(damage, ignoreArmor, type);
        }
Beispiel #18
0
        protected override void CheckDeath()
        {
            if (global::Cheats.GodMode)
            {
                return;
            }
            if (this.Health <= 0f && !this.Dead)
            {
                if (ModdedPlayer.instance.NearDeathExperienceUnlocked && !ModdedPlayer.instance.NearDeathExperience)
                {
                    Health = ModdedPlayer.instance.MaxHealth;
                    BuffDB.AddBuff(20, 61, 0, 600);
                    BuffDB.AddBuff(6, 82, 0, 10);
                    BuffDB.AddBuff(26, 83, 0, 10);
                    return;
                }

                switch (ModSettings.dropsOnDeath)
                {
                case ModSettings.DropsOnDeathMode.All:
                    Inventory.Instance.DropAll();
                    break;

                case ModSettings.DropsOnDeathMode.Equipped:
                    Inventory.Instance.DropEquipped();
                    break;
                }

                if (TheForest.Utils.LocalPlayer.AnimControl.swimming)
                {
                    this.DeathInWater(0);
                    return;
                }

                this.Dead           = true;
                this.Player.enabled = false;
                if (ModSettings.killOnDowned)
                {
                    TheForest.Save.PlayerRespawnMP.KillPlayer();
                }
                else
                {
                    this.FallDownDead();
                }
            }
        }
Beispiel #19
0
 public static void Init()
 {
     TwitchMod.Register("randomitem", s => ChampionsOfForest.Network.NetworkManager.SendItemDrop(ItemDataBase.GetRandomItem(Random.value * 2000), LocalPlayer.Transform.position + Vector3.up * 3f));
     TwitchMod.Register("buff", s =>
     {
         int r = Random.Range(0, positiveBuffs.Length);
         BuffDB.AddBuff(positiveBuffs[r], 90000, positiveBuffs_amounts[r], 10);
     });
     TwitchMod.Register("debuff", s =>
     {
         int r = Random.Range(0, negativeBuffs.Length);
         BuffDB.AddBuff(negativeBuffs[r], 90001, negativeBuffs_amounts[r], 10);
     });
     TwitchMod.Register("meteors", s => Meteor.CreateEnemy(LocalPlayer.Transform.position, Random.Range(0, 1000000)));
     TwitchMod.Register("laser", s => EnemyLaser.CreateLaser(LocalPlayer.Transform.position - LocalPlayer.Transform.forward * 10, LocalPlayer.Transform.forward));
     TwitchMod.Register("cataclysm", s => Cataclysm.Create(LocalPlayer.Transform.position, 7, 100, 5, Cataclysm.TornadoType.Fire, true));
 }
Beispiel #20
0
 public static void ResistDeath()
 {
     if (ResistDeathTimeStamp < Time.time)
     {
         if (ResistDeathTimeStamp + 60 <= Time.time)
         {
             ResistDeathTimeStamp     = Time.time;
             LocalPlayer.Stats.Health = ModdedPlayer.Stats.TotalMaxHealth;
             BuffDB.AddBuff(6, 82, 1, 5);
             BuffDB.AddBuff(26, 108, 0.02f, 5);                     //98% damage reduction
             BuffDB.AddBuff(25, 99, 35, 5);                         //+35 hp/s
         }
     }
     else
     {
         ResistDeathTimeStamp = 0;
     }
 }
Beispiel #21
0
        private void Update()
        {
            if (isOn)
            {
                if ((LocalPlayer.Transform.position - transform.position).sqrMagnitude < 49)
                {
                    float dmgPerTick = Time.deltaTime * damage * ModdedPlayer.Stats.allDamageTaken * ModdedPlayer.Stats.magicDamageTaken * ModReferences.DamageReduction((int)ModdedPlayer.Stats.TotalArmor);

                    if (LocalPlayer.Stats.Health - 1 > dmgPerTick)
                    {
                        LocalPlayer.Stats.Health -= dmgPerTick;
                    }

                    BuffDB.AddBuff(10, 72, 0.7f, 5);
                    BuffDB.AddBuff(21, 73, Time.deltaTime * damage / 30, 15);
                }
            }
        }
Beispiel #22
0
 private void Update()
 {
     transform.position = followTarget.position;                                                     //copies position of the caster
     transform.Rotate(Vector3.up * 720 * Time.deltaTime, Space.World);                               //rotates
     if ((LocalPlayer.Transform.position - transform.position).sqrMagnitude < _radius * _radius)     //if player is in range, slows him
     {
         if (ModdedPlayer.Stats.perk_blizzardSlowReduced)
         {
             BuffDB.AddBuff(1, 30, 0.8f, 1);
             BuffDB.AddBuff(2, 31, 0.9f, 1);
             BuffDB.AddBuff(21, 70, armorReduction * Time.deltaTime / 2, 10);
         }
         else
         {
             BuffDB.AddBuff(1, 30, 0.5f, 6);
             BuffDB.AddBuff(2, 31, 0.25f, 6);
             BuffDB.AddBuff(21, 70, armorReduction * Time.deltaTime, 20);
         }
     }
 }
Beispiel #23
0
        private void Update()
        {
            timeShift           += Time.deltaTime * 2.3f;
            transform.localScale = Vector3.one * (radius + Mathf.Sin(timeShift * 3.14f * 4f));

            if ((LocalPlayer.Transform.position - transform.position).sqrMagnitude < radius * radius)
            {
                LocalPlayer.Stats.HealthTarget += healing * Time.deltaTime;
                LocalPlayer.Stats.Health       += healing * Time.deltaTime;
                if (GrantImmunity)
                {
                    BuffDB.AddBuff(4, 40002, 0, 3f);
                    BuffDB.AddBuff(6, 40001, 0, 3f);
                }
                if (regenEnergy)
                {
                    LocalPlayer.Stats.Energy += healing * Time.deltaTime / 10;
                }
            }
        }
Beispiel #24
0
 private void Update()
 {
     if (IsOn)
     {
         if (ModdedPlayer.instance.DanceOfFiregod)
         {
             SpellCaster.RemoveStamina(Cost * 10 * Time.deltaTime);
         }
         else
         {
             SpellCaster.RemoveStamina(Cost * Time.deltaTime);
         }
         if (LocalPlayer.Stats.Stamina < 5)
         {
             Toggle();
         }
         if (GiveDamageBuff)
         {
             BuffDB.AddBuff(13, 44, 1.6f, 1f);
         }
     }
 }
Beispiel #25
0
        public override void Hit(int damage, bool ignoreArmor, DamageType type)
        {
            if (type == DamageType.Physical)
            {
                if (UnityEngine.Random.value > ModdedPlayer.Stats.getHitChance)
                {
                    if (ModdedPlayer.Stats.i_isWindArmor)
                    {
                        //grant buffs;
                        BuffDB.AddBuff(5, 84, 1.2f, 30);
                        BuffDB.AddBuff(9, 85, 1.35f, 10);
                        BuffDB.AddBuff(15, 86, 2000, 10);
                        HealthTarget += ModdedPlayer.Stats.TotalMaxHealth * 0.05f;
                    }
                    Sfx.PlayWhoosh();
                    return;
                }
            }
            float f = damage * ModdedPlayer.Stats.allDamageTaken;

            if (!ignoreArmor)
            {
                f *= 1 - ModReferences.DamageReduction(Mathf.Max(0, ModdedPlayer.Stats.armor - (int)ModdedPlayer.instance.lostArmor));
            }
            if (type == DamageType.Fire)
            {
                f *= 0.01f * ModdedPlayer.Stats.TotalMaxHealth;
                f *= UnityEngine.Random.Range(0.9f, 1.4f);
                //f *= 1-ModdedPlayer.Stats.magicDamageTaken;
                f *= ModdedPlayer.Stats.fireDamageTaken;
            }
            if (ModdedPlayer.Stats.i_KingQruiesSword)
            {
                BuffDB.AddBuff(22, 80, f, 1);
            }

            base.Hit(damage, ignoreArmor, type);
        }
Beispiel #26
0
        public override void Hit(int damage, bool ignoreArmor, DamageType type)
        {
            if (type == DamageType.Physical)
            {
                if (UnityEngine.Random.value < ModdedPlayer.instance.DodgeChance)
                {
                    if (ModdedPlayer.instance.isWindArmor)
                    {
                        //grant buffs;
                        BuffDB.AddBuff(5, 84, 1.1f, 10);
                        BuffDB.AddBuff(9, 85, 1.15f, 10);
                        BuffDB.AddBuff(15, 86, 1500, 10);
                    }
                    return;
                }
            }
            float f = damage * ModdedPlayer.instance.DamageReductionTotal;

            if (!ignoreArmor)
            {
                f *= 1 - ModdedPlayer.instance.ArmorDmgRed;
            }
            if (type == DamageType.Fire)
            {
                f *= 0.01f * ModdedPlayer.instance.MaxHealth;
                f *= UnityEngine.Random.Range(0.9f, 1.4f);
                //f *= 1-ModdedPlayer.instance.MagicResistance;
                f *= ModdedPlayer.instance.FireDamageTakenMult;
            }
            damage = Mathf.RoundToInt(f);
            if (ModdedPlayer.instance.KingQruiesSpecial)
            {
                BuffDB.AddBuff(22, 80, damage / 2, 4);
            }

            base.Hit(damage, ignoreArmor, type);
        }
Beispiel #27
0
 private void Update()
 {
     transform.Rotate((transform.forward + transform.up + Vector3.right) * rotSpeed * Time.deltaTime);
     Lifetime += Time.deltaTime;
     if (caughtPlayer && ModdedPlayer.Stats.stunImmunity == 0 && playerTransform != null)
     {
         var mag = (playerTransform.position - transform.position).sqrMagnitude;
         if (mag > Radius * Radius)
         {
             playerTransform.position = Vector3.MoveTowards(playerTransform.position, transform.position, mag / 2 * Time.deltaTime);
             BuffDB.AddBuff(5, 71, 0.6f, 5);
             BuffDB.AddBuff(10, 72, 0.6f, 5);
         }
     }
     else
     {
         caughtPlayer = false;
     }
     if (Lifetime < Duration)
     {
         if ((LocalPlayer.Transform.root.position - transform.position).sqrMagnitude < Radius * Radius - 2)
         {
             caughtPlayer    = true;
             playerTransform = LocalPlayer.Transform.root;
         }
     }
     else
     {
         transform.localScale -= Vector3.one * Time.deltaTime * 2;
         Radius -= Time.deltaTime * 2;
         if (transform.localScale.x < 0.002f)
         {
             Destroy(gameObject);
         }
     }
 }
        public static void OnCommand(string s)
        {
            try
            {
                if (s.StartsWith("AB"))     //ask the host to send the command to set the difficulty for clinet
                {
                    if (GameSetup.IsMpServer && ModSettings.DifficultyChoosen)
                    {
                        string answer = "AA" + (int)ModSettings.difficulty + ";";
                        if (ModSettings.FriendlyFire)
                        {
                            answer += "t;";
                        }
                        else
                        {
                            answer += "f;";
                        }

                        Network.NetworkManager.SendLine(answer, Network.NetworkManager.Target.Clinets);
                    }
                }
                else if (s.StartsWith("AA"))    //answer for the what is the difficulty query
                {
                    if (ModSettings.DifficultyChoosen || !GameSetup.IsMpClient || ModSettings.IsDedicated)
                    {
                        return;
                    }
                    i  = 2;
                    ch = s.ToCharArray();
                    int   index  = int.Parse(Read());
                    Array values = Enum.GetValues(typeof(ModSettings.Difficulty));
                    ModSettings.difficulty        = (ModSettings.Difficulty)values.GetValue(index);
                    ModSettings.DifficultyChoosen = true;
                    LocalPlayer.FpCharacter.UnLockView();
                    LocalPlayer.FpCharacter.MovementLocked = false;
                }
                else if (s.StartsWith("SC"))    //spell cast
                {
                    if (ModSettings.IsDedicated)
                    {
                        return;
                    }

                    i  = 2;
                    ch = s.ToCharArray();
                    int spellid = int.Parse(Read());
                    if (spellid == 1)
                    {
                        Vector3 pos = new Vector3(float.Parse(Read()), float.Parse(Read()), float.Parse(Read()));
                        BlackHole.CreateBlackHole(pos, ReadBool(), float.Parse(Read()), float.Parse(Read()), float.Parse(Read()), float.Parse(Read()));
                    }
                    else if (spellid == 2)
                    {
                        Vector3 pos = new Vector3(float.Parse(Read()), float.Parse(Read()), float.Parse(Read()));
                        HealingDome.CreateHealingDome(pos, float.Parse(Read()), float.Parse(Read()), ReadBool(), float.Parse(Read()));
                    }
                    else if (spellid == 3)
                    {
                        Vector3 pos = new Vector3(float.Parse(Read()), float.Parse(Read()), float.Parse(Read()));
                        DarkBeam.Create(pos, ReadBool(), float.Parse(Read()), float.Parse(Read()), float.Parse(Read()), float.Parse(Read()), float.Parse(Read()), float.Parse(Read()));
                    }
                }
                else if (s.StartsWith("RI"))    //remove item
                {
                    i  = 2;
                    ch = s.ToCharArray();
                    int id = int.Parse(Read());
                    PickUpManager.RemovePickup(id);
                }
                else if (s.StartsWith("CI"))    //create item
                {
                    i  = 2;
                    ch = s.ToCharArray();
                    Item item = new Item(ItemDataBase.ItemBases[int.Parse(Read())], 1, 0, false);   //reading first value, id
                    int  id   = int.Parse(Read());
                    item.level = int.Parse(Read());
                    int     amount = int.Parse(Read());
                    Vector3 pos    = new Vector3(float.Parse(Read()), float.Parse(Read()), float.Parse(Read()));
                    while (i < ch.Length)
                    {
                        ItemStat stat = new ItemStat(ItemDataBase.Stats[int.Parse(Read())])
                        {
                            Amount = float.Parse(Read())
                        };
                        item.Stats.Add(stat);
                    }
                    PickUpManager.SpawnPickUp(item, pos, amount, id);
                }
                else if (s.StartsWith("EE"))       //host has been asked to share info on enemy
                {
                    if (!GameSetup.IsMpClient)
                    {
                        i  = 2;
                        ch = s.ToCharArray();
                        ulong packed = ulong.Parse(Read());
                        if (EnemyManager.hostDictionary.ContainsKey(packed))
                        {
                            EnemyProgression ep = EnemyManager.hostDictionary[packed];
                            parseval = "EA" + packed + ";" + ep.EnemyName + ";" + ep.Level + ";" + ep.Health + ";" + ep.MaxHealth + ";" + ep.Bounty + ";" + ep.Armor + ";" + ep.ArmorReduction + ";" + ep.SteadFest + ";" + ep.abilities.Count + ";";
                            foreach (EnemyProgression.Abilities item in ep.abilities)
                            {
                                parseval += (int)item + ";";
                            }
                            Network.NetworkManager.SendLine(parseval, Network.NetworkManager.Target.Everyone);
                        }
                    }
                }
                else if (s.StartsWith("ES"))       //enemy spell
                {
                    if (ModSettings.IsDedicated)
                    {
                        return;
                    }

                    i  = 2;
                    ch = s.ToCharArray();
                    int id = int.Parse(Read());
                    switch (id)
                    {
                    case 1:     //snow aura
                        ulong    packed = ulong.Parse(Read());
                        SnowAura sa     = new GameObject("Snow").AddComponent <SnowAura>();
                        if (!EnemyManager.allboltEntities.ContainsKey(packed))
                        {
                            EnemyManager.GetAllEntities();
                        }

                        sa.followTarget = EnemyManager.allboltEntities[packed].transform;
                        break;

                    default:
                        break;
                    }
                }
                else if (s.StartsWith("PO"))    //poison Player
                {
                    if (ModSettings.IsDedicated)
                    {
                        return;
                    }

                    i  = 2;
                    ch = s.ToCharArray();
                    ulong playerPacked = ulong.Parse(Read());
                    if (ModReferences.ThisPlayerPacked == playerPacked)
                    {
                        int   source   = int.Parse(Read());
                        float amount   = float.Parse(Read());
                        float duration = float.Parse(Read());

                        BuffDB.AddBuff(3, source, amount, duration);
                    }
                }
                else if (s.StartsWith("KX"))    //kill experience
                {
                    if (ModSettings.IsDedicated)
                    {
                        return;
                    }

                    i  = 2;
                    ch = s.ToCharArray();
                    long exp = long.Parse(Read());
                    ModAPI.Console.Write("Gained exp " + exp);
                    ModdedPlayer.instance.AddKillExperience(exp);
                }
                else if (s.StartsWith("EA"))       //host answered info about a enemy and the info is processed
                {
                    if (ModSettings.IsDedicated)
                    {
                        return;
                    }

                    if (GameSetup.IsMpClient)
                    {
                        i  = 2;
                        ch = s.ToCharArray();
                        ulong packed = ulong.Parse(Read());
                        if (!EnemyManager.allboltEntities.ContainsKey(packed))
                        {
                            EnemyManager.GetAllEntities();
                        }
                        if (EnemyManager.allboltEntities.ContainsKey(packed))
                        {
                            BoltEntity entity  = EnemyManager.allboltEntities[packed];
                            string     name    = Read();
                            int        v1      = int.Parse(Read());
                            int        v2      = int.Parse(Read());
                            int        v3      = int.Parse(Read());
                            int        v4      = int.Parse(Read());
                            int        v5      = int.Parse(Read());
                            int        v6      = int.Parse(Read());
                            float      v7      = float.Parse(Read());
                            int        lenght  = int.Parse(Read());
                            int[]      affixes = new int[lenght];
                            int        id      = 0;
                            while (i < ch.Length)
                            {
                                affixes[id] = int.Parse(Read());
                                id++;
                            }
                            if (EnemyManager.clinetProgressions.ContainsKey(entity))
                            {
                                ClinetEnemyProgression cp = EnemyManager.clinetProgressions[entity];
                                cp.creationTime   = Time.time;
                                cp.Entity         = entity;
                                cp.Level          = v1;
                                cp.Health         = v2;
                                cp.MaxHealth      = v3;
                                cp.Armor          = v5;
                                cp.ArmorReduction = v6;
                                cp.EnemyName      = name;
                                cp.ExpBounty      = v4;
                                cp.SteadFest      = v7;
                                cp.Affixes        = affixes;
                            }
                            else
                            {
                                new ClinetEnemyProgression(entity, name, v1, v2, v3, v4, v5, v6, v7, affixes);
                            }
                        }
                    }
                }
                else if (s.StartsWith("RO"))    //root the player
                {
                    if (ModSettings.IsDedicated)
                    {
                        return;
                    }

                    if (!ModdedPlayer.instance.RootImmune && !ModdedPlayer.instance.StunImmune)
                    {
                        i  = 2;
                        ch = s.ToCharArray();
                        Vector3 pos = new Vector3(float.Parse(Read()), float.Parse(Read()), float.Parse(Read()));
                        if ((LocalPlayer.Transform.position - pos).sqrMagnitude < 1200)
                        {
                            float duration = float.Parse(Read());
                            NetworkManager.SendLine("RE" + LocalPlayer.Transform.position.x + ";" + LocalPlayer.Transform.position.y + ";" + LocalPlayer.Transform.position.z + ";" + duration + ";", NetworkManager.Target.Everyone);
                            ModdedPlayer.instance.Root(duration);
                        }
                    }
                }
                else if (s.StartsWith("ST"))    //stun the player
                {
                    if (ModSettings.IsDedicated)
                    {
                        return;
                    }

                    if (!ModdedPlayer.instance.StunImmune)
                    {
                        i  = 2;
                        ch = s.ToCharArray();
                        ulong packed = ulong.Parse(Read());
                        if (ModReferences.ThisPlayerPacked == packed)
                        {
                            float duration = float.Parse(Read());
                            ModdedPlayer.instance.Stun(duration);
                        }
                    }
                }
                else if (s.StartsWith("RE"))
                {
                    if (ModSettings.IsDedicated)
                    {
                        return;
                    }

                    i  = 2;
                    ch = s.ToCharArray();
                    Vector3 pos      = new Vector3(float.Parse(Read()), float.Parse(Read()), float.Parse(Read()));
                    float   duration = float.Parse(Read());
                    RootSpell.Create(pos, duration);
                }
                else if (s.StartsWith("TR"))
                {
                    if (ModSettings.IsDedicated)
                    {
                        return;
                    }

                    i  = 2;
                    ch = s.ToCharArray();
                    Vector3 pos      = new Vector3(float.Parse(Read()), float.Parse(Read()), float.Parse(Read()));
                    float   duration = float.Parse(Read());
                    float   radius   = float.Parse(Read());
                    TrapSphereSpell.Create(pos, radius, duration);
                }
                else if (s.StartsWith("LA"))
                {
                    i  = 2;
                    ch = s.ToCharArray();
                    Vector3 pos = new Vector3(float.Parse(Read()), float.Parse(Read()), float.Parse(Read()));
                    Vector3 dir = new Vector3(float.Parse(Read()), float.Parse(Read()), float.Parse(Read()));

                    EnemyLaser.CreateLaser(pos, dir);
                }
                else if (s.StartsWith("MT"))
                {
                    i  = 2;
                    ch = s.ToCharArray();
                    Vector3 pos = new Vector3(float.Parse(Read()), float.Parse(Read()), float.Parse(Read()));
                    Meteor.CreateEnemy(pos, int.Parse(Read()));
                }
                else if (s.StartsWith("RL"))
                {
                    if (s.Length > 2)
                    {
                        ModReferences.PlayerLevels.Clear();
                    }
                    NetworkManager.SendLine("AL" + ModReferences.ThisPlayerPacked + ";" + ModdedPlayer.instance.Level + ";", NetworkManager.Target.Everyone);
                }
                else if (s.StartsWith("AL"))
                {
                    i  = 2;
                    ch = s.ToCharArray();
                    ulong packed = ulong.Parse(Read());
                    int   level  = int.Parse(Read());
                    if (ModReferences.PlayerLevels.ContainsKey(packed))
                    {
                        ModReferences.PlayerLevels[packed] = level;
                    }
                    else
                    {
                        ModReferences.PlayerLevels.Add(packed, level);
                    }
                }
                else if (s.StartsWith("EH"))    //enemy hitmarker
                {
                    if (ModSettings.IsDedicated)
                    {
                        return;
                    }

                    i  = 2;
                    ch = s.ToCharArray();
                    int     amount = int.Parse(Read());
                    Vector3 pos    = new Vector3(float.Parse(Read()), float.Parse(Read()), float.Parse(Read()));
                    new MainMenu.HitMarker(amount, pos);
                }
                else if (s.StartsWith("AC"))    //slow Enemy
                {
                    if (GameSetup.IsMpServer || GameSetup.IsSinglePlayer)
                    {
                        i  = 2;
                        ch = s.ToCharArray();
                        ulong id     = ulong.Parse(Read());
                        float amount = float.Parse(Read());
                        float time   = float.Parse(Read());
                        int   src    = int.Parse(Read());
                        EnemyManager.hostDictionary[id].Slow(src, amount, time);
                    }
                }
                else if (s.StartsWith("AD"))    //slow Enemy
                {
                    if (GameSetup.IsMpServer)
                    {
                        if (ModSettings.IsDedicated)
                        {
                            ItemDataBase.MagicFind = 1;
                        }
                        else
                        {
                            ItemDataBase.MagicFind = ModdedPlayer.instance.MagicFindMultipier;
                        }
                    }
                    else
                    {
                        Network.NetworkManager.SendLine("AE" + ModdedPlayer.instance.MagicFindMultipier + ";", Network.NetworkManager.Target.OnlyServer);
                    }
                }
                else if (s.StartsWith("AE"))    //slow Enemy
                {
                    if (GameSetup.IsMpServer)
                    {
                        i  = 2;
                        ch = s.ToCharArray();
                        ItemDataBase.MagicFind *= float.Parse(Read());
                    }
                }
            }
            catch (Exception e)
            {
                ModAPI.Log.Write(e.ToString());
            }
        }
 public static void Cast()
 {
     BuffDB.AddBuff(17, 50, 0, 30);
 }
        public static void OnCommand(byte[] bytes)
        {
            using (MemoryStream stream = new MemoryStream(bytes))
            {
                using (BinaryReader r = new BinaryReader(stream))
                {
                    int cmdIndex = r.ReadInt32();

                    if (cmdIndex == 1)  //previousely AB
                    {
                        if (GameSetup.IsMpServer && ModSettings.DifficultyChoosen)
                        {
                            using (MemoryStream answerStream = new MemoryStream())
                            {
                                using (BinaryWriter w = new BinaryWriter(answerStream))
                                {
                                    w.Write(2);
                                    w.Write((int)ModSettings.difficulty);
                                    w.Write(ModSettings.FriendlyFire);
                                    w.Write((int)ModSettings.dropsOnDeath);
                                    w.Write(ModSettings.killOnDowned);
                                    w.Close();
                                }
                                Network.NetworkManager.SendLine(answerStream.ToArray(), Network.NetworkManager.Target.Clients);
                                answerStream.Close();
                            }
                        }
                    }
                    else if (cmdIndex == 2) //request for the what is the difficulty
                    {
                        if (!GameSetup.IsMpClient || ModSettings.IsDedicated)
                        {
                            return;
                        }

                        int index = r.ReadInt32();
                        ModSettings.FriendlyFire = r.ReadBoolean();
                        ModSettings.dropsOnDeath = (ModSettings.DropsOnDeathMode)r.ReadInt32();
                        ModSettings.killOnDowned = r.ReadBoolean();
                        Array values = Enum.GetValues(typeof(ModSettings.Difficulty));
                        ModSettings.difficulty = (ModSettings.Difficulty)values.GetValue(index);
                        if (!ModSettings.DifficultyChoosen)
                        {
                            LocalPlayer.FpCharacter.UnLockView();
                            LocalPlayer.FpCharacter.MovementLocked = false;
                        }
                        ModSettings.DifficultyChoosen = true;
                    }
                    else if (cmdIndex == 3) //spell casted
                    {
                        int spellid = r.ReadInt32();
                        if (spellid == 1)
                        {
                            Vector3 pos = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                            BlackHole.CreateBlackHole(pos, r.ReadBoolean(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadString());
                        }
                        else if (spellid == 2)
                        {
                            Vector3 pos = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                            HealingDome.CreateHealingDome(pos, r.ReadSingle(), r.ReadSingle(), r.ReadBoolean(), r.ReadBoolean(), r.ReadSingle());
                        }
                        else if (spellid == 3)
                        {
                            Vector3 pos = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                            DarkBeam.Create(pos, r.ReadBoolean(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                        }
                        else if (spellid == 4)
                        {
                            bool   isOn   = r.ReadBoolean();
                            string packed = r.ReadString();
                            BlackFlame.ToggleOtherPlayer(packed, isOn);
                        }
                        else if (spellid == 5)
                        {
                            Vector3 pos     = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                            float   radius  = r.ReadSingle();
                            float   speed   = r.ReadSingle();
                            float   dmg     = r.ReadSingle();
                            bool    GiveDmg = r.ReadBoolean();
                            bool    GiveAr  = r.ReadBoolean();
                            int     ar      = 0;
                            if (GiveAr)
                            {
                                ar = r.ReadInt32();
                            }

                            WarCry.Cast(pos, radius, speed, dmg, GiveDmg, GiveAr, ar);
                        }
                        else if (spellid == 6)
                        {
                            Vector3 pos      = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                            float   duration = r.ReadSingle();
                            int     id       = r.ReadInt32();

                            Portal.CreatePortal(pos, duration, id, r.ReadBoolean(), r.ReadBoolean());
                        }
                        else if (spellid == 7)
                        {
                            Vector3 pos = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                            Vector3 dir = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());

                            float  dmg       = r.ReadSingle();
                            string caster    = r.ReadString();
                            float  duration  = r.ReadSingle();
                            bool   slow      = r.ReadBoolean();
                            bool   dmgdebuff = r.ReadBoolean();
                            if (GameSetup.IsMpServer)
                            {
                                MagicArrow.Create(pos, dir, dmg, caster, duration, slow, dmgdebuff);
                            }
                            else
                            {
                                MagicArrow.CreateEffect(pos, dir, dmgdebuff, duration);
                            }
                        }
                        else if (spellid == 8)
                        {
                            Purge.Cast(new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle()), r.ReadSingle(), r.ReadBoolean(), r.ReadBoolean());
                        }
                        else if (spellid == 9)
                        {
                            Vector3 pos  = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                            float   dist = r.ReadSingle();

                            SnapFreeze.CreateEffect(pos, dist);
                            if (!GameSetup.IsMpClient)
                            {
                                SnapFreeze.HostAction(pos, dist, r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                            }
                        }
                        else if (spellid == 10)
                        {
                            Vector3 pos   = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                            Vector3 speed = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                            float   dmg   = r.ReadSingle();
                            uint    id    = r.ReadUInt32();

                            if (BallLightning.lastID < id)
                            {
                                BallLightning.lastID = id;
                            }

                            BallLightning.Create(pos, speed, dmg, id);
                        }
                        else if (spellid == 11)
                        {
                            Vector3 pos       = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                            float   radius    = r.ReadSingle();
                            float   dmg       = r.ReadSingle();
                            float   duration  = r.ReadSingle();
                            bool    isArcane  = r.ReadBoolean();
                            bool    fromEnemy = r.ReadBoolean();
                            Cataclysm.Create(pos, radius, dmg, duration, isArcane ? Cataclysm.TornadoType.Arcane : Cataclysm.TornadoType.Fire, fromEnemy);
                        }
                        else if (spellid == 12)
                        {
                            //a request from a client to a host to spawn a ball lightning. The host assigns the id of
                            //a ball lightning to not create overlapping ids
                            using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                            {
                                using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                                {
                                    w.Write(3);
                                    w.Write(10);
                                    w.Write(r.ReadSingle());
                                    w.Write(r.ReadSingle());
                                    w.Write(r.ReadSingle());
                                    w.Write(r.ReadSingle());
                                    w.Write(r.ReadSingle());
                                    w.Write(r.ReadSingle());
                                    w.Write(r.ReadSingle());
                                    w.Write((uint)(BallLightning.lastID + 1));
                                    w.Close();
                                    BallLightning.lastID++;
                                }
                                ChampionsOfForest.Network.NetworkManager.SendLine(answerStream.ToArray(), ChampionsOfForest.Network.NetworkManager.Target.Everyone);
                                answerStream.Close();
                            }
                        }
                        else if (spellid == 13) //parry was casted by a client
                        {
                            Vector3 pos    = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                            float   radius = r.ReadSingle();
                            bool    ignite = r.ReadBoolean();
                            float   dmg    = r.ReadSingle();

                            DamageMath.DamageClamp(dmg, out int d, out int rep);
                            var hits = Physics.SphereCastAll(pos, radius, Vector3.one);

                            for (int i = 0; i < hits.Length; i++)
                            {
                                if (hits[i].transform.CompareTag("enemyCollide"))
                                {
                                    for (int a = 0; a < rep; a++)
                                    {
                                        hits[i].transform.SendMessageUpwards("Hit", d, SendMessageOptions.DontRequireReceiver);
                                        if (ignite)
                                        {
                                            hits[i].transform.SendMessageUpwards("Burn", SendMessageOptions.DontRequireReceiver);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (cmdIndex == 4) //remove item
                    {
                        PickUpManager.RemovePickup(r.ReadUInt64());
                    }
                    else if (cmdIndex == 5)                                                        //create item
                    {
                        Item  item = new Item(ItemDataBase.ItemBases[r.ReadInt32()], 1, 0, false); //reading first value, id
                        ulong id   = r.ReadUInt64();
                        item.level = r.ReadInt32();
                        int     amount = r.ReadInt32();
                        Vector3 pos    = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                        while (r.BaseStream.Position != r.BaseStream.Length)
                        {
                            ItemStat stat = new ItemStat(ItemDataBase.Stats[r.ReadInt32()])
                            {
                                Amount = r.ReadSingle()
                            };
                            item.Stats.Add(stat);
                        }
                        PickUpManager.SpawnPickUp(item, pos, amount, id);
                    }
                    else if (cmdIndex == 6) //host has been asked to share info on enemy
                    {
                        if (!GameSetup.IsMpClient)
                        {
                            ulong packed = r.ReadUInt64();
                            if (EnemyManager.hostDictionary.ContainsKey(packed))
                            {
                                EnemyProgression ep = EnemyManager.hostDictionary[packed];
                                using (MemoryStream answerStream = new MemoryStream())
                                {
                                    using (BinaryWriter w = new BinaryWriter(answerStream))
                                    {
                                        w.Write(7);
                                        w.Write(packed);
                                        w.Write(ep.EnemyName);
                                        w.Write(ep.Level);
                                        w.Write(ep._hp + ep._Health.Health);
                                        w.Write(ep.MaxHealth);
                                        w.Write(ep.bounty);
                                        w.Write(ep.Armor);
                                        w.Write(ep.ArmorReduction);
                                        w.Write(ep.Steadfast);
                                        w.Write(ep.abilities.Count);
                                        foreach (EnemyProgression.Abilities item in ep.abilities)
                                        {
                                            w.Write((int)item);
                                        }

                                        w.Close();
                                    }
                                    Network.NetworkManager.SendLine(answerStream.ToArray(), Network.NetworkManager.Target.Clients);
                                    answerStream.Close();
                                }
                            }
                            else
                            {
                                CotfUtils.Log("no enemy in host's dictionary");
                            }
                        }
                    }
                    else if (cmdIndex == 7) //host answered info about a enemy and the info is processed
                    {
                        if (ModSettings.IsDedicated)
                        {
                            return;
                        }

                        if (GameSetup.IsMpClient)
                        {
                            ulong packed = r.ReadUInt64();
                            if (!EnemyManager.allboltEntities.ContainsKey(packed))
                            {
                                EnemyManager.GetAllEntities();
                            }
                            if (EnemyManager.allboltEntities.ContainsKey(packed))
                            {
                                BoltEntity entity         = EnemyManager.allboltEntities[packed];
                                string     name           = r.ReadString();
                                int        level          = r.ReadInt32();
                                float      health         = r.ReadSingle();
                                float      maxhealth      = r.ReadSingle();
                                long       bounty         = r.ReadInt64();
                                int        armor          = r.ReadInt32();
                                int        armorReduction = r.ReadInt32();
                                float      steadfast      = r.ReadSingle();
                                int        length         = r.ReadInt32();
                                int[]      affixes        = new int[length];
                                for (int i = 0; i < length; i++)
                                {
                                    affixes[i] = r.ReadInt32();
                                }
                                if (EnemyManager.clinetProgressions.ContainsKey(entity))
                                {
                                    ClinetEnemyProgression cp = EnemyManager.clinetProgressions[entity];
                                    cp.creationTime   = Time.time;
                                    cp.Entity         = entity;
                                    cp.Level          = level;
                                    cp.Health         = health;
                                    cp.MaxHealth      = maxhealth;
                                    cp.Armor          = armor;
                                    cp.ArmorReduction = armorReduction;
                                    cp.EnemyName      = name;
                                    cp.ExpBounty      = bounty;
                                    cp.Steadfast      = steadfast;
                                    cp.Affixes        = affixes;
                                }
                                else
                                {
                                    new ClinetEnemyProgression(entity, name, level, health, maxhealth, bounty, armor, armorReduction, steadfast, affixes);
                                }
                            }
                        }
                    }
                    else if (cmdIndex == 8) //enemy spell casted
                    {
                        int id = r.ReadInt32();
                        if (id == 1) //snow aura
                        {
                            ulong    packed = r.ReadUInt64();
                            SnowAura sa     = new GameObject("Snow").AddComponent <SnowAura>();
                            if (!EnemyManager.allboltEntities.ContainsKey(packed))
                            {
                                EnemyManager.GetAllEntities();
                            }
                            sa.followTarget = EnemyManager.allboltEntities[packed].transform;
                        }
                        else if (id == 2) //fire aura
                        {
                            ulong      packed = r.ReadUInt64();
                            float      dmg    = r.ReadSingle();
                            GameObject go     = EnemyManager.allboltEntities[packed].gameObject;
                            FireAura.Cast(go, dmg);
                        }
                    }
                    else if (cmdIndex == 9)  //poison Player
                    {
                        string playerID = r.ReadString();
                        if (ModReferences.ThisPlayerID == playerID)
                        {
                            int   source   = r.ReadInt32();
                            float amount   = r.ReadSingle();
                            float duration = r.ReadSingle();

                            BuffDB.AddBuff(3, source, amount, duration);
                        }
                    }
                    else if (cmdIndex == 10) //kill experience
                    {
                        ModdedPlayer.instance.AddKillExperience(r.ReadInt64());
                    }
                    else if (cmdIndex == 11) //add experience without massacre
                    {
                        ModdedPlayer.instance.AddFinalExperience(r.ReadInt64());
                    }
                    else if (cmdIndex == 12)  //root the player
                    {
                        if (ModdedPlayer.instance.RootImmune == 0 && ModdedPlayer.instance.StunImmune == 0)
                        {
                            Vector3 pos = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                            if ((LocalPlayer.Transform.position - pos).sqrMagnitude < 1250)
                            {
                                float duration = r.ReadSingle();
                                ModdedPlayer.instance.Root(duration);
                                using (MemoryStream answerStream = new MemoryStream())
                                {
                                    using (BinaryWriter w = new BinaryWriter(answerStream))
                                    {
                                        w.Write(14);
                                        w.Write(LocalPlayer.Transform.position.x);
                                        w.Write(LocalPlayer.Transform.position.y);
                                        w.Write(LocalPlayer.Transform.position.z);
                                        w.Write(duration);
                                        w.Close();
                                    }
                                    NetworkManager.SendLine(answerStream.ToArray(), NetworkManager.Target.Everyone);
                                    answerStream.Close();
                                }
                            }
                        }
                    }
                    else if (cmdIndex == 13)  //stun the player
                    {
                        if (ModSettings.IsDedicated)
                        {
                            return;
                        }
                        if (ModdedPlayer.instance.StunImmune == 0)
                        {
                            string playerID = r.ReadString();
                            if (ModReferences.ThisPlayerID == playerID)
                            {
                                float duration = r.ReadSingle();
                                ModdedPlayer.instance.Stun(duration);
                            }
                        }
                    }
                    else if (cmdIndex == 14) //player has been chained, now spawn effect
                    {
                        if (ModSettings.IsDedicated)
                        {
                            return;
                        }

                        Vector3 pos      = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                        float   duration = r.ReadSingle();
                        RootSpell.Create(pos, duration);
                    }
                    else if (cmdIndex == 15)    //create trap sphere
                    {
                        Vector3 pos      = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                        float   duration = r.ReadSingle();
                        float   radius   = r.ReadSingle();
                        TrapSphereSpell.Create(pos, radius, duration);
                    }
                    else if (cmdIndex == 16)    //create enemy laser, aka plasma cannon
                    {
                        Vector3 pos = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                        Vector3 dir = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());

                        EnemyLaser.CreateLaser(pos, dir);
                    }
                    else if (cmdIndex == 17) //create enemy meteor rain
                    {
                        Vector3 pos = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                        Meteor.CreateEnemy(pos, r.ReadInt32());
                    }
                    else if (cmdIndex == 18) //player's level info, or command to wipe level data
                    {
                        if (r.BaseStream.Position == r.BaseStream.Length)
                        {
                            ModReferences.PlayerLevels.Clear();
                        }
                        using (MemoryStream answerStream = new MemoryStream())
                        {
                            using (BinaryWriter w = new BinaryWriter(answerStream))
                            {
                                w.Write(19);
                                w.Write(ModReferences.ThisPlayerID);
                                w.Write(ModdedPlayer.instance.Level);
                                w.Close();
                            }
                            Network.NetworkManager.SendLine(answerStream.ToArray(), NetworkManager.Target.Others);
                            answerStream.Close();
                        }
                    }
                    else if (cmdIndex == 19)//add or update some players level to list
                    {
                        string packed = r.ReadString();
                        int    level  = r.ReadInt32();
                        if (ModReferences.PlayerLevels.ContainsKey(packed))
                        {
                            ModReferences.PlayerLevels[packed] = level;
                        }
                        else
                        {
                            ModReferences.PlayerLevels.Add(packed, level);
                        }
                    }
                    else if (cmdIndex == 20) //enemy hitmarker
                    {
                        if (ModSettings.IsDedicated)
                        {
                            return;
                        }

                        int     amount = r.ReadInt32();
                        Vector3 pos    = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                        Color   c      = new Color(r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                        MainMenu.CreateHitMarker(amount, pos, c);
                    }
                    else if (cmdIndex == 21)  //player hitmarker
                    {
                        if (ModSettings.IsDedicated)
                        {
                            return;
                        }

                        int     amount = r.ReadInt32();
                        Vector3 pos    = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                        new MainMenu.HitMarker(amount, pos, true);
                    }
                    else if (cmdIndex == 22)   //slow Enemy
                    {
                        if (GameSetup.IsMpServer || GameSetup.IsSinglePlayer)
                        {
                            ulong id = r.ReadUInt64();
                            if (EnemyManager.hostDictionary.ContainsKey(id))
                            {
                                float amount = r.ReadSingle();
                                float time   = r.ReadSingle();
                                int   src    = r.ReadInt32();
                                EnemyManager.hostDictionary[id].Slow(src, amount, time);
                            }
                        }
                    }
                    else if (cmdIndex == 23)  //sync magic find
                    {
                        if (GameSetup.IsMpServer)
                        {
                            if (ModSettings.IsDedicated)
                            {
                                ItemDataBase.MagicFind = 1;
                            }
                            else
                            {
                                ItemDataBase.MagicFind = ModdedPlayer.instance.MagicFindMultipier;
                            }
                        }
                        else
                        {
                            using (MemoryStream answerStream = new MemoryStream())
                            {
                                using (BinaryWriter w = new BinaryWriter(answerStream))
                                {
                                    w.Write(24);
                                    w.Write(ModdedPlayer.instance.MagicFindMultipier);
                                    w.Close();
                                }
                                Network.NetworkManager.SendLine(answerStream.ToArray(), Network.NetworkManager.Target.OnlyServer);
                                answerStream.Close();
                            }
                        }
                    }
                    else if (cmdIndex == 24) //update magic find for host
                    {
                        if (GameSetup.IsMpServer)
                        {
                            ItemDataBase.MagicFind *= r.ReadSingle();
                        }
                    }
                    else if (cmdIndex == 25) //ask for item
                    {
                        if (GameSetup.IsMpServer)
                        {
                            ulong itemID = r.ReadUInt64();
                            if (PickUpManager.PickUps.ContainsKey(itemID))
                            {
                                int    itemAmount = r.ReadInt32();
                                string playerID   = r.ReadString();

                                if (PickUpManager.PickUps[itemID].amount > 0)
                                {
                                    int givenAmount = itemAmount;
                                    if (itemAmount > PickUpManager.PickUps[itemID].amount)
                                    {
                                        givenAmount = Mathf.Min(PickUpManager.PickUps[itemID].amount, itemAmount);
                                    }

                                    NetworkManager.SendItemToPlayer(PickUpManager.PickUps[itemID].item, playerID, givenAmount);

                                    PickUpManager.PickUps[itemID].amount -= givenAmount;

                                    if (PickUpManager.PickUps[itemID].amount > 0)
                                    {
                                        return;
                                    }
                                }
                            }
                            using (MemoryStream answerStream = new MemoryStream())
                            {
                                using (BinaryWriter w = new BinaryWriter(answerStream))
                                {
                                    w.Write(4);
                                    w.Write(itemID);
                                    w.Close();
                                }
                                Network.NetworkManager.SendLine(answerStream.ToArray(), Network.NetworkManager.Target.Clients);
                                answerStream.Close();
                            }
                        }
                    }
                    else if (cmdIndex == 26) //give item to player
                    {
                        string playerID = r.ReadString();
                        if (ModReferences.ThisPlayerID == playerID)
                        {
                            //creating the item.
                            Item item = new Item(ItemDataBase.ItemBases[r.ReadInt32()], r.ReadInt32(), 0, false)
                            {
                                level = r.ReadInt32()
                            };

                            //adding stats to the item
                            while (r.BaseStream.Position != r.BaseStream.Length)
                            {
                                ItemStat stat = new ItemStat(ItemDataBase.Stats[r.ReadInt32()])
                                {
                                    Amount = r.ReadSingle()
                                };
                                item.Stats.Add(stat);
                            }

                            Player.Inventory.Instance.AddItem(item, item.Amount);
                        }
                    }
                    else if (cmdIndex == 27) // bonus fire damage
                    {
                        if (GameSetup.IsMpServer || GameSetup.IsSinglePlayer)
                        {
                            ulong id = r.ReadUInt64();
                            if (EnemyManager.hostDictionary.ContainsKey(id))
                            {
                                float amount = r.ReadSingle();
                                float time   = r.ReadSingle();
                                int   src    = r.ReadInt32();
                                EnemyManager.hostDictionary[id].FireDebuff(src, amount, time);
                            }
                        }
                    }
                    else if (cmdIndex == 28) //custom weapon in mp
                    {
                        string id       = r.ReadString();
                        int    weaponID = r.ReadInt32();
                        if (!ModReferences.PlayerHands.ContainsKey(id))
                        {
                            ModReferences.FindHands();
                        }

                        if (ModReferences.PlayerHands.ContainsKey(id))
                        {
                            CoopCustomWeapons.SetWeaponOn(ModReferences.PlayerHands[id], weaponID);
                            Console.WriteLine(ModReferences.PlayerHands[id].name);
                        }
                        else
                        {
                            Debug.LogWarning("NO HAND IN COMMAND READER");
                        }
                    }
                    else if (cmdIndex == 29) //request for enemy damage information
                    {
                        if (GameSetup.IsMpServer)
                        {
                            ulong id = r.ReadUInt64();
                            if (EnemyManager.hostDictionary.ContainsKey(id))
                            {
                                EnemyProgression p = EnemyManager.hostDictionary[id];
                                using (MemoryStream answerStream = new MemoryStream())
                                {
                                    using (BinaryWriter w = new BinaryWriter(answerStream))
                                    {
                                        w.Write(30);
                                        w.Write(id);
                                        w.Write(p.BaseDamageMult);
                                        foreach (EnemyProgression.Abilities ability in p.abilities)
                                        {
                                            w.Write((int)ability);
                                        }
                                        w.Close();
                                    }
                                    NetworkManager.SendLine(answerStream.ToArray(), NetworkManager.Target.Clients);
                                    answerStream.Close();
                                }
                            }
                        }
                    }
                    else if (cmdIndex == 30) //answer to client damage
                    {
                        ulong id  = r.ReadUInt64();
                        float dmg = r.ReadSingle();
                        List <EnemyProgression.Abilities> abilities = new List <EnemyProgression.Abilities>();
                        while (r.BaseStream.Position != r.BaseStream.Length)
                        {
                            abilities.Add((EnemyProgression.Abilities)r.ReadInt32());
                        }
                        new ClientEnemy(id, dmg, abilities);
                    }
                    else if (cmdIndex == 31) //detonate ball lightning
                    {
                        uint    id  = r.ReadUInt32();
                        Vector3 pos = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                        if (BallLightning.list.ContainsKey(id))
                        {
                            BallLightning.list[id].CoopTrigger(pos);
                        }
                    }
                    else if (cmdIndex == 32) //apply DoT to an enemy
                    {
                        ulong id = r.ReadUInt64();
                        if (EnemyManager.hostDictionary.ContainsKey(id))
                        {
                            EnemyProgression p = EnemyManager.hostDictionary[id];
                            p.DoDoT(r.ReadInt32(), r.ReadSingle());
                        }
                    }
                    else if (cmdIndex == 33) //enemy got bashed
                    {
                        ulong enemy = r.ReadUInt64();
                        if (EnemyManager.hostDictionary.ContainsKey(enemy))
                        {
                            EnemyProgression p        = EnemyManager.hostDictionary[enemy];
                            float            duration = r.ReadSingle();
                            var   source      = r.ReadInt32();
                            float slowAmount  = r.ReadSingle();
                            float dmgDebuff   = r.ReadSingle();
                            var   bleedDmg    = r.ReadInt32();
                            float bleedChance = r.ReadSingle();
                            p.Slow(source, slowAmount, duration);
                            p.DmgTakenDebuff(source, dmgDebuff, duration);
                            if (UnityEngine.Random.value < bleedChance)
                            {
                                p.DoDoT(bleedDmg, duration);
                            }
                        }
                    }
                    else if (cmdIndex == 34)
                    {
                        if (GameSetup.IsMpServer)
                        {
                            ulong enemy = r.ReadUInt64();
                            if (EnemyManager.hostDictionary.ContainsKey(enemy))
                            {
                                EnemyProgression p = EnemyManager.hostDictionary[enemy];
                                var   source       = r.ReadInt32();
                                float amount       = r.ReadSingle();
                                float duration     = r.ReadSingle();
                                p.DmgTakenDebuff(source, amount, duration);
                            }
                        }
                    }
                    else if (cmdIndex == 35)    //clear ping command
                    {
                        string player = r.ReadString();
                        if (MainMenu.Instance.otherPlayerPings.ContainsKey(player))
                        {
                            MainMenu.Instance.otherPlayerPings.Remove(player);
                        }
                    }
                    else if (cmdIndex == 36)    //create ping command
                    {
                        string PlayerID           = r.ReadString();
                        MarkObject.PingType ptype = (MarkObject.PingType)r.ReadInt32();
                        switch (ptype)
                        {
                        case MarkObject.PingType.Enemy:
                            ulong EnemyID = r.ReadUInt64();
                            if (!EnemyManager.allboltEntities.ContainsKey(EnemyID))
                            {
                                EnemyManager.GetAllEntities();
                            }
                            if (EnemyManager.allboltEntities.ContainsKey(EnemyID))
                            {
                                bool      isElite = r.ReadBoolean();
                                string    name    = r.ReadString();
                                Transform tr      = EnemyManager.allboltEntities[EnemyID].transform;
                                if (PlayerID == ModReferences.ThisPlayerID)
                                {
                                    MainMenu.Instance.localPlayerPing = new MarkEnemy(tr, name, isElite);
                                }
                                else
                                {
                                    if (MainMenu.Instance.otherPlayerPings.ContainsKey(PlayerID))
                                    {
                                        MainMenu.Instance.otherPlayerPings[PlayerID] = new MarkEnemy(tr, name, isElite);
                                    }
                                    else
                                    {
                                        MainMenu.Instance.otherPlayerPings.Add(PlayerID, new MarkEnemy(tr, name, isElite));
                                    }
                                }
                            }
                            break;

                        case MarkObject.PingType.Location:
                            float x = r.ReadSingle(), y = r.ReadSingle(), z = r.ReadSingle();
                            if (PlayerID == ModReferences.ThisPlayerID)
                            {
                                MainMenu.Instance.localPlayerPing = new MarkPostion(new Vector3(x, y, z));
                            }
                            else
                            {
                                if (MainMenu.Instance.otherPlayerPings.ContainsKey(PlayerID))
                                {
                                    MainMenu.Instance.otherPlayerPings[PlayerID] = new MarkPostion(new Vector3(x, y, z));
                                }
                                else
                                {
                                    MainMenu.Instance.otherPlayerPings.Add(PlayerID, new MarkPostion(new Vector3(x, y, z)));
                                }
                            }

                            break;

                        case MarkObject.PingType.Item:
                            ulong PickupID = r.ReadUInt64();
                            if (PickUpManager.PickUps.ContainsKey(PickupID))
                            {
                                var pu = PickUpManager.PickUps[PickupID];
                                if (PlayerID == ModReferences.ThisPlayerID)
                                {
                                    MainMenu.Instance.localPlayerPing = new MarkPickup(pu.transform, pu.item.name, pu.item.Rarity);
                                }
                                else
                                {
                                    if (MainMenu.Instance.otherPlayerPings.ContainsKey(PlayerID))
                                    {
                                        MainMenu.Instance.otherPlayerPings[PlayerID] = new MarkPickup(pu.transform, pu.item.name, pu.item.Rarity);
                                    }
                                    else
                                    {
                                        MainMenu.Instance.otherPlayerPings.Add(PlayerID, new MarkPickup(pu.transform, pu.item.name, pu.item.Rarity));
                                    }
                                }
                            }
                            break;
                        }
                    }
                    else if (cmdIndex == 37)    //create ping for enemy
                    {
                        if (GameSetup.IsMpServer)
                        {
                            string PlayerID = r.ReadString();
                            ulong  EnemyID  = r.ReadUInt64();
                            if (EnemyManager.hostDictionary.ContainsKey(EnemyID))
                            {
                                var enemy = EnemyManager.hostDictionary[EnemyID];
                                using (MemoryStream answerStream = new MemoryStream())
                                {
                                    using (BinaryWriter w = new BinaryWriter(answerStream))
                                    {
                                        w.Write(36);
                                        w.Write(PlayerID);
                                        w.Write(0);
                                        w.Write(EnemyID);
                                        w.Write(enemy._rarity != EnemyProgression.EnemyRarity.Normal);
                                        w.Write(enemy.EnemyName);
                                        w.Close();
                                    }
                                    NetworkManager.SendLine(answerStream.ToArray(), NetworkManager.Target.Everyone);
                                    answerStream.Close();
                                }
                            }
                        }
                    }
                    else if (cmdIndex == 38)    //spark of light after darkness callback to clients
                    {
                        if (GameSetup.IsMpClient)
                        {
                            string PlayerID = r.ReadString();
                            if (ModReferences.ThisPlayerID == PlayerID)
                            {
                                Vector3 pos = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                                SpellActions.CastBallLightning(pos, Vector3.down);
                            }
                        }
                    }
                    else if (cmdIndex == 39)    //archangel bow hit a player
                    {
                        var s = r.ReadString();
                        if (ModReferences.ThisPlayerID == s)
                        {
                            BuffDB.AddBuff(25, 91, r.ReadSingle(), 30);
                            BuffDB.AddBuff(9, 92, 1.35f, 30);
                            ModdedPlayer.instance.damageAbsorbAmounts[2] = r.ReadSingle();
                        }
                    }
                    else if (cmdIndex == 40)    //buff a player by ID
                    {
                        var s = r.ReadString();
                        if (ModReferences.ThisPlayerID == s)
                        {
                            BuffDB.AddBuff(r.ReadInt32(), r.ReadInt32(), r.ReadSingle(), r.ReadSingle());
                        }
                    }
                    else if (cmdIndex == 41)    //buff a player by distance
                    {
                        var vector = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
                        var dist   = r.ReadSingle();
                        if ((vector - LocalPlayer.Transform.position).sqrMagnitude <= dist * dist)
                        {
                            BuffDB.AddBuff(r.ReadInt32(), r.ReadInt32(), r.ReadSingle(), r.ReadSingle());
                        }
                    }
                    else if (cmdIndex == 42)    //buff all players globally
                    {
                        BuffDB.AddBuff(r.ReadInt32(), r.ReadInt32(), r.ReadSingle(), r.ReadSingle());
                    }
                    r.Close();
                }
                stream.Close();
            }
        }