Beispiel #1
0
        public bool Carry(Item item)
        {
            if (item == null)
            {
                return(false);
            }

            if (!item.ContainsProperty <PortableProperty>())
            {
                return(false);
            }

            PortableProperty portable = item.GetProperty <PortableProperty>();

            return(carrier.Carry(portable));
        }
Beispiel #2
0
        /// <summary>
        /// Tries to pick up the target item.
        /// </summary>
        /// <param name="info">Item to pick up</param>
        /// <returns>Success</returns>
        public bool Carry(ItemInfo info)
        {
            // Drops old Items
            if (carrier.CarrierLoad != null)
            {
                carrier.Drop();
            }

            var item = Item.GetItemFromInfo(info);

            // Make sure target is portable
            var portable = item.GetProperty <PortableProperty>();

            if (portable == null)
            {
                return(false);
            }

            // Take
            return(carrier.Carry(portable));
        }
Beispiel #3
0
        public void CheckPortableItemAddedAndRemoved()
        {
            InitItem(new Vector2(50, 100), new Vector2(150, 50), new Vector2(150, 150), null);
            InitFlat(true);
            Portable3.PortableRadius = 1000f;

            int             triggeredNew  = 0;
            int             triggeredLost = 0;
            CarrierProperty expected      = null;
            bool            result        = false;

            Portable3.OnNewCarrierItem += (v) =>
            {
                Assert.AreEqual(expected, v);
                triggeredNew++;
            };

            Portable3.OnLostCarrierItem += (v) =>
            {
                Assert.AreEqual(expected, v);
                triggeredLost++;
            };

            // Item1 aufnehmen
            expected = Carrier1;
            result   = Carrier1.Carry(Portable3);
            Assert.AreEqual(true, result);
            Assert.AreEqual(1, triggeredNew);
            Assert.AreEqual(0, triggeredLost);
            triggeredNew  = 0;
            triggeredLost = 0;
            Assert.AreEqual(1, Portable3.CarrierItems.Count);
            Assert.AreEqual(true, Portable3.CarrierItems.Contains(Carrier1));
            Assert.AreEqual(false, Portable3.CarrierItems.Contains(Carrier2));

            // Item1 fallen lassen
            expected = Carrier1;
            Carrier1.Drop();
            Assert.AreEqual(0, triggeredNew);
            Assert.AreEqual(1, triggeredLost);
            triggeredNew  = 0;
            triggeredLost = 0;
            Assert.AreEqual(0, Portable3.CarrierItems.Count);
            Assert.AreEqual(false, Portable3.CarrierItems.Contains(Carrier1));
            Assert.AreEqual(false, Portable3.CarrierItems.Contains(Carrier2));

            // Item2 aufnehmen
            expected = Carrier2;
            result   = Carrier2.Carry(Portable3);
            Assert.AreEqual(true, result);
            Assert.AreEqual(1, triggeredNew);
            Assert.AreEqual(0, triggeredLost);
            triggeredNew  = 0;
            triggeredLost = 0;
            Assert.AreEqual(1, Portable3.CarrierItems.Count);
            Assert.AreEqual(false, Portable3.CarrierItems.Contains(Carrier1));
            Assert.AreEqual(true, Portable3.CarrierItems.Contains(Carrier2));

            // Item1 aufnehmen
            expected = Carrier1;
            result   = Carrier1.Carry(Portable3);
            Assert.AreEqual(true, result);
            Assert.AreEqual(1, triggeredNew);
            Assert.AreEqual(0, triggeredLost);
            triggeredNew  = 0;
            triggeredLost = 0;
            Assert.AreEqual(2, Portable3.CarrierItems.Count);
            Assert.AreEqual(true, Portable3.CarrierItems.Contains(Carrier1));
            Assert.AreEqual(true, Portable3.CarrierItems.Contains(Carrier2));

            // Item2 fallen lassen
            expected = Carrier2;
            Carrier2.Drop();
            Assert.AreEqual(0, triggeredNew);
            Assert.AreEqual(1, triggeredLost);
            triggeredNew  = 0;
            triggeredLost = 0;
            Assert.AreEqual(1, Portable3.CarrierItems.Count);
            Assert.AreEqual(true, Portable3.CarrierItems.Contains(Carrier1));
            Assert.AreEqual(false, Portable3.CarrierItems.Contains(Carrier2));
        }
Beispiel #4
0
        public void CheckCarrierLoadChanged()
        {
            InitItem(new Vector2(50, 100), new Vector2(150, 50), null, new Vector2(150, 150));
            InitFlat(true);
            Portable3.PortableRadius = 1000f;
            Portable4.PortableRadius = 1000f;

            int triggered = 0;
            PortableProperty expected1 = null;
            PortableProperty expected2 = null;
            bool             result    = false;

            Carrier1.OnCarrierLoadChanged += (i, v) =>
            {
                if (triggered == 0)
                {
                    Assert.AreEqual(expected1, v);
                }
                else if (triggered == 1)
                {
                    Assert.AreEqual(expected2, v);
                }
                triggered++;
            };

            // Item 1 aufnehmen
            expected1 = Portable3;
            result    = Carrier1.Carry(Portable3);
            Assert.AreEqual(true, result);
            Assert.AreEqual(1, triggered);
            triggered = 0;

            // Item 1 wieder fallen lassen
            expected1 = null;
            Carrier1.Drop();
            Assert.AreEqual(1, triggered);
            triggered = 0;

            // Item 1 wieder aufnehmen
            expected1 = Portable3;
            result    = Carrier1.Carry(Portable3);
            Assert.AreEqual(true, result);
            Assert.AreEqual(1, triggered);
            triggered = 0;

            // Item 2 aufnehmen, solange 1 noch getragen
            expected1 = null;
            expected2 = Portable4;
            result    = Carrier1.Carry(Portable4);
            Assert.AreEqual(true, result);
            Assert.AreEqual(2, triggered);
            triggered = 0;
        }