Aura.Channel.Skills.Life.Fishing.StartFishing C# (CSharp) Метод

StartFishing() публичный Метод

Starts fishing with given delay.
This method uses async Tasks to control when the skill continues (basically timers). Since the player could cancel the skill before the method continues, or props could be removed because of a reload, we need to make sure not to continue and not to crash because of a change in the prop situation. TODO: Use cancellation tokens? TODO: Don't reload spawned props, but only scripted ones?
public StartFishing ( Creature creature, int delay ) : void
creature Aura.Channel.World.Entities.Creature
delay int
Результат void
		public async void StartFishing(Creature creature, int delay)
		{
			var rnd = RandomProvider.Get();
			var prop = creature.Temp.FishingProp;

			await Task.Delay(delay);

			// Check that the prop is still the same (player could have canceled
			// and restarted, spawning a new one) and the prop wasn't removed
			// from region (e.g. >reloadscripts).
			if (creature.Temp.FishingProp != prop || creature.Temp.FishingProp.Region == Region.Limbo)
				return;

			// Update prop state
			creature.Temp.FishingProp.SetState("normal");

			await Task.Delay(rnd.Next(5000, 120000));
			if (creature.Temp.FishingProp != prop || creature.Temp.FishingProp.Region == Region.Limbo)
				return;

			// Update prop state
			creature.Temp.FishingProp.SetState("hooked");

			// Get fishing drop 
			creature.Temp.FishingDrop = this.GetFishingDrop(creature, rnd);
			if (creature.Temp.FishingDrop == null)
			{
				Log.Debug("Fishing.StartFishing: No drop found.");
				return;
			}

			// Random time
			var time = 10000;
			switch (rnd.Next(4))
			{
				case 0: time = 4000; break;
				case 1: time = 8000; break;
				case 2: time = 6000; break;
				case 3: time = 10000; break;
			}

			var catchSize = CatchSize.Something;
			var fishSpeed = 1f;

			var fishData = AuraData.FishDb.Find(creature.Temp.FishingDrop.ItemId);
			if (fishData != null && fishData.SizeMin + fishData.SizeMax != 0)
				catchSize = (rnd.NextDouble() < 0.5 ? CatchSize.SmallCatch : CatchSize.BigOne);

			// Request action
			creature.Temp.FishingActionRequested = true;
			creature.Temp.CatchSize = catchSize;
			Send.FishingActionRequired(creature, catchSize, time, fishSpeed);
		}