void controllerBehavior_OnEnter(object sender, GameEventArgs e)
        {
            var beh = (InputBehavior)sender;

            _player2 = new Player2 {
                Position = Position + new Vector2(Size.X), CurrentLevel = CurrentLevel
            };

            if (!e.Level.Map.Collides(_player2.CollisionRect) && !e.Level.CollidesWith(_player2.CollisionRect, true).Any())
            {
                _player2.Health.ValueChanged += Health_ValueChanged;

                RemoveBehavior(beh);
                _player2.RemoveBehaviors(b => b is InputBehavior);
                _player2.AddBehavior(beh);
                e.Level.AddEntity(_player2);
                beh.OnEnter -= controllerBehavior_OnEnter;
                var oldHealth = Health.Quantity;

                LevelCollection.CloneWaypoints(this, _player2);

                if (Weapons != null)
                {
                    foreach (var weapon in Weapons)
                    {
                        _player2.AddWeapon(GameStateManager.WeaponFactory[weapon.GetType().Name]());
                    }
                }

                foreach (var ctn in Containers)
                {
                    _player2.Containers[ctn.Key].Quantity = ctn.Key == "Magic" ? ctn.Value.Quantity : ctn.Value.Quantity / 2;
                }

                Health.Quantity         /= 2;
                _player2.Health.Quantity = oldHealth - Health.Quantity;
                if (Health.Quantity <= 0)
                {
                    Health.Quantity = 1;
                }
                if (_player2.Health.Quantity <= 0)
                {
                    _player2.Health.Quantity = 1;
                }

                _controller2Behavior = null;
                _keyboardBehavior    = null;
            }
        }
 /* This override is to add the PotionFixBehavior to the player and to reset all of the potion stats to default */
 public override void StartServerSide(ICoreServerAPI api)
 {
     this.sapi = api;
     api.Event.PlayerNowPlaying += (IServerPlayer iServerPlayer) =>
     {
         if (iServerPlayer.Entity is EntityPlayer)
         {
             Entity entity = iServerPlayer.Entity;
             entity.AddBehavior(new PotionFixBehavior(entity, config));
             //api.Logger.Debug("[Potion] Adding PotionFixBehavior to spawned EntityPlayer");
             TempEffect   tempEffect = new TempEffect();
             EntityPlayer player     = (iServerPlayer.Entity as EntityPlayer);
             tempEffect.reset(player, false);
             //api.Logger.Debug("potion player ready");
         }
     };
     base.StartServerSide(api);
 }
Exemple #3
0
        static EntityTemplates()
        {
            Car = new Entity {
                Name = nameof(Car)
            };
            Car.AddBehavior(new TransformBehavior());
            Car.AddBehavior(new MovableBehavior {
                Speed = 0.5f
            });
            Car.AddBehavior(new CarBehavior());
            Car.AddBehavior(new SimpleGeometryRendererBehavior
            {
                Geometry     = SimpleGeometry.Square,
                DrawCenter   = false,
                Color        = Colors.DarkGreen,
                FillGeometry = true,
                Size         = new Windows.Foundation.Size(6, 2)
            });

            Customer = new Entity {
                Name = nameof(Customer)
            };
            Customer.AddBehavior(new TransformBehavior());
            Customer.AddBehavior(new MovableBehavior());
            Customer.AddBehavior(new CustomerBehavior());
            Customer.AddBehavior(new SimpleGeometryRendererBehavior
            {
                Geometry     = SimpleGeometry.Circle,
                DrawCenter   = false,
                Color        = Colors.Cyan,
                FillGeometry = true,
                Size         = new Windows.Foundation.Size(1, 1)
            });
            Customer.GetBehavior <CustomerBehavior>().Inventory.AddItem(Items.Money, 100);

            Road = new Entity {
                Name = nameof(Road)
            };
            Road.AddBehavior(new LineTransformBehavior());
            Road.AddBehavior(new RoadBehavior());

            MapIO = new Entity {
                Name = nameof(MapIO)
            };
            MapIO.AddBehavior(new TransformBehavior());
            MapIO.AddBehavior(new GraphConnectorNodeBehavior());
            MapIO.AddBehavior(new SpawnerBehavior());

            ParkingLot = new Entity {
                Name = nameof(ParkingLot)
            };
            ParkingLot.AddBehavior(new TransformBehavior());
            ParkingLot.AddBehavior(new ParkingLotBehavior());

            GraphConnector = new Entity {
                Name = nameof(GraphConnector)
            };
            GraphConnector.AddBehavior(new TransformBehavior());
            GraphConnector.AddBehavior(new GraphConnectorNodeBehavior());

            SingleCashier = new Entity {
                Name = nameof(SingleCashier)
            };
            SingleCashier.AddBehavior(new TransformBehavior());
            SingleCashier.AddBehavior(new GraphConnectorNodeBehavior());
            SingleCashier.AddBehavior(new CashierBehavior());

            WaitingQueue = new Entity {
                Name = nameof(WaitingQueue)
            };
            WaitingQueue.AddBehavior(new TransformBehavior());
            WaitingQueue.AddBehavior(new GraphConnectorNodeBehavior());
            WaitingQueue.AddBehavior(new WaitingQueueBehavior());

            CashierBooth = new Entity {
                Name = nameof(CashierBooth)
            };
            CashierBooth.AddBehavior(new TransformBehavior());
            CashierBooth.AddBehavior(new GraphConnectorNodeBehavior());
            CashierBooth.AddBehavior(new SubgraphEntranceBehavior());
            var cbQueue = WaitingQueue.Clone();

            cbQueue.Name = "CashierBooth.WaitingQueue";
            var cbqQueueBehavior = cbQueue.GetBehavior <WaitingQueueBehavior>();

            cbqQueueBehavior.MaxQueueSize = 10;
            cbQueue.SetParent(CashierBooth, Reasons.TemplateCreation);
            var cbCashier1 = SingleCashier.Clone();

            cbCashier1.Name = "CashierBooth.Cashier1";
            var cbc1CashierBehavior = cbCashier1.GetBehavior <CashierBehavior>();

            cbc1CashierBehavior.TicketPrice = 42;
            cbc1CashierBehavior.NextNode    = CashierBooth.GetImplementation <IGraphNode>();
            cbc1CashierBehavior.MinimumProcessingSeconds = 1;
            cbc1CashierBehavior.MaximumProcessingSeconds = 5;
            cbc1CashierBehavior.UseWaitingQueueOfParent  = true;
            cbCashier1.SetParent(CashierBooth, Reasons.TemplateCreation);
            CashierBooth.GetBehavior <SubgraphEntranceBehavior>().SubgraphNode = cbQueue.GetImplementation <IGraphNode>();

            Slope = new Entity {
                Name = nameof(Slope)
            };
            Slope.AddBehavior(new LineTransformBehavior());
            Slope.AddBehavior(new SlopeBehavior());

            // TODO remove debug code
            Car.AddBehavior(new DebugBehavior());
            Customer.AddBehavior(new DebugBehavior());
        }