Esempio n. 1
0
        public void BehaviourUpdate()
        {
            // continue doing whatever you were doing
            if (Global.Now - LastMoveUpdate > TimeSpan.FromSeconds(1))
            {
                if (MobileState >= EnumMobileState.Standing)
                {
                    Rotation.Y += (float)(Global.Rand.NextDouble() * 40 - 20);
                    while (Rotation.Y < 0)
                    {
                        Rotation.Y += 360;
                    }
                    while (Rotation.Y >= 360)
                    {
                        Rotation.Y -= 360;
                    }
                }
                Matrix3D m = Matrix3D.Identity;
                m.RotatePrepend(Rotation);
                Vector3D velocity = new Vector3D(1, 0, 0) * m;
                switch (MobileState)
                {
                case EnumMobileState.Running:
                    // TODO: using timing, not constant values
                    World.Relocate(this, (Position + 3 * velocity / 10), Rotation);
                    break;

                case EnumMobileState.Walking:
                    World.Relocate(this, (Position + velocity / 10), Rotation);
                    break;

                default:
                    // do nothing
                    break;
                }
            }
            if (Global.Now - LastBehaviourUpdate > TimeSpan.FromSeconds(3))
            {
                // change behavior?
                LastBehaviourUpdate = Global.Now;
                if (MobileState > EnumMobileState.Incapacitated)
                {
                    int rand = Global.Rand.Next(5) - 2;
                    if (rand > 1 && MobileState > EnumMobileState.Sleeping)
                    {
                        SetMobileState(MobileState - 1);
                        //Log.Info( TemplateObjectName + " changed behavior from " + (MobileState+1) + " to " + MobileState + "." );
                    }
                    else if (rand < -1 && MobileState < EnumMobileState.Running)
                    {
                        SetMobileState(MobileState + 1);
                        //Log.Info( TemplateObjectName + " changed behavior from " + (MobileState-1) + " to " + MobileState + "." );
                    }
                }
            }
        }
Esempio n. 2
0
        void ProcessMessage(ClientConnection client, MyPosition message)
        {
            if (client.Avatar == null)
            {
                _log.Warn("Position message from client " + client.RemoteEndPoint + " who has no avatar.");
                return;
            }
            var ma = (MobileAvatar)client.Avatar;

            if (message.Position != client.Avatar.Position)
            {
                ma.LastMoveUpdate = Global.Now;
            }
            ma.SetMobileState(message.State);

            _world.Relocate(client.Avatar, message.Position, message.Rotation);
        }