-
Notifications
You must be signed in to change notification settings - Fork 83
KillCommand, Improve Warp and Buff command, Level Up Potion #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3800ced
KillCommand, Improve Warp and Buff command, Level Up Potion
Zintixx 31e62f2
Check for Job Advance
Zintixx ff58cca
remove broadcast of buff removal. already happens upon remove func
Zintixx a50c465
Debug line
Zintixx 8bc6daa
formatting
Zintixx 7d47a0d
formatting never ends
Zintixx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| using System.CommandLine; | ||
| using System.CommandLine.Invocation; | ||
| using System.CommandLine.IO; | ||
| using System.Numerics; | ||
| using Maple2.Model.Enum; | ||
| using Maple2.Model.Metadata; | ||
| using Maple2.Server.Game.Model; | ||
| using Maple2.Server.Game.Model.Skill; | ||
| using Maple2.Server.Game.Packets; | ||
| using Maple2.Server.Game.Session; | ||
| using Maple2.Tools.Collision; | ||
|
|
||
| namespace Maple2.Server.Game.Commands; | ||
|
|
||
| public class KillCommand : Command { | ||
| private const string NAME = "kill"; | ||
| private const string DESCRIPTION = "Kill NPCs and/or Mobs."; | ||
|
|
||
| public KillCommand(GameSession session) : base(NAME, DESCRIPTION) { | ||
| AddCommand(new KillAllNpcCommand(session)); | ||
| AddCommand(new KillNearNpcCommand(session)); | ||
| } | ||
|
|
||
| private class KillAllNpcCommand : Command { | ||
| private readonly GameSession session; | ||
|
|
||
| public KillAllNpcCommand(GameSession session) : base("all", "Kill all NPCs in map.") { | ||
| this.session = session; | ||
|
|
||
| var npcOnly = new Option<bool>("npc", () => false, "Kill only npcs."); | ||
| var mobOnly = new Option<bool>("mob", () => false, "Kill only mobs."); | ||
|
|
||
| AddOption(npcOnly); | ||
| AddOption(mobOnly); | ||
| this.SetHandler<InvocationContext, bool, bool>(Handle, npcOnly, mobOnly); | ||
| } | ||
|
|
||
| private void Handle(InvocationContext ctx, bool npcOnly, bool mobOnly) { | ||
| if (!session.SkillMetadata.TryGet(10000001, 1, out SkillMetadata? skill)) { | ||
| ctx.Console.Out.WriteLine("Skill not found."); | ||
| return; | ||
| } | ||
|
|
||
| if (npcOnly == mobOnly) { | ||
| // Consider both to be true | ||
| foreach (FieldNpc npc in session.Field.Npcs.Values) { | ||
| Kill(session, npc, skill); | ||
|
|
||
| } | ||
| foreach (FieldNpc npc in session.Field.Mobs.Values) { | ||
| Kill(session, npc, skill); | ||
| } | ||
| ctx.Console.Out.WriteLine("All NPCs and Mobs removed."); | ||
| return; | ||
| } | ||
|
|
||
| if (npcOnly) { | ||
| foreach (FieldNpc npc in session.Field.Npcs.Values) { | ||
| Kill(session, npc, skill); | ||
| } | ||
| ctx.Console.Out.WriteLine("All NPCs removed."); | ||
| } else { | ||
| foreach (FieldNpc npc in session.Field.Mobs.Values) { | ||
| Kill(session, npc, skill); | ||
| } | ||
| ctx.Console.Out.WriteLine("All Mobs removed."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private class KillNearNpcCommand : Command { | ||
| private readonly GameSession session; | ||
|
|
||
| public KillNearNpcCommand(GameSession session) : base("near", "Kill mobs/npcs within a given range.") { | ||
| this.session = session; | ||
|
|
||
| var distance = new Option<int>(["--distance", "-d"], () => 150, "Radius to kill mobs/npcs."); | ||
|
|
||
| AddOption(distance); | ||
| this.SetHandler<InvocationContext, int>(Handle, distance); | ||
|
|
||
| } | ||
|
|
||
| private void Handle(InvocationContext ctx, int distance) { | ||
| var rec = new Rectangle(new Vector2(session.Player.Position.X, session.Player.Position.Y), distance, distance, 0); | ||
| var prism = new Prism(rec, session.Player.Position.Z, distance * 2); | ||
| if (!session.SkillMetadata.TryGet(10000001, 1, out SkillMetadata? skill)) { | ||
| ctx.Console.Out.WriteLine("Skill not found."); | ||
| return; | ||
| } | ||
| foreach (FieldNpc npc in session.Field.Npcs.Values) { | ||
| if (prism.Intersects(npc.Shape)) { | ||
| ctx.Console.Out.WriteLine($"Killing {npc.Value.Metadata.Name} - ObjectId: ({npc.ObjectId})"); | ||
| Kill(session, npc, skill); | ||
| } | ||
| } | ||
|
|
||
| foreach (FieldNpc npc in session.Field.Mobs.Values) { | ||
| if (prism.Intersects(npc.Shape)) { | ||
| ctx.Console.Out.WriteLine($"Killing {npc.Value.Metadata.Name} - ObjectId: ({npc.ObjectId})"); | ||
| Kill(session, npc, skill); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void Kill(GameSession session, FieldNpc npc, SkillMetadata skill) { | ||
| var damageRecord = new DamageRecord(skill, skill.Data.Motions[0].Attacks[0]) { | ||
| CasterId = session.Player.ObjectId, | ||
| TargetUid = ((long) Random.Shared.Next(int.MinValue, int.MaxValue) << 32) | (uint) Random.Shared.Next(int.MinValue, int.MaxValue), | ||
| OwnerId = session.Player.ObjectId, | ||
| SkillId = skill.Id, | ||
| Level = skill.Level, | ||
| AttackPoint = 0, | ||
| MotionPoint = 0, | ||
| Position = npc.Position, | ||
| Direction = session.Player.Rotation, | ||
| }; | ||
| var target = new DamageRecordTarget() { | ||
| ObjectId = npc.ObjectId, | ||
| Position = session.Player.Position, | ||
| Direction = session.Player.Rotation, | ||
| }; | ||
|
|
||
| long damage = npc.Stats.Values[BasicAttribute.Health].Current; | ||
| target.AddDamage(DamageType.Normal, damage); | ||
| damageRecord.Targets.Add(target); | ||
| npc.Stats.Values[BasicAttribute.Health].Add(-damage); | ||
| session.Field.Broadcast(StatsPacket.Update(npc, BasicAttribute.Health)); | ||
|
|
||
| session.Field.Broadcast(SkillDamagePacket.Damage(damageRecord)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.