Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Maple2.Server.Game/Manager/Field/AgentNavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ public bool UpdatePosition() {
return true;
}

public bool UpdatePosition(Vector3 position) {
if (!field.FindNearestPoly(position, out _, out RcVec3f rcPosition)) {
Logger.Error("Failed to find valid position from {Source} => {Position}", npc.Position, rcPosition);
return false;
}

agent.npos = rcPosition;
npc.Position = DotRecastHelper.FromNavMeshSpace(rcPosition);
return true;
}

public Vector3 GetAgentPosition() {
return DotRecastHelper.FromNavMeshSpace(agent.npos);
}
Expand Down Expand Up @@ -229,7 +240,7 @@ public Vector3 GetRandomPatrolPoint() {
return DotRecastHelper.FromNavMeshSpace(randomPt);
}

public Vector3 FindClosestPoint(Vector3 point, int maxDistance, Vector3 fallback) {
public Vector3 FindRandomPointAround(Vector3 point, int maxDistance, Vector3 fallback) {
if (!field.FindNearestPoly(point, out long closest, out RcVec3f position)) {
return fallback;
}
Expand All @@ -244,8 +255,8 @@ public Vector3 FindClosestPoint(Vector3 point, int maxDistance, Vector3 fallback
return DotRecastHelper.FromNavMeshSpace(randomPt);
}

public Vector3 FindClosestPoint(Vector3 point, int maxDistance) {
return FindClosestPoint(point, maxDistance, DotRecastHelper.FromNavMeshSpace(agent.npos));
public Vector3 FindRandomPointAround(Vector3 point, int maxDistance) {
return FindRandomPointAround(point, maxDistance, DotRecastHelper.FromNavMeshSpace(agent.npos));
}

public bool PathTo(Vector3 goal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,6 @@ private void Idle(string sequence = "") {
}
}

public void Died() {
SetState(ActorState.Dead);

UpdateControl();

Velocity = new Vector3(0, 0, 0);
}

public void StateRegenEvent(string keyName) {
switch (keyName) {
case "end":
Expand Down Expand Up @@ -196,9 +188,7 @@ public void Update(long tickCount) {

Velocity = new Vector3(0, 0, 0);

if (actor.Stats.Values[BasicAttribute.Health].Current == 0) {
SetState(ActorState.Dead);

if (actor.IsDead) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

using Maple2.Model.Common;
using Maple2.Model.Metadata;
using Maple2.Model.Metadata;
using Maple2.Server.Game.Model.Skill;
using System.Numerics;
using static Maple2.Server.Game.Model.ActorStateComponent.TaskState;
Expand Down Expand Up @@ -29,16 +27,14 @@ public void StateSkillEvent(string keyName) {
actor.AppendDebugMessage(actor.AnimationState.PlayingSequence.Name);
}

if (castSkill.Motion.AttackPoints.ContainsKey(keyName)) {
if (castSkill.Motion.AttackPoints.TryGetValue(keyName, out byte point)) {
var targets = new List<IActor>();

// TODO: change BattleState to track a list of targets for multi projectile skills & use that instead
if (actor.BattleState.Target is not null) {
targets.Add(actor.BattleState.Target);
}

byte point = castSkill.Motion.AttackPoints[keyName];

if (point != 0xFF) {
actor.SkillState.SkillCastAttack(castSkill, point, targets);
} else {
Expand Down Expand Up @@ -126,12 +122,7 @@ private void StateSkillCastMoveUpdate(long tickCount, long tickDelta, float delt
castMoveLastTick = castMoveTick;
}

int searchRadius = Math.Max((int) Math.Ceiling(offset.Length()), 0) + 10;

Vector3 lastPosition = actor.Position;

actor.Navigation!.UpdatePosition();
actor.Position = actor.Navigation.FindClosestPoint(newPosition, searchRadius, actor.Position);
actor.Navigation!.UpdatePosition(newPosition);

float timeStep = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ public bool IsMovingToTarget() {

private void StateWalkDirectionUpdate(long tickCount, long tickDelta, float delta) {
Vector3 newPosition = actor.Position + delta * Speed * walkDirection;
int searchRadius = Math.Max((int) (delta * Speed * 1.1f), 10);

actor.Navigation!.UpdatePosition();
actor.Position = actor.Navigation.FindClosestPoint(newPosition, searchRadius);
actor.Navigation!.UpdatePosition(newPosition);

Velocity = Speed * walkDirection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,5 @@ private void SkillCast(NpcSkillCastTask task, int id, short level, long uid, byt
SetState(ActorState.PcSkill);

stateSequence = sequence;

return;
}
}
2 changes: 1 addition & 1 deletion Maple2.Server.Game/Model/Field/Actor/FieldNpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public override void Update(long tickCount) {
}
}

bool isSpawning = MovementState.State == ActorState.Spawn || MovementState.State == ActorState.Regen;
bool isSpawning = MovementState.State is ActorState.Spawn or ActorState.Regen;

if (!isSpawning) {
BattleState.Update(tickCount);
Expand Down
2 changes: 0 additions & 2 deletions Maple2.Server.Game/Packets/NpcControlPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using Maple2.Server.Core.Constants;
using Maple2.Server.Core.Packets;
using Maple2.Server.Game.Model;
using Maple2.Server.Game.Model.State;
using Maple2.Tools.Extensions;
using System.Numerics;

namespace Maple2.Server.Game.Packets;
Expand Down