protected override void OnExecuteEvent(VEntity entity) { CardDrawEvent cardDraw = entity.GetVComponent <CardDrawEvent>(); CardZoneDataComponent zoneData = ecsManager.GetVSingletonComponent <CardZoneDataComponent>(); PlayerHandComponent PlayerHandComponent = ecsManager.GetVSingletonComponent <PlayerHandComponent>(); for (int cardDrawIndex = 0; cardDrawIndex < cardDraw.numCards; ++cardDrawIndex) { // get top card of deck //If deck is empty, shuffle discard into deck if (zoneData.zones[Zone.DECK].Count == 0) { //If there is no discard pile, draw fizzles. if (zoneData.zones[Zone.DISCARD].Count == 0) { return; } for (int i = zoneData.zones[Zone.DISCARD].Count - 1; i >= 0; i--) { ecsManager.ExecuteImmediateEvent("moveZone", component: new CardZoneMoveEvent { source = Zone.DISCARD, destination = Zone.DECK, card = zoneData.zones[Zone.DISCARD][i] }); } DeckHelper.Shuffle(zoneData.zones[Zone.DECK]); } string cardToDraw = zoneData.zones[Zone.DECK][0]; //If there's space, draw, else discard. if (zoneData.zones[Zone.HAND].Count < PlayerHandComponent.maxHandSize) { ecsManager.ExecuteImmediateEvent("moveZone", component: new CardZoneMoveEvent { source = Zone.DECK, destination = Zone.HAND, card = cardToDraw }); } else { ecsManager.ExecuteImmediateEvent("moveZone", component: new CardZoneMoveEvent { source = Zone.DECK, destination = Zone.DISCARD, card = cardToDraw }); } } }
protected override void OnExecuteEvent(VEntity entity) { CellContent[, ] _currLevel = levelToLoad.levelData; for (int i = 0; i < _currLevel.GetLength(0); i++) { for (int j = 0; j < _currLevel.GetLength(1); j++) { Coord c = new Coord(j, i); if (_currLevel[i, j].unitData != null) { EntityScriptableObject unitDataObject = _currLevel[i, j].unitData; ecsManager.CreateEvent("UnitCreate", component: new UnitCreateEvent { position = c, entityBlueprint = unitDataObject.entity }); } } } for (int i = 0; i < _currLevel.GetLength(0); i++) { for (int j = 0; j < _currLevel.GetLength(1); j++) { Coord c = new Coord(j, i); // create events for making cells ecsManager.CreateEvent("CellCreate", component: new CreateTerrainCellEvent { coord = c, movementCost = _currLevel[i, j].cellStruct.MovementCost, cellType = _currLevel[i, j].cellStruct.cellType }); } } //Initialize Deck /* foreach(string cardEntityId in deckListObject.decklist) { * //ecsManager.CreateEvent * }*/ CardZoneDataComponent cardZones = ecsManager.GetVSingletonComponent <CardZoneDataComponent>(); List <VEntity> cards = new List <VEntity>(); foreach (string cardName in deckList.cardNames) { // look up card in card database EntityScriptableObject cardEntity = cardDatabase.Cards.Find((scriptableObject) => scriptableObject.entity.GetVComponent <CardNameComponent>().name == cardName); Assert.IsNotNull(cardEntity); VEntity newCardEntity = ecsManager.InsantiateEntityFromBlueprint(cardEntity.entity); newCardEntity.GetVComponent <CardDisplayComponent>().cardDisplay = CardViewController.Instance.InitCard(newCardEntity); cards.Add(newCardEntity); ecsManager.ExecuteImmediateEvent("AddCardToZone", component: new CardZoneMoveEvent { source = Zone.NULL, destination = Zone.DECK, card = newCardEntity.id, }); } CardGameObject cantrip = GameObject.FindGameObjectWithTag("cantrip").GetComponent <CardGameObject>(); EntityScriptableObject cantripEntity = cardDatabase.Cards.Find((scriptableObject) => scriptableObject.entity.GetVComponent <CardNameComponent>().name == "Cantrip"); Assert.IsNotNull(cantripEntity); VEntity newCantripEntity = ecsManager.InsantiateEntityFromBlueprint(cantripEntity.entity); newCantripEntity.GetVComponent <CardDisplayComponent>().cardDisplay = CardViewController.Instance.InitCard(newCantripEntity); cards.Add(newCantripEntity); cantrip.cardEntityId = newCantripEntity.id; Debug.Log("Name: " + newCantripEntity.GetVComponent <CardNameComponent>().name); cantrip.cantrip = true; DeckHelper.Shuffle(cardZones.zones[Zone.DECK]); //HACK }