• 0
Seravy

How to find nearest enemy/obtain a list of units on the same map, etc...

Question

I'm trying to implement a @ command that makes the character have limited autopilot capabilities like, buff or attack the nearest thing. I'm playing the game alone on my server and would like to use multiple characters...but there is a limit to how many I can play actively at a time, and it's not very fun to do it that way. I tried using a bot but it didn't work but then I realized "hey I can just make the server do it for me, even better and I get to code all the AI". Yes, I'm crazy enough to play RO as a single player game, but even then, I'm going to need a party to fight the stronger enemies  :)

So I was able to add the command (and tested it actually works by outputting a message), made it get stored in a variable : sd->autopilotmode = 1;, added a new timer to unit.cpp, got as far as


// @autopilot timer
int unit_autopilot_timer(int tid, unsigned int tick, int id, intptr_t data)
{
	struct block_list *bl;
	struct unit_data *ud;
	int target_id;

	bl = map_id2bl(id);

	if (!bl || bl->prev == NULL)
		return 0;

	ud = unit_bl2ud(bl);

	if (!ud)
		return 0;


	if (bl->type != BL_PC) // Players are handled by map_quit
	{
		ShowError("Nonplayer set to autopilot!");
		return 0;
	}

	struct map_session_data *sd = (struct map_session_data*)bl;

	if (sd->status.autopilotmode==0) {

		return 0;
	}

	// Tanking mode is set
	if (sd->status.autopilotmode == 1) 	{



	}

 

although this is mostly guessing so far, but here I'm stuck. How do I find the nearest enemy (or party member, for buffs) to target? Tried searching for other code parts that target monster attacks and similar but it looks way too complicated. It's hard without even knowing what each structure is for. Didn't see any Findnearest kind of functions anywhere either. In fact I don't even know how to access a list of units on the same map. I think I'm going to need to call "clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)" to execute the action but first I need to somehow find a target.

Share this post


Link to post
Share on other sites

Recommended Posts

  • 0
Posted (edited)

Is there a function I can call to check if a specific map tile has a Warp Portal active? I'd like to make the AI automatically enter warps I open so I don't have to move them all manually. If not, are warp portals stored as one of those "skillunit" things on the player who opened them?

Nevermind, checking skillunits on all players on the map worked.

(I haven't been able to work on RO much recently because I was busy buying a new computer and reinstalling everything. I didn't give up on this, don't worry!)

Edited by Seravy

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)

I'm experimenting with the Ninja class, never played it before.

AI for the magic skills and throw skills probably won't be an issue, they are just DPS skills used at range like most such skills. (though the zeny one seems useless, it'll always cost more than the loot from the monster is worth...)

However no idea what to do with the melee skills.

Haze Slasher - this hits the enemy then hides. Hiding makes no sense in tanking mode and you can't use this in other modes due to having no range. So probably use this as an "emergency reaction" like safety wall or various quick casting time spells on mages and wizards? I guess 200% isn't really high enough to consider this a DPS skill.

Shadow Leap - I'd expect this is for getting close to an enemy when in melee/tanking mode. But you have to be hiding and the only way to do so is the skill we are not using in that mode. So instead it's for moving away from enemies then?

Shadow Slash - this is where things go wrong first. This seems to be the main melee DPS skill but you have to hide first. So you'd need to either use the hide skill in tanking mode which breaks the AI if the user intends the Ninja to actually tank, or used in "skill" = dps mode but then the dps mode has to walk the character near the enemy which is something only the tanking mode does. Neither seems good so this would probably go into the "tank+" mode which is basically tanking mode using class specific skills you normally don't want to use, for example on a Monk, Steel Body is exclusive t this mode.

Cicada Skin Shed - This one is ugly. It prevents physical damage so you want it in melee/tanking mode, but it also moves you away from the enemy so you don't. I guess use it for the "skill" mode instead to avoid stray incoming attacks?

Mirror Image - this has no backwards movement but has a casting time which seems a bad idea to try to cast during combat.

Killing Strike - I guess this should follow a similar protocol as Asura Strike (except instead of SP and Fury, check HP, Ninja Aura and Mirror Image)? So basically a "boss only" skill?

Edit : Okay, so after trying Throw Shuriken I came to realize using this class for melee is not practical anyway. The skill costs 2 SP so it's basically free and has no (aspd only?) delay and a minimal cost while doing 1x ATK damage plus whatever skill bonus. So it's equivalent to a ranged normal attack. Meanwhile the melee skills do 2x and 5x ATK damage which sounds good but cost a lot of SP and ultimately it's still not as good as Bash. So it's like trying to use Bash with an Archer, even if I could, why would I want to if I'm not tanking either way? I guess it's useful if Shurikens run out and that's about it...

So that means :

Haze Slasher - this is useless. Cicada already takes care of avoiding damage when using skills from a range and we don't want to hide when tanking. Using melee on a ranged class without the intention to tank is not something that AI needs to be able to do. This automatically makes Shadow Leap and Shadow Slash AI unusable as well. If there are no items left to throw, there is still Throw Huuma Shuriken.

Flip Tatami, Cicada Skin Shed - Limit these to the "skill" mode and avoid using them when tanking and it should be fine.

...or not. Just realized Flip Tatami has 3 seconds of cast delay. That's totally useless, a Ninja can't attack from range without using skills and this knocks away melee enemies. I suppose you can use it to tank and never get hurt which is great except Pnemua does the same thing better and what kind of RO party doesn't want a priest?

Edited by Seravy

Share this post


Link to post
Share on other sites
  • 0

first you need to enable the commands, like all other GM commands.

@autopilot to turn it on, if you type it without a parameter it gives you a list of possible parameters.

Tanking mode makes the character go to the monster and hit it with short range skills. Skill mode makes the character use damage skills. Support mode does neither but still uses support skills. All modes follow the party leader, so it's strongly recommended for the leader to be the character you are playing.

@autopilotsp <sp percentage> to specify the character should use SP items below that much SP.

@autosong to specify which song or dance to play.

@autoconc enables... I think it was the Concentration skill for Lord Knights or something? The one that lowers DEF and increases ATK or something like that.

The feature assumes there are no other players on the server, for example buffing isn't limited to your party members, the priest will try to buff anyone she sees.

Share this post


Link to post
Share on other sites
  • 0
4 hours ago, Seravy said:

first you need to enable the commands, like all other GM commands.

@autopilot to turn it on, if you type it without a parameter it gives you a list of possible parameters.

Tanking mode makes the character go to the monster and hit it with short range skills. Skill mode makes the character use damage skills. Support mode does neither but still uses support skills. All modes follow the party leader, so it's strongly recommended for the leader to be the character you are playing.

@autopilotsp <sp percentage> to specify the character should use SP items below that much SP.

@autosong to specify which song or dance to play.

@autoconc enables... I think it was the Concentration skill for Lord Knights or something? The one that lowers DEF and increases ATK or something like that.

The feature assumes there are no other players on the server, for example buffing isn't limited to your party members, the priest will try to buff anyone she sees.

and who is use that command the party leader?
really nice 😄 i'll try it

Share this post


Link to post
Share on other sites
  • 0

You use it on every character individually, except the one you want to play manually. Good luck and don't forget it's a WIP, you can read the previous posts to get an idea which classes work and which do not.

Share this post


Link to post
Share on other sites
  • 0

Geez, Gravity.

https://ragnarok.gamepedia.com/RO_Patch_(2019_Mar._06)

Why is it always the classes I want to make AI for? I'm stuck on 1st classes because of the ongoing rebalancing of those and now it's ninjas?

Although having seen what Throw Huuma Shuriken does currently, yeah, anything is better than that.

So I guess I put my Ninja away for a year now, waiting for this to get into Rathena? Eh, whatever, I can change the casting time and such myself.

  • MVP 1

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)

Status report : AI for Throw Shuriken, Throw Kunai, Throw Huuma Shuriken, and Flip Tatami works. I changed Flip Tatami to have a cooldown instead of a skill delay, making it still a lot worse than Pneuma but at least playable. Without that modification, disabling the AI code for that skill is strongly recommended.

The AI isn't use Throw Zeny - without modding the skill, it's useless anyway. In made it have no delay and no damage reduction on bosses for my server - it's still nowhere near as good as Cart Termination considering this eats like 5 times the zeny but again, at least playable.

I'm unsure what to do with the hide and strike skills, they'll likely remain unplayable for the AI no matter what as damage skills. Even if I increase the damage of these skills, I find it hard to come up with a valid reason why are they worth picking instead of throwing something, even less a reason commonly occurring that's worth teaching for the AI. (or using magic, I haven't yet looked at magic at all...).

However as a "hide to avoid getting targeted" ability, they might be useful. I see I haven't even made the AI use the thief's Hiding skill. Maybe something like "use if targeted by enemies, only if not in tanking mode, then immediately cancel to regain the ability to fight" could be helpful? Not sure... the problem is, the character the monster targets instead might be even less tanky or more important. Like if the ninja/thief hides and the monster starts attacking the wizard or priest that's really bad. So I think it's best if the AI stays away from these skills.

I also see one good use of these for a human player, using a Smokie card to hide then using the Shadow Slash skill to effectively teleport to the next monster and one-shot it. I can see this being faster than walking and using thrown skills but it's not something the AI can or is meant to do.

Ninja Aura, Cicada Skin Shedding, Mirror Image : Implemented these as well.

Mirror Image : Most wikis seem to say it's useless because it's same effect as Cicada but I think we can use this very well. If the AI is in tanking mode, you don't want to move backwards, that's very important. It also blocks 2 more hits. Unfortunately it has a casting time but it's reasonably low. Also unfortunately it's interruptable, but against normal mobs, they die quickly, giving a chance to recast it before moving to the next monster. Alternately the player can wear "casting is uninterruptable" equipment which allows recasting this while actively tanking mobs. This skill is far better than it looks like at first sight. So this is for AI use in tanking mode while Cicada will be used for other modes only. For a while I was thinking about changing the skill but I'm sure it's playable as is.

Killing Strike deals ~20K damage on a max level Ninja, ~50K on Oboro. That is...not impressive. I guess maxhp equipment can even double that but still not anywhere near as good as Asura - and you die. Although, that's better than getting stuck with no SP. On the other hand this actually is easy to make AI rules for. "target hp at least 80% of the expected damage and party has priest -> use, otherwise don't" sounds about right. 20k+ damage for spending a blue gem and some heals isn't such a bad deal.

Wait, Ninja Aura costs HP to use? That's crazy, I'm removing that. Seriously, this isn't even as good as half of Blessing, why? Shouldn't make a difference for the AI though, the HP cost isn't enough to really matter for the "normal" use of the skill. But it is annoying before Killing Strike where hp is the main component of the damage output...

Edited by Seravy

Share this post


Link to post
Share on other sites
  • 0

Killing Strike AI now works.

Let's see the magic!

Flaming Petals - This is Fire Bolt with reduced damage, higher SP cost, about double the casting time and no skill delay. Considering Ninja also gets worse matk equipment than mages, this is pretty much unplayable. Casting it once takes more time than throwing 3 kunais for the same damage output (and that's assuming the worst case damage formula for kunai). Unplayable, I have to make it better...

Freezing Spear - More of the same. 2 more hits than colt bolt but total damage is still only 840% instead of 1000%, higher casting time (especially considering there is an additional rebalancing coming for the bolts to make them even better), will have to change this skill too.

Wind Blade - Again, 900% total damage, but this one comes in 6 hits so considering MDEF, this is overall as good or better than Lighting Bolt. Casting time is not as high as the other two either. This needs less improving but does need some - Ninja isn't a 1st class, so their skills should be slightly better than mages, but worse than wizards.

For the AI, these are easy, same as bolt spells. Trivial to implement.

Blaze Shield - This is unique. It doesn't work like normal AOE skills - each map tile is limited in the number of hits so if multiple monsters are on the same tile, it won't be effective. Instead of the usual AOE code, triggering it on multiple melee monsters heading towards the caster might work well - but that won't happen much unless we are in tanking mode and this is interruptable so if any monster actually manages to reach and attack, it fails. Sounds like something for ninjas with "uninterruptable cast" equipment only. Even then, it's best used by casting it then kiting the monster through as much tiles as possible - the AI can't do that. I think this should stay human use only. Also, even considering the item cost this is so much faster to cast for dealing much more potential damage than Flaming Petals, it's ridiculous, FP definitely needs buffing. It's sad Gravity's patch doesn't seem to do that.

Exploding Dragon - This is basically a Fireball with more damage and casting time - same AI should work except the part that uses it as a quick spell in emergencies. Fireball is 170% damage, this one is 900%. Basically same damage as Flaming Petals but faster and AOE. What is Flaming Petals for, then? (well, ok, this costs an item but still... I think Flame Petals should have similar casting time as this.)

Watery Evasion - Quagmire wannabe, but not instant cast, interruptable, actually very slow to cast, useless. Also costs an item and effect is weaker on AGI  than Quagmire. I'm going to buff this one for sure. For the AI, probably useless. AGI and DEX reduction was the important part, making it easier to tank the monsters. The AI doesn't use Quagmire to slow movement and run away.

Snow Flake Draft - Low AOE, self targeted, single hit, low damage. This is useful for high chance of freezing, effectively a Frost Nova. Except unlike Frost Nova the casting time is too high so it can't be used for crowd control. Another completely useless skill that needs buffing 😞

Lightning Jolt - This is finally a normal AOE spell but damage is a joke. 350% MATK, really? Even the 1st class Thunderstorm is 800% total although this one seems faster. Fortunately Gravity increased it so I might as well do the same. AI should be same as Thunderstorm, copy-paste, yay.

First Wind - 600% MATK but this isn't hitting a proper AOE, instead it hits a line. The problem? The AOE AI targets a tanking player or other stationary point, assuming monsters will likely head towards that point so anything in the AOE, stays inside the AOE. This skill doesn't work like that. Even if the monster does move towards the tank, it might not stay in the narrow line the spell hits. I see no other solution than to code this as if it was a 1x1 AOE and hope all monsters on the tile head towards the same target. It's targeted so it will at least follow the chosen target's movement. Not ideal but playable for the AI at least.

There is one more thing to worry about. We have to compare the character's ATK and MATK to decide if we even want to use magic with it at all, or throwing things is better. And the ratio for that depends on how I set up my spells. It will need to be adjusted for servers with official skill configurations.

Edited by Seravy

Share this post


Link to post
Share on other sites
  • 0

Ninja class AI is finally done.

https://github.com/SeravySensei/rathena/commit/0dbe0a51a9c6db488558f4ced8588d84f930a9f3

Fixing up the skills to be playable was almost as hard as making the AI. Most underpowered class I worked on so far?

I guess next will be the Gunslinger or the Hunter but for the time being I'll just enjoy playing my Ninja.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...