示例#1
0
    /// <summary>
    /// Called when holding the fishing rod
    /// </summary>
    /// <param name="_data">A reference to the items inventory data.</param>
    public override void OnHoldingUpdate(ItemInventoryData _data)
    {
        // Debug
        //DisplayChatAreaText("OnHoldingUpdate");

        // Base code - no need to run it for the rod.
        //base.OnHoldingUpdate(_data);

        // Don't run this code if remote entity
        if (_data.holdingEntity.isEntityRemote)
        {
            return;
        }
        // check if the player is aiming at water
        // Check reference to local player
        if (!epLocalPlayer)
        {
            // Get and store a reference to the local player
            epLocalPlayer = GameManager.Instance.World.GetLocalPlayer();

            // Debug
            //DisplayChatAreaText("Reference to local player stored.");
        }
        try
        {
            if (!CheckWaterInRange())
            {
                if (boolAimingWater)
                {
                    boolAimingWater = false;
                    DisplayToolTipText("Man... I can't fish here...");
                    ResetFishing();
                }
                return;
            }
            else
            {
                if (!boolAimingWater)
                {
                    if (CheckAnimatorReference(_data))
                    {
                        ResetFishing();
                        if (epLocalPlayer)
                        {
                            MultiBuffClassAction multiBuffClassAction = MultiBuffClassAction.NewAction("fishingWater");
                            multiBuffClassAction.Execute(epLocalPlayer.entityId, (EntityAlive)epLocalPlayer, false,
                                                         EnumBodyPartHit.None, (string)null);
                        }
                    }
                    boolAimingWater = true;
                    DisplayToolTipText("Yea... This looks like a nice spot.");
                }
            }
        }
        catch (Exception)
        {
            DisplayChatAreaText("DEBUG: Oops something went wrong with the fishing mod.");
        }
        // Check if the player is already fishing
        if (true)
        {
            #region Hook event expired;

            if (boolFishHooked && boolAimingWater)
            {
                if (DateTime.Now > dteEndHook)
                {
                    animator.SetTrigger("stopFishing");
                    DisplayToolTipText("Shit... Whatever it was... It's gone!");
                    boolFishHooked = false;
                    dteNextAction  = DateTime.Now.AddSeconds(0.5);
                }
            }

            #endregion ;

            #region fish event expired;

            if (boolFishing && boolAimingWater)
            {
                if (DateTime.Now > dteEndFish)
                {
                    animator.SetTrigger("stopFishing");
                    if (intLoot != LootType.nothing)
                    {
                        DisplayToolTipText("Great... It's gone... Let's be faster next time, shall we?");
                    }
                    else
                    {
                        DisplayToolTipText("Oh well... Shall we try again?");
                    }
                    boolFishing   = false;
                    intLoot       = LootType.nothing;
                    dteNextAction = DateTime.Now.AddSeconds(0.5);
                }
            }

            #endregion ;

            #region Wait for bait;

            if (!boolFishHooked && !boolRodBaited && !boolBaitWait && !boolFishing && boolAimingWater)
            {
                if (DateTime.Now > dteNextAction)
                {
                    if (animator)
                    {
                        animator.SetTrigger("waitBait");
                        boolBaitWait  = true;
                        dteNextAction = DateTime.Now.AddSeconds(0.5);
                    }
                }
            }

            #endregion ;

            #region Bait rod;

            // bait rod if not already baited, no hook event present, and no loot to get.
            if (Input.GetKey(KeyCode.R) && boolAimingWater && !boolRodBaited && !boolFishHooked && boolBaitWait)
            {
                if (DateTime.Now > dteNextAction)
                {
                    ItemValue earthworm = ItemClass.GetItem("earthworm", false);
                    int       numWorms  = epLocalPlayer.bag.GetItemCount(earthworm);
                    if (numWorms >= 1)
                    {
                        bool itemGood = true;
                        // cause decay
                        if (_data.itemValue.MaxUseTimes > 0)
                        {
                            ItemValue itemValue = _data.itemValue;
                            itemValue.UseTimes += AttributeBase.GetVal <AttributeDegradationRate>(_data.itemValue, 1);
                            _data.itemValue     = itemValue;
                            if (_data.itemValue.MaxUseTimes > 0 &&
                                _data.itemValue.UseTimes >= _data.itemValue.MaxUseTimes ||
                                _data.itemValue.UseTimes == 0 && _data.itemValue.MaxUseTimes == 0)
                            {
                                // cane is broken
                                itemGood = false;
                                DisplayToolTipText("Hmm, i think i've been fishing too much... Need to fix this...");
                            }
                        }
                        if (itemGood)
                        {
                            epLocalPlayer.bag.DecItem(earthworm, 1);
                            if (animator)
                            {
                                animator.SetTrigger("stopFishing");
                                DisplayToolTipText("Alright! Got this thing baited, let's see what I get...");
                                boolRodBaited = true;
                                boolBaitWait  = false;
                            }
                            dteNextAction = DateTime.Now.AddSeconds(2);
                        }
                        else
                        {
                            dteNextAction = DateTime.Now.AddSeconds(0.5);
                        }
                    }
                    else
                    {
                        DisplayToolTipText("You don't have enough earth worms...");
                        dteNextAction = DateTime.Now.AddSeconds(0.5);
                    }
                }
            }

            #endregion ;

            #region Hook event;

            // if baited and not fish hooked...
            if (boolRodBaited && !boolFishHooked && boolAimingWater && !boolFishing)
            {
                // randomly does hook warning -> it lasts 2 seconds.
                if (DateTime.Now > dteNextAction)
                {
                    System.Random r       = new System.Random();
                    int           hookNow = r.Next(1, 101);
                    if (hookNow <= 8)
                    {
                        if (animator)
                        {
                            this.boolFishHooked = true;
                            boolRodBaited       = false; // always looses the bait here.
                            // decides what the loot will be here, to determine what time the player will have to react
                            // the rarer the loot the less time he has
                            intLoot = Choose(_data);
                            double timeToReact = numLootTypes - 2;
                            if (intLoot > 0 && intLoot != LootType.nothing)
                            {
                                timeToReact = timeToReact / intLoot.GetHashCode();
                            }
                            animator.SetTrigger("fishHook");
                            dteEndHook = DateTime.Now.AddSeconds(timeToReact);
                            //DisplayToolTipText("You've hooked something");
                            dteNextAction = DateTime.Now.AddSeconds(0.1);
                        }
                    }
                    else
                    {
                        // next possible bite will only be evaluated every one second
                        dteNextAction = DateTime.Now.AddSeconds(1);
                    }
                }
            }

            #endregion ;

            #region Hook Pull;

            // pulls the rod, decides what is the loot and waits 2 seconds...
            // if the player doesn't react, puff... Loot is gone!
            if (boolFishHooked && boolAimingWater)
            {
                if (Input.GetKey(KeyCode.Keypad1) || Input.GetKey(KeyCode.Mouse0) || Input.GetMouseButton(0))
                {
                    if (DateTime.Now > dteNextAction)
                    {
                        boolFishHooked = false;
                        if (animator)
                        {
                            animator.SetTrigger("hookPull");
                            boolFishing = true;
                            // see what was gotten, and show the proper animation
                            if (intLoot == LootType.nothing)
                            {
                                DisplayToolTipText("What the f**k? Nothing?");
                            }
                            else if (intLoot == LootType.head)
                            {
                                DisplayToolTipText("What... the... f... AAAAAAHHHHH!");
                                animator.SetTrigger("head");
                            }
                            else if (intLoot == LootType.trashBag)
                            {
                                DisplayToolTipText("YES! Got it! hmm... no? what?");
                                animator.SetTrigger("trash");
                            }
                            else if (intLoot == LootType.bigBass || intLoot == LootType.bigSalmon)
                            {
                                DisplayToolTipText("YES! That's a big one!");
                                animator.SetTrigger("bigFish");
                            }
                            else if (intLoot == LootType.salmon)
                            {
                                DisplayToolTipText("A salmon... Tasty!");
                                animator.SetTrigger("smallFish");
                            }
                            else if (intLoot == LootType.bass)
                            {
                                DisplayToolTipText("A nice looking bass fish!");
                                animator.SetTrigger("smallFish");
                            }
                            else
                            {
                                DisplayToolTipText("Better then nothing. Food is food!");
                                animator.SetTrigger("smallFish");
                            }
                            if (intLoot != LootType.nothing)
                            {
                                dteEndFish = DateTime.Now.AddSeconds(10); // 10 seconds to pick the fish up
                            }
                            else
                            {
                                dteEndFish = DateTime.Now.AddSeconds(0.5);
                            }
                        }
                        dteNextAction = DateTime.Now.AddSeconds(0.5);
                    }
                }
            }

            #endregion ;

            #region Get loot;

            // get's whatever is in the hook
            if (boolFishing && boolAimingWater)
            {
                if (Input.GetKey(KeyCode.Keypad2) || Input.GetKey(KeyCode.Mouse1) || Input.GetMouseButton(1))
                {
                    if (DateTime.Now > dteNextAction)
                    {
                        boolFishing = false;
                        if (intLoot != LootType.nothing)
                        {
                            //DisplayToolTipText("Got it... Shall we try again?");
                            //ItemValue lootItem = ItemClass.GetItem(intLoot.ToString());
                            ItemValue lootItem  = ItemClass.GetItem(intLoot.ToString(), false);
                            ItemStack lootStack = new ItemStack(lootItem, 1);
                            epLocalPlayer.bag.AddItem(lootStack);
                        }
                        //else DisplayToolTipText("Oh well... Shall we try again?");
                        ResetFishing();
                        dteNextAction = DateTime.Now.AddSeconds(0.5);
                    }
                }
            }

            #endregion ;
        }
    }
示例#2
0
    public void ShootProjectile(Transform projectileLauncher, string weaponSlotType, string soundPath, bool isGun)
    {
        //if (isGun && (!entityVehicle.HasGun() || !entityVehicle.HasGunAmmo()))
        if (isGun && !entityVehicle.HasGunAmmo())
        {
            GameManager.ShowTooltip(entityVehicle.player, "No Vehicle Gun Ammo");
            return;
        }
        //if (!isGun && (!entityVehicle.HasExplosiveLauncher() || !entityVehicle.HasExplosiveLauncherAmmo()))
        if (!isGun && !entityVehicle.HasExplosiveLauncherAmmo())
        {
            GameManager.ShowTooltip(entityVehicle.player, "No Vehicle Explosive Ammo");
            return;
        }

        ItemValue ammoItem   = entityVehicle.GetWeaponAmmoType(weaponSlotType);
        ItemStack itemStack  = new ItemStack(ammoItem, 1);
        Transform projectile = ammoItem.ItemClass.CloneModel(GameManager.Instance.World, ammoItem, Vector3.zero, null, false, false);

        if (projectileLauncher != null)
        {
            projectile.parent        = projectileLauncher;
            projectile.localPosition = Vector3.zero;
            projectile.localRotation = Quaternion.identity;
        }
        else
        {
            projectile.parent = null;
        }

        ItemValue launcherValue;

        if (isGun)
        {
            launcherValue = entityVehicle.GetGunItemValue();
            //DebugMsg("Gun: Quality = " + launcherValue.Quality.ToString() + " | UseTimes = " + launcherValue.UseTimes.ToString() + " | MaxUseTimes = " + launcherValue.MaxUseTimes.ToString() + " | GetHealthPercentage = " + entityVehicle.gunPart.GetHealthPercentage().ToString());
            // Change weapons UseTimes (degrade weapon)
            launcherValue.UseTimes += AttributeBase.GetVal <AttributeDegradationRate>(launcherValue, 1);
            entityVehicle.gunPart.SetItemValue(launcherValue);
            if (gunAmmoUILabel != null)
            {
                gunAmmoUILabel.text = (entityVehicle.uiforPlayer.xui.PlayerInventory.GetItemCount(gunAmmoItemValue.ItemClass.Id) - 1).ToString();
            }
        }
        else
        {
            launcherValue = entityVehicle.GetExplosiveLauncherItemValue();
            //DebugMsg("Explosive Launcher: Quality = " + launcherValue.Quality.ToString() + " | UseTimes = " + launcherValue.UseTimes.ToString() + " | MaxUseTimes = " + launcherValue.MaxUseTimes.ToString() + " | GetHealthPercentage = " + entityVehicle.explosiveLauncherPart.GetHealthPercentage().ToString());
            // Change weapons UseTimes (degrade weapon)
            launcherValue.UseTimes += AttributeBase.GetVal <AttributeDegradationRate>(launcherValue, 1);
            entityVehicle.explosiveLauncherPart.SetItemValue(launcherValue);
            if (explosiveAmmoUILabel != null)
            {
                explosiveAmmoUILabel.text = (entityVehicle.uiforPlayer.xui.PlayerInventory.GetItemCount(explosiveAmmoItemValue.ItemClass.Id) - 1).ToString();
            }
        }

        Utils.SetLayerRecursively(projectile.gameObject, (!(projectileLauncher != null)) ? 0 : projectileLauncher.gameObject.layer);
        BlockProjectileMoveScript blockProjectileMoveScript = projectile.gameObject.AddComponent <BlockProjectileMoveScript>();

        blockProjectileMoveScript.itemProjectile      = ammoItem.ItemClass;
        blockProjectileMoveScript.itemValueProjectile = ammoItem;
        //blockProjectileMoveScript.itemValueLauncher = ItemValue.None.Clone();
        blockProjectileMoveScript.itemValueLauncher    = launcherValue;
        blockProjectileMoveScript.itemActionProjectile = (ItemActionProjectile)((!(ammoItem.ItemClass.Actions[0] is ItemActionProjectile)) ? ammoItem.ItemClass.Actions[1] : ammoItem.ItemClass.Actions[0]);
        //blockProjectileMoveScript.AttackerEntityId = 0;
        blockProjectileMoveScript.AttackerEntityId = entityVehicle.player.entityId;

        //Vector3 target = headlightTargetPos - projectileLauncher.position;
        Ray        ray       = Camera.main.ScreenPointToRay(Input.mousePosition);
        float      rayOffset = Vector3.Distance(entityVehicle.player.GetThirdPersonCameraTransform().position, projectileLauncher.position) + 2f;
        Vector3    rayStart  = ray.GetPoint(rayOffset);
        RaycastHit hit;

        if (Physics.Raycast(rayStart, ray.direction, out hit))
        {
            //Vector3 crossHairPos = ray.GetPoint(1000);// + (Vector3.up * 20);
            //Vector3 targetScreenPos = player.playerCamera.WorldToScreenPoint(crossHairPos);     //headlightTargetPos
            blockProjectileMoveScript.Fire(projectileLauncher.position, hit.point - projectileLauncher.position, entityVehicle.player, 0);
            //blockProjectileMoveScript.Fire(projectileLauncher.position, ray.direction, player, 0);
        }
        else
        {
            Vector3 rayEnd = ray.GetPoint(200f);
            blockProjectileMoveScript.Fire(projectileLauncher.position, rayEnd - projectileLauncher.position, entityVehicle.player, 0);
        }


        //LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityVehicle.player);
        if (isGun)
        {
            ParticleEffect pe         = new ParticleEffect("nozzleflash_ak", projectileLauncher.position, Quaternion.Euler(0f, 180f, 0f), 1f, Color.white, "Pistol_Fire", projectileLauncher);
            float          lightValue = GameManager.Instance.World.GetLightBrightness(World.worldToBlockPos(projectileLauncher.position)) / 2f;
            ParticleEffect pe2        = new ParticleEffect("nozzlesmokeuzi", projectileLauncher.position, lightValue, new Color(1f, 1f, 1f, 0.3f), null, projectileLauncher, false);
            SpawnParticleEffect(pe, -1);
            SpawnParticleEffect(pe2, -1);
            //entityVehicle.playerInventory.RemoveItem(itemStack);
            //uiforPlayer.xui.PlayerInventory.RemoveItem(itemStack);
            entityVehicle.uiforPlayer.xui.PlayerInventory.RemoveItem(itemStack);
            return;
        }

        //entityVehicle.playerInventory.RemoveItem(itemStack);
        //uiforPlayer.xui.PlayerInventory.RemoveItem(itemStack);
        entityVehicle.uiforPlayer.xui.PlayerInventory.RemoveItem(itemStack);

        //if (Steam.Network.IsServer)
        {
            Audio.Manager.BroadcastPlay(projectileLauncher.position, soundPath);
        }
    }