public void AddComponents(VEntity entity, IEnumerable <VComponent> components)
 {
     foreach (VComponent component in components)
     {
         entity.Components.Add(component);
     }
 }
예제 #2
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);
        }
        // helper function for creating an entity that will be put on the event stack.
        public VEntity CreateEvent(string prefix, IList <VComponent> components = null, VComponent component = null)
        {
            VEntity ent = CreateEntity(prefix, components: components, component: component);

            StackEvent(ent);
            return(ent);
        }
        // helper function for creating an entity that will be put on the event stack.
        public VEntity ExecuteImmediateEvent(string prefix, IList <VComponent> components = null, VComponent component = null)
        {
            VEntity ent = CreateEntity(prefix, components: components, component: component);

            gameplayEventQueue.ImmediateExecute(ent);
            return(ent);
        }
        private void Init()
        {
            // initialize objects
            gameEntities       = new List <VEntity>();
            entitiesToDelete   = new HashSet <VEntity>();
            gameplayEventQueue = new GameplayEventQueue(this);

            // add self to systems
            foreach (VAnimationSystem aniSys in animationSystems)
            {
                aniSys.Init(this);
            }
            foreach (VSystem s in gameSystems)
            {
                s.Init(this);
            }

            // create special start game event
            VEntity startGameEvent = CreateEntity("StartGame");

            AddComponents(startGameEvent, new VComponent[] {
                new StartGameComponent()
            });
            gameplayEventQueue.Push(startGameEvent);
        }
예제 #6
0
파일: Block.cs 프로젝트: mdlandis/voidheart
        protected override void OnBeforeEvent(VEntity entity)
        {
            LowLevelDealDamageEvent dealDamage = entity.GetVComponent <LowLevelDealDamageEvent>();
            VEntity blockingEntity             = ecsManager.GetVEntityById(dealDamage.receiverId);

            BlockBuffComponent block = blockingEntity.GetVComponent <BlockBuffComponent>();

            if (block != null)
            {
                int blockDeduct = Math.Min(block.blockAmount, dealDamage.damageAmount);

                block.blockAmount       -= blockDeduct;
                dealDamage.damageAmount -= blockDeduct;

                if (blockingEntity.HasVComponent <BlockDisplayComponent>())
                {
                    int newBlockAmount = block.blockAmount;
                    NumberedIconDisplay blockDisplay = blockingEntity.GetVComponent <BlockDisplayComponent>().blockDisplay;
                    ecsManager.QueueAnimationEvent("blockRemoveEvent", component: new GenericBlockingAnimationEvent {
                        a = (passedEcsManager) => {
                            blockDisplay.transform.DOShakePosition(.5f, .1f);
                            blockDisplay.SetValue(newBlockAmount);
                        },
                        duration = 0.5f
                    });
                }
            }
        }
예제 #7
0
        public bool Dequeue()
        {
            bool isImmediate = true;

            currentAnimationEntity = animationEventsQueue.RemoveFront();
            foreach (VAnimationSystem aniSys in game.GetAllAnimationSystems())
            {
                if (aniSys.ShouldOperate(currentAnimationEntity) && !aniSys.IsImmediate())
                {
                    awaited++;
                    isImmediate = false;
                }
            }

            foreach (VAnimationSystem aniSys in game.GetAllAnimationSystems())
            {
                if (aniSys.ShouldOperate(currentAnimationEntity))
                {
                    if (aniSys.IsImmediate())
                    {
                        aniSys.DoImmediateAnimation(currentAnimationEntity);
                    }
                    else
                    {
                        StartCoroutine(aniSys.StartAnimation(currentAnimationEntity, YieldAnimation));
                    }
                }
            }

            return(isImmediate);
        }
예제 #8
0
        private void ProcessCoord(VEntity character, Coord coord, TargetingComponent cardTargeter)
        {
            //Outline cell c (by toggling each edge).
            ecsManager.GetAnimationSystem <HighlightDisplaySystem>().CreateGreyHighlightWithTags(new Coord[] {
                coord
            }, new string[] {
                "Outline"
            });
            bool passes = true;

            foreach (ValidTargetingMethod validTargetingMethod in cardTargeter.validTargetingMethods)
            {
                if (!validTargetingMethod.ValidateCoord(coord, ecsManager))
                {
                    passes = false;
                }
            }
            if (passes)
            {
                GetList(targetingSpaces, character.id).Add(coord);
                //Highlight the cell according to validTargetingMethod.effectType. Tag it with ValidSpace
                ecsManager.GetAnimationSystem <HighlightDisplaySystem>().CreateHighlightsWithTags(new List <Coord> {
                    coord
                }, new List <string> {
                    "ValidSpace"
                }, ecsManager.GetAnimationSystem <HighlightDisplaySystem>().lightGreenColor);
            }
        }
예제 #9
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);
        }
예제 #10
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
                }));
            }
        }
예제 #11
0
        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
                }
            });
        }
예제 #12
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
            }));
        }
예제 #13
0
        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
                });
            }
        }
예제 #14
0
        public CardGameObject InitCard(VEntity e)
        {
            CardGameObject newCard = Instantiate <CardGameObject>(cardPrefab);

            newCard.InitializeFromEntity(e);
            newCard.transform.parent = this.transform;
            return(newCard);
        }
예제 #15
0
 protected override void OnExecuteEvent(VEntity entity)
 {
     if (VEntityComponentSystemManager.GetVComponent <SetLifecycleEventComponent>(entity).newVLifecycle == VLifecycle.EnemySetupStart)
     {
         var turnCounter = ecsManager.GetVSingletonComponent <TurnCounterComponent>();
         turnCounter.turnCounter += 1;
     }
 }
예제 #16
0
        protected override void OnPlayerTurnStart(VEntity entity)
        {
            PlayerHandComponent playerHandComponent = entity.GetVComponent <PlayerHandComponent>();

            ecsManager.CreateEvent("StartTurnDraw", component: new CardDrawEvent {
                numCards = playerHandComponent.startTurnDrawCount
            });
        }
예제 #17
0
        public override IEnumerator StartAnimation(VEntity entity, Action yieldAnimation)
        {
            MovementAnimationEvent moveEvent = entity.GetVComponent <MovementAnimationEvent>();
            Tween myTween = ecsManager.GetVEntityById(moveEvent.entityToMove).GetVComponent <PositionDisplayComponent>().mainTransform.DOMove(ecsManager.GetSystem <PositionWorldConversionSystem>().GetTransformFromCoord(moveEvent.to), 0.5f);

            yield return(myTween.WaitForCompletion());

            yieldAnimation();
        }
예제 #18
0
        public override IEnumerator StartAnimation(VEntity entity, Action yieldAnimation)
        {
            GenericBlockingAnimationEvent genericAnim = entity.GetVComponent <GenericBlockingAnimationEvent>();

            genericAnim.a(ecsManager);
            yield return(new WaitForSeconds(genericAnim.duration));

            yieldAnimation();
        }
예제 #19
0
        public void YieldAnimation()
        {
            awaited--;

            if (awaited == 0 && currentAnimationEntity != null)
            {
                game.MarkRemovalEntity(currentAnimationEntity);
                currentAnimationEntity = null;
            }
        }
예제 #20
0
 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()
         });
     }
 }
예제 #21
0
        public bool IsPlayable(string cardId)
        {
            VEntity cardEntity = ecsManager.GetVEntityById(cardId);
            CardZoneDataComponent     cardZoneData  = ecsManager.GetVSingletonComponent <CardZoneDataComponent>();
            PlayerManaComponent       mana          = ecsManager.GetVSingletonComponent <PlayerManaComponent>();
            CurrentLifecycleComponent currLifecycle = ecsManager.GetVSingletonComponent <CurrentLifecycleComponent>();

            //HACK
            return(currLifecycle.currentLifecycle == VLifecycle.PlayerTurnExecute && (cardZoneData.zones[Zone.HAND].Contains(cardId) || (cardEntity.GetVComponent <CardNameComponent>().name == "Cantrip" && !ecsManager.GetSystem <CantripSystem>().cantripUsed)) && cardEntity.GetVComponent <ManaCostComponent>().cost <= mana.currMana);
        }
 public static T GetVComponent <T>(VEntity entity) where T : VComponent
 {
     foreach (VComponent comp in entity.Components)
     {
         if (comp is T)
         {
             return((T)comp);
         }
     }
     return(null);
 }
예제 #23
0
        public override bool ValidateCoord(Coord loc, VEntityComponentSystemManager boardState)
        {
            VEntity unit = boardState.GetSystem <UnitFinderSystem>().GetUnitAtCoord(loc);

            if (unit != null)
            {
                return(unit.GetVComponent <TeamComponent>().team == team);
            }

            return(false);
        }
예제 #24
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
            });
        }
예제 #25
0
        public override void DoImmediateAnimation(VEntity entity)
        {
            HealthSetAnimationEvent healthSetEvent = entity.GetVComponent <HealthSetAnimationEvent>();
            VEntity targetEntity = ecsManager.GetVEntityByIdIncludingRemoved(healthSetEvent.targetEntity);

            HealthDisplayComponent healthDisplay = targetEntity.GetVComponent <HealthDisplayComponent>();

            if (healthDisplay != null)
            {
                healthDisplay.healthBarDisplay.SetValue(healthSetEvent.currHealth);
            }
        }
예제 #26
0
        public override void DoImmediateAnimation(VEntity entity)
        {
            UnitDamagedAnimationEvent unitDamagedEvent = entity.GetVComponent <UnitDamagedAnimationEvent>();
            VEntity targetEntity = ecsManager.GetVEntityByIdIncludingRemoved(unitDamagedEvent.targetEntity);

            UnitDisplayComponent unitDisplay = targetEntity.GetVComponent <UnitDisplayComponent>();

            if (unitDisplay != null)
            {
                var tween = unitDisplay.unitDisplayGameObject.GetSpriteRenderer().DOColor(Color.red, 0.1f).SetLoops(4, LoopType.Yoyo);
            }
        }
예제 #27
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);
        }
예제 #28
0
        protected override void OnBeforeEvent(VEntity eventEntity)
        {
            CardPlayEvent cardPlayEvent = eventEntity.GetVComponent <CardPlayEvent>();
            VEntity       card          = ecsManager.GetVEntityById(cardPlayEvent.cardId);

            //ecsManager.ExecuteImmediateEvent("cardMoveInPlay", component: new CardZoneMoveEvent
            //{
            //    source = Zone.HAND,
            //    destination = Zone.INPLAY,
            //    card = card.id,
            //});
        }
예제 #29
0
        public void OnLifecycle(VEntity entity, VLifecycle lifecycle)
        {
            switch (lifecycle)
            {
            case VLifecycle.EnemySetupStart:
                OnEnemySetupStart(entity);
                break;

            case VLifecycle.EnemySetupExecute:
                OnEnemySetupExecute(entity);
                break;

            case VLifecycle.PlayerTurnStart:
                OnPlayerTurnStart(entity);
                break;

            case VLifecycle.PlayerTurnExecute:
                OnPlayerTurnExecute(entity);
                break;

            case VLifecycle.PlayerTurnEnd:
                OnPlayerTurnEnd(entity);
                break;

            case VLifecycle.EnemyActionsStart:
                OnEnemyActionsStart(entity);
                break;

            case VLifecycle.EnemyActionsResolve:
                OnEnemyActionsResolve(entity);
                break;

            case VLifecycle.EnemyActionsEnd:
                OnEnemyActionsEnd(entity);
                break;

            case VLifecycle.OnBeforeEvent:
                OnBeforeEvent(entity);
                break;

            case VLifecycle.OnExecuteEvent:
                OnExecuteEvent(entity);
                break;

            case VLifecycle.OnAfterEvent:
                OnAfterEvent(entity);
                break;

            default:
                throw new Exception("Unhandled lifecycle");
            }
        }
예제 #30
0
        protected override void OnExecuteEvent(VEntity entity)
        {
            VEntity singletonEntity = ecsManager.CreateEntity("SingletonContainer");

            ecsManager.AddComponent(singletonEntity, new CurrentLifecycleComponent {
                currentLifecycle = VLifecycle.EnemySetupStart
            });
            ecsManager.AddComponent(singletonEntity, new TurnCounterComponent {
                turnCounter = 0
            });
            ecsManager.AddComponent(singletonEntity, new CardZoneDataComponent {
                zones = new Dictionary <Zone, List <string> > {
                    {
                        Zone.DECK, new List <string>()
                    },
                    {
                        Zone.HAND,
                        new List <string>()
                    },
                    {
                        Zone.DISCARD,
                        new List <string>()
                    }, {
                        Zone.INPLAY,
                        new List <string>()
                    }
                }
            });
            ecsManager.AddComponent(singletonEntity, new CellsListComponent {
                cellIds = new List <string>()
            });
            ecsManager.AddComponent(singletonEntity, new UnitsList {
                unitIds = new List <string>()
            });
            ecsManager.AddComponent(singletonEntity, new PlayerManaComponent {
                currMana = 0,
                maxMana  = 4
            });
            ecsManager.AddComponent(singletonEntity, new PlayerHandComponent {
                startTurnDrawCount = 5,
                maxHandSize        = 10,
            });
            ecsManager.AddComponent(singletonEntity, new CellScoresComponent {
                cellScores = new Dictionary <Coord, int>()
            });

            VEntity firstLifecycleEvent = ecsManager.CreateEvent("FirstLifecycleEvent");

            ecsManager.AddComponent(firstLifecycleEvent, new SetLifecycleEventComponent {
                newVLifecycle = VLifecycle.EnemySetupStart
            });
        }