コード例 #1
0
        public override void Interact(Entity entity, EntityUniverseFacade facade, ControlState main, ControlState alt)
        {
            if (!alt.DownClick)
            {
                return;
            }
            if (!IsClaimed())
            {
                var player = entity.PlayerEntityLogic;
                player.ShowNotification(GameContext.NotificationDatabase.CreateNotificationFromCode(Component.NotClaimedNotification, entity.Step, NotificationParams.EmptyParams));
                return;
            }
            if (!Totem.IsReady())
            {
                var player = entity.PlayerEntityLogic;
                player.ShowNotification(GameContext.NotificationDatabase.CreateNotificationFromCode(Component.NotReadyNotification, entity.Step, NotificationParams.EmptyParams));
                return;
            }

            if (Totem.CanStartNewGame())
            {
                Totem.ResetGame();
                PrepareReset(facade.Step);
            }
        }
コード例 #2
0
        public override void Update(Timestep timestep, EntityUniverseFacade universe)
        {
            Tile tile;

            if (!universe.ReadTile(Location, TileAccessFlags.None, out tile))
            {
                return;
            }
            if ((tile.Configuration != _configuration) || (_variant != tile.Variant()))
            {
                _done = true;
                if (tile.Configuration == _configuration)
                {
                    universe.RemoveTile(Entity, Location, TileAccessFlags.None);
                }
                return;
            }

            _countPosition = tile.Configuration.TileCenterTop(Location, tile);

            Vector3F tileOffset;

            if (universe.TileOffset(Location, TileAccessFlags.None, out tileOffset))
            {
                _countPosition.Y += tileOffset.Y;
            }

            CheckIfEntityExists();

            if (!IsClaimed() || !Totem.HasGameStarted())
            {
                return;
            }

            if (SpawnFireworksStart + (long)(_goalComponent.FireworkLaunchingLength * Constants.TimestepsPerSecond) > timestep)
            {
                if (timestep - _lastSpawn > _goalComponent.FireworkTimeBetweenLaunch * Constants.TimestepsPerSecond)
                {
                    _lastSpawn = timestep;
                    SpawnFireworks(universe);
                }
                return;
            }

            if (Totem.CanStartNewGame())
            {
                return;
            }

            // get all entities inside the goal area
            var entities = universe.FindAllEntitiesInRange(tile.Configuration.TileCenter(Location, tile.Variant()), (float)_boundingShape.Radius.Length(),
                                                           FindEntityCondition);

            if (entities == null || entities.Count <= 0)
            {
                return;
            }

            // if an item has moved into the goal area increase the score
            Console.WriteLine("Checking all entities in collision.");
            foreach (var entity in entities)
            {
                var itemlogic = entity.Logic as ItemEntityLogic;
                if (itemlogic == null)
                {
                    continue;
                }
                Console.WriteLine("There is an item logic.");
                ItemStack stack = (ItemStack)GetInstanceField(typeof(ItemEntityLogic), itemlogic, "Stack"); //Use reflection to find internal stack
                if (stack.Item.Configuration.Code == "mods.Deamon.Soccer.item.SoccerBall")
                {
                    SetInstanceField(typeof(ItemEntityLogic), itemlogic, "Stack", new ItemStack());
                    Totem.IncreaseScore(Team, timestep); //Increase the score
                }
            }
        }