suriyun-production / mmorpg-kit-docs

This is document for MMORPG KIT project (https://www.assetstore.unity3d.com/#!/content/110188?aid=1100lGeN)
https://suriyun-production.github.io/mmorpg-kit-docs
49 stars 11 forks source link

Another Bug with Buffs -> including Fix #2314

Closed moepi2k closed 11 months ago

moepi2k commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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

insthync commented 11 months ago

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