public MarketResult AddToMarket(int slot, int price) { var acc = Client.Account; if (!(Owner is Marketplace)) { return(LogError(MarketResult.NotMarketPlace)); } if (!Manager.Config.serverSettings.enableMarket) { return(LogError(MarketResult.MarketplaceDisabled)); } if (tradeTarget != null) { return(LogError(MarketResult.CurrentlyTrading)); } if (slot >= Inventory.Length) { return(LogError(MarketResult.InvalidSlot)); } if (price < 0) { return(LogError(MarketResult.PriceLessThanZero)); } var it = Inventory.CreateTransaction(); var item = it[slot]; it[slot] = null; if (item == null) { return(LogError(MarketResult.NullItem)); } //if (item.Soulbound) //return LogError(MarketResult.IsSoulbound); // create shopItem var shopItem = Manager.Database.CreatePlayerShopItemAsync( item.ObjectType, price, DateTime.UtcNow.ToUnixTimestamp(), AccountId).Result; var tran = Manager.Database.Conn.CreateTransaction(); Manager.Market.Add(shopItem, tran); if (!tran.Execute()) { return(LogError(MarketResult.AddMarketFailure)); } if (!Inventory.Execute(it)) { Manager.Market.Remove(shopItem); return(LogError(MarketResult.InventoryTransferFailure)); } Client.Account.LastMarketId = shopItem.Id; Log.Info($"{Name} added a {item.DisplayName} to the market for {price} fame"); return(MarketResult.Success); }
public void UseItem(RealmTime time, int objId, int slot, Position pos) { using (TimedLock.Lock(_useLock)) { //Log.Debug(objId + ":" + slot); var entity = Owner.GetEntity(objId); if (entity == null) { Client.SendPacket(new InvResult() { Result = 1 }); return; } if (entity is Player && objId != Id) { Client.SendPacket(new InvResult() { Result = 1 }); return; } var container = entity as IContainer; // eheh no more clearing BBQ loot bags if (this.Dist(entity) > 3) { Client.SendPacket(new InvResult() { Result = 1 }); return; } var cInv = container?.Inventory.CreateTransaction(); // get item Item item = null; foreach (var stack in Stacks.Where(stack => stack.Slot == slot)) { item = stack.Pull(); if (item == null) { return; } break; } if (item == null) { if (container == null) { return; } item = cInv[slot]; } if (item == null) { return; } // make sure not trading and trying to cunsume item if (tradeTarget != null && item.Consumable) { return; } if (MP < item.MpCost) { Client.SendPacket(new InvResult() { Result = 1 }); return; } // use item var slotType = 10; if (slot < cInv.Length) { slotType = container.SlotTypes[slot]; if (item.TypeOfConsumable) { var gameData = Manager.Resources.GameData; var db = Manager.Database; if (item.Consumable) { Item successor = null; if (item.SuccessorId != null) { successor = gameData.Items[gameData.IdToObjectType[item.SuccessorId]]; } cInv[slot] = successor; } if (!Inventory.Execute(cInv)) // can result in the loss of an item if inv trans fails... { entity.ForceUpdate(slot); return; } if (slotType > 0) { FameCounter.UseAbility(); } else { if (item.ActivateEffects.Any(eff => eff.Effect == ActivateEffects.Heal || eff.Effect == ActivateEffects.HealNova || eff.Effect == ActivateEffects.Magic || eff.Effect == ActivateEffects.MagicNova)) { FameCounter.DrinkPot(); } } Activate(time, item, pos); return; } if (slotType > 0) { FameCounter.UseAbility(); } } else { FameCounter.DrinkPot(); } //Log.Debug(item.SlotType + ":" + slotType); if (item.Consumable || item.SlotType == slotType) { //Log.Debug("HUH"); Activate(time, item, pos); } else { Client.SendPacket(new InvResult() { Result = 1 }); } } }
public void UseItem(RealmTime time, int objId, int slot, Position pos) { using (TimedLock.Lock(_useLock)) { //Log.Debug(objId + ":" + slot); var entity = Owner.GetEntity(objId); if (entity == null) { Client.SendPacket(new InvResult() { Result = 1 }); return; } if (entity is Player && objId != Id) { Client.SendPacket(new InvResult() { Result = 1 }); return; } var container = entity as IContainer; // eheh no more clearing BBQ loot bags if (this.Dist(entity) > 3) { Client.SendPacket(new InvResult() { Result = 1 }); return; } var cInv = container?.Inventory.CreateTransaction(); // get item Item item = null; foreach (var stack in Stacks.Where(stack => stack.Slot == slot)) { item = stack.Pull(); if (item == null) { return; } break; } if (item == null) { if (container == null) { return; } item = cInv[slot]; } if (item == null) { return; } // make sure not trading and trying to cunsume item if (tradeTarget != null && item.Consumable) { return; } if (MP < item.MpCost) { Client.SendPacket(new InvResult() { Result = 1 }); return; } // use item var slotType = 10; if (slot < cInv.Length) { slotType = container.SlotTypes[slot]; if (item.TypeOfConsumable) { var gameData = Manager.Resources.GameData; var db = Manager.Database; Item successor = null; if (item.Consumable) { // reminder that only consumables disappear if (item.SuccessorId != null) { successor = gameData.Items[gameData.IdToObjectType[item.SuccessorId]]; } cInv[slot] = successor; var trans = db.Conn.CreateTransaction(); if (container is GiftChest) { if (successor != null) { db.SwapGift(Client.Account, item.ObjectType, successor.ObjectType, trans); } else { db.RemoveGift(Client.Account, item.ObjectType, trans); } } var task = trans.ExecuteAsync(); task.ContinueWith(t => { var success = !t.IsCanceled && t.Result; if (!success || !Inventory.Execute(cInv)) // can result in the loss of an item if inv trans fails... { entity.ForceUpdate(slot); return; } if (slotType > 0) { FameCounter.UseAbility(); } else { if (item.ActivateEffects.Any(eff => eff.Effect == ActivateEffects.Heal || eff.Effect == ActivateEffects.HealNova || eff.Effect == ActivateEffects.Magic || eff.Effect == ActivateEffects.MagicNova)) { FameCounter.DrinkPot(); } } Activate(time, item, pos); }); task.ContinueWith(e => Log.Error(e.Exception.InnerException.ToString()), TaskContinuationOptions.OnlyOnFaulted); return; } if (!Inventory.Execute(cInv)) // can result in the loss of an item if inv trans fails... { entity.ForceUpdate(slot); return; } if (slotType > 0) { FameCounter.UseAbility(); } else { if (item.ActivateEffects.Any(eff => eff.Effect == ActivateEffects.Heal || eff.Effect == ActivateEffects.HealNova || eff.Effect == ActivateEffects.Magic || eff.Effect == ActivateEffects.MagicNova)) { FameCounter.DrinkPot(); } } Activate(time, item, pos); return; } if (slotType > 0) { FameCounter.UseAbility(); } } else { FameCounter.DrinkPot(); } //Log.Debug(item.SlotType + ":" + slotType); if (item.Consumable || item.SlotType == slotType) { //Log.Debug("HUH"); Activate(time, item, pos); } else { Client.SendPacket(new InvResult() { Result = 1 }); } } }