Beispiel #1
0
        public EntityScriptableObject GenerateRandomCard(List <EntityScriptableObject> pool)
        {
            CardRarity rarity; // Default to common rarity
            float      rand = UnityEngine.Random.Range(0.0f, 1.0f);

            if (rand <= OfferingChances.legendary && pool.FindAll(c => VEntityComponentSystemManager.GetVComponent <CardRarityComponent>(c.entity).cardRarity == CardRarity.LEGENDARY).Count > 0)
            {
                rarity = CardRarity.LEGENDARY;
            }
            else if (rand <= OfferingChances.legendary + OfferingChances.rare && pool.FindAll(c => VEntityComponentSystemManager.GetVComponent <CardRarityComponent>(c.entity).cardRarity == CardRarity.RARE).Count > 0)
            {
                rarity = CardRarity.RARE;
            }
            else
            {
                rarity = CardRarity.COMMON;
            }

            var matchingCards = pool.FindAll(c => VEntityComponentSystemManager.GetVComponent <CardRarityComponent>(c.entity).cardRarity == rarity);

            if (matchingCards.Count == 0)
            {
                return(null);
            }

            EntityScriptableObject card = matchingCards[UnityEngine.Random.Range(0, matchingCards.Count)];

            matchingCards.Remove(card);
            return(card);
        }
Beispiel #2
0
        protected override void OnExecuteEvent(VEntity entity)
        {
            CardZoneMoveEvent     eventity = VEntityComponentSystemManager.GetVComponent <CardZoneMoveEvent>(entity);
            CardZoneDataComponent comp     = ecsManager.GetVSingletonComponent <CardZoneDataComponent>();

            if (eventity.source != Zone.NULL)
            {
                //Assert.IsTrue(comp.zones[eventity.source].Contains(eventity.card));
                if (!comp.zones[eventity.source].Contains(eventity.card))
                {
                    return; //HACK
                }
                comp.zones[eventity.source].Remove(eventity.card);
                comp.zones[eventity.destination].Add(eventity.card);
            }
            else
            {
                comp.zones[eventity.destination].Add(eventity.card);
            }

            ecsManager.QueueAnimationEvent(ecsManager.CreateEntity("CardMovementAnimation", component: new CardZoneMoveEvent {
                source      = eventity.source,
                destination = eventity.destination,
                card        = eventity.card
            }));
        }
Beispiel #3
0
        public void InitializeFields(VEntity cardTemplate)
        {
            if (cardTemplate == null)
            {
                return;
            }
            this.cardTemplate = cardTemplate;
            cardBacks         = new Dictionary <CardType, GameObject>();
            cardBacks.Add(CardType.NEUTRAL, neutralQuad);
            cardBacks.Add(CardType.ORION, orionQuad);
            cardBacks.Add(CardType.OPHELIA, opheliaQuad);
            foreach (CardType t in cardBacks.Keys)
            {
                cardBacks[t].SetActive(false);
            }

            cost   = VEntityComponentSystemManager.GetVComponent <ManaCostComponent>(cardTemplate).cost;
            effect = VEntityComponentSystemManager.GetVComponent <EffectTextComponent>(cardTemplate).effect;
            CardType cardType = VEntityComponentSystemManager.GetVComponent <CardClassComponent>(cardTemplate).cardType;

            nameText.text   = VEntityComponentSystemManager.GetVComponent <CardNameComponent>(cardTemplate).name;
            costText.text   = cost.ToString();
            effectText.text = effect;
            classText.text  = StringUtils.ClassEnumToString(cardType);
            cardBacks[cardType].SetActive(true);
        }
Beispiel #4
0
        protected override void OnExecuteEvent(VEntity entity)
        {
            MovementEvent       moveEvent           = VEntityComponentSystemManager.GetVComponent <MovementEvent>(entity);
            PositionTrackSystem positionTrackSystem = ecsManager.GetSystem <PositionTrackSystem>();

            // check to make sure that the square is unoccupied
            bool isUnoccupied = true;

            foreach (VEntity v in positionTrackSystem.GetAtCoord(moveEvent.targetCoord))
            {
                if (VEntityComponentSystemManager.HasVComponent <MovementBlockComponent>(v))
                {
                    isUnoccupied = false;
                }
            }

            if (isUnoccupied)
            {
                PositionComponent movedPosition = ecsManager.GetVComponent <PositionComponent>(moveEvent.sourceId);
                Coord             prevPosition  = movedPosition.position;
                movedPosition.position = moveEvent.targetCoord;
                positionTrackSystem.Update(movedPosition.position, moveEvent.sourceId);

                ecsManager.QueueAnimationEvent(ecsManager.CreateEntity("MoveAnim", component: new MovementAnimationEvent {
                    entityToMove = moveEvent.sourceId,
                    from         = prevPosition,
                    to           = moveEvent.targetCoord
                }));
            }
        }
        protected override void OnExecuteEvent(VEntity entity)
        {
            LowLevelDealDamageEvent damageEvent = entity.GetVComponent <LowLevelDealDamageEvent>();

            if (damageEvent.damageAmount <= 0)
            {
                return;
            }

            VEntity         damageDealtEntity = ecsManager.GetVEntityById(damageEvent.receiverId);
            HealthComponent h = VEntityComponentSystemManager.GetVComponent <HealthComponent>(damageDealtEntity);

            h.currHealth -= damageEvent.damageAmount;

            if (h.currHealth <= 0)
            {
                h.currHealth = 0;
                ecsManager.CreateEvent("unitDeath", component: new DeathEventComponent {
                    id = damageDealtEntity.id
                });
            }

            ecsManager.QueueAnimationEvent("setHealth", components: new VComponent[] {
                new HealthSetAnimationEvent {
                    targetEntity = damageDealtEntity.id,
                    currHealth   = h.currHealth,
                    maxHealth    = h.maxHealth
                },
                new UnitDamagedAnimationEvent {
                    targetEntity = damageDealtEntity.id
                }
            });
        }
Beispiel #6
0
        protected override void OnExecuteEvent(VEntity entity)
        {
            var     createEvent   = VEntityComponentSystemManager.GetVComponent <CreateTerrainCellEvent>(entity);
            VEntity newCellEntity = ecsManager.CreateEntity("Cell", components: new List <VComponent> {
                new PositionComponent {
                    position = createEvent.coord
                },
                new TerrainCellComponent {
                    movementCost = createEvent.movementCost, cellType = createEvent.cellType
                },
                new TerrainCellDisplayComponent {
                    cellDisplay = VCellDisplay.Instantiate(cellDisplayPrefab),
                    cellType    = createEvent.cellType
                }
            });

            VEntityComponentSystemManager.GetVComponent <TerrainCellDisplayComponent>(newCellEntity).cellDisplay.gameObject.SetActive(false);
            ecsManager.GetVSingletonComponent <CellsListComponent>().cellIds.Add(newCellEntity.id);
            ecsManager.GetSystem <PositionTrackSystem>().Track(newCellEntity);

            VEntity cellCreationAnimationEntity = ecsManager.CreateEntity(prefix: "CellCreationAnimation", component: new TerrainCellDisplayAppearEvent {
                coord = createEvent.coord,
                terrainCellEntityId = newCellEntity.id
            });

            ecsManager.QueueAnimationEvent(cellCreationAnimationEntity);
        }
        protected override void OnExecuteEvent(VEntity entity)
        {
            DeathEventComponent ecDeath     = VEntityComponentSystemManager.GetVComponent <DeathEventComponent>(entity);
            VEntity             dyingEntity = ecsManager.GetVEntityById(ecDeath.id);

            if (dyingEntity != null)
            {
                HealthComponent h = dyingEntity.GetVComponent <HealthComponent>();
                if (h != null && h.currHealth > 0)
                {
                    return;
                }

                ecsManager.MarkRemovalEntity(dyingEntity);

                // remove the entity from all relevant things
                UnitsList unitsList = ecsManager.GetVSingletonComponent <UnitsList>();
                unitsList.unitIds.Remove(dyingEntity.id);
                PositionTrackSystem positionTrackSystem = ecsManager.GetSystem <PositionTrackSystem>();
                positionTrackSystem.Untrack(dyingEntity.id);

                ecsManager.QueueAnimationEvent("DeathAnimation", component: new DeathAnimationEvent {
                    deathTransform = dyingEntity.GetVComponent <PositionDisplayComponent>().mainTransform,
                    dyingEntityId  = dyingEntity.id
                });
            }
        }
Beispiel #8
0
 protected override void OnExecuteEvent(VEntity entity)
 {
     if (VEntityComponentSystemManager.GetVComponent <SetLifecycleEventComponent>(entity).newVLifecycle == VLifecycle.EnemySetupStart)
     {
         var turnCounter = ecsManager.GetVSingletonComponent <TurnCounterComponent>();
         turnCounter.turnCounter += 1;
     }
 }
 protected override void OnBeforeEvent(VEntity entity)
 {
     if (VEntityComponentSystemManager.GetVComponent <SetLifecycleEventComponent>(entity).newVLifecycle == VLifecycle.PlayerTurnStart)
     {
         CardZoneDataComponent cardZoneData = ecsManager.GetVSingletonComponent <CardZoneDataComponent>();
         ecsManager.ExecuteImmediateEvent("discardCards", component: new CardDiscardEvent {
             cardIds = cardZoneData.zones[Zone.HAND].ToArray()
         });
     }
 }
Beispiel #10
0
        protected override void OnExecuteEvent(VEntity entity)
        {
            CardCreateEvent eventity = VEntityComponentSystemManager.GetVComponent <CardCreateEvent>(entity);
            VEntity         newCard  = ecsManager.InsantiateEntityFromBlueprint(eventity.blueprintCard);

            ecsManager.CreateEvent("CardMove", component: new CardZoneMoveEvent {
                source      = Zone.NULL,
                destination = eventity.destination,
                card        = newCard.id
            });
        }
Beispiel #11
0
        public void Track(VEntity e)
        {
            var positionComponent = VEntityComponentSystemManager.GetVComponent <PositionComponent>(e);
            var positionDisplay   = VEntityComponentSystemManager.GetVComponent <PositionDisplayComponent>(e);

            if (positionDisplay != null)
            {
                positionDisplay.mainTransform          = new GameObject("mainTransform").transform;
                positionDisplay.mainTransform.position = ecsManager.GetSystem <PositionWorldConversionSystem>().GetTransformFromCoord(positionComponent.position);
            }
            Insert(positionComponent.position, e.id);
        }
        public override void DoImmediateAnimation(VEntity entity)
        {
            TerrainCellDisplayAppearEvent appearEvent       = VEntityComponentSystemManager.GetVComponent <TerrainCellDisplayAppearEvent>(entity);
            PositionComponent             positionComponent = ecsManager.GetVComponent <PositionComponent>(appearEvent.terrainCellEntityId);
            TerrainCellDisplayComponent   displayComponent  = ecsManager.GetVComponent <TerrainCellDisplayComponent>(appearEvent.terrainCellEntityId);

            displayComponent.cellDisplay.SetCellId(appearEvent.terrainCellEntityId);
            displayComponent.cellDisplay.SetCellType(displayComponent.cellType);
            displayComponent.cellDisplay.SetState(VCellSelectedState.NORMAL);
            displayComponent.cellDisplay.ResizeSprite(ecsManager.GetSystem <PositionWorldConversionSystem>().SquareDimensions);
            displayComponent.cellDisplay.transform.position = ecsManager.GetSystem <PositionWorldConversionSystem>().GetTransformFromCoord(positionComponent.position);
            displayComponent.cellDisplay.gameObject.SetActive(true);

            displayComponent.cellDisplay.CellHovered += this.OnCellHover;
        }
Beispiel #13
0
        // Start is called before the first frame update
        void Start()
        {
            List <EntityScriptableObject> opheliaPool = AllCards.Cards.FindAll(c => VEntityComponentSystemManager.GetVComponent <CardClassComponent>(c.entity).cardType == CardType.OPHELIA || VEntityComponentSystemManager.GetVComponent <CardClassComponent>(c.entity).cardType == CardType.NEUTRAL);

            foreach (Transform child in transform.Find("OpheliaCards"))
            {
                child.gameObject.GetComponent <MetaCardGameObject>().InitializeFields(GenerateRandomCard(opheliaPool).entity);
            }
            List <EntityScriptableObject> orionPool = AllCards.Cards.FindAll(c => VEntityComponentSystemManager.GetVComponent <CardClassComponent>(c.entity).cardType == CardType.ORION || VEntityComponentSystemManager.GetVComponent <CardClassComponent>(c.entity).cardType == CardType.NEUTRAL);

            foreach (Transform child in transform.Find("OrionCards"))
            {
                child.gameObject.GetComponent <MetaCardGameObject>().InitializeFields(GenerateRandomCard(orionPool).entity);
            }
        }
Beispiel #14
0
        protected override void OnExecuteEvent(VEntity entity)
        {
            PushEventComponent pushComponent = VEntityComponentSystemManager.GetVComponent <PushEventComponent>(entity);

            foreach (VEntity enemyEntity in ecsManager.FilterEntities(test: (ventity) => {
                return(ventity.HasVComponent <TeamComponent>() && ventity.HasVComponent <PositionComponent>() && ventity.GetVComponent <TeamComponent>().team == Team.ENEMY);
            }))
            {
                PositionComponent currPosition = enemyEntity.GetVComponent <PositionComponent>();
                ecsManager.CreateEvent("wind", component: new MovementEvent {
                    sourceId    = enemyEntity.id,
                    targetCoord = currPosition.position + Coord.Rotate(new Coord(pushComponent.squares, 0), pushComponent.dir)
                });
            }
        }
Beispiel #15
0
        protected override void OnExecuteEvent(VEntity entity)
        {
            var unitCreateEvent = VEntityComponentSystemManager.GetVComponent <UnitCreateEvent>(entity);
            var newUnitEntity   = ecsManager.InsantiateEntityFromBlueprint(unitCreateEvent.entityBlueprint);

            // TODO: replace with object pool
            VEntityComponentSystemManager.GetVComponent <UnitDisplayComponent>(newUnitEntity).unitDisplayGameObject = VUnitDisplay.Instantiate(unitDisplayPrefab);
            VEntityComponentSystemManager.GetVComponent <UnitDisplayComponent>(newUnitEntity).unitDisplayGameObject.gameObject.SetActive(false);
            VEntityComponentSystemManager.GetVComponent <PositionComponent>(newUnitEntity).position = unitCreateEvent.position;
            ecsManager.GetSystem <PositionTrackSystem>().Track(newUnitEntity);
            ecsManager.GetVSingletonComponent <UnitsList>().unitIds.Add(newUnitEntity.id);

            ecsManager.QueueAnimationEvent(ecsManager.CreateEntity("UnitAppear", component: new EntityAppearEvent {
                entityId = newUnitEntity.id
            }));
        }
Beispiel #16
0
        protected override void OnExecuteEvent(VEntity entity)
        {
            DamageEffectEventComponent damageComponent = VEntityComponentSystemManager.GetVComponent <DamageEffectEventComponent>(entity);
            VEntity damageDealingEnitty = ecsManager.GetVEntityById(damageComponent.sourceId);

            foreach (Coord c in damageComponent.groupTargetCoords)
            {
                VEntity damageDealtEntity = ecsManager.GetSystem <UnitFinderSystem>().GetUnitAtCoord(c);
                if (damageDealtEntity != null && damageDealtEntity.GetVComponent <TeamComponent>().team != damageDealingEnitty.GetVComponent <TeamComponent>().team)
                {
                    ecsManager.ExecuteImmediateEvent("lowLevelDamageEvent", component: new LowLevelDealDamageEvent {
                        damageAmount = damageComponent.damageAmount,
                        sourceId     = damageComponent.sourceId,
                        receiverId   = damageDealtEntity.id
                    });
                }
            }
        }
Beispiel #17
0
        public override IEnumerator StartAnimation(VEntity entity, Action yieldAnimation)
        {
            EntityAppearEvent appearEvent = VEntityComponentSystemManager.GetVComponent <EntityAppearEvent>(entity);
            var unitEntity = ecsManager.GetVEntityById(appearEvent.entityId);

            var unitDisplay = VEntityComponentSystemManager.GetVComponent <UnitDisplayComponent>(unitEntity);

            VEntityComponentSystemManager.GetVComponent <UnitDisplayComponent>(unitEntity).unitDisplayGameObject.gameObject.SetActive(true);
            unitDisplay.unitDisplayGameObject.transform.position = unitEntity.GetVComponent <PositionDisplayComponent>().mainTransform.position;
            unitDisplay.spriteSize = ecsManager.GetSystem <PositionWorldConversionSystem>().SquareDimensions;
            unitDisplay.unitDisplayGameObject.BindEntity(unitEntity);

            unitDisplay.unitDisplayGameObject.ResizeSprite(unitDisplay.spriteSize);
            unitDisplay.getTransform().SetParent(unitEntity.GetVComponent <PositionDisplayComponent>().mainTransform);

            yield return(new WaitForSeconds(0.1f));

            yieldAnimation();
        }
Beispiel #18
0
        void FinishPlayingCard(CardGameObject card, Coord space, VEntity caster)
        {
            Debug.Log("Finish playing card");
            cardSelected.locked = false;
            cardSelected        = null;

            VEntity            cardPlayed = boardState.GetVEntityById(card.cardEntityId);
            TargetingComponent targeting  = VEntityComponentSystemManager.GetVComponent <TargetingComponent>(cardPlayed);
            Dictionary <CardEffectType, List <Coord> > mapping = new Dictionary <CardEffectType, List <Coord> >();

            foreach (GroupTargetingMethod m in targeting.groupTargetingMethods)
            {
                if (!mapping.ContainsKey(m.effectType))
                {
                    mapping[m.effectType] = new List <Coord>();
                }
                mapping[m.effectType].AddRange(m.SelectGroupCoords(space, caster.GetVComponent <PositionComponent>().position, boardState));
            }
            foreach (CardEffectType t in mapping.Keys)
            {
                Debug.Log("Type Key: " + t);
            }

            boardState.CreateEvent("playCard", component: new CardPlayEvent {
                cardId               = card.cardEntityId,
                targetSpace          = space,
                casterId             = caster.id,
                groupTargetingSpaces = mapping
            });

            if (card.cantrip)
            {
                boardState.CreateEvent("cantripUsed", component: new CantripUseEvent
                {
                });
            }

            spaceSelected = Coord.nullCoord;
            State         = InputState.SELECTCARD;
            cardController.MyHandState = HandState.IDLE;
        }
        protected override void OnExecuteEvent(VEntity entity)
        {
            var currentTurn = ecsManager.GetVSingletonComponent <CurrentLifecycleComponent>();

            currentTurn.currentLifecycle = VEntityComponentSystemManager.GetVComponent <SetLifecycleEventComponent>(entity).newVLifecycle;

            if (currentTurn.currentLifecycle != VLifecycle.PlayerTurnExecute)
            {
                foreach (VEntity e in new List <VEntity>(ecsManager.GetAllEntities()))
                {
                    foreach (VSystem system in ecsManager.GetAllSystems())
                    {
                        if (system.ShouldOperate(e))
                        {
                            system.OnLifecycle(e, currentTurn.currentLifecycle);
                        }

                        ecsManager.GetGameplayEventQueue().Flush();
                    }
                }
            }
        }
Beispiel #20
0
        protected override CellContent DrawElement(Rect rect, CellContent value)
        {
            EditorGUI.DrawRect(rect, Level.CellTypeToColor(value.cellStruct.cellType));

            if (value.unitData != null)
            {
                // Item count
                var countRect = rect.Padding(2).AlignBottom(16);
                EditorGUI.DrawRect(countRect, new Color(0.0f, 0.0f, 0.0f, 0.5f));
                GUI.Label(countRect, VEntityComponentSystemManager.GetVComponent <NameComponent>(value.unitData.entity).name, SirenixGUIStyles.CenteredGreyMiniLabel);
            }

            Texture texture = null;

            if (value.unitData != null && VEntityComponentSystemManager.HasVComponent <UnitDisplayComponent>(value.unitData.entity))
            {
                texture = GUIHelper.GetAssetThumbnail(VEntityComponentSystemManager.GetVComponent <UnitDisplayComponent>(value.unitData.entity).displaySprite, typeof(EntityScriptableObject), true);
            }

            value.unitData = (EntityScriptableObject)SirenixEditorFields.UnityPreviewObjectField(rect.Padding(16), value.unitData, texture, typeof(EntityScriptableObject));
            return(value);
        }
Beispiel #21
0
 public void BindEntity(VEntity entity)
 {
     SetSprite(VEntityComponentSystemManager.GetVComponent <UnitDisplayComponent>(entity).displaySprite);
 }
Beispiel #22
0
        protected override void OnEnemySetupStart(VEntity entity)
        {
            CellScoresComponent CellScoresComponent = ecsManager.GetVSingletonComponent <CellScoresComponent>();

            CellScoresComponent.cellScores = new Dictionary <Coord, int>();
            CellsListComponent       cellsList        = ecsManager.GetVSingletonComponent <CellsListComponent>();
            List <PositionComponent> positions        = ecsManager.GetVComponentsFromList <PositionComponent>(cellsList.cellIds);
            TerrainCellFinderSystem  cellFinderSystem = ecsManager.GetSystem <TerrainCellFinderSystem>();

            foreach (PositionComponent p in positions)
            {
                CellScoresComponent.cellScores.Add(p.position, 0);
            }

            // generically gets all entities that are targetable by the AI, has a position component, and ripples the scores the their positions.
            List <VEntity> enemyTargets = ecsManager.FilterEntities(test: (ventity) => {
                return(VEntityComponentSystemManager.HasVComponent <EnemyTargetComponent>(ventity) && VEntityComponentSystemManager.HasVComponent <PositionComponent>(ventity));
            });

            foreach (VEntity targetEntity in enemyTargets)
            {
                PositionComponent targetComponent = targetEntity.GetVComponent <PositionComponent>();
                RippleScores(targetComponent.position, 5, CellScoresComponent.cellScores);
            }

            List <VEntity> enemies = ecsManager.GetSystem <UnitFinderSystem>().GetAllEnemyUnits().ToList();

            foreach (VEntity enemy in enemies)
            {
                var availableDestinations = ecsManager.GetSystem <PathingSystem>().GetAvailableDestinations(VEntityComponentSystemManager.GetVComponent <PositionComponent>(enemy).position, 5);

                var moveScores = new Dictionary <Coord, int>();
                foreach (Coord cell in availableDestinations.Keys)
                {
                    int s = 0;
                    foreach (Coord neighbor in cell.GetSurroundingCoords(true, false).FindAll(c => cellFinderSystem.IsValidCell(c)))
                    {
                        s += CellScoresComponent.cellScores[neighbor];
                    }
                    moveScores.Add(cell, s);
                }

                var sortedMoveScore = moveScores.OrderByDescending(x => x.Value);

                // destination cell is where the unit is going to move to, defaulting to its original position
                Coord destinationCell = VEntityComponentSystemManager.GetVComponent <PositionComponent>(enemy).position;
                if (sortedMoveScore.Count() == 1)
                {
                    destinationCell = sortedMoveScore.First().Key;
                }
                else if (sortedMoveScore.Count() > 1)
                {
                    // randomly choose between the top two choices if there are more than 1
                    destinationCell = sortedMoveScore.ElementAt(Random.Range(0, 2)).Key;
                }
                ecsManager.ExecuteImmediateEvent("EnemyMove", component: new MovementEvent {
                    sourceId    = enemy.id,
                    targetCoord = destinationCell
                });

                ecsManager.ExecuteImmediateEvent("QueueAction", component: new QueueActionEvent {
                    entityId = enemy.id
                });
            }
        }
Beispiel #23
0
 public void AddToDeck()
 {
     Deck.Add(VEntityComponentSystemManager.GetVComponent <CardNameComponent>(transform.Find("OpheliaCards").GetComponent <ChooseSingleCard>().selectedCard).name);
     Deck.Add(VEntityComponentSystemManager.GetVComponent <CardNameComponent>(transform.Find("OrionCards").GetComponent <ChooseSingleCard>().selectedCard).name);
 }
Beispiel #24
0
 public T GetVComponent <T>() where T : VComponent
 {
     return(VEntityComponentSystemManager.GetVComponent <T>(this));
 }