Beispiel #1
0
        public void Run()
        {
            int divider = 0;

            while (true)
            {
                System.Threading.Thread.Sleep(20); // 50 fps

                local = players[ph.getLocalId()];

                if (local == null)
                {
                    continue;
                }

                if (local.Team == 0) // spectator
                {
                    //continue;
                    int fair_team = selectFairTeam();
                    ph.send_team_change_20((byte)fair_team, 2);
                    local.Team = (byte)fair_team;
                }

                if (local.Health == 0) // dead
                {
                    continue;
                }

                PlayerObject cl = SelectTarget(true); // hitable target
                if (cl != null)
                {
                    float dx = cl.X - local.X; float dy = cl.Y - local.Y;
                    float angle = (float)Math.Atan2(dy, dx) * (float)(180 / Math.PI) + 90.0f;
                    ph.send_rotate_12(angle);

                    if (canShoot)
                    {
                        canShoot = false;
                        local.AmmoIn--;
                        if (local.AmmoIn == 0)
                        {
                            ph.send_reload_16();
                            b_reloading = true;
                        }
                        //if(!b_reloading)
                        ph.send_fire_7();
                    }
                }
                else
                {
                    if (b_spin)
                    {
                        MakeCircles();
                    }
                }

                if (currentRoute != null) // yay a path has been found
                {
                    //DxMove((currentRoute[0].X * 32+16) - local.X, (currentRoute[0].Y * 32) - local.Y+16);
                    if (currentRoute.Count >= 1)
                    {
                        int targetX = currentRoute[0].X * 32 + 16;
                        int targetY = currentRoute[0].Y * 32 + 16;


                        if (local.X == targetX && local.Y == targetY)
                        {
                            if (currentRoute.Count >= 2)
                            {
                                currentRoute.RemoveAt(0);
                            }
                            targetX = (currentRoute[0].X * 32 + 16); targetY = (currentRoute[0].Y * 32 + 16);
                        }

                        int next_x = targetX;   //.X * 32 + 16;
                        int next_y = targetY;

                        int dx = next_x - local.X; int dy = next_y - local.Y;

                        Vector2D moveVector = new Vector2D(dx, dy);

                        if (moveVector.length() <= walkingSpeed)
                        {
                            DxMove((int)moveVector.X, (int)moveVector.Y);
                        }
                        else
                        {
                            Vector2D moveVectorUniformed = moveVector.Uniform();
                            DxMove((int)moveVectorUniformed.X * walkingSpeed, (int)moveVectorUniformed.Y * walkingSpeed);
                        }
                    }
                }

                /* DETERMINE WALK PATH */

                divider++;
                if (divider == 10)
                {
                    divider      = 0;
                    currentRoute = null;

                    switch (walkingState)
                    {
                    case WalkingState.EnemySearch:
                        PlayerObject cl2 = SelectTarget(false);     // walkable target
                        if (cl2 != null)
                        {
                            Goto(cl2.X, cl2.Y);
                        }
                        break;

                    case WalkingState.WeaponSearch:
                        Item scan = ItemScan("primary");
                        if (scan != null)
                        {
                            Goto(scan.tilex * 32 + 16, scan.tiley * 32 + 16);
                        }
                        break;

                    case WalkingState.BombPlant:
                        break;
                    }
                }
            }
        }