Jump to content
  • 0

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


Seravy

Question


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.02
  • Content Count:  176
  • Reputation:   60
  • Joined:  01/11/19
  • Last Seen:  

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.

Link to comment
Share on other sites

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.02
  • Content Count:  176
  • Reputation:   60
  • Joined:  01/11/19
  • Last Seen:  

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
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.02
  • Content Count:  176
  • Reputation:   60
  • Joined:  01/11/19
  • Last Seen:  

Now that things actually run at an acceptable speed on my new computer, I tried making a proper branch for this feature : https://github.com/SeravySensei/rathena/tree/Autopilot

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.02
  • Content Count:  176
  • Reputation:   60
  • Joined:  01/11/19
  • Last Seen:  

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
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  107
  • Topics Per Day:  0.02
  • Content Count:  770
  • Reputation:   69
  • Joined:  02/10/12
  • Last Seen:  

btw how to use your autopilot?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.02
  • Content Count:  176
  • Reputation:   60
  • Joined:  01/11/19
  • Last Seen:  

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.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  107
  • Topics Per Day:  0.02
  • Content Count:  770
  • Reputation:   69
  • Joined:  02/10/12
  • Last Seen:  

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

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.02
  • Content Count:  176
  • Reputation:   60
  • Joined:  01/11/19
  • Last Seen:  

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.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.02
  • Content Count:  176
  • Reputation:   60
  • Joined:  01/11/19
  • Last Seen:  

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
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.02
  • Content Count:  176
  • Reputation:   60
  • Joined:  01/11/19
  • Last Seen:  

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
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.02
  • Content Count:  176
  • Reputation:   60
  • Joined:  01/11/19
  • Last Seen:  

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
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.02
  • Content Count:  176
  • Reputation:   60
  • Joined:  01/11/19
  • Last Seen:  

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.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.02
  • Content Count:  176
  • Reputation:   60
  • Joined:  01/11/19
  • Last Seen:  

Started my work on Gunslinger AI.

Coin Flip, Increase Accuracy - this is easy, always use when idle, skill level is high and not maxed on coins, like similar self buffs that take some time.

Cracker - Use when an enemy is near and targeting us, similar to Mage's Frost Diver

Madness Canceller, Gatling Fever - not being able to move for more atk, these are very similar skills. I think the AI should specifically only activate these if the total HP of nearby enemies is above a certain threshold (maybe more than 1000% * party member count * Gunslinger's ATK?)

Adjustment - Only when under attack by a ranged enemy

Bull's Eye - Only if target is of the proper races. Considering the cast time and coin cost this skill is actually useless as is, but I adjusted that to be more worth it. I'm going to ignore the 0.1% Coma chance, not only is it too rare but on a normal monster it's not really a big deal even when it works.

Magical Bullet - Use if MAtk and AGI (for aspd) is high enough

Fling - Do not use. AI isn't smart enough to know if a target needs a defense reduction to kill or not.

Triple Action - Doesn't seem to be as good as the more specialized skills so use them only if those are not available/valid. Might get used for weapon types that have no matching specialized skills for the situation and while job level is to low to learn them.

Rapid Shower - Best skill with revolver, use as highest priority for single target

Desperado - Use as self-target AOE with the usual priorities.

Tracking - This seems strictly inferior to Rapid Shower with a Revolver so use with Rifle only? I mean 1200% damage is more than 1000% but the other is instant and uninterruptable, +200% isn't worth the casting time, is it? I guess it also consumes less ammo but does that matter? They aren't that heavy or expensive?

Piercing Shot - Casting time rivals Tracking but damage is about a quarter. Even with high Dex which can reduce casting time on this and not tracking, I don't think this is useful. Higher range (with Snake Eyes) is an advantage though, might be worth using if the enemy is too far for Tracking when equipped by a Rifle? Ability to ignore armor seems to be the selling point but I don't think the AI can properly judge when that makes this skill worth it. In fact I have no either if it's ever worth it either, are there ANY monsters that reduce 75%+ of the incoming damage not counting the unreasonable case of fighting something 50 levels higher than myself? Might be worth considering to buff this skill although I think I'll play it safe and leave it alone. Armor Piercing and bleeding might have some uses for human players at least. I might reconsider on the AI for this though. Instead of using it while still at a higher range, isn't it better to just use normal attacks? Those also have higher range, and considering the casting time, probably deal more damage overall. What's even better, they aggro the monster immediately, reducing range so Tracking will become available and other party members can also attack it. So I think the best AI for this skill is "Do not use" afterall.

 

Disarm - Useless. No effect on bosses and you usually don't need to debuff normal mobs. Might be helpful for human players though when fighting really high atk normal mobs with weak characters. AI will never use this.

Dust - ugh a close range gun skill that knocks back. Well, it is more useful than Cracker at least, for getting rid of enemies that got dangerously close.

Full Buster - this is basically Tracking but for Shotguns. Range and less casting time are the benefits, more delay, more ammo consumption and self-blinding are the drawbacks. Fair I guess? AI doesn't need anything special for it.

Spread Attack - Generic AOE code will work for this one. Damage is unimpressive but it's an instant case long range AOE so I guess it's okay. Works with grenade launchers too.

Ground Drift - Like most trap skills this also will be unusable for the AI. Oh, you can put this directly under a monster, nice then it can be used as a normal single target skill except it targets the ground....oh it has a casting time, nevermind then, the monster will likely move away... more importantly, this does 300% ATK damage, Spread Attack does 280% but that's instant. So that's strictly superior unless you are actually planning to place the mines in advance and then lure monsters on it which is clearly a human only tactic.

btw I wonder, this isn't really a question thread anymore, more like a feature development one, not sure if this is the correct place for it?

Edited by Seravy
  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.02
  • Content Count:  176
  • Reputation:   60
  • Joined:  01/11/19
  • Last Seen:  

btw a question. Double Strafe and Arrow Shower, do these have range 9+Vulture Eye or weapon range+vulture eye?

No idea what range -9 in the skilldb means.

Same for gunslinger skills and Snake Eyes, is it added to 9 or the weapons' own range?

Edit : pushed the gunslinger update. Skill ranges might be inaccurate until I get an answer to my question but the AI does use them.

That leaves Sniper (traps are a no-go for the AI so very little to do here) and Stalker (similar case, a lot are not useful for the AI, and many skills are duplicates that are already implemented from other classes) and both will get some major changes to their skills so I'll wait for that update first. Which means Taekwon/Soul Linker/Star Gladiator should be next and after that, waiting for the 1st/2nd rebalance update. After adjusting the AI to those changes, all non-3rd jobs will be done. Oh, and there is the homunculus, too.

Edited by Seravy
  • Upvote 1
Link to comment
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.

×
×
  • Create New...