Пример #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 ;
        }
    }