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); }
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); }
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) { 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 })); }
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 } }); }
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 }); } }
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); }
public override List <Coord> SelectCoords(Coord loc, VEntityComponentSystemManager boardState) { List <Coord> selectedCoords = new List <Coord> { loc }; return(selectedCoords); }
protected override void OnExecuteEvent(VEntity entity) { if (VEntityComponentSystemManager.GetVComponent <SetLifecycleEventComponent>(entity).newVLifecycle == VLifecycle.EnemySetupStart) { var turnCounter = ecsManager.GetVSingletonComponent <TurnCounterComponent>(); turnCounter.turnCounter += 1; } }
private void Start() { cardHovering = null; boardSpaceHovering = Coord.nullCoord; cardController = FindObjectOfType <CardViewController>(); boardState = VEntityComponentSystemManager.Instance; cardMover = FindObjectOfType <CardMover>(); SendEventToBoard(); }
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() }); } }
void Start() { deck = new List <CardGameObject>(); hand = new List <CardGameObject>(); discardPile = new List <CardGameObject>(); board = FindObjectOfType <VEntityComponentSystemManager>(); cardMover = FindObjectOfType <CardMover>(); cantrip = GameObject.FindWithTag("cantrip").GetComponent <CardGameObject>(); handControlSystem = VEntityComponentSystemManager.Instance.GetSystem <HandControlSystem>(); }
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); }
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 }); }
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 List <Coord> SelectGroupCoords(Coord loc, Coord casterLoc, VEntityComponentSystemManager boardState) { List <Coord> selectedCoords = new List <Coord>(); Coord dir = Coord.GetDirection(casterLoc, loc); Coord current = casterLoc + dir; while (boardState.GetSystem <TerrainCellFinderSystem>().GetCellAtCoord(current) != null) { selectedCoords.Add(current); current += dir; } return(selectedCoords); }
public override List <Coord> SelectGroupCoords(Coord loc, Coord casterLoc, VEntityComponentSystemManager boardState) { List <Coord> selectedCoords = new List <Coord>(); for (int i = 1; i <= length; i++) { foreach (Coord dir in Coord.cardinalCoords) { selectedCoords.Add(loc + dir * length); } } return(selectedCoords); }
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; }
// 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); } }
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) }); } }
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 })); }
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 }); } } }
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(); }
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; }
public override List <Coord> SelectGroupCoords(Coord loc, Coord casterLoc, VEntityComponentSystemManager boardState) { List <Coord> selectedCoords = new List <Coord>(); Coord dir = Coord.GetDirection(casterLoc, loc); Coord current = casterLoc; while (boardState.GetSystem <TerrainCellFinderSystem>().IsValidCell(current)) { VEntity unit = boardState.GetSystem <UnitFinderSystem>().GetUnitAtCoord(current); if (unit != null) //&&unit.team == team { break; } current += dir; } if (current != casterLoc) { selectedCoords.Add(current); } return(selectedCoords); }
public override List <Coord> SelectGroupCoords(Coord loc, Coord casterLoc, VEntityComponentSystemManager boardState) { List <Coord> selectedCoords = new List <Coord>(); foreach (Coord direction in Coord.cardinalCoords) { for (int distance = offset + 1; infinite || distance <= length; distance++) { Coord newCoord = casterLoc + (direction * distance); if (boardState.GetSystem <TerrainCellFinderSystem>().IsValidCell(newCoord)) { selectedCoords.Add(newCoord); } else { break; } } } return(selectedCoords); }
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(); } } } }
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); }
public override bool ShouldOperate(VEntity entity) { return(VEntityComponentSystemManager.HasVComponent <DamageEffectEventComponent>(entity)); }
public override bool ShouldOperate(VEntity entity) { return(VEntityComponentSystemManager.HasVComponent <DeathAnimationEvent>(entity)); }