Beispiel #1
0
    public void SelectEntity(GridEntity gridEntity)
    {
        if (selectedBoardFightCreature != null)
        {
            // The currently selected fight creature will be unselected
            selectedFightCreatureMoveSet.Clear();
            UnselectSelectedFightCreature();
        }

        if (gridEntity != null)
        {
            if (gridEntity is FightCreature)
            {
                selectedBoardFightCreature = gridEntity as FightCreature;
                GlobalGameManager.Instance.fightPanels.OnSelectedBoardEntity(selectedBoardFightCreature);
                ProcessSelectedCreature();
            }
            else
            {
                Debug.LogWarning("Warning: entity of type " + gridEntity + " selected but only FightCreature supported by FightManager");
            }
        }
        else
        {
        }
    }
Beispiel #2
0
 public void OnSelectedBoardEntity(FightCreature fightCreature)
 {
     selectedCardDescription.gameObject.SetActive(true);
     currentlyShownFightCreature = fightCreature;
     selectedCardImage.sprite    = fightCreature.card.cardDefinition.sprite;
     UpdateSelectedCardDescription();
 }
Beispiel #3
0
    public void FireProjectile(Card owner, FightCreature caster, GridSpot target, Action onHit, Action onEnd)
    {
        ProjectileFeedback newProjectile = Instantiate(projectileModel, projectileModel.transform.parent).GetComponent <ProjectileFeedback>();

        newProjectile.gameObject.SetActive(true);
        newProjectile.FireProjectile(owner, caster, target, onHit, onEnd);
    }
Beispiel #4
0
    public void SpawnCreature(Card creatureCard, bool ally, GridSpot initialSpot = null)
    {
        if (creatureCard.cardDefinition.cardCategory != CardCategory.Creature)
        {
            Debug.LogError("Error: trying to spawn " + creatureCard.cardDefinition.cardType + " but it's not a creature.");
            return;
        }

        GridSpot spawnSpot = initialSpot;
        int remainingTries = 20;
        while ((spawnSpot == null || !creatureCard.IsValidTarget(spawnSpot)) && remainingTries > 0)
        {
            int x = UnityEngine.Random.Range(0, PlayGrid.size);
            int y = UnityEngine.Random.Range(0, PlayGrid.size);
            spawnSpot = grid.GetSpot(x, y);
            remainingTries--;
        }
        if (spawnSpot != null)
        {
            FightCreature newCreature = grid.SpawnFightCreature(creatureCard, spawnSpot, ally);
            if (ally)
            {
                allyCreatures.Add(newCreature);
            }
            else
            {
                enemyCreatures.Add(newCreature);
            }
        }
    }
Beispiel #5
0
        public FightWorld(Land land, Vector2 landPosition, Creature humanFightCreature, Creature AIFightCreature)
        {
            this.land = land;
            this.landPosition = landPosition;

            humanFighter = humanFightCreature.createFightCreature(this);
            humanFighter.position.X = -300f;
            PlayerManager.getPlayer("player1").addControlable(humanFighter);
            AIFighter = AIFightCreature.createFightCreature(this);
            AIFighter.position.X = 300f;

            floorLevel = 0f;

            //ground
            Dummy dum = new Dummy(this, "whiteSquare");
            dum.texture.filter = Color.Brown;
            dum.texture.size = new Vector2(1000f, 500f);
            dum.position.Y = 300f;

            //sky
            dum = new Dummy(this, "whiteSquare");
            dum.texture.filter = Color.SkyBlue;
            dum.texture.size = new Vector2(1000f, 600f);
            dum.position.Y = -250f;
        }
Beispiel #6
0
    public void FireProjectile(Card owner, FightCreature caster, GridSpot target, Action onHit, Action onEnd)
    {
        onHitAction = onHit;
        onEndAction = onEnd;

        InitElements(owner.cardDefinition.cardType);
        transform.position   = caster.transform.position;
        transform.localScale = Vector3.one * 0.0001f;

        startDate           = Time.time;
        startLocalPosition  = transform.localPosition;
        targetLocalPosition = transform.parent.InverseTransformPoint(target.transform.position);
    }
Beispiel #7
0
 public FightCreature GetClosestOpponentCreature(FightCreature attacker)
 {
     List<FightCreature> opponents = attacker.isAlly ? enemyCreatures : allyCreatures;
     float bestSqrDist = float.PositiveInfinity;
     FightCreature bestCandidate = null;
     for (int i = 0; i < opponents.Count; i++)
     {
         float sqrDist = (opponents[i].transform.position - attacker.transform.position).sqrMagnitude;
         if (sqrDist < bestSqrDist)
         {
             bestSqrDist = sqrDist;
             bestCandidate = opponents[i];
         }
     }
     return bestCandidate;
 }
Beispiel #8
0
 public bool TryAndMoveAI(PlayGrid.MoveSet moveSet)
 {
     if (turnRemainingMoves > 0)
     {
         FightCreature target = FightManager.instance.GetClosestOpponentCreature(this);
         if (target != null)
         {
             GridSpot destination = moveSet.GetClosestSpot(target.currentGridSpot, turnRemainingMoves);
             if (destination != currentGridSpot)
             {
                 GoTo(destination, moveSet);
                 return true;
             }
         }
     }
     return false;
 }
Beispiel #9
0
    public void OnDeadCreature(FightCreature creature)
    {
        if (creature == selectedBoardFightCreature)
        {
            UnselectSelectedFightCreature();
        }
        if (creature.isAlly)
        {
            int i = allyCreatures.IndexOf(creature);
            if (CurrentFightState == FightState.PlayerTurnResolution)
            {
                if (i <= currentStateElementIndex)
                    currentStateElementIndex--;
            }
            allyCreatures.RemoveAt(i);
            if (creature.isMC)
            {
                CurrentFightState = FightState.GameOverScreen;
            }
        }
        else
        {
            int i = enemyCreatures.IndexOf(creature);
            if (CurrentFightState == FightState.EnemyTurnMove ||
                CurrentFightState == FightState.EnemyTurnResolution)
            {
                if (i <= currentStateElementIndex)
                    currentStateElementIndex--;
            }

            //GlobalGameManager.Instance.CoinsAmount += creature.coinsGain;
            creature.ReapReward();

            enemyCreatures.RemoveAt(i);
            if (enemyCreatures.Count == 0)
            {
                CurrentFightState = FightState.FightVictoryScreen;
            }
        }
        creature.currentGridSpot.OnEntityLeave(creature);
        Destroy(creature.gameObject);
        UpdateGridVisuals();
    }
Beispiel #10
0
    // Start is called before the first frame update
    void Start()
    {
        spots = new GridSpot[size][];
        for (int i = 0; i < size; i++)
        {
            spots[i] = new GridSpot[size];
        }

        float canvasSize = GetComponent <RectTransform>().rect.width /*.sizeDelta.x*/ - margin;

        GridSpot spotModel = GetComponentInChildren <GridSpot>();

        float spotDefaultSize = spotModel.GetComponent <RectTransform>().sizeDelta.x;
        float spotScale       = canvasSize / (size * spotDefaultSize);

        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < size; j++)
            {
                GridSpot spot = spotModel;
                if (i > 0 || j > 0)
                {
                    spot = Instantiate(spotModel.gameObject, spotModel.transform.parent).GetComponent <GridSpot>();
                }
                spot.transform.localPosition = new Vector3(i + 0.5f - size / 2f, j + 0.5f - size / 2f, 0f) * canvasSize / size;
                spot.transform.localScale    = Vector3.one * spotScale;
                spots[i][j] = spot;
                spot.Init(i, j);
            }
        }

        fightCreatureModel = GetComponentInChildren <FightCreature>();
        fightCreatureModel.transform.localScale = Vector3.one * spotScale;
        fightCreatureModel.gameObject.SetActive(false);

        gridCardUIModel = GetComponentInChildren <GridCardUI>();
        gridCardUIModel.transform.localScale = Vector3.one * spotScale;
        gridCardUIModel.gameObject.SetActive(false);

        gridFeedbackManager.transform.localScale = Vector3.one * spotScale;
    }
Beispiel #11
0
 public FightCreature SpawnFightCreature(Card creatureCard, GridSpot spot, bool ally)
 {
     if (spot.IsFree())
     {
         GameObject newFightCreatureObject = Instantiate(fightCreatureModel.gameObject, fightCreatureModel.transform.parent);
         newFightCreatureObject.SetActive(true);
         FightCreature result = newFightCreatureObject.GetComponent <FightCreature>();
         result.Init(creatureCard, spot, ally);
         newFightCreatureObject.transform.localPosition = spot.transform.localPosition;
         spot.OnEntityEnters(result);
         if (creatureCard.cardDefinition.cardType == CardDefinitionType.MC)
         {
             mc = result;
         }
         return(result);
     }
     else
     {
         Debug.LogWarning("Trying to spawn fight creature on taken spot.");
         return(null);
     }
 }
Beispiel #12
0
 void OnNewGameState(GlobalGameManager.GameState previousGameState, GlobalGameManager.GameState newGameState)
 {
     gameObject.SetActive(newGameState == GlobalGameManager.GameState.Fight);
     selectedCardDescription.gameObject.SetActive(false);
     currentlyShownFightCreature = null;
 }
Beispiel #13
0
 void UnselectSelectedFightCreature()
 {
     selectedBoardFightCreature = null;
     GlobalGameManager.Instance.fightPanels.OnUnselectedBoardEntity();
     selectedFightCreatureMoveSet.Clear();
 }