Aura.Channel.Skills.Music.PlayingInstrument.Prepare C# (CSharp) Method

Prepare() public method

Prepares skill, goes straight to Use and starts playing.
public Prepare ( Creature creature, Skill skill, Aura.Shared.Network.Packet packet ) : bool
creature Aura.Channel.World.Entities.Creature
skill Skill
packet Aura.Shared.Network.Packet
return bool
		public bool Prepare(Creature creature, Skill skill, Packet packet)
		{
			var rnd = RandomProvider.Get();

			// Check for instrument
			if (creature.RightHand == null || creature.RightHand.Data.Type != ItemType.Instrument)
				return false;

			creature.StopMove();

			// Get instrument type
			var instrumentType = this.GetInstrumentType(creature);

			// TODO: Make db for instruments with installable props.

			// Get mml from equipped score scroll if available.
			var mml = this.GetScore(creature);

			// Random score if no usable scroll was found.
			var rndScore = (mml == null ? this.GetRandomScore(rnd) : 0);

			// Quality seems to go from 0 (worst) to 3 (best).
			// TODO: Base quality on skills and score ranks.
			// The quality was apparently changed to a value from 0 to 100
			// in the MusicQ update. We'll use the quality "rating" as fall-
			// back for the success messages and the training for now.
			var quality = rnd.Next(0, 100 + 1);

			// Sunday: Increase in success rate for instrument playing.
			// Another attempt if quality was bad, unofficial.
			if (quality < 50 && ErinnTime.Now.Month == ErinnMonth.Imbolic)
				quality = rnd.Next(0, 100 + 1);

			// Up quality by chance, based on Musical Knowledge
			var musicalKnowledgeSkill = creature.Skills.Get(SkillId.MusicalKnowledge);
			if (musicalKnowledgeSkill != null && rnd.Next(100) < musicalKnowledgeSkill.RankData.Var2)
				quality += 25;

			if (quality > 100)
				quality = 100;

			// Get quality for the effect, perfect play makes every sound perfect.
			var effectQuality = quality;
			if (ChannelServer.Instance.Conf.World.PerfectPlay)
			{
				effectQuality = 100;
				Send.ServerMessage(creature, Localization.Get("Perfect play is enabled, your performance will sound perfect."));
			}

			// Reduce scroll's durability.
			if (mml != null)
				creature.Inventory.ReduceDurability(creature.Magazine, DurabilityUse);

			// Music effect and Use
			this.StartPlay(creature, skill, instrumentType, effectQuality, mml, rndScore);
			this.OnPlay(creature, skill, quality);
			Send.SkillUsePlayingInstrument(creature, skill.Info.Id, instrumentType, mml, rndScore);
			skill.State = SkillState.Used;

			// Special motion on highest quality.
			if (quality >= 100)
				Send.UseMotion(creature, 88, 2, true);

			// Give proficiency
			if (creature.RightHand.Durability != 0)
			{
				var amount = Item.GetProficiencyGain(creature.Age, ProficiencyGainType.Music);
				creature.Inventory.AddProficiency(creature.RightHand, amount);
			}

			// Called from Complete, once the song is finished.
			creature.Skills.Callback(skill.Info.Id, () =>
			{
				Send.Notice(creature, this.GetRandomQualityMessage(quality));
				this.AfterPlay(creature, skill, quality);
			});

			return true;
		}