void UpdateOrientation() { const float distMax = 180; const float distMin = 0; if (distance < distMin) { distance = distMin; } else if (distance > distMax) { distance = distMax; } float offsetY = (distance - 100) * 0.4f - 20; vis.RotationYaw = Angles.Deg2Rad(rotation); vis.OffsetY = offsetY; vis.OffsetZ = distance; }
static void Update() { NPCInst hero = currentPlayer; if (hero == null) { Deactivate(); return; } float maxYaw = Angles.Deg2Rad(60); bool fightMode = hero.IsInFightMode; ItemInst wep = hero.GetDrawnWeapon(); float maxRange = (fightMode && wep != null && wep.IsWepRanged) ? 3000 : 400; Vec3f heroPos = hero.GetPosition(); Angles heroAng = hero.GetAngles(); float bestFit = 2.0f; BaseVobInst bestVob = null; if (hero?.World?.BaseWorld != null) { hero.World.BaseWorld.ForEachVob(v => { BaseVobInst vob = (BaseVobInst)v.ScriptObject; if (vob == hero) { return; } bool hasPriority = false; if (fightMode) { if (!(vob is NPCInst npc)) { return; } if (npc.IsDead) { return; } if (bestVob != null) { NPCInst bestNPC = (NPCInst)bestVob; if (npc.IsUnconscious) { if (!bestNPC.IsUnconscious) { return; // alive targets are more important } } else { if (bestNPC.IsUnconscious) { hasPriority = true; } } if (npc.TeamID == hero.TeamID) { if (bestNPC.TeamID != hero.TeamID) { return; } } else { if (bestNPC.TeamID == hero.TeamID) { hasPriority = true; } } } } Vec3f targetPos; using (zVec3 z = zVec3.Create()) { vob.BaseInst.gVob.BBox3D.GetCenter(z); targetPos = (Vec3f)z; } float distance = heroPos.GetDistance(targetPos); if (distance > maxRange) { return; } float yaw = Angles.GetYawFromAtVector(targetPos - heroPos); yaw = Math.Abs(Angles.Difference(yaw, heroAng.Yaw)); if (yaw > maxYaw) { return; // target is not in front of hero } if (!CanSee(heroPos, targetPos, vob)) { return; } float fit = distance / maxRange + yaw / maxYaw; if (hasPriority || fit < bestFit) { bestVob = vob; bestFit = fit; } }); SetFocus(bestVob); } }
public void KeyPressed(VirtualKeys key) { if (!enabled) { return; } switch (key) { case VirtualKeys.Right: SetCursor(cursor.X + 1, cursor.Y); return; case VirtualKeys.Left: SetCursor(cursor.X - 1, cursor.Y); return; case VirtualKeys.Up: SetCursor(cursor.X, cursor.Y - 1); return; case VirtualKeys.Down: SetCursor(cursor.X, cursor.Y + 1); return; // left/right case VirtualKeys.Numpad4: descrVis.OffsetX -= 5; break; case VirtualKeys.Numpad6: descrVis.OffsetX += 5; break; // up / down case VirtualKeys.Numpad8: descrVis.OffsetY += 5; break; case VirtualKeys.Numpad2: descrVis.OffsetY -= 5; break; // forth / back case VirtualKeys.Add: descrVis.OffsetZ -= 5; break; case VirtualKeys.Subtract: descrVis.OffsetZ += 5; break; // rotation yaw case VirtualKeys.Numpad7: descrVis.RotationYaw -= Angles.Deg2Rad(5); break; case VirtualKeys.Numpad9: descrVis.RotationYaw += Angles.Deg2Rad(5); break; // rotation roll case VirtualKeys.Numpad1: descrVis.RotationRoll -= Angles.Deg2Rad(5); break; case VirtualKeys.Numpad3: descrVis.RotationRoll += Angles.Deg2Rad(5); break; // rotation pitch case VirtualKeys.Divide: descrVis.RotationPitch += Angles.Deg2Rad(5); break; case VirtualKeys.Multiply: descrVis.RotationPitch -= Angles.Deg2Rad(5); break; default: return; } Log.Logger.Log("Offset: ({0} {1} {2}) Rotation: ({3} {4} {5})", descrVis.OffsetX, descrVis.OffsetY, descrVis.OffsetZ, descrVis.RotationPitch, descrVis.RotationYaw, descrVis.RotationRoll); }