Esempio n. 1
0
        private void LoadNewData(GameBoardState gameBoardState)
        {
            foreach (var planet in gameBoardState.Planets)
            {
                var planetE = _game.CreateEntity();
                planetE.ReplaceComponent(GameComponentsLookup.Planet, planet.Planet);
                planetE.ReplaceComponent(GameComponentsLookup.Position, planet.Position);
                planetE.ReplaceComponent(GameComponentsLookup.Mass, planet.Mass);
                planetE.ReplaceComponent(GameComponentsLookup.Health, planet.Health);
                planetE.ReplaceComponent(GameComponentsLookup.Cannon, planet.Cannon);
                planetE.ReplaceComponent(GameComponentsLookup.CooldownTimer, planet.CooldownTimer);
            }

            foreach (var rocket in gameBoardState.Rockets)
            {
                var rocketE = _game.CreateEntity();
                rocketE.ReplaceComponent(GameComponentsLookup.FirePower, rocket.FirePower);
                rocketE.ReplaceComponent(GameComponentsLookup.Health, rocket.Health);
                rocketE.ReplaceComponent(GameComponentsLookup.Position, rocket.Position);
                rocketE.ReplaceComponent(GameComponentsLookup.Velocity, rocket.Velocity);
                rocketE.isRocket = true;
            }

            foreach (var player in gameBoardState.Players)
            {
                var playerE = _game.CreateEntity();
                playerE.ReplaceComponent(GameComponentsLookup.Player, player.Player);
            }
        }
Esempio n. 2
0
    private void SetupPlayers(GameContext game, Presets preset, HexGridBehaviour grid)
    {
        PlayerListData pld = GameObject.FindObjectOfType <PlayerListData>();

        if (pld != null)
        {
            IEnumerator <Vector3> basePos = CoordinatesForBases(grid);
            foreach (var player in pld._model)
            {
                GameEntity pEntity = game.CreateEntity();
                pEntity.AddTeam(player.Color);
                pEntity.isLocalPlayer = (player.Type == PlayerTypeEnum.Human);
                pEntity.isAIPlayer    = (player.Type == PlayerTypeEnum.AI);

                basePos.MoveNext();
                GameEntity       baseEntity = preset.CreateBlueprint(Presets.EntitasPresetEnum.BASE);
                HexCellBehaviour home       = grid.GetCell(basePos.Current);
                baseEntity.ReplaceLocation(home, home.GetComponent <EntitasLink>().id);
                baseEntity.ReplaceTeam(player.Color);
                baseEntity.ReplaceStartPosition(home.transform.position.x, home.transform.position.y, home.transform.position.z);
            }
        }
        else
        {
            Debug.Log("No player setup found; I'm assuming this scene was started in Unity Editor for debugging purposes");

            GameEntity pEntity = game.CreateEntity();
            pEntity.AddTeam(0);
            pEntity.isLocalPlayer = true;
            pEntity.isAIPlayer    = false;
        }
    }
Esempio n. 3
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (_context != null)
     {
         _context.CreateEntity().AddCollision(_entity, collision.gameObject.tag);
     }
 }
    protected override void Execute(List <InputEntity> entities)
    {
        clicksToColorList = new List <ClicksToColor>(_gameContext.clicksToColorVariant.list);

        foreach (InputEntity e in entities)
        {
            if (_clickCounter != null)
            {
                int numberOfClicks = _clickCounter.totalClicksNumber.totalClicks + 1;
                _clickCounter.ReplaceTotalClicksNumber(numberOfClicks);

                ClicksToColor clicksToColor = clicksToColorList.Find(c => numberOfClicks % c.clicksNumber == 0);

                if (clicksToColor != null)
                {
                    _gameContext.CreateEntity().AddDebugMessage("Emitting change to color: " + clicksToColor.color);
                    CheckAndChangeColor(clicksToColor.color);
                    break;
                }
                else
                {
                    _gameContext.CreateEntity().AddDebugMessage("Emitting change to default color");
                    CheckAndChangeColor(Color.white);
                }
            }
        }
    }
Esempio n. 5
0
        public void TurnManagerAssignsTurnsToEntitiesWithEnergy()
        {
            GameContext    context         = Contexts.sharedInstance.game;
            var            entityGenerator = Container.Resolve <IEntityGenerator>();
            IEntityRecipee recipee         = Mock.Of <IEntityRecipee>();
//        entityGenerator.GenerateActorFromRecipeeAndAddToContext(context, recipee, new Position(0, 0), out GameEntity entity);

            var entity1 = context.CreateEntity();

            entity1.ReplacePosition(new Position(0, 0));
            entity1.ReplaceEnergy(1f, 0.5f);

            var entity2 = context.CreateEntity();

            entity2.ReplaceEnergy(0.3f, 0f);
            entity2.ReplacePosition(new Position(1, 1));

            var turnManager = Container.Resolve <ITurnManager>();

            turnManager.OnGameStart();

            for (int i = 1; i < 10; i++)
            {
                _log.Add($"{i} has turn!");
                turnManager.Update();
            }

            Assert.Pass(string.Join(Environment.NewLine, _log));
        }
Esempio n. 6
0
    protected override void Execute(List <GameEntity> entities)
    {
        if (_context.hasBattleOver)
        {
            return;
        }

        // 50% + (defend speed - attack speed) * 15% - (attack taijutsu - 7) * 10%

        foreach (var e in entities)
        {
            var probability      = 0.5f;
            var defenderSpeed    = _context.characterBaseAttributes.dic[e.name.text].speed;
            var attackerSpeed    = _context.characterBaseAttributes.dic[e.taijutsuAttackHit.hitBy.name.text].speed;
            var attackerTaijutsu = _context.characterBaseAttributes.dic[e.taijutsuAttackHit.hitBy.name.text].taijutsu;
            probability = probability + (defenderSpeed - attackerSpeed) * 0.15f - (attackerTaijutsu - 7) * 0.1f;

            if (e.taijutsuAttackHit.hitBy.position.value.X < e.position.value.X != e.toward.left)
            {
                probability -= 0.3f;
            }

            if (!Utilities.CheckSuccess(probability))
            {
                continue;
            }

            _context.CreateEntity().ReplaceDebugMessage(e.name.text + " dodge " + e.taijutsuAttackHit.hitBy.name.text + "'s hit");
            _context.CreateEntity().ReplaceBattleValueDisplay(-1, 1, new Vector3(0, 132, 255), "闪避", e);
            e.RemoveTaijutsuAttackHit();
        }
    }
Esempio n. 7
0
    protected override void Execute(List <GameEntity> entities)
    {
        foreach (var entity in entities)
        {
            if (entity.hasEventTrigger)
            {
                if (entity.eventTrigger.Evt == EventsEnum.DayStarted)
                {
                    ProcessNewDay(entity.eventTrigger.Index);
                }
                else
                {
                    ProcessEvent(entity.eventTrigger.Evt, entity.eventTrigger.Index);
                }
            }

            if (entity.isPlayerAdvanceNextDayInput && _isDayFinished)
            {
                GameEntity advanceNextDay = _gameContext.CreateEntity();
                advanceNextDay.isLoadNextLevelTrigger = true;

                _gameContext.globals.value.endGameView.Toggle(false);
            }

            if (!entity.isInteractible)
            {
                entity.Destroy();
            }
            else
            {
                entity.RemoveEventTrigger();
            }
        }
    }
Esempio n. 8
0
        private void Initialize()
        {
            var sunE = _game.CreateEntity();

            sunE.ReplacePlanet("Sun", 0f, 0f);
            sunE.ReplaceHealth(Consts.SunHealth);
            sunE.ReplaceMass(750f);

            var cannons = _cannons.ToList();

            cannons.Shuffle();

            for (var i = 0; i < Consts.PlanetNames.Length; i++)
            {
                var rotationRadius = (i + 1) * 1.33f; // Do not exceed 4 (for 3 planets)
                var randomValue    = (float)_rand.NextDouble();
                var sign           = Math.Sign(randomValue - 0.5f);
                var rotationSpeed  = sign * (20f + randomValue * 20f);

                var planetE = _game.CreateEntity();
                planetE.ReplacePlanet(Consts.PlanetNames[i], rotationRadius, rotationSpeed);
                planetE.ReplaceHealth(1000f);
                planetE.ReplaceMass(250f);
                planetE.ReplaceComponent(GameComponentsLookup.Cannon, cannons[i]);
            }
        }
    public static void CreateShadowAndGlass(this GameContext context, float x, int number)
    {
        var shadowGameObject = InstantiateFromAsset("shadow");
        var shadowEntity     = context.CreateEntity();

        shadowEntity.AddGameObject(shadowGameObject);
        shadowEntity.AddPosition(new Vector2(x, -30));
        shadowEntity.AddPlaceNumber(context.variables.currentPlaceNumber++);
        shadowEntity.AddParentTransform(context.viewParent.value);

        var isDudeHolder = number == 1 || number == 2;

        var glassEntity = context.CreateEntity();

        glassEntity.AddGameObject(InstantiateFromAsset("glass"));
        glassEntity.AddPosition(new Vector2(0, 7.5F));
        glassEntity.AddParentTransform(shadowGameObject.transform);
        glassEntity.AddDudeHolder(isDudeHolder);

        if (!isDudeHolder)
        {
            return;
        }
        var dudeEntity = context.CreateEntity();

        dudeEntity.AddGameObject(InstantiateFromAsset("dude"));
        dudeEntity.AddPosition(new Vector2(0, 2));
        dudeEntity.AddParentTransform(shadowGameObject.transform);
        dudeEntity.AddColor(number == 1 ? Color.cyan : Color.yellow);
    }
Esempio n. 10
0
    protected override void Execute(List <InputEntity> entities)
    {
        GameEntity[] selectedUnitProduction = selected.GetEntities();
        if (selectedUnitProduction.Length > 0)
        {
            GameEntity unitProductionBuilding = selectedUnitProduction[0];
            foreach (var entity in entities)
            {
                int price = DeterminePrice(entity.unitType.type);
                if (GameUtils.IsEnoughResource(gameContext, gameContext.playerInventory, GameResource.GOLD, price))
                {
                    GameEntity buildWorkerAction = gameContext.CreateEntity();
                    buildWorkerAction.AddChannelAction(5f);
                    buildWorkerAction.AddCountdown(5f);
                    buildWorkerAction.AddAction(false);
                    buildWorkerAction.AddParentLink(unitProductionBuilding.id.value);
                    buildWorkerAction.AddUnitType(entity.unitType.type);
                    buildWorkerAction.isCreateUnitAction = true;

                    GameEntity payResourcesAction = gameContext.CreateEntity();
                    payResourcesAction.AddTransferResourceAction(gameContext.playerInventory.resourceIndex[GameResource.GOLD],
                                                                 buildWorkerAction.id.value, price);
                    payResourcesAction.AddAction(false);
                    payResourcesAction.isAct = true;
                }
                else
                {
                    //TODO: Not enough warning
                }
            }
        }
    }
    public void Execute()
    {
        if (spawnCharacterCommandGroup.count > 0)
        {
            foreach (var inputEntity in spawnCharacterCommandGroup.GetEntities())
            {
                var spawnCharacterData = inputEntity.spawnCharacter.value;
                var id = GetNewId(spawnCharacterData.teamId);
                if (id >= 0)
                {
                    var characterEntity = _gameContext.CreateEntity();
                    characterEntity.AddViewAsset(AssetId.Knight_01);

                    characterEntity.AddCharacterCharacterMetaData(id,
                                                                  new CharacterMetaData()
                    {
                        level  = spawnCharacterData.level, displayName = "Dummy" + id,
                        teamId = spawnCharacterData.teamId
                    });

                    characterEntity.AddCharacterPosition(spawnCharacterData.Position);
                    characterEntity.AddCharacterMovement(0f, Vector2.right);
                    characterEntity.AddCharacterState(new CharacterStateData()
                    {
                        currentState = CharacterState.Idle, prevState = CharacterState.None
                    });
                    characterEntity.AddBT(new BaseCharacterBT());

                    AddCharacterStat(characterEntity, CharacterType.Creep, spawnCharacterData.level);
                }

                inputEntity.isEntityDestroyed = true;
            }
        }
    }
 public void Initialize()
 {
     _gameContext.isPlayer = true;
     _gameContext.CreateEntity().AddInventoryUpdate(Resource.Wood, 1000);
     _gameContext.CreateEntity().AddInventoryUpdate(Resource.Steel, 1000);
     _gameContext.CreateEntity().AddInventoryUpdate(Resource.Gold, 1000);
 }
Esempio n. 13
0
    private void OnNotification(object sender, IApiNotification notification)
    {
        switch (notification.Code)
        {
        case 501:
            var matchReadyState = Utilities.ParseJson <SCReadyState>(notification.Content);
            if (matchReadyState.customMatchId == _context.currentMatchData.value.customMatchId)
            {
                _context.CreateEntity().ReplaceMatchReadyState(matchReadyState);
            }
            break;

        case 502:
            var allocationNinja = Utilities.ParseJson <SCAllocationNinja>(notification.Content);
            _context.ReplaceAllocationNinjaNotification(allocationNinja);
            break;

        case 503:
            var chooseNinja = Utilities.ParseJson <SCChooseNinja>(notification.Content);
            _context.CreateEntity().ReplacePlayerChooseNinjaInfo(chooseNinja.userId, chooseNinja.ninjaName, chooseNinja.confirm);
            break;

        case 504:
            var matchData = Utilities.ParseJson <SCMatchData>(notification.Content);
            _context.ReplaceCurrentMatchData(matchData);
            _context.isMatchStart = true;
            break;

        default:
            break;
        }
    }
Esempio n. 14
0
    private IEnumerator MoveUi(string uiName, Vector2 forLocation, float time)
    {
        _context.CreateEntity().ReplaceDebugMessage(uiName + " move to " + forLocation);
        var oldPosition   = _context.sceneService.instance.GetUILocalPosition(uiName);
        var finalPosition = oldPosition + forLocation;
        var lastPosition  = oldPosition;
        var durationTime  = 0.0f;

        while (durationTime < time)
        {
            var newPosition = lastPosition + _context.timeService.instance.GetDeltaTime() / time * forLocation;
            if (Math.Abs(newPosition.X - oldPosition.X) > Math.Abs(finalPosition.X - oldPosition.X) || Math.Abs(newPosition.Y - oldPosition.Y) > Math.Abs(finalPosition.Y - oldPosition.Y))
            {
                _context.sceneService.instance.SetUILocalPosition(uiName, forLocation);
                break;
            }
            _context.sceneService.instance.SetUILocalPosition(uiName, newPosition);
            lastPosition  = newPosition;
            durationTime += _context.timeService.instance.GetDeltaTime();
            yield return(_context.coroutineService.instance.WaitForEndOfFrame());
        }
        _context.sceneService.instance.SetUILocalPosition(uiName, finalPosition);
        var success = _context.movingUiList.list.Remove(uiName);

        _context.CreateEntity().ReplaceDebugMessage(uiName + " move over " + success);
    }
    public void Initialize()
    {
        var go = new GameObject("Intensity");
        var e  = _gameContext.CreateEntity();

        e.AddIntensity(100, new Vector2(2f, 5f));
        go.Link(e, _gameContext);
    }
 public void Execute()
 {
     if (Input.GetMouseButtonDown(0))
     {
         _context.CreateEntity().AddDebugMessage("Left Mouse Down Clicked");
     }
     if (Input.GetMouseButtonDown(1))
     {
         _context.CreateEntity().AddDebugMessage("Right Mouse Down Clicked");
     }
 }
Esempio n. 17
0
 public void Execute()
 {
     if (Input.GetMouseButtonDown(0))
     {
         _context.CreateEntity().AddDebugMessage("鼠标左键点击");
     }
     if (Input.GetMouseButtonDown(1))
     {
         _context.CreateEntity().AddDebugMessage("鼠标右键点击");
     }
 }
Esempio n. 18
0
 public void Execute()
 {
     // 获取到左右按键,就创建个Entity,并添加一个DebguMessage组件
     if (Input.GetMouseButtonDown(0))
     {
         _context.CreateEntity().AddDebugMessage("Left Mouse Button Clicked");
     }
     if (Input.GetMouseButtonDown(1))
     {
         _context.CreateEntity().AddDebugMessage("Right Mouse Button Clicked");
     }
 }
    protected override void Execute(List <GameEntity> entities)
    {
        foreach (GameEntity e in entities)
        {
            GameObject gameObjectA = e.collider.me;
            GameObject gameObjectB = e.collider.other;

            Rigidbody2D rb = gameObjectA.GetComponent <Rigidbody2D> ();

            if (gameObjectB.tag == "Boundary")
            {
                var        newAsset  = Resources.Load <GameObject> ("Explosion");
                GameObject explosion = null;
                try {
                    explosion = UnityEngine.Object.Instantiate(newAsset);
                } catch (Exception) {
                    Debug.Log("Cannot instantiate 'Explosion'");
                }
                if (explosion != null)
                {
                    explosion.transform.position = gameObjectA.transform.position;
                    UnityEngine.Object.Destroy(explosion, 0.35f);
                }
                // reset ball
                gameObjectA.transform.position = Vector2.zero;

                if (gameObjectB.name.EndsWith("Player"))
                {
                    _context.CreateEntity()
                    .AddChangeScore(1, +1);
                }
                else if (gameObjectB.name.EndsWith("Opponent"))
                {
                    _context.CreateEntity()
                    .AddChangeScore(0, +1);
                }

                Vector2 startV = new Vector2(-5f, -1.5f);
                startV      = Vector2.ClampMagnitude(startV, 4f);
                rb.velocity = new Vector2(
                    startV.x * Mathf.Sign(gameObjectB.transform.position.x),
                    startV.y * UnityEngine.Random.Range(-2, 2) * 0.7f
                    );
            }
            else if (gameObjectB.tag == "Paddle")
            {
                // increase velocity when ball hits paddle
                float changeX = Mathf.Min(rb.velocity.x * 0.13f, 0.5f);
                float changeY = Mathf.Min(rb.velocity.y * 0.13f, 0.5f);
                rb.velocity = new Vector2(rb.velocity.x + changeX, rb.velocity.y + changeY);
            }
        }
    }
Esempio n. 20
0
 public void Initialize()
 {
     foreach (var setup in _setups)
     {
         for (int i = 0; i < setup.Count; i++)
         {
             var entity = _gameContext.CreateEntity();
             entity.AddView(ViewService.sharedInstance.CreateViewAndLink(entity, _gameContext, setup.Name, setup.Source));
             entity.AddPool(setup.Id, false);
         }
     }
 }
Esempio n. 21
0
    private void OnTriggerEnter2D(Collider2D collidedObject)
    {
        //Trigger enter fired, create appropriate trigger entity
        var collidedEntity = collidedObject.gameObject.GetEntityLink().entity as GameEntity;

        if (collidedEntity != null)
        {
            var collidedEntityId = collidedEntity.id.Id;
            var triggerEntity    = _context.CreateEntity();
            triggerEntity.AddTrigger(_entityId, collidedEntityId, true);
        }
        //else - we dont know what entity was "triggered" (no entity linked to collidedObject)
    }
Esempio n. 22
0
    public void Initialize()
    {
        var layerConfig = _context.uiLayerConfig.config;

        _context.sceneService.instance.InitializeLayers(layerConfig);
        _context.uiLayerConfigEntity.isDestroy = true;

        _context.ReplaceUuidToEntity(new Dictionary <int, GameEntity>());
        _context.ReplaceUiChildList(new Dictionary <int, List <int> >());

        var e = _context.CreateEntity();

        e.ReplaceUiOpen("GameState");
        e.ReplaceName("GameState");
    }
Esempio n. 23
0
        public void CreationIndex()
        {
            var context = new GameContext();
            var entity  = context.CreateEntity();

            entity.AddId(Guid.NewGuid());
            Console.WriteLine(entity.creationIndex);
            Console.WriteLine(entity.id.Id);
            var entity2 = context.CreateEntity();

            Console.WriteLine(entity2.creationIndex);
            //entity2.AddId(1);
//			Console.WriteLine(entity2.id.Id);
            Console.WriteLine($"{context.GetEntityWithId(Guid.NewGuid()).creationIndex}");
        }
Esempio n. 24
0
    public void Initialize()
    {
        _context.CreateEntity()
        .AddDebugMessage("Hello World");

        var index  = GameComponentsLookup.DebugMessage;
        var type   = typeof(DebugMessageComponent);
        var entity = _context.CreateEntity();
        // var dm = entity.CreateComponent(index, type) as DebugMessageComponent;
        var dm = entity.CreateComponent <DebugMessageComponent>(index);

        dm.message = "Haaaaaaaaaaaaa";
        entity.AddComponent(index, dm);
        dm.message = "123";
    }
Esempio n. 25
0
    public static GameEntity CreateGameBoard(this GameContext context)
    {
        var entity = context.CreateEntity();

        entity.AddBoadGame(8, 8);
        return(entity);
    }
Esempio n. 26
0
        private static async Task <int> RunContext(int number)
        {
            GameContext context = new GameContext();

            GameMatcher matcher = new GameMatcher(new MatcherInstance <GameEntity>());

            var entity = context.CreateEntity();

            entity.AddPosition(new Vector3Int(0, 0, 0));

            var systems = new Systems().Add(new CreateEntitySystem(context)).Add(new MoveEntitySystem(matcher, context, number));

            systems.Initialize();

            int iterationCount = 0;

            int endIterationCount = ITERATION_COUNT * number;

            while (iterationCount < endIterationCount)
            {
                systems.Execute();

                iterationCount++;

                await Task.Delay(20);
            }

            return(number);
        }
Esempio n. 27
0
    public void Execute()
    {
        if (_context.currentScene.name != "BattleScene")
        {
            return;
        }
        if (!_context.isReplaying)
        {
            return;
        }
        if (!_context.hasReplayStartTime)
        {
            return;
        }

        var deltaTime = _context.timeService.instance.GetLocalTimeStamp() - _context.replayStartTime.value;
        var record    = _context.currentReplayData.value.matchRecord;

        while (record.Count > 0 && record.First().time <= deltaTime)
        {
            var recordItem = record.First();
            record.RemoveAt(0);
            _context.CreateEntity().ReplaceMatchData(recordItem.opCode, recordItem.data);
        }
    }
Esempio n. 28
0
 protected override void Execute(List <GameEntity> entities)
 {
     foreach (GameEntity entity in entities)
     {
         m_Context.CreateEntity();
     }
 }
Esempio n. 29
0
    protected override void Execute(List <GameEntity> entities)
    {
        foreach (var e in entities)
        {
            if (gameContext.uiRootEntity != null)
            {
                if (gameContext.uiRootEntity.hasUiRoot)
                {
                    var        ui = gameContext.uiRoot.root;
                    GameObject winnerTextPrefab = GameObject.Instantiate(Resources.Load("WinnerText"), ui) as GameObject;

                    if (e.isPlayer1Winner)
                    {
                        winnerTextPrefab.GetComponent <Text>().text = "Winner\nPlayer1";
                    }

                    if (e.isPlayer2Winner)
                    {
                        winnerTextPrefab.GetComponent <Text>().text = "Winner\nPlayer2";
                    }

                    var winnerText = gameContext.CreateEntity();
                    winnerText.AddView(winnerTextPrefab);
                    winnerText.isUiElement = true;
                }
            }
        }
    }
Esempio n. 30
0
    protected override void Execute(List <GameEntity> entities)
    {
        if (entities.Count > 1)
        {
            throw new InvalidOperationException();
        }

        foreach (var entity in entities)
        {
            entity.isShouldAct        = false;
            entity.isActionInProgress = true;

            var currentPos = entity.position.value;
            var moved      = false;
            for (int i = 0; i < 10; i++)
            {
                var pos = currentPos + new IntVector2(3 * UnityEngine.Random.Range(-1, 2), 3 * UnityEngine.Random.Range(-1, 2));
                if (Map.Instance.IsWalkable(pos))
                {
                    entity.ReplacePosition(pos, true);
                    moved = true;
                    break;
                }
            }

            if (moved == false)
            {
                entity.isActionInProgress = false;
                context.CreateEntity().AddAction(ActionType.NOTHING, new NothingArgs()
                {
                    source = entity
                });
            }
        }
    }