Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public AITarget(VobInst vobTarget)
 {
     this.VobTargets = new List <VobInst>()
     {
         vobTarget
     };
 }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
 public void GoTo(AIAgent aiAgent, VobInst target)
 {
     foreach (var ai in aiAgent.AIClients)
     {
         GoTo(ai, target);
     }
 }
Exemplo n.º 5
0
        static VobInst CreateBarrier(HordeBarrier bar)
        {
            VobInst vob = new VobInst(VobDef.Get(bar.Definition));

            vob.Spawn(activeWorld, bar.Position, bar.Angles);
            return(vob);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        VobInst CreateBarrier(HordeScenario.Barrier bar)
        {
            VobInst vob = new VobInst(VobDef.Get(bar.Definition));

            vob.Spawn(World, bar.Position, bar.Angles);
            return(vob);
        }
Exemplo n.º 8
0
 public void UpdateInfo(GuideCmd guideCommand, VobInst guidedVobInst, DateTime expirationDate)
 {
     this.guideCommand   = guideCommand;
     this.guidedVobInst  = guidedVobInst;
     this.ExpirationDate = expirationDate;
     this.ChangeDate     = DateTime.Now;
 }
Exemplo n.º 9
0
        public ModelInst(VobInst vob)
        {
            if (vob == null)
            {
                throw new ArgumentNullException("Vob is null!");
            }

            this.vob = vob;
        }
Exemplo n.º 10
0
        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);
                }
            }
        }
Exemplo n.º 11
0
 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);
             }
         };
     }
 }
Exemplo n.º 12
0
        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);
                }
            }
        }
Exemplo n.º 13
0
 protected void UnsubscribeGuideCommand(VobInst guided)
 {
     guideCommandByVobInst.Remove(guided);
 }
Exemplo n.º 14
0
 public GuideCommandInfo(GuideCmd guideCommand, VobInst guidedVobInst)
     : this(guideCommand, guidedVobInst, DateTime.MaxValue)
 {
 }
Exemplo n.º 15
0
 public VobInstEffectHandler(string objName, List <Effect> effects, VobInst host)
     : base(objName, effects, host)
 {
 }
Exemplo n.º 16
0
 public VobInstEffectHandler(List <Effect> effects, VobInst host)
     : this("VobInstEffectHandler", effects, host)
 {
 }
Exemplo n.º 17
0
 public void TurnAround(VobInst guided, Vec3f direction, float angularVelocity)
 {
     //guided.BaseInst.SetDirection(direction);
 }
Exemplo n.º 18
0
        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 !
            }
        }
Exemplo n.º 19
0
 public ModelInst(VobInst vob)
 {
     Vob = vob ?? throw new ArgumentNullException(nameof(vob));
 }
Exemplo n.º 20
0
 public void DefendAgainst(AIAgent aiAgent, VobInst defendedVob, VobInst aggressor)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 21
0
 public bool HasAIClient(VobInst aiClient)
 {
     return(aiClients.Contains(aiClient));
 }