Echizen-ham / SRPGcore

Tactical battle system for RPGtkool MV
http://www.lemon-slice.net/index.html
MIT License
20 stars 14 forks source link

Game_BattlerBase.prototype.isTargetInRange doesn't work properly #5

Open ShoukangHong opened 2 years ago

ShoukangHong commented 2 years ago

I quote the code here:

    Game_BattlerBase.prototype.isTargetInRange = function(item) {
        var rangeList = $gameTemp.rangeList();
        var target = $gameTemp.targetEvent();
        if (item.scope === 11) return true;
        if (!target) return false;
        for (var i = 0; i < rangeList.length; i++) {
            var pos =  rangeList[i];
            if (target.posX() == pos[0] && target.posY() == pos[1]) return true;
        }
        return false;
    };

range list contains a list of tiles that are in attack range but not in move range. Therefore, this function will disable skills for friends (tile with a friend is moveable, therefore such tile will in many cases appear in movelist, not range list.) Please use the range table to do the check. Actually, I don't think this function is necessary as I have never seen the canuse() function fail in 1.32Q(I may be wrong).

Echizen-ham commented 2 years ago

This is difficult, but ... Without this part, enemies behind walls that are out of range will be mistaken for being within range. However, I think that the judgment of whether or not there is a target within the range should be drastically corrected. Specifically, I think this way. At the beginning of the battle scene, both user and target have a range list of the skills they use and check if the opponent is within range.

ShoukangHong commented 2 years ago

For now, I think this function can be replaced by this. Unlike the range list which only stores 'red' tiles, the range table stores all the tiles that are in attack range. Enemy units will be able to cast skills to their friends with this setup.

Game_BattlerBase.prototype.isTargetInRange = function(item) {
        var target = $gameTemp.targetEvent();
        return $gameTemp.RangeTable(target.posX(), target.posY())[0] >= 0;
};

You remind me that when the target tries to counter-attack, they will also call the canUse() function... which makes the matter worse. For example, the user's skill can go through the wall but the target cannot... Making range tables for both the user and the target is the right solution, but yes it's difficult.

Echizen-ham commented 2 years ago

Yes, that's a good point. Therefore, instead of using the existing range table and range list, I created a new range list for the battle scene and introduced a mechanism to judge can Use based on it. The srpgRangeControl created by Dr.Q calculates the range without using the range table (common function) (a great technique). Therefore, it is now possible to create a new independent range list for each unit.

ShoukangHong commented 2 years ago

That's great. I think it's also worth the time to compile all the range checks in one function and call that function in canUse(). The current canUse() function is too complex. Some of the battle state checks can also be simplified as ['invoke_action', 'auto_actor_action','enemy_action', 'battle_window'].contains($gameSystem.isSubBattlePhase())

Echizen-ham commented 2 years ago

interesting! I haven't studied java script properly, and I'm making it by imitating the RPG maker plugin, so that kind of content is very educational. I will improve it!