/// <summary> /// Executes this command /// </summary> public override void Execute() { List <string> sb = new List <string>(); bool wantsSellSheet = Subject == null || string.IsNullOrWhiteSpace(Subject.ToString()) || Subject.ToString() != "buy"; if (Target == null) { RenderError("There is no merchant in that direction."); return; } INonPlayerCharacter merchant = (INonPlayerCharacter)Target; if (merchant == null || (!merchant.DoIBuyThings() && !merchant.DoISellThings())) { RenderError("There is no merchant in that direction."); return; } string errorMessage; if (wantsSellSheet) { errorMessage = merchant.RenderInventory(Actor); } else { errorMessage = merchant.RenderPurchaseSheet(Actor); } if (!string.IsNullOrWhiteSpace(errorMessage)) { RenderError(errorMessage); } }
/// <summary> /// Executes this command /// </summary> internal override bool ExecutionBody() { INonPlayerCharacter merchant = (INonPlayerCharacter)Subject; if (merchant == null || !merchant.DoIBuyThings()) { RenderError("There is no merchant that buys items in that direction."); return(false); } IInanimate thing = (IInanimate)Target; if (Target == null) { RenderError("That item does not exist."); return(false); } int price = merchant.HaggleCheck(thing); if (price <= 0) { RenderError("The merchant will not buy that item."); return(false); } string errorMessage = merchant.MakePurchase((IMobile)Actor, thing, price); if (!string.IsNullOrWhiteSpace(errorMessage)) { RenderError(errorMessage); } ILexicalParagraph toActor = new LexicalParagraph(string.Format("You sell a $T$ to $S$ for {0}blz.", price)); ILexicalParagraph toArea = new LexicalParagraph("$A$ sells an item to $S$."); //TODO: language outputs Message messagingObject = new Message(toActor) { ToOrigin = new List <ILexicalParagraph> { toArea } }; messagingObject.ExecuteMessaging(Actor, merchant, thing, OriginLocation.CurrentZone, null); return(true); }
/// <summary> /// Executes this command /// </summary> internal override bool ExecutionBody() { IInanimate thing = (IInanimate)Subject; if (Target == null) { RenderError("There is no merchant in that direction."); return(false); } INonPlayerCharacter merchant = (INonPlayerCharacter)Target; if (merchant == null || (!merchant.DoIBuyThings())) { RenderError("There is no merchant that buys items in that direction."); return(false); } int price = merchant.HaggleCheck(thing); if (price <= 0) { RenderError("The merchant will not buy that item."); return(false); } ILexicalParagraph toActor = new LexicalParagraph(string.Format("The merchant appraises your {0} at {1}blz.", thing.GetDescribableName(Actor), price)); ILexicalParagraph toArea = new LexicalParagraph("$T$ looks very closely at $A$'s $S$."); //TODO: language outputs Message messagingObject = new Message(toActor) { ToOrigin = new List <ILexicalParagraph> { toArea } }; messagingObject.ExecuteMessaging(Actor, thing, merchant, OriginLocation.CurrentZone, null); return(true); }