/// <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.DoISellThings()) { RenderError("There is no merchant that sells items in that direction."); return(false); } IInanimate thing = (IInanimate)Target; if (Target == null) { RenderError("The merchant does not sell that item."); return(false); } int price = merchant.PriceCheck(thing, true); if (price <= 0) { RenderError("The merchant will not sell that item."); return(false); } string errorMessage = merchant.MakeSale((IMobile)Actor, thing, price); if (!string.IsNullOrWhiteSpace(errorMessage)) { RenderError(errorMessage); } ILexicalParagraph toActor = new LexicalParagraph(string.Format("You purchase a $T$ from $S$ for {0}blz.", price)); ILexicalParagraph toArea = new LexicalParagraph("$A$ makes a purchase from $S$."); //TODO: language outputs Message messagingObject = new Message(toActor) { ToOrigin = new List <ILexicalParagraph> { toArea } }; messagingObject.ExecuteMessaging(Actor, merchant, thing, OriginLocation.CurrentZone, null); return(true); }