Exemple #1
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;
        }
Exemple #2
0
        /// <summary>
        /// Drops all stuff
        /// </summary>
        public void Drop()
        {
            // Drop portable
            carrier.Drop();

            // Drops Collectables
            apple.Amount = 0;

            // Drop Sugar
            int amount = sugar.Amount;

            if (Item.Settings.GetBool <AntItem>("DropSugar").Value)
            {
                Item.Engine.InsertItem(new SugarItem(Item.Faction.Level.Context, Item.Position.ToVector2XY(), amount));
            }
        }
Exemple #3
0
        /// <summary>
        ///     Hängt alle Eventhandler wieder aus.
        /// </summary>
        public void Dispose()
        {
            // Detach Portable Stuff
            if (portable != null)
            {
                // Drop all Carriers
                foreach (CarrierProperty carrierItem in portable.CarrierItems.ToArray())
                {
                    carrierItem.Drop();
                }

                portable.OnPortableWeightChanged -= portable_OnPortableMassChanged;
                portable.OnNewCarrierItem        -= portable_OnNewCarrierItem;
                portable.OnLostCarrierItem       -= portable_OnLostCarrierItem;
            }

            // Detach Carrier Stuff
            if (carrier != null)
            {
                // Drop carried item
                carrier.Drop();

                carrier.OnCarrierLoadChanged     -= carrier_OnCarrierLoadChanged;
                carrier.OnCarrierStrengthChanged -= carrier_OnCarrierStrengthChanged;
            }

            // Detach Collision Stuff
            if (collidable != null)
            {
                collidable.OnCollisionFixedChanged -= collidable_OnCollisionFixedChanged;
                collidable.OnCollisionMassChanged  -= collidable_OnCollisionMassChanged;
            }

            // Detach Moving Stuff
            if (moving != null)
            {
                moving.OnMoveSpeedChanged        -= moving_OnMoveSpeedChanged;
                moving.OnMoveDirectionChanged    -= moving_OnMoveDirectionChanged;
                moving.OnMaximumMoveSpeedChanged -= moving_OnMaximumMoveSpeedChanged;
            }

            // Detach Item Stuff
            item.CellChanged -= item_CellChanged;
        }
Exemple #4
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));
        }
Exemple #5
0
 public void Drop()
 {
     carrier.Drop();
 }