protected override void Respawn()
        {
            base.Respawn();
            try
            {
                ModdedPlayer.ResetAllStats();
                CustomBowBase.baseBow  = null;
                CustomBowBase.baseBowC = null;
                GreatBow.instance      = null;
            }
            catch (Exception e)
            {
                ModAPI.Log.Write(e.ToString());
            }

            ModReferences.rightHandTransform = null;

            ModdedPlayer.instance.ExpCurrent              = 0;
            ModdedPlayer.instance.NewlyGainedExp          = 0;
            ModdedPlayer.instance.MassacreKills           = 0;
            ModdedPlayer.instance.MassacreMultipier       = 1;
            ModdedPlayer.instance.TimeUntillMassacreReset = 0;
            ModdedPlayer.instance.InitializeHandHeld();
            BlackFlame.instance.Start();
        }
Beispiel #2
0
        protected override void Respawn()
        {
            base.Respawn();
            try
            {
                ModdedPlayer.ResetAllStats();
                CustomBowBase.baseBow  = null;
                CustomBowBase.baseBowC = null;
                GreatBow.instance      = null;
            }
            catch (Exception e)
            {
                ModAPI.Log.Write(e.ToString());
            }

            ModReferences.rightHandTransform = null;

            ModdedPlayer.instance.ExpCurrent              = 0;
            ModdedPlayer.instance.NewlyGainedExp          = 0;
            ModdedPlayer.instance.MassacreKills           = 0;
            ModdedPlayer.instance.MassacreMultiplier      = 1;
            ModdedPlayer.instance.TimeUntillMassacreReset = 0;
            ModdedPlayer.instance.AfterRespawn();
            BlackFlame.instance.Start();
            if (GameSetup.IsMultiplayer)
            {
                using (MemoryStream answerStream = new MemoryStream())
                {
                    using (BinaryWriter w = new BinaryWriter(answerStream))
                    {
                        w.Write(19);
                        w.Write(ModReferences.ThisPlayerID);
                        w.Write(ModdedPlayer.instance.level);
                    }
                    NetworkManager.SendLine(answerStream.ToArray(), NetworkManager.Target.Others);
                }
            }
        }
        public override void fireProjectile()
        {
            int repeats = ModdedPlayer.RangedRepetitions();

            ChampionsOfForest.COTFEvents.Instance.OnAttackRanged.Invoke();

            for (int i = 0; i < repeats; i++)
            {
                bool noconsume = ModdedPlayer.Stats.perk_projectileNoConsumeChance >= 0 && Random.value < ModdedPlayer.Stats.perk_projectileNoConsumeChance;
                if (noconsume || LocalPlayer.Inventory.RemoveItem(_ammoItemId, 1, false, true))
                {
                    Vector3 position = _ammoSpawnPos.transform.position;
                    if (i > 0)
                    {
                        position += 0.5f * _ammoSpawnPos.transform.up * (i + 1) / 3;
                        position += 0.5f * _ammoSpawnPos.transform.right * (((i - 1) % 3) - 1);
                    }
                    Quaternion rotation = _ammoSpawnPos.transform.rotation;
                    if (ForestVR.Enabled)
                    {
                        position = _ammoSpawnPosVR.transform.position;
                        rotation = _ammoSpawnPosVR.transform.rotation;
                    }
                    GameObject gameObject = Object.Instantiate(_Ammo, position, rotation);
                    gameObject.transform.localScale *= ModdedPlayer.Stats.projectileSize;

                    Rigidbody component  = gameObject.GetComponent <Rigidbody>();
                    rockSound component2 = gameObject.GetComponent <rockSound>();
                    if ((bool)component2)
                    {
                        component2.slingShot = true;
                    }
                    if (BoltNetwork.isRunning)
                    {
                        BoltEntity component3 = gameObject.GetComponent <BoltEntity>();
                        if ((bool)component3)
                        {
                            BoltNetwork.Attach(gameObject);
                        }
                    }
                    PickUp componentInChildren = gameObject.GetComponentInChildren <PickUp>();
                    if ((bool)componentInChildren)
                    {
                        SheenBillboard[] componentsInChildren = gameObject.GetComponentsInChildren <SheenBillboard>();
                        SheenBillboard[] array = componentsInChildren;
                        foreach (SheenBillboard sheenBillboard in array)
                        {
                            sheenBillboard.gameObject.SetActive(false);
                        }
                        componentInChildren.gameObject.SetActive(false);
                        if (base.gameObject.activeInHierarchy)
                        {
                            base.StartCoroutine(enablePickupTrigger(componentInChildren.gameObject));
                        }
                    }
                    Vector3 forward = _ammoSpawnPos.transform.forward;
                    if (ForestVR.Enabled)
                    {
                        forward = _ammoSpawnPosVR.transform.forward;
                    }
                    component.AddForce(4000f * ModdedPlayer.Stats.projectileSpeed * (0.016666f / Time.fixedDeltaTime) * forward);
                }
            }
        }
Beispiel #4
0
 void Awake()
 {
     instance = this;
 }
Beispiel #5
0
        public IEnumerator AsyncCrossbowFire(int _ammoId, GameObject _ammoSpawnPosGo, GameObject _boltProjectile, crossbowController cc)
        {
            int        repeats          = ModdedPlayer.RangedRepetitions();
            Vector3    updir            = _ammoSpawnPosGo.transform.up;
            Vector3    right            = _ammoSpawnPosGo.transform.right;
            Vector3    positionOriginal = _ammoSpawnPosGo.transform.position;
            Quaternion rotation         = _ammoSpawnPosGo.transform.rotation;
            Vector3    forceUp          = Vector3.zero;
            bool       noconsume        = ModdedPlayer.Stats.perk_projectileNoConsumeChance > 0 && Random.value < ModdedPlayer.Stats.perk_projectileNoConsumeChance;

            for (int i = 0; i < repeats; i++)
            {
                if (noconsume || LocalPlayer.Inventory.RemoveItem(_ammoId, 1, true, true))
                {
                    Vector3 position = positionOriginal;
                    if (i > 0)
                    {
                        position += 0.5f * updir * Mathf.Sin((i / 2f) * Mathf.PI) / 3;
                        position += 0.4f * right * (((i) % 3) - 2);
                    }

                    GameObject gameObject = Object.Instantiate(_boltProjectile, position, rotation);
                    gameObject.transform.localScale *= ModdedPlayer.Stats.projectileSize;
                    gameObject.layer = 19;
                    Physics.IgnoreLayerCollision(19, 19, true);
                    if (i > 0)
                    {
                        float dmgPen = Mathf.Pow(ModdedPlayer.Stats.perk_multishotDamagePennalty, i);
                        gameObject.SendMessage("ModifyStartingDamage", dmgPen, SendMessageOptions.DontRequireReceiver);
                    }
                    Rigidbody component = gameObject.GetComponent <Rigidbody>();
                    component.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
                    if (BoltNetwork.isRunning)
                    {
                        BoltEntity component2 = gameObject.GetComponent <BoltEntity>();
                        if ((bool)component2)
                        {
                            BoltNetwork.Attach(gameObject);
                        }
                    }
                    PickUp componentInChildren = gameObject.GetComponentInChildren <PickUp>(true);
                    if ((bool)componentInChildren)
                    {
                        SheenBillboard[] componentsInChildren = gameObject.GetComponentsInChildren <SheenBillboard>();
                        SheenBillboard[] array = componentsInChildren;
                        foreach (SheenBillboard sheenBillboard in array)
                        {
                            sheenBillboard.gameObject.SetActive(false);
                        }
                        componentInChildren.gameObject.SetActive(false);
                        if (gameObject.activeInHierarchy)
                        {
                            cc.SendMessage("PublicEnablePickupTrigger", componentInChildren.gameObject);
                        }
                    }
                    if (i == 0)
                    {
                        forceUp = gameObject.transform.up;
                    }
                    Vector3 force = 22000f * ModdedPlayer.Stats.projectileSpeed * (0.016666f / Time.fixedDeltaTime) * forceUp;
                    if (ModdedPlayer.Stats.spell_bia_AccumulatedDamage > 0)
                    {
                        gameObject.transform.localScale *= 2f;
                        force *= 2f;
                        component.useGravity = false;
                        if (ModReferences.bloodInfusedMaterial == null)
                        {
                            ModReferences.bloodInfusedMaterial = BuilderCore.Core.CreateMaterial(new BuilderCore.BuildingData()
                            {
                                EmissionColor = new Color(0.6f, 0.1f, 0),
                                renderMode    = BuilderCore.BuildingData.RenderMode.Fade,
                                MainColor     = Color.red,
                                Metalic       = 1f,
                                Smoothness    = 0.9f,
                            });
                        }
                        //gameObject.GetComponent<Renderer>().material = bloodInfusedMaterial;
                        var trail = gameObject.AddComponent <TrailRenderer>();
                        trail.widthCurve      = new AnimationCurve(new Keyframe[] { new Keyframe(0f, 1f, 0f, 0f), new Keyframe(0.5f, 1f, 0f, 0f), new Keyframe(1f, 0.006248474f, 0f, 0f), });
                        trail.material        = ModReferences.bloodInfusedMaterial;
                        trail.widthMultiplier = 0.55f;
                        trail.time            = 1.25f;
                    }
                    component.AddForce(force);
                }
                else
                {
                    break;
                }
                if (i % 2 == 1)
                {
                    yield return(null);
                }
            }
        }
Beispiel #6
0
        public IEnumerator AsyncRangedFire(PlayerInventory inv, float _weaponChargeStartTime, InventoryItemView inventoryItemView, InventoryItemView inventoryItemView2, bool noconsume)
        {
            TheForest.Items.Item itemCache = inventoryItemView.ItemCache;
            bool       flag        = itemCache._maxAmount < 0;
            int        repeats     = ModdedPlayer.RangedRepetitions();
            Vector3    forceUp     = inventoryItemView2._held.transform.up;
            Vector3    right       = inventoryItemView2._held.transform.right;
            Vector3    up          = inventoryItemView2._held.transform.up;
            Vector3    originalPos = inventoryItemView2._held.transform.position;
            FakeParent component   = inventoryItemView2._held.GetComponent <FakeParent>();
            Quaternion rotation    = inventoryItemView2._held.transform.rotation;

            TheForest.Items.Item itemCache2 = inventoryItemView2.ItemCache;
            for (int i = 0; i < repeats; i++)
            {
                if (noconsume)
                {
                    Vector3 pos = originalPos;
                    if (i > 0)
                    {
                        // pos += 0.5f * up * (i + 1) / 3;
                        pos += 0.5f * right * (((i - 1) % 3) - 1);
                    }

                    GameObject projectileObject = (!(bool)component || component.gameObject.activeSelf) ? Object.Instantiate(itemCache2._ammoPrefabs.GetPrefabForBonus(inventoryItemView.ActiveBonus, true).gameObject, pos, rotation) : Object.Instantiate(itemCache2._ammoPrefabs.GetPrefabForBonus(inventoryItemView.ActiveBonus, true).gameObject, pos, rotation);

                    projectileObject.transform.localScale *= ModdedPlayer.Stats.projectileSize;


                    try
                    {
                        projectileObject.transform.GetChild(0).gameObject.layer = 19;
                    }
                    catch (System.Exception)
                    {
                        throw;
                    }
                    projectileObject.layer = 19;
                    Physics.IgnoreLayerCollision(19, 19, true);
                    if (noconsume)
                    {
                        GameObject.Destroy(projectileObject, 40f);
                    }
                    else
                    {
                        if (i >= 4)
                        {
                            GameObject.Destroy(projectileObject, 40);                                     //if spamming arrows, delete 4th and further after really short time
                        }
                    }
                    if ((bool)projectileObject.GetComponent <Rigidbody>())
                    {
                        if (itemCache.MatchRangedStyle(TheForest.Items.Item.RangedStyle.Shoot))
                        {
                            projectileObject.GetComponent <Rigidbody>().AddForce(projectileObject.transform.TransformDirection(Vector3.forward * (0.016666f / Time.fixedDeltaTime) * ModdedPlayer.Stats.projectileSpeed * itemCache._projectileThrowForceRange), ForceMode.VelocityChange);
                        }
                        else
                        {
                            float num = Time.time - _weaponChargeStartTime;
                            if (ForestVR.Enabled)
                            {
                                projectileObject.GetComponent <Rigidbody>().AddForce(inventoryItemView2._held.transform.up * ModdedPlayer.Stats.projectileSpeed * itemCache._projectileThrowForceRange);
                            }
                            else
                            {
                                Vector3 proj_force = forceUp * ModdedPlayer.Stats.projectileSpeed * Mathf.Clamp01(num / itemCache._projectileMaxChargeDuration) * (0.016666f / Time.fixedDeltaTime) * itemCache._projectileThrowForceRange;
                                var     proj_rb    = projectileObject.GetComponent <Rigidbody>();
                                proj_rb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
                                var col = projectileObject.GetComponent <CapsuleCollider>();
                                if (col)
                                {
                                    col.height *= ModdedPlayer.Stats.projectileSpeed;
                                }
                                else
                                {
                                    Debug.LogError("No capsule collider on projectile");
                                }
                                if (GreatBow.isEnabled)
                                {
                                    proj_force        *= 1.1f;
                                    proj_rb.useGravity = false;
                                }
                                if (ModdedPlayer.Stats.spell_bia_AccumulatedDamage > 0)
                                {
                                    proj_force        *= 1.1f;
                                    proj_rb.useGravity = false;
                                    if (ModReferences.bloodInfusedMaterial == null)
                                    {
                                        ModReferences.bloodInfusedMaterial = BuilderCore.Core.CreateMaterial(new BuilderCore.BuildingData()
                                        {
                                            EmissionColor = new Color(0.6f, 0.1f, 0),
                                            renderMode    = BuilderCore.BuildingData.RenderMode.Opaque,
                                            MainColor     = Color.red,
                                            Metalic       = 1f,
                                            Smoothness    = 0.9f,
                                        });
                                    }
                                    var trail = projectileObject.AddComponent <TrailRenderer>();
                                    trail.widthCurve      = new AnimationCurve(new Keyframe[] { new Keyframe(0f, 1f, 0f, 0f), new Keyframe(0.5f, 1f, 0f, 0f), new Keyframe(1f, 0.006248474f, 0f, 0f), });
                                    trail.material        = ModReferences.bloodInfusedMaterial;
                                    trail.widthMultiplier = 0.45f;
                                    trail.time            = 1.25f;
                                    trail.autodestruct    = false;
                                }
                                if (i > 0)
                                {
                                    float dmgPen = 1;
                                    for (int k = 0; k < i; k++)
                                    {
                                        dmgPen *= ModdedPlayer.Stats.perk_multishotDamagePennalty.Value;
                                    }
                                    //using XBArrowDamageMod as a typename here results in erros with modapi
                                    projectileObject.SendMessage("ModifyStartingDamage", dmgPen, SendMessageOptions.DontRequireReceiver);
                                }
                                proj_rb.AddForce(proj_force);
                            }
                            if (LocalPlayer.Inventory.HasInSlot(TheForest.Items.Item.EquipmentSlot.RightHand, LocalPlayer.AnimControl._bowId))
                            {
                                projectileObject.SendMessage("setCraftedBowDamage", SendMessageOptions.DontRequireReceiver);
                            }
                        }
                        inventoryItemView._held.SendMessage("OnAmmoFired", projectileObject, SendMessageOptions.DontRequireReceiver);
                    }
                    if (itemCache._attackReleaseSFX != 0)
                    {
                        LocalPlayer.Sfx.SendMessage(itemCache._attackReleaseSFX.ToString(), SendMessageOptions.DontRequireReceiver);
                    }
                    Mood.HitRumble();
                }
                else
                {
                    if (itemCache._dryFireSFX != 0)
                    {
                        LocalPlayer.Sfx.SendMessage(itemCache._dryFireSFX.ToString(), SendMessageOptions.DontRequireReceiver);
                    }
                }
                if (i % 2 == 1)
                {
                    yield return(null);
                }
            }
            if (flag)
            {
                inv.UnequipItemAtSlot(itemCache._equipmentSlot, false, false, flag);
            }
            else
            {
                inv.ToggleAmmo(inventoryItemView, true);
            }

            yield break;
        }