Пример #1
0
    //bool GetIsTargetableAndHighlightUnitCanvasBasedOnUPMConfigApplicability(UniquePowerModifierConfig uniquePowerModifierConfig)
    //{
    //    // verify if active party unit ability is applicable to this cell (example: summon) and party unit (if it is present)
    //    //if (uniquePowerModifierConfig.AreRequirementsMetInContextOf(activePartyUnitUI.GetComponentInParent<PartyPanelCell>(), this))
    //    //if (uniquePowerModifierConfig.AreRequirementsMetInContextOf(BattleContext.Instance))
    //    if (uniquePowerModifierConfig.AreRequirementsMetInContextOf(GameContext.Context))
    //    {
    //        Debug.Log("Cell Requirements are met");
    //        // verify if party unit is not present, because if it is present, then we need to give it a possibility to override "applicability"
    //        // it maybe already overritten, because PartyUnitUI could possibly react earlier on event
    //        // get party unit UI
    //        PartyUnitUI partyUnitUI = GetComponentInChildren<PartyUnitUI>();
    //        // verify if its not null
    //        if (partyUnitUI != null)
    //        {
    //            // let party unit override highlights and react on begin item drag event
    //            return partyUnitUI.ActOnBattleNewUnitHasBeenActivatedEvent();
    //        }
    //        else
    //        {
    //            // highlight with applicable color
    //            CanvasText.color = uniquePowerModifierConfig.UniquePowerModifierUIConfig.ValidationUIConfig.upmIsApplicableForUnitSlotColor;
    //            // targetable
    //            return true;
    //        }
    //    }
    //    else
    //    {
    //        Debug.Log("Cell Requirements are not met");
    //        // highlight with not applicable color
    //        CanvasText.color = uniquePowerModifierConfig.UniquePowerModifierUIConfig.ValidationUIConfig.upmIsNotApplicableForUnitSlotColor;
    //        // not targetable
    //        return false;
    //    }
    //}

    public void SetCanvasTextColorBasedOnUPMValidationResult(ModifierLimiter.ValidationResult validationResult, UniquePowerModifierConfig uniquePowerModifierConfig)
    {
        if (validationResult.doDiscardModifier)
        {
            // highlight with not applicable color
            CanvasText.color = uniquePowerModifierConfig.UniquePowerModifierUIConfig.ValidationUIConfig.upmIsNotApplicableForUnitSlotColor;
        }
        else
        {
            CanvasText.color = uniquePowerModifierConfig.UniquePowerModifierUIConfig.ValidationUIConfig.upmIsApplicableForUnitSlotColor;
        }
    }
Пример #2
0
 public void SetOnClickAction(ModifierLimiter.ValidationResult validationResult)
 {
     if (validationResult.doDiscardModifier)
     {
         isAllowedToApplyPowerToThisUnit = false;
     }
     else
     {
         isAllowedToApplyPowerToThisUnit = true;
     }
     errorMessage = validationResult.message;
 }
Пример #3
0
    //public bool AreRequirementsMetInContextOf(System.Object srcContext, System.Object dstContext)
    //{
    //    // loop through all limiters
    //    foreach (ModifierLimiter modifierLimiter in modifierLimiters)
    //    {
    //        // verify is modifier power is limited
    //        Debug.LogError(".. uncomment below and fix");
    //        //if (modifierLimiter.DoDiscardModifierInContextOf(srcContext, dstContext))
    //        {
    //            // at least one requirement is not met
    //            return false;
    //        }
    //    }
    //    // if none of limiter is limiting, then return true
    //    return true;
    //}

    public ModifierLimiter.ValidationResult AreRequirementsMetInContextOf(System.Object context)
    {
        // loop through all limiters
        foreach (ModifierLimiter modifierLimiter in modifierLimiters)
        {
            ModifierLimiter.ValidationResult result = modifierLimiter.DoDiscardModifierInContextOf(context);
            Debug.LogWarning(modifierLimiter.GetType().Name + " validation [" + result.doDiscardModifier + "] : [" + result.message + "]");
            // verify is modifier power is limited
            if (result.doDiscardModifier)
            {
                // at least one requirement is not met
                return(result);
            }
        }
        // if none of limiter is limiting, then return true
        return(ModifierLimiter.ValidationResult.Pass());
    }
Пример #4
0
    public void OnBattleNewUnitHasBeenActivatedEvent(System.Object context)
    {
        // verify if context is wrong
        if (!(context is PartyUnitUI))
        {
            // exit
            return;
        }
        // init error message (if cell is not targetable)
        // .. set it dynamically based on limiter triggered
        //string errorMessage = "Cannot target this cell";
        // init is targetable
        //bool isTargetable = false;
        //// init and cache newly activated party unit UI from context
        //activePartyUnitUI = (PartyUnitUI)context;
        // reset battle context values (we don't want to have previously cached targeted party unit slot and upm index)
        //BattleContext.Reset();
        // cache active unit in battle context
        //BattleContext.ActivePartyUnitUI = activePartyUnitUI;
        // cache this unit slot as destination unit slot for battle context
        BattleContext.DestinationUnitSlot = GetComponentInChildren <UnitSlot>();
        // get UPM config
        UniquePowerModifierConfig uniquePowerModifierConfig = BattleContext.ActivePartyUnitUI.LPartyUnit.UnitAbilityConfig.PrimaryUniquePowerModifierConfig;

        // Highlight unit canvas based on whether UPM is applicable to this unit or not
        // isTargetable = GetIsTargetableAndHighlightUnitCanvasBasedOnUPMConfigApplicability(uniquePowerModifierConfig);
        ModifierLimiter.ValidationResult validationResult = uniquePowerModifierConfig.AreRequirementsMetInContextOf(GameContext.Context);
        // set UnitSlot in cell as targetable or not
        //GetComponentInChildren<UnitSlot>().SetOnClickAction(isTargetable, errorMessage);
        GetComponentInChildren <UnitSlot>().SetOnClickAction(validationResult);
        // set unit cell color based on validation result
        SetCanvasTextColorBasedOnUPMValidationResult(validationResult, uniquePowerModifierConfig);
        // adjust cell color if it is not advised to use UPM
        AdjustCellCavasTextColorBasedOnWhetherItIsAdvisedToUseUPM(uniquePowerModifierConfig);
        // verify and set canvas highlight
        SetCellCavastTextHighlight();
    }
Пример #5
0
    public void OnBeginItemDrag()
    {
        // Debug.LogWarning("OnBeginItemDrag");
        // save original color
        // Debug.LogWarning("Save original color");
        beforeItemDragColor = CanvasText.color;
        // set battle item context
        //BattleContext.ItemBeingUsed = InventoryItemDragHandler.itemBeingDragged.LInventoryItem;
        // cache this unit slot as destination unit slot for battle context
        GameContext.SetDestinationUnitSlot(GetComponentInChildren <UnitSlot>());
        // get UPM config
        UniquePowerModifierConfig uniquePowerModifierConfig = GameContext.GetItemBeingUsed().InventoryItemConfig.PrimaryUniquePowerModifierConfig;

        // Highlight unit canvas based on whether UPM is applicable to this unit or not
        // isTargetable = GetIsTargetableAndHighlightUnitCanvasBasedOnUPMConfigApplicability(uniquePowerModifierConfig);
        ModifierLimiter.ValidationResult validationResult = uniquePowerModifierConfig.AreRequirementsMetInContextOf(GameContext.Context);
        // set UnitSlot in cell as targetable or not
        //GetComponentInChildren<UnitSlot>().SetOnClickAction(isTargetable, errorMessage);
        GetComponentInChildren <UnitSlot>().SetOnClickAction(validationResult);
        // set unit cell color based on validation result
        SetCanvasTextColorBasedOnUPMValidationResult(validationResult, uniquePowerModifierConfig);
        // adjust cell color if it is not advised to use UPM
        AdjustCellCavasTextColorBasedOnWhetherItIsAdvisedToUseUPM(uniquePowerModifierConfig);
        //// verify if item is usable
        //if (uniquePowerModifierConfig.AreRequirementsMetInContextOf(BattleContext.ItemBeingUsed, this))
        //{
        //    Debug.Log("Cell Requirements are met");
        //    // verify if party unit is not present, because if it is present, then we need to give it a possibility to override "applicability"
        //    // it maybe already overritten, because PartyUnitUI could possibly react earlier on event
        //    // get party unit UI
        //    PartyUnitUI partyUnitUI = GetComponentInChildren<PartyUnitUI>();
        //    // verify if its not null
        //    if (partyUnitUI != null)
        //    {
        //        // let party unit override highlights and react on begin item drag event
        //        partyUnitUI.ActOnBeginItemDrag();
        //    }
        //    else
        //    {
        //        // highlight with applicable color
        //        // CanvasText.color = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.inventoryItemUIConfig.itemIsApplicableForUnitSlotColor;
        //        CanvasText.color = uniquePowerModifierConfig.UniquePowerModifierUIConfig.ValidationUIConfig.upmIsApplicableForUnitSlotColor;
        //    }
        //}
        //else
        //{
        //    Debug.Log("Cell Requirements are not met");
        //    // highlight with not applicable color
        //    // CanvasText.color = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.inventoryItemUIConfig.itemIsNotApplicableForUnitSlotColor;
        //    CanvasText.color = uniquePowerModifierConfig.UniquePowerModifierUIConfig.ValidationUIConfig.upmIsNotApplicableForUnitSlotColor;
        //}
        //// verify if item has active modifiers or usages
        //if (InventoryItemDragHandler.itemBeingDragged.LInventoryItem.HasActiveModifiers())
        //{
        //    Debug.Log("Item has active modifiers");
        //    // get party unit UI
        //    PartyUnitUI partyUnitUI = GetComponentInChildren<PartyUnitUI>();
        //    // verify if its not null
        //    if (partyUnitUI != null)
        //    {
        //        Debug.Log("Found partyUnitUI");
        //        // activate highlight
        //        // get source context
        //        // try to get party unit (assume that during battle unit can only use items which are located in (childs of) this unit game object)
        //        // if outside of the battle or if item is dragged from inventiry, then this will result in null
        //        System.Object srcContext = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.GetComponentInParent<PartyUnit>();
        //        // verify if srcPartyUnit is null
        //        if (srcContext == null)
        //        {
        //            // context is hero party (item is dragged from inventory)
        //            // get party
        //            HeroParty heroParty = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.GetComponentInParent<HeroParty>();
        //            // verify if party is garnizon type
        //            if (heroParty.PartyMode == PartyMode.Garnizon)
        //            {
        //                // set context to the city
        //                srcContext = heroParty.GetComponentInParent<City>();
        //            }
        //            else
        //            {
        //                // party mode = normal party
        //                // set context to the party leader
        //                srcContext = heroParty.GetPartyLeader();
        //            }
        //        }
        //        // verify if UPM can be applied to destination unit
        //        if (InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.uniquePowerModifierConfigs[0].AreRequirementsMetInContextOf(srcContext, partyUnitUI.LPartyUnit) )
        //        {
        //            Debug.Log("Requirements are met");
        //            // verify if it is advised to use this item in this context
        //            if (InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.uniquePowerModifierConfigs[0].IsItAdvisedToActInContextOf(srcContext, partyUnitUI.LPartyUnit))
        //            {
        //                Debug.Log("Advised");
        //                // advised
        //                // item can be applied to this hero, highlight with applicable color
        //                canvasText.color = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.inventoryItemUIConfig.itemIsApplicableForUnitSlotColor;
        //            }
        //            else
        //            {
        //                Debug.Log("Not Advised");
        //                // not advised
        //                // item can be applied to this hero, highlight with applicable color
        //                canvasText.color = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.inventoryItemUIConfig.itemIsApplicableButNotAdvisedForUnitSlotColor;
        //            }
        //        }
        //        else
        //        {
        //            Debug.Log("Requirements are not met");
        //            // item cannot be applied to this hero, highlight with not applicable color
        //            canvasText.color = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.inventoryItemUIConfig.itemIsNotApplicableForUnitSlotColor;
        //        }
        //        //// try to consume item in preview mode without actually doing anything
        //        //if (partyUnitUI.LPartyUnit.UseItem(InventoryItemDragHandler.itemBeingDragged.LInventoryItem, true))
        //        //{
        //        //    // item can be applied to this hero, highlight with applicable color
        //        //    canvasText.color = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.inventoryItemUIConfig.itemIsApplicableForUnitSlotColor;
        //        //}
        //        //else
        //        //{
        //        //    // item cannot be applied to this hero, highlight with not applicable color
        //        //    canvasText.color = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.inventoryItemUIConfig.itemIsNotApplicableForUnitSlotColor;
        //        //}
        //    }
        //    else
        //    {
        //        Debug.Log("no party unit UI");
        //        // there is no hero in this slot, highlight with not applicable color
        //        canvasText.color = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.inventoryItemUIConfig.itemIsNotApplicableForUnitSlotColor;
        //    }
        //}
        //else
        //{
        //    Debug.Log("Item has no active modifiers");
        //    // item is not consumable, highlight with not applicable color
        //    canvasText.color = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.inventoryItemUIConfig.itemIsNotApplicableForUnitSlotColor;
        //}
    }
    public void OnBeginItemDrag()
    {
        // save original slot color
        beforeBeginItemDragColor = canvasText.color;
        // init isCompatible with this slot item flag
        bool isCompatible = false;

        // reset is droppable flag
        // verify if equipment slot is compatible
        if ((InventoryItemDragHandler.itemBeingDragged.LInventoryItem.CompatibleEquipmentSlots & EquipmentSlot) == EquipmentSlot)
        {
            // set context
            EquipmentScreenContext.DestinationItemSlotDropHandler = this;
            // verify item is compatible with hero (all required prerequisites are net)
            ModifierLimiter.ValidationResult validationResult = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.PrimaryUniquePowerModifierConfig.AreRequirementsMetInContextOf(GameContext.Context);
            // if (InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.uniquePowerModifierConfigs[0].AreRequirementsMetInContextOf(null, GetComponentInParent<HeroEquipment>().LPartyUnit))
            // if (InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.PrimaryUniquePowerModifierConfig.AreRequirementsMetInContextOf(null, this))
            if (!validationResult.doDiscardModifier)
            {
                // set compatible flag
                isCompatible = true;
            }
            else
            {
                // set cavast message
                // Debug.LogError(".. uncomment below and fix");
                //canvasMessageText.text = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.PrimaryUniquePowerModifierConfig.GetLimiterMessageInContextOf(null, GetComponentInParent<HeroEquipment>().LPartyUnit);
                canvasMessageText.text = validationResult.message;
                // set highlight color to not the color which indicates that prerequisites are not met
                canvasText.color = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.inventoryItemUIConfig.itemPrerequsitesAreNotMetForThisUnitColor;
            }
            //// verify if this is shard slot
            //if (EquipmentSlot == HeroEquipmentSlots.Shard)
            //{
            //    // for shard slot we need to verify if party leader has skill at least 1st level
            //    if (Array.Find(GetComponentInParent<HeroEquipment>().LPartyUnit.UnitSkillsData, element => element.unitSkill == UnitSkillID.ShardAura).currentSkillLevel >= 1)
            //    {
            //        // set compatible flag
            //        isCompatible = true;
            //    }
            //    else
            //    {
            //        // set highlight color to not the color which indicates that prerequisites are not met
            //        canvasText.color = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.inventoryItemUIConfig.itemPrerequsitesAreNotMetForThisUnitColor;
            //        // set cavast message
            //        canvasMessageText.text = "Requires " + ConfigManager.Instance[UnitSkillID.ShardAura].skillDisplayName + " skill";
            //    }
            //}
            //else
            //{
            //    // set compatible flag
            //    isCompatible = true;
            //}
        }
        else
        {
            // set highlight color to not applicable for this equipment slot
            canvasText.color = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.inventoryItemUIConfig.itemIsNotCompatibleWithEquipmentSlotColor;
        }
        // verify if slot is compatible
        if (isCompatible)
        {
            // set droppable flag
            IsDroppable = true;
            // set highlight color to applicable
            canvasText.color = InventoryItemDragHandler.itemBeingDragged.LInventoryItem.InventoryItemConfig.inventoryItemUIConfig.itemCanBeEquippedColor;
        }
        else
        {
            // unset droppable flag
            IsDroppable = false;
        }
        // reset normal button color
        canvasText.GetComponent <TextButton>().NormalColor = canvasText.color;
    }