示例#1
0
 public void Test_FilterValueArraylist()
 {
     ScriptMain m = new ScriptMain();
 }
    public static async System.Threading.Tasks.Task <List <Address> > GetDataAsync(string endpoint, ScriptMain scriptMain)
    {
        bool cancelled;
        var  addressList = new List <Address>();

        try
        {
            //var response = await _client.GetAsync(endpoint);
            var response = await _client.GetAsync(endpoint, HttpCompletionOption.ResponseHeadersRead);

            var result = await response.Content.ReadAsStreamAsync();

            if (response.IsSuccessStatusCode)
            {
                return(DeserialzeJsonStream <List <Address> >(result));
            }
            else
            {
                string errorContent = string.Empty;
                if (result != null)
                {
                    using (var streamReader = new StreamReader(result))
                    {
                        errorContent = await streamReader.ReadToEndAsync();
                    }
                }
                scriptMain.ComponentMetaData.FireWarning(0, "WebApi", $"Request {endpoint} return status: {(int)response.StatusCode} - {response.ReasonPhrase} \n {errorContent}", string.Empty, 0);
            }
        }
        catch (Exception ex)
        {
            scriptMain.ComponentMetaData.FireError(0, "WebApi", $"{endpoint} in error {ex.Message} \n {ex.InnerException}", string.Empty, 0, out cancelled);
        }
        return(addressList);
    }
        public override void OnUpdate(int gameTime)
        {
            base.OnUpdate(gameTime);

            var position = Player.Position;

            if (!ScriptThread.GetVar <bool>("scr_hardcore").Value)
            {
                if (Function.Call <bool>(Hash.IS_OBJECT_NEAR_POINT, 0x9A3207B7, position.X, position.Y, position.Z, (float)random.Next(50, 200)) &&
                    position.DistanceTo(GameplayCamera.Position) < 700.0f &&
                    !flareMgr.CooldownActive &&
                    Probability.GetBoolean(0.0020f + intelligenceBias))
                {
                    flareMgr.Start();
                }

                /*(  if (Player.Vehicle.Ref.Health < Player.Vehicle.Ref.MaxHealth &&
                 *    !extinguisher.CooldownActive &&
                 *    Probability.GetBoolean(intelligenceBias) )
                 * {
                 *    ScriptMain.DebugPrint("use extinguisher (" + Name + ")");
                 *    extinguisher.Start();
                 * }*/
            }

            if (gameTime > state.NextDecisionTime)
            {
                // If we arent chasing a target, they have moved too far away, or have been chasing a target for a set amount of time, make a new decision.
                if (Player.ActiveTarget == null || Player.ActiveTarget.Ped.Ref.IsDead ||
                    position.DistanceTo(Player.ActiveTarget.Position) > 1000.0f ||
                    !Utility.IsPositionInArea(Player.ActiveTarget.Position, levelMgr.Level.Bounds.Min, levelMgr.Level.Bounds.Max) ||
                    Game.GameTime - attackStartedTime > 30000)
                {
                    MakeDecision();
                }

                state.SetNextDecisionTime(gameTime + random.Next(1000, 5000));
            }

            switch (state.Status)
            {
            case AIStatus.FightOther:
            {
                if (Player.ActiveTarget != null)
                {
                    if (Player.ActiveTarget.Position.DistanceTo(Player.Position) > 600.0f)
                    {
                        if (!tooFar)
                        {
                            var destination = Player.ActiveTarget.Position;

                            Function.Call(Hash.TASK_PLANE_MISSION,
                                          Player.Ped.Ref,
                                          Player.Vehicle.Ref,
                                          0,
                                          0,
                                          destination.X, destination.Y, destination.Z,
                                          6, 309.0, 26.0f, 200.0, 1000.0, 20.0);

                            tooFar = true;
                        }
                    }

                    else if (Function.Call <int>(Hash.GET_ACTIVE_VEHICLE_MISSION_TYPE, Player.Vehicle.Ref) != 6)
                    {
                        tooFar = false;
                        Player.PersueTarget(Player.ActiveTarget);
                        UI.ShowSubtitle("persuing " + Function.Call <int>(Hash.GET_ACTIVE_VEHICLE_MISSION_TYPE, Player.Vehicle.Ref).ToString());
                    }
                }


                break;
            }

            case AIStatus.RandomFlight:
            {
                if (position.DistanceTo(destination) < 15.0f)
                {
                    SetRandomDestination();

                    ScriptMain.DebugPrint("Set new random destination for " + Player.Name);
                }

                else if (Player.Position.DistanceTo(sessionMgr.Current.Players[0].PlayerRef.Position) < 1000.0f &&
                         Player.Info.Sess.TeamNum != sessionMgr.Current.Players[0].TeamIdx)
                {
                    Player.PersueTarget(sessionMgr.Current.Players[0].PlayerRef);

                    state.Status = AIStatus.FightOther;
                }

                break;
            }
            }

            for (int i = 0; i < sessionMgr.Current.NumPlayers; i++)
            {
                if (gameTime - lastShotAtTime > 900)
                {
                    var otherPlayer = sessionMgr.Current.Players[i];

                    if (otherPlayer.TeamIdx == Player.Info.Sess.TeamNum)
                    {
                        continue;
                    }

                    var p = otherPlayer.PlayerRef.Position;

                    var direction = Vector3.Normalize(p - position);

                    var otherHeading = otherPlayer.PlayerRef.Vehicle.Ref.Heading;

                    if (Probability.GetBoolean(0.1f + intelligenceBias) && position.DistanceTo(p) < 400.0f)
                    {
                        Function.Call(Hash.SET_VEHICLE_SHOOT_AT_TARGET, Player.Ped.Ref, otherPlayer.PlayerRef.Vehicle.Ref, p.X, p.Y, p.Z);

                        ScriptMain.DebugPrint("Shoot at target (" + Player.Name + " > " + otherPlayer.PlayerRef.Name + ") team idx:" + otherPlayer.PlayerRef.Info.Sess.TeamNum.ToString() + " sess team:" + otherPlayer.TeamIdx);

                        lastShotAtTime = gameTime;
                    }
                }
            }
        }