/// <summary> /// Value: Find out how much a shopkeeper will pay for an item. /// </summary> /// <param name="ch"></param> /// <param name="str"></param> public static void Value(CharData ch, string[] str) { if( ch == null ) return; Object obj; CharData keeper; int cost; if (str.Length == 0) { ch.SendText("Value what?\r\n"); return; } if (!(keeper = ch.FindShopkeeper(""))) return; if (!(obj = ch.GetObjCarrying(str[0]))) { SocketConnection.Act("$n&n tells you 'You don't have that item'.", keeper, null, ch, SocketConnection.MessageTarget.victim); ch.ReplyTo = keeper; return; } if (!ch.CanDropObject(obj)) { ch.SendText("That's not something you can sell.\r\n"); return; } if (!CharData.CanSeeObj(keeper, obj)) { SocketConnection.Act("$n&+W tells you 'You are offering me an imaginary object!?!?'&n", keeper, null, ch, SocketConnection.MessageTarget.victim); ch.ReplyTo = keeper; return; } if ((cost = Object.GetCost(ch, keeper, obj, false)) <= 0) { SocketConnection.Act("$n&n looks uninterested in $p&n.", keeper, obj, ch, SocketConnection.MessageTarget.victim); return; } if (obj.HasFlag(ObjTemplate.ITEM_POISONED)) { SocketConnection.Act("$n&+W tells you 'I won't buy that! It's poisoned!'&n", keeper, null, ch, SocketConnection.MessageTarget.victim); ch.ReplyTo = keeper; return; } string buf = String.Format("$n&+W tells you 'I'll give you {0} &n&+ycopper&+W coins for $p&n.'", cost); SocketConnection.Act(buf, keeper, obj, ch, SocketConnection.MessageTarget.victim); ch.ReplyTo = keeper; return; }
/// <summary> /// Sell an item. /// </summary> /// <param name="ch"></param> /// <param name="str"></param> public static void Sell(CharData ch, string[] str) { if( ch == null ) return; Object obj; CharData keeper; string arg2 = String.Empty; int cost; if (str.Length == 0) { ch.SendText("Sell what?\r\n"); return; } if (!(keeper = ch.FindShopkeeper(arg2))) { return; } if (!ch.IsNPC()) { // Won't buy from bottom 25% of faction range. if (((PC)ch).GetFaction(keeper) < (Limits.MIN_FACTION / 2)) { SocketConnection.Act("$n&+W tells you 'I won't do business with scum like you.'&n", keeper, null, ch, SocketConnection.MessageTarget.victim); ch.ReplyTo = keeper; return; } } if (!(obj = ch.GetObjCarrying(str[0]))) { SocketConnection.Act("$n&+W tells you 'You don't have that item.'&n", keeper, null, ch, SocketConnection.MessageTarget.victim); ch.ReplyTo = keeper; return; } if (!ch.CanDropObject(obj)) { ch.SendText("You couldn't possibly part with that.\r\n"); return; } if (!CharData.CanSeeObj(keeper, obj)) { SocketConnection.Act("$n&+W tells you 'I can't see that item.'&n", keeper, null, ch, SocketConnection.MessageTarget.victim); ch.ReplyTo = keeper; return; } if ((cost = Object.GetCost(ch, keeper, obj, false)) <= 0 || obj.HasFlag(ObjTemplate.ITEM_NOSELL)) { SocketConnection.Act("$n&n looks uninterested in $p&n.", keeper, obj, ch, SocketConnection.MessageTarget.victim); return; } if (cost > obj.Cost) { Log.Error("Shopkeeper with index number {0} buys for more than 100 percent of value.\r\n", keeper.MobileTemplate.IndexNumber); cost = obj.Cost; } if (cost < 1) cost = 1; if (obj.HasFlag(ObjTemplate.ITEM_POISONED)) { SocketConnection.Act("$n&+W tells you 'I won't buy that! It's poisoned!'&n", keeper, null, ch, SocketConnection.MessageTarget.victim); ch.ReplyTo = keeper; return; } string buf = String.Format("You sell $p&n for {0}.", StringConversion.CoinString(cost)); SocketConnection.Act(buf, ch, obj, null, SocketConnection.MessageTarget.character); SocketConnection.Act("$n&n sells $p&n.", ch, obj, null, SocketConnection.MessageTarget.room); ch.ReceiveCash(cost); if (obj.ItemType == ObjTemplate.ObjectType.trash) { obj.RemoveFromWorld(); } else { obj.RemoveFromChar(); obj.ObjToChar(keeper); // Selling an object decreases its scarcity. --obj.ObjIndexData.Scarcity; } return; }
/// <summary> /// Purchase something in a shop. /// </summary> /// <param name="ch"></param> /// <param name="str"></param> public static void Buy(CharData ch, string[] str) { if( ch == null ) return; string arg2 = String.Empty; string arg3 = String.Empty; string text; bool fPerm = false; if (str.Length == 0) { ch.SendText("Buy what?\r\n"); return; } if (ch.InRoom.HasFlag(RoomTemplate.ROOM_PET_SHOP)) { if (ch.IsNPC()) return; Room nextRoom = Room.GetRoom(ch.InRoom.IndexNumber + 1); if (nextRoom == null) { Log.Error("Buy: bad pet shop at index number {0}.", ch.InRoom.IndexNumber); ch.SendText("Sorry, you can't buy that here.\r\n"); return; } Room inRoom = ch.InRoom; ch.InRoom = nextRoom; CharData pet = ch.GetCharRoom(str[0]); ch.InRoom = inRoom; if (pet && ch.MaxPets()) { ch.SendText("Sorry, you can't keep track of that many pets.\r\n"); return; } if (pet == null || !pet.HasActionBit(MobTemplate.ACT_PET)) { ch.SendText("Sorry, you can't buy that here.\r\n"); return; } // Altered Pricing to match the ones that were given in the list // command below... original was set to 500 * pet.level * pet.level // Xangis tweaked it to 100 * pet level squared if (ch.GetCash() < ((100 * pet.Level) * pet.Level)) { ch.SendText("You can't afford it.\r\n"); return; } ch.SpendCash(((100 * pet.Level) * pet.Level)); pet = Database.CreateMobile(pet.MobileTemplate); pet.SetActionBit(MobTemplate.ACT_PET); pet.SetActionBit(MobTemplate.ACT_NOEXP); pet.SetAffectBit(Affect.AFFECT_CHARM); if (!String.IsNullOrEmpty(str[0])) { text = String.Format("{0} {1}", pet.Name, str[0]); pet.Name = text; } text = String.Format("{0}&+LA neck tag says '&+RI belong to {1}&+L'.&n\r\n", pet.Description, ch.Name); pet.Description = text; pet.AddToRoom(ch.InRoom); CharData.AddFollower(pet, ch); ch.SendText("Enjoy your pet.\r\n"); SocketConnection.Act("$n&n just purchased $N&n.", ch, null, pet, SocketConnection.MessageTarget.room); return; } ObjTemplate objTemplate; Object obj = null; CharData keeper; int itemCount = 1; /* buy only one by default */ if (MUDString.IsNumber(str[0])) { Int32.TryParse(str[0], out itemCount); str[0] = arg2; arg2 = arg3; } if (!(keeper = ch.FindShopkeeper(arg2))) { return; } if (!ch.IsNPC()) { // Won't sell to bottom 25% of faction range. if (((PC)ch).GetFaction(keeper) < (Limits.MIN_FACTION / 2)) { SocketConnection.Act("$n&+W tells you 'I won't do business with scum like you.'&n", keeper, null, ch, SocketConnection.MessageTarget.victim); ch.ReplyTo = keeper; return; } } if (keeper.MobileTemplate.ShopData.ItemsForSale.Count != 0) { foreach (int item in keeper.MobileTemplate.ShopData.ItemsForSale) { objTemplate = Database.GetObjTemplate(item); if (!objTemplate) { continue; } if (MUDString.NameContainedIn(str[0], objTemplate.Name)) { obj = Database.CreateObject(objTemplate, objTemplate.Level); fPerm = true; break; } } } if (!obj) { obj = keeper.GetObjCarrying(str[0]); } if (!obj || !CharData.CanSeeObj(ch, obj)) { SocketConnection.Act("$n&+W tells you 'I don't sell that -- try 'list'.'&n", keeper, null, ch, SocketConnection.MessageTarget.victim); ch.ReplyTo = keeper; return; } int cost = Object.GetCost(ch, keeper, obj, true); if (cost < obj.Cost) { Log.Error("Shopkeeper with index number {0} sells for less than 100 percent of value.\r\n", keeper.MobileTemplate.IndexNumber); cost = obj.Cost; } if (itemCount < 1) { ch.SendText("Buy how many? Quantity must be greater than zero.\r\n"); return; } if (ch.GetCash() < (cost * itemCount)) { if (itemCount == 1) { SocketConnection.Act("$n&+W tells you 'You can't afford to buy $p&+W.'&n", keeper, obj, ch, SocketConnection.MessageTarget.victim); ch.ReplyTo = keeper; return; } else { string buf4; if ((ch.GetCash() / cost) > 0) { buf4 = String.Format("$n&+W tells you, 'You can only afford {0} of those!'&n", (ch.GetCash() / cost)); } else { buf4 = String.Format("$n&+W tells you, 'You can't even afford one!'&n"); } SocketConnection.Act(buf4, keeper, obj, ch, SocketConnection.MessageTarget.victim); ch.ReplyTo = keeper; return; } } if (ch.CarryNumber + itemCount > ch.GetMaxItemsCarried()) { ch.SendText("You cannot carry that many items.\r\n"); return; } if (ch.CarryWeight + (itemCount * obj.GetWeight()) > ch.MaxCarryWeight()) { ch.SendText("You cannot carry that much weight.\r\n"); return; } if ((itemCount > 1) && !obj.HasFlag(ObjTemplate.ITEM_INVENTORY)) { SocketConnection.Act("$n&+W tells you, 'Sorry, $p&+W is something I have only one of.'&n", keeper, obj, ch, SocketConnection.MessageTarget.character); ch.ReplyTo = keeper; return; } if (cost < 1) cost = 1; if (itemCount == 1) { text = String.Format("You buy $p&n for {0}.", StringConversion.CoinString(cost * itemCount)); SocketConnection.Act(text, ch, obj, null, SocketConnection.MessageTarget.character); SocketConnection.Act("$n&n purchases $p&n.", ch, obj, null, SocketConnection.MessageTarget.room); } else { text = String.Format("$n&n purchases {0} * $p&n.", itemCount); SocketConnection.Act(text, ch, obj, null, SocketConnection.MessageTarget.room); text = String.Format("You buy {0} * $p&n.", itemCount); SocketConnection.Act(text, ch, obj, null, SocketConnection.MessageTarget.character); } ch.SpendCash(cost * itemCount); if (fPerm) { obj.ObjToChar(ch); } else if (obj.HasFlag(ObjTemplate.ITEM_INVENTORY)) { for (; itemCount > 0; itemCount--) { obj = Database.CreateObject(obj.ObjIndexData, obj.Level); obj.ObjToChar(ch); } } else { obj.RemoveFromChar(); obj.ObjToChar(ch); } obj.Timer = -1; // Selling an object decreases its scarcity. --obj.ObjIndexData.Scarcity; return; }
/// <summary> /// Shows the items that a shop has for sale. /// </summary> /// <param name="ch"></param> /// <param name="str"></param> public static void ListCommand(CharData ch, string[] str) { if( ch == null ) return; string text; string buf1 = String.Empty; if (ch.InRoom.HasFlag(RoomTemplate.ROOM_PET_SHOP)) { if (!ch.InRoom) { ch.SendText("Nothing to list here.\r\n"); return; } Room nextRoom = Room.GetRoom(ch.InRoom.IndexNumber + 1); if (!nextRoom) { Log.Error("ListCommand: bad pet shop at index number {0}.", ch.InRoom.IndexNumber); ch.SendText("You can't do that here.\r\n"); return; } bool found = false; foreach (CharData pet in nextRoom.People) { if (pet.HasActionBit(MobTemplate.ACT_PET)) { // I set this here so as to list a nicer and more comprehensive // pet shop stock/price list. I *think* I got it right. int cost = ((100 * pet.Level) * pet.Level); if (cost <= 0) { cost = 1; } if (!found) { found = true; buf1 += "&+LPets for sale&n&+r:&n\r\n"; } text = String.Format("{0}&n for {1}.\r\n", pet.ShortDescription, StringConversion.CoinString(cost)); buf1 += text; } } if (!found) { ch.SendText("Sorry, we're out of pets right now.\r\n"); } ch.SendText(buf1); return; } else { ObjTemplate objTemplate; CharData keeper; string arg2 = String.Empty; int cost; if (!(keeper = ch.FindShopkeeper(arg2))) { return; } if (ch.IsImmortal()) { buf1 = String.Format("Shop sell profit: {0} percent Shop buy profit: {1} percent\r\n", keeper.MobileTemplate.ShopData.PercentSell, keeper.MobileTemplate.ShopData.PercentBuy); } bool found = false; foreach (Object obj in keeper.Carrying) { if (obj.WearLocation != ObjTemplate.WearLocation.none) continue; cost = Object.GetCost(ch, keeper, obj, true); if (cost <= 0) cost = 1; if (CharData.CanSeeObj(ch, obj) && (str.Length == 0 || str[0] == "all" || MUDString.NameContainedIn(str[0], obj.Name))) { if (!found) { found = true; buf1 += "&+LYou can buy&n&+r:&n\r\n"; } text = String.Format("{0}&n for {1}.\r\n", obj.ShortDescription, StringConversion.CoinString(cost)); buf1 += text; } } if (keeper.MobileTemplate.ShopData.ItemsForSale.Count != 0) { bool fListed = false; int count = 0; foreach (int item in keeper.MobileTemplate.ShopData.ItemsForSale) { objTemplate = Database.GetObjTemplate(item); if (!objTemplate) { continue; } ++count; foreach (Object obj2 in keeper.Carrying) { if (obj2.ObjIndexData == objTemplate && obj2.WearLocation == ObjTemplate.WearLocation.none) { fListed = true; break; } } if (fListed) continue; cost = objTemplate.Cost; text = String.Format("{0}&n for {1}.\r\n", objTemplate.ShortDescription, StringConversion.CoinString(cost)); buf1 += text; } } if (!found) { if (str.Length == 0) ch.SendText("You can't buy anything here.\r\n"); else ch.SendText("You can't buy that here.\r\n"); return; } ch.SendText(buf1); return; } }