示例#1
0
    public void Init(PlayerModel owner, CardData definition, bool isFromPlayersHand)
    {
        // EARLY OUT! //
        if (owner == null || definition == null)
        {
            Debug.LogWarning("Need an owner and card to initialize an entity.");
            return;
        }

        _spawnSeconds = 0f;
        _owner        = owner;
        _definition   = definition;
        _hp           = definition.StartHP;

        if (isFromPlayersHand && definition.SpawnChargeSeconds > 0)
        {
            var clockPrefab = Resources.Load <GameObject>(Consts.SpawnClockPrefabPath);
            if (clockPrefab != null)
            {
                var go = Utils.Instantiate(clockPrefab, SL.Get <GameModel>().BoardRoot.transform);
                if (go != null)
                {
                    var clock = go.GetComponent <SpawnClock>();
                    if (clock != null)
                    {
                        clock.Init(transform.position + Consts.SpawnClockOffset, _definition.SpawnChargeSeconds);
                    }
                }
            }
        }

        InitializedEvent.Invoke();
    }
示例#2
0
    void Update()
    {
        int numImagesUsed = 0;
        var player        = SL.Get <GameModel>().EnemyPlayer;

        foreach (var building in player.Buildings)
        {
            if (building.Entity != null && building.Entity.HP > 0)
            {
                foreach (var territory in building.Territory.Territories)
                {
                    if (numImagesUsed < _imagePool.Count)
                    {
                        var rectTransform = _imagePool[numImagesUsed];
                        var rect          = TerritoryData.ToWorldRect(territory);
                        rectTransform.gameObject.SetActive(true);
                        rectTransform.offsetMin = new Vector2(rect.xMin, rect.yMin);
                        rectTransform.offsetMax = new Vector2(rect.xMax, rect.yMax);

                        numImagesUsed++;
                    }
                }
            }
        }

        for (int i = numImagesUsed; i < _imagePool.Count; i++)
        {
            if (_imagePool[i].gameObject.activeSelf)
            {
                _imagePool[i].gameObject.SetActive(false);
            }
        }
    }
示例#3
0
    public static IProjectile FireProjectile(Entity creator, Rigidbody projectilePrefab, Transform fireTransform,
                                             Vector3 destination, float secondsToFlyHorizontalMeter)
    {
        // EARLY OUT! //
        if (creator == null || projectilePrefab == null || fireTransform == null)
        {
            return(null);
        }

        // Create an instance of the shell and store a reference to it's rigidbody.
        Rigidbody projectileRigidbody =
            Utils.Instantiate(projectilePrefab, fireTransform.position, fireTransform.rotation);

        projectileRigidbody.transform.SetParent(SL.Get <GameModel>().BoardRoot.transform, worldPositionStays: true);

        Vector3 velocity = CombatUtils.CalculateVelocityToHit(
            fireTransform.position,
            destination,
            secondsToFlyHorizontalMeter);

        projectileRigidbody.AddForce(velocity, ForceMode.VelocityChange);

        var projectile = projectileRigidbody.gameObject.GetInterface <IProjectile>();

        if (projectile != null)
        {
            projectile.Init(creator);
        }
        else
        {
            Debug.LogWarning("Problem with the projectile setup.");
        }

        return(projectile);
    }
示例#4
0
    private void OnTriggerEnter(Collider other)
    {
        // EARLY OUT! //
        // If the trigger isn't on an impact layer, ignore it.
        if (_isCollided || !CombatUtils.IsProjectileCollider(other.gameObject.layer))
        {
            return;
        }

        // EARLY OUT! //
        // If the collider is a friendly entity, early out.
        if (CombatUtils.IsEntity(other.gameObject.layer) && !CombatUtils.IsEnemy(_creator.Owner, other))
        {
            return;
        }

        _isCollided = true;

        var card = SL.Get <Config>().GetCardByName(_entityToSpawn);

        if (card != null)
        {
            card.SpawnChargeSeconds = 0;
            var unit = Entity.SpawnFromDefinition(_creator.Owner, card, transform.position.ZeroY(), isFromPlayersHand: false);
            _creator.Owner.RotateForPlayer(unit.gameObject);
        }
        else
        {
            Debug.LogWarning("Can't find card: " + card.Name);
        }

        // Destroy the shell.
        Destroy(gameObject);
    }
示例#5
0
    public static Entity GetClosestEnemyBuilding(Entity entity)
    {
        var enemy = SL.Get <GameModel>().GetOppositePlayer(entity.Owner);

        // EARLY OUT! //
        if (enemy == null)
        {
            return(null);
        }

        Entity closestEnemyBuilding = null;
        float  closestDist          = float.MaxValue;

        // Find the closest structure.
        foreach (var building in enemy.Buildings)
        {
            var buildingEntity = building.Entity;
            if (buildingEntity != null && buildingEntity.HP > 0)
            {
                var dist = Vector3.Distance(entity.transform.position, buildingEntity.transform.position);
                if (dist < closestDist)
                {
                    closestEnemyBuilding = buildingEntity;
                    closestDist          = dist;
                }
            }
        }

        return(closestEnemyBuilding);
    }
示例#6
0
    /// <summary>
    /// Static initialization of an entity.
    /// </summary>
    /// <param name="owner">The owning player.  Recommend not writing, just reading from it
    /// to let <see cref="GameModel"/> be authoritative.</param>
    /// <param name="definition">The card's definition.</param>
    /// <param name="position">The spawn position.</param>
    /// <param name="isFromPlayersHand">Was the card played from the player's hand?  If not, it was spawned
    /// by some other entity/effect in the game.</param>
    /// <returns>The created entity.</returns>
    public static Entity SpawnFromDefinition(PlayerModel owner, CardData definition, Vector3 position, bool isFromPlayersHand)
    {
        var prefab = SL.Get <ResourceManager>().Load <GameObject>(Consts.UnitsPath + definition.PrefabName);

        // EARLY OUT! //
        if (prefab == null)
        {
            Debug.LogWarning("Prefab not found: " + definition.Name);
            return(null);
        }

        var spawnPosition = position;

        if (definition.IsAirUnit)
        {
            spawnPosition.y = Consts.AirUnitHeight;
        }
        var go = Utils.Instantiate(prefab, SL.Get <GameModel>().BoardRoot.transform);

        go.transform.position = spawnPosition;

        var entity = go.GetComponent <Entity>();

        // EARLY OUT! //
        if (entity == null)
        {
            Debug.LogWarning("Unit component not found on prefab: " + definition.Name);
            return(null);
        }

        entity.Init(owner, definition, isFromPlayersHand);
        return(entity);
    }
示例#7
0
    void Update()
    {
        foreach (var child in transform)
        {
            Destroy(((Transform)child).gameObject);
        }

        if (IsDrawingEnemyGrid)
        {
            CreateTerritoryGridForPlayer(SL.Get <GameModel>().EnemyPlayer);
        }

        if (IsDrawingFriendlyGrid)
        {
            CreateTerritoryGridForPlayer(SL.Get <GameModel>().MyPlayer);
        }

        if (IsDrawingMapGrid)
        {
            // Our snapping actually puts 0,0 in the middle of a grid square, so we need to make sure to
            // offset by half a cell on the start position!
            int startX = (int)((-_gridWidth / 2f) / Consts.GridCellWidth);
            int startZ = (int)((-_gridHeight / 2f) / Consts.GridCellHeight);

            int numWidths  = (int)(_gridWidth / Consts.GridCellWidth);
            int numHeights = (int)(_gridHeight / Consts.GridCellHeight);

            CreateGrid(startX, startZ, numWidths, numHeights);
        }
    }
    // Triggered when the card at this hand index was changed.
    private void onCardChanged(int index)
    {
        if (index == HandIndex)
        {
            var handState = SL.Get <GameModel>().MyPlayer.CardState.Hand;

            // EARLY OUT! //
            if (handState == null)
            {
                Debug.LogWarning("Hand is null");
                return;
            }

            // Destroy the old figurine.
            destroyFigurine();

            var data = handState[index];
            _figurine = createFigurineFromDefinition(data);
            if (_figurine != null)
            {
                _figurine.FigurinePlacedEvent.AddListener(onFigurinePlaced);
            }

            // Update if we have enough mana to use this figurine.
            onManaChanged();

            CardChangedEvent.Invoke();
        }
    }
 private void OnDisable()
 {
     if (SL.Exists && SL.Get <GameModel>() != null && SL.Get <GameModel>().MyPlayer.ManaChangedEvent != null)
     {
         SL.Get <GameModel>().MyPlayer.ManaChangedEvent.RemoveListener(onManaChanged);
     }
 }
 private void Awake()
 {
     if (SL.Get <GameModel>().MyPlayer.CardState != null)
     {
         SL.Get <GameModel>().MyPlayer.CardState.CardChangedEvent.AddListener(onCardChanged);
     }
 }
示例#11
0
        /// <summary>
        /// The method saves a highscore to the database.
        /// </summary>
        /// <param name="playerName">Name of the player who achieved the highscore</param>
        /// <param name="levelName">Name of the level on which the score was achieved</param>
        /// <param name="score">The score itself as an integer</param>
        public void SaveHighscore(string playerName, string levelName, int score)
        {
            var db = (DatabaseService)SL.Get(typeof(DatabaseService));

            db.AddHighScore(new Db.Util.Highscore {
                PlayerName = playerName, LevelName = levelName, Score = score
            });
        }
 private void OnDestroy()
 {
     // Might be a bad idea to try and access service locator on destroy.
     if (SL.Exists && SL.Get <GameModel>() != null && SL.Get <GameModel>().MyPlayer.CardState != null)
     {
         SL.Get <GameModel>().MyPlayer.CardState.CardChangedEvent.RemoveListener(onCardChanged);
     }
 }
示例#13
0
 private void onEventTriggered()
 {
     if (_prefabToSpawn != null)
     {
         var go = Utils.Instantiate(_prefabToSpawn, SL.Get <GameModel>().BoardRoot.transform);
         go.transform.position = transform.position;
         go.Init(_entity);
     }
 }
示例#14
0
    private IEnumerator RoundStarting()
    {
        yield return(SL.Get <FigurineTutorial>().StepTutorial());

        SL.Get <GameModel>().InitGame(TestFactory.GetDefaultEnemyDeck(), TestFactory.GetDefaultPlayerDeck());
        //_model.InitGame(GameSessionData.Instance.EnemyDeck, GameSessionData.Instance.PlayerDeck);

        SL.Get <GameModel>().GameStartedEvent.Invoke();
    }
 private void onManaChanged()
 {
     if (_figurine != null)
     {
         int  mana        = Mathf.FloorToInt(SL.Get <GameModel>().MyPlayer.Mana);
         bool canInteract = _figurine.Data.ManaCost <= mana;
         LockedGameObject.SetActive(!canInteract);
         _figurine.SetInteractable(canInteract);
     }
 }
示例#16
0
 public static PlaceObjectMode Instance()
 {
     if (instance == null)
     {
         instance = new PlaceObjectMode();
         manager  = SL.Get <GameManager>();
         control  = SL.Get <IVRControl>();
     }
     return(instance);
 }
示例#17
0
 public static TitleScreenMode Instance()
 {
     if (instance == null)
     {
         instance = new TitleScreenMode();
         manager  = SL.Get <GameManager>();
         control  = SL.Get <IVRControl>();
         shared   = SL.Get <WorldBuilderMain>();
     }
     return(instance);
 }
示例#18
0
 public static AdventureTester Instance()
 {
     if (instance == null)
     {
         instance = new AdventureTester();
         manager  = SL.Get <GameManager>();
         control  = SL.Get <IVRControl>();
         shared   = SL.Get <WorldBuilderMain>();
     }
     return(instance);
 }
示例#19
0
 public static WorldBuilderMain Instance()
 {
     if (instance == null)
     {
         instance = new WorldBuilderMain();
         manager  = SL.Get <GameManager>();
         control  = SL.Get <IVRControl>();
         SL.Add <WorldBuilderMain>(instance);
     }
     return(instance);
 }
示例#20
0
 public static PoserMode Instance()
 {
     if (instance == null)
     {
         instance    = new PoserMode();
         manager     = SL.Get <GameManager>();
         control     = SL.Get <IVRControl>();
         poserWidget = manager.poserWidget;
     }
     return(instance);
 }
示例#21
0
 public static ModeExample Instance()
 {
     if (instance == null)
     {
         instance = new ModeExample();
         manager  = SL.Get <GameManager>();
         control  = SL.Get <IVRControl>();
         shared   = SL.Get <WorldBuilderMain>();
     }
     return(instance);
 }
示例#22
0
 public static KeyboardMode Instance()
 {
     if (instance == null)
     {
         instance = new KeyboardMode();
         manager  = SL.Get <GameManager>();
         control  = SL.Get <IVRControl>();
         shared   = SL.Get <WorldBuilderMain>();
         keyboard = SL.Get <Keyboard>();
     }
     return(instance);
 }
示例#23
0
    private void initBuildings()
    {
        // EARLY OUT! //
        if (TopOutpost == null || HQ == null || BottomOutpost == null)
        {
            return;
        }

        TopOutpost.Init(this, SL.Get <Config>().GetCardByName("Outpost"), false);
        BottomOutpost.Init(this, SL.Get <Config>().GetCardByName("Outpost"), false);
        HQ.Init(this, SL.Get <Config>().GetCardByName("HQ"), false);
    }
示例#24
0
    /// <summary>
    /// Change the card's artwork and attributes to match the given definition.
    /// </summary>
    public void Init(CardData definition)
    {
        // EARLY OUT! //
        if (definition == null || _image == null || _manaText == null)
        {
            return;
        }

        Definition = definition;

        _manaText.text = definition.ManaCost.ToString();
        _image.sprite  = SL.Get <ResourceManager>().Load <Sprite>(Consts.ImagePath + definition.CardImageName);
    }
示例#25
0
    private void onInit()
    {
        var card = SL.Get <Config>().GetCardByName(_entityToSpawn);

        if (card != null)
        {
            card.SpawnChargeSeconds = 0;
            var unit = Entity.SpawnFromDefinition(_entity.Owner, card, transform.position.ZeroY(), isFromPlayersHand: false);
            _entity.Owner.RotateForPlayer(unit.gameObject);
        }

        Destroy(gameObject);
    }
示例#26
0
 public void Begin()
 {
     if (Selection != null && Selection.IsDeckComplete())
     {
         var deck = Selection.GetDeckList();
         SL.Get <GameSessionData>().PlayerDeck = deck;
         SL.Get <GameSessionData>().EnemyDeck  = TestFactory.GetDefaultEnemyDeck();
         SceneManager.LoadScene("ClashScene");
     }
     else
     {
         // TODO: Tell the player to select the right number of cards.
     }
 }
示例#27
0
    void Update()
    {
        if (SL.Get <GameModel>().IsPlaying)
        {
            float previousMana  = Mana;
            float unclampedMana = Mana + Consts.ManaRechargePerSecond * Time.deltaTime;
            Mana = Mathf.Clamp(unclampedMana, 0f, Consts.MaxMana);

            if (Mathf.FloorToInt(previousMana) != Mathf.FloorToInt(Mana))
            {
                ManaChangedEvent.Invoke();
            }
        }
    }
示例#28
0
    //-------------------------------------------------
    // Called when this GameObject is detached from the hand
    //-------------------------------------------------
    private void OnDetachedFromHand(Hand hand)
    {
        if (hand != null)
        {
            if (_snapper != null)
            {
                _snapper.GridSquareChangedEvent.RemoveListener(onFigurineGridSquareChanged);
                _snapper.enabled = false;
            }

            SL.Get <TerritoryUI>().Hide();
            SL.Get <GridSquareHighlight>().gameObject.SetActive(false);
        }
    }
示例#29
0
 /// <summary>
 /// Helper to rotate a model in the opposite player's direction.  Asumming facing down to start.
 /// </summary>
 public void RotateForPlayer(GameObject go)
 {
     if (go != null)
     {
         if (this == SL.Get <GameModel>().LeftPlayer)
         {
             go.transform.rotation = Quaternion.Euler(0f, -90f, 0f);
         }
         else
         {
             go.transform.rotation = Quaternion.Euler(0f, 90f, 0f);
         }
     }
 }
示例#30
0
    void Update()
    {
        if (SL.Get <GameModel>().IsPlaying)
        {
            _slider.Value = SL.Get <GameModel>().MyPlayer.Mana / Consts.MaxMana;
            int mana = Mathf.FloorToInt(SL.Get <GameModel>().MyPlayer.Mana);

            if (_lastUpdatedMana != mana)
            {
                _countText.text  = mana.ToString();
                _lastUpdatedMana = mana;
            }
        }
    }