static public void CreateDeal(RequestContext request) { int userstate = UserHandler.AuthUser(request); if (userstate == 1 || userstate == 2) { TradeItem item = JsonConvert.DeserializeObject <TradeItem>(request.Message); User user = UserHandler.GetUserDataByToken(request); if (UserCardsHandler.CheckValidCardToUser(item.cardToTrade, user)) { try { TradingDatabaseHandler.CreateTradingDeal(user, item); Output.WriteConsole(Output.TradeCreationSuccess); } catch (Exception e) { Output.WriteConsole(e.Message); } return; } Output.WriteConsole(Output.TradeCreationInvalidCard); return; } Output.WriteConsole(Output.AuthError); }
public bool AddItem(MapleItem item, byte tradeSlot, short quantity, MapleCharacter itemOwner) { if (Partners.Count == 0) return false; //Partner hasn't accepted trade if (item.Tradeable) return false; //theyre probably hacking if they put in an untradable item too foreach (TradeItem[] arr in items) { if (arr.Any(t => t != null && t.Item == item)) //item is already added { return false; } } if (Type == TradeType.Trade) { if (tradeSlot > 9 || tradeSlot < 1) return false;//hacking if (Owner == itemOwner) { items[0][tradeSlot] = new TradeItem(item, quantity); } else { items[1][tradeSlot] = new TradeItem(item, quantity); } bool isOwner = Owner == itemOwner; Owner.Client.SendPacket(GenerateTradeItemAdd(item, !isOwner, tradeSlot)); Partners[0].Client.SendPacket(GenerateTradeItemAdd(item, isOwner, tradeSlot)); return true; } return false; }
public long DeliverShipments(TradeItem ti, long amount) { switch (ti) { case TradeItem.FOOD: food += amount; break; case TradeItem.PARTS: parts += amount; break; case TradeItem.WORKERS: workers += amount; break; case TradeItem.FUEL: fuel += amount; break; case TradeItem.LUXURY: luxuries += amount; break; default: throw new System.Exception("Did not get expected shipment"); } return(PurchasePrice(ti, amount)); }
private async void LoadItemId(string item_id) { var document = await CrossCloudFirestore.Current .Instance .Collection("items") .Document(item_id) .GetAsync(); item = document.ToObject <TradeItem>(); if (item == null) { await DisplayAlert("Oh! Oh!", "Invalid Item", "OK"); return; } TitleText.Text = item.title; ItemPicHolder.Source = item.photo_url; ProfilePicHolder.Source = item.user_photo_url; userNameText.Text = item.user_name; postedTimeText.Text = item.posted_time; DescText.Text = item.description; if (DependencyService.Get <IAuth>().getCurrentUserUID().Equals(item.user_id)) { TradeButton.IsVisible = false; } LoadUser(); HandleTradeStatus(); }
private void AddItems(Character chr) { // Note: Exchange logic, so A gets B and B gets A stuff for (int i = 0; i < 2; i++) { if (i == chr.RoomSlotId) { continue; } var charFrom = Users[i]; for (int j = 0; j < 10; j++) { TradeItem ti = ItemList[i][j]; if (ti?.OriginalItem != null) { chr.Inventory.AddItem2(ti.OriginalItem); ItemTransfer.PlayerTradeExchange(charFrom.ID, chr.ID, ti.OriginalItem.ItemID, ti.OriginalItem.Amount, _transaction, ti.OriginalItem); ti.OriginalItem = null; } } var mesos = Mesos[i]; if (mesos != 0) { chr.AddMesos(mesos); MesosTransfer.PlayerTradeExchange(charFrom.ID, chr.ID, mesos, _transaction); } } }
static public void CreateTradingDeal(User user, TradeItem item) { using var conn = new NpgsqlConnection(connString); //connect to db conn.Open(); try { using (var cmd = new NpgsqlCommand("INSERT INTO tradings VALUES (@id, @ctt, @type, @md, @uid)", conn)) //inserting into db { cmd.Parameters.AddWithValue("@id", item.id); //adding parameters cmd.Parameters.AddWithValue("@ctt", item.cardToTrade); cmd.Parameters.AddWithValue("@type", item.type); cmd.Parameters.AddWithValue("@md", item.minimumDamage); cmd.Parameters.AddWithValue("@uid", user.uid); cmd.Prepare(); cmd.ExecuteNonQuery(); } } catch (Exception e) { conn.Close(); throw new Exception(Output.TradeCreationAlreadyExists); } conn.Close(); CardsUsersDatabaseHandler.updateShopStatusTrue(item.cardToTrade); }
public bool MoveItemToInventory(int guid, uint amount) { TradeItem tradeItem = base.Items.SingleOrDefault((TradeItem entry) => entry.Guid == guid); bool result; if (amount == 0u) { result = false; } else { this.ToggleReady(false); if (tradeItem == null) { result = false; } else { if (tradeItem.Stack <= amount) { base.RemoveItem(tradeItem); tradeItem.Stack = 0u; } else { tradeItem.Stack -= amount; } this.OnItemMoved(tradeItem, tradeItem.Stack != 0u, (int)(-(int)((ulong)amount))); result = true; } } return(result); }
public async Task <TradeItem> GetItemDetailAsync(string id) { baseUrl = $"http://tradewithme.azurewebsites.net/api/item/Details/{id}"; var item = new TradeItem(); var httpClient = new HttpClient(); httpClient.BaseAddress = new Uri(baseUrl); httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // Add the Authorization header with the AccessToken. // httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + Settings.AuthLoginToken); try { var response = await httpClient.GetAsync(baseUrl); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); item = JsonHelper.Deserialize <TradeItem>(content); } return(item); } catch (Exception) { return(item); } }
public bool RemoveItem(ItemTemplate template, uint amount) { TradeItem tradeItem = base.Items.FirstOrDefault((TradeItem x) => x.Template == template); bool result; if (tradeItem == null) { result = false; } else { uint num = amount; if (tradeItem.Stack - amount <= 0u) { base.RemoveItem(tradeItem); num = tradeItem.Stack; } else { tradeItem.Stack -= amount; } this.OnItemMoved(tradeItem, tradeItem.Stack > 0u, (int)(-(int)num)); result = true; } return(result); }
private void ConsumeResource(TradeItem ti, long amount) { switch (ti) { case TradeItem.FOOD: food -= amount; break; case TradeItem.PARTS: parts -= amount; break; case TradeItem.WORKERS: workers -= amount; break; case TradeItem.FUEL: fuel -= amount; break; case TradeItem.LUXURY: luxuries -= amount; break; default: throw new System.Exception("Did not try and get NONE"); } }
public void RemoveFromList(TradeItem item, bool trade) {//Reduces the item amounts and determines how much is being carried if (trade) { if (GetQuantity() > item.tradeNum) { carryItem = item.tradeNum; item.tradeNum = 0; } else { carryItem = GetQuantity(); item.tradeNum = item.tradeNum - GetQuantity(); } } else { if (GetQuantity() > item.itemNum) { carryItem = item.itemNum; item.itemNum = 0; } else { carryItem = GetQuantity(); item.itemNum = item.itemNum - GetQuantity(); } } DisplayUpdate(); }
protected virtual void OnItemMoved(TradeItem item, bool modified, int difference) { Trader.ItemMovedHandler itemMoved = this.ItemMoved; if (itemMoved != null) { itemMoved(this, item, modified, difference); } }
public EditViewModel(TradeItem tradeItem) { this.itrade = DependencyService.Get <Itrade>(); itemRef = tradeItem.ItemRef; itemName = tradeItem.ItemName; price = tradeItem.ItemPrice.ToString(); description = tradeItem.ItemDescription; }
protected override void Read(NReader rdr) { MyItems = new TradeItem[rdr.ReadInt16()]; for (int i = 0; i < MyItems.Length; i++) { MyItems[i] = TradeItem.Read(rdr); } }
private void DeleteItemFromTradeList(object sender, RoutedEventArgs e) { if (TradeListBox.SelectedIndex >= 0) { TradeItem item = TradeListBox.SelectedItem as TradeItem; _tradeList.Remove(item); refreshTradeList(); } }
public void getValuables() { bool inValuableSection = false; string name = ""; string title = ""; int worth = 0; int id = 0; int amount = 0; XmlReader reader = XmlReader.Create((new StringReader(xmldoc.InnerXml))); while (reader.Read() && inValuableSection == false) { if (reader.NodeType.Equals(XmlNodeType.Element) && reader.Name.Equals("Valuable")) { inValuableSection = true; break; } } while (reader.Read()) { if (reader.NodeType.Equals(XmlNodeType.EndElement) && reader.Name.Equals("Valuable")) { break; } else if (reader.NodeType.Equals(XmlNodeType.EndElement) && reader.Name.Equals("BaseItem")) { items[id] = new TradeItem(id, name, title, amount, worth); } else if (reader.NodeType.Equals(XmlNodeType.Element)) { if (reader.HasAttributes) { name = reader.GetAttribute("name"); } else if (reader.Name.Equals("title")) { reader.Read(); title = reader.Value; } else if (reader.Name.Equals("worth")) { reader.Read(); worth = int.Parse(reader.Value); } else if (reader.Name.Equals("amount")) { reader.Read(); amount = int.Parse(reader.Value); } else if (reader.Name.Equals("id")) { reader.Read(); id = int.Parse(reader.Value); } } } }
protected virtual void OnTraderItemMoved(Trader trader, TradeItem item, bool modified, int difference) { TFirst firstTrader = this.FirstTrader; firstTrader.ToggleReady(false); TSecond secondTrader = this.SecondTrader; secondTrader.ToggleReady(false); }
public PriceItem(TradeItem result) { Item = result; if (Item.Requirements != null) { var requires = new LineContent() { DisplayMode = -1, Name = PriceResources.Requires, Values = new List <LineContentValue> { new LineContentValue() { Type = LineContentType.Simple, Value = string.Join(", ", Item.Requirements.Select(x => { if (x.DisplayMode == 0) { x.DisplayMode = -1; } return(x.Parsed); })), } } }; Item.Requirements.Clear(); Item.Requirements.Add(requires); } if (Item.ItemLevel > 0) { if (Item.Requirements == null) { Item.Requirements = new List <LineContent>(); } Item.Requirements.Add(new LineContent() { DisplayMode = 0, Name = PriceResources.ItemLevel, Values = new List <LineContentValue> { new LineContentValue() { Type = LineContentType.Simple, Value = Item.ItemLevel.ToString(), } }, Order = -1, }); } if (Item.Requirements != null) { Item.Requirements = Item.Requirements.OrderBy(x => x.Order).ToList(); } }
private void Socket_OnTradeMessage(string exchange, string primaryCurrency, string secondaryCurrency, TradeItem trade) { WriteLog($"Received new trade for (exchange) market {primaryCurrency}/{secondaryCurrency} price {trade.Price}"); /*WriteLog($"Received new trade for {exchange} market { primaryCurrency}/{ secondaryCurrency} price { trade.Price} ");*/ }
public StockItem buyItems(TradeItem titem, float m, int quant) { int q = titem.takeStock(quant); if (q > 0) { money += m * 0.05f; } return(new StockItem(new Item(titem.getName()), q)); }
protected override void OnTraderItemMoved(Trader trader, TradeItem item, bool modified, int difference) { base.OnTraderItemMoved(trader, item, modified, difference); if (!(trader is PlayerTrader)) { return; } AdjustLoots(); }
private bool ContainsItem(TradeItem tItemArgs) { foreach (StashControl item in spnl_Buttons.Children) { if (item.GetTItem.Item == tItemArgs.Item && item.GetTItem.Customer == tItemArgs.Customer && item.GetTItem.Price == tItemArgs.Price && item.GetTItem.StashPosition == tItemArgs.StashPosition) { return(true); } } return(false); }
protected override void Read(ClientProcessor psr, NReader rdr) { MyItems = new TradeItem[rdr.ReadInt16()]; for (var i = 0; i < MyItems.Length; i++) MyItems[i] = TradeItem.Read(rdr); YourName = rdr.ReadUTF(); YourItems = new TradeItem[rdr.ReadInt16()]; for (var i = 0; i < YourItems.Length; i++) YourItems[i] = TradeItem.Read(rdr); }
public float getBuyPrice(TradeItem titem, int quant) { if (quant <= titem.quantity) { return(titem.currentBuyPrice * quant * 1.05f); } else { return(titem.currentBuyPrice * titem.quantity * 1.05f); } }
protected override void Read(NReader rdr) { MyItems = new TradeItem[rdr.ReadInt16()]; for (int i = 0; i < MyItems.Length; i++) MyItems[i] = TradeItem.Read(rdr); YourName = rdr.ReadUTF(); YourItems = new TradeItem[rdr.ReadInt16()]; for (int i = 0; i < YourItems.Length; i++) YourItems[i] = TradeItem.Read(rdr); }
TradeItem CheckForItem(TradeItem item, List <TradeItem> list) {//Returns the item if it exists in the opposing inventory foreach (TradeItem tItem in list) { if (tItem.itemName == item.itemName) { return(tItem); } } return(null); }
public void AddToList(TradeItem item, bool trade) { if (trade) { item.tradeNum += carryItem; } else { item.itemNum += carryItem; } }
public void RequestTake(RealmTime time, RequestTradePacket pkt) { if (tradeTarget != null) { SendError("You're already trading!"); tradeTarget = null; return; } var target = Owner.GetUniqueNamedPlayer(pkt.Name); if (target == null) { SendError("Player not found!"); return; } if (target.tradeTarget != null && target.tradeTarget != this) { SendError(target.Name + " is already trading!"); return; } tradeTarget = target; trade = new bool[12]; tradeAccepted = false; target.tradeTarget = this; target.trade = new bool[12]; taking = true; tradeTarget.intake = true; var my = new TradeItem[Inventory.Length]; for (var i = 0; i < Inventory.Length; i++) my[i] = new TradeItem { Item = target.Inventory[i] == null ? -1 : target.Inventory[i].ObjectType, SlotType = target.SlotTypes[i], Included = false, Tradeable = (target.Inventory[i] != null) }; var your = new TradeItem[target.Inventory.Length]; for (var i = 0; i < target.Inventory.Length; i++) your[i] = new TradeItem { Item = -1, SlotType = target.SlotTypes[i], Included = false, Tradeable = false }; psr.SendPacket(new TradeStartPacket { MyItems = my, YourName = target.Name, YourItems = your }); }
internal void RemoveStashControl(TradeItem tItemArgs) { foreach (StashControl item in spnl_Buttons.Children) { if (item.GetTItem.Item == tItemArgs.Item && item.GetTItem.Customer == tItemArgs.Customer && item.GetTItem.Price == tItemArgs.Price) { spnl_Buttons.Children.Remove(item); break; //important step } } }
protected TradeOffer(IReadOnlyPacket packet) : this() { UserId = packet.ReadInt(); int n = packet.ReadInt(); for (int i = 0; i < n; i++) { Items.Add(TradeItem.Parse(packet)); } FurniCount = packet.ReadInt(); CreditCount = packet.ReadInt(); }
public void AddButton(TradeItem tItemArgs) { UpdateLocationAndSize(); if (ContainsItem(tItemArgs) == false && !String.IsNullOrEmpty(tItemArgs.Stash)) { StashControl sCtrl = new StashControl(tItemArgs); sCtrl.MouseEnter += MouseEnterDrawRectangle; spnl_Buttons.Children.Add(sCtrl); } }
private void CustomListview_ItemTapped(object sender, ItemTappedEventArgs e) { string source = e.Item.GetType().Name; switch (source) { case "HomeItem": if (e.Item != null) { var vm = BindingContext as HomeViewModel; // ItemClickCommand?.Execute(e.Item); HomeItem homeItem = e.Item as HomeItem; vm.ShowExtraButtton(homeItem); SelectedItem = null; } break; case "TradeItem": if (e.Item != null) { var vm = BindingContext as MyTradeViewModel; // ItemClickCommand?.Execute(e.Item); TradeItem tradeItem = e.Item as TradeItem; vm.ShowExtraButtton(tradeItem); SelectedItem = null; } break; case "BetItem": if (e.Item != null) { try { var vm = BindingContext as NotifyInViewModel; // ItemClickCommand?.Execute(e.Item); BetItem betItem = e.Item as BetItem; vm.ShowExtraButtton(betItem); SelectedItem = null; } catch (Exception) { var vm = BindingContext as NotifyOutViewModel; // ItemClickCommand?.Execute(e.Item); BetItem betItem = e.Item as BetItem; vm.ShowExtraButtton(betItem); SelectedItem = null; } } break; } }
public void Sell() { if (this.status == StrategyOrderStatus.Inprogress) { if (this.Live && this.HasBought) { this.account.Sell(this.DataProvider.Candles.Last(), this.Symbol, Binance.Net.Objects.OrderType.Limit, this.OperationID, this.LotSize.ChangeType <decimal>()); LinkedTrades = this.account.ExecutedOrders.Where(y => y.OperationID == this.OperationID).First(); bool waitfortrade = true; while (waitfortrade) { var order = this.account.ExecutedOrders.Where(y => y.OperationID == this.OperationID).First(); if (order.State == OrderExecutionStatus.Filled) { this.Profit = this.BuyPrice.FindDifference(order.Soldprice.ChangeType <double>()); this.Profit -= 0.075 * 2; this.InvestedInTotalWithProfit = (this.InvestedInTotal * this.Profit); this.ProfitLot = (this.LotSize + this.Profit); this.SellTime = this.DataProvider.Candles.Last().Candle.DateTime.DateTime; this.SellPrice = this.DataProvider.Low.Last(); this.HasBought = false; this.status = StrategyOrderStatus.Done; this.PNL = (this.DataProvider.Candles.Last().Candle.Close.ChangeType <double>() / this.LotSize - this.DataProvider.Candles.Last().Candle.Close.ChangeType <double>()); waitfortrade = false; } if (order.State == OrderExecutionStatus.Error) { this.status = StrategyOrderStatus.Inprogress; waitfortrade = false; } System.Threading.Thread.Sleep(3000); } } else { this.Profit = this.BuyPrice.FindDifference(this.DataProvider.Close.Last()); this.Profit -= 0.075 * 2; this.InvestedInTotalWithProfit = (this.InvestedInTotal * this.Profit); this.ProfitLot = (this.LotSize + this.Profit); this.SellTime = this.DataProvider.Candles.Last().Candle.DateTime.DateTime; this.SellPrice = this.DataProvider.Low.Last(); this.HasBought = false; this.status = StrategyOrderStatus.Done; this.PNL = (this.DataProvider.Candles.Last().Candle.Close.ChangeType <double>() / this.LotSize - this.DataProvider.Candles.Last().Candle.Close.ChangeType <double>()); } } }
public void ItemSelect(Func<Item,ItemData,bool> valid, Action<int> action) { TradeItem[] items = new TradeItem[Inventory.Length]; for (int i = 0; i < Inventory.Length; i++) { items[i] = new TradeItem { Item = Inventory[i] == null ? -1 : Inventory[i].ObjectType, Data = Inventory.Data[i] ?? new ItemData(), SlotType = SlotTypes[i], Included = false, Tradeable = Inventory[i] == null ? false : valid.Invoke(Inventory[i], Inventory.Data[i]) }; } client.SendPacket(new ItemSelectStartPacket { MyItems = items }); this.selection = Tuple.Create(valid, action); }
public void RequestTrade(RealmTime time, RequestTradePacket pkt) { if (!NameChosen) { SendInfo("Unique name is required to trade with others!"); return; } if (tradeTarget != null) { SendError("You're already trading!"); tradeTarget = null; return; } Player target = Owner.GetUniqueNamedPlayer(pkt.Name); if (target == null) { SendError("Player not found or is offline!"); return; } if (target.tradeTarget != null && target.tradeTarget != this) { SendError(target.Name + " is already trading!"); return; } if (this.potentialTrader.ContainsKey(target)) { this.tradeTarget = target; this.trade = new bool[12]; this.tradeAccepted = false; target.tradeTarget = this; target.trade = new bool[12]; target.tradeAccepted = false; this.potentialTrader.Clear(); target.potentialTrader.Clear(); TradeItem[] my = new TradeItem[Inventory.Length]; for (int i = 0; i < Inventory.Length; i++) my[i] = new TradeItem() { Item = this.Inventory[i] == null ? -1 : Inventory[i].ObjectType, SlotType = this.SlotTypes[i], Included = false, Tradeable = (Inventory[i] == null || i < 4) ? false : (!Inventory[i].Soulbound && !Inventory[i].Undead && !Inventory[i].SUndead) }; TradeItem[] your = new TradeItem[target.Inventory.Length]; for (int i = 0; i < target.Inventory.Length; i++) your[i] = new TradeItem() { Item = target.Inventory[i] == null ? -1 : target.Inventory[i].ObjectType, SlotType = target.SlotTypes[i], Included = false, Tradeable = (target.Inventory[i] == null || i < 4) ? false : (!target.Inventory[i].Soulbound && !target.Inventory[i].Undead && !target.Inventory[i].SUndead) }; psr.SendPacket(new TradeStartPacket() { MyItems = my, YourName = target.Name, YourItems = your }); target.psr.SendPacket(new TradeStartPacket() { MyItems = your, YourName = this.Name, YourItems = my }); } else { target.potentialTrader[this] = 1000 * 20; target.psr.SendPacket(new TradeRequestedPacket() { Name = Name }); SendInfo("You have requested to trade with " + target.Name); return; } }
public void RequestTrade(RealmTime time, RequestTradePacket pkt) { var target = Owner.GetPlayerByName(pkt.Name); if (target == null) { SendInfo("{\"key\":\"server.player_not_found\",\"tokens\":{\"player\":\"" + pkt.Name + "\"}}"); return; } if (!NameChosen || !target.NameChosen) { SendInfo("{\"key\":\"server.trade_needs_their_name\"}"); return; } if (Client.Player == target) { SendInfo("{\"key\":\"server.self_trade\"}"); return; } if (TradeManager.TradingPlayers.Count(_ => _.AccountId == target.AccountId) > 0) { SendInfo("{\"key\":\"server.they_already_trading\",\"tokens\":{\"player\":\"" + target.Name + "\"}}"); return; } if (TradeManager.CurrentRequests.Count(_ => _.Value.AccountId == AccountId && _.Key.AccountId == target.AccountId) > 0) { var myItems = new TradeItem[12]; var yourItems = new TradeItem[12]; for (var i = 0; i < myItems.Length; i++) { myItems[i] = new TradeItem { Item = Inventory[i] == null ? -1 : Inventory[i].ObjectType, SlotType = SlotTypes[i], Tradeable = (Inventory[i] != null && i >= 4) && (!Inventory[i].Soulbound), Included = false }; } for (var i = 0; i < yourItems.Length; i++) { yourItems[i] = new TradeItem { Item = target.Inventory[i] == null ? -1 : target.Inventory[i].ObjectType, SlotType = SlotTypes[i], Tradeable = (target.Inventory[i] != null && i >= 4) && (!target.Inventory[i].Soulbound), Included = false }; } Client.SendPacket(new TradeStartPacket { MyItems = myItems, YourItems = yourItems, YourName = target.Name }); target.Client.SendPacket(new TradeStartPacket { MyItems = yourItems, YourItems = myItems, YourName = Name }); var t = new TradeManager(this, target); target.TradeHandler = t; TradeHandler = t; } else { SendInfo("{\"key\":\"server.trade_requested\",\"tokens\":{\"player\":\"" + target.Name + "\"}}"); if (target.Ignored.Contains(Client.Account.AccountId)) return; target.Client.SendPacket(new TradeRequestedPacket { Name = Name }); var format = new KeyValuePair<Player, Player>(this, target); TradeManager.CurrentRequests.Add(format); Owner.Timers.Add(new WorldTimer(60 * 1000, (w, t) => { if (!TradeManager.CurrentRequests.Contains(format)) return; TradeManager.CurrentRequests.Remove(format); SendInfo("{\"key\":\"server.trade_timeout\"}"); })); } }
private bool CheckBuyingItems(ref TradeItem MyTradeItem) { bool Member = (TheMySqlManager.CheckIfTradeMember(TradeHandler.username, Settings.botid) == true); //loop through the wanted list to see if we want it... bool buying = false; foreach (WantedItem MyWantedItem in TheMySqlManager.GetWantedItemList(0).Values) { if (MyTradeItem.name.ToLower() == MyWantedItem.name.ToLower()) { int qtyOnHand = TheInventory.Quantity(MyWantedItem.name); if (qtyOnHand >= MyWantedItem.maxquantity && MyWantedItem.maxquantity > 0) { TheTCPWrapper.Send(CommandCreator.SEND_PM(TradeHandler.username, "I'm already at my maximum quantity of " + MyTradeItem.name)); buying = false; } else if (MyWantedItem.maxquantity == 0) { TheTCPWrapper.Send(CommandCreator.SEND_PM(TradeHandler.username, "I am buying an unlimited number of " + MyTradeItem.name + " for " + (Member ? MyWantedItem.pricepurchasemembers.ToString() : MyWantedItem.pricepurchase.ToString()) + " gc each.")); buying = true; } else { TheTCPWrapper.Send(CommandCreator.SEND_PM(TradeHandler.username, "I am buying up to " + (MyWantedItem.maxquantity - qtyOnHand) + " " + MyTradeItem.name + " for " + (Member ? MyWantedItem.pricepurchasemembers.ToString() : MyWantedItem.pricepurchase.ToString()) + " gc each.")); buying = true; } MyTradeItem.pricepurchase = MyWantedItem.pricepurchase; MyTradeItem.pricepurchasemembers = MyWantedItem.pricepurchasemembers; MyTradeItem.maxQuantity = (MyWantedItem.maxquantity - qtyOnHand); if (MyTradeItem.maxQuantity < 0) { MyTradeItem.maxQuantity = 0; } break; } } return buying; }
private void GET_TRADE_OBJECT(byte[] buffer) { if (Gambling || claimingPrize) { return; } TheLogger.Debug("GET_TRADE_OBJECT\n"); Console.WriteLine("Size of trade object buffer: " + buffer.Length); idleTradeTime = 0; // buffer[11]==1 --> New trade object on the trade partner side // buffer[11]==0 --> New trade object on my side if (buffer[11] == 1) { totalCalculated = false; byte pos = buffer[10]; //here here TradeItem MyTradeItem; if (PartnerTradeItemsList.Contains(pos)) // is this item already in the trade window? { MyTradeItem = (TradeItem)PartnerTradeItemsList[pos]; MyTradeItem.quantity += System.BitConverter.ToUInt32(buffer, 5); PartnerTradeItemsList[pos] = MyTradeItem; } else { MyTradeItem = new TradeItem(); MyTradeItem.pos = pos; MyTradeItem.imageid = System.BitConverter.ToInt16(buffer, 3); MyTradeItem.quantity = System.BitConverter.ToUInt32(buffer, 5); MyTradeItem.name = ""; MyTradeItem.pricepurchase = 0; MyTradeItem.pricepurchasemembers = 0; MyTradeItem.KnownItemsSqlID = -1; MyTradeItem.validTradeItem = true; PartnerTradeItemsList.Add(pos, MyTradeItem); if (Inventory.sizeOfPacket == 10) { MyTradeItem.ELServerItemID = System.BitConverter.ToInt16(buffer, 12); Console.WriteLine(MyTradeItem.ELServerItemID); TheMySqlManager.getItemInfo(ref MyTradeItem); Console.WriteLine("Item ID: " + MyTradeItem.KnownItemsSqlID + "|Item name: " + MyTradeItem.name + "|Item weight: " + MyTradeItem.weight); if (MyTradeItem.KnownItemsSqlID == -1) { TheTCPWrapper.Send(CommandCreator.LOOK_AT_TRADE_ITEM(pos, true)); } else { if (Settings.IsTradeBot == true && !(Donating || PutOnSale)) { if (MyTradeItem.name.ToLower() != "gold coins") { if (CheckBuyingItems(ref MyTradeItem)) { MyTradeItem.validTradeItem = true; } else { TheTCPWrapper.Send(CommandCreator.SEND_PM(TradeHandler.username, "!!!I am not buying " + MyTradeItem.name + ". You will need to remove this item before I will accept the trade!!!")); MyTradeItem.validTradeItem = false; } } else { MyTradeItem.validTradeItem = true; MyTradeItem.pricepurchase = 1; MyTradeItem.pricepurchasemembers = 1; } } PartnerTradeItemsList[MyTradeItem.pos] = MyTradeItem; } } else { TheTCPWrapper.Send(CommandCreator.LOOK_AT_TRADE_ITEM(pos, true)); } } } else { int imageID = System.BitConverter.ToInt16(buffer, 3); uint quantity = System.BitConverter.ToUInt32(buffer, 5); if (imageID == 3 && !(Donating || PutOnSale)) { AcceptStatePartner = 1; TheTCPWrapper.Send(CommandCreator.ACCEPT_TRADE()); TheLogger.Debug("TX: ACCEPT_TRADE\n"); } } }
private void INVENTORY_ITEM_TEXT(byte[] data) { if (Trading == false || TheInventory.GettingInventoryItems == true || Gambling || claimingPrize) return; //if getting storage items still, pause here... int i=0; string ItemDescription = ""; string TempItemDescription = ""; TempItemDescription=System.Text.ASCIIEncoding.ASCII.GetString(data,4,data.Length-4).Trim(); // remove bad some chars (eg color tags) TempItemDescription = TempItemDescription.Replace((char)10, ' '); TheLogger.Debug("Beginning FOR loop (1)\n"); for (i=0;i<TempItemDescription.Length;i++) { if (!(TempItemDescription[i]<32 || TempItemDescription[i]>126)) { ItemDescription = ItemDescription+TempItemDescription[i]; } } TheLogger.Debug("FOR loop (1) completed\n"); TradeItem MyTradeItem = new TradeItem(); MyTradeItem.pos = 0; // Get all the keys in the hashtable and sort them ArrayList keys = new ArrayList(PartnerTradeItemsList.Keys); keys.Sort(); foreach (object obj in keys) { MyTradeItem = (TradeItem)PartnerTradeItemsList[obj]; if (MyTradeItem.name == "") { break; } } TheLogger.Debug("Beginning TRIM(1) of " + ItemDescription + "\n"); ItemDescription = ItemDescription.Trim(); if (ItemDescription.Contains(" - ")) { if (ItemDescription.ToLower().Contains("extract")) { MyTradeItem.name = ItemDescription.Substring(0, ItemDescription.LastIndexOf(" - ")).Trim(); } else { MyTradeItem.name = ItemDescription.Substring(0, ItemDescription.IndexOf(" - ")).Trim(); } } else { MyTradeItem.name = ItemDescription; MyTradeItem.name = MyTradeItem.name.Replace((char)10, ' '); MyTradeItem.name = MyTradeItem.name.Substring(0, MyTradeItem.name.IndexOf("Weight:")); MyTradeItem.name = MyTradeItem.name.Trim(); } if (Settings.IsTradeBot == true && !(Donating || PutOnSale)) { if (MyTradeItem.name.ToLower() != "gold coins") { if (CheckBuyingItems(ref MyTradeItem)) { MyTradeItem.validTradeItem = true; } else { TheTCPWrapper.Send(CommandCreator.SEND_PM(TradeHandler.username, "!!!I am not buying " + MyTradeItem.name + ". You will need to remove this item before I will accept the trade!!!")); MyTradeItem.validTradeItem = false; } } else { MyTradeItem.validTradeItem = true; MyTradeItem.pricepurchase = 1; MyTradeItem.pricepurchasemembers = 1; } } MyTradeItem.weight = int.Parse(ItemDescription.Substring(ItemDescription.IndexOf("Weight:") + 8, ItemDescription.Length - (ItemDescription.IndexOf("Weight:") + 8 + 4))); MyTradeItem.KnownItemsSqlID = TheMySqlManager.GetKnownItemsSQLID(MyTradeItem); PartnerTradeItemsList[MyTradeItem.pos] = MyTradeItem; //double check if this was needed or not..... testing Inventory.inventory_item MyInventoryItem = new Inventory.inventory_item(); MyInventoryItem.name = MyTradeItem.name; MyInventoryItem.imageid = MyTradeItem.imageid; MyInventoryItem.name = MyTradeItem.name; MyInventoryItem.is_resource = false; MyInventoryItem.is_reagent = false; MyInventoryItem.is_stackable = false; MyInventoryItem.use_with_inventory = false; MyInventoryItem.description = ""; MyInventoryItem.weight = MyTradeItem.weight; TheMySqlManager.updateknownitems(MyInventoryItem, MyTradeItem.KnownItemsSqlID); }
public void RequestForge(RealmTime time, RequestTradePacket pkt) { if (tradeTarget != null) { SendError("You're already trading!"); tradeTarget = null; return; } trade = new bool[12]; tradeAccepted = false; forging = true; ForgeList f = new ForgeList(); foreach (var i in f.combos) { for (var x = 0; x < i.Key.Length; x++) { requestedItems.Add(i.Key[x]); } for (var x = 0; x < Inventory.Length; x++) { if (Inventory[x] != null) { playerItems.Add(Inventory[x].ObjectId); } } for (var x = 0; x < playerItems.Count; x++) { for (var y = 0; y < requestedItems.Count; y++) { if (requestedItems[y] == playerItems[x]) { requestedItems.RemoveAt(y); break; } } } if (requestedItems.Count == 0) { var icdatas = new Dictionary<string, short>(db.data.XmlDatas.IdToType, StringComparer.OrdinalIgnoreCase); short objType; icdatas.TryGetValue(i.Value, out objType); forgableItems.Add(objType); } } if (forgableItems.Count < Inventory.Length) { for (var i = forgableItems.Count; i < Inventory.Length; i++) { forgableItems.Add(-1); } } var my = new TradeItem[Inventory.Length]; for (var i = 0; i < Inventory.Length; i++) { my[i] = new TradeItem { Item = forgableItems[i], SlotType = SlotTypes[0], Included = false, Tradeable = forgableItems[i] != -1 }; } var your = new TradeItem[12]; for (var i = 0; i < Inventory.Length; i++) your[i] = new TradeItem { Item = Inventory[i] == null ? -1 : Inventory[i].ObjectType, SlotType = SlotTypes[i], Included = false, Tradeable = false }; psr.SendPacket(new TradeStartPacket { MyItems = my, YourName = "Items", YourItems = your }); }
public void RequestTrade(RealmTime time, RequestTradePacket pkt) { if (!NameChosen) { psr.SendPacket(new TextPacket() { BubbleTime = 0, Stars = -1, Name = "", Text = "Unique name is required to trade with other!" }); return; } if (tradeTarget != null) { psr.SendPacket(new TextPacket() { BubbleTime = 0, Stars = -1, Name = "*Error*", Text = "You're already trading!" }); return; } Player target = Owner.GetUniqueNamedPlayer(pkt.Name); if (target == null) { psr.SendPacket(new TextPacket() { BubbleTime = 0, Stars = -1, Name = "*Error*", Text = "Player not found!" }); return; } if (target.tradeTarget != null && target.tradeTarget != this) { psr.SendPacket(new TextPacket() { BubbleTime = 0, Stars = -1, Name = "*Error*", Text = target.Name + " is already trading!" }); return; } if (this.potentialTrader.ContainsKey(target)) { this.tradeTarget = target; this.trade = new bool[12]; this.tradeAccepted = false; target.tradeTarget = this; target.trade = new bool[12]; target.tradeAccepted = false; this.potentialTrader.Clear(); target.potentialTrader.Clear(); TradeItem[] my = new TradeItem[this.Inventory.Length]; for (int i = 0; i < this.Inventory.Length; i++) my[i] = new TradeItem() { Item = this.Inventory[i] == null ? -1 : this.Inventory[i].ObjectType, SlotType = this.SlotTypes[i], Included = false, Tradeable = (this.Inventory[i] == null || i < 4) ? false : !this.Inventory[i].Soulbound }; TradeItem[] your = new TradeItem[target.Inventory.Length]; for (int i = 0; i < target.Inventory.Length; i++) your[i] = new TradeItem() { Item = target.Inventory[i] == null ? -1 : target.Inventory[i].ObjectType, SlotType = target.SlotTypes[i], Included = false, Tradeable = (target.Inventory[i] == null || i < 4) ? false : !target.Inventory[i].Soulbound }; this.psr.SendPacket(new TradeStartPacket() { MyItems = my, YourName = target.Name, YourItems = your }); target.psr.SendPacket(new TradeStartPacket() { MyItems = your, YourName = this.Name, YourItems = my }); } else { target.potentialTrader[this] = 1000 * 20; target.psr.SendPacket(new TradeRequestedPacket() { Name = Name }); psr.SendPacket(new TextPacket() { BubbleTime = 0, Stars = -1, Name = "", Text = "You have sent a trade request to " + target.Name + "!" }); return; } }
private static void InjectBonusesToItemTemplate(XmlWriterSettings saveSettings, string outputPath) { try { using (var fs = new FileStream(Path.Combine(root, @".\data\item_templates.xml"), FileMode.Open, FileAccess.Read)) using (var reader = XmlReader.Create(fs)) { XmlSerializer ser = new XmlSerializer(typeof(ItemTemplates)); Utility.OriginalItemTemplate = (ItemTemplates)ser.Deserialize(reader); } } catch (Exception ex) { Debug.Print(ex.ToString()); return; } // Utility.CreateSkillMap(root); var allItems = itemGroups.grouped.SelectMany(g => g.items).SelectMany(s => s.items) .ToDictionary(i => i.itemId, i => i); List<int> splitItems = Utility.ItemIndex.ItemList .Where(i => (i.disassembly_item.HasValue && i.disassembly_item.Value) && i.Category == ItemCategories.harvest).Select(i => i.id).ToList(); List<int> questStart = Utility.ItemIndex.ItemList .Where(i => i.ActivateTarget == ActivateTargets.standalone && i.name.StartsWith("quest_") && i.quest == 3 && i.motion_name == null && i.area_to_use == null). Select(i => i.id).ToList(); Dictionary<int, List<int>> itemSkillPoints; Dictionary<int, List<int>> taskLevels = taskExport.RaceTasks.SelectMany(r => r.Tasks) .SelectMany(t => AggregatedTaskItem.CreateList(t.Items, t.race, t.skill, t.skillpoints)) .Aggregate(itemSkillPoints = new Dictionary<int, List<int>>(), (l, a) => { if (a.SkillId == 0 || a.SkillPoints > 399) return l; int bonusLevel = a.SkillId; bonusLevel <<= 10; bonusLevel |= a.SkillPoints; if (l.ContainsKey(a.ItemId)) { var skillPoints = l[a.ItemId]; skillPoints.Add(bonusLevel); } else { List<int> list = new List<int>(); list.Add(bonusLevel); l.Add(a.IsRecipe ? -a.ItemId : a.ItemId, list); } return l; }); var elyosCraftItems = taskExport.RaceTasks[0].Tasks.SelectMany(t => t.Items).Select(rc => rc.id); var asmoCraftItems = taskExport.RaceTasks[1].Tasks.SelectMany(t => t.Items).Select(rc => rc.id); var commonCraftItems = elyosCraftItems.Intersect(asmoCraftItems).ToList(); elyosCraftItems = elyosCraftItems.Except(commonCraftItems); asmoCraftItems = asmoCraftItems.Except(commonCraftItems); questStart.Add(182200214); // Namus's Diary // Documents which start quests questStart.Add(182200558); // Odium Refining Method questStart.Add(182200559); // Bandit's Letter questStart.Add(182201728); // Parchment Map questStart.Add(182201744); // Mapping the Revolutionaries questStart.Add(182201765); // Old Letter questStart.Add(182201770); // Adventurer's Diary questStart.Add(182203107); // Rolled Scroll questStart.Add(182203130); // Old Scroll questStart.Add(182203263); // A Bill Found in a Box questStart.Add(182204169); // Pamphlet questStart.Add(182204232); // Sodden Scroll questStart.Add(182204501); // Lepharist Book questStart.Add(182206084); // Lifeform Remodeling Report questStart.Add(182206700); // Dusty Book questStart.Add(182206722); // Balaur's Quartz of Memory questStart.Add(182206724); // Balaur's Map questStart.Add(182207009); // Ornate Jewelry Box questStart.Add(182207127); // Lifeform Remodeling Report questStart.Add(182207865); // Half-folded Paper questStart.Add(182208034); // Bloodied Note questStart.Add(182208043); // Red Journal questStart.Add(182208053); // Research Center Document questStart.Add(182209024); // Wet Letter questStart.Add(182209037); // Zombie's Diary questStart.Add(182209824); // Worn Book - 2.0 questStart.Remove(182206722); // Murmur Fluid questStart.Remove(182206724); // Seasoned Moonflower Vegetables questStart.Add(182201309); // Jewel Box questStart.Add(182201400); // Fire Temple Key questStart.Add(182206842); // Vorgaltem Secret Order questStart.Add(182206843); // Stanis's Secret Order questStart.Add(182206844); // Temenos's Secret Order questStart.Add(182206845); // Omega's Fragment questStart.Add(182206846); // Violet Orb questStart.Add(182206847); // Violet Orb questStart.Add(182206848); // Violet Orb questStart.Add(182207845); // Angrief Special Orders questStart.Add(182207846); // Fundin's Special Orders questStart.Add(182207847); // Kirhua's Special Orders questStart.Add(182207848); // Shining Scroll questStart.Add(182207920); // Berokin's Image Marble questStart.Add(182207923); // Sakti's Crystal ItemTemplates saveTemplate = new ItemTemplates(); List<ItemTemplate> exportTemplates = new List<ItemTemplate>(); saveTemplate.TemplateList = new ItemTemplate[allItems.Count]; var enumerator = allItems.Values.GetEnumerator(); StringBuilder sqlData = new StringBuilder(); while (enumerator.MoveNext()) { ItemTemplate template = new ItemTemplate(); exportTemplates.Add(template); ItemExport exportItem = enumerator.Current; Item originalItem = exportItem.originalItem; template.id = exportItem.itemId; template.race = originalItem.race; template.origRace = exportItem.raceInternal; // zp - al3 3.0 Template Updates template.attack_gap = originalItem.attack_gap; //template.weapon_stats = originalItem.GetWeaponStats(); template.burn_attack = originalItem.burn_on_attack; template.burn_defend = originalItem.burn_on_defend; if (originalItem.charge_level != 0) { template.charge_level = originalItem.charge_level; template.charge_price1 = (int)(originalItem.charge_price1 * 1000000); template.charge_price2 = (int)(originalItem.charge_price2 * 1000000); } if (!String.IsNullOrEmpty(originalItem.gender_permitted)) template.gender = (Gender)Enum.Parse(typeof(Gender), originalItem.gender_permitted, true); /* zp - Correction is Incorrect? Recipe Templates are correct and items are correct before this correction? if (elyosCraftItems.Contains(template.id)) template.origRace = ItemRace.ELYOS; else if (asmoCraftItems.Contains(template.id)) template.origRace = ItemRace.ASMODIANS; if (template.race != template.origRace) { if (template.race != ItemRace.PC_ALL) { Debug.Print("Race mismatch... id: {0}", template.id); } } */ /* if (feedItems.ContainsKey(template.id)) { template.feed = feedItems[template.id].ToArray(); } if (originalItem.doping_pet_useable) { var feedItem = new ItemFeed() { type = FoodType.DOPING }; if (template.feed == null) template.feed = new ItemFeed[1] { feedItem }; else { Array.Resize(ref template.feed, template.feed.Length + 1); template.feed[template.feed.Length - 1] = feedItem; } } if (originalItem.quest == 0 && originalItem.Quality == ItemQualities.junk && originalItem.name.IndexOf("_pet_reward") == -1 && originalItem.name.IndexOf("_petreward") == -1 && originalItem.tag == ItemTag.none) { string descr = originalItem.Description; if (descr != null && descr.IndexOf("stinking", StringComparison.CurrentCultureIgnoreCase) == -1) { var feedItem = new ItemFeed() { type = FoodType.MISC }; if (template.feed == null) template.feed = new ItemFeed[1] { feedItem }; else { Array.Resize(ref template.feed, template.feed.Length + 1); template.feed[template.feed.Length - 1] = feedItem; } } } Thread.Sleep(10); */ if (splitItems.Contains(template.id) || Utility.OriginalDecomposableItemsFile.isDecomposable(template.id)) { if (template.actions == null) { template.actions = new ItemActions[1]; template.actions[0] = new ItemActions(); } template.actions[0].split = new SplitAction[1] { new SplitAction() }; } if (originalItem.cash_social > 0) { if (template.actions == null) { template.actions = new ItemActions[1]; template.actions[0] = new ItemActions(); } var ema = new EmotionAction(); ema.emotionid = originalItem.cash_social; if (originalItem.cash_available_minute > 0) { ema.minutes = originalItem.cash_available_minute; if (ema.minutes > 60) ema.minutes--; } template.actions[0].emotion = new EmotionAction[1] { ema }; } if (originalItem.cash_title > 0) { if (template.actions == null) { template.actions = new ItemActions[1]; template.actions[0] = new ItemActions(); } var tia = new TitleAction(); tia.titleid = originalItem.cash_title; if (originalItem.cash_available_minute > 0) { tia.minutes = originalItem.cash_available_minute; if (tia.minutes > 60) tia.minutes--; } template.actions[0].title = new TitleAction[1] { tia }; } if (template.actions != null && template.actions[0] != null && !template.HasActions()) { template.actions = null; // clear } if (questStart.Contains(template.id)) { if (template.actions == null) { template.actions = new ItemActions[1]; template.actions[0] = new ItemActions(); } /* if (template.quest == 0) { Item item = Utility.ItemIndex.ItemList.Where(i => i.id == template.id).FirstOrDefault(); int pos = item.name.LastIndexOf('_'); template.quest = Int32.Parse(item.name.Substring(pos + 1, item.name.Length - 2 - pos)); template.questSpecified = true; } */ var qa = new QuestStartAction(); // qa.questid = template.quest; // qa.questidSpecified = true; template.actions[0].queststart = new QuestStartAction[1] { qa }; } template.can_fuse = exportItem.canFuse; // template.can_fuseSpecified = true; // flavour.name = Utility.StringIndex.GetString(feed.name); // zp strip characters template.name = Utility.StringIndex.GetString(Regex.Replace(Utility.StringIndex.GetString(exportItem.desc), @"[^\u0030-\u007A\u0020]", string.Empty)); // zp add pet funct id if(originalItem.func_pet_name != null) template.func_pet_id = Utility.ToyPetIndex[originalItem.func_pet_name]; template.category = GetItemCategory(exportItem.itemIcon); template.item_type = exportItem.itemType.ToString().ToUpper(); template.mask = exportItem.mask; template.maskSpecified = true; template.expire_time = (ExpireDuration)exportItem.expire_time; template.cash_minute = (ExpireDuration)exportItem.cash_minute; template.temp_exchange_time = (ExpireDuration)exportItem.exchange_time; /* zp unused for now template.world_drop = exportItem.itemGroup == "random_drop"; if (template.world_drop || exportItem.desc != null && exportItem.desc.StartsWith("[Event")) { if (exportItem.level >= 52) template.origRace = ItemRace.PC_ALL; sqlData.AppendFormat("DELETE FROM `droplist` WHERE itemId = {0};\n", template.id); var allDrops = Utility.DropListTemplate.Drops.SelectMany(d => d.DropItems); var removed = allDrops.Where(d => d.id == template.id).ToList(); foreach (var dropEntry in Utility.DropListTemplate.Drops) { dropEntry.DropItems.RemoveAll(i => removed.Contains(i)); } } */ /* zp testing, should always be added to template string minLevel = String.Empty; for (int i = 0; i < 12; i++) minLevel += exportItem.level + ","; minLevel = minLevel.TrimEnd(','); if (exportItem.restricts != minLevel) template.restrict = exportItem.restricts; */ template.restrict = exportItem.restricts; if (exportItem.restricts_max != "0,0,0,0,0,0,0,0,0,0,0,0") template.restrict_max = exportItem.restricts_max; SkillTemplate skill = exportItem.skill_use; if (skill != null) { if (template.actions == null) template.actions = new ItemActions[1]; if (template.actions[0] == null) template.actions[0] = new ItemActions(); template.actions[0].skilluse = new SkillUseAction[1] { new SkillUseAction(skill.skill_id, skill.lvl) }; } else if (template.actions != null) { template.actions[0].skilluse = null; // clear it } if (exportItem.modifiers != null) template.modifiers = new Modifiers[1] { new Modifiers() { modifierList = exportItem.modifiers/*.OrderBy(m => m.GetType().Name) .ToList()*/ } }; else if (template.modifiers != null) template.modifiers = null; template.quality = (ItemQuality)Enum.Parse(typeof(ItemQuality), originalItem.Quality.ToString().ToUpper()); template.qualitySpecified = true; template.price = (int)originalItem.price; template.priceSpecified = template.price > 0; template.option_slot_bonus = originalItem.option_slot_bonus; if (originalItem.no_enchant != null) { bool value = originalItem.no_enchant.ToBoolean(CultureInfo.InvariantCulture); if (value) { template.no_enchant = value; } } if (originalItem.can_proc_enchant != null) { bool value = originalItem.can_proc_enchant.ToBoolean(CultureInfo.InvariantCulture); if (value) { template.can_proc_enchant = true; // template.can_proc_enchantSpecified = true; } } template.max_stack_count = originalItem.max_stack_count; template.level = originalItem.level; template.levelSpecified = true; template.slot = (int)originalItem.EquipmentSlots; if (template.slot > 0) template.slotSpecified = true; if (originalItem.weapon_boost_value > 0) { template.weapon_boost = originalItem.weapon_boost_value; template.weapon_boostSpecified = true; } if (originalItem.EquipmentSlots != EquipmentSlots.none) { if (originalItem.WeaponType != WeaponTypes.None && originalItem.WeaponType != WeaponTypes.NoWeapon) { // DAGGER_1H,MACE_1H,SWORD_1H,TOOLHOE_1H,BOOK_2H,ORB_2H, // POLEARM_2H,STAFF_2H,SWORD_2H,TOOLPICK_2H,TOOLROD_2H,BOW template.equipment_type = EquipType.WEAPON; template.equipment_typeSpecified = true; template.weapon_type = (weaponType)originalItem.WeaponType; template.weapon_typeSpecified = true; } if (originalItem.EquipmentSlots == EquipmentSlots.right_or_left_battery) { template.equipment_type = EquipType.ARMOR; template.equipment_typeSpecified = true; template.armor_type = armorType.SHARD; template.armor_typeSpecified = true; } else if (template.category == "SHIELD" || template.category == "CASH_SHIELD") { template.equipment_type = EquipType.ARMOR; template.equipment_typeSpecified = true; template.armor_type = armorType.SHIELD; template.armor_typeSpecified = true; } else if (template.category == "ARROW") { template.equipment_type = EquipType.ARMOR; template.equipment_typeSpecified = true; template.armor_type = armorType.ARROW; template.armor_typeSpecified = true; } else if (originalItem.ArmorType != ArmorTypes.none && originalItem.ArmorType != ArmorTypes.no_armor) { template.equipment_type = EquipType.ARMOR; template.equipment_typeSpecified = true; // + SHARD, ARROW, SHIELD template.armor_type = (armorType)Enum.Parse(typeof(armorType), originalItem.ArmorType.ToString().ToUpper()); template.armor_typeSpecified = true; } else if (template.equipment_type == EquipType.NONE) { template.equipment_type = EquipType.ARMOR; template.equipment_typeSpecified = true; } } //zp if(template.equipment_type == EquipType.ARMOR || template.equipment_type == EquipType.WEAPON){ //zp add manaslots bases on item rarity switch (originalItem.Quality){ case ItemQualities.common: template.m_slots = 2; break; case ItemQualities.rare: template.m_slots = 3; break; case ItemQualities.legend: template.m_slots = 4; break; case ItemQualities.unique: template.m_slots = 5; break; case ItemQualities.epic: template.m_slots = 6; break; default: template.m_slots = 1; break; } //zp add random manaslots bases on item type switch (originalItem.ItemType) { case ItemTypes.normal: template.m_slots_r = 1; break; case ItemTypes.abyss: template.m_slots_r = 2; break; case ItemTypes.draconic: template.m_slots_r = 1; break; case ItemTypes.devanion: template.m_slots_r = 0; break; default: template.m_slots_r = 0; break; } } // Check if missing original description, some test items or bugged data in client etc? if (!String.IsNullOrEmpty(originalItem.desc)) { int desc = Utility.StringIndex[originalItem.desc]; // if desc id not found in item strings keep searching // search general strings if (desc == -1) { desc = Utility.StringIndex[originalItem.desc]; } // if desc id not found in general strings keep searching // search quest strings if (desc == -1) { desc = Utility.StringIndex[originalItem.desc]; } // Log if string name id can not be found // Leave -1 for template search to add missing string files if necessary if (desc == -1) { Debug.Print("Missing description for {0}", originalItem.id); } if (desc != -1) { template.desc = desc * 2 + 1; } else { template.desc = desc; } template.descSpecified = true; } /* Old Way to get name desc id Just for documentation if (!String.IsNullOrEmpty(originalItem.desc)) { int desc = Utility.ItemStringIndex[originalItem.desc]; if (desc != -1) { template.desc = desc * 2 + 1; template.descSpecified = true; } else { Debug.Print("Missing description for {0}", originalItem.id); } } */ if (originalItem.item_drop_permitted != null) { bool value = originalItem.item_drop_permitted.ToBoolean(CultureInfo.InvariantCulture); if (value) { template.drop = true; // template.dropSpecified = true; } } template.usedelayid = originalItem.use_delay_type_id; if (template.usedelayid > 0) { template.usedelayidSpecified = true; template.usedelay = originalItem.use_delay; template.usedelaySpecified = template.usedelay > 0; } if (originalItem.require_shard > 0) { template.stigma = new Stigma(); template.stigma.shard = originalItem.require_shard; template.stigma.shardSpecified = true; ClientSkill stigmaSkill = Utility.SkillIndex[originalItem.gain_skill1]; if (stigmaSkill != null) { // gain_skill2 and gain_level2 used only in the test item template.stigma.skillid = stigmaSkill.id; template.stigma.skillidSpecified = true; template.stigma.skilllvl = originalItem.gain_level1; template.stigma.skilllvlSpecified = true; var utility = Utility<Item>.Instance; List<string> requiredSkills = new List<string>(); utility.Export<String>(originalItem, "require_skill", requiredSkills); if (requiredSkills.Count > 0) { List<RequireSkill> skills = new List<RequireSkill>(); for (int n = 1; n <= requiredSkills.Count; n++) { FieldInfo fld = typeof(Item).GetField(String.Format("require_skill{0}_lv", n), BindingFlags.Instance | BindingFlags.Public); int skillLvl = (int)fld.GetValue(originalItem); string[] skillIds = requiredSkills[n - 1].Split(new string[] { " ", "," }, StringSplitOptions.RemoveEmptyEntries); List<int> ids = new List<int>(); foreach (string skillId in skillIds) { stigmaSkill = Utility.SkillIndex[skillId]; if (stigmaSkill != null && stigmaSkill.id > 0) ids.Add(stigmaSkill.id); } if (ids.Count > 0) skills.Add(new RequireSkill() { skillId = ids.ToArray(), skilllvl = skillLvl, skilllvlSpecified = true }); } if (skills.Count > 0) template.stigma.require_skill = skills.ToArray(); } } else { Debug.Print("Missing stigma for {0}", originalItem.id); } } if (originalItem.can_dye) { template.dye = true; } if (originalItem.craft_recipe_info != null) { var recipe = Utility.RecipeIndex[originalItem.craft_recipe_info]; if (recipe != null) { if (template.actions == null) template.actions = new ItemActions[1]; if (template.actions[0] == null) template.actions[0] = new ItemActions(); var action = new CraftLearnAction(); action.recipeid = recipe.id; action.recipeidSpecified = true; template.actions[0].craftlearn = new CraftLearnAction[1] { action }; } else { Debug.Print("Missing recipe for {0}", originalItem.id); } } if (!String.IsNullOrEmpty(originalItem.dyeing_color) || originalItem.name == "dye_remover") { if (template.actions == null) template.actions = new ItemActions[1]; if (template.actions[0] == null) template.actions[0] = new ItemActions(); var action = new DyeAction(); if (originalItem.name == "dye_remover") action.color = "no"; else action.color = action.color = getHexRGB(originalItem.dyeing_color); template.actions[0].dye = new DyeAction[1] { action }; } // add item action for charging items if (originalItem.charge_capacity > 0) { if (template.actions == null) template.actions = new ItemActions[1]; if (template.actions[0] == null) template.actions[0] = new ItemActions(); var action = new ChargeAction(); action.capacity = originalItem.charge_capacity; /* if(originalItem.name.Contains("pack")){ action.isPack = true; }else{ action.isPack = false; } */ template.actions[0].condition = new ChargeAction[1] { action }; } // add trade items if (originalItem.tradeItems.Count > 0) { List<TradeItem> tradelist = new List<TradeItem>(); foreach (var tradeItem in originalItem.tradeItems) { TradeItem outputItem = new TradeItem(); outputItem.id = Utility.ItemIndex.GetItem(tradeItem.trade_in_item).id; outputItem.price = tradeItem.trade_in_item_count; tradelist.Add(outputItem); } TradeItemList newTradeItemList = new TradeItemList(); newTradeItemList.tradeItems = tradelist.ToArray(); template.tradeList = newTradeItemList; } // add item action for motions if (originalItem.name.Contains("customize_motion")) { if (template.actions == null) template.actions = new ItemActions[1]; if (template.actions[0] == null) template.actions[0] = new ItemActions(); var action = new MotionAction(); string typeofmotion = String.Empty; typeofmotion = template.name.Contains("Ninja") ? "NINJA" : typeofmotion; typeofmotion = template.name.Contains("Hovering") ? "HOVERING" : typeofmotion; typeofmotion = template.name.Contains("Levitation") ? "LEVITATION" : typeofmotion; switch (typeofmotion) { case "NINJA": action.idle = 1; action.jump = 3; action.rest = 4; action.run = 2; action.minutes = originalItem.anim_expire_time != 0 ? originalItem.anim_expire_time : 0; break; case "HOVERING": action.idle = 5; action.jump = 7; action.rest = 8; action.run = 6; action.minutes = originalItem.anim_expire_time != 0 ? originalItem.anim_expire_time : 0; break; case "LEVITATION": action.idle = 5; action.jump = 7; action.rest = 8; action.run = 8; action.minutes = originalItem.anim_expire_time != 0 ? originalItem.anim_expire_time : 0; break; } Debug.Write("Missing animation action for itemId: " + template.id); template.actions[0].motion = new MotionAction[1] { action }; } // add item action for ride if (originalItem.name.Contains("ride_") && originalItem.ride_data_name != null) { if (template.actions == null) template.actions = new ItemActions[1]; if (template.actions[0] == null) template.actions[0] = new ItemActions(); var action = new RideAction(); // Associate with Ride data // TODO: Add parser for rides.xml in client and crossreference ride id by name of ride string[] rideSplit = originalItem.ride_data_name.Split('_'); switch (rideSplit[0].ToUpper()) { case "CLOUD": switch (rideSplit[1].ToUpper()) { case "001": if (rideSplit.Length > 2) { action.rideId = 2000015; break; } action.rideId = 2000000; break; case "002": if (rideSplit.Length > 2) { action.rideId = 2000018; break; } action.rideId = 2000001; break; case "003": action.rideId = 2000002; break; } break; case "PAGATI": switch (rideSplit[1].ToUpper()) { case "001": if (originalItem.ride_data_name.ToUpper() == "PAGATI_001_ET5") { action.rideId = 2000014; break; } if (rideSplit.Length > 2) { action.rideId = 2000024; break; } action.rideId = 2000003; break; case "002": if (rideSplit.Length > 2) { action.rideId = 2000021; break; } action.rideId = 2000004; break; } break; case "RAY": switch (rideSplit[1].ToUpper()) { case "001": action.rideId = 2000005; break; case "002": action.rideId = 2000006; break; case "003": action.rideId = 2000007; break; } break; case "BIKE": switch (rideSplit[1].ToUpper()) { case "001": if (rideSplit.Length > 2) { action.rideId = 2000023; break; } action.rideId = 2000008; break; case "002": if (rideSplit.Length > 2) { action.rideId = 2000020; break; } action.rideId = 2000009; break; } break; case "WHALE": switch (rideSplit[1].ToUpper()) { case "001": if (originalItem.ride_data_name.ToUpper() == "WHALE_001_LIGHT") { action.rideId = 2000019; break; } if (rideSplit.Length > 2) { action.rideId = 2000016; break; } action.rideId = 2000010; break; case "002": if (originalItem.ride_data_name.ToUpper() == "WHALE_002_ET60") { action.rideId = 2000014; break; } if (originalItem.ride_data_name.ToUpper() == "WHALE_002_WORLD") { action.rideId = 2000022; break; } if (rideSplit.Length > 2) { action.rideId = 2000017; break; } action.rideId = 2000011; break; case "003": action.rideId = 2000012; break; } break; } template.actions[0].ride = new RideAction[1] { action }; } if (!String.IsNullOrEmpty(originalItem.cosmetic_name)) { CosmeticInfo info = Utility.CosmeticsIndex[originalItem.cosmetic_name.ToLower()]; if (info == null) { Debug.Print("Cosmetics not found: {0}", originalItem.cosmetic_name); } else { if (template.actions == null) template.actions = new ItemActions[1]; if (template.actions[0] == null) template.actions[0] = new ItemActions(); var action = new CosmeticAction(); if (info.hair_type > 0) { action.cosmeticName = CosmeticType.hair_type; } if (info.face_type > 0) { action.cosmeticName = CosmeticType.face_type; } if (info.makeup_type > 0) { action.cosmeticName = CosmeticType.makeup_type; } if (info.tattoo_type > 0) { action.cosmeticName = CosmeticType.tattoo_type; } if (info.voice_type > 0) { action.cosmeticName = CosmeticType.voice_type; } if (!String.IsNullOrEmpty(info.face_color)) { action.cosmeticName = CosmeticType.face_color; } if (!String.IsNullOrEmpty(info.hair_color)) { action.cosmeticName = CosmeticType.hair_color; } if (!String.IsNullOrEmpty(info.lip_color)) { action.cosmeticName = CosmeticType.lip_color; } if (!String.IsNullOrEmpty(info.eye_color)) { action.cosmeticName = CosmeticType.eye_color; } if (!String.IsNullOrEmpty(info.preset_name)) { action.cosmeticName = CosmeticType.preset_name; } template.actions[0].cosmetic = new CosmeticAction[1] { action }; } } if (originalItem.inven_warehouse_max_extendlevel != 0 && (template.category == "CUBE" || template.category == "CASH_CARD")) { if (template.actions == null) template.actions = new ItemActions[1]; if (template.actions[0] == null) template.actions[0] = new ItemActions(); var action = new TicketAction(); action.storage = template.category == "CUBE" ? StorageType.CUBE : StorageType.WAREHOUSE; template.actions[0].ticket = new TicketAction[1] { action }; } if (!String.IsNullOrEmpty(originalItem.proc_enchant_skill)) { ClientSkill enchantSkill = Utility.SkillIndex[originalItem.proc_enchant_skill]; if (enchantSkill != null) { template.godstone = new Godstone(); template.godstone.probability = originalItem.proc_enchant_effect_occur_prob; if (template.godstone.probability > 0) template.godstone.probabilitySpecified = true; template.godstone.probabilityleft = originalItem.proc_enchant_effect_occur_left_prob; template.godstone.skillid = enchantSkill.id; template.godstone.skillidSpecified = true; template.godstone.skilllvl = originalItem.proc_enchant_skill_level; template.godstone.skilllvlSpecified = true; } else { Debug.Print("Missing godstone for {0}", originalItem.id); } } if (!String.IsNullOrEmpty(originalItem.skill_to_learn)) { ClientSkill learnSkill = Utility.SkillIndex[originalItem.skill_to_learn]; if (learnSkill != null) { if (template.actions == null) template.actions = new ItemActions[1]; if (template.actions[0] == null) template.actions[0] = new ItemActions(); var learns = Utility.SkillLearnIndex[originalItem.skill_to_learn]; if (learns.Count() > 0) { var validActions = new List<SkillLearnAction>(); for (int i = 0; i < learns.Count(); i++) { LearnSkill learn = learns.ElementAt(i); if (learn.skill_level > 1) continue; var action = new SkillLearnAction(); validActions.Add(action); action.skillid = learnSkill.id; action.skillidSpecified = true; action.@class = (skillPlayerClass)Enum.Parse(typeof(skillPlayerClass), learn.@class); action.classSpecified = true; // zp fix reference switch (action.@class) { case skillPlayerClass.FIGHTER: action.@class = skillPlayerClass.GLADIATOR; break; case skillPlayerClass.KNIGHT: action.@class = skillPlayerClass.TEMPLAR; break; case skillPlayerClass.WIZARD: action.@class = skillPlayerClass.SORCERER; break; case skillPlayerClass.ELEMENTALLIST: action.@class = skillPlayerClass.SPIRIT_MASTER; break; } action.level = learn.pc_level; action.levelSpecified = true; /* action.race = learn.skillRace; action.raceSpecified = true; */ } template.actions[0].skilllearn = validActions.ToArray(); } } else { Debug.Print("Missing learn skill for {0}", originalItem.id); } } if (!String.IsNullOrEmpty(originalItem.toy_pet_name)) { int npcId = Utility.ClientNpcIndex[originalItem.toy_pet_name]; if (npcId == -1) Debug.Print("Missing pet NPC for {0}", originalItem.id); else { if (template.actions == null) template.actions = new ItemActions[1]; if (template.actions[0] == null) template.actions[0] = new ItemActions(); var action = new ToyPetSpawnAction(); action.npcid = npcId; action.npcidSpecified = true; template.actions[0].toypetspawn = new ToyPetSpawnAction[1] { action }; } } if (originalItem.return_worldid > 0) { template.return_world = originalItem.return_worldid; template.return_worldSpecified = true; if (!String.IsNullOrEmpty(originalItem.return_alias)) template.return_alias = originalItem.return_alias.ToUpper(); } if (template.category == "PINCER") { if (template.actions == null) template.actions = new ItemActions[1]; if (template.actions[0] == null) template.actions[0] = new ItemActions(); var action = new ExtractAction(); template.actions[0].extract = new ExtractAction[1] { action }; } if (originalItem.sub_enchant_material_many > 0) { if (template.actions == null) template.actions = new ItemActions[1]; if (template.actions[0] == null) template.actions[0] = new ItemActions(); var action = new EnchantItemAction(); //action.count = originalItem.sub_enchant_material_many; template.actions[0].enchant = new EnchantItemAction[1] { action }; } if (originalItem.AttackType != AttackTypes.none) { template.attack_type = originalItem.AttackType.ToString().ToUpper(); } if (originalItem.abyss_point > 0) { template.ap = (int)originalItem.abyss_point; } if (originalItem.abyss_item_count > 0) { template.aic = (int)originalItem.abyss_item_count; } if (!String.IsNullOrEmpty(originalItem.abyss_item)) { Item abyssItem = Utility.ItemIndex.GetItem(originalItem.abyss_item); if (abyssItem == null) Debug.Print("Missing abyss item for {0}", originalItem.id); else { template.ai = abyssItem.id; } } if (originalItem.extra_currency_item_count > 0) { template.ric = (int)originalItem.extra_currency_item_count; } if (!String.IsNullOrEmpty(originalItem.extra_currency_item)) { Item extraItem = Utility.ItemIndex.GetItem(originalItem.extra_currency_item); if (extraItem == null) Debug.Print("Missing extra item for {0}", originalItem.id); else { template.ri = extraItem.id; } } /* if (originalItem.coupon_item_count > 0) { template.cic = (int)originalItem.coupon_item_count; } if (!String.IsNullOrEmpty(originalItem.coupon_item)) { Item extraItem = Utility.ItemIndex.GetItem(originalItem.coupon_item); if (extraItem == null) Debug.Print("Missing extra item for {0}", originalItem.id); else { template.ci = extraItem.id; } } */ if (originalItem.BonusApply != Bonuses.none) { template.bonus_apply = (BonusApplyType)Enum.Parse(typeof(BonusApplyType), originalItem.BonusApply.ToString().ToUpper()); // template.bonus_applySpecified = true; } // template.name } saveTemplate.TemplateList = exportTemplates.OrderBy(i => i.id).ToArray(); //var droplistDrops = Utility.DropListTemplate.Drops.SelectMany(d => d.DropItems); //var existingItems = exportTemplates.Select(t => t.id); //var nonexistant = droplistDrops.Where(d => !existingItems.Contains(d.id)).ToList(); //foreach (var dropEntry in Utility.DropListTemplate.Drops) { // dropEntry.DropItems.RemoveAll(i => nonexistant.Contains(i)); //} using (FileStream stream = new FileStream(Path.Combine(outputPath, "item_templates.xml"), FileMode.Create, FileAccess.Write)) { using (XmlWriter wr = XmlWriter.Create(stream, saveSettings)) { XmlSerializer ser = new XmlSerializer(typeof(ItemTemplates)); ser.Serialize(wr, saveTemplate); } } using (FileStream stream = new FileStream(Path.Combine(outputPath, "clean_world_drops.sql"), FileMode.Create, FileAccess.Write)) { using (var wr = new StreamWriter(stream, Encoding.ASCII)) { wr.Write(sqlData.ToString()); } } var emptyDrops = Utility.DropListTemplate.Drops.Where(d => d.DropItems.Count == 0).ToList(); Utility.DropListTemplate.Drops.RemoveAll(d => emptyDrops.Contains(d)); using (FileStream stream = new FileStream(Path.Combine(outputPath, "droplist.xml"), FileMode.Create, FileAccess.Write)) { using (XmlWriter wr = XmlWriter.Create(stream, saveSettings)) { XmlSerializer ser = new XmlSerializer(typeof(Droplist)); ser.Serialize(wr, Utility.DropListTemplate); } } // Do some tests // TestUtility.TestWorkOrders(itemTemplates); }
public void RequestTrade(RealmTime time, RequestTradePacket pkt) { if (!NameChosen) { SendInfo("Unique name is required to trade with others!"); return; } var target = Owner.GetUniqueNamedPlayer(pkt.Name); if (intake) { SendError(target.Name + " is already trading!"); return; } if (tradeTarget != null) { SendError("You're already trading!"); tradeTarget = null; return; } //if (psr.Player == target) //{ // SendError("Trading with yourself would be pointless."); // tradeTarget = null; // return; //} if (target == null) { SendError("Player not found!"); return; } if (target.tradeTarget != null && target.tradeTarget != this) { SendError(target.Name + " is already trading!"); return; } if (potentialTrader.ContainsKey(target)) { tradeTarget = target; trade = new bool[12]; tradeAccepted = false; target.tradeTarget = this; target.trade = new bool[12]; target.tradeAccepted = false; potentialTrader.Clear(); target.potentialTrader.Clear(); taking = false; var my = new TradeItem[Inventory.Length]; for (var i = 0; i < Inventory.Length; i++) my[i] = new TradeItem { Item = Inventory[i] == null ? -1 : Inventory[i].ObjectType, SlotType = SlotTypes[i], Included = false, Tradeable = (Inventory[i] != null && i >= 4) && (!Inventory[i].Soulbound && !Inventory[i].Undead && !Inventory[i].SUndead) }; var your = new TradeItem[target.Inventory.Length]; for (var i = 0; i < target.Inventory.Length; i++) your[i] = new TradeItem { Item = target.Inventory[i] == null ? -1 : target.Inventory[i].ObjectType, SlotType = target.SlotTypes[i], Included = false, Tradeable = (target.Inventory[i] != null && i >= 4) && (!target.Inventory[i].Soulbound && !target.Inventory[i].Undead && !target.Inventory[i].SUndead) }; psr.SendPacket(new TradeStartPacket { MyItems = my, YourName = target.Name, YourItems = your }); target.psr.SendPacket(new TradeStartPacket { MyItems = your, YourName = Name, YourItems = my }); } else { target.potentialTrader[this] = 1000*20; target.psr.SendPacket(new TradeRequestedPacket { Name = Name }); SendInfo("Sent trade request to " + target.Name); } }