/// <inheritdoc />
        public async ValueTask <Optional <Block> > GetBlockAsync(long guildId, string commandName)
        {
            var cachePackage = await cache.HashGetAsync <BlockCache>(
                CommandCacheKey, commandName + ":" + guildId);

            if (cachePackage != null)
            {
                await using var stream = new MemoryStream(cachePackage.Bytes);
                var reader = new BinaryReader(stream);

                return(reader.ReadBlock());
            }

            var repository = unitOfWork.GetRepository <CustomCommand>();

            var command = await repository.GetAsync(guildId, commandName);

            if (command == null)
            {
                return(Optional <Block> .None);
            }

            var block = BlockGenerator.Compile(command.CommandBody);

            await cache.HashUpsertAsync(
                CommandCacheKey, commandName + ":" + guildId, BlockCache.Create(block));

            return(block);
        }
        /// <inheritdoc />
        public async ValueTask <bool> ExecuteCodeAsync(IContext e, string body)
        {
            var provider = new CodeProvider(body);

            try
            {
                var block = BlockGenerator.Compile(body);
                return(await ExecuteAsync(e, block, provider));
            }
            catch (MiScriptException ex)
            {
                await SendErrorAsync(
                    e,
                    "error_miscript_parse",
                    ex.Message,
                    new CodeProvider(body),
                    ex.Position);

                return(false);
            }
            catch (Exception ex)
            {
                await SendErrorAsync(
                    e,
                    "error_miscript_parse",
                    "Internal error in MiScript: " + ex.Message,
                    provider);

                return(false);
            }
        }
Beispiel #3
0
 public void ToMain(string stage)
 {
     this.sePlayer.Play("button");
     // ブロック生成クラスに、現在のステージを教える。
     BlockGenerator.SetStage(stage);
     SceneManager.LoadScene("Main");
 }
Beispiel #4
0
 public static void PauseGame()
 {
     BlockGenerator.MultiplyDropRate(0);
     ScoreManager.pauseClock();
     GravityManager.KeyboardInput = false;
     paused = true;
 }
Beispiel #5
0
    public void SetBlock(int x, int y, BlockGenerator block, bool wrap = false)
    {
        if (wrap)
        {
            Int2 wrappedIndex = WrapIndex(x, y);
            x = wrappedIndex.x;
            y = wrappedIndex.y;
        }
        if (BlockInRange(x, y))
        {
            if (x < 0)
            {
                x += Width;
            }
            if (y < 0)
            {
                y += Height;
            }

            Blocks[x, y] = block;
        }
        else
        {
            Debug.Log(string.Format("Block index [{0}, {1}] out of range", x, y));
        }
    }
Beispiel #6
0
 public static void ResumeGame()
 {
     BlockGenerator.MultiplyDropRate(ScoreManager.dropRate);
     ScoreManager.resumeClock();
     GravityManager.KeyboardInput = true;
     paused = false;
 }
 public MeteorsGenerator(PlaySettings ss, RandomItem <int> carSizeDistribution, RandomItem <int> carAmountDistribution,
                         RandomItem <int> metAmountDistribution, int minCount, int maxCount,
                         Transform launcher)
 {
     if (carAmountDistribution.Items.Min() < 2 ||
         carAmountDistribution.Items.Max() > ss.Road.LinesCount ||
         metAmountDistribution.Items.Min() < 1 ||
         metAmountDistribution.Items.Max() >= carAmountDistribution.Items.Max())
     {
         throw new ArgumentOutOfRangeException();
     }
     _blockGen       = new BlockGenerator(ss, carSizeDistribution, carAmountDistribution);
     _metAmountDistr = metAmountDistribution;
     _carCountDistr  = carAmountDistribution;
     _carSizeDistr   = carSizeDistribution;
     _launcher       = launcher;
     _ss             = ss;
     _minCount       = minCount;
     _maxCount       = maxCount;
     _lowerBounds    = new float[_ss.Road.LinesCount];
     _topBounds      = new float[_ss.Road.LinesCount];
     _lastOnLine     = new CarDescriptor[_ss.Road.LinesCount];
     _isActual       = new bool[_ss.Road.LinesCount];
     _isMeteorTarget = new bool[_ss.Road.LinesCount];
 }
Beispiel #8
0
 private void Awake()
 {
     blockGenerator         = GameObject.Find("BlockGenerator").transform;
     blockGeneratorScript   = GameObject.Find("BlockGenerator").GetComponent <BlockGenerator>();
     platformNewLocation    = GameObject.Find("PlatFormLocation").transform;
     platformNewLocationTwo = GameObject.Find("PlatFormLocationTwo").transform;
 }
Beispiel #9
0
    void AddGenerators(List <IGenerator> generators)
    {
        LevelInfo levelInfo = new LevelInfo();

        levelInfo.columns          = columns;
        levelInfo.rows             = rows;
        levelInfo.playerHeight     = playerHeight;
        levelInfo.maxJumpHeight    = maxJumpHeight;
        levelInfo.maxJumpLength    = maxJumpLength;
        levelInfo.minGroundHeight  = minGroundHeight;
        levelInfo.minGroundLength  = minGroundLength;
        levelInfo.maxGroundLength  = maxGroundLength;
        levelInfo.gapProbability   = gapProbability;
        levelInfo.steepProbability = steepProbability;
        levelInfo.blockProbability = blockProbability;

        GroundGenerator   groundGenerator   = new GroundGenerator(levelInfo);
        ObstacleGenerator obstacleGenerator = new ObstacleGenerator(levelInfo);
        BlockGenerator    blockGenerator    = new BlockGenerator(levelInfo);
        ItemGenerator     itemGenerator     = new ItemGenerator(levelInfo);

        generators.Add(groundGenerator);
        generators.Add(obstacleGenerator);
        generators.Add(blockGenerator);
        generators.Add(itemGenerator);
    }
Beispiel #10
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
 }
Beispiel #11
0
    public void Init()
    {
        // Default values
        levelEnemyTypes.Add(EnemyNames.GOBLIN);

        enemy    = (GameObject)Resources.Load("EnemyPrototype");
        platform = (GameObject)Resources.Load("Platform");

        tag = "LevelHandler";
        transform.position = new Vector3(Camera.main.transform.position.x + 2 * Camera.main.orthographicSize, Camera.main.transform.position.y - Camera.main.orthographicSize / 2);

        // Init the generator and HUD
        GameObject blockGeneratorObject = new GameObject();

        blockGenerator = blockGeneratorObject.AddComponent <BlockGenerator>();
        blockGenerator.Init();
        blockGeneratorObject.transform.position = new Vector3(Camera.main.transform.position.x - Camera.main.orthographicSize, Camera.main.transform.position.y - Camera.main.orthographicSize);
        blockGenerator.SetLevelGenerator(this);

        GameObject levelHUDObject = new GameObject();

        levelHUD = levelHUDObject.AddComponent <LevelHUD>();
        levelHUD.SetLevelGenerator(this);

        manaRegenTimer = maxManaRegenTimer;

        // Testing
        pSpawnTimer = Random.Range(1f, 3f); // Spawn Platforms

        StandardLevel.speedModifier = StandardLevel.originalSpeedModifier;

        SwapPlayers(0);
    }
Beispiel #12
0
 public PoliceGenerator(PlaySettings ss, float sideSpeed, float radius, float sandvichProb = 0)
 {
     SS            = ss;
     _sandvichProb = sandvichProb;
     _blockGen     = new BlockGenerator(SS, new RandomItem <int>(new[] { 1 }), null);
     _sideSpeed    = sideSpeed;
     _radius       = radius;
 }
 void Start()
 {
     _currentLevel             = 0;
     CounterScript.OnComplete += OnCountComplete;
     _generator = GetComponent <BlockGenerator>();
     _generator.Initialize(firstScale);
     levelSelect.Initialize(this.levels);
 }
Beispiel #14
0
 public void Activate(Vector3 position, float width, BlockGenerator bg)
 {
     Bg = bg;
     gameObject.SetActive(true);
     gameObject.transform.position   = position;
     gameObject.transform.localScale = new Vector3(0.9f, 0.9f, width);
     StartCoroutine("Move");
 }
Beispiel #15
0
    void Awake()
    {
        blockGenerator = GameObject.FindObjectOfType <BlockGenerator> ();
        csvMaker       = GameObject.FindObjectOfType <CSV_Maker> ();

        currentBlock = 0;
        currentTrial = 0;
    }
 public ColdStackingModel(
     Settings settings,
     MagicChain223 magicChain223,
     BlockGenerator blockGenerator)
 {
     _settings       = settings;
     _magicChain223  = magicChain223;
     _blockGenerator = blockGenerator;
 }
Beispiel #17
0
 // Use this for initialization
 void Start()
 {
     activeGenerator = transform.Find("TopGenerator").GetComponent <BlockGenerator> ();
     Physics.gravity = new Vector3(0, gravity * -1, 0);
     UIPanel         = GameObject.Find("UIContainer").GetComponent <RectTransform> ();
     //Gravity can only be switched every 0.5 seconds, doing immediately back to back often had weird results
     CanSwitch     = 0.5f;
     KeyboardInput = true;
 }
Beispiel #18
0
 public static void Clear()
 {
     _globalEvent.Clear();
     _globalEvent    = null;
     _randomUtil     = null;
     _gameData       = null;
     _blockGenerator = null;
     _excelUtil      = null;
 }
Beispiel #19
0
 private void Start()
 {
     blockTarget    = this.gameObject.GetComponent <BlockTarget>();
     blockGenerator = this.gameObject.GetComponent <BlockGenerator>();
     blockSlider    = this.gameObject.GetComponent <BlockSlider>();
     resetCheck     = blockGenerator.GenerateBlockSet(true);
     itemDoCount    = itemSuCount = totalHit = totalMiss = 0;
     SoundManager.Instance.PlayBGM(SoundManager.Instance.bgm_Play);
 }
Beispiel #20
0
    private static void CheckForNewRule()
    {
        if (NextRuleIndex < rules.Length && Score >= rules [NextRuleIndex].GetPoints())
        {
            rules [NextRuleIndex].Activate();
            Messenger.SendMessage("New Rule! " + rules [NextRuleIndex].GetDescription());
            switch (rules[NextRuleIndex].getType())
            {
            case Rule.RuleType.Other:
                if (rules [NextRuleIndex].getValue() == 0)
                {
                    TimerActive = true;
                    Clock.SetActive(true);
                }
                else if (rules [NextRuleIndex].getValue() == 1)
                {
                    BonusPoints(1000, "being way too good at this game");
                }
                break;

            case Rule.RuleType.DropSpeed:
                dropRate = rules [NextRuleIndex].getValue();
                BlockGenerator.MultiplyDropRate(rules[NextRuleIndex].getValue());
                RuleDescription [0] = rules [NextRuleIndex].GetDescription();
                break;

            case Rule.RuleType.PrimaryRule:
                PrimaryRuleRequirement = rules [NextRuleIndex].getValue();
                PrimaryRule            = true;
                PrimaryRule2           = false;
                RuleDescription[2]     = rules [NextRuleIndex].GetDescription();
                break;

            case Rule.RuleType.PrimaryRule2:
                if (PrimaryPercent() - PrimaryRuleRequirement > 0.01)
                {
                    bonus = (int)Mathf.Pow((float)(100 * (PrimaryPercent() - PrimaryRuleRequirement)), 1f + 3f * PrimaryRuleRequirement);
                    BonusPoints(bonus, "exceeding rule expectations");
                }
                PrimaryRule2       = true;
                PrimaryRule        = false;
                RuleDescription[2] = rules [NextRuleIndex].GetDescription();
                break;

            case Rule.RuleType.MergeNum:
                CheckForMerge.StacksForPoints = (int)rules [NextRuleIndex].getValue();
                RuleDescription [1]           = rules [NextRuleIndex].GetDescription();
                TimeToDeath = CheckForMerge.StacksForPoints * 10;
                break;
            }

            NextRuleIndex++;
            //If points sufficient for a rule, check to see if sufficient for next rule until it isn't
            CheckForNewRule();
        }
    }
Beispiel #21
0
    public void Init(Coords coords, BlockGenerator blockgen)
    {
        bg          = blockgen;
        coordinates = coords;
        transform.SetParent(blockgen.transform);
        transform.localPosition = new Vector3(coords.x * Size, -coords.y * Size, 0);
        gameObject.name         = coords.x + " : " + coords.y + " " + gameObject.name;

        Connect();
    }
        private static void AddBlocks(XElement xElement, ICollection <XmlDocBlock> blocks)
        {
            var generator = new BlockGenerator();

            generator.AddNodes(xElement.Nodes());
            foreach (var block in generator.GetBlocks())
            {
                blocks.Add(block);
            }
        }
Beispiel #23
0
    public void Init(Coords coords, BlockGenerator blockgen)
    {
        bg = blockgen;
        coordinates = coords;
        transform.SetParent(blockgen.transform);
        transform.localPosition = new Vector3(coords.x * Size, -coords.y * Size, 0);
        gameObject.name = coords.x + " : " + coords.y + " " + gameObject.name;

        Connect();
    }
 public SoloMeteorGenerator(PlaySettings ss, float minDelay, float maxDelay, float addVelocity,
                            RandomItem <int> secondBlockCarAmntDistr)
 {
     SS = ss;
     _carAmountDistr = secondBlockCarAmntDistr;
     _blockGen       = new BlockGenerator(SS, new RandomItem <int>(new[] { 1, 2 }), _carAmountDistr);
     _minDelay       = minDelay;
     _maxDelay       = maxDelay;
     _addVelocity    = addVelocity;
 }
 void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }
Beispiel #26
0
        public GridBundle(int aPlayerIndex)
        {
            GridRandomizer = new Random(123 + "HejNicos".GetHashCode());

            Container = new GridContainer();
            Generator = new BlockGenerator();

            Container.SetGenerator(Generator);
            Generator.SetBundle(this);

            Behavior = new GridBehavior(Container, aPlayerIndex);
        }
Beispiel #27
0
 /// <summary>
 /// Starts game or gets next block to the game field
 /// </summary>
 public void Start()
 {
     Running      = true;
     PositionY    = 0;
     PositionX    = Container.GetUpperBound(1) / 2;
     CurrentBlock = Next ?? BlockGenerator.GetRandomBlock();
     Next         = BlockGenerator.GetRandomBlock();
     if (!CanPosition(CurrentBlock, PositionX, PositionY))
     {
         GameOver();
     }
 }
 public CopterGenerator(PlaySettings ps, float reloadTime, float missileVel, float missileRotVel,
                        float missileLimit, int minCount, int maxCount,
                        RandomItem <int> carSizeDistr, RandomItem <int> carCountDistr)
 {
     _ps            = ps;
     _reloadTime    = reloadTime;
     _missileVel    = missileVel;
     _missileRotVel = missileRotVel;
     _missileLimit  = missileLimit;
     _minCount      = minCount;
     _maxCount      = maxCount;
     _blockGen      = new BlockGenerator(ps, carSizeDistr, carCountDistr);
 }
    private BlockGenerator CreateBlock(Int2 index)
    {
        Int2    wrappedIndex = cityBlocks.WrapIndex(index.x, index.y);
        Vector3 position     = GetPositionAtBlockIndex(wrappedIndex);

        BlockGenerator newGenerator = Instantiate(BlockGeneratorPrefab).GetComponent <BlockGenerator>();

        cityBlocks.SetBlock(wrappedIndex.x, wrappedIndex.y, newGenerator, wrapLoadedArea);
        newGenerator.transform.SetParent(this.transform);
        newGenerator.transform.position = position;
        newGenerator.Initialize(wrappedIndex, Random.Range(minBuildingsPerBlock, maxBuildingsPerBlock), blockSize, Random.Range(minRoadWidth, maxRoadWidth));

        return(newGenerator);
    }
Beispiel #30
0
    public override void InitWithGenerator(BlockGenerator gene, int blockX, int blockY, int rand)
    {
        _blockX = blockX;
        _blockY = blockY;

        once        = true;
        _gene       = gene;
        isEffecting = false;
        canTouch    = false;

        transform.position = gene.transform.position;
        gameObject.SetActive(true);

        blockType = (BlockType)rand;
        ChangeColor(blockType);
    }
Beispiel #31
0
    /// <summary>
    /// Gets a 2-dimensional array of 9 blocks centered around [x, y]
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="wrap">Should blocks on the opposite edge of the grid be wrapped to?</param>
    /// <returns></returns>
    public BlockGenerator[,] GetAdjacentBlocks(int x, int y, bool wrap = false)
    {
        BlockGenerator[,] adjacent = new BlockGenerator[3, 3];

        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                int adjX = x + i - 1;
                int adjY = y + j - 1;
                adjacent[i, j] = GetBlock(adjX, adjY, wrap);
            }
        }

        return(adjacent);
    }
Beispiel #32
0
 public WallGenerator(PlaySettings ss, RandomItem <int> carSizeDistr, RandomItem <int> carCountDistr,
                      float wallLenMin, float wallLenMax, float gapLenMin, float gapLenMax,
                      float vehVelDelta, int minCount, int maxCount, bool modifable)
 {
     _ss          = ss;
     _wallLenMax  = wallLenMax;
     _wallLenMin  = wallLenMin;
     _gapLenMax   = gapLenMax;
     _gapLenMin   = gapLenMin;
     _minCarSpeed = _ss.NormalCarSpeed - vehVelDelta;
     _maxCarSpeed = _ss.NormalCarSpeed + vehVelDelta;
     _maxCount    = maxCount;
     _minCount    = minCount;
     _bufferList  = new LinkedList <IDescriptorWithID>();
     _blockGen    = new BlockGenerator(ss, carSizeDistr, carCountDistr, 0x20);
     _modifable   = modifable;
 }
Beispiel #33
0
    private void GenerateLevel(GameObject level, BlockGenerator generator)
    {
        Level levelObj = level.GetComponent<Level>();
        string[] levelAry = levelObj.levelMap.text.Replace("\r\n","\n").Split('\n');

        int levelHeight = levelAry.Length - 1;

        Vector3 currentPos = new Vector3(0, (float)levelHeight, 0);

        foreach (string line in levelAry) {
            currentPos.x = 0;
            char[] blocks = line.ToCharArray();
            foreach (char c in blocks) {
                LevelBlock b = levelObj.getBlock(c);

                if (b != null)
                    generator(currentPos, levelContainer.transform.rotation, b.blockObject);

                currentPos.x++;
            }
            currentPos.y--;
        }
    }
Beispiel #34
0
 public abstract void InitWithGenerator(BlockGenerator gene, int blockX, int blockY, int rand);