コード例 #1
0
 /// <summary>
 /// Creates a new caught fish view.
 /// </summary>
 /// <param name="state">The fishing state producing caught fish.</param>
 public FishCaughtView(FishingState state)
 {
     state.ActionChanged += OnActionChanged;
     state.Event         += OnFishingEvent;
 }
コード例 #2
0
    /// <summary>
    /// Moves the fishing hook and updates the finite state of the fishing rod
    /// </summary>
    private void UpdateFishingHook()
    {
        hookPrevPosition = hookPosition;

        switch (finiteState)
        {
        case FishingState.Inactive:
            // Finite state handled in CastLine(...)
            break;

        case FishingState.Casting:
            if (hookVelocity.y >= 0.0f)
            {
                hookVelocity = new Vector2(0.0f, 2.0f);
                finiteState  = FishingState.Rising;
            }
            else
            {
                if (hookPosition.y > transform.position.y - 2.0f)
                {
                    hookVelocity += new Vector2(0.0f, -4.0f) * Time.deltaTime;
                }

                hookPosition += hookVelocity * Time.deltaTime;
                hookVelocity -= hookVelocity.normalized * 3.0f * Time.deltaTime;     // Reduces velocity by 1.0 per second

                if (hookPosition.x < -2.1f)
                {
                    hookPosition.x  = -2.1f;
                    hookVelocity.x *= -0.8f;
                    hookVelocity.y *= 0.8f;
                }
                else if (hookPosition.x > 2.7f)
                {
                    hookPosition.x  = 2.7f;
                    hookVelocity.x *= -0.8f;
                    hookVelocity.y *= 0.8f;
                }

                if (hookPosition.y < -68.0f)
                {
                    hookPosition.y = -68.0f;
                    hookVelocity.y = 0.0f;
                }
            }
            break;

        case FishingState.Rising:
            hookVelocity = hookVelocity * 0.9f
                           + new Vector2(0.0f, 2.0f) * 0.1f;
            if (hookPosition.y > transform.position.y - 1.0f)
            {
                Catch newCatch = new Catch();
                foreach (GameObject fish in hookedFish)
                {
                    // collect money for fish
                    FishMovement fishComp = fish.GetComponent <FishMovement>();
                    fishComp.goldManager.ReturnGoldByWeight(fish.GetComponent <Fish>().type, fishComp.fishWeight);

                    // get fish weight and add it to fish object
                    Fish fishData = fish.GetComponent <Fish>();
                    fishData.weight = fishComp.fishWeight;

                    // add fish obj to catch
                    newCatch.fish.Add(fish.GetComponent <Fish>());

                    // get rid of caught fish from scene
                    Destroy(fish);
                    vfxMachine.GetComponent <fishReeled>().Begin("", new Vector3(0.0f, 0.0f, 0.0f));
                    //WaitForSeconds (0.1f);
                }
                FishmongerFile.UpdateFishmongerFile(newCatch);
                hookedFish.Clear();

                hookPosition = hookInactivePosition;
                finiteState  = FishingState.Inactive;
            }
            else
            {
                hookPosition += hookVelocity * Time.deltaTime;
                HandleFishCollision();
                for (int i = 0; i < hookedFish.Count; i++)
                {
                    hookedFish[i].transform.position = hookPosition + new Vector2(0.0f, -0.2f);
                }
            }
            break;
        }

        fishingHook.transform.position = hookPosition;
    }
コード例 #3
0
ファイル: Program.cs プロジェクト: vhytyk/fishing
 public static void LogStatus(FishingState state)
 {
     LogStatus($"status - {state}");
 }
コード例 #4
0
ファイル: FishingScript.cs プロジェクト: wampirr/IceFlake
        public override void OnTick()
        {
            if (!Manager.ObjectManager.IsInGame)
            {
                return;
            }

            if ((DateTime.Now - SleepTimer).TotalMilliseconds < 200)
            {
                return;
            }
            SleepTimer = DateTime.Now;

            switch (CurrentState)
            {
            case FishingState.Lure:
                //if (!HasBait)
                //{
                //    // Implement applying lure
                //}
                ProfessionInfo fish = API.Profession.Fishing;
                if (fish != null)
                {
                    if (fish.Level >= (fish.MaxLevel - 25) && fish.MaxLevel < 450)
                    {
                        CurrentState = FishingState.Training;
                        return;
                    }
                }
                CurrentState = FishingState.Cast;
                break;

            case FishingState.Cast:
                Print("Casting Fishing Pole");
                Fishing.Cast();
                CurrentState = FishingState.Fishing;
                break;

            case FishingState.Fishing:
                if (IsFishing)
                {
                    if (IsBobbing)
                    {
                        CurrentState = FishingState.Loot;
                    }
                }
                else
                {
                    CurrentState = FishingState.Lure;
                }
                break;

            case FishingState.Loot:
                Print("Getting Fishing Bobber");
                Bobber.Interact();
                LootTimer    = DateTime.Now;
                CurrentState = FishingState.Looting;
                break;

            case FishingState.Looting:
                TimeSpan span = DateTime.Now - LootTimer;
                if (span.TotalSeconds > 3)
                {
                    Print("No loot? Back to fishing then!");
                    CurrentState = FishingState.Lure;
                }
                break;

            // TODO: Clean up, add dynamic fishing trainer locator.
            case FishingState.Training:
                if (Trainer == null || !Trainer.IsValid)
                {
                    // Marcia Chase, Dalaran - Neutral.
                    Trainer =
                        Manager.ObjectManager.Objects.Where(x => x.IsValid && x.IsUnit)
                        .OfType <WoWUnit>()
                        .FirstOrDefault(u => u.Entry == 28742);
                    return;
                }

                if (Trainer.Distance > 6f)
                {
                    if (Manager.Movement.Destination == Trainer.Location)
                    {
                        Sleep(100);
                    }
                    Manager.Movement.PathTo(Trainer.Location);
                    return;
                }

                if (!API.Gossip.IsShown && !API.Trainer.IsShown)
                {
                    Trainer.Interact();
                    return;
                }

                if (API.Gossip.IsShown)
                {
                    GossipOption opt = API.Gossip.Options.FirstOrDefault(g => g.Gossip == GossipType.Trainer);
                    if (opt != null)
                    {
                        opt.Select();
                    }
                    return;
                }

                if (API.Trainer.IsShown)
                {
                    API.Trainer.BuyAllAvailable();
                    Fishing = null;
                    Manager.Spellbook.Update = true;
                    CurrentState             = FishingState.Lure;
                    return;
                }

                CurrentState = FishingState.Lure;

                break;
            }
        }
コード例 #5
0
        // Update is called once per frame
        void Update()
        {
            switch (fishingState)
            {
            // If looking for fish, update our fish check timer, and if it's reached the check time, check for a fish!
            case FishingState.Looking:
                if (fishCheckTimer < fishCheckUpdate)
                {
                    fishCheckTimer += Time.deltaTime;
                }
                else
                {
                    CheckForFish();
                }
                break;

            // Once we found a fish and notify player, track a window. If the player doesn't press the button in time, the fish escapes!
            case FishingState.Hooking:
                if (escapeTimer < escapeWindow)
                {
                    escapeTimer += Time.deltaTime;
                }
                else
                {
                    FishEscaped();
                }
                break;

            // Okay, fish is getting reeled in!
            case FishingState.Reeling:
                AdjustReel();     // Timestep our current reeling power
                // And our reel power is in the fishy catch zone
                if (reelMin < reelPower && reelPower < reelMax)
                {
                    // Add to the catch timer if we haven't reached the catch count
                    if (catchTimer < escapeWindow)
                    {
                        catchTimer += reelSpeed * Time.deltaTime;
                    }
                    // Or if we have: CATCH DAT FISH
                    else
                    {
                        FishCaught();
                    }
                }
                // If we aren't in the catch zone...
                else
                {
                    fishingState = FishingState.Escaping; // Swap state to fish escaping
                    escapeTimer  = 0f;                    // Reset our escape timer so it starts escaping again
                }
                break;

            // If fish is currently escaping
            case FishingState.Escaping:
                AdjustReel();     // Timestep our current reeling power
                // But we got in the catch zone!
                if (reelMin < reelPower && reelPower < reelMax)
                {
                    fishingState = FishingState.Reeling;     // Swap to catching the fish!
                }
                // Otherwise if we haven't reached the end of escape timer...
                else if (escapeTimer < escapeWindow)
                {
                    escapeTimer += reelSpeed * Time.deltaTime;     // Add to the escape timer
                }
                // Otherwise if we have reached the end
                else
                {
                    FishEscaped();     // The fish is freeeee
                }
                break;
            }
        }
コード例 #6
0
 private void ChangeState(FishingState state)
 {
     m_currState = state;
 }
コード例 #7
0
 public void FishEscaped()
 {
     fishingState = FishingState.Escaped;
     Debug.Log("Fish escaped...");
     StopFishing();
 }
コード例 #8
0
 public SetFishingState(FishingState state)
 {
     State = state;
 }
コード例 #9
0
ファイル: Fishing.cs プロジェクト: trananh1992/MapleStoryBot
        public void Start()
        {
            Console.WriteLine("Starting JC MS2 Fishing Bot v2.2se");
            Console.WriteLine("Limited edition build!");
            Console.WriteLine("Make sure your game resolution is 1280x960");
            Console.WriteLine("Make sure your interface size is 50");
            Console.Write("Would you like to use 3hr Lures on the R key? (y/n): ");
            string input = Console.ReadLine();

            if (input.StartsWith("y"))
            {
                Console.WriteLine("I will use Lures using the R key every 3 hours.");
                UseLure = false;
            }
            else
            {
                Console.WriteLine("Lures disabled.");
                UseLure = true;
            }

            Console.WriteLine("Once you cast your line, I will take over");

            float testpercent = getFishProgress();

            while (testpercent == 0)
            {
                Thread.Sleep(1000);
                testpercent = getFishProgress();
            }
            Console.WriteLine(DateTime.Now.ToString("h:mm:ss tt") + " STARTING");
            if (UseLure)
            {
                new Thread(UseLureThread).Start();
            }
            while (true)
            {
                Thread.Sleep(20);
                float percent;
                float bob;
                switch (fishingState)
                {
                case FishingState.NotCast:
                    if (!ms2.Ms2Focus())
                    {
                        ms2.WaitGameToFront();
                        Thread.Sleep(2000);
                    }
                    percent = getFishProgress();

                    if (percent > 0)
                    {
                        fishingState = FishingState.FindingFish;
                    }
                    else
                    {
                        ms2.input.SendKey(Keys.Space, KeyState.Down);
                        Thread.Sleep(300);
                        ms2.input.SendKey(Keys.Space, KeyState.Up);
                        Thread.Sleep(500);
                    }

                    break;

                case FishingState.FindingFish:
                    percent = getFishProgress();
                    if (percent == 0)
                    {
                        Thread.Sleep(400);
                        bob = getBobberLocation();
                        if (bob == -1)
                        {
                            fishAttempts += 1;
                            Console.WriteLine(DateTime.Now.ToString("h:mm:ss tt") + " fishing attempts: " + fishAttempts);
                            fishingState = FishingState.NotCast;
                            Thread.Sleep(1000);
                        }
                        else
                        {
                            fishGames += 1;
                            Console.WriteLine(DateTime.Now.ToString("h:mm:ss tt") + " CATCHING!!! fish games so far: " + fishGames);
                            fishingState = FishingState.CatchingFish;
                        }
                    }
                    break;

                case FishingState.CatchingFish:
                    bob = getBobberLocation();
                    if (bob > 0)
                    {
                        if (bob > .45)
                        {
                            ms2.input.SendKey(Keys.Space, KeyState.Down);
                            Thread.Sleep(50);
                            ms2.input.SendKey(Keys.Space, KeyState.Up);
                            Thread.Sleep(100);
                        }
                    }
                    else
                    {
                        fishingState = FishingState.NotCast;
                    }

                    break;
                }
            }
        }
コード例 #10
0
 /// <summary>
 /// Creates a new eaten fish view.
 /// </summary>
 /// <param name="state">The fishing state producing eaten fish.</param>
 public FishEatenView(FishingState state)
 {
     _fishes      = new Dictionary <Fish, IAnimation>();
     state.Event += OnFishingEvent;
 }
コード例 #11
0
        void SetState(FishingState newState)
        {
            Debug.Log("set fishing state to " + newState);

            // Remove any looping clips
            loopingClipName = null;

            // Enable/disable stuff
            if (newState == FishingState.StartFishing)
            {
                // Set control locks
                ControlTypes locks = ControlTypes.All ^ ControlTypes.QUICKLOAD;
                InputLockManager.SetControlLock(locks, "Fishing");

                // Hide navball
                navballToggled = NavBallToggle.Instance.panel.expanded;
                if (navballToggled)
                {
                    NavBallToggle.Instance.panel.Collapse();
                }
            }
            // Undo what we did
            else if (newState == FishingState.NotFishing)
            {
                // Clear the locks
                InputLockManager.RemoveControlLock("Fishing");

                // Restore navball
                if (navballToggled && NavBallToggle.Instance != null)
                {
                    NavBallToggle.Instance.panel.Expand();
                }

                // Remove the fishing pole
                Destroy(fishingPole);

                if (evaVessel != null)
                {
                    // Set the animation back to the idle one
                    KerbalEVA eva = evaVessel.GetComponent <KerbalEVA>();
                    animation.Stop();
                    animation.Play(eva.Animations.idle.animationName);

                    // Update the fishing module record
                    ModuleFishing mFishing = evaVessel.GetComponent <ModuleFishing>();
                    if (mFishing != null)
                    {
                        mFishing.fishRecord = fishingData.BiggestFish(evaVessel.mainBody);
                        mFishing.fishCount  = fishingData.FishCount(evaVessel.mainBody);
                    }
                }
            }

            // Calculate the camera start position
            if (newState == FishingState.StartFishing)
            {
                Vector3 cameraRelPos = FlightCamera.fetch.transform.position - evaVessel.transform.position;
                Vector3 projection   = Vector3.ProjectOnPlane(cameraRelPos, evaVessel.transform.up);
                startAngle  = (float)Math.Acos(Vector3.Dot(projection.normalized, evaVessel.transform.forward));
                startHeight = Vector3.Dot(cameraRelPos, evaVessel.transform.up);
                double x = Vector3.Dot(cameraRelPos, evaVessel.transform.right);
                double y = Vector3.Dot(cameraRelPos, evaVessel.transform.forward);
                startDist = (float)Math.Sqrt(x * x + y * y);

                cameraZoomTime = defaultCameraZoomTime;
                if (Math.Abs(startAngle - cameraAngle) / minAngularVelocity < cameraZoomTime)
                {
                    cameraZoomTime = Math.Abs(startAngle - cameraAngle) / minAngularVelocity;
                }
                if (cameraZoomTime != defaultCameraZoomTime && Math.Abs(startHeight - cameraHeight) / maxZoomVelocity > cameraZoomTime)
                {
                    cameraZoomTime = Math.Min(defaultCameraZoomTime, Math.Abs(startHeight - cameraHeight) / maxZoomVelocity);
                }
                if (cameraZoomTime != defaultCameraZoomTime && Math.Abs(startDist - cameraDist) / maxZoomVelocity > cameraZoomTime)
                {
                    cameraZoomTime = Math.Min(defaultCameraZoomTime, Math.Abs(startDist - cameraDist) / maxZoomVelocity);
                }
            }

            // Play the idle animation
            if (newState == FishingState.Idle)
            {
                KerbalEVA eva = evaVessel.GetComponent <KerbalEVA>();
                animation.Stop();
                animation.Play(eva.Animations.idle.animationName);
            }
            // Play the casting animation
            else if (newState == FishingState.Casting)
            {
                // Set the casting animation
                animation.Stop();
                animation.Play("fishingCasting");

                // Start at the zero distance when casting
                bobDistance = 0.0f;
            }
            // Reeling animation
            else if (newState == FishingState.Reeling)
            {
                // Set the casting animation
                loopingClipStart = Time.time;
                loopingClipTime  = 4.0f;
                loopingClipName  = "fishingReeling";
                animation.Stop();
            }
            // Hooked animation
            else if (newState == FishingState.Hooked)
            {
                animation.Stop();
            }
            else if (newState == FishingState.Caught)
            {
                animation.Stop();
                animation.Play("fishingCaught");
            }

            // Decide if a fish will be caught on this cast, and when
            if (newState == FishingState.Reeling)
            {
                double catchChance = (SportsScenario.Instance.failedAttempts + 1) / 5.0;
                if (catchChance >= 1.0 || rand.NextDouble() < catchChance)
                {
                    fishHookDistance = (float)rand.NextDouble() * 0.55f + 0.25f;
                }
                else
                {
                    fishHookDistance = -1.0f;
                }
            }

            // Center the rod when we hook a fish
            if (newState == FishingState.Hooked)
            {
                rodPosition      = 0.5f;
                rodLeeway        = 0.0f;
                fishHookDistance = -1.0f;
            }

            // Caught a fish, record it
            if (newState == FishingState.Caught)
            {
                fishingData.CaughtFish(evaVessel.mainBody, currentFish);
                fishingData.IncreaseSkill(caughtSkillIncrease);
            }

            stateStartTime = Time.fixedTime;
            lCtrlTime      = rCtrlTime = 0.0;
            fishingState   = newState;
        }