PartyUnitUI GetPartyUnitUIWithHighestInitiative(PartyUnitUI partyUnitUI1, PartyUnitUI partyUnitUI2) { if (partyUnitUI1.LPartyUnit.GetEffectiveInitiative() > partyUnitUI2.LPartyUnit.GetEffectiveInitiative()) { // player has higher initiative return(partyUnitUI1); } else if (partyUnitUI1.LPartyUnit.GetEffectiveInitiative() == partyUnitUI2.LPartyUnit.GetEffectiveInitiative()) { // player and enemy has equal initiative // randomly choose between player and enemy units // Random.value resturns a value between 0 and 1, // so by shifting 0.5 you could also modify the probability of the two numbers. if (UnityEngine.Random.value < 0.5f) { return(partyUnitUI1); } else { return(partyUnitUI2); } } else { // enemy has higher initiative return(partyUnitUI2); } }
public override void Run(System.Object context) { // verify if context doesn't match requirements of this animation if (!DoesContextMatch(context)) { // context is not in scope of this animation // don't run return; } // verify if context matches battle context if (context is BattleContext) { // get destination unit party unit UI PartyUnitUI activePartyUnitUI = BattleContext.ActivePartyUnitUI; // verify if there is a party unit UI if (activePartyUnitUI != null) { Debug.Log("Run Heal Animation on active unit"); // run text animation sourceUnitTextAnimation.Run(activePartyUnitUI.UnitInfoPanelText); } // get destination unit party unit UI PartyUnitUI destinationPartyUnitUI = BattleContext.DestinationUnitSlot.GetComponentInChildren <PartyUnitUI>(); // verify if there is a party unit UI if (destinationPartyUnitUI != null) { Debug.Log("Run Damage Animation on destination unit"); // run text animation destinationUnitTextAnimation.Run(destinationPartyUnitUI.UnitInfoPanelText); } } }
//public bool ActivateNextUnit() //{ // //Debug.Log("ActivateNextUnit"); // canActivate = false; // if (CanContinueBattle()) // { // // find next unit, which can act in the battle // PartyUnitUI nextUnitUI = FindNextUnit(); // //Debug.Log("Next unit is " + nextUnit); // if (nextUnitUI) // { // // found next unit // // save it for later needs // ActiveUnitUI = nextUnitUI; // // activate it // Queue.Run(NextUnit()); // canActivate = true; // } // else // { // // no other units can be activated // // go the next turn // canActivate = StartTurn(); // } // } // else // { // Queue.Run(EndBattle()); // } // return canActivate; //} public void ActivateNextUnit() { //Debug.Log("ActivateNextUnit"); if (CanContinueBattle()) { // find next unit, which can act in the battle PartyUnitUI nextUnitUI = FindNextUnit(); //Debug.Log("Next unit is " + nextUnit); if (nextUnitUI) { // found next unit // activate it CoroutineQueueManager.Run(SetNextUnitActive(nextUnitUI)); } else { // no other units can be activated // start next turn StartTurn(); } } else { CoroutineQueueManager.Run(EndBattle()); } }
PartyUnit HireGenericUnit(PartyUnit hiredUnitTemplate, HeroParty heroParty, Transform destinationUnitSlotTransform, bool doCreateUI = true) { // create unit in HeroParty PartyUnit newPartyUnit = Instantiate(hiredUnitTemplate, heroParty.transform).GetComponent <PartyUnit>(); // Set new unit cell address newPartyUnit.PartyUnitData.unitPPRow = destinationUnitSlotTransform.GetComponent <UnitSlot>().GetUnitPPRow(); newPartyUnit.PartyUnitData.unitPPCell = destinationUnitSlotTransform.GetComponent <UnitSlot>().GetUnitPPCell(); // Reset new unit current health to max newPartyUnit.ResetCurrentHealth(); // Reset new unit current move points to max newPartyUnit.ResetCurrentMovePointsNumber(); // take gold from player TurnsManager.Instance.GetActivePlayer().TotalGold -= hiredUnitTemplate.UnitCost; if (doCreateUI) { // create unit canvas in unit slot PartyUnitUI partyUnitUI = Instantiate(unitCanvasTemplate, destinationUnitSlotTransform).GetComponent <PartyUnitUI>(); // link unit to unit canvas partyUnitUI.LPartyUnit = newPartyUnit; // Activate PartyUnitUI (canvas) partyUnitUI.gameObject.SetActive(true); } // return result return(newPartyUnit); }
IEnumerator SetNextUnitActive(PartyUnitUI nextUnitUI) { // save it for later needs ActiveUnitUI = nextUnitUI; UpdateBattleControlPanelAccordingToUnitPossibilities(); ExecutePreActivateActions(); ProcessBuffsAndDebuffs(); CoroutineQueueManager.Run(ActivateUnit()); yield return(null); }
public void DismissGenericUnit(UnitSlot unitSlot) { // get PartyUnit UI PartyUnitUI unitUI = unitSlot.GetComponentInChildren <PartyUnitUI>(); // get PartyUnit PartyUnit partyUnit = unitUI.LPartyUnit; // Get Unit size, because unit is going to be destroyed UnitSize unitSize = partyUnit.UnitSize; // Get Party Unit HeroParty //HeroParty heroParty = partyUnit.GetComponentInParent<HeroParty>(); // 1 get all required variables, before removing unit Transform unitCell = unitSlot.transform.parent; PartyPanel partyPanel = GetUnitsParentPartyPanel(unitCell); // 2 and put it to recycle bin, because otherwise PartyPanel.GetNumberOfPresentUnits() will return wrong number of units, because object is actually destroyed after Update() // unitUI.transform.SetParent(transform.root.GetComponentInChildren<RecycleBin>().transform); // 3 destory unit canvas, where it is linked to // Destroy(unitUI.gameObject); // 4 and put it to recycle bin, because otherwise city.GetNumberOfPresentUnits() will return wrong number of units, because object is actually destroyed after Update() // partyUnit.transform.SetParent(transform.root.GetComponentInChildren<RecycleBin>().transform); // 5 and destory party unit itself // Destroy(partyUnit.gameObject); RecycleBin.Recycle(unitUI.gameObject); RecycleBin.Recycle(partyUnit.gameObject); // Update party panel // act based on the unit size if (unitSize == UnitSize.Single) { partyPanel.OnChange(PartyPanel.ChangeType.DismissSingleUnit, unitCell); } else { partyPanel.OnChange(PartyPanel.ChangeType.DismissDoubleUnit, unitCell); } // if parent Party panel is in Garnizon state, then update focus panel if (PartyMode.Garnizon == partyPanel.PartyMode) { // Instruct focus panel linked to a city to update information // act based on the unit size if (unitSize == UnitSize.Single) { GetComponentInParent <UIManager>().GetFocusPanelByCity(LCity).OnChange(FocusPanel.ChangeType.DismissSingleUnit); } else { GetComponentInParent <UIManager>().GetFocusPanelByCity(LCity).OnChange(FocusPanel.ChangeType.DismissDoubleUnit); } // Activate hire unit buttons again SetHireUnitPnlButtonActive(true); } }
public void ActOnClick() { // Defend Debug.Log("Defend"); // Get active unit from Battle Screen // Structure: BattleScreen-CtrlPnlFight-this button PartyUnitUI activeUnitUI = transform.root.GetComponentInChildren <UIManager>().GetComponentInChildren <BattleScreen>().ActiveUnitUI; // Apply defense stance status // Get active unit party panel //PartyPanel partyPanel = activeUnitUI.GetUnitPartyPanel(); //partyPanel.SetUnitDefenseBuffActive(activeUnitUI); Proceed(); }
void LinkPartyUnitToUI(PartyUnit partyUnit) { // Get PartyPanel PartyPanel partyPanel = GetComponentInChildren <PartyPanel>(true); // Get unit slot Transform by unit address Transform unitSlotTransform = partyPanel.transform.Find(partyUnit.UnitPPRow + "/" + partyUnit.UnitPPCell).GetComponentInChildren <UnitSlot>(true).transform; // Get unit canvas template GameObject unitCanvasTemplate = transform.root.Find("Templates/UI/UnitCanvas").gameObject; // Create new unit canvas in unit slot PartyUnitUI newUnitCanvas = Instantiate(unitCanvasTemplate, unitSlotTransform).GetComponent <PartyUnitUI>(); // link party Unit to canvas newUnitCanvas.LPartyUnit = partyUnit; // enable new unit canvas newUnitCanvas.gameObject.SetActive(true); }
void SwapTwoCellsContent(Transform srcCellTr, Transform dstCellTr) { // Debug.Log("Swap 2 cells: " + srcCellTr.name + " > " + dstCellTr.name); // swap all relevan cells content and states // swap UnitCanvas PartyUnitUI srcPartyUnitUI = srcCellTr.Find("UnitSlot").GetComponentInChildren <PartyUnitUI>(); PartyUnitUI dstPartyUnitUI = dstCellTr.Find("UnitSlot").GetComponentInChildren <PartyUnitUI>(); // Get source party // structure: 3HeroPartyUI-2PartyPanel-1Row-cell(dstCellTr) HeroParty srcHeroParty = srcCellTr.parent.GetComponentInParent <PartyPanel>().GetComponentInParent <HeroPartyUI>().LHeroParty; // Get destination party HeroParty dstHeroParty = dstCellTr.parent.GetComponentInParent <PartyPanel>().GetComponentInParent <HeroPartyUI>().LHeroParty; // verify is src unit canvas exist, it may not exist on double unit swap if (srcPartyUnitUI != null) { // Swap UI srcPartyUnitUI.transform.SetParent(dstCellTr.Find("UnitSlot")); ResetPositionToZero(srcPartyUnitUI.transform); // verify unit's party is about to change if (srcHeroParty.gameObject.GetInstanceID() != dstHeroParty.gameObject.GetInstanceID()) { // Swap Unit between parties srcPartyUnitUI.LPartyUnit.transform.SetParent(dstHeroParty.transform); } // Change unit's address srcPartyUnitUI.LPartyUnit.UnitPPRow = srcPartyUnitUI.GetUnitRow().Row; srcPartyUnitUI.LPartyUnit.UnitPPCell = srcPartyUnitUI.GetUnitCell().GetComponent <PartyPanelCell>().Cell; } // verfy that unit canvas is present, dst cell may be free if (dstPartyUnitUI != null) { dstPartyUnitUI.transform.SetParent(srcCellTr.Find("UnitSlot")); ResetPositionToZero(dstPartyUnitUI.transform); // verify unit's party is about to change if (srcHeroParty.gameObject.GetInstanceID() != dstHeroParty.gameObject.GetInstanceID()) { // Swap Unit between parties dstPartyUnitUI.LPartyUnit.transform.SetParent(srcHeroParty.transform); } // Change unit's address dstPartyUnitUI.LPartyUnit.UnitPPRow = dstPartyUnitUI.GetUnitRow().Row; dstPartyUnitUI.LPartyUnit.UnitPPCell = dstPartyUnitUI.GetUnitCell().GetComponent <PartyPanelCell>().Cell; } }
PartyUnitUI FindNextUnit() { // Find unit with the highest initiative, which can still move during this turn in battle PartyUnitUI playerNextUnitUI = playerPartyPanel.GetActiveUnitUIWithHighestInitiativeWhichHasNotMoved(BattleTurnPhase); PartyUnitUI enemyNextUnitUI = enemyPartyPanel.GetActiveUnitUIWithHighestInitiativeWhichHasNotMoved(BattleTurnPhase); // verify if player and enemy has more units to move if (playerNextUnitUI && enemyNextUnitUI) { // both parties still have units to move return(GetPartyUnitUIWithHighestInitiative(playerNextUnitUI, enemyNextUnitUI)); } else { // some parties do not have units to move // find which party has and which does not have if (playerNextUnitUI) { // player has next unit, return it return(playerNextUnitUI); } else if (enemyNextUnitUI) { // player has next unit, return it return(enemyNextUnitUI); } else { // no any pary has units to move // verify current phase if (BattleTurnPhase.Main == BattleTurnPhase) { // do the same check but for units, which are in waiting status BattleTurnPhase = BattleTurnPhase.PostWait; return(FindNextUnit()); } else { // return null, this should initiate new battle turn return(null); } } } }
public override ValidationResult DoDiscardModifierInContextOf(System.Object context) { // verify if context doesn't match requirements of this limiter if (!DoesContextMatch(context)) { // verify if destination unit is set if (BattleContext.DestinationUnitSlot != null) { // context is not in scope of this limiter // don't limit return(ValidationResult.Pass()); } } // verify if context matches battle context if (context is BattleContext) { // get party unit UI in destination slot PartyUnitUI partyUnitUI = BattleContext.DestinationUnitSlot.GetComponentInChildren <PartyUnitUI>(); // verify if destination slot has unit if (partyUnitUI != null) { // verify if we need to discard this modifier // ignore source context return(DoDiscardModifierInContextOf(null, partyUnitUI.LPartyUnit)); } } // verify if context matches EditPartyScreenContext context if (context is EditPartyScreenContext) { // get party unit UI in destination slot PartyUnitUI partyUnitUI = EditPartyScreenContext.DestinationUnitSlot.GetComponentInChildren <PartyUnitUI>(); // verify if destination slot has unit if (partyUnitUI != null) { // verify if we need to discard this modifier // ignore source context return(DoDiscardModifierInContextOf(null, partyUnitUI.LPartyUnit)); } } // don't limit return(ValidationResult.Pass()); }
public void ShowUpgradeUnitMenu() { //// structure: //// 2[Front/Back/Wide]Cell-1UpgradeUnitPanel-PlusButton(this), UnitCanvas-PartyUnit //// [Front/Back/Wide]Cell-UnitSlot-UnitCanvas-PartyUnit //PartyUnit partyUnit; //// check whether we are in battle or in other mode //if (transform.parent.parent.GetComponentInChildren<UnitSlot>().GetComponentInChildren<UnitOnBattleMouseHandler>()) //{ // // we are in battle mode // partyUnit = transform.parent.parent.GetComponentInChildren<UnitSlot>().GetComponentInChildren<UnitOnBattleMouseHandler>().GetComponent<PartyUnitUI>().LPartyUnit; //} //else //{ // // we are in other mode // partyUnit = transform.parent.parent.GetComponentInChildren<UnitSlot>().GetComponentInChildren<UnitDragHandler>().GetComponent<PartyUnitUI>().LPartyUnit; //} // structure: 2PartyUnitUI-1UpgradeUnitPanel-PlusButton(this) PartyUnitUI partyUnitUI = transform.parent.GetComponentInParent <PartyUnitUI>(); Debug.Log("ShowUpgradeUnitMenu for " + partyUnitUI.LPartyUnit.name + " unit"); transform.root.Find("MiscUI/UpgradeUnit").GetComponent <UpgradeUnit>().ActivateAdvance(partyUnitUI); }
ValidationResult DoDiscardModifierInContextOf(System.Object srcContext, System.Object dstContext) { // verify if source or destination context do not match requirements of this limiter if (!DoesContextMatch(srcContext, dstContext)) { // context is not in scope of this limiter // don't limit return(ValidationResult.Pass()); } //if (dstContext is InventorySlotDropHandler) //{ // // ignore this limiter (don't discard) // return false; //} switch (modifierScopeID) { case ModifierScopeID.Self: // verify if source context and destination context are of PartyUnit type (also verifies if it is not null) if ((srcContext is PartyUnit) && (dstContext is PartyUnit)) { // verify if source and destination party units are the same if (((PartyUnit)srcContext).GetInstanceID() == ((PartyUnit)dstContext).GetInstanceID()) { // don't limit return(ValidationResult.Pass()); } } // limit by default return(ValidationResult.Discard(onDiscardMessage)); case ModifierScopeID.SingleUnit: // verify if source context is UnitSlotDropHandler and destination context is of PartyUnit type if (srcContext is UnitSlotDropHandler && dstContext is PartyUnit) { // get unit UI in slot drop handler PartyUnitUI partyUnitUI = ((UnitSlotDropHandler)srcContext).GetComponentInChildren <PartyUnitUI>(); // verify if it is not null if (partyUnitUI != null) { // make sure that UPM is applied only to destination unit if modifier scope is single unit // verify if this unit belongs to this unit slot (normally this is the slot to which item has been dropped) (IDs of units are the same) if (partyUnitUI.LPartyUnit == (PartyUnit)dstContext) { // don't limit return(ValidationResult.Pass()); } else { // limit return(ValidationResult.Discard(onDiscardMessage)); } } else { // limit return(ValidationResult.Discard(onDiscardMessage)); } } // verify if destination context is of PartyUnit type (also verifies if it is not null) if (dstContext is PartyUnit) { // don't limit return(ValidationResult.Pass()); } // limit by default return(ValidationResult.Discard(onDiscardMessage)); case ModifierScopeID.EntireParty: // verify if destination context is of Party or PartyUnit type (also verifies if it is not null) if ((dstContext is HeroParty) || (dstContext is PartyUnit)) { // don't limit return(ValidationResult.Pass()); } // limit by default return(ValidationResult.Discard(onDiscardMessage)); case ModifierScopeID.AllPlayerUnits: // use case: global spells, player abilities // verify if destination context is of Player type (also verifies if it is not null) if ((dstContext is GamePlayer) || (dstContext is HeroParty) || (dstContext is PartyUnit)) { // don't limit return(ValidationResult.Pass()); } // limit by default return(ValidationResult.Discard(onDiscardMessage)); default: Debug.LogError("Unknown modifier scope: " + modifierScopeID.ToString()); // limit by default return(ValidationResult.Discard("Unknown modifier scope")); } }
void OnApplyAbilityFromUnitUIToUnitCell(PartyUnitUI activePartyUnitUI, PartyPanelCell partyPanelCell) { Debug.LogWarning(".. OnApplyAbilityFromUnitUIToUnitCell"); }
// context is destination unit slot public void OnUnitSlotLeftClickEvent(System.Object context) { // verify if context is correct if (context is UnitSlot) { // init unit slot from context UnitSlot unitSlot = (UnitSlot)context; Debug.Log("UnitSlot ActOnClick in City"); // Get city state EditPartyScreenActiveState cityState = EditPartyScreenActiveState; // Verify if city state is not normal if (EditPartyScreenActiveState.Normal != cityState) { DeactivateActiveToggle(); } // Get party unit UI in this slot PartyUnitUI unitUI = unitSlot.GetComponentInChildren <PartyUnitUI>(); // Verify if unit is found if (unitUI) { // act based on the city (and cursor) state switch (cityState) { case EditPartyScreenActiveState.Normal: // do nothing for now break; case EditPartyScreenActiveState.ActiveDismiss: // cache unit slot to dismiss (it is used in OnDismissYesConfirmation()) unitSlotToDismissCache = unitSlot; // try to dismiss unit, if it is possible TryToDismissUnit(unitUI.LPartyUnit); break; case EditPartyScreenActiveState.ActiveHeal: // try to heal unit, if it is possible Debug.Log("Show Heal Unit confirmation box"); break; case EditPartyScreenActiveState.ActiveResurect: // try to resurect unit, if it is possible Debug.Log("Show Resurect Unit confirmation box"); break; case EditPartyScreenActiveState.ActiveUnitDrag: // ?? break; case EditPartyScreenActiveState.ActiveItemDrag: // this should not be triggered here, because it should be triggered in the unit slot drop handler when item is being dropped in it Debug.LogWarning("Unpredicted condition"); break; default: Debug.LogError("Unknown state"); break; } } else { Debug.LogWarning("Unit no found"); } // Verify if city state is not normal if (EditPartyScreenActiveState.Normal != cityState) { // disable previous city state SetActiveState(cityState, false); } } }