init commit

This commit is contained in:
2025-05-12 18:07:43 -07:00
commit b410345c18
1023 changed files with 57521 additions and 0 deletions
+93
View File
@@ -0,0 +1,93 @@
using Godot;
using System;
using System.Collections.Generic;
public partial class Alert : Control {
Options _Options;
Reference _Reference;
Queue<string> AlertQueue = new Queue<string>();
public override void _Ready() {
_Options = GetNode<Options>( "/root/Options" );
_Reference = GetNode<Reference>("/root/Reference");
_Reference.Alert = this;
}
// This needs to notify the user
public void PerformAlert(string NotificationText ) {
if ( _Options.isServer ) {
GD.Print( NotificationText );
} else {
AlertQueue.Enqueue( NotificationText );
}
}
Panel working = null;
float CurrentStep;
float PauseCounter;
int task = 0;
public override void _Process( double delta ) {
switch( task ) {
// Create the label
case 0: {
if (AlertQueue.Count > 0 ) {
working = new Panel();
working.Size = new Vector2( 300, 50 );
AddChild( working );
working.Position = new Vector2( 0, -50 );
Label text = new Label();
text.Text = AlertQueue.Dequeue();
text.Size = new Vector2( 300, 50 );
text.HorizontalAlignment = HorizontalAlignment.Center;
text.VerticalAlignment = VerticalAlignment.Center;
working.AddChild( text );
CurrentStep = 0;
PauseCounter = 0;
task = 1;
}
break;
}
// Bring down the label
case 1: {
if ( CurrentStep < _Options.AlertTime / 2 ) {
CurrentStep += Convert.ToSingle( delta );
float alertTime = _Options.AlertTime / 2;
working.Position = new Vector2( 0, Mathf.Lerp( -50, 25, CurrentStep / alertTime ) );
} else {
task = 2;
}
break;
}
// Pause the label
case 2: {
PauseCounter += Convert.ToSingle( delta );
if (PauseCounter >= _Options.AlertPauseTime) {
task = 3;
}
break;
}
// Bring Up the label
case 3: {
if ( CurrentStep > 0 ) {
CurrentStep -= Convert.ToSingle( delta );
float alertTime = _Options.AlertTime / 2;
working.Position = new Vector2( 0, Mathf.Lerp( -50, 25, CurrentStep / alertTime ) );
} else {
working.Free();
working = null;
task = 0;
}
break;
}
}
}
}
+29
View File
@@ -0,0 +1,29 @@
using System;
using Godot;
public partial class Bullet : RigidBody3D {
Reference _Reference;
Options _Options;
public int Creator = -1;
public float Damage = 1;
public override void _Ready() {
_Options = GetNode<Options>( "/root/Options" );
_Reference = GetNode<Reference>("/root/Reference");
}
public void _on_body_entered( Node body ) {
if (Multiplayer.GetUniqueId() == 1){
if ( body is Humanoid ) {
Humanoid player = (Humanoid)body;
_Reference.GameHandler.TakeDamage(Damage, Creator, Convert.ToInt32( player.Name.ToString().Split(new char[]{','})[0] ));
_Reference.Alert.PerformAlert("Bullet his player with ID: " + body.GetMultiplayerAuthority());
}
}
this.QueueFree();
}
}
+16
View File
@@ -0,0 +1,16 @@
using Godot;
using System;
public partial class DayCycle : DirectionalLight3D {
Options _Options;
Reference _Reference;
public override void _Process(double delta) {
_Options = GetNode<Options>( "/root/Options" );
_Reference = GetNode<Reference>("/root/Reference");
if ( _Options.isServer ){
Rotation = Rotation + new Vector3(Convert.ToSingle(delta),0,0);
}
}
}
+349
View File
@@ -0,0 +1,349 @@
using Godot;
using System;
using System.Collections.Generic;
public partial class Humanoid : CharacterBody3D {
Options _Options;
Reference _Reference;
[Export]
public AnimationTree Animator;
[Export]
public AnimQuickState CurrentAnimation;
[Export]
public Vector2 InputDirection;
UIMode CurrentUIMode = UIMode.Game;
(UIMode, Control)[] UIFrames;
public ProgressBar HealthBar;
ProgressBar StaminaBar;
public ITool EquippedTool;
Node Backpack;
public string PlayerName = "";
public float Health = 100;
public float MaxHealth = 100;
public float Stamina = 100;
public float MaxStamina = 100;
public float StaminaDrain = 5;
public float StaminaCharge = 5;
public float JumpStamina = 10;
public bool Running = false;
public float JumpVelocity = 5.5f;
public float RotationSpeed = 1f;
public float FallDistanceForDamage = 15;
public float FallDamageScale = 5f;
public Ability Ability;
public float Gravity = ProjectSettings.GetSetting( "physics/3d/default_gravity" ).AsSingle();
public bool mouseLock = true;
public float Speed {
get {
if( Running ) {
return 9f;
}
return 5f;
}
}
public override void _EnterTree() {
_Options = GetNode<Options>( "/root/Options" );
_Reference = GetNode<Reference>("/root/Reference");
string[] Data = Name.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
string PID = Data[0];
string AID = Data[1];
PlayerName = Data[2];
this.SetMultiplayerAuthority( Convert.ToInt32(PID), true );
if( IsMultiplayerAuthority() ) {
_Reference.Humanoid = this;
_Options.isAlive = true;
_Reference.Humanoid = this;
_Reference.Camera = GetChild<Camera3D>( 0 );
_Reference.Camera.GetChild<AudioListener3D>(0).MakeCurrent();
_Reference.Camera.Current = true;
UIFrames = new (UIMode, Control) [] {
( UIMode.Game, GetNode<Control>( "/root/GameRoot/UI/GameUI/Game" ) ),
( UIMode.Inventory, GetNode<Control>( "/root/GameRoot/UI/GameUI/Inventory" ) ),
( UIMode.Pause, GetNode<Control>( "/root/GameRoot/UI/SettingsFrame" ) )
};
HealthBar = GetNode<ProgressBar>( "/root/GameRoot/UI/GameUI/Game/HealthBar" );
StaminaBar = GetNode<ProgressBar>( "/root/GameRoot/UI/GameUI/Game/StaminaBar" );
Input.MouseMode = Input.MouseModeEnum.ConfinedHidden;
SetUIMode( CurrentUIMode );
HealthBar.MaxValue = MaxHealth;
HealthBar.Value = Health;
StaminaBar.MaxValue = MaxStamina;
StaminaBar.Value = Stamina;
EquipTool( 0 );
List<Vector3> spawnPoints = new List<Vector3>();
foreach (Node3D cur in _Reference.PlayerSpawnPoints.GetChildren()){
spawnPoints.Add(cur.GlobalPosition);
}
int chosenSpawn = new Random(DateTime.Now.Millisecond).Next(0, spawnPoints.Count);
this.SetDeferred("global_position", spawnPoints[chosenSpawn]);
Ability _Ability = (Ability)Convert.ToInt32(AID);
if (_Ability == Ability.Vitality){
MaxHealth *= 1.25f;
Health = MaxHealth;
} else if ( _Ability == Ability.Stamina ){
MaxStamina *= 1.25f;
StaminaCharge *= 1.25f;
Stamina = MaxStamina;
} else if ( _Ability == Ability.Strength ){
_Reference.Inventory.UpdateMaxWeight(500);
}
GetNode<Node3D>("PlayerModel").Visible = false;
}
}
public enum AnimQuickState{
Idle,
Walk,
Run,
Jump
}
Vector3 GetMovement( float deltaTime ) {
// Copy current velocity off the CharacterBody3d
Vector3 velocity = Velocity;
if( CurrentUIMode == UIMode.Game ) {
// Add the gravity.
if ( IsOnFloor() ) {
if ( Input.GetActionStrength( "Jump" ) == 1 && Stamina >= JumpStamina ) {
CurrentAnimation = AnimQuickState.Jump;
Stamina -= JumpStamina;
velocity.Y = JumpVelocity;
}
} else {
CurrentAnimation = AnimQuickState.Idle;
velocity.Y -= Gravity * deltaTime;
}
if (Running && Stamina <= 0){
Running = false;
}
// Get the input direction and handle the movement/deceleration.
Vector2 inputDir = Input.GetVector("Left", "Right", "Forward", "Backward");
Vector3 direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
if( direction != Vector3.Zero ) { // If there was input
velocity.X = direction.X * Speed;
velocity.Z = direction.Z * Speed;
if (Running){
Stamina -= deltaTime * StaminaDrain;
StaminaBar.Value = Stamina;
StaminaBar.MaxValue = MaxStamina;
CurrentAnimation = AnimQuickState.Run;
InputDirection = inputDir;
}else{
if (Stamina < MaxStamina){
Stamina += deltaTime * StaminaCharge / 2;
StaminaBar.Value = Stamina;
StaminaBar.MaxValue = MaxStamina;
}
CurrentAnimation = AnimQuickState.Walk;
InputDirection = inputDir;
}
} else { // If there was no input
velocity.X = Mathf.MoveToward( Velocity.X, 0, Speed );
velocity.Z = Mathf.MoveToward( Velocity.Z, 0, Speed );
if (Stamina < MaxStamina){
Stamina += deltaTime * StaminaCharge;
StaminaBar.Value = Stamina;
StaminaBar.MaxValue = MaxStamina;
}
CurrentAnimation = AnimQuickState.Idle;
}
} else {
velocity = new Vector3 (
Mathf.MoveToward( Velocity.X, 0, Speed /6 ),
velocity.Y - (Gravity * deltaTime),
Mathf.MoveToward( Velocity.Z, 0, Speed /6 )
);
if (Stamina < MaxStamina){
Stamina += deltaTime * StaminaCharge;
StaminaBar.Value = Stamina;
StaminaBar.MaxValue = MaxStamina;
}
CurrentAnimation = AnimQuickState.Idle;
}
return velocity;
}
public void EquipTool(int BackpackIndex ) {
if( Backpack == null ) {
Backpack = GetNode<Node>( "/root/GameRoot/UI/GameUI/Game/ToolBar" );
}
var Children = Backpack.GetChildren();
if( Children.Count > BackpackIndex ) {
foreach( Label cur in Children ) {
cur.Modulate = new Color( 1, 1, 1 );
}
if (EquippedTool != null ) {
EquippedTool.UnEquipped();
}
// If same button is pressed put tool away
Label UILabel = Backpack.GetChild<Label>( BackpackIndex );
UILabel.Modulate = new Color(1,0,1);
EquippedTool = ( ITool )UILabel.GetChild(0);
EquippedTool.Equiped();
}
}
enum UIMode {
Game,
Inventory,
Pause
}
void SetUIMode(UIMode mode) {
if (CurrentUIMode == UIMode.Inventory ) {
foreach( var cur in UIFrames ) {
if( cur.Item1 == UIMode.Inventory ) {
Inventory inv = (Inventory)cur.Item2;
if( inv._splitFrame != null ) {
inv._splitFrame.Free();
inv._splitFrame = null;
}
}
}
}
CurrentUIMode = mode;
foreach (var cur in UIFrames) {
if (cur.Item1 == mode) {
cur.Item2.Visible = true;
} else {
cur.Item2.Visible = false;
}
}
if (mode == UIMode.Game) {
Input.MouseMode = Input.MouseModeEnum.Captured;
mouseLock = true;
} else {
Input.MouseMode = Input.MouseModeEnum.Visible;
mouseLock = false;
}
}
public override void _Input( InputEvent _event ) {
if( IsMultiplayerAuthority() ) {
if( _event is InputEventKey eventKey ) {
int KeyCode = (int)eventKey.PhysicalKeycode;
if( eventKey.Keycode == Key.Escape ) {
if( eventKey.Pressed ) {
if( CurrentUIMode != UIMode.Pause ) {
SetUIMode( UIMode.Pause );
} else {
SetUIMode( UIMode.Game );
}
}
} else if( eventKey.Keycode == Key.Tab ) {
if( eventKey.Pressed ) {
if( CurrentUIMode != UIMode.Inventory ) {
SetUIMode( UIMode.Inventory );
} else {
SetUIMode( UIMode.Game );
}
}
}
if( CurrentUIMode == UIMode.Game ) {
if( eventKey.Keycode == Key.Shift ) {
if( eventKey.Pressed && Stamina > 0 ) {
Running = true;
} else {
Running = false;
}
} else if( eventKey.Pressed && KeyCode >= 49 && KeyCode <= 57 ) {
EquipTool( KeyCode - 49 );
} else if( eventKey.Pressed ) {
if( EquippedTool != null ) {
EquippedTool.KeyPress( eventKey.Keycode );
}
} else if( !eventKey.Pressed ) {
if( EquippedTool != null ) {
EquippedTool.KeyRelease( eventKey.Keycode );
}
}
}
} else if ( _event is InputEventMouseMotion ) {
if( mouseLock ) {
InputEventMouseMotion inputEventMouseMotion = (InputEventMouseMotion)_event;
Vector2 LookChange = inputEventMouseMotion.Relative;
// Horizontal Rotation
RotateY( LookChange.X * RotationSpeed * -0.002f );
// Vertical Rotation
_Reference.Camera.RotateX( LookChange.Y * RotationSpeed * -0.002f );
if( _Reference.Camera.RotationDegrees.X < -90 ) {
_Reference.Camera.RotationDegrees = new Vector3( -90, _Reference.Camera.RotationDegrees.Y, _Reference.Camera.RotationDegrees.Z );
} else if( _Reference.Camera.RotationDegrees.X > 90 ) {
_Reference.Camera.RotationDegrees = new Vector3( 90, _Reference.Camera.RotationDegrees.Y, _Reference.Camera.RotationDegrees.Z );
}
}
} else if ( _event is InputEventMouseButton _mouseevent ) {
if( mouseLock ) {
if( _mouseevent.ButtonIndex == MouseButton.Left ) {
if( EquippedTool != null && _mouseevent.Pressed ) {
EquippedTool.LeftMouseDown();
} else if( EquippedTool != null && !_mouseevent.Pressed ) {
EquippedTool.LeftMouseUp();
}
} else if( _mouseevent.ButtonIndex == MouseButton.Right ) {
if( EquippedTool != null && _mouseevent.Pressed ) {
EquippedTool.RightMouseDown();
} else if( EquippedTool != null && !_mouseevent.Pressed ) {
EquippedTool.RightMouseUp();
}
}
}
}
}
}
void SetAnimation(){
AnimationNodeStateMachinePlayback stateMachine = (AnimationNodeStateMachinePlayback)Animator.Get("parameters/playback");
stateMachine.Travel( CurrentAnimation.ToString() );
Animator.Set("parameters/Walk/BlendSpace2D/blend_position", InputDirection);
Animator.Set("parameters/Run/BlendSpace2D/blend_position", InputDirection);
}
float LastY = -1;
public override void _PhysicsProcess( double _dT ) {
SetAnimation();
if( IsMultiplayerAuthority() ) {
float deltaTime = Convert.ToSingle( _dT );
// Fall Damage
if( IsOnFloor() ) {
if( LastY != -1 ) {
float FallDistance = LastY - GlobalPosition.Y;
if( FallDistance > FallDistanceForDamage ) {
_Reference.GameHandler.TakeDamage( (FallDistance - FallDistanceForDamage) * FallDamageScale, 0, Multiplayer.GetUniqueId() );
}
LastY = -1;
}
} else {
if( LastY == -1 ) {
LastY = GlobalPosition.Y;
}
}
// Copy the Velocity back onto the CharacterBody3d
Velocity = GetMovement( deltaTime );
// Apply Motion
MoveAndSlide();
}
}
}
+550
View File
@@ -0,0 +1,550 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
// Remove all the global positions from this file
public partial class Inventory : Panel {
Options _Options;
Reference _Reference;
[Export] PackedScene SplitFrame;
Vector2I InventorySize = new Vector2I(4, 15);
int MaxWeight;
List<(InventoryItem, Panel)> _Inventory;
Vector2 _GridSize;
ProgressBar _WeightBar;
HeldItem _itemBeingHeld;
HeldItem __h;
HeldItem _lastRightClickedItem {
get {
return __h;
}
set {
if (_splitFrame != null) {
_splitFrame.Free();
_splitFrame = null;
}
__h = value;
}
}
public Control _splitFrame;
public override void _EnterTree() {
_Options = GetNode<Options>( "/root/Options" );
_Reference = GetNode<Reference>("/root/Reference");
_Reference.Inventory = this;
_Inventory = new List<(InventoryItem, Panel)>();
MaxWeight = 400;
Control GridBackdrop = GetChild(0).GetChild<Control>( 0 );
_WeightBar = GetChild<ProgressBar>( 1 );
// Scale Scrollbar
Vector2 FrameSize = GetChild<Control>(0).Size;
GridBackdrop.CustomMinimumSize = new Vector2( GetChild<Control>(0).Size.X - 8 , InventorySize.Y * FrameSize.X / InventorySize.X );
GridBackdrop.Size = GridBackdrop.CustomMinimumSize;
_GridSize = new Vector2( GridBackdrop.Size.X / InventorySize.X, GridBackdrop.Size.Y / InventorySize.Y );
_WeightBar.MaxValue = MaxWeight;
// Horizontal Grid Bars
for (int y=0; y< InventorySize.Y - 1; y++) {
HSeparator cur = new HSeparator{
Position = new Vector2(0, _GridSize.Y * (y + 1) - 2),
Size = new Vector2(GridBackdrop.Size.X, 4)
};
GetChild(0).GetChild(0).AddChild( cur );
}
// Vertical Grid Bars
for (int x=0; x< InventorySize.X - 1; x++) {
VSeparator cur = new VSeparator{
Position = new Vector2(_GridSize.X * (x + 1) - 2, 0),
Size = new Vector2(4, GridBackdrop.Size.Y)
};
GetChild(0).GetChild(0).AddChild( cur );
}
GetWeight();
}
public void UpdateMaxWeight(int maxWeight){
MaxWeight = maxWeight;
_WeightBar.MaxValue = MaxWeight;
GetWeight();
}
//------------------------------//
// Public Functions //
//------------------------------//
public int GetWeight() {
int _w = 0;
foreach( (InventoryItem, Control) cur in _Inventory ) {
_w += cur.Item1.Weight;
}
_WeightBar.Value = _w;
_WeightBar.GetChild<Label>( 0 ).Text = _w.ToString() + " / " + MaxWeight.ToString();
return _w;
}
public void UpdateItem( InventoryItem item ) {
foreach( (InventoryItem, Panel) cur in _Inventory ) {
if( item.Guid == cur.Item1.Guid ) {
cur.Item1.Quantity = item.Quantity;
cur.Item2.GetChild<MenuButton>( 0 ).Text = item.Name + "\n" +
item.Quantity + " / " + item.MaxQuantity;
break;
}
}
}
public bool AddInventory( InventoryItem Item ) {
Item.Rotated = false;
if( GetWeight() + Item.Weight > MaxWeight ) {
_Reference.Alert.PerformAlert( "Max weight!" );
return false;
}
for( int rotation = 0; rotation <= 1; rotation++ ) {
// Try both rotations of the block
Vector2I tempSize = Item.GridSize;
if( rotation == 1 ) {
Item.Rotated = true;
tempSize = new Vector2I( Item.GridSize.Y, Item.GridSize.X );
}
// Go through the inventory grid minus overflow from the size of the item were trying to place
for( int yindex = 0; yindex <= (InventorySize.Y - tempSize.Y); yindex++ ) {
for( int xindex = 0; xindex <= (InventorySize.X - tempSize.X); xindex++ ) {
if( CheckBlock( tempSize, new Vector2I( xindex, yindex ), null ) ) {
// We found our space
Panel ItemBackDrop = new Panel();
GetChild( 0 ).GetChild( 0 ).AddChild( ItemBackDrop );
ItemBackDrop.Size = new Vector2( _GridSize.X * tempSize.X - 10, _GridSize.Y * tempSize.Y - 10 );
ItemBackDrop.Position = new Vector2( xindex * _GridSize.X + 5, yindex * _GridSize.Y + 5 );
ItemBackDrop.GuiInput += frameInput;
MenuButton dropDown = new MenuButton();
if( Item.isQuantityItem ) {
dropDown.Text = Item.Name + "\n" +
Item.Quantity + " / " + Item.MaxQuantity;
} else {
dropDown.Text = Item.Name;
}
dropDown.SetAnchorsPreset( LayoutPreset.FullRect );
ItemBackDrop.AddChild( dropDown );
dropDown.ButtonMask = MouseButtonMask.Right;
dropDown.GuiInput += frameInput;
dropDown.GetPopup().IndexPressed += DropdownPressed;
foreach( string cur in Enum.GetNames( typeof( InventoryOptions ) ) ) {
if( cur == "Split" && !Item.isQuantityItem ) {
continue;
}
dropDown.GetPopup().AddItem( cur );
}
Item.GridPosition = new Vector2I( xindex, yindex );
_Inventory.Add( (Item, ItemBackDrop) );
GetWeight();
// Add Tool if its a tool
if (!string.IsNullOrEmpty(Item.ToolPath)){
PackedScene toolCopy = GD.Load<PackedScene>(Item.ToolPath);
Label tool = toolCopy.Instantiate<Label>();
// Place tool into toolbar in the correct spot and shift everything down to zero if need be
Node[] toolbarChildren = _Reference.ToolBar.GetChildren().ToArray();
for( int i=0; i<toolbarChildren.Count(); i++ ){
Label cur = (Label)toolbarChildren[i];
if ( cur.Text.Substring(1, 2) == ". " ){
cur.Text = (i+1).ToString() + ". " + cur.Text.Substring(3);
}
}
Debug.WriteLine( tool.Text.Substring(1, 2) );
if ( tool.Text.Substring(1, 2) == ". " ){
tool.Text = (toolbarChildren.Count()+1).ToString() + ". " + tool.Text.Substring(3);
} else {
tool.Text = (toolbarChildren.Count()+1).ToString() + ". " + tool.Text;
}
_Reference.ToolBar.AddChild( tool );
}
return true;
}
}
}
}
_Reference.Alert.PerformAlert( "No Space" );
// No space was found
return false;
}
public void DropInventory( InventoryItem item, Panel frame ) {
string[] PickupItems = _Reference.ItemSpawner._SpawnableScenes;
PackedScene ps = GD.Load<PackedScene>(PickupItems[item.ItemID]);
Pickup prefab = ps.Instantiate<Pickup>();
prefab.GlobalTransform = _Reference.Humanoid.GlobalTransform;
prefab.Quantity = item.Quantity;
_Reference.ItemSpawnPath.AddChild( prefab );
RemoveInventory( item, frame );
}
public void RemoveInventory( InventoryItem item, Panel frame ) {
foreach(Label cur in _Reference.ToolBar.GetChildren()){
if ( cur.GetChild(0) is ITool ){
ITool x = (ITool)cur.GetChild(0);
if ( x.ToolID == item.ItemID ){
if(_Reference.Humanoid.EquippedTool == x){
_Reference.Humanoid.EquipTool(0);
}
cur.QueueFree();
break;
}
}
}
_Inventory.Remove( (item, frame) ) ;
frame.Free();
GetWeight();
}
//------------------------------//
// Mouse Functions //
//------------------------------//
void MouseDown( Vector2 mousePos ) {
(InventoryItem, Panel)? clicked = GetItemFromScreen( mousePos );
if( clicked.HasValue ) {
_itemBeingHeld = new HeldItem {
MouseStart = mousePos,
MouseOffset = clicked.Value.Item2.Position - mousePos,
Frame = clicked.Value.Item2,
Item = clicked.Value.Item1
};
}
}
void MouseMove( Vector2 mousePos ) {
if( _itemBeingHeld != null ) {
Vector2I TempSize = _itemBeingHeld.Item.GridSize;
if( _itemBeingHeld.Item.Rotated ) {
TempSize = new Vector2I( _itemBeingHeld.Item.GridSize.Y, _itemBeingHeld.Item.GridSize.X );
}
Vector2 newFramePos = mousePos + _itemBeingHeld.MouseOffset;
if( newFramePos.X < 0 ) {
newFramePos.X = 0;
}
if( newFramePos.Y < 0 ) {
newFramePos.Y = 0;
}
if( newFramePos.X > _GridSize.X * InventorySize.X - (_GridSize.X * TempSize.X) ) {
newFramePos.X = _GridSize.X * InventorySize.X - (_GridSize.X * TempSize.X);
}
if( newFramePos.Y > _GridSize.Y * InventorySize.Y - (_GridSize.Y * TempSize.Y) ) {
newFramePos.Y = _GridSize.Y * InventorySize.Y - (_GridSize.Y * TempSize.Y);
}
_itemBeingHeld.Frame.Position = newFramePos;
}
}
void MouseUp( Vector2 mousePos ) {
if( _itemBeingHeld != null ) {
Vector2I TempSize = _itemBeingHeld.Item.GridSize;
if( _itemBeingHeld.Item.Rotated ) {
TempSize = new Vector2I( _itemBeingHeld.Item.GridSize.Y, _itemBeingHeld.Item.GridSize.X );
}
Vector2 FinalGrid = new Vector2(
Mathf.Round((mousePos.X + _itemBeingHeld.MouseOffset.X) / _GridSize.X),
Mathf.Round((mousePos.Y + _itemBeingHeld.MouseOffset.Y) / _GridSize.Y)
);
if( FinalGrid.X < 0 ) { FinalGrid.X = 0; }
if( FinalGrid.Y < 0 ) { FinalGrid.Y = 0; }
if( FinalGrid.X > (InventorySize.X - TempSize.X) ) { FinalGrid.X = InventorySize.X - TempSize.X; }
if( FinalGrid.Y > (InventorySize.Y - TempSize.Y) ) { FinalGrid.Y = InventorySize.Y - TempSize.Y; }
if( CheckBlock( TempSize, new Vector2I( Convert.ToInt32( FinalGrid.X ), Convert.ToInt32( FinalGrid.Y )), _itemBeingHeld.Item ) ) { // Check fitment
_itemBeingHeld.Item.GridPosition = new Vector2I( Convert.ToInt32( FinalGrid.X ), Convert.ToInt32( FinalGrid.Y ) );
_itemBeingHeld.Frame.Position = _GridSize * FinalGrid + new Vector2( 5, 5 );
} else {
(InventoryItem, Panel)? itemAtSpot = GetItemFromScreen( mousePos );
if( itemAtSpot.Value.Item1.isQuantityItem && itemAtSpot.Value.Item1.ItemID == _itemBeingHeld.Item.ItemID ) {
// Try Combine
int MaxQuantity = _itemBeingHeld.Item.MaxQuantity;
int Total = itemAtSpot.Value.Item1.Quantity + _itemBeingHeld.Item.Quantity;
if( Total > MaxQuantity ) {
int remainder = Total - MaxQuantity;
itemAtSpot.Value.Item1.Quantity = MaxQuantity;
_itemBeingHeld.Item.Quantity = remainder;
_itemBeingHeld.Frame.Position = new Vector2(
_itemBeingHeld.Item.GridPosition.X * _GridSize.X + 5,
_itemBeingHeld.Item.GridPosition.Y * _GridSize.Y + 5
);
} else {
itemAtSpot.Value.Item1.Quantity = Total;
MenuButton button = itemAtSpot.Value.Item2.GetChild<MenuButton>(0);
button.Text = itemAtSpot.Value.Item1.Name + "\n" +
itemAtSpot.Value.Item1.Quantity + " / " + itemAtSpot.Value.Item1.MaxQuantity;
RemoveInventory( _itemBeingHeld.Item, _itemBeingHeld.Frame );
}
} else {
_itemBeingHeld.Frame.Position = new Vector2(
_itemBeingHeld.Item.GridPosition.X * _GridSize.X + 5,
_itemBeingHeld.Item.GridPosition.Y * _GridSize.Y + 5
);
}
}
_itemBeingHeld = null;
}
}
void RightMouseDown( Vector2 mousePos ) {
(InventoryItem, Panel)? clicked = GetItemFromScreen( mousePos );
if( clicked.HasValue ) {
_lastRightClickedItem = new HeldItem {
Frame = clicked.Value.Item2,
Item = clicked.Value.Item1,
MouseStart = mousePos,
};
}
}
//------------------------------//
// Screen Space Math //
//------------------------------//
(InventoryItem, Panel)? GetItemFromScreen( Vector2 screenPos ) {
Vector2 ClickedGrid = new Vector2( Mathf.Floor(screenPos.X / _GridSize.X), Mathf.Floor(screenPos.Y / _GridSize.Y) );
foreach( (InventoryItem, Panel) cur in _Inventory ) {
Vector2I TempSize = cur.Item1.GridSize;
if( cur.Item1.Rotated ) {
TempSize = new Vector2I( cur.Item1.GridSize.Y, cur.Item1.GridSize.X );
}
if( ClickedGrid.X >= cur.Item1.GridPosition.X && ClickedGrid.X <= (cur.Item1.GridPosition.X + TempSize.X - 1) &&
ClickedGrid.Y >= cur.Item1.GridPosition.Y && ClickedGrid.Y <= (cur.Item1.GridPosition.Y + TempSize.Y - 1) ) {
return cur;
}
}
return null;
}
Vector2 TranslateGlobalToFramePosition( Vector2 globalPos ) {
ScrollContainer InventoryFrame = GetChild<ScrollContainer>( 0 );
Vector2 FrameGlobalPos = InventoryFrame.GlobalPosition;
Vector2 ScrollAmount = new Vector2( InventoryFrame.ScrollHorizontal, InventoryFrame.ScrollVertical );
Vector2 localPos = globalPos - FrameGlobalPos + ScrollAmount;
return localPos;
}
bool CheckBlock( Vector2I BlockSize, Vector2I BlockGridPostion, InventoryItem Ignore ) {
for( int y = 0; y < BlockSize.Y; y++ ) {
for( int x = 0; x < BlockSize.X; x++ ) {
foreach( (InventoryItem, Control) cur in _Inventory ) {
// Check Ignore
if( Ignore != null && cur.Item1.Guid == Ignore.Guid ) {
continue;
}
// Properly rotate block
Vector2I tempSize;
if( !cur.Item1.Rotated ) {
tempSize = cur.Item1.GridSize;
} else {
tempSize = new Vector2I( cur.Item1.GridSize.Y, cur.Item1.GridSize.X );
}
// Check fit
Vector2I curTopLeft = cur.Item1.GridPosition;
Vector2I curBotRight = new Vector2I( cur.Item1.GridPosition.X + tempSize.X - 1, cur.Item1.GridPosition.Y + tempSize.Y - 1 );
if( (x + BlockGridPostion.X) >= curTopLeft.X && (x + BlockGridPostion.X) <= curBotRight.X &&
(y + BlockGridPostion.Y) >= curTopLeft.Y && (y + BlockGridPostion.Y) <= curBotRight.Y ) {
return false;
}
}
}
}
return true;
}
void frameInput( InputEvent iEvent ) {
if ( iEvent is InputEventMouseButton mouseButton) {
if( mouseButton.ButtonIndex == MouseButton.Left ) {
if( mouseButton.Pressed ) {
MouseDown( TranslateGlobalToFramePosition(mouseButton.GlobalPosition) );
} else {
MouseUp( TranslateGlobalToFramePosition( mouseButton.GlobalPosition ) );
}
} else if( mouseButton.ButtonIndex == MouseButton.Right ) {
if ( mouseButton.Pressed ) {
RightMouseDown( TranslateGlobalToFramePosition( mouseButton.GlobalPosition ) );
}
}
} else if( iEvent is InputEventMouseMotion mouseMotion) {
MouseMove( TranslateGlobalToFramePosition( mouseMotion.GlobalPosition ) );
}
}
//------------------------------//
// Right Click Functions //
//------------------------------//
(bool, Vector2I) TryRotate( InventoryItem item ) {
Vector2I tempSize;
if( item.Rotated ) {
tempSize = item.GridSize;
} else {
tempSize = new Vector2I( item.GridSize.Y, item.GridSize.X );
}
// Go through the inventory grid minus overflow from the size of the item were trying to place
for( int yindex = 0; yindex <= (InventorySize.Y - tempSize.Y); yindex++ ) {
for( int xindex = 0; xindex <= (InventorySize.X - tempSize.X); xindex++ ) {
if( CheckBlock( tempSize, new Vector2I( xindex, yindex ), item ) ) {
return (true, new Vector2I(xindex, yindex));
}
}
}
return (false, Vector2I.Zero);
}
string GetNumbers( String InputString ) {
String Result = "";
string Numbers = "0123456789";
int i = 0;
for( i = 0; i < InputString.Length; i++ ) {
if( Numbers.Contains( InputString.ElementAt( i ) ) ) {
Result += InputString.ElementAt( i );
}
}
return Result;
}
void SplitFrame_Split() {
int quantity = Convert.ToInt32( _splitFrame.GetChild<LineEdit>( 1 ).Text );
InventoryItem x = _lastRightClickedItem.Item;
if (quantity <= x.Quantity ) {
PickupItem test = new PickupItem( x.ItemID, x.Name, x.GridSize, x.Weight, x.isQuantityItem, quantity, x.MaxQuantity );
if( AddInventory( test ) ) {
_lastRightClickedItem.Item.Quantity -= quantity;
UpdateItem( _lastRightClickedItem.Item );
} else {
_Reference.Alert.PerformAlert( "Not enough space to split" );
}
}
_splitFrame.Free();
_splitFrame = null;
}
void SplitFrame_Cancel() {
_splitFrame.Free();
_splitFrame = null;
}
void SplitFrame_TextChanged( string NewText ) {
string output = GetNumbers( NewText );
if ( string.IsNullOrEmpty( output ) ) {
output = "0";
}
int test = Convert.ToInt32(output);
if (test < 0) {
test = 0;
}else if (test > _lastRightClickedItem.Item.MaxQuantity) {
test = _lastRightClickedItem.Item.MaxQuantity;
}
_splitFrame.GetChild<LineEdit>( 1 ).Text = test.ToString();
_splitFrame.GetChild<LineEdit>( 1 ).CaretColumn = 50;
}
void DropdownPressed( long index ) {
InventoryOptions pressed = (InventoryOptions)index;
if( pressed == InventoryOptions.Drop ) {
DropInventory( _lastRightClickedItem.Item, _lastRightClickedItem.Frame );
} else if( pressed == InventoryOptions.Rotate ) {
(bool, Vector2I) tryRotate = TryRotate( _lastRightClickedItem.Item );
if( tryRotate.Item1 ) {
_lastRightClickedItem.Item.Rotated = !_lastRightClickedItem.Item.Rotated;
Vector2 tempSize;
if( _lastRightClickedItem.Item.Rotated ) {
tempSize = new Vector2( _lastRightClickedItem.Item.GridSize.Y, _lastRightClickedItem.Item.GridSize.X );
} else {
tempSize = _lastRightClickedItem.Item.GridSize;
}
_lastRightClickedItem.Frame.Size = new Vector2( _GridSize.X * tempSize.X - 10, _GridSize.Y * tempSize.Y - 10 );
_lastRightClickedItem.Frame.Position = new Vector2( tryRotate.Item2.X * _GridSize.X + 5, tryRotate.Item2.Y * _GridSize.Y + 5 );
_lastRightClickedItem.Item.GridPosition = tryRotate.Item2;
} else {
_Reference.Alert.PerformAlert( "Not enough space to rotate");
}
} else if( pressed == InventoryOptions.Split ) {
_splitFrame = SplitFrame.Instantiate<Control>();
GetNode( "/root/Game/UI/" ).AddChild( _splitFrame );
_splitFrame.GetChild<Button>( 2 ).ButtonDown += SplitFrame_Split;
_splitFrame.GetChild<Button>( 3 ).ButtonDown += SplitFrame_Cancel;
_splitFrame.GetChild<LineEdit>( 1 ).TextChanged += SplitFrame_TextChanged;
}
}
}
//------------------------------//
// Data Objects //
//------------------------------//
class HeldItem {
public Vector2 MouseStart;
public Vector2 MouseOffset;
public InventoryItem Item;
public Panel Frame;
}
public class PickupItem : InventoryItem {
public Guid Guid { get; }
public int ItemID { get; }
public string Name { get; }
public Vector2I GridPosition { get; set; }
public bool Rotated { get; set; }
public Vector2I GridSize { get; }
public int Weight {get;}
public bool isQuantityItem { get; }
public int Quantity { get; set; }
public int MaxQuantity { get; set; }
public string ToolPath{ get; }
public PickupItem( int _ItemID, string _Name, Vector2I _GridSize, int _Weight, bool _isQuantityItem, int _Quanitity = 0, int _MaxQuantity = 0, string _ToolPath = "" ) {
Guid = Guid.NewGuid();
ItemID = _ItemID;
Name = _Name;
GridSize = _GridSize;
Weight = _Weight;
isQuantityItem = _isQuantityItem;
Quantity = _Quanitity;
MaxQuantity = _MaxQuantity;
ToolPath = _ToolPath;
}
}
public interface InventoryItem {
public Guid Guid { get; }
public int ItemID { get; }
public string Name { get; }
public Vector2I GridPosition { get; set; }
public bool Rotated { get; set; }
public Vector2I GridSize { get; }
public int Weight { get; }
public bool isQuantityItem { get; }
public int Quantity { get; set; }
public int MaxQuantity { get; set; }
public string ToolPath { get; }
}
enum InventoryOptions {
Drop,
Rotate,
Split
}
+11
View File
@@ -0,0 +1,11 @@
using Godot;
public partial class Pickup : RigidBody3D {
[Export]
public int ItemID {get; set;}
[Export]
public int Quantity {get; set;}
}
+13
View File
@@ -0,0 +1,13 @@
using Godot;
public partial class SpawnPoint : Node3D {
Options _Options;
Reference _Reference;
public override void _EnterTree() {
_Reference = GetNode<Reference>("/root/Reference");
_Reference.PlayerSpawnPoints = this.GetChild<Node3D>(0);
_Reference.ItemSpawnPoints = this.GetChild<Node3D>(1);
}
}
+120
View File
@@ -0,0 +1,120 @@
using Godot;
using Godot.Collections;
using System.Diagnostics;
public partial class SelectTool : Node3D, ITool {
public int ToolID { get{ return -1; } } // -1 for non-existant tool stat
Options _Options;
Reference _Reference;
ItemStats _Stats;
[Export] PackedScene SelectToolFrame;
[Export] Material HoverMaterial;
Material _defaultMaterial;
MeshInstance3D _lookingAt;
Control _SelectToolFrame;
bool mouseDown = false;
bool mouseDownDebounce = false;
bool equipped = false;
public (bool, Dictionary) screenSpaceToRay( float Distance ) {
Vector2 ClickPos = GetViewport().GetMousePosition();
Vector3 from = _Reference.Camera.ProjectRayOrigin( ClickPos );
Vector3 to = from + _Reference.Camera.ProjectRayNormal( ClickPos ) * Distance;
PhysicsDirectSpaceState3D spaceState = GetWorld3D().DirectSpaceState;
Dictionary rayArray = spaceState.IntersectRay(new PhysicsRayQueryParameters3D(){ From=from, To=to });
if( rayArray.Count > 0 ) {
return (true, rayArray);
}
return (false, null);
}
void ClearLookingAt() {
if( _lookingAt != null ) {
_lookingAt.SetSurfaceOverrideMaterial( 0, _defaultMaterial );
_lookingAt = null;
_SelectToolFrame.Visible = false;
}
}
public override void _PhysicsProcess( double delta ) {
if( equipped ) {
var x = screenSpaceToRay(_Options.ClickDistance);
if( x.Item1 ) {
Node test = (Node)x.Item2["collider"];
if( test is Pickup ) {
int ItemID = ((Pickup)test).ItemID;
int Quantity = ((Pickup)test).Quantity;
StatItem ItemStats = _Stats.stats[ ItemID ];
PickupItem item = new PickupItem( ItemID, ItemStats.ItemName, ItemStats.InventorySize, ItemStats.Weight, ItemStats.IsQuantityItem, Quantity, ItemStats.MaxQuantity, ItemStats.ToolPath );
if( _lookingAt == null ) {
_lookingAt = test.GetChild<MeshInstance3D>( 1 );
_defaultMaterial = _lookingAt.GetSurfaceOverrideMaterial( 0 );
_lookingAt.SetSurfaceOverrideMaterial( 0, HoverMaterial );
_SelectToolFrame.Visible = true;
_SelectToolFrame.GetChild<Label>( 0 ).Text = item.Name;
_SelectToolFrame.GetChild<Label>( 1 ).Text = "Slot : " + item.GridSize.ToString();
_SelectToolFrame.GetChild<Label>( 2 ).Text = "Weight : " + item.Weight;
if (item.isQuantityItem ) {
_SelectToolFrame.GetChild<Label>( 3 ).Text = "Capacity : " + item.Quantity + "/" + item.MaxQuantity;
_SelectToolFrame.Size = new Vector2( _SelectToolFrame.Size.X, 95 );
} else {
_SelectToolFrame.GetChild<Label>( 3 ).Text = "";
_SelectToolFrame.Size = new Vector2( _SelectToolFrame.Size.X, 72 );
}
}else if (_lookingAt != test.GetChild<MeshInstance3D>( 1 ) ) {
ClearLookingAt();
}
if( mouseDown && mouseDownDebounce ) {
mouseDownDebounce = false;
bool PickedUp = _Reference.Inventory.AddInventory(item);
if( PickedUp ) {
ClearLookingAt();
_Reference.GameHandler.ClearItemNetworked( test.Name );
}
}
} else {
ClearLookingAt();
}
} else {
ClearLookingAt();
}
}
}
public void Equiped() {
_Options = GetNode<Options>( "/root/Options" );
_Reference = GetNode<Reference>("/root/Reference");
_Stats = (ItemStats)_Reference.ItemSpawnPath;
_SelectToolFrame = SelectToolFrame.Instantiate<Control>();
GetNode( "/root/GameRoot/UI/GameUI/Game" ).AddChild( _SelectToolFrame );
equipped = true;
}
public void LeftMouseDown() {
mouseDown = true;
mouseDownDebounce = true;
}
public void LeftMouseUp() {
mouseDown = false;
mouseDownDebounce = false;
}
public void KeyPress( Key key ) {}
public void KeyRelease( Key key ) {}
public void RightMouseDown() {}
public void RightMouseUp() {}
public void UnEquipped() {
if (_SelectToolFrame != null ) {
_SelectToolFrame.Free();
}
equipped = false;
}
}
+89
View File
@@ -0,0 +1,89 @@
using Godot;
using System;
public partial class Sniper : Node, ITool {
public int ToolID { get{ return 0; } } // Match ToolID to ItemStat Index
Options _Options;
Reference _Reference;
float BulletSpawnSpacing = 2; // Distance off the front of the camera that the bullet spawn
bool isZoomed = false;
float ZoomFOV = 30;
float _normalZoom;
float HipAccuracy = 5; // Maximum offset in degrees | 15 would be 7.5 deg in each direction
float HipRecoil = 5; // Maximum offset in degrees | 5 would be 2.5 horizontally and 5 up
float AimAccuracy = 2; // Maximum offset in degrees
float AimRecoil = 2; // Maximum offset in degrees
public void Equiped() {
_Options = GetNode<Options>( "/root/Options" );
_Reference = GetNode<Reference>("/root/Reference");
_normalZoom = _Reference.Camera.Fov;
}
public void KeyPress( Key key ) {
}
public void KeyRelease( Key key ) {
}
Vector3 Accuracy() {
Random Random = new Random( DateTime.Now.Millisecond );
if( isZoomed ) {
float xAccuracy = ( ( Random.NextSingle() * 2 ) - 1 ) * AimAccuracy / 2;
float yAccuracy = ( ( Random.NextSingle() * 2 ) - 1 ) * AimAccuracy / 2;
return new Vector3( xAccuracy, yAccuracy, 0 );
} else {
float xAccuracy = ( ( Random.NextSingle() * 2 ) - 1 ) * HipAccuracy / 2;
float yAccuracy = ( ( Random.NextSingle() * 2 ) - 1 ) * HipAccuracy / 2;
return new Vector3( xAccuracy, yAccuracy, 0 );
}
}
void Recoil() {
Random Random = new Random( DateTime.Now.Millisecond );
Vector2 recoil;
if ( isZoomed ) {
float xRecoil = ( ( Random.NextSingle() * 2 ) - 1 ) * AimRecoil / 2;
float yRecoil = Random.NextSingle() * AimRecoil;
recoil = new Vector2( xRecoil, yRecoil );
} else {
float xRecoil = ( ( Random.NextSingle() * 2 ) - 1 ) * HipRecoil / 2;
float yRecoil = Random.NextSingle() * HipRecoil;
recoil = new Vector2( xRecoil, yRecoil );
}
_Reference.Camera.RotateX( 1 ); // IE Up and Down
_Reference.Humanoid.RotateX( 1 ); // IE Left and Right
}
public void LeftMouseDown() {
Vector3 LookVector = -_Reference.Camera.GlobalBasis.Z;
_Reference.GameHandler.Shoot(ToolID, LookVector, 200);
//Recoil();
}
public void LeftMouseUp() {
}
public void RightMouseDown() {
isZoomed = true;
_Reference.Camera.Fov = ZoomFOV;
}
public void RightMouseUp() {
isZoomed = false;
_Reference.Camera.Fov = _normalZoom;
}
public void UnEquipped() {
}
}
+13
View File
@@ -0,0 +1,13 @@
using Godot;
public interface ITool {
public int ToolID{ get; }
public void Equiped();
public void UnEquipped();
public void LeftMouseDown();
public void LeftMouseUp();
public void RightMouseDown();
public void RightMouseUp();
public void KeyPress( Key key );
public void KeyRelease( Key key );
}
+253
View File
@@ -0,0 +1,253 @@
using System;
using Godot;
public partial class GameHandler : Node3D {
Reference _Reference;
Options _Options;
[Export]
public PackedScene[] MapList;
[Export]
public PackedScene Player;
[Export]
public PackedScene Sun;
public bool serverRunning = false;
public override void _Ready() {
_Options = GetNode<Options>( "/root/Options" );
_Reference = GetNode<Reference>("/root/Reference");
_Reference.GameHandler = this;
_Reference.GameUI = GetNode<Control>("/root/GameRoot/UI/GameUI");
_Reference.Lighting = GetNode<WorldEnvironment>("/root/GameRoot/Lighting");
_Reference.ItemSpawner = GetNode<MultiplayerSpawner>("/root/GameRoot/ItemSpawner");
_Reference.ItemSpawnPath = GetNode<Node>("/root/GameRoot/PickupItems");
_Reference.ToolBar = GetNode<Control>("/root/GameRoot/UI/GameUI/Game/ToolBar");
string[] CMDS = OS.GetCmdlineArgs();
bool temp_launch_as_server = false;
for( int i = 0; i < CMDS.Length; i++ ) {
if( CMDS [i].ToLower() == "--map" | CMDS [i].ToLower() == "/map" ) {
_Options.SelectedMap = Convert.ToInt32( CMDS [i + 1] );
} else if( CMDS [i].ToLower() == "--port" | CMDS [i].ToLower() == "/port" ) {
_Options.Port = Convert.ToInt32( CMDS [i + 1] );
} else if( CMDS [i].ToLower() == "--players" | CMDS [i].ToLower() == "/players" ) {
_Options.maxPlayers = Convert.ToInt32( CMDS [i + 1] );
} else if( CMDS [i].ToLower() == "--host" | CMDS [i].ToLower() == "/host" ) {
_Options.Host = CMDS [i + 1];
} else if( CMDS [i].ToLower() == "server" ) {
temp_launch_as_server = true;
}
}
if( OS.HasFeature( "dedicated_server" ) || DisplayServer.GetName() == "headless" || temp_launch_as_server ) {
StartServer();
}
}
public void StartServer(){
_Options.isServer = true;
_Options.connection = new ENetMultiplayerPeer();
_Options.connection.CreateServer( _Options.Port, _Options.maxPlayers );
Multiplayer.MultiplayerPeer = _Options.connection;
_Options.connection.PeerConnected += peerConnected;
_Options.connection.PeerDisconnected += peerDisconnected;
Node3D MapSelected = _Reference.GameHandler.MapList[_Options.SelectedMap].Instantiate<Node3D>();
MapSelected.SetMultiplayerAuthority(Multiplayer.GetUniqueId());
MapSelected.Name = "Workspace";
_Reference.Workspace = MapSelected;
_Reference.GameHandler.AddChild( MapSelected );
// Spawn the sun
AddChild( Sun.Instantiate<Node3D>() );
ResetItemDrops();
serverRunning = true;
}
public void StopServer(){
serverRunning = false;
}
public void StopClient(){
_Options.connection.PeerConnected -= peerConnected;
_Options.connection.PeerDisconnected -= peerDisconnected;
_Reference.Workspace.Multiplayer.ConnectedToServer -= ConnectedToServer;
_Reference.Workspace.Multiplayer.ConnectionFailed -= ConnectionFailed;
_Reference.Workspace.Multiplayer.ServerDisconnected -= DisconnectedFromServer;
}
public void StartClient(){
_Options.connection = new ENetMultiplayerPeer();
_Options.connection.CreateClient( _Options.Host, _Options.Port );
Multiplayer.MultiplayerPeer = _Options.connection;
Multiplayer.ConnectedToServer += ConnectedToServer;
Multiplayer.ConnectionFailed += ConnectionFailed;
Multiplayer.ServerDisconnected += DisconnectedFromServer;
}
public void RemovePlayer(int id){
if (HasNode(id.ToString())) {
GetNode(id.ToString()).QueueFree();
}
}
double timeElapsed = 0;
void ResetItemDrops(){
foreach( Node3D cur in _Reference.ItemSpawnPath.GetChildren()){
cur.QueueFree();
}
foreach( Node3D cur in _Reference.ItemSpawnPoints.GetChildren() ){
string[] PickupItems = _Reference.ItemSpawner._SpawnableScenes;
int chosenItem = new Random(DateTime.Now.Millisecond).Next(0, PickupItems.Length);
PackedScene ps = GD.Load<PackedScene>(PickupItems[chosenItem]);
Node3D prefab = ps.Instantiate<Node3D>();
prefab.Name = Guid.NewGuid().ToString();
_Reference.ItemSpawnPath.AddChild( prefab );
prefab.GlobalPosition = cur.GlobalPosition;
}
}
public override void _Process(double delta) {
if(serverRunning){
timeElapsed += delta;
if (timeElapsed > _Options.timeBetweenDropsReset * 60){
ResetItemDrops();
timeElapsed = 0;
}
}
}
// Called on server
public void peerConnected( long peerID ) {
}
public void peerDisconnected( long peerID ) {
RemovePlayer(Convert.ToInt32(peerID));
}
// Called on client
public void ConnectedToServer() {
_Reference.Alert.PerformAlert( "Connected to server successfully" );
}
public void ConnectionFailed() {
_Reference.Alert.PerformAlert( "Connection failed" );
}
public void DisconnectedFromServer() {
_Reference.Alert.PerformAlert( "Disconnected from server" );
}
///////////////////////////////////////////////////////////////////////
/// RPC's
///////////////////////////////////////////////////////////////////////
[Rpc( MultiplayerApi.RpcMode.AnyPeer, CallLocal = true, TransferChannel = 1, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)]
void _takeDamage(float DMG, int Creator, int Hit){
// Take Damage
Humanoid HitUser = null;
foreach(Node cur in _Reference.GameHandler.GetChildren()){
if ( cur.Name.ToString().Split(new char[]{','})[0] == Hit.ToString() ){
HitUser = (Humanoid)cur;
break;
}
}
Humanoid CreatorUser = null;
foreach(Node cur in _Reference.GameHandler.GetChildren()){
if ( cur.Name.ToString().Split(new char[]{','})[0] == Creator.ToString() ){
CreatorUser = (Humanoid)cur;
break;
}
}
HitUser.Health -= DMG;
// If Player Died
if( HitUser.Health <= 0 ) {
// Stuff to do on the died players computer
if (HitUser.GetMultiplayerAuthority() == Multiplayer.GetUniqueId()){
Input.MouseMode = Input.MouseModeEnum.Visible;
_Reference.Alert.PerformAlert("You died from Player : " + CreatorUser.PlayerName);
}
// Stuff to do on the killers computer
else if (CreatorUser.GetMultiplayerAuthority() == Multiplayer.GetUniqueId()){
_Reference.Alert.PerformAlert("You killed Player : " + HitUser.PlayerName);
}
// Stuff to do on Server
else if ( Multiplayer.GetUniqueId() == 1 ){
}
// Stuff to perform for everybody
// Award the player points
// Notify Player of kill
// Reset Dead player
}
// Update UI For Hit Player
if (HitUser.GetMultiplayerAuthority() == Multiplayer.GetUniqueId()){
HitUser.HealthBar.MaxValue = HitUser.MaxHealth;
HitUser.HealthBar.Value = Convert.ToDouble( HitUser.Health );
}
}
public void TakeDamage(float DMG, int Creator, int Hit){
Rpc("_takeDamage", DMG, Creator, Hit);
}
[Rpc( MultiplayerApi.RpcMode.AnyPeer, CallLocal = false, TransferChannel = 1, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)]
void _Shoot(int Creator, int itemID, Vector3 initialPosition, Vector3 ImpulseVector){
if (Multiplayer.GetUniqueId() == 1){
PackedScene ps = GD.Load<PackedScene>("res://Prefab/bullet.tscn");
Bullet physicsBullet = ps.Instantiate<Bullet>();
physicsBullet.Name = Guid.NewGuid().ToString();
physicsBullet.Creator = Creator;
physicsBullet.Damage = ((ItemStats)_Reference.ItemSpawnPath).stats[itemID].ToolDamage ;
GetNode<Node3D>("/root/GameRoot/Game").AddChild(physicsBullet);
physicsBullet.SetDeferred("global_position", initialPosition);
physicsBullet.CallDeferred("apply_impulse", ImpulseVector);
}
}
public void Shoot(int ToolID, Vector3 LookVector, float ImpulseForce){
Rpc("_Shoot", Multiplayer.GetUniqueId(), ToolID, _Reference.Humanoid.GlobalPosition + LookVector * 4, LookVector * ImpulseForce);
}
[Rpc( MultiplayerApi.RpcMode.AnyPeer, CallLocal = false, TransferChannel = 1, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)]
void _SpawnPlayer( int UniqueID, string PlayerName, int AbilityIndex ){
if (Multiplayer.IsServer()){
Humanoid playerCharacter = _Reference.GameHandler.Player.Instantiate<Humanoid>();
playerCharacter.Name = UniqueID.ToString() + "," + AbilityIndex + "," + PlayerName;
playerCharacter.PlayerName = PlayerName;
AddChild(playerCharacter, true);
playerCharacter.SetMultiplayerAuthority( UniqueID );
}
}
public void SpawnPlayer( int UniqueID, string PlayerName, Ability _Ability ){
Rpc( "_SpawnPlayer", UniqueID, PlayerName, (int)_Ability );
}
[Rpc( MultiplayerApi.RpcMode.AnyPeer, CallLocal = true, TransferChannel = 1, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)]
void _clearItemNetworked(string ItemName){
Node3D item = _Reference.ItemSpawnPath.GetNode<Node3D>(ItemName);
if (item != null){
try{
item.QueueFree();
}catch{}
}
}
public void ClearItemNetworked( string ItemName ){
Rpc("_clearItemNetworked", ItemName);
}
public class HumanoidStats {
public int HumanoidOwner { get; set; }
public string UserName { get; set; }
public int MaxHealth { get; set; }
public int Health { get; set; }
}
}
+46
View File
@@ -0,0 +1,46 @@
using Godot;
using System;
public partial class MainMenu : Control {
Options _Options;
Reference _Reference;
public override void _Ready() {
_Reference = GetNode<Reference>("/root/Reference");
_Options = GetNode<Options>( "/root/Options" );
_Reference.MainMenu = this;
}
void _on_settings_button_down() {
_Reference.SettingsFrame.ToggleSettingsVisibility();
}
public async void _on_join_game_pressed() {
SettingsFile sf = _Options._SettingsFile;
GameSettings gs = sf.Game;
string userN = gs.UserName;
string passW = gs.SessionToken;
(bool, Account) User = await _Reference.MistoxNet.TrySession( userN, passW );
if( User.Item1 ) {
_Reference.Lighting.Environment.SsrEnabled = sf.Display.ScreenSpaceReflections;
_Reference.Lighting.Environment.SsaoEnabled = sf.Display.ScreenSpaceAmbiantOcclusion;
_Reference.Lighting.Environment.SdfgiEnabled = sf.Display.GlobalIllumination;
_Reference.GameHandler.Visible = true;
_Reference.GameUI.Visible = true;
Visible = false;
_Options.Host = GetNode<TextEdit>("Host").Text;
_Reference.GameHandler.StartClient();
this.Visible = false;
_Reference.PreGame.Visible = true;
} else {
_Reference.Alert.PerformAlert( "Login failed" );
_Reference.SessionHandler.GetParent<Control>().Visible = true;
}
}
public void _on_start_server_pressed(){
_Reference.GameHandler.StartServer();
_Reference.MainMenu.Visible = false;
}
}
+46
View File
@@ -0,0 +1,46 @@
using Godot;
using System;
public partial class PreGame : Control {
Options _Options;
Reference _Reference;
Label _AbilityLabel;
public Ability _Ability = Ability.None;
[Export]
public PackedScene Backpack;
public override void _Ready() {
_Reference = GetNode<Reference>("/root/Reference");
_Options = GetNode<Options>( "/root/Options" );
_Reference.PreGame = this;
_AbilityLabel = this.GetChild<Label>(0);
_AbilityLabel.Text = "Current Ability : " + _Ability.ToString();
}
public void _on_ability_pressed() {
int AbilityIndex = (int)_Ability;
_Ability = ( Ability )(AbilityIndex + 1);
if( AbilityIndex >= Enum.GetValues( typeof( Ability ) ).Length - 1 ) {
_Ability = 0;
}
_AbilityLabel.Text = "Current Ability : " + _Ability.ToString();
}
public void _on_player_spawn_pressed(){
Inventory inv = Backpack.Instantiate<Inventory>();
GetNode<Control>("/root/GameRoot/UI/GameUI").AddChild(inv);
inv.Name = "Inventory";
_Reference.GameHandler.SpawnPlayer( Multiplayer.GetUniqueId(), _Options._SettingsFile.Game.UserName, _Ability );
_Reference.PreGame.Visible = false;
}
}
public enum Ability {
None, // No boost perk
Vitality, // Gain slightly more health
Strength, // Gain extra weight carrying | moves faster with more stuff
Stamina, // Run Faster
}
+33
View File
@@ -0,0 +1,33 @@
using Godot;
public partial class SessionHandler : Panel {
Options _Options;
Reference _Reference;
[Export] LineEdit UsernameBox;
[Export] LineEdit PasswordBox;
public override void _Ready() {
_Options = GetNode<Options>( "/root/Options" );
_Reference = GetNode<Reference>("/root/Reference");
_Reference.SessionHandler = this;
}
public async void onLogin() {
(bool, Account) User = await _Reference.MistoxNet.TryLogin( UsernameBox.Text, PasswordBox.Text );
if( User.Item1 ) {
_Reference.Alert.PerformAlert( "Login Success" );
_Options._SettingsFile.Game.UserName = User.Item2.UserName;
_Options._SettingsFile.Game.SessionToken = User.Item2.PasswordHash;
_Options._SettingsFile.Save();
GetParent<Control>().Visible = false;
} else {
_Reference.Alert.PerformAlert("Login Failed");
}
}
public void onRegister() {
OS.ShellOpen("https://www.mistox.net/account/register");
}
}
+266
View File
@@ -0,0 +1,266 @@
using Godot;
using System;
using Newtonsoft.Json;
public partial class Settings : TabContainer {
Control _GameSettings;
Control _DisplaySettings;
Control _AudioSettings;
Control _InputSettings;
Options _Options;
Reference _Reference;
public override void _Ready() {
_Reference = GetNode<Reference>("/root/Reference");
_Options = GetNode<Options>( "/root/Options" );
_Reference.SettingsFrame = this;
// Get Locations For Settings
_GameSettings = GetChild( ( int )Tabs.Game ).GetChild( 0 ).GetChild<Control>( 0 );
_DisplaySettings = GetChild( ( int )Tabs.Display ).GetChild( 0 ).GetChild<Control>( 0 );
_AudioSettings = GetChild( ( int )Tabs.Audio ).GetChild( 0 ).GetChild<Control>( 0 );
_InputSettings = GetChild( ( int )Tabs.Input ).GetChild( 0 ).GetChild<Control>( 0 );
if( !_Options.isServer ) {
// Load Settings
_Options._SettingsFile = new SettingsFile( "Settings.json" );
SetSettings();
// Game Settings
// Display Settings
Action<DisplayServer.WindowMode> wm = ( DisplayServer.WindowMode mode ) => { _Options._SettingsFile.Display.WindowMode = mode; };
BuildSetting( "Window Mode", _DisplaySettings, _Options._SettingsFile.Display.WindowMode, wm );
Action<float> rs = ( float mode ) => { _Options._SettingsFile.Display.ScreenScalingFactor = mode; };
BuildSetting( "Resolution Scale", _DisplaySettings, _Options._SettingsFile.Display.ScreenScalingFactor, rs );
Action<int> mf = ( int mode ) => { _Options._SettingsFile.Display.MaxFPS = mode; };
BuildSetting( "Max FPS", _DisplaySettings, _Options._SettingsFile.Display.MaxFPS, mf );
Action<DisplayServer.VSyncMode> vs = ( DisplayServer.VSyncMode mode ) => { _Options._SettingsFile.Display.VSync = mode; };
BuildSetting( "VSync", _DisplaySettings, _Options._SettingsFile.Display.VSync, vs );
Action<Viewport.Scaling3DModeEnum> ss = ( Viewport.Scaling3DModeEnum mode ) => { _Options._SettingsFile.Display.ScreenScaling = mode; };
BuildSetting( "Screen Scaling", _DisplaySettings, _Options._SettingsFile.Display.ScreenScaling, ss );
Action<float> fs = (float mode) => { _Options._SettingsFile.Display.FSRSharpness = mode; };
BuildSetting( "FSR Sharpness", _DisplaySettings, _Options._SettingsFile.Display.FSRSharpness, fs );
Action<Viewport.Msaa> msaa = ( Viewport.Msaa mode ) => { _Options._SettingsFile.Display.Msaa = mode; };
BuildSetting( "MSAA", _DisplaySettings, _Options._SettingsFile.Display.Msaa, msaa );
Action<Viewport.ScreenSpaceAAEnum> ssaa = ( Viewport.ScreenSpaceAAEnum mode ) => { _Options._SettingsFile.Display.ScreenSpaceAA = mode; };
BuildSetting( "SSAA", _DisplaySettings, _Options._SettingsFile.Display.ScreenSpaceAA, ssaa );
Action<bool> taa = ( bool mode ) => { _Options._SettingsFile.Display.TAA = mode; };
BuildSetting( "TAA", _DisplaySettings, _Options._SettingsFile.Display.TAA, taa );
Action<bool> SSR = ( bool mode ) => { _Options._SettingsFile.Display.ScreenSpaceReflections = mode; };
BuildSetting( "Screen Space Reflections", _DisplaySettings, _Options._SettingsFile.Display.ScreenSpaceReflections, SSR );
Action<bool> SSIL = ( bool mode ) => { _Options._SettingsFile.Display.ScreenSpaceIndirectLighting = mode; };
BuildSetting( "Indirect Lighting", _DisplaySettings, _Options._SettingsFile.Display.ScreenSpaceIndirectLighting, SSIL );
Action<bool> SSAO = ( bool mode ) => { _Options._SettingsFile.Display.ScreenSpaceAmbiantOcclusion = mode; };
BuildSetting( "Ambiant Occlusion", _DisplaySettings, _Options._SettingsFile.Display.ScreenSpaceAmbiantOcclusion, SSAO );
Action<bool> GI = ( bool mode ) => { _Options._SettingsFile.Display.GlobalIllumination = mode; };
BuildSetting( "Global Ilumination", _DisplaySettings, _Options._SettingsFile.Display.GlobalIllumination, GI );
// Audio Settings
// Input Settings
}
}
bool settingsVisible = true;
public void ToggleSettingsVisibility() {
if( _Options.isAlive ) {
} else {
GetNode<Control>( "/root/GameRoot/UI/SettingsFrame" ).Visible = settingsVisible;
GetNode<Control>( "/root/GameRoot/UI/MainMenu/ButtonList" ).Visible = !settingsVisible;
GetNode<Control>( "/root/GameRoot/UI/MainMenu/SelectedAbility" ).Visible = !settingsVisible;
settingsVisible = !settingsVisible;
}
}
public void OnSaveButtonDown() {
SetSettings();
_Options._SettingsFile.Save();
_Reference.Alert.PerformAlert( "Settings Saved" );
if ( !settingsVisible ) {
ToggleSettingsVisibility();
}
}
public void OnCancelButtonDown() {
if ( !settingsVisible ) {
ToggleSettingsVisibility();
}
}
void BuildSetting<T>( string SettingName, Control Parent, T DefaultSetting, Action<T> SettingEvent ) {
Control SettingFrameControl = new Control{
CustomMinimumSize = new Vector2(0, 50)
};
Panel Background = new Panel{
LayoutMode = 1
};
Background.SetAnchorsPreset( LayoutPreset.TopWide );
Background.SetSize( new Vector2( 780, 50 ) );
Background.Position = new Vector2( 10, 10 );
SettingFrameControl.AddChild( Background );
HBoxContainer container = new HBoxContainer{
LayoutMode = 1
};
container.SetAnchorsPreset( LayoutPreset.FullRect );
Background.AddChild( container );
Label SettingTitle = new Label{
Text = SettingName,
VerticalAlignment = VerticalAlignment.Center,
Uppercase = true,
CustomMinimumSize = new Vector2(390, 0)
};
container.AddChild( SettingTitle );
if( typeof( T ) == typeof( float ) ) {
// Slider 0 - 2
HSlider slider = new HSlider{
CustomMinimumSize = new Vector2(390, 50),
MinValue = 0,
MaxValue = 20,
TickCount = 21,
Rounded = true,
Value = Convert.ToSingle(DefaultSetting) * 10
};
slider.DragEnded += (bool changed) => {
SettingEvent((T)(object)( Convert.ToSingle( slider.Value ) / 10 ));
};
container.AddChild( slider );
} else if( typeof( T ) == typeof( int ) ) {
// Number Input
LineEdit numberEdit = new LineEdit{
CustomMinimumSize = new Vector2(390, 50),
Text = DefaultSetting.ToString()
};
numberEdit.TextChanged += ( string newText ) => {
if ( int.TryParse( newText, out int value ) ) {
SettingEvent((T)(object)( value ));
} else {
numberEdit.Text = DefaultSetting.ToString();
}
};
container.AddChild( numberEdit );
} else if( typeof( T ).IsEnum ) {
OptionButton menuButton = new OptionButton{
CustomMinimumSize = new Vector2(390, 0),
Text = DefaultSetting.ToString()
};
foreach (var settingOption in Enum.GetValues( typeof( T ) ) ) {
menuButton.AddItem( settingOption.ToString() );
}
menuButton.Selected = Convert.ToInt32( DefaultSetting );
menuButton.ItemSelected += ( long index ) => {
SettingEvent((T)(object)index);
};
container.AddChild( menuButton );
} else if ( typeof( T ) == typeof( bool ) ) {
// check box
CheckBox checkBox = new CheckBox{
CustomMinimumSize = new Vector2(390, 50),
ToggleMode = true,
ButtonPressed = Convert.ToBoolean(DefaultSetting)
};
checkBox.Toggled += (bool value) => {
checkBox.ButtonPressed = value;
SettingEvent((T)(object)value );
};
container.AddChild( checkBox );
}
Parent.AddChild( SettingFrameControl );
}
void SetSettings() {
// Display Settings
DisplayServer.WindowSetMode( _Options._SettingsFile.Display.WindowMode );
Engine.MaxFps = _Options._SettingsFile.Display.MaxFPS;
DisplayServer.WindowSetVsyncMode( _Options._SettingsFile.Display.VSync );
GetViewport().Scaling3DMode = _Options._SettingsFile.Display.ScreenScaling;
GetViewport().FsrSharpness = _Options._SettingsFile.Display.FSRSharpness;
GetViewport().Scaling3DScale = _Options._SettingsFile.Display.ScreenScalingFactor;
GetViewport().Msaa2D = _Options._SettingsFile.Display.Msaa;
GetViewport().Msaa3D = _Options._SettingsFile.Display.Msaa;
GetViewport().ScreenSpaceAA = _Options._SettingsFile.Display.ScreenSpaceAA;
GetViewport().UseTaa = _Options._SettingsFile.Display.TAA;
}
}
enum Tabs {
Game = 0,
Display = 1,
Audio = 2,
Input = 3
}
[Serializable]
public class SettingsFile {
string FilePath = string.Empty;
public GameSettings Game { get; set; }
public DisplaySettings Display { get; set; }
public AudioSettings Audio { get; set; }
public InputSettings Input { get; set; }
public SettingsFile( string Path ) {
FilePath = "user://" + Path;
using (Godot.FileAccess file = Godot.FileAccess.Open(FilePath, Godot.FileAccess.ModeFlags.Read)) {
if ( file != null ) {
string content = file.GetAsText();
SettingsFile temp = JsonConvert.DeserializeObject<SettingsFile>(content);
Game = temp.Game != null ? temp.Game : new GameSettings();
Display = temp.Display != null ? temp.Display : new DisplaySettings();
Audio = temp.Audio != null ? temp.Audio : new AudioSettings();
Input = temp.Input != null ? temp.Input : new InputSettings();
}else{
Game = new GameSettings();
Display = new DisplaySettings();
Audio = new AudioSettings();
Input = new InputSettings();
}
}
}
public void Save() {
using (Godot.FileAccess file = Godot.FileAccess.Open( FilePath, Godot.FileAccess.ModeFlags.Write ) ) {
file.StoreString( JsonConvert.SerializeObject( this, Formatting.Indented ) );
}
}
}
///
/// Settings File Settings
///
public class GameSettings {
public string UserName { get; set; } = String.Empty;
public string SessionToken { get; set; } = String.Empty;
}
public class DisplaySettings {
public DisplayServer.WindowMode WindowMode { get; set; }
public float ScreenScalingFactor { get; set; }
public int MaxFPS { get; set; }
public DisplayServer.VSyncMode VSync { get; set; }
public Viewport.Scaling3DModeEnum ScreenScaling { get; set; }
public float FSRSharpness { get; set; }
public Viewport.Msaa Msaa { get; set; }
public Viewport.ScreenSpaceAAEnum ScreenSpaceAA { get; set; }
public bool TAA { get; set; }
public bool ScreenSpaceReflections { get; set; }
public bool ScreenSpaceIndirectLighting { get; set; }
public bool ScreenSpaceAmbiantOcclusion { get; set; }
public bool GlobalIllumination { get; set; }
}
public class AudioSettings {
}
public class InputSettings {
}
+36
View File
@@ -0,0 +1,36 @@
using Godot;
public partial class ItemStats : Node {
// Item 0
public StatItem[] stats = {
new StatItem{
ItemName = "Sniper",
InventorySize = new Vector2I(1, 4),
Weight = 400,
IsQuantityItem = false,
ToolPath = "res://Prefab/Tools/Sniper.tscn",
ToolDamage = 50
},
// Item 1
new StatItem{
},
// Item 2
new StatItem{
},
};
}
public class StatItem {
public string ItemName {get; set;} = "";
public Vector2I InventorySize {get; set;}
public int Weight {get; set;}
public bool IsQuantityItem {get; set;}
public int MaxQuantity {get; set;}
public string ToolPath {get; set;}
public int ToolDamage { get; set; }
}
+59
View File
@@ -0,0 +1,59 @@
using Godot;
using Newtonsoft.Json;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
public partial class MistoxNet : Node{
Options _Options;
Reference _Reference;
public override void _Ready() {
_Options = GetNode<Options>( "/root/Options" );
_Reference = GetNode<Reference>("/root/Reference");
_Reference.MistoxNet = this;
}
public async Task<(bool, Account)> TrySession( string UserName, string Password ) {
using( System.Net.Http.HttpClient client = new System.Net.Http.HttpClient() ) {
HttpResponseMessage response = await client.PostAsJsonAsync( "https://mistox.net/api/account/session", new Account { UserName = UserName, PasswordHash = Password } );
string result = await response.Content.ReadAsStringAsync();
Account User = JsonConvert.DeserializeObject<Account>(result);
if( User != null && string.IsNullOrEmpty( User.Error ) ) {
return (true, User);
}
return (false, User);
}
}
public async Task<(bool, Account)> TryLogin( string UserName, string Password ) {
using( System.Net.Http.HttpClient client = new System.Net.Http.HttpClient() ) {
HttpResponseMessage response = await client.PostAsJsonAsync( "https://mistox.net/api/account/login", new Account { UserName = UserName, PasswordHash = Password } );
string result = await response.Content.ReadAsStringAsync();
Account User = JsonConvert.DeserializeObject<Account>(result);
if( User != null && string.IsNullOrEmpty( User.Error ) ) {
return (true, User);
}
return (false, User);
}
}
}
public class Account {
public int ID { get; set; } // PK
public string UserName { get; set; } = "";
public string Email { get; set; } = "";
public bool EmailVerified { get; set; } = false;
public string PasswordHash { get; set; } = "";
public string Error { get; set; } = "";
}
public class ProjectMistData {
public int AccountID { get; set; } // PK
public int Credits { get; set; }
public int OddballTimer { get; set; }
public string SessionToken { get; set; } = "";
public int SessionID { get; set; }
public int Kills { get; set; }
public int Deaths { get; set; }
}
+48
View File
@@ -0,0 +1,48 @@
using Godot;
using System;
public partial class Options : Node {
// Server Settings
public ENetMultiplayerPeer connection;
public bool isServer = false;
public string Host = "mistox.net";
public int Port = 6500;
public int SelectedMap = 0;
public int maxPlayers = 32;
public bool isAlive = false;
public double timeBetweenDropsReset = 2f; // in Minutes
// Saved Settings
public SettingsFile _SettingsFile;
// Alert Settings
public float AlertTime = 2f;
public float AlertPauseTime = 1f;
// Select Tool
public float ClickDistance = 5;
}
namespace Godot {
public static class Extensions {
public static T [] Join<T>( this T [] first, T [] second ) {
T[] bytes = new T[first.Length + second.Length];
#pragma warning disable CA2018 // 'Buffer.BlockCopy' expects the number of bytes to be copied for the 'count' argument
Buffer.BlockCopy( first, 0, bytes, 0, first.Length );
Buffer.BlockCopy( second, 0, bytes, first.Length, second.Length );
#pragma warning restore CA2018 // 'Buffer.BlockCopy' expects the number of bytes to be copied for the 'count' argument
return bytes;
}
public static T [] Sub<T>( this T [] data, int index, int length ) {
T[] result = new T[length];
Array.Copy( data, index, result, 0, length );
return result;
}
}
}
+24
View File
@@ -0,0 +1,24 @@
using Godot;
public partial class Reference : Node {
public MistoxNet MistoxNet { get; set; }
public Alert Alert { get; set; }
public GameHandler GameHandler { get; set; }
public Humanoid Humanoid { get; set; }
public Inventory Inventory { get; set; }
public Node Workspace { get; set; }
public WorldEnvironment Lighting { get; set; }
public Control GameUI { get; set; }
public Camera3D Camera { get; set; }
public MainMenu MainMenu { get; set; }
public PreGame PreGame { get; set; }
public Settings SettingsFrame { get; set; }
public SessionHandler SessionHandler { get; set; }
public Control ToolBar{ get; set; }
public MultiplayerSpawner GameSpawner { get; set; }
public Node3D PlayerSpawnPoints { get; set; }
public MultiplayerSpawner ItemSpawner{ get; set; }
public Node3D ItemSpawnPoints { get; set; }
public Node ItemSpawnPath{ get; set; }
}