Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another Bug with Buffs -> including Fix #2314

Closed
moepi2k opened this issue Nov 23, 2023 · 3 comments
Closed

Another Bug with Buffs -> including Fix #2314

moepi2k opened this issue Nov 23, 2023 · 3 comments

Comments

@moepi2k
Copy link

moepi2k commented Nov 23, 2023

in stock kit use mage -> spell Heal.

https://gyazo.com/a9d40ce956ff3416fc8124cfb190fc63

so when use 'Buff to target' with option 'Buff to user when no target'

and player has no target. it cast the spell but never apply it own player.

in skill.cs i saw there was a change for this:
bool foundTarget = skillUser.CurrentGameManager.TryGetEntityByObjectId(targetObjectId, out BaseCharacterEntity targetEntity) && !targetEntity.IsDead();

so when using this it works

 protected void ApplySkillBuff(BaseCharacterEntity skillUser, int skillLevel, CharacterItem weapon, uint targetObjectId)
 {
     if (skillUser.IsDead() || !skillUser.IsServer || skillLevel <= 0)
         return;
     int overlapMask = GameInstance.Singleton.playerLayer.Mask | GameInstance.Singleton.playingLayer.Mask | GameInstance.Singleton.monsterLayer.Mask;
     EntityInfo instigator = skillUser.GetInfo();
     List<BaseCharacterEntity> tempCharacters;
     BaseCharacterEntity targetEntity;
     switch (skillBuffType)
     {
         case SkillBuffType.BuffToUser:
             skillUser.ApplyBuff(DataId, BuffType.SkillBuff, skillLevel, instigator, weapon);
             break;
         case SkillBuffType.BuffToNearbyAllies:
             tempCharacters = skillUser.FindAliveEntities<BaseCharacterEntity>(buffDistance.GetAmount(skillLevel), true, false, false, overlapMask);
             foreach (BaseCharacterEntity applyBuffCharacter in tempCharacters)
             {
                 applyBuffCharacter.ApplyBuff(DataId, BuffType.SkillBuff, skillLevel, instigator, weapon);
             }
             skillUser.ApplyBuff(DataId, BuffType.SkillBuff, skillLevel, instigator, weapon);
             break;
         case SkillBuffType.BuffToNearbyCharacters:
             tempCharacters = skillUser.FindAliveEntities<BaseCharacterEntity>(buffDistance.GetAmount(skillLevel), true, false, true, overlapMask);
             foreach (BaseCharacterEntity applyBuffCharacter in tempCharacters)
             {
                 applyBuffCharacter.ApplyBuff(DataId, BuffType.SkillBuff, skillLevel, instigator, weapon);
             }
             skillUser.ApplyBuff(DataId, BuffType.SkillBuff, skillLevel, instigator, weapon);
             break;
         case SkillBuffType.BuffToTarget:
             targetEntity = null;
             if (buffToUserIfNoTarget && !skillUser.CurrentGameManager.TryGetEntityByObjectId(targetObjectId, out targetEntity))
                 targetEntity = skillUser;
             if (targetEntity != null && !targetEntity.IsDead())
                 targetEntity.ApplyBuff(DataId, BuffType.SkillBuff, skillLevel, instigator, weapon);
             break;
         case SkillBuffType.Toggle:
             int indexOfBuff = skillUser.IndexOfBuff(BuffType.SkillBuff, DataId);
             if (indexOfBuff >= 0)
                 skillUser.Buffs.RemoveAt(indexOfBuff);
             else
                 skillUser.ApplyBuff(DataId, BuffType.SkillBuff, skillLevel, instigator, weapon);
             break;
         case SkillBuffType.BuffToAlly:
             targetEntity = null;
             if (buffToUserIfNoTarget && !skillUser.CurrentGameManager.TryGetEntityByObjectId(targetObjectId, out targetEntity))
                 targetEntity = skillUser;
             if (targetEntity != null && !targetEntity.IsDead())
                 targetEntity.ApplyBuff(DataId, BuffType.SkillBuff, skillLevel, instigator, weapon);
             break;
         case SkillBuffType.BuffToEnemy:
             targetEntity = null;
             if (buffToUserIfNoTarget && !skillUser.CurrentGameManager.TryGetEntityByObjectId(targetObjectId, out targetEntity))
                 targetEntity = skillUser;
             if (targetEntity != null && !targetEntity.IsDead())
                 targetEntity.ApplyBuff(DataId, BuffType.SkillBuff, skillLevel, instigator, weapon);
             break;
     }
 }

p.S would be cool to add this change also to core:

public override bool CanUse(BaseCharacterEntity skillUser, int level, bool isLeftHand, uint targetObjectId, out UITextKeys gameMessage, bool isItem = false)
{
    bool foundTarget = skillUser.CurrentGameManager.TryGetEntityByObjectId(targetObjectId, out BaseCharacterEntity targetEntity) && !targetEntity.IsDead();
    switch (skillBuffType)
    {
        case SkillBuffType.BuffToTarget:
            if (!foundTarget && !buffToUserIfNoTarget)
            {
                // Cannot buff enemy
                gameMessage = UITextKeys.UI_ERROR_NO_SKILL_TARGET;
                return false;
            }
            break;
        case SkillBuffType.BuffToAlly:
            if ((!foundTarget && !buffToUserIfNoTarget) || (foundTarget && !targetEntity.IsAlly(skillUser.GetInfo())))
            {
                // Cannot buff enemy
                gameMessage = UITextKeys.UI_ERROR_NO_SKILL_TARGET;
                return false;
            }
            break;
        case SkillBuffType.BuffToEnemy:
            if ((!foundTarget && !buffToUserIfNoTarget) || (foundTarget && !targetEntity.IsEnemy(skillUser.GetInfo())))
            {
                // Cannot buff enemy
                gameMessage = UITextKeys.UI_ERROR_NO_SKILL_TARGET;
                return false;
            }
            break;
    }
    bool canUse = base.CanUse(skillUser, level, isLeftHand, targetObjectId, out gameMessage, isItem);
    if (!canUse && gameMessage == UITextKeys.UI_ERROR_NO_SKILL_TARGET && buffToUserIfNoTarget)
    {
        // Still allow to use skill but it's going to set applies target to skill user
        gameMessage = UITextKeys.NONE;
        return true;
    }
    return canUse;
}

so that 'Buff to user when no target' also works with 'Buff to ally' and 'Buff to enemy'

@insthync
Copy link
Member

Disagree the below part, buff to ally and enemy were made with the intention that it won't be able to buff to the user.

@insthync
Copy link
Member

But it can be added, let's users try it by themself

@insthync
Copy link
Member

But condition for BuffToEnemy with buffToUserIfNoTarget will never be TRUE because user cannot be itself enemy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants