Esempio n. 1
0
 void Sleep()
 {
     NPC.state = BaseNPC.State.Sleeping;
     NPC.sleep.Recover(20f);
     Metabolism.stamina.Run(20f);
     NPC.StartCooldown(20f, true);
 }
Esempio n. 2
0
 void Sleep()
 {
     Base.state = BaseNPC.State.Sleeping;
     Base.sleep.Recover(2f);
     RustMetabolism.stamina.Run(4f);
     Base.StartCooldown(2f, true);
 }
Esempio n. 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;
                                }
                            }
                        }
                    }
                }
            }