static void CheckCombineAim(NPCInst hero, Vec3f direction) { var gModel = hero.BaseInst.gModel; int aniID; if (gModel.IsAnimationActive("S_BOWAIM")) { aniID = gModel.GetAniIDFromAniName("S_BOWAIM"); } else if (gModel.IsAnimationActive("S_CBOWAIM")) { aniID = gModel.GetAniIDFromAniName("S_CBOWAIM"); } else { if (freeAim) { crosshair.Hide(); } return; } if (freeAim) { crosshair.Show(); } Angles heroAngles = hero.GetAngles(); Angles angles = Angles.FromAtVector(direction); float pitch = Angles.Difference(angles.Pitch, heroAngles.Pitch); float yaw = Angles.Difference(angles.Yaw, heroAngles.Yaw); float x = 0.6f;// Alg.Clamp(0, 0.5f - yaw / Angles.PI, 1); float y = Alg.Clamp(0, 0.47f - (pitch < 0 ? 1.2f : 1.0f) * pitch / Angles.PI, 1); hero.BaseInst.gAI.InterpolateCombineAni(x, y, aniID); }
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); } }
static void DoTurning(NPCInst hero) { if (hero.BaseInst.gAI.GetFoundLedge()) { return; } const float maxTurnFightSpeed = 0.07f; NPCInst enemy = PlayerFocus.LockedTarget; if (enemy != null) { Vec3f heroPos = hero.GetPosition(); Vec3f enemyPos = enemy.GetPosition(); float bestYaw = Angles.GetYawFromAtVector(enemyPos - heroPos); Angles curAngles = hero.GetAngles(); float yawDiff = Angles.Difference(bestYaw, curAngles.Yaw); curAngles.Yaw += Alg.Clamp(-maxTurnFightSpeed, yawDiff, maxTurnFightSpeed); hero.SetAngles(curAngles); CheckCombineAim(hero, enemyPos - heroPos); return; } const float maxLookupSpeed = 2f; float rotSpeed = 0; if (InputHandler.MouseDistY != 0) { rotSpeed = Alg.Clamp(-maxLookupSpeed, InputHandler.MouseDistY * 0.35f * MouseSpeed, maxLookupSpeed); if (hero.Environment.WaterLevel >= 1) { hero.BaseInst.gAI.DiveRotateX(rotSpeed); } else { var cam = zCAICamera.CurrentCam; cam.BestElevation = Alg.Clamp(-50, cam.BestElevation + rotSpeed, 85); } } // Fixme: do own turning const float maxTurnSpeed = 2f; if (!KeyBind.Action.IsPressed()) { float turn = 0; if (KeyBind.TurnLeft.IsPressed()) { turn = -maxTurnSpeed; } else if (KeyBind.TurnRight.IsPressed()) { turn = maxTurnSpeed; } else if (Math.Abs(InputHandler.MouseDistX) > ((rotSpeed > 0.5f && hero.Movement == NPCMovement.Stand) ? 18 : 2)) { turn = Alg.Clamp(-maxTurnSpeed, InputHandler.MouseDistX * 0.45f * MouseSpeed, maxTurnSpeed); } if (turn != 0) { hero.BaseInst.gAI.Turn(turn, !hero.ModelInst.IsInAnimation()); return; } } hero.BaseInst.gVob.AniCtrl.StopTurnAnis(); }