static void SetFocus(BaseVobInst target) { if (focusVob == target) { return; } focusVob = target; NPCInst.Hero.BaseInst.gVob.SetFocusVob(target == null ? new zCVob(0) : target.BaseInst.gVob); }
/// <summary> Gets a vob by ID from this world. </summary> public bool TryGetVob(int id, out BaseVobInst vob) { WorldObjects.BaseVob baseVob; if (this.baseWorld.TryGetVob(id, out baseVob)) { vob = (BaseVobInst)baseVob.ScriptObject; return(true); } vob = null; return(false); }
static bool CanSee(Vec3f start, Vec3f end, BaseVobInst target) { using (zVec3 zStart = start.CreateGVec()) using (zVec3 zDir = (end - start).CreateGVec()) { var zWorld = GothicGlobals.Game.GetWorld(); if (zWorld.TraceRayFirstHit(zStart, zDir, zCWorld.zTraceRay.Ignore_Alpha | zCWorld.zTraceRay.Ignore_NPC | zCWorld.zTraceRay.Ignore_Vob_No_Collision)) { return(zWorld.Raytrace_FoundVob.Address == target.BaseInst.gVob.Address); } } return(true); }
public GoToVobLookAtCommand(BaseVobInst target, float distance = 500) : base(target, 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 SetTarget(BaseVobInst vob) { this.targetVob = vob; this.targetPos = Vec3f.Null; }
public GoToVobCommand(BaseVobInst target, float distance = 500f) : base(target.BaseInst, distance) { }
void RemoveVobHandler(BaseVobInst vob, WorldInst world) { RemoveVob((T)vob); }