/// <summary> /// Selecteds the values as int. /// </summary> /// <returns></returns> public IEnumerable <int> SelectedValuesAsInt() { var ids = new List <int>(); if (ItemIds == null || !ItemIds.Any()) { return(ids); } foreach (string keyVal in ItemIds) { int id; if (int.TryParse(keyVal, out id)) { ids.Add(id); } } return(ids); }
public IDictionary <string, string> GetParameters() { var parameters = new YunDictionary { { "pagenum", PageNum }, { "pagesize", PageSize }, { "itemtitle", ItemTitle }, { "mincreatetime", MinCreateTime }, { "maxcreatetime", MaxCreateTime }, { "nick", Nick }, { "orderid", OrderId }, { "mobile", Mobile }, { "tradestatus", TradeStatus }, { "commentstatus", CommentStatus }, { "logisticsservice", LogisticsService }, { "type", Type }, { "itemids", ItemIds != null && ItemIds.Any() ? string.Join(",", ItemIds) : "" }, { "ordertypes", OrderTypes }, { "shopid", ShopId } }; return(parameters); }
public override void Process(Actor actor) { if (Quantity < 0) { actor.SendMessage(new ActionNotAllowedMessage() { Message = "Cannot give negative items." }); return; } IEnumerable <Actor> receivers; if (ActorId != null) { receivers = actor.Room.ActiveActors.Where(x => x.Id == ActorId.Value); } else { receivers = actor.Room.ActiveActors.FindActorsByName(ActorName, true).ToList(); } if (!receivers.Any()) { actor.SendMessage(new ActionNotAllowedMessage() { Message = "Cannot find player!" }); return; } if (receivers.Count() > 1) { actor.SendMessage(new AmbiguousActorMessage() { Actors = receivers.Select(x => new ActorDescription(x)).ToArray() }); return; } var receiver = receivers.First(); IEnumerable <IItem> items; if (ItemIds != null && ItemIds.Any()) { items = actor.Items.Where(x => ItemIds.Contains(x.Id)); } else { var availableCurrencies = Game.Data.AllCurrencies.Where(x => Currency.Get(x, actor.Cash) > 0).ToList(); items = GetItemCommand.FindItems(availableCurrencies, actor.Items.ToList(), ItemName); } if (items.Count() > 1) { actor.SendMessage(new AmbiguousItemMessage() { Items = items.Select(x => new ItemDescription(x)).ToArray() }); return; } if (!items.Any()) { actor.SendMessage(new ActionNotAllowedMessage() { Message = "Cannot find item!" }); return; } // Handle a cash give. if (items.First() is Currency) { var currency = items.First() as Currency; if (Quantity == 0) { // In the event that no number is specified (ie 0), then we assume the user // wants to drop all currency. So, we oblige them. // TODO: see if this is a correct assumption. Could be dangerous? Quantity = (int)Currency.Get(currency, actor.Cash); } var action = actor.CanRemoveCash(currency, Quantity); if (!action.Allowed) { actor.SendMessage(new ActionNotAllowedMessage() { Message = action.FirstPerson }); return; } action = receiver.CanAcceptCash(currency, Quantity); if (!action.Allowed) { actor.SendMessage(new ActionNotAllowedMessage() { Message = action.ThirdPerson }); return; } var quantity = actor.RemoveCash(currency, Quantity); receiver.AcceptCash(currency, quantity); var message = new CashTransferMessage() { Giver = new ActorDescription(actor), Taker = new ActorDescription(receiver), Currency = new CurrencyDescription(currency, quantity) }; actor.Room.ActiveActors.ForEach(x => x.SendMessage(message)); return; } // Handle a regular give Quantity = Math.Max(Quantity, 1); // 0 is valid in the event that no number is specified. In that instance, we assume 1 instead. IEnumerable <Item> finalItems; if (items.First() is ItemGroup) { finalItems = (items.First() as ItemGroup).Items.Take(Quantity); } else { finalItems = items.Cast <Item>(); } List <Item> successes = new List <Item>(); List <string> failures = new List <string>(); foreach (var item in finalItems) { var give = actor.CanRemoveItem(item); var take = receiver.CanAcceptItem(item); if (give.Allowed && take.Allowed) { actor.RemoveItem(item); receiver.AcceptItem(item); successes.Add(item); } if (!give.Allowed) { failures.Add(give.FirstPerson); } if (!take.Allowed) { failures.Add(take.ThirdPerson); } } if (successes.Any()) { var message = new ItemOwnershipMessage() { Giver = new ActorDescription(actor), Taker = new ActorDescription(receiver), Items = successes.Select(x => new ItemDescription(x)).ToArray(), }; actor.Room.ActiveActors.ForEach(x => x.SendMessage(message)); } if (failures.Any()) { failures.Distinct().ForEach(x => actor.SendMessage(new ActionNotAllowedMessage() { Message = x })); } }
public override void Process(Actor actor) { if (Quantity < 0) { actor.SendMessage(new ActionNotAllowedMessage() { Message = "Cannot drop negative items." }); return; } IEnumerable <IItem> items; if (ItemIds != null && ItemIds.Any()) { items = actor.Items.Where(x => ItemIds.Contains(x.Id)); } else { var availableCurrencies = Game.Data.AllCurrencies.Where(x => Currency.Get(x, actor.Cash) > 0).ToList(); items = GetItemCommand.FindItems(availableCurrencies, actor.Items.ToList(), ItemName); } if (items.Count() > 1) { actor.SendMessage(new AmbiguousItemMessage() { Items = items.Select(x => new ItemDescription(x)).ToArray() }); return; } if (!items.Any()) { actor.SendMessage(new ActionNotAllowedMessage() { Message = "Cannot find item!" }); return; } // Handle a cash drop. if (items.First() is Currency) { var currency = items.First() as Currency; if (Quantity == 0) { // In the event that no number is specified (ie 0), then we assume the user // wants to drop all currency. So, we oblige them. // TODO: see if this is a correct assumption. Could be dangerous? Quantity = (int)Currency.Get(currency, actor.Cash); } var action = actor.CanDropCash(currency, Quantity, Hide); if (action.Allowed) { actor.DropCash(currency, Quantity, Hide); var message = new CashTransferMessage() { Giver = new ActorDescription(actor), Currency = new CurrencyDescription(currency, Quantity), Hide = Hide }; if (Hide == false) { // let the actors in the room know, but only if it's not being hidden. actor.Room.ActiveActors.Where(x => x != actor).ForEach(x => x.SendMessage(message)); } actor.SendMessage(message); } else { actor.SendMessage(new ActionNotAllowedMessage() { Message = action.FirstPerson }); } return; } // Handle a regular drop Quantity = Math.Max(Quantity, 1); // 0 is valid in the event that no number is specified. In that instance, we assume 1 instead. IEnumerable <Item> finalItems; if (items.First() is ItemGroup) { finalItems = (items.First() as ItemGroup).Items.Take(Quantity); } else { finalItems = items.Cast <Item>(); } List <Item> successes = new List <Item>(); List <string> failures = new List <string>(); foreach (var item in finalItems) { var action = actor.CanDropItem(item, Hide); if (action.Allowed) { actor.DropItem(item, Hide); successes.Add(item); } else { failures.Add(action.FirstPerson); } } if (successes.Any()) { var message = new ItemOwnershipMessage() { Giver = new ActorDescription(actor), Items = successes.Select(x => new ItemDescription(x)).ToArray(), Hide = Hide }; if (Hide == false) { actor.Room.ActiveActors.ForEach(x => x.SendMessage(message)); } else { actor.SendMessage(message); } } if (failures.Any()) { failures.Distinct().ForEach(x => actor.SendMessage(new ActionNotAllowedMessage() { Message = x })); } }