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
+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 );
}