Ejemplo n.º 1
0
        private void ErstelleTasche(object[] ParameterListe)
        {
            double Kopfhöhe       = Convert.ToDouble(ParameterListe[7]);
            double Durchmesser    = Convert.ToDouble(ParameterListe[1]);
            double Schlüsseltiefe = 0 - Durchmesser / 2;

            // Listen Werte wieder in richtige Datentypen umwandeln
            int    Kopf              = Convert.ToInt32(ParameterListe[0]);
            double Gewindelänge      = Convert.ToDouble(ParameterListe[2]);
            double Schaftlänge       = Convert.ToDouble(ParameterListe[3]);
            double Steigung          = Convert.ToDouble(ParameterListe[4]);
            int    Gewindeart        = Convert.ToInt32(ParameterListe[5]);
            double Schlüsselweite    = Convert.ToDouble(ParameterListe[6]);
            double Kopfdurchmesser   = Convert.ToDouble(ParameterListe[8]);
            string Schraubenrichtung = Convert.ToString(ParameterListe[9]);


            // Tasche erzeugen
            ShapeFactory catShapeFactory11 = (ShapeFactory)hsp_catiaPart.Part.ShapeFactory;

            Pocket catPad3 = catShapeFactory11.AddNewPocket(hsp_catiaProfil_Schlüssel, Schlüsseltiefe);

            // Part aktualisieren
            hsp_catiaPart.Part.Update();
        }
Ejemplo n.º 2
0
        public async Task <RequestResult <PocketViewModel> > CreateAsync(string name, string userId)
        {
            var result = new RequestResult <PocketViewModel>();

            try
            {
                var pocket = new Pocket()
                {
                    Name   = name,
                    UserId = userId
                };

                pocket = _uow.Repository <Pocket>().Create(pocket);
                await _uow.SaveChangesAsync();

                result.Obj = new PocketViewModel().SetFrom(pocket);
                result.SetStatusOK();
            }
            catch (Exception ex)
            {
                result.SetInternalServerError();
                _logger.LogException(ex);
            }

            return(result);
        }
Ejemplo n.º 3
0
    public void WearUp(int itemID, ArmorType type)
    {
        WearDown(type);
        switch (type)
        {
        case ArmorType.Body:
            Pocket.Remove(BodyID);
            BodyID = itemID;
            ChangeCharacteristicsWithItem(BodyID, 2);
            break;

        case ArmorType.Hands:
            Pocket.Remove(HandsID);
            HandsID = itemID;
            ChangeCharacteristicsWithItem(HandsID, 2);
            break;

        case ArmorType.Head:
            Pocket.Remove(HeadID);
            HeadID = itemID;
            ChangeCharacteristicsWithItem(HeadID, 2);
            break;

        case ArmorType.Legs:
            Pocket.Remove(LegsID);
            LegsID = itemID;
            ChangeCharacteristicsWithItem(LegsID, 2);
            break;
        }
    }
Ejemplo n.º 4
0
        public PocketViewModel SetFrom(Pocket entity)
        {
            Id   = entity.Id;
            Name = entity.Name;

            return(this);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Makes sure you can't combine invalid equipment, like 2H and shields.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="source"></param>
        /// <param name="target"></param>
        private void CheckRightHand(Item item, Pocket source, Pocket target)
        {
            var rightItem = this.RightHand;

            // Move 2H weapon if shield is euipped
            if (target == this.LeftHandPocket && item.IsShieldLike && (rightItem != null && rightItem.IsTwoHand))
            {
                // Switch item
                var success = _pockets[source].Add(rightItem);

                // Fallback, temp inv
                if (!success)
                {
                    success = _pockets[Pocket.Temporary].Add(rightItem);
                }

                if (success)
                {
                    _pockets[this.RightHandPocket].Remove(rightItem);

                    Send.ItemMoveInfo(_creature, rightItem, this.RightHandPocket, null);
                    Send.EquipmentMoved(_creature, this.RightHandPocket);
                }
            }
        }
Ejemplo n.º 6
0
    public void LoadPocketsFromTxt()
    {
        for (int i = 0; i < currencies.Count; i++)
        {
            if (currencies[i] == null)
            {
                continue;
            }

            Pocket tempPocket = currencyPockets[currencies[i]];
            Pocket newPocket;
            try
            {
                newPocket = SaveAndLoad.LoadFromTxt <Pocket>(currencies[i].name + ".txt");
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                newPocket = tempPocket;
            }

            if (newPocket != null)
            {
                currencyPockets[currencies[i]] = newPocket;
                onValueChange.Invoke(currencies[i], newPocket.Value);
            }
        }
    }
Ejemplo n.º 7
0
        // Returns winnings for given bet
        public virtual double PlaceBetAndSpin(Bet b)
        {
            int    result = _wheel.Spin();
            Pocket pocket = _rouletteTable.GetPocket(result);

            return(b.CalculateWinnings(pocket));
        }
Ejemplo n.º 8
0
 public float GetSpaceUsed(PocketType type)
 {
     return(Manifest.Samples
            .Where(sample => sample.Type == type)
            .Sum(sample => Manifest.GetQuantity(sample) *
                 Pocket.GetUnitSize(sample)));
 }
Ejemplo n.º 9
0
 private Pocket BackflipHorizontal(Pocket res)
 {
     if (res == Pocket.GL)
     {
         res = Pocket.DL;
     }
     else if (res == Pocket.GP)
     {
         res = Pocket.DP;
     }
     else if (res == Pocket.GS)
     {
         res = Pocket.DS;
     }
     else if (res == Pocket.DL)
     {
         res = Pocket.GL;
     }
     else if (res == Pocket.DP)
     {
         res = Pocket.GP;
     }
     else if (res == Pocket.DS)
     {
         res = Pocket.GS;
     }
     return(res);
 }
        /// <summary>
        /// Обнаружение столкновения с коллайдером лузы
        /// </summary>
        /// <param name="parBall">Шар</param>
        /// <param name="parPocket">Луза</param>
        /// <returns>True если есть столкновение</returns>
        private bool IsPocketCollision(BallModelData parBall, Pocket parPocket)
        {
            SpVector3 ballDistanceVector = parPocket.Center - parBall.Center;
            double    centersDistance    = ballDistanceVector.Length();

            return(centersDistance <= parBall.Radius + parPocket.Radius);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Modifies position in inventory.
 /// </summary>
 /// <param name="pocket"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 public void Move(Pocket pocket, int x, int y)
 {
     this.Info.Pocket = pocket;
     this.Info.Region = 0;
     this.Info.X      = x;
     this.Info.Y      = y;
 }
Ejemplo n.º 12
0
        public void Ctor_Normal_ShouldSetCardB()
        {
            var actual = new Pocket(Deck);

            Assert.IsTrue(actual.CardB.Suit.IsValid());
            Assert.IsTrue(actual.CardB.Face.IsValid());
        }
Ejemplo n.º 13
0
        public void Ctor_BinaryValid_ShouldCreate()
        {
            var actual = new Pocket(new byte[] { 0x21, 0x84 });

            Assert.AreEqual("2h", actual.CardA.ToString());
            Assert.AreEqual("8s", actual.CardB.ToString());
        }
Ejemplo n.º 14
0
        // Helpers
        // ------------------------------------------------------------------

        /// <summary>
        /// Checks and updates all equipment references for source and target.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="source"></param>
        /// <param name="target"></param>
        private void UpdateInventory(Item item, Pocket source, Pocket target)
        {
            this.CheckLeftHand(item, source, target);
            this.CheckRightHand(item, source, target);
            this.UpdateEquipReferences(source, target);
            this.CheckEquipMoved(item, source, target);
        }
        public async Task <CreateWithdrawalResponse> Handle(CreateWithdrawalRequest request, CancellationToken cancellationToken)
        {
            var result = new CreateWithdrawalResponse();

            Wallet walletForWithdrawal = await _context.Wallets
                                         .Where(x => x.WalletID == request.WalletID)
                                         .Include(x => x.Pockets)
                                         .SingleOrDefaultAsync(cancellationToken);

            if (walletForWithdrawal == null)
            {
                throw new NotFoundException(nameof(Wallet), request.WalletID);
            }

            Pocket pocketForWithdrawal = walletForWithdrawal.Pockets.Single(x => x.IsMain);

            Transaction transactionForWithdrawal = new Transaction
            {
                PocketID            = pocketForWithdrawal.PocketID,
                Amount              = -request.Amount,
                TransactionHash     = string.Empty,
                TransactionType     = TransactionType.Withdrawal,
                TransactionDateTime = request.TransactionDateTime
            };

            _context.Transactions.Add(transactionForWithdrawal);
            await _context.SaveChangesAsync(cancellationToken);

            result.TransactionID = transactionForWithdrawal.TransactionID;
            result.WalletID      = walletForWithdrawal.WalletID;

            return(result);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Unequips item in left hand/magazine, if item in right hand is moved.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="source"></param>
        /// <param name="target"></param>
        private void CheckLeftHand(Item item, Pocket source, Pocket target)
        {
            var pocketOfInterest = Pocket.None;

            if (source == Pocket.RightHand1 || source == Pocket.RightHand2)
            {
                pocketOfInterest = source;
            }
            if (target == Pocket.RightHand1 || target == Pocket.RightHand2)
            {
                pocketOfInterest = target;
            }

            if (pocketOfInterest == Pocket.None)
            {
                return;
            }

            // Check LeftHand first, switch to Magazine if it's empty
            var leftPocket = pocketOfInterest + 2;             // Left Hand 1/2
            var leftItem   = _pockets[leftPocket].GetItemAt(0, 0);

            if (leftItem == null)
            {
                leftPocket += 2;                 // Magazine 1/2
                leftItem    = _pockets[leftPocket].GetItemAt(0, 0);

                // Nothing to remove
                if (leftItem == null)
                {
                    return;
                }
            }

            // Don't remove if combination is valid, this should allow weapons
            // to be switched while having a shield equipped.
            if ((item.HasTag("/righthand/") && !item.HasTag("/bow/")) && (leftItem.HasTag("/lefthand/") && !leftItem.HasTag("/arrow/")))
            {
                return;
            }

            // Try inventory first.
            // TODO: List of pockets stuff can be auto-moved to.
            var success = _pockets[Pocket.Inventory].Add(leftItem);

            // Fallback, temp inv
            if (!success)
            {
                success = _pockets[Pocket.Temporary].Add(leftItem);
            }

            if (success)
            {
                _pockets[leftPocket].Remove(leftItem);

                Send.ItemMoveInfo(_creature, leftItem, leftPocket, null);
                Send.EquipmentMoved(_creature, leftPocket);
            }
        }
Ejemplo n.º 17
0
 public Item(int itemId, Pocket pocket, uint color1, uint color2, uint color3)
 {
     this.Info.Id     = itemId;
     this.Info.Pocket = pocket;
     this.Info.Color1 = color1;
     this.Info.Color2 = color2;
     this.Info.Color3 = color3;
 }
Ejemplo n.º 18
0
Archivo: Item.cs Proyecto: xKamuna/aura
		public Item(int itemId, Pocket pocket, uint color1, uint color2, uint color3)
		{
			this.Info.Id = itemId;
			this.Info.Pocket = pocket;
			this.Info.Color1 = color1;
			this.Info.Color2 = color2;
			this.Info.Color3 = color3;
		}
Ejemplo n.º 19
0
        /// <summary>
        /// Broadcasts EquipmentMoved in creature's range.
        /// </summary>
        /// <param name="creature"></param>
        /// <param name="from"></param>
        public static void EquipmentMoved(Creature creature, Pocket from)
        {
            var packet = new Packet(Op.EquipmentMoved, creature.EntityId);
            packet.PutByte((byte)from);
            packet.PutByte(1);

            creature.Region.Broadcast(packet, creature);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Returns true if pocket is an equipment pocket (incl Face and Hair).
 /// </summary>
 /// <param name="pocket"></param>
 /// <returns></returns>
 public static bool IsEquip(this Pocket pocket)
 {
     if ((pocket >= Pocket.Face && pocket <= Pocket.Accessory2) || (pocket >= Pocket.ArmorStyle && pocket <= Pocket.RobeStyle))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 21
0
 public Fight()
 {
     chickenA            = new Chicken();
     chickenB            = new Chicken();
     status              = "choosing";
     GamePocket          = new Pocket();
     GamePocket.AllChips = new List <Chips>();
 }
Ejemplo n.º 22
0
    public static void AddPocket(this List <Pocket> pockets, decimal amount, out Pocket pocket, params string[] labels)
    {
        var label     = new SmartLabel(labels);
        var coinsView = new CoinsView(new[] { BitcoinFactory.CreateSmartCoin(NewKey(label), amount) });

        pocket = new Pocket((label, coinsView));
        pockets.Add(pocket);
    }
Ejemplo n.º 23
0
        public ActionResult DeleteConfirmed(int id)
        {
            Pocket pocket = Db.Pocket.Find(id);

            Db.Pocket.Remove(pocket);
            Db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Sends ItemRemove to creature's client.
        /// </summary>
        /// <param name="creature"></param>
        /// <param name="item"></param>
        /// <param name="pocket"></param>
        public static void ItemRemove(Creature creature, Item item, Pocket pocket)
        {
            var packet = new Packet(Op.ItemRemove, creature.EntityId);

            packet.PutLong(item.EntityId);
            packet.PutByte((byte)pocket);

            creature.Client.Send(packet);
        }
Ejemplo n.º 25
0
        public CornerBet(double amount, int leftTopCornerNr) : base(amount, 8)
        {
            if (leftTopCornerNr >= 34 || Pocket.ColumnOfPocket(leftTopCornerNr) == 3)
            {
                throw new ArgumentException("Invalid left top corner value");
            }

            _leftTopCornerNr = leftTopCornerNr;
        }
Ejemplo n.º 26
0
        public LineBet(double amount, int startNrOfLine) : base(amount, 5)
        {
            if (Pocket.ColumnOfPocket(startNrOfLine) != 1 && startNrOfLine < 34)
            {
                throw new ArgumentException("Value is not a start of a line");
            }

            _startNrOfLine = startNrOfLine;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Returns list of all items in pocket. Returns null if the pocket
        /// doesn't exist.
        /// </summary>
        /// <param name="pocket"></param>
        /// <returns></returns>
        public List <Item> GetAllItemsFrom(Pocket pocket)
        {
            if (!_pockets.ContainsKey(pocket))
            {
                return(null);
            }

            return(_pockets[pocket].Items.Where(a => a != null).ToList());
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Returns the number of items in the given pocket.
        /// Returns -1 if the pocket doesn't exist.
        /// </summary>
        /// <param name="pocket"></param>
        /// <returns></returns>
        public int CountItemsInPocket(Pocket pocket)
        {
            if (!_pockets.ContainsKey(pocket))
            {
                return(-1);
            }

            return(_pockets[pocket].Count);
        }
Ejemplo n.º 29
0
        public InventoryPocketNormal(Pocket pocket, int width, int height)
            : base(pocket)
        {
            _items = new Dictionary <long, Item>();
            _map   = new Item[width, height];

            _width  = width;
            _height = height;
        }
Ejemplo n.º 30
0
 public Item(string n, string d, ushort p, Pocket b, Action<Pokemon, int> a)
 {
     name = n;
     description = d;
     price = p;
     pocket = b;
     battleEffect = a;
     fieldEffect = a;
 }
Ejemplo n.º 31
0
    public void destroyIngredient(InteractableObject ingredient, int times)
    {
        int t = 0;

        foreach (InteractableObject pocket in inventory.nounsInInventory)
        {
            if (pocket.GetType() == typeof(Pocket))
            {
                Pocket p = pocket as Pocket;
                if (p.have(ingredient))
                {
                    int volume = p.getVolumeOf(ingredient);
                    if (times <= volume)
                    {
                        for (int i = 0; i < p.ingredients.Count; i++)
                        {
                            if (p.ingredients[i] == ingredient && t < times)
                            {
                                p.ingredients.RemoveAt(i);
                                t++;

                                if (t == times && times == volume)
                                {
                                    p.usage--;
                                }

                                if (t == times)
                                {
                                    inventory.DisplayInventory();
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }

        if (t < times)
        {
            foreach (InteractableObject i in inventory.nounsInInventory)
            {
                if (i == ingredient)
                {
                    inventory.nounsInInventory.Remove(i);
                    t++;
                }
                if (t == times)
                {
                    inventory.DisplayInventory();
                    return;
                }
            }
        }

        inventory.DisplayInventory();
    }
Ejemplo n.º 32
0
        public StreetBet(double amount, int startNrOfRow) : base(amount, 11)
        {
            if (Pocket.ColumnOfPocket(startNrOfRow) != 1)
            {
                throw new ArgumentException("Not a valid start of a row");
            }

            _startNrOfRow = startNrOfRow;
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Broadcasts EquipmentMoved in creature's range.
        /// </summary>
        /// <param name="creature"></param>
        /// <param name="from"></param>
        public static void EquipmentMoved(Creature creature, Pocket from)
        {
            var packet = new Packet(Op.EquipmentMoved, creature.EntityId);

            packet.PutByte((byte)from);
            packet.PutByte(1);

            creature.Region.Broadcast(packet, creature);
        }
Ejemplo n.º 34
0
        protected virtual void EquipItem(Pocket slot, string itemName, uint color1 = 0, uint color2 = 0, uint color3 = 0)
        {
            var dbInfo = MabiData.ItemDb.Find(itemName);
            if (dbInfo == null)
            {
                Logger.Warning("Unknown item '" + itemName + "' cannot be eqipped. Try specifying the ID manually.");
                return;
            }

            this.EquipItem(slot, dbInfo.Id, color1, color2, color3);
        }
Ejemplo n.º 35
0
        protected virtual void EquipItem(Pocket pocket, uint itemClass, uint color1 = 0, uint color2 = 0, uint color3 = 0)
        {
            var item = new MabiItem(itemClass);
            item.Info.ColorA = color1;
            item.Info.ColorB = color2;
            item.Info.ColorC = color3;
            item.Info.Pocket = (byte)pocket;

            //var inPocket = this.Creature.GetItemInPocket(slot);
            //if (inPocket != null)
            //    this.Creature.Items.Remove(inPocket);

            this.Creature.Items.Add(item);

            Send.EquipmentChanged(this.Creature, item);
        }
Ejemplo n.º 36
0
        protected virtual void EquipItem(Pocket pocket, uint itemClass, uint color1 = 0, uint color2 = 0, uint color3 = 0)
        {
            if (!pocket.IsEquip())
                return;

            var item = new MabiItem(itemClass);
            item.Info.ColorA = color1;
            item.Info.ColorB = color2;
            item.Info.ColorC = color3;

            //var inPocket = this.Creature.GetItemInPocket(slot);
            //if (inPocket != null)
            //    this.Creature.Items.Remove(inPocket);

            this.Creature.Inventory.ForceAdd(item, pocket);

            Send.EquipmentChanged(this.Creature, item);
        }
Ejemplo n.º 37
0
		/// <summary>
		/// Sends ItemMoveInfo or ItemSwitchInfo to creature's client,
		/// depending on whether collidingItem is null.
		/// </summary>
		/// <param name="creature"></param>
		/// <param name="item"></param>
		/// <param name="source"></param>
		/// <param name="target"></param>
		/// <param name="collidingItem"></param>
		public static void ItemMoveInfo(Creature creature, Item item, Pocket source, Item collidingItem)
		{
			var packet = new Packet((collidingItem == null ? Op.ItemMoveInfo : Op.ItemSwitchInfo), creature.EntityId);
			packet.PutLong(item.EntityId);
			packet.PutByte((byte)source);
			packet.PutByte((byte)item.Info.Pocket);
			packet.PutByte(2);
			packet.PutByte((byte)item.Info.X);
			packet.PutByte((byte)item.Info.Y);
			if (collidingItem != null)
			{
				packet.PutLong(collidingItem.EntityId);
				packet.PutByte((byte)item.Info.Pocket);
				packet.PutByte((byte)collidingItem.Info.Pocket);
				packet.PutByte(2);
				packet.PutByte((byte)collidingItem.Info.X);
				packet.PutByte((byte)collidingItem.Info.Y);
			}

			creature.Client.Send(packet);
		}
Ejemplo n.º 38
0
		/// <summary>
		/// Creates a new instance of PocketListener
		/// </summary>
		/// <param name="pocket">The pocket used by this pocket listners</param>
		public PocketListener(Pocket pocket) {
			this.pocket = pocket;
		}
Ejemplo n.º 39
0
		/// <summary>
		/// Tries to add item to pocket and updates clients.
		/// Returns false if the pocket doesn't exist or there was no space.
		/// </summary>
		public bool AddWithUpdate(Item item, Pocket pocket)
		{
			if (!this.Add(item, pocket))
				return false;

			this.CheckEquipMoved(item, Pocket.None, pocket);
			return true;
		}
Ejemplo n.º 40
0
		public InventoryPocketSingle(Pocket pocket)
			: base(pocket)
		{
		}
Ejemplo n.º 41
0
		/// <summary>
		/// Runs equipment updates if necessary.
		/// </summary>
		/// <param name="item"></param>
		/// <param name="source"></param>
		/// <param name="target"></param>
		private void CheckEquipMoved(Item item, Pocket source, Pocket target)
		{
			if (source.IsEquip())
				Send.EquipmentMoved(_creature, source);

			if (target.IsEquip())
				Send.EquipmentChanged(_creature, item);

			// Send stat update when moving equipment
			if (source.IsEquip() || target.IsEquip())
				this.UpdateEquipStats();
		}
Ejemplo n.º 42
0
		/// <summary>
		/// Returns item at the location, or null.
		/// </summary>
		/// <param name="pocket"></param>
		/// <param name="x"></param>
		/// <param name="y"></param>
		/// <returns></returns>
		public Item GetItemAt(Pocket pocket, int x, int y)
		{
			return !this.Has(pocket) ? null : _pockets[pocket].GetItemAt(x, y);
		}
Ejemplo n.º 43
0
		/// <summary>
		/// Modifies position in inventory.
		/// </summary>
		/// <param name="pocket"></param>
		/// <param name="x"></param>
		/// <param name="y"></param>
		public void Move(Pocket pocket, int x, int y)
		{
			this.Info.Pocket = pocket;
			this.Info.Region = 0;
			this.Info.X = x;
			this.Info.Y = y;
		}
Ejemplo n.º 44
0
        // Handlers
        // ------------------------------------------------------------------
        /// <summary>
        /// Used from MoveItem handler.
        /// </summary>
        /// <remarks>
        /// The item is the one that's interacted with, the one picked up
        /// when taking it, the one being put into a packet when it's one
        /// the cursor. Colliding items switch places with it.
        /// </remarks>
        /// <param name="item">Item to move</param>
        /// <param name="target">Pocket to move it to</param>
        /// <param name="targetX"></param>
        /// <param name="targetY"></param>
        /// <returns></returns>
        public bool Move(Item item, Pocket target, byte targetX, byte targetY)
        {
            if (!this.Has(target))
                return false;

            var source = item.Info.Pocket;
            var amount = item.Info.Amount;

            Item collidingItem = null;
            if (!_pockets[target].TryAdd(item, targetX, targetY, out collidingItem))
                return false;

            // If amount differs (item was added to stack)
            if (collidingItem != null && item.Info.Amount != amount)
            {
                Send.ItemAmount(_creature, collidingItem);

                // Left overs, update
                if (item.Info.Amount > 0)
                {
                    Send.ItemAmount(_creature, item);
                }
                // All in, remove from cursor.
                else
                {
                    _pockets[item.Info.Pocket].Remove(item);
                    Send.ItemRemove(_creature, item);
                }
            }
            else
            {
                // Remove the item from the source pocket
                _pockets[source].Remove(item);

                // Toss it in, it should be the cursor.
                if (collidingItem != null)
                    _pockets[source].Add(collidingItem);

                Send.ItemMoveInfo(_creature, item, source, collidingItem);
            }

            this.UpdateInventory(item, source, target);

            return true;
        }
Ejemplo n.º 45
0
 /// <summary>
 /// Returns true if pocket exists in this inventory.
 /// </summary>
 /// <param name="pocket"></param>
 /// <returns></returns>
 public bool Has(Pocket pocket)
 {
     return _pockets.ContainsKey(pocket);
 }
Ejemplo n.º 46
0
        /// <summary>
        /// Returns item at the location, or null.
        /// </summary>
        /// <param name="pocket"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public Item GetItemAt(Pocket pocket, int x, int y)
        {
            if (!this.Has(pocket))
                return null;

            return _pockets[pocket].GetItemAt(x, y);
        }
Ejemplo n.º 47
0
        /// <summary>
        /// Tries to add item to pocket. Returns false if the pocket
        /// doesn't exist or there was no space.
        /// </summary>
        public bool Add(int itemId, Pocket pocket)
        {
            var item = new Item(itemId);

            if (!this.Add(item, pocket))
                return false;

            this.CheckEquipMoved(item, Pocket.None, pocket);
            return true;
        }
Ejemplo n.º 48
0
        // Adding
        // ------------------------------------------------------------------
        /// <summary>
        /// Tries to add item to pocket. Returns false if the pocket
        /// doesn't exist or there was no space.
        /// </summary>
        public bool Add(Item item, Pocket pocket)
        {
            if (!_pockets.ContainsKey(pocket))
                return false;

            var success = _pockets[pocket].Add(item);
            if (success)
            {
                Send.ItemNew(_creature, item);
                this.UpdateEquipReferences(pocket);
            }

            return success;
        }
Ejemplo n.º 49
0
		protected InventoryPocket(Pocket pocket)
		{
			this.Pocket = pocket;
		}
Ejemplo n.º 50
0
		// Adding
		// ------------------------------------------------------------------

		// TODO: Add central "Add" method that all others use, for central stuff
		//   like adding bag pockets. This wil require a GetFreePosition
		//   method in the pockets.

		/// <summary>
		/// Tries to add item to pocket. Returns false if the pocket
		/// doesn't exist or there was no space.
		/// </summary>
		public bool Add(Item item, Pocket pocket)
		{
			if (!_pockets.ContainsKey(pocket))
				return false;

			var success = _pockets[pocket].Add(item);
			if (success)
			{
				Send.ItemNew(_creature, item);
				this.UpdateEquipReferences(pocket);

				// Add bag pocket if it doesn't already exist.
				if (item.OptionInfo.LinkedPocketId != Pocket.None && !this.Has(item.OptionInfo.LinkedPocketId))
					this.AddBagPocket(item);
			}

			return success;
		}
Ejemplo n.º 51
0
		/// <summary>
		/// Removes pocket from inventory.
		/// </summary>
		/// <param name="pocket"></param>
		/// <returns></returns>
		public bool Remove(Pocket pocket)
		{
			if (pocket == Pocket.None || !_pockets.ContainsKey(pocket))
				return false;

			_pockets.Remove(pocket);

			return true;
		}
Ejemplo n.º 52
0
        /// <summary>
        /// Moving item between char and pet, used from handler.
        /// </summary>
        /// <param name="pet">Always the pet</param>
        /// <param name="item"></param>
        /// <param name="other">The "other" creature, player when taking out, pet when putting in.</param>
        /// <param name="target"></param>
        /// <param name="targetX"></param>
        /// <param name="targetY"></param>
        /// <returns></returns>
        public bool MovePet(Creature pet, Item item, Creature other, Pocket target, int targetX, int targetY)
        {
            if (!this.Has(target) || !other.Inventory.Has(target))
                return false;

            var source = item.Info.Pocket;
            var amount = item.Info.Amount;

            // We have to copy the item to get a new id, otherwise there could
            // be collisions when saving, because the moved item is still in
            // the inventory of the pet/character (from the pov of the db).
            // http://dev.mabinoger.com/forum/index.php/topic/804-pet-inventory/
            var newItem = new Item(item);

            Item collidingItem = null;
            if (!other.Inventory._pockets[target].TryAdd(newItem, (byte)targetX, (byte)targetY, out collidingItem))
                return false;

            // If amount differs (item was added to stack)
            if (collidingItem != null && newItem.Info.Amount != amount)
            {
                Send.ItemAmount(other, collidingItem);

                // Left overs, update
                if (newItem.Info.Amount > 0)
                {
                    Send.ItemAmount(_creature, item);
                }
                // All in, remove from cursor.
                else
                {
                    _pockets[item.Info.Pocket].Remove(item);
                    Send.ItemRemove(_creature, item);
                }
            }
            else
            {
                // Remove the item from the source pocket
                _pockets[source].Remove(item);
                Send.ItemRemove(_creature, item, source);

                if (collidingItem != null)
                {
                    // Remove colliding item
                    Send.ItemRemove(other, collidingItem, target);

                    // Toss it in, it should be the cursor.
                    _pockets[source].Add(collidingItem);
                    Send.ItemNew(_creature, collidingItem);
                }

                Send.ItemNew(other, newItem);

                Send.ItemMoveInfo(_creature, item, source, collidingItem);
            }

            pet.Inventory.UpdateInventory(newItem, source, target);

            return true;
        }
Ejemplo n.º 53
0
		/// <summary>
		/// Returns list of all items in pocket. Returns null if the pocket
		/// doesn't exist.
		/// </summary>
		/// <param name="pocket"></param>
		/// <returns></returns>
		public List<Item> GetAllItemsFrom(Pocket pocket)
		{
			if (!_pockets.ContainsKey(pocket))
				return null;

			return _pockets[pocket].Items.Where(a => a != null).ToList();
		}
Ejemplo n.º 54
0
        /// <summary>
        /// Runs equipment updates if necessary.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="source"></param>
        /// <param name="target"></param>
        private void CheckEquipMoved(Item item, Pocket source, Pocket target)
        {
            if (source.IsEquip())
                Send.EquipmentMoved(_creature, source);

            if (target.IsEquip())
                Send.EquipmentChanged(_creature, item);

            // Send stat update when moving equipment
            if (source.IsEquip() || target.IsEquip())
            {
                Send.StatUpdate(_creature, StatUpdateType.Private,
                    Stat.AttackMinBaseMod, Stat.AttackMaxBaseMod,
                    Stat.WAttackMinBaseMod, Stat.WAttackMaxBaseMod,
                    Stat.BalanceBaseMod, Stat.CriticalBaseMod,
                    Stat.DefenseBaseMod, Stat.ProtectionBaseMod
                );
            }
        }
Ejemplo n.º 55
0
        /// <summary>
        /// Sends ItemRemove to creature's client.
        /// </summary>
        /// <param name="creature"></param>
        /// <param name="item"></param>
        /// <param name="pocket"></param>
        public static void ItemRemove(Creature creature, Item item, Pocket pocket)
        {
            var packet = new Packet(Op.ItemRemove, creature.EntityId);
            packet.PutLong(item.EntityId);
            packet.PutByte((byte)pocket);

            creature.Client.Send(packet);
        }
Ejemplo n.º 56
0
        /// <summary>
        /// Unequips item in left hand/magazine, if item in right hand is moved.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="source"></param>
        /// <param name="target"></param>
        private void CheckLeftHand(Item item, Pocket source, Pocket target)
        {
            var pocketOfInterest = Pocket.None;

            if (source == Pocket.RightHand1 || source == Pocket.RightHand2)
                pocketOfInterest = source;
            if (target == Pocket.RightHand1 || target == Pocket.RightHand2)
                pocketOfInterest = target;

            if (pocketOfInterest == Pocket.None)
                return;

            // Check LeftHand first, switch to Magazine if it's empty
            var leftPocket = pocketOfInterest + 2; // Left Hand 1/2
            var leftItem = _pockets[leftPocket].GetItemAt(0, 0);
            if (leftItem == null)
            {
                leftPocket += 2; // Magazine 1/2
                leftItem = _pockets[leftPocket].GetItemAt(0, 0);

                // Nothing to remove
                if (leftItem == null)
                    return;
            }

            // Try inventory first.
            // TODO: List of pockets stuff can be auto-moved to.
            var success = _pockets[Pocket.Inventory].Add(leftItem);

            // Fallback, temp inv
            if (!success)
                success = _pockets[Pocket.Temporary].Add(leftItem);

            if (success)
            {
                _pockets[leftPocket].Remove(leftItem);

                Send.ItemMoveInfo(_creature, leftItem, leftPocket, null);
                Send.EquipmentMoved(_creature, leftPocket);
            }
        }
Ejemplo n.º 57
0
 // Helpers
 // ------------------------------------------------------------------
 /// <summary>
 /// Checks and updates all equipment references for source and target.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="source"></param>
 /// <param name="target"></param>
 private void UpdateInventory(Item item, Pocket source, Pocket target)
 {
     this.CheckLeftHand(item, source, target);
     this.UpdateEquipReferences(source, target);
     this.CheckEquipMoved(item, source, target);
 }
Ejemplo n.º 58
0
		/// <summary>
		/// Adds item to NPC's inventory.
		/// </summary>
		/// <param name="pocket"></param>
		/// <param name="itemId"></param>
		/// <param name="color1"></param>
		/// <param name="color2"></param>
		/// <param name="color3"></param>
		/// <param name="state">For robes and helmets</param>
		protected void EquipItem(Pocket pocket, int itemId, uint color1 = 0, uint color2 = 0, uint color3 = 0, ItemState state = ItemState.Up)
		{
			if (this.NPC == null)
				throw new InvalidOperationException("NPC's race has to be set first.");

			if (!pocket.IsEquip())
			{
				Log.Error("Pocket '{0}' is not for equipment ({1})", pocket, this.GetType().Name);
				return;
			}

			if (!AuraData.ItemDb.Exists(itemId))
			{
				Log.Error("Unknown item '{0}' ({1})", itemId, this.GetType().Name);
				return;
			}

			var item = new Item(itemId);
			item.Info.Pocket = pocket;
			item.Info.Color1 = color1;
			item.Info.Color2 = color2;
			item.Info.Color3 = color3;
			item.Info.State = (byte)state;

			this.NPC.Inventory.InitAdd(item);
		}
Ejemplo n.º 59
0
		public InventoryPocketNormal(Pocket pocket, int width, int height)
			: base(pocket)
		{
			_items = new Dictionary<long, Item>();
			_map = new Item[width, height];

			_width = width;
			_height = height;
		}
Ejemplo n.º 60
0
		public InventoryPocketStack(Pocket pocket)
			: base(pocket)
		{
			_items = new List<Item>();
		}