public BaseVob CreateVob(byte type) { BaseVobInst vob; switch ((VobType)type) { case VobType.Vob: vob = new VobInst(); break; case VobType.Mob: vob = new MobInst(); break; case VobType.Item: vob = new ItemInst(); break; case VobType.NPC: vob = new NPCInst(); break; case VobType.Projectile: vob = new ProjInst(); break; default: throw new Exception("Unsupported VobType: " + (VobType)type); } return(vob.BaseInst); }
public AITarget(VobInst vobTarget) { this.VobTargets = new List <VobInst>() { vobTarget }; }
public static bool TryFindClosestTarget(VobInst vob, List <VobInst> vobTargets, out VobInst closestTarget) { closestTarget = null; int closestTargetIndex = -1; float closestTargetRange = float.MaxValue; float currTargetRange = float.MaxValue; for (int t = 0; t < vobTargets.Count; t++) { if (Cast.Try(vobTargets[t], out NPCInst npc) && (npc.IsDead || npc.IsUnconscious)) { continue; } currTargetRange = vob.GetPosition().GetDistance(vobTargets[t].GetPosition()); if (currTargetRange <= closestTargetRange) { closestTargetIndex = t; closestTargetRange = currTargetRange; } } if (closestTargetIndex == -1) { return(false); } else { closestTarget = vobTargets[closestTargetIndex]; return(true); } }
public void GoTo(AIAgent aiAgent, VobInst target) { foreach (var ai in aiAgent.AIClients) { GoTo(ai, target); } }
static VobInst CreateBarrier(HordeBarrier bar) { VobInst vob = new VobInst(VobDef.Get(bar.Definition)); vob.Spawn(activeWorld, bar.Position, bar.Angles); return(vob); }
public void GoTo(VobInst guided, VobInst target) { // find out if there already is an existing, similar guide-command // and recycle it if possible before assigning a new one (costly on client-side) if (guideCommandByVobInst.TryGetValue(guided, out GuideCommandInfo oldInfo)) { if (oldInfo.GuideCommand.CmdType == (byte)CommandType.GoToVob) { if (((GoToVobCommand)oldInfo.GuideCommand).Target.Equals(target)) { oldInfo.UpdateInfo(oldInfo.GuideCommand, oldInfo.GuidedVobInst, DateTime.MaxValue); return; } } } // initialize new guide and remove old one from GUC-memory automatically GoToVobCommand cmd = new GoToVobCommand(target); guided.BaseInst.SetGuideCommand(cmd); // replace possible old guide from script-memory or insert new value GuideCommandInfo info = new GuideCommandInfo(cmd, guided); SubscribeGuideCommand(info); }
VobInst CreateBarrier(HordeScenario.Barrier bar) { VobInst vob = new VobInst(VobDef.Get(bar.Definition)); vob.Spawn(World, bar.Position, bar.Angles); return(vob); }
public void UpdateInfo(GuideCmd guideCommand, VobInst guidedVobInst, DateTime expirationDate) { this.guideCommand = guideCommand; this.guidedVobInst = guidedVobInst; this.ExpirationDate = expirationDate; this.ChangeDate = DateTime.Now; }
public ModelInst(VobInst vob) { if (vob == null) { throw new ArgumentNullException("Vob is null!"); } this.vob = vob; }
public void GoTo(AIAgent aiAgent, AITarget aiTarget) { // let each client follow its nearest VobInst from aiTarget respectively VobInst closestTarget = null; foreach (var follower in aiAgent.AIClients) { if (TryFindClosestTarget(follower, aiTarget, out closestTarget)) { GoTo(follower, closestTarget); } } }
public void Add(VobInst vob) { aiClients.Add(vob); if (vob is NPCInst npc) { npc.OnHit += (a, t, d) => { if (aiPersonality is SimpleAIPersonality ai && ai.EnemyTarget == null) { ai.Attack(npc, a); } }; } }
public void Attack(AIAgent aiAgent, AITarget aiTarget) { List <VobInst> targets = aiTarget.VobTargets; VobInst closestTarget = null; if (aiTarget.VobTargets.Count < 1) { return; } // for now, let each aiClient attack its closest foe foreach (var ai in aiAgent.AIClients) { if (TryFindClosestTarget(ai, aiTarget, out closestTarget)) { Attack(ai, closestTarget); } } }
protected void UnsubscribeGuideCommand(VobInst guided) { guideCommandByVobInst.Remove(guided); }
public GuideCommandInfo(GuideCmd guideCommand, VobInst guidedVobInst) : this(guideCommand, guidedVobInst, DateTime.MaxValue) { }
public VobInstEffectHandler(string objName, List <Effect> effects, VobInst host) : base(objName, effects, host) { }
public VobInstEffectHandler(List <Effect> effects, VobInst host) : this("VobInstEffectHandler", effects, host) { }
public void TurnAround(VobInst guided, Vec3f direction, float angularVelocity) { //guided.BaseInst.SetDirection(direction); }
public void Attack(VobInst aggressor, VobInst target) { EnemyTarget = target; if (aggressor is NPCInst aggressorNPC) { if (!aggressorNPC.IsInFightMode && !aggressorNPC.ModelInst.IsInAnimation()) { ItemInst weapon; if ((weapon = aggressorNPC.GetEquipmentBySlot(NPCSlots.OneHanded1)) != null || (weapon = aggressorNPC.GetEquipmentBySlot(NPCSlots.TwoHanded)) != null) { aggressorNPC.EffectHandler.TryDrawWeapon(weapon); } else { aggressorNPC.EffectHandler.TryDrawFists(); } } float fightRange = target.ModelDef.Radius + aggressorNPC.GetFightRange(); var cmd = aggressorNPC.BaseInst.CurrentCommand; if (cmd == null || !(cmd is GoToVobLookAtCommand) || ((GoToVobLookAtCommand)cmd).Target != target) { aggressorNPC.BaseInst.SetGuideCommand(new GoToVobLookAtCommand(target, fightRange)); // -20 cm for safety } if ((aggressorNPC.CurrentFightMove == FightMoves.None || aggressorNPC.CanCombo) && target is NPCInst enemy) { FightMoves move = FightMoves.Fwd; float distance = aggressorNPC.GetPosition().GetDistance(enemy.GetPosition()); if (distance < fightRange + 20f) { if (enemy.FightAnimation != null && enemy.CurrentFightMove >= FightMoves.Fwd && enemy.CurrentFightMove <= FightMoves.Run) // in attack { if (enemy.CurrentFightMove == FightMoves.Run) { // strafe move = Randomizer.GetInt(3) == 0 ? FigureAttackCombo(aggressorNPC) : FightMoves.Parry; } else { float progress = enemy.FightAnimation.GetProgress(); if (progress < 0.15) { move = Randomizer.GetInt(4) == 0 ? FigureAttackCombo(aggressorNPC) : FightMoves.Dodge; } else if (progress < 0.5) { move = Randomizer.GetInt(4) == 0 ? FigureAttackCombo(aggressorNPC) : FightMoves.Parry; } else { move = FigureAttackCombo(aggressorNPC); } } } else { move = FigureAttackCombo(aggressorNPC); } } else if (distance < fightRange + 100f) { move = FightMoves.Run; } else { return; } aggressorNPC.EffectHandler.TryFightMove(move); } } else { // Do nothing, you lifeless object ! } }
public ModelInst(VobInst vob) { Vob = vob ?? throw new ArgumentNullException(nameof(vob)); }
public void DefendAgainst(AIAgent aiAgent, VobInst defendedVob, VobInst aggressor) { throw new NotImplementedException(); }
public bool HasAIClient(VobInst aiClient) { return(aiClients.Contains(aiClient)); }