Пример #1
0
            void FixedUpdate()
            {
                if (AI.deltaTime < ConVar.Server.TickDelta())
                {
                    return;
                }
                if (NPC.IsStunned())
                {
                    return;
                }
                NPC.Tick();
                if (NPC.attack.IsActive())
                {
                    NPC.attack.gameObject.SetActive(false);
                    Move(NextPos);
                    return;
                }
                if (Vector3.Distance(transform.position, Home) > 100)
                {
                    Move(Home);
                    return;
                }
                if (isAttacking && Target != null)
                {
                    var distance = Vector3.Distance(transform.position, Target.transform.position);
                    if (distance >= 70)
                    {
                        isAttacking = false;
                        Target      = null;
                        return;
                    }
                    else if (distance < targetAttackRange)
                    {
                        var normalized = (Target.transform.position - transform.position).XZ3D().normalized;
                        if (NPC.diet.Eat(Target))
                        {
                            NPC.Heal(NPC.MaxHealth() / 10);
                            Metabolism.calories.Add(Metabolism.calories.max / 10);
                            Metabolism.hydration.Add(Metabolism.hydration.max / 10);
                        }
                        else if (NPC.attack.Hit(Target, 1, false))
                        {
                            transform.rotation = Quaternion.LookRotation(normalized);
                        }
                        NPC.steering.Face(normalized);
                    }
                    else
                    {
                        Move(Target.transform.position);
                    }
                }
                else if (Vector3.Distance(transform.position, NextPos) < 20)
                {
                    CalculateNextPos();

                    if (Metabolism.calories.value < 20f)
                    {
                        NPC.diet.Forage();
                    }
                    else if (Metabolism.sleep.value < 20f)
                    {
                        Sleep();
                    }
                }
                else
                {
                    Move(NextPos);
                }
            }
Пример #2
0
            void FixedUpdate()
            {
                SetDeltaTimeMethod.Invoke(RustAI, new object[] { Time.time - lastTick });
                if (RustAI.deltaTime < ConVar.Server.TickDelta())
                {
                    return;
                }
                lastTick = Time.time;
                if (Base.IsStunned())
                {
                    return;
                }
                Base.Tick();

                if (action != Act.Sleep)
                {
                    RustMetabolism.sleep.MoveTowards(0.0f, RustAI.deltaTime * sleepLose);
                    RustMetabolism.hydration.MoveTowards(0.0f, RustAI.deltaTime * thristyLose);
                    RustMetabolism.calories.MoveTowards(0.0f, RustAI.deltaTime * hungerLose);
                }

                if (action == Act.None)
                {
                    return;
                }

                if (action == Act.Move)
                {
                    if (Vector3.Distance(transform.position, targetpoint) < PointMoveDistance)
                    {
                        action = Act.None;
                    }
                    else
                    {
                        Move(targetpoint);
                    }
                }
                else if (action == Act.Sleep)
                {
                    Sleep();
                }
                else if (targetentity == null)
                {
                    action     = Act.None;
                    Base.state = BaseNPC.State.Normal;
                }
                else
                {
                    var distance = Vector3.Distance(transform.position, targetentity.transform.position);
                    if (distance >= IgnoreTargetDistance)
                    {
                        action = Act.None;
                        return;
                    }

                    if (action != Act.Follow && distance <= attackrange)
                    {
                        var normalized = (targetentity.transform.position - transform.position).XZ3D().normalized;
                        if (action == Act.Eat)
                        {
                            if (Base.diet.Eat(targetentity))
                            {
                                Base.Heal(Base.MaxHealth() * 0.01f);
                                RustMetabolism.calories.Add(RustMetabolism.calories.max * 0.03f);
                                RustMetabolism.hydration.Add(RustMetabolism.hydration.max * 0.03f);
                            }
                        }
                        else if (Base.attack.Hit(targetentity, AttackModificator, false))
                        {
                            transform.rotation = Quaternion.LookRotation(normalized);
                        }
                        Base.steering.Face(normalized);
                    }
                    else if (action != Act.Follow || distance > TargetMoveDistance && distance > attackrange)
                    {
                        Move(targetentity.transform.position);
                    }
                }
            }
Пример #3
0
            void FixedUpdate()
            {
                SetDeltaTimeMethod.Invoke(RustAI, new object[] { Time.time - lastTick });
                if ((double)RustAI.deltaTime >= (double)server.NPCTickDelta())
                {
                    lastTick = Time.time;
                    if (!Base.IsStunned())
                    {
                        Base.Tick();

                        if (action != Act.Sleep)
                        {
                            RustMetabolism.sleep.MoveTowards(0.0f, RustAI.deltaTime * sleepLose);
                            RustMetabolism.hydration.MoveTowards(0.0f, RustAI.deltaTime * thristyLose);
                            RustMetabolism.calories.MoveTowards(0.0f, RustAI.deltaTime * hungerLose);
                        }

                        if (action != Act.None)
                        {
                            if (action == Act.Move)
                            {
                                if (Vector3.Distance(transform.position, targetpoint) < PointMoveDistance)
                                {
                                    action = Act.None;
                                }
                                else
                                {
                                    Move(targetpoint);
                                }
                            }
                            else if (action == Act.Sleep)
                            {
                                Base.state = BaseNPC.State.Sleeping;
                                Base.sleep.Recover(2f);
                                RustMetabolism.stamina.Run(4f);
                                Base.StartCooldown(2f, true);
                            }
                            else if (targetentity == null)
                            {
                                action     = Act.None;
                                Base.state = BaseNPC.State.Normal;
                            }
                            else
                            {
                                float distance = Vector3.Distance(transform.position, targetentity.transform.position);
                                if (distance < IgnoreTargetDistance)
                                {
                                    if (action != Act.Follow && distance <= attackrange)
                                    {
                                        Vector3 normalized = Vector3Ex.XZ3D(targetentity.transform.position - transform.position).normalized;
                                        if (action == Act.Eat)
                                        {
                                            if (Base.diet.Eat(targetentity))
                                            {
                                                Base.Heal(Base.MaxHealth() * 0.01f);
                                                RustMetabolism.calories.Add(RustMetabolism.calories.max * 0.03f);
                                                RustMetabolism.hydration.Add(RustMetabolism.hydration.max * 0.03f);
                                            }
                                        }
                                        else if (Base.attack.Hit(targetentity, (targetentity is BaseNPC ? 1f : 2f) * AttackModificator, false))
                                        {
                                            transform.rotation = Quaternion.LookRotation(normalized);
                                        }
                                        Base.steering.Face(normalized);
                                    }
                                    else if (action != Act.Follow || distance > TargetMoveDistance && distance > attackrange)
                                    {
                                        Move(targetentity.transform.position);
                                    }
                                }
                                else
                                {
                                    action = Act.None;
                                }
                            }
                        }
                    }
                }
            }