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

Monster faction bug. #2324

Closed CLAXES closed 9 months ago

CLAXES commented 9 months ago

Hello, arrows hit and damage the monster in the same faction

    protected override bool IsMonsterAlly(BaseMonsterCharacterEntity monsterCharacter, EntityInfo targetEntity)
    {
        if (string.IsNullOrEmpty(targetEntity.Id))
            return false;

        if (monsterCharacter.IsSummonedAndSummonerExisted)
        {
            // If summoned by someone, will have same allies with summoner
            return targetEntity.Id.Equals(monsterCharacter.Summoner.Id) || monsterCharacter.Summoner.IsAlly(targetEntity);
        }

        if (targetEntity.Type == EntityTypes.Monster)
        {
            if (targetEntity.HasSummoner)
            {
                return monsterCharacter.IsAlly(targetEntity.Summoner);
            }
            else
            {
                if (targetEntity.FactionId != 0 && monsterCharacter.FactionId == targetEntity.FactionId)
                    return true;
            }
            // If another monster has same allyId so it is ally
            return GameInstance.MonsterCharacters[targetEntity.DataId].AllyId == monsterCharacter.CharacterDatabase.AllyId;
        }

        return false;
    }

when I add this code into it, the problem disappears

        // Attack only player by default
        if (targetEntity.Type == EntityTypes.Player)
        {
            // If it has faction set, then check the faction between two characters
            if (targetEntity.FactionId != 0 && monsterCharacter.FactionId == targetEntity.FactionId)
                return true;
            // Player always be monster's enemy
            return false;
        }
insthync commented 9 months ago

Add what to where?

insthync commented 9 months ago

I see

CLAXES commented 9 months ago

Like this one here

protected override bool IsMonsterAlly(BaseMonsterCharacterEntity monsterCharacter, EntityInfo targetEntity)
{
    if (string.IsNullOrEmpty(targetEntity.Id))
        return false;

    // Attack only player by default
    if (targetEntity.Type == EntityTypes.Player)
    {
        // If it has faction set, then check the faction between two characters
        if (targetEntity.FactionId != 0 && monsterCharacter.FactionId == targetEntity.FactionId)
            return true;
        // Player always be monster's enemy
        return false;
    }

    if (monsterCharacter.IsSummonedAndSummonerExisted)
    {
        // If summoned by someone, will have same allies with summoner
        return targetEntity.Id.Equals(monsterCharacter.Summoner.Id) || monsterCharacter.Summoner.IsAlly(targetEntity);
    }

    if (targetEntity.Type == EntityTypes.Monster)
    {
        if (targetEntity.HasSummoner)
        {
            return monsterCharacter.IsAlly(targetEntity.Summoner);
        }
        else
        {
            if (targetEntity.FactionId != 0 && monsterCharacter.FactionId == targetEntity.FactionId)
                return true;
        }
        // If another monster has same allyId so it is ally
        return GameInstance.MonsterCharacters[targetEntity.DataId].AllyId == monsterCharacter.CharacterDatabase.AllyId;
    }

    return false;
}
insthync commented 9 months ago

Too slow :P