Sardelka 88a4f046d4 Many poops.
Basically working resource system
Improved projectile movement
Better receive messages
Include Lidgren.Network in core
2022-06-11 18:41:10 +08:00

148 lines
4.4 KiB
C#

#undef DEBUG
using System.Collections.Generic;
using System;
using System.Linq;
using RageCoop.Core;
namespace RageCoop.Client.Scripting
{
/// <summary>
/// ?
/// </summary>
public static class API
{
public static class Config
{
/// <summary>
/// Enable automatic respawn for this player.
/// </summary>
public static bool EnableAutoRespawn { get; set; } = true;
}
public static class Events
{
public delegate void EmptyEvent();
/// <summary>
/// The local player is dead
/// </summary>
public static event EmptyEvent OnPlayerDied;
/// <summary>
/// A local vehicle is spawned
/// </summary>
public static event EventHandler<SyncedVehicle> OnVehicleSpawned;
/// <summary>
/// A local vehicle is deleted
/// </summary>
public static event EventHandler<SyncedVehicle> OnVehicleDeleted;
public static event EventHandler<SyncedPed> OnPedSpawned;
public static event EventHandler<SyncedPed> OnPedDeleted;
#region INVOKE
internal static void InvokeVehicleSpawned(SyncedVehicle v) { OnVehicleSpawned.Invoke(null,v); }
internal static void InvokeVehicleDeleted(SyncedVehicle v) { OnVehicleDeleted.Invoke(null, v); }
internal static void InvokePedSpawned(SyncedPed p) { OnPedSpawned.Invoke(null, p); }
internal static void InvokePedDeleted(SyncedPed p) { OnPedDeleted.Invoke(null, p); }
internal static void InvokePlayerDied() { OnPlayerDied.Invoke(); }
#endregion
}
/// <summary>
/// Send a local chat message to this player
/// </summary>
/// <param name="from">Name of the sender</param>
/// <param name="message">The player's message</param>
public static void LocalChatMessage(string from, string message)
{
Main.MainChat.AddMessage(from, message);
}
public static Core.Logging.Logger GetLogger()
{
return Main.Logger;
}
/// <summary>
/// Queue an action to be executed on next tick.
/// </summary>
/// <param name="a"></param>
public static void QueueAction(Action a)
{
Main.QueueAction(a);
}
/// <summary>
/// Disconnect from the server
/// </summary>
public static void Disconnect()
{
Networking.ToggleConnection(null);
}
/// <summary>
/// Check if the player is already on a server
/// </summary>
public static bool IsOnServer
{
get { return Networking.IsOnServer; }
}
/// <summary>
/// Get the local player's ID
/// </summary>
/// <returns>PlayerID</returns>
public static int LocalPlayerID
{
get { return Main.LocalPlayerID; }
}
/// <summary>
/// Check if a RAGECOOP menu is visible
/// </summary>
public static bool IsMenuVisible
{
get { return Menus.CoopMenu.MenuPool.AreAnyVisible; }
}
/// <summary>
/// Check if the RAGECOOP chat is visible
/// </summary>
public static bool IsChatFocused
{
get { return Main.MainChat.Focused; }
}
/// <summary>
/// Check if the RAGECOOP list of players is visible
/// </summary>
public static bool IsPlayerListVisible
{
get { return Util.GetTickCount64() - PlayerList.Pressed < 5000; }
}
/// <summary>
/// Get the version of RAGECOOP
/// </summary>
public static string CurrentVersion
{
get { return Main.CurrentVersion; }
}
/// <summary>
/// Get or set local player's username, set won't be effective if already connected to a server.
/// </summary>
public static string Username
{
get { return Main.Settings.Username; }
set
{
if (IsOnServer || string.IsNullOrEmpty(value))
{
return;
}
Main.Settings.Username = value;
}
}
}
}