Пример #1
0
 private void CollectibleItemEventHandler(CollectibleItemArgs collectibleItemArgs)
 {
     if (collectibleItemArgs.index == groundIndex)
     {
         PublisherSubscriber.Publish(GameEventType.IncrementCollectibleItemCount);
     }
 }
Пример #2
0
        public void OnPointerUp(PointerEventData eventData)
        {
            currentScreenPosition = eventData.position;
            currentPosition       = cameraMain.GetWorldPositionIn3D(currentScreenPosition, -1f * cameraMain.transform.position.z);

            var distance = Vector3.Distance(initialPosition, currentPosition);

            if (distance >= 1f)
            {
                //Try to Swipe
                if (initialScreenPosition.x > currentScreenPosition.x)
                {
                    PublisherSubscriber.Publish(SwipeDirection.Left);
                }
                else
                {
                    PublisherSubscriber.Publish(SwipeDirection.Right);
                }
                return;
            }

            var hit = Physics2D.Raycast(initialPosition, cameraMain.transform.forward, Mathf.Infinity, layerToHit);

            if (hit.transform == null)
            {
                return;
            }
            if (hit.transform.GetComponent <GridItem>(out var gridItem))
            {
                gridItem.Select(hit.point);
            }
        }
Пример #3
0
        public override void Construct(CharacterModel model, bool isLoad = false)
        {
            heroControllers = FindObjectsOfType <HeroController>().ToList();
            var heroModels = heroControllers.Select(controller => controller.HeroModel).ToList();

            enemyModel = model as EnemyModel;

            if (enemyModel == null)
            {
                Debug.Log("Enemy Model could not resolve in EnemyController");
                return;
            }

            if (!isLoad)
            {
                enemyModel.Construct(heroModels);
                enemyModel.CurrentHealth = enemyModel.Health;
            }

            characterGraphicsController.Construct(enemyModel.Sprite);

            healthBarController.Construct(enemyModel.name);
            PublisherSubscriber.Publish(new ProgressBarData
            {
                Id            = enemyModel.name,
                BarType       = ProgressBarType.HealthProgression,
                TotalAmount   = enemyModel.Health,
                CurrentAmount = enemyModel.CurrentHealth
            });
        }
        private void OnEnable()
        {
            playerTransform = transform;
            playerPosition  = playerTransform.position;

            inputEventSubscription = PublisherSubscriber.Subscribe <InputEventArgs>(Move);
        }
Пример #5
0
        private void ItemCollected()
        {
            if (--itemCount != 0)
            {
                PublisherSubscriber.Publish(new CollectedItemArgs()
                {
                    groundIndex      = currentGroundIndex,
                    currentItemCount = ++currentItemCount,
                    totalItemCount   = totalItemCount
                });
            }
            else
            {
                PublisherSubscriber.Publish(new CollectedItemArgs()
                {
                    groundIndex      = currentGroundIndex,
                    currentItemCount = 1,
                    totalItemCount   = 1
                });

                PublisherSubscriber.Publish(currentGroundIndex == 1
                    ? GameEventType.GroundCompleted
                    : GameEventType.LevelComplete);
            }
        }
Пример #6
0
 private void FindCollectibleItemCount()
 {
     PublisherSubscriber.Publish(new CollectibleItemArgs()
     {
         index = currentGroundIndex
     });
 }
Пример #7
0
        public override void Construct(CharacterModel model, bool isLoad = false)
        {
            HeroModel = model as HeroModel;

            if (HeroModel == null)
            {
                Debug.Log($"HeroModel could not resolve in HeroController");
                return;
            }

            if (!isLoad)
            {
                HeroModel.CurrentHealth = HeroModel.Health;
            }

            gameObject.name = HeroModel.name;

            characterGraphicsController.Construct(HeroModel.Sprite);

            healthBarController.Construct(HeroModel.name);
            PublisherSubscriber.Publish(new ProgressBarData
            {
                Id            = HeroModel.name,
                BarType       = ProgressBarType.HealthProgression,
                TotalAmount   = HeroModel.Health,
                CurrentAmount = HeroModel.CurrentHealth
            });
        }
        public static async Task <PublisherSubscriber> GetPublisherSubscriberDualChannel(this WampPlayground playground)
        {
            const string realmName = "realm1";

            playground.Host.Open();

            PublisherSubscriber result = new PublisherSubscriber();

            result.Publisher =
                playground.CreateNewChannel(realmName);

            result.Subscriber =
                playground.CreateNewChannel(realmName);

            long?publisherSessionId = null;

            result.Publisher.RealmProxy.Monitor.ConnectionEstablished +=
                (x, y) => { publisherSessionId = y.SessionId; };

            await result.Publisher.Open();

            await result.Subscriber.Open();

            result.PublisherSessionId = publisherSessionId.Value;

            return(result);
        }
Пример #9
0
 private void CheckPossibleMoveCount()
 {
     if (totalPossibleMoveCount == 0)
     {
         PublisherSubscriber.Publish(GameEventType.GameOver);
     }
 }
Пример #10
0
        private void GameEventHandler(GameEventType gameEventType)
        {
            switch (gameEventType)
            {
            case GameEventType.GameStart:
                var level = playerData.GetLevel();
                currentGround1TransformIndex = (level - 1) % ground1Transforms.Length;
                currentGround2TransformIndex = (level - 1) % ground2Transforms.Length;

                LoadLevel();

                onGameStartEvent?.Invoke();
                PublisherSubscriber.Publish(GameEventType.LevelStart);
                break;

            case GameEventType.LevelStart:
                currentGroundIndex = 1;
                FindCollectibleItemCount();
                break;

            case GameEventType.ItemCollected:
                ItemCollected();
                break;

            case GameEventType.LevelComplete:
                playerData.SetLevel(playerData.GetLevel() + 1);
                playerData.SetGold(playerData.GetGold() + 50);
                PublisherSubscriber.Publish(GameEventType.GameStart);
                Debug.Log("Level Completed");
                break;

            case GameEventType.GroundCompleted:
                itemCount = 0;
                PublisherSubscriber.Publish(new GroundCompletedEventArgs()
                {
                    currentGroundIndex = currentGroundIndex
                });
                currentGroundIndex++;
                FindCollectibleItemCount();
                break;

            case GameEventType.IncrementCollectibleItemCount:
                currentItemCount = 0;
                itemCount++;
                totalItemCount = itemCount;
                break;

            case GameEventType.LevelReload:
                itemCount = 0;
                PublisherSubscriber.Publish(GameEventType.GameStart);
                break;

            default:
                //do nothing;
                break;
            }
        }
Пример #11
0
    public static void Main(string[] args)
    {
        // AnimalWorld animalWorld = new AnimalWorld();
        // animalWorld.Run();

        var ps = new PublisherSubscriber();

        ps.Run();
    }
Пример #12
0
 private void ExecuteTurn()
 {
     transform.DOMove(enemyPosition, 0.5f).OnComplete(() =>
     {
         enemyController.TakeDamage(HeroModel.AttackPower);
         transform.DOMove(initialPosition, 0.5f).OnComplete(() =>
         {
             PublisherSubscriber.Publish(GameEventType.PlayerFinishedTurn);
         });
     });
 }
Пример #13
0
        private void OnDisable()
        {
            if (!isBomb)
            {
                return;
            }
            IsBombEnabled = false;
            isBomb        = false;

            PublisherSubscriber.Unsubscribe(gameEventSubscription);
        }
Пример #14
0
        private void OnDisable()
        {
            if (collectibleType == CollectibleType.Default)
            {
                PublisherSubscriber.Unsubscribe(collectibleItemEventSubscription);
            }

            if (collectibleType == CollectibleType.Enemy)
            {
                PublisherSubscriber.Unsubscribe(groundCompletedEventSubscription);
            }
        }
Пример #15
0
 private void GameEventHandler(GameEventType gameEventType)
 {
     if (gameEventType != GameEventType.UpdateMoveCount)
     {
         return;
     }
     countdown--;
     text.text = countdown.ToString();
     if (countdown == 0)
     {
         PublisherSubscriber.Publish(GameEventType.GameOver);
     }
 }
Пример #16
0
 private void Start()
 {
     playerCollider = GetComponent <SphereCollider>();
     playerCollider.OnCollisionEnterAsObservable().Subscribe(collision =>
     {
         if (!collision.collider.GetComponent <IGetColor>(out var getColor))
         {
             return;
         }
         if (getColor.GetColor() != playerGraphicsController.GetColor())
         {
             PublisherSubscriber.Publish(GameEventType.LevelFailed);
         }
     });
 }
Пример #17
0
 public void OnPointerDown(PointerEventData eventData)
 {
     cameraRay = mainCamera.ScreenPointToRay(eventData.position);
     if (!Physics.Raycast(cameraRay, out raycastHit, Mathf.Infinity, hitMask))
     {
         return;
     }
     initialPositionVector = raycastHit.point;
     PublisherSubscriber.Publish(new InputEventArgs
     {
         InputState           = InputState.Down,
         CurrentWorldPosition = initialPositionVector,
         Delta = Vector3.zero
     });
 }
Пример #18
0
        private static void CheckFlags()
        {
            var isStillShowing = false;

            foreach (var flag in Flags.Where(flag => flag.IsStillShowing))
            {
                isStillShowing = true;
            }

            if (isStillShowing)
            {
                return;
            }
            PublisherSubscriber.Publish(GameEventType.EndBattle);
        }
Пример #19
0
 public void Collect()
 {
     if (collectibleType == CollectibleType.Linker)
     {
         gameObject.SetActive(false);
         return;
     }
     if (isCollected)
     {
         return;
     }
     isCollected = true;
     PublisherSubscriber.Publish(collectibleType == CollectibleType.Enemy
         ? GameEventType.LevelFailed
         : GameEventType.ItemCollected);
 }
Пример #20
0
        public void NextState()
        {
            foreach (var state in states)
            {
                if (state.currentGameState != currentState.nextGameState)
                {
                    continue;
                }
                currentState = state;

                currentState.onStateEvent.Invoke();
                break;
            }

            PublisherSubscriber.Publish(GameEventType.NextState);
        }
Пример #21
0
        public void OnDrag(PointerEventData eventData)
        {
            cameraRay = mainCamera.ScreenPointToRay(eventData.position);
            if (!Physics.Raycast(cameraRay, out raycastHit, Mathf.Infinity, hitMask))
            {
                return;
            }
            currentPositionVector = raycastHit.point;
            positionDeltaVector   = currentPositionVector - initialPositionVector;
            initialPositionVector = currentPositionVector;

            inputEventArgs = new InputEventArgs()
            {
                delta = positionDeltaVector
            };
            PublisherSubscriber.Publish(inputEventArgs);
        }
Пример #22
0
        public void Generate()
        {
            ClearGridItems();

            ClearRemainingChildren();

            CalculateScreenView();
            CalculateScaleFactor();
            CalculateStartingPosition();

            if (gridItemTransforms == null)
            {
                gridItemTransforms = new List <Vector3>();
            }
            gridItemTransforms.Clear();

            for (var i = 0; i < gridRowCount; i++)
            {
                for (var j = 0; j < gridColumnCount; j++)
                {
                    var tempItem = Instantiate(gridItemPrefab);
                    tempItem.name = $"GridItem [{i},{j}]";

                    var tempItemTransform = tempItem.transform;
                    tempItemTransform.position   = startingPosition + CalculatePosition(i, j);
                    tempItemTransform.localScale = Vector3.one * scaleFactor;
                    tempItemTransform.SetParent(transform);

                    gridItemTransforms.Add(tempItemTransform.position);

                    var tempGridItem = tempItem.GetComponent <GridItem>();
                    tempGridItem.Deselect();
                    tempGridItem.Position = new GridPosition()
                    {
                        rowPosition    = i,
                        columnPosition = j
                    };

                    gridItems.Add(tempGridItem);
                }
            }

            PublisherSubscriber.Publish(GameEventType.CheckNeighbors);
        }
Пример #23
0
        private void OnEnable()
        {
            if (collectibleType == CollectibleType.Default)
            {
                collectibleItemEventSubscription =
                    PublisherSubscriber.Subscribe <CollectibleItemArgs>(CollectibleItemEventHandler);
            }

            if (collectibleType == CollectibleType.Enemy)
            {
                groundCompletedEventSubscription =
                    PublisherSubscriber.Subscribe <GroundCompletedEventArgs>(GroundCompleteEventHandler);
            }

            if (collectibleType == CollectibleType.Linker)
            {
                collectibleItemRigidbody.isKinematic = true;
            }
        }
Пример #24
0
        public override void TakeDamage(float attackPower)
        {
            HeroModel.CurrentHealth -= attackPower;
            PublisherSubscriber.Publish(new ProgressBarData
            {
                Id            = HeroModel.name,
                BarType       = ProgressBarType.HealthProgression,
                TotalAmount   = HeroModel.Health,
                CurrentAmount = HeroModel.CurrentHealth
            });

            var popup = GetFadingPopup();

            popup.Construct(-1f * attackPower, transform.position);

            if (HeroModel.CurrentHealth <= 0f)
            {
                gameObject.SetActive(false);
            }
        }
Пример #25
0
        private void OnEnable()
        {
            bombCanvas.SetActive(false);

            if (GameManager.TotalScore < GameManager.BombCount * GameManager.BombStep)
            {
                return;
            }
            if (IsBombEnabled)
            {
                return;
            }
            IsBombEnabled = true;
            isBomb        = true;
            GameManager.BombCount++;
            bombCanvas.SetActive(true);
            text.text = (countdown = Random.Range(8, 13)).ToString();

            gameEventSubscription = PublisherSubscriber.Subscribe <GameEventType>(GameEventHandler);
        }
Пример #26
0
        private void UpdateLevelProgressBar(bool isFilled = false)
        {
            var playerPosition = TryPlayerPosition();

            var finishPosition = TryFinishPosition();

            if (!isTotalLevelDistanceCalculated)
            {
                totalLevelDistance = Mathf.Abs(playerPosition - finishPosition);

                levelProgressBarData.TotalAmount = totalLevelDistance;
            }

            currentLevelDistance = isFilled
                ? totalLevelDistance
                : totalLevelDistance - Mathf.Abs(playerPosition - finishPosition);

            levelProgressBarData.CurrentAmount = currentLevelDistance;
            PublisherSubscriber.Publish(levelProgressBarData);
        }
Пример #27
0
        public override void Attack()
        {
            var initialPosition = transform.position;

            var randomIndex            = Random.Range(0, heroControllers.Count);
            var selectedHeroController = heroControllers[randomIndex];

            while (selectedHeroController.HeroModel.CurrentHealth <= 0f)
            {
                heroControllers.RemoveAt(randomIndex);
                randomIndex            = Random.Range(0, heroControllers.Count);
                selectedHeroController = heroControllers[randomIndex];
            }

            TimeSystem.CreateTimer(
                $"{enemyModel.name}'s Attack",
                1f,
                new []
            {
                new TimerActionData
                {
                    ActionType  = TimerActionType.OnStart,
                    TimerAction = () =>
                    {
                        transform.DOMove(selectedHeroController.transform.position, 0.5f).OnComplete(() =>
                        {
                            selectedHeroController.TakeDamage(enemyModel.AttackPower);
                            transform.DOMove(initialPosition, 0.5f).OnComplete(() =>
                            {
                                PublisherSubscriber.Publish(GameEventType.EnemyFinishedTurn);
                            });
                        });
                    }
                }
            }
                );
        }
Пример #28
0
        public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
        {
            if (placementId != rewardedAdPlacementId)
            {
                return;
            }
            switch (showResult)
            {
            case ShowResult.Failed:
                //do nothing.
                break;

            case ShowResult.Skipped:
                PublisherSubscriber.Publish(GameEventType.LevelReload);
                break;

            case ShowResult.Finished:
                //do nothing.
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(showResult), showResult, null);
            }
        }
Пример #29
0
 public void SendCameraEventMessage(string message)
 {
     message = $"CAMERA_{message}";
     PublisherSubscriber.Publish(message);
 }
Пример #30
0
 private void OnDisable()
 {
     PublisherSubscriber.Unsubscribe(cameraEventSubscription);
 }
Пример #31
0
 public void UnSubscribe(PublisherSubscriber.EventDelegate listener)
 {
     m_ps.UnSubscribe(listener);
 }