Compare commits

...

8 Commits

45 changed files with 240 additions and 224 deletions

View File

@ -1,19 +1,13 @@
[gd_scene load_steps=3 format=3] [gd_scene load_steps=3 format=3 uid="uid://dmjlddmt2h1pa"]
[ext_resource type="Texture2D" uid="uid://cgptnp74ive4r" path="res://resource/sprite/common/Circle.png" id="1"] [ext_resource type="Texture2D" uid="uid://cgptnp74ive4r" path="res://resource/sprite/common/Circle.png" id="1"]
[ext_resource type="Script" path="res://src/game/effects/Blood.cs" id="2"] [ext_resource type="Script" path="res://src/game/effects/Blood.cs" id="2"]
[node name="Blood" type="CPUParticles2D"] [node name="Blood" type="CPUParticles2D"]
z_index = -5 z_index = -5
lifetime = 0.2 lifetime = 0.2
explosiveness = 0.9 explosiveness = 0.9
texture = ExtResource( 1 ) texture = ExtResource("1")
gravity = Vector2( 0, 0 ) gravity = Vector2(0, 0)
initial_velocity = 150.0 color = Color(0.627451, 0.0705882, 0.0705882, 0.705882)
initial_velocity_random = 1.0 script = ExtResource("2")
scale_amount = 0.15
scale_amount_random = 0.4
color = Color( 0.627451, 0.0705882, 0.0705882, 0.705882 )
script = ExtResource( 2 )

View File

@ -4,8 +4,6 @@
[ext_resource type="Shader" path="res://resource/shader/Blend.gdshader" id="2_1c01w"] [ext_resource type="Shader" path="res://resource/shader/Blend.gdshader" id="2_1c01w"]
[ext_resource type="Texture2D" uid="uid://b74yx6c2jifyd" path="res://resource/sprite/item/hall_b/item-31.png" id="3_mua0g"] [ext_resource type="Texture2D" uid="uid://b74yx6c2jifyd" path="res://resource/sprite/item/hall_b/item-31.png" id="3_mua0g"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_wh4b7"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_wh4b7"]
resource_local_to_scene = true resource_local_to_scene = true
shader = ExtResource("2_1c01w") shader = ExtResource("2_1c01w")
@ -42,7 +40,7 @@ animations = [{
}] }]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_kmpvc"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_kmpvc"]
size = Vector2(58, 16) size = Vector2(42, 16)
[node name="Item0001" type="CharacterBody2D" node_paths=PackedStringArray("ShadowSprite", "AnimatedSprite", "Collision")] [node name="Item0001" type="CharacterBody2D" node_paths=PackedStringArray("ShadowSprite", "AnimatedSprite", "Collision")]
collision_layer = 512 collision_layer = 512
@ -62,5 +60,9 @@ position = Vector2(0, -10.5)
sprite_frames = SubResource("SpriteFrames_uqva1") sprite_frames = SubResource("SpriteFrames_uqva1")
[node name="Collision" type="CollisionShape2D" parent="."] [node name="Collision" type="CollisionShape2D" parent="."]
position = Vector2(0, 4) position = Vector2(-3, -15)
shape = SubResource("RectangleShape2D_kmpvc") shape = SubResource("RectangleShape2D_kmpvc")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
position = Vector2(32, -10)
polygon = PackedVector2Array(-14, 31, -14, -13, 4, -13, 4, 31)

View File

@ -4,8 +4,6 @@
[ext_resource type="Shader" path="res://resource/shader/Blend.gdshader" id="2_u3oiv"] [ext_resource type="Shader" path="res://resource/shader/Blend.gdshader" id="2_u3oiv"]
[ext_resource type="Texture2D" uid="uid://dl15qkga1kc82" path="res://resource/sprite/item/hall_b/item-12.png" id="3_6b42f"] [ext_resource type="Texture2D" uid="uid://dl15qkga1kc82" path="res://resource/sprite/item/hall_b/item-12.png" id="3_6b42f"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_wh4b7"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_wh4b7"]
resource_local_to_scene = true resource_local_to_scene = true
shader = ExtResource("2_u3oiv") shader = ExtResource("2_u3oiv")
@ -55,7 +53,7 @@ material = SubResource("ShaderMaterial_wh4b7")
[node name="AnimatedSprite" type="AnimatedSprite2D" parent="."] [node name="AnimatedSprite" type="AnimatedSprite2D" parent="."]
material = SubResource("ShaderMaterial_f7tsa") material = SubResource("ShaderMaterial_f7tsa")
position = Vector2(15.5, -10) position = Vector2(0, -10)
sprite_frames = SubResource("SpriteFrames_uqva1") sprite_frames = SubResource("SpriteFrames_uqva1")
[node name="Collision" type="CollisionShape2D" parent="."] [node name="Collision" type="CollisionShape2D" parent="."]

View File

@ -4,8 +4,6 @@
[ext_resource type="Shader" path="res://resource/shader/Blend.gdshader" id="2_fbidd"] [ext_resource type="Shader" path="res://resource/shader/Blend.gdshader" id="2_fbidd"]
[ext_resource type="Texture2D" uid="uid://dr2d6toqxxifv" path="res://resource/sprite/item/hall_b/item-32.png" id="3_4miy3"] [ext_resource type="Texture2D" uid="uid://dr2d6toqxxifv" path="res://resource/sprite/item/hall_b/item-32.png" id="3_4miy3"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_wh4b7"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_wh4b7"]
resource_local_to_scene = true resource_local_to_scene = true
shader = ExtResource("2_fbidd") shader = ExtResource("2_fbidd")
@ -42,7 +40,7 @@ animations = [{
}] }]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_p3c6b"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_p3c6b"]
size = Vector2(54, 17) size = Vector2(28, 29)
[node name="Item0003" type="CharacterBody2D" node_paths=PackedStringArray("ShadowSprite", "AnimatedSprite", "Collision")] [node name="Item0003" type="CharacterBody2D" node_paths=PackedStringArray("ShadowSprite", "AnimatedSprite", "Collision")]
collision_layer = 512 collision_layer = 512
@ -58,9 +56,7 @@ material = SubResource("ShaderMaterial_wh4b7")
[node name="AnimatedSprite" type="AnimatedSprite2D" parent="."] [node name="AnimatedSprite" type="AnimatedSprite2D" parent="."]
material = SubResource("ShaderMaterial_f7tsa") material = SubResource("ShaderMaterial_f7tsa")
position = Vector2(0, -4)
sprite_frames = SubResource("SpriteFrames_uqva1") sprite_frames = SubResource("SpriteFrames_uqva1")
[node name="Collision" type="CollisionShape2D" parent="."] [node name="Collision" type="CollisionShape2D" parent="."]
position = Vector2(0, 2.5)
shape = SubResource("RectangleShape2D_p3c6b") shape = SubResource("RectangleShape2D_p3c6b")

View File

@ -4,8 +4,6 @@
[ext_resource type="Shader" path="res://resource/shader/Blend.gdshader" id="2_lp5ce"] [ext_resource type="Shader" path="res://resource/shader/Blend.gdshader" id="2_lp5ce"]
[ext_resource type="Texture2D" uid="uid://belr22s50exy8" path="res://resource/sprite/item/hall_b/item-18.png" id="3_px2by"] [ext_resource type="Texture2D" uid="uid://belr22s50exy8" path="res://resource/sprite/item/hall_b/item-18.png" id="3_px2by"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_wh4b7"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_wh4b7"]
resource_local_to_scene = true resource_local_to_scene = true
shader = ExtResource("2_lp5ce") shader = ExtResource("2_lp5ce")
@ -42,7 +40,7 @@ animations = [{
}] }]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_p3c6b"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_p3c6b"]
size = Vector2(24, 12) size = Vector2(62, 73)
[node name="Item0004" type="CharacterBody2D" node_paths=PackedStringArray("ShadowSprite", "AnimatedSprite", "Collision")] [node name="Item0004" type="CharacterBody2D" node_paths=PackedStringArray("ShadowSprite", "AnimatedSprite", "Collision")]
collision_layer = 512 collision_layer = 512
@ -58,9 +56,17 @@ material = SubResource("ShaderMaterial_wh4b7")
[node name="AnimatedSprite" type="AnimatedSprite2D" parent="."] [node name="AnimatedSprite" type="AnimatedSprite2D" parent="."]
material = SubResource("ShaderMaterial_f7tsa") material = SubResource("ShaderMaterial_f7tsa")
position = Vector2(0, -4) position = Vector2(0, 27)
sprite_frames = SubResource("SpriteFrames_uqva1") sprite_frames = SubResource("SpriteFrames_uqva1")
[node name="Collision" type="CollisionShape2D" parent="."] [node name="Collision" type="CollisionShape2D" parent="."]
position = Vector2(0, 2) position = Vector2(0, 35)
scale = Vector2(1e-05, 1e-05)
shape = SubResource("RectangleShape2D_p3c6b") shape = SubResource("RectangleShape2D_p3c6b")
one_way_collision_margin = 0.0
debug_color = Color(0, 0.6, 0.701961, 0.419608)
metadata/collsionShape2D1 = false
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
position = Vector2(-29, 14)
polygon = PackedVector2Array(-12, -14, 48, -14, 48, 51, 69, 51, 69, 55, -12, 55)

View File

@ -4,8 +4,6 @@
[ext_resource type="Shader" path="res://resource/shader/Blend.gdshader" id="2_fshwj"] [ext_resource type="Shader" path="res://resource/shader/Blend.gdshader" id="2_fshwj"]
[ext_resource type="Texture2D" uid="uid://bijiqseh8y667" path="res://resource/sprite/item/hall_b/item-01.png" id="3_3isqs"] [ext_resource type="Texture2D" uid="uid://bijiqseh8y667" path="res://resource/sprite/item/hall_b/item-01.png" id="3_3isqs"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_wh4b7"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_wh4b7"]
resource_local_to_scene = true resource_local_to_scene = true
shader = ExtResource("2_fshwj") shader = ExtResource("2_fshwj")
@ -58,9 +56,9 @@ material = SubResource("ShaderMaterial_wh4b7")
[node name="AnimatedSprite" type="AnimatedSprite2D" parent="."] [node name="AnimatedSprite" type="AnimatedSprite2D" parent="."]
material = SubResource("ShaderMaterial_f7tsa") material = SubResource("ShaderMaterial_f7tsa")
position = Vector2(0, -4) position = Vector2(0.5, -0.5)
sprite_frames = SubResource("SpriteFrames_uqva1") sprite_frames = SubResource("SpriteFrames_uqva1")
[node name="Collision" type="CollisionShape2D" parent="."] [node name="Collision" type="CollisionShape2D" parent="."]
position = Vector2(0, -1) position = Vector2(0, 5)
shape = SubResource("RectangleShape2D_p3c6b") shape = SubResource("RectangleShape2D_p3c6b")

View File

@ -4,7 +4,6 @@
[ext_resource type="Shader" path="res://resource/shader/Blend.gdshader" id="2_5sjig"] [ext_resource type="Shader" path="res://resource/shader/Blend.gdshader" id="2_5sjig"]
[ext_resource type="Texture2D" uid="uid://u3ri36urv8xn" path="res://resource/sprite/item/hall_c/item _56.png" id="3_bkxin"] [ext_resource type="Texture2D" uid="uid://u3ri36urv8xn" path="res://resource/sprite/item/hall_c/item _56.png" id="3_bkxin"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_wh4b7"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_wh4b7"]
resource_local_to_scene = true resource_local_to_scene = true
shader = ExtResource("2_5sjig") shader = ExtResource("2_5sjig")
@ -41,7 +40,7 @@ animations = [{
}] }]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_kmpvc"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_kmpvc"]
size = Vector2(46, 12) size = Vector2(26, 12)
[node name="Item0056" type="CharacterBody2D" node_paths=PackedStringArray("ShadowSprite", "AnimatedSprite", "Collision")] [node name="Item0056" type="CharacterBody2D" node_paths=PackedStringArray("ShadowSprite", "AnimatedSprite", "Collision")]
collision_layer = 512 collision_layer = 512
@ -61,5 +60,5 @@ position = Vector2(0, 2)
sprite_frames = SubResource("SpriteFrames_uqva1") sprite_frames = SubResource("SpriteFrames_uqva1")
[node name="Collision" type="CollisionShape2D" parent="."] [node name="Collision" type="CollisionShape2D" parent="."]
position = Vector2(0, 5) position = Vector2(0, 17)
shape = SubResource("RectangleShape2D_kmpvc") shape = SubResource("RectangleShape2D_kmpvc")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 462 B

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 616 B

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 971 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 317 B

After

Width:  |  Height:  |  Size: 350 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -134,6 +134,12 @@ texture = ExtResource("1_vwr2k")
3:5/0 = 0 3:5/0 = 0
3:5/0/physics_layer_0/linear_velocity = Vector2(0, 0) 3:5/0/physics_layer_0/linear_velocity = Vector2(0, 0)
3:5/0/physics_layer_0/angular_velocity = 0.0 3:5/0/physics_layer_0/angular_velocity = 0.0
4:5/0 = 0
4:5/0/physics_layer_0/linear_velocity = Vector2(0, 0)
4:5/0/physics_layer_0/angular_velocity = 0.0
5:5/0 = 0
5:5/0/physics_layer_0/linear_velocity = Vector2(0, 0)
5:5/0/physics_layer_0/angular_velocity = 0.0
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_wecvb"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_wecvb"]
texture = ExtResource("2_01oxu") texture = ExtResource("2_01oxu")
@ -144,5 +150,5 @@ texture = ExtResource("2_01oxu")
[resource] [resource]
physics_layer_0/collision_layer = 1 physics_layer_0/collision_layer = 1
physics_layer_0/collision_mask = 0 physics_layer_0/collision_mask = 0
sources/0 = SubResource("TileSetAtlasSource_7e1ow")
sources/1 = SubResource("TileSetAtlasSource_wecvb") sources/1 = SubResource("TileSetAtlasSource_wecvb")
sources/0 = SubResource("TileSetAtlasSource_7e1ow")

File diff suppressed because one or more lines are too long

View File

@ -88,7 +88,7 @@ public partial class AffiliationArea : Area2D, IDestroy
if (_includeItems.Add(activityObject)) if (_includeItems.Add(activityObject))
{ {
//如果是玩家 //如果是玩家
if (activityObject == Player.Current) if (activityObject == RoomInfo.World.Player)
{ {
CallDeferred(nameof(OnPlayerInsertRoom)); CallDeferred(nameof(OnPlayerInsertRoom));
} }
@ -287,7 +287,7 @@ public partial class AffiliationArea : Area2D, IDestroy
{ {
if (IsFirstEnterFlag) if (IsFirstEnterFlag)
{ {
Player.Current.OnFirstEnterRoom(RoomInfo); RoomInfo.World.Player.OnFirstEnterRoom(RoomInfo);
EventManager.EmitEvent(EventEnum.OnPlayerFirstEnterRoom, RoomInfo); EventManager.EmitEvent(EventEnum.OnPlayerFirstEnterRoom, RoomInfo);
} }
EventManager.EmitEvent(EventEnum.OnPlayerEnterRoom, RoomInfo); EventManager.EmitEvent(EventEnum.OnPlayerEnterRoom, RoomInfo);

View File

@ -63,7 +63,7 @@ public partial class AisleFogArea : Area2D, IDestroy
private void OnBodyEntered(Node2D body) private void OnBodyEntered(Node2D body)
{ {
if (body == Player.Current) if (body == RoomDoorInfo.RoomInfo.World.Player)
{ {
//注意需要延时调用 //注意需要延时调用
CallDeferred(nameof(InsertPlayer)); CallDeferred(nameof(InsertPlayer));

View File

@ -20,6 +20,11 @@ public class RoomInfo : IDestroy
RoomType = type; RoomType = type;
RoomSplit = roomSplit; RoomSplit = roomSplit;
} }
/// <summary>
/// 所在世界对象
/// </summary>
public World World;
/// <summary> /// <summary>
/// 房间 id /// 房间 id

View File

@ -12,7 +12,12 @@ public partial class World : CanvasModulate, ICoroutine
/// <summary> /// <summary>
/// 当前的游戏世界对象 /// 当前的游戏世界对象
/// </summary> /// </summary>
public static World Current => GameApplication.Instance?.DungeonManager?.CurrWorld; public static World Current => GameApplication.Instance.DungeonManager.CurrWorld;
/// <summary>
/// 当前操作的玩家
/// </summary>
public Player Player { get; private set; }
/// <summary> /// <summary>
/// //对象根节点 /// //对象根节点
@ -119,6 +124,17 @@ public partial class World : CanvasModulate, ICoroutine
return null; return null;
} }
/// <summary>
/// 设置当前操作的玩家对象
/// </summary>
public void SetCurrentPlayer(Player player)
{
Player = player;
//设置相机和鼠标跟随玩家
GameCamera.Main.SetFollowTarget(player);
GameApplication.Instance.Cursor.SetMountRole(player);
}
/// <summary> /// <summary>
/// 通知其他敌人发现目标了 /// 通知其他敌人发现目标了
/// </summary> /// </summary>

View File

@ -103,7 +103,7 @@ public partial class Laser : Area2D, IBullet
LineSprite.Scale = new Vector2(0, width * _pixelScale); LineSprite.Scale = new Vector2(0, width * _pixelScale);
//如果子弹会对玩家造成伤害, 则显示成红色 //如果子弹会对玩家造成伤害, 则显示成红色
if (Player.Current.CollisionWithMask(attackLayer)) if (BulletData.World.Player.CollisionWithMask(attackLayer))
{ {
LineSprite.Modulate = new Color(2.5f, 0.5f, 0.5f); LineSprite.Modulate = new Color(2.5f, 0.5f, 0.5f);
} }

View File

@ -120,7 +120,7 @@ public partial class Bullet : ActivityObject, IBullet
MoveController.AddForce(new Vector2(data.FlySpeed, 0).Rotated(Rotation)); MoveController.AddForce(new Vector2(data.FlySpeed, 0).Rotated(Rotation));
//如果子弹会对玩家造成伤害, 则显示红色描边 //如果子弹会对玩家造成伤害, 则显示红色描边
if (Player.Current != null && Player.Current.CollisionWithMask(attackLayer)) if (World.Player != null && World.Player.CollisionWithMask(attackLayer))
{ {
if (!IsEnemyBullet) if (!IsEnemyBullet)
{ {

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using Godot; using Godot;
/// <summary> /// <summary>
@ -27,7 +28,7 @@ public partial class Gold : ActivityObject, IPoolItem
protected override void OnThrowOver() protected override void OnThrowOver()
{ {
var current = Player.Current; var current = World.Player;
if (current != null) if (current != null)
{ {
this.CallDelay(0.3f, () => this.CallDelay(0.3f, () =>
@ -70,4 +71,29 @@ public partial class Gold : ActivityObject, IPoolItem
MoveController.ClearForce(); MoveController.ClearForce();
MoveController.SetAllVelocity(Vector2.Zero); MoveController.SetAllVelocity(Vector2.Zero);
} }
/// <summary>
/// 创建散落的金币
/// </summary>
/// <param name="position">位置</param>
/// <param name="count">金币数量</param>
/// <param name="force">投抛力度</param>
public static List<Gold> CreateGold(Vector2 position, int count, int force = 10)
{
var list = new List<Gold>();
var goldList = Utils.GetGoldList(count);
foreach (var id in goldList)
{
var o = ObjectManager.GetActivityObject<Gold>(id);
o.Position = position;
o.Throw(0,
Utils.Random.RandomRangeInt(5 * force, 11 * force),
new Vector2(Utils.Random.RandomRangeInt(-2 * force, 2 * force), Utils.Random.RandomRangeInt(-2 * force, 2 * force)),
0
);
list.Add(o);
}
return list;
}
} }

View File

@ -1013,7 +1013,7 @@ public abstract partial class Role : ActivityObject
/// </summary> /// </summary>
public bool IsPlayer() public bool IsPlayer()
{ {
return this == Player.Current; return this == World.Player;
} }
/// <summary> /// <summary>
@ -1021,11 +1021,11 @@ public abstract partial class Role : ActivityObject
/// </summary> /// </summary>
public bool IsEnemyWithPlayer() public bool IsEnemyWithPlayer()
{ {
if (Player.Current == null) if (World.Player == null)
{ {
return false; return false;
} }
return CollisionWithMask(Player.Current.EnemyLayer); return CollisionWithMask(World.Player.EnemyLayer);
} }
/// <summary> /// <summary>

View File

@ -100,7 +100,15 @@ public abstract partial class AiRole : Role
//NavigationAgent2D.VelocityComputed += OnVelocityComputed; //NavigationAgent2D.VelocityComputed += OnVelocityComputed;
} }
/// <summary> /// <summary>
/// 获取攻击的目标对象, 该函数不能返回 null
/// </summary>
public virtual Role GetAttackTarget()
{
return World.Player;
}
/// <summary>
/// 返回地上的武器是否有可以拾取的, 也包含没有被其他敌人标记的武器 /// 返回地上的武器是否有可以拾取的, 也包含没有被其他敌人标记的武器
/// </summary> /// </summary>
public bool CheckUsableWeaponInUnclaimed() public bool CheckUsableWeaponInUnclaimed()
@ -369,7 +377,17 @@ public abstract partial class AiRole : Role
AffiliationArea.RoomInfo.MarkTargetPosition[LookTarget.Id] = LookTarget.Position; AffiliationArea.RoomInfo.MarkTargetPosition[LookTarget.Id] = LookTarget.Position;
} }
} }
protected override void OnDie()
{
//扔掉所有武器
ThrowAllWeapon();
//创建金币
Gold.CreateGold(Position, RoleState.Gold);
//销毁
Destroy();
}
// private void OnVelocityComputed(Vector2 velocity) // private void OnVelocityComputed(Vector2 velocity)
// { // {
// if (Mathf.Abs(velocity.X) >= 0.01f && Mathf.Abs(velocity.Y) >= 0.01f) // if (Mathf.Abs(velocity.X) >= 0.01f && Mathf.Abs(velocity.Y) >= 0.01f)

View File

@ -75,14 +75,14 @@ public class AiFindAmmoState : StateBase<AiRole, AIStateEnum>
if (Master.LookTarget == null) //没有目标 if (Master.LookTarget == null) //没有目标
{ {
//临时处理 //临时处理
var player = Player.Current; var attackTarget = Master.GetAttackTarget();
var playerPos = player.GetCenterPosition(); var targetPos = attackTarget.GetCenterPosition();
if (Master.IsInViewRange(playerPos) && !Master.TestViewRayCast(playerPos)) //发现玩家 if (Master.IsInViewRange(targetPos) && !Master.TestViewRayCast(targetPos)) //发现玩家
{ {
//关闭射线检测 //关闭射线检测
Master.TestViewRayCastOver(); Master.TestViewRayCastOver();
//发现玩家 //发现玩家
Master.LookTarget = player; Master.LookTarget = attackTarget;
//进入惊讶状态, 然后再进入通知状态 //进入惊讶状态, 然后再进入通知状态
ChangeState(AIStateEnum.AiAstonished, AIStateEnum.AiFindAmmo, TargetWeapon); ChangeState(AIStateEnum.AiAstonished, AIStateEnum.AiFindAmmo, TargetWeapon);
return; return;

View File

@ -102,16 +102,17 @@ public class AiLeaveForState : StateBase<AiRole, AIStateEnum>
Master.DoIdle(); Master.DoIdle();
} }
var playerPos = Player.Current.GetCenterPosition(); var attackTarget = Master.GetAttackTarget();
var targetPos = attackTarget.GetCenterPosition();
//检测玩家是否在视野内, 如果在, 则切换到 AiTargetInView 状态 //检测玩家是否在视野内, 如果在, 则切换到 AiTargetInView 状态
if (Master.IsInTailAfterViewRange(playerPos)) if (Master.IsInTailAfterViewRange(targetPos))
{ {
if (!Master.TestViewRayCast(playerPos)) //看到玩家 if (!Master.TestViewRayCast(targetPos)) //看到玩家
{ {
//关闭射线检测 //关闭射线检测
Master.TestViewRayCastOver(); Master.TestViewRayCastOver();
//切换成发现目标状态 //切换成发现目标状态
Master.LookTarget = Player.Current; Master.LookTarget = attackTarget;
ChangeState(AIStateEnum.AiAstonished, AIStateEnum.AiFollowUp); ChangeState(AIStateEnum.AiAstonished, AIStateEnum.AiFollowUp);
return; return;
} }

View File

@ -46,17 +46,17 @@ public class AiNormalState : StateBase<AiRole, AIStateEnum>
public override void Process(float delta) public override void Process(float delta)
{ {
//检测玩家 //获取攻击目标
var player = Player.Current; var attackTarget = Master.GetAttackTarget();
//玩家中心点坐标 //玩家中心点坐标
var playerPos = player.GetCenterPosition(); var targetPos = attackTarget.GetCenterPosition();
if (Master.IsInViewRange(playerPos) && !Master.TestViewRayCast(playerPos)) //发现玩家 if (Master.IsInViewRange(targetPos) && !Master.TestViewRayCast(targetPos)) //发现目标
{ {
//关闭射线检测 //关闭射线检测
Master.TestViewRayCastOver(); Master.TestViewRayCastOver();
//发现玩家 //发现玩家
Master.LookTarget = player; Master.LookTarget = attackTarget;
//判断是否进入通知状态 //判断是否进入通知状态
if (Master.World.Enemy_InstanceList.FindIndex(enemy => if (Master.World.Enemy_InstanceList.FindIndex(enemy =>
enemy != Master && !enemy.IsDie && enemy.AffiliationArea == Master.AffiliationArea && enemy != Master && !enemy.IsDie && enemy.AffiliationArea == Master.AffiliationArea &&

View File

@ -110,9 +110,6 @@ public partial class Enemy : AiRole
protected override void OnDie() protected override void OnDie()
{ {
//扔掉所有武器
ThrowAllWeapon();
var effPos = Position + new Vector2(0, -Altitude); var effPos = Position + new Vector2(0, -Altitude);
//血液特效 //血液特效
var blood = ObjectManager.GetPoolItem<AutoDestroyParticles>(ResourcePath.prefab_effect_enemy_EnemyBlood0001_tscn); var blood = ObjectManager.GetPoolItem<AutoDestroyParticles>(ResourcePath.prefab_effect_enemy_EnemyBlood0001_tscn);
@ -130,12 +127,10 @@ public partial class Enemy : AiRole
debris.MoveController.AddForce(Velocity + realVelocity); debris.MoveController.AddForce(Velocity + realVelocity);
} }
//创建金币
CreateGold();
//派发敌人死亡信号 //派发敌人死亡信号
EventManager.EmitEvent(EventEnum.OnEnemyDie, this); EventManager.EmitEvent(EventEnum.OnEnemyDie, this);
Destroy();
base.OnDie();
} }
protected override void Process(float delta) protected override void Process(float delta)
@ -172,24 +167,6 @@ public partial class Enemy : AiRole
} }
} }
/// <summary>
/// 创建散落的金币
/// </summary>
protected void CreateGold()
{
var goldList = Utils.GetGoldList(RoleState.Gold);
foreach (var id in goldList)
{
var o = ObjectManager.GetActivityObject<Gold>(id);
o.Position = Position;
o.Throw(0,
Utils.Random.RandomRangeInt(50, 110),
new Vector2(Utils.Random.RandomRangeInt(-20, 20), Utils.Random.RandomRangeInt(-20, 20)),
0
);
}
}
public override bool IsAllWeaponTotalAmmoEmpty() public override bool IsAllWeaponTotalAmmoEmpty()
{ {
if (!_enemyAttribute.CanPickUpWeapon) if (!_enemyAttribute.CanPickUpWeapon)

View File

@ -71,7 +71,7 @@ public partial class NoWeaponEnemy : Enemy
debris.BrushPrevPosition = BrushPrevPosition; debris.BrushPrevPosition = BrushPrevPosition;
//创建金币 //创建金币
CreateGold(); Gold.CreateGold(Position, RoleState.Gold);
//派发敌人死亡信号 //派发敌人死亡信号
EventManager.EmitEvent(EventEnum.OnEnemyDie, this); EventManager.EmitEvent(EventEnum.OnEnemyDie, this);

View File

@ -14,11 +14,6 @@ public partial class Player : Role
/// </summary> /// </summary>
public event Action<RoomInfo> OnFirstEnterRoomEvent; public event Action<RoomInfo> OnFirstEnterRoomEvent;
/// <summary>
/// 获取当前操作的角色
/// </summary>
public static Player Current { get; private set; }
/// <summary> /// <summary>
/// 玩家身上的状态机控制器 /// 玩家身上的状态机控制器
/// </summary> /// </summary>
@ -36,17 +31,6 @@ public partial class Player : Role
private BrushImageData _brushData2; private BrushImageData _brushData2;
/// <summary>
/// 设置当前操作的玩家对象
/// </summary>
public static void SetCurrentPlayer(Player player)
{
Current = player;
//设置相机和鼠标跟随玩家
GameCamera.Main.SetFollowTarget(player);
GameApplication.Instance.Cursor.SetMountRole(player);
}
public override void OnInit() public override void OnInit()
{ {
base.OnInit(); base.OnInit();

View File

@ -8,7 +8,7 @@ public partial class Gun : Weapon
{ {
protected override void OnFire() protected override void OnFire()
{ {
if (Master == Player.Current) if (Master == World.Player)
{ {
//创建抖动 //创建抖动
GameCamera.Main.DirectionalShake(Vector2.Right.Rotated(GlobalRotation) * Attribute.CameraShake); GameCamera.Main.DirectionalShake(Vector2.Right.Rotated(GlobalRotation) * Attribute.CameraShake);

View File

@ -94,7 +94,7 @@ public partial class Knife : Weapon
} }
if (Master == Player.Current) if (Master == World.Player)
{ {
var r = Master.MountPoint.RotationDegrees; var r = Master.MountPoint.RotationDegrees;
//创建屏幕抖动 //创建屏幕抖动

View File

@ -18,16 +18,6 @@ public class Eff_GetGold : EffectFragment
public override void OnUse() public override void OnUse()
{ {
var goldList = Utils.GetGoldList(Mathf.FloorToInt(_value)); Gold.CreateGold(Role.Position, _value);
foreach (var id in goldList)
{
var o = ObjectManager.GetActivityObject<Gold>(id);
o.Position = Role.Position;
o.Throw(0,
Utils.Random.RandomRangeInt(50, 110),
new Vector2(Utils.Random.RandomRangeInt(-20, 20), Utils.Random.RandomRangeInt(-20, 20)),
0
);
}
} }
} }

View File

@ -25,17 +25,7 @@ public class Eff_PiggyBank : EffectFragment
public override void OnUse() public override void OnUse()
{ {
var goldList = Utils.GetGoldList(Mathf.FloorToInt(_currValue * _value)); Gold.CreateGold(Role.Position, Mathf.FloorToInt(_currValue * _value));
foreach (var id in goldList)
{
var o = ObjectManager.GetActivityObject<Gold>(id);
o.Position = Role.Position;
o.Throw(0,
Utils.Random.RandomRangeInt(50, 110),
new Vector2(Utils.Random.RandomRangeInt(-20, 20), Utils.Random.RandomRangeInt(-20, 20)),
0
);
}
_currValue = 0; _currValue = 0;
} }

View File

@ -7,6 +7,11 @@ using Godot;
/// </summary> /// </summary>
public class BulletData : IClone<BulletData> public class BulletData : IClone<BulletData>
{ {
/// <summary>
/// 数据所在世界对象
/// </summary>
public World World;
/// <summary> /// <summary>
/// 发射该子弹的武器, 可能为null /// 发射该子弹的武器, 可能为null
/// </summary> /// </summary>
@ -77,9 +82,14 @@ public class BulletData : IClone<BulletData>
/// </summary> /// </summary>
public float Rotation; public float Rotation;
public BulletData(World world)
{
World = world;
}
public BulletData Clone() public BulletData Clone()
{ {
return new BulletData return new BulletData(World)
{ {
Weapon = Weapon, Weapon = Weapon,
BulletBase = BulletBase, BulletBase = BulletBase,

View File

@ -172,7 +172,7 @@ public static class FireManager
private static BulletData CreateSolidBulletData(Weapon weapon, float fireRotation, ExcelConfig.BulletBase bullet) private static BulletData CreateSolidBulletData(Weapon weapon, float fireRotation, ExcelConfig.BulletBase bullet)
{ {
var data = new BulletData() var data = new BulletData(weapon.World)
{ {
Weapon = weapon, Weapon = weapon,
BulletBase = bullet, BulletBase = bullet,
@ -216,7 +216,7 @@ public static class FireManager
private static BulletData CreateSolidBulletData(Role role, float fireRotation, ExcelConfig.BulletBase bullet) private static BulletData CreateSolidBulletData(Role role, float fireRotation, ExcelConfig.BulletBase bullet)
{ {
var data = new BulletData() var data = new BulletData(role.World)
{ {
Weapon = null, Weapon = null,
BulletBase = bullet, BulletBase = bullet,
@ -261,7 +261,7 @@ public static class FireManager
private static BulletData CreateLaserData(Weapon weapon, float fireRotation, ExcelConfig.BulletBase bullet) private static BulletData CreateLaserData(Weapon weapon, float fireRotation, ExcelConfig.BulletBase bullet)
{ {
var data = new BulletData() var data = new BulletData(weapon.World)
{ {
Weapon = weapon, Weapon = weapon,
BulletBase = bullet, BulletBase = bullet,

View File

@ -16,12 +16,12 @@ public partial class DungeonManager : Node2D
/// <summary> /// <summary>
/// 当前玩家所在的房间 /// 当前玩家所在的房间
/// </summary> /// </summary>
public RoomInfo ActiveRoomInfo => Player.Current?.AffiliationArea?.RoomInfo; public RoomInfo ActiveRoomInfo => CurrWorld.Player?.AffiliationArea?.RoomInfo;
/// <summary> /// <summary>
/// 当前玩家所在的区域 /// 当前玩家所在的区域
/// </summary> /// </summary>
public AffiliationArea ActiveAffiliationArea => Player.Current?.AffiliationArea; public AffiliationArea ActiveAffiliationArea => CurrWorld.Player?.AffiliationArea;
/// <summary> /// <summary>
/// 是否在地牢里 /// 是否在地牢里
@ -277,6 +277,7 @@ public partial class DungeonManager : Node2D
//创建房间数据 //创建房间数据
var roomInfo = new RoomInfo(0, DungeonRoomType.None, null); var roomInfo = new RoomInfo(0, DungeonRoomType.None, null);
roomInfo.World = CurrWorld;
roomInfo.Size = hall.BgSprite.Texture.GetSize().AsVector2I() / GameConfig.TileCellSize + new Vector2I(10, 10); roomInfo.Size = hall.BgSprite.Texture.GetSize().AsVector2I() / GameConfig.TileCellSize + new Vector2I(10, 10);
roomInfo.Position = hall.BgSprite.Position.AsVector2I() - new Vector2I(5, 5) * GameConfig.TileCellSize; roomInfo.Position = hall.BgSprite.Position.AsVector2I() - new Vector2I(5, 5) * GameConfig.TileCellSize;
hall.RoomInfo = roomInfo; hall.RoomInfo = roomInfo;
@ -316,7 +317,7 @@ public partial class DungeonManager : Node2D
yield return 0; yield return 0;
//创建玩家 //创建玩家
var player = Player.Current; var player = CurrWorld.Player;
if (player == null) if (player == null)
{ {
player = ActivityObject.Create<Player>(ActivityObject.Ids.Id_role0001); player = ActivityObject.Create<Player>(ActivityObject.Ids.Id_role0001);
@ -325,7 +326,7 @@ public partial class DungeonManager : Node2D
player.World = CurrWorld; player.World = CurrWorld;
player.Position = hall.BirthMark.Position; player.Position = hall.BirthMark.Position;
player.PutDown(RoomLayerEnum.YSortLayer); player.PutDown(RoomLayerEnum.YSortLayer);
Player.SetCurrentPlayer(player); CurrWorld.SetCurrentPlayer(player);
affiliation.InsertItem(player); affiliation.InsertItem(player);
player.WeaponPack.PickupItem(ActivityObject.Create<Weapon>(ActivityObject.Ids.Id_weapon0001)); player.WeaponPack.PickupItem(ActivityObject.Create<Weapon>(ActivityObject.Ids.Id_weapon0001));
yield return 0; yield return 0;
@ -359,11 +360,11 @@ public partial class DungeonManager : Node2D
yield return 0; yield return 0;
if (!keepPlayer) if (!keepPlayer)
{ {
Player.SetCurrentPlayer(null); CurrWorld.SetCurrentPlayer(null);
} }
else else
{ {
var player = Player.Current; var player = CurrWorld.Player;
player.AffiliationArea?.RemoveItem(player); player.AffiliationArea?.RemoveItem(player);
player.GetParent().RemoveChild(player); player.GetParent().RemoveChild(player);
player.World = null; player.World = null;
@ -452,6 +453,11 @@ public partial class DungeonManager : Node2D
//创建世界场景 //创建世界场景
var dungeon = (Dungeon)CreateNewWorld(_dungeonGenerator.Random, ResourcePath.scene_Dungeon_tscn); var dungeon = (Dungeon)CreateNewWorld(_dungeonGenerator.Random, ResourcePath.scene_Dungeon_tscn);
dungeon.InitLayer(); dungeon.InitLayer();
//初始化房间 World 字段
foreach (var roomInfo in _dungeonGenerator.RoomInfos)
{
roomInfo.World = dungeon;
}
yield return 0; yield return 0;
var group = GameApplication.Instance.RoomConfig[CurrConfig.GroupName]; var group = GameApplication.Instance.RoomConfig[CurrConfig.GroupName];
var tileSetSplit = GameApplication.Instance.TileSetConfig[group.TileSet]; var tileSetSplit = GameApplication.Instance.TileSetConfig[group.TileSet];
@ -483,7 +489,7 @@ public partial class DungeonManager : Node2D
var playerBirthMark = StartRoomInfo.RoomPreinstall.GetSpecialMark(SpecialMarkType.BirthPoint); var playerBirthMark = StartRoomInfo.RoomPreinstall.GetSpecialMark(SpecialMarkType.BirthPoint);
//创建玩家 //创建玩家
var player = Player.Current; var player = CurrWorld.Player;
if (player == null) if (player == null)
{ {
player = ActivityObject.Create<Player>(ActivityObject.Ids.Id_role0001); player = ActivityObject.Create<Player>(ActivityObject.Ids.Id_role0001);
@ -496,7 +502,7 @@ public partial class DungeonManager : Node2D
player.World = CurrWorld; player.World = CurrWorld;
player.PutDown(RoomLayerEnum.YSortLayer); player.PutDown(RoomLayerEnum.YSortLayer);
Player.SetCurrentPlayer(player); CurrWorld.SetCurrentPlayer(player);
StartRoomInfo.AffiliationArea.InsertItem(player); StartRoomInfo.AffiliationArea.InsertItem(player);
yield return 0; yield return 0;
player.Collision.Disabled = false; player.Collision.Disabled = false;
@ -530,11 +536,11 @@ public partial class DungeonManager : Node2D
yield return 0; yield return 0;
if (!keepPlayer) if (!keepPlayer)
{ {
Player.SetCurrentPlayer(null); CurrWorld.SetCurrentPlayer(null);
} }
else else
{ {
var player = Player.Current; var player = CurrWorld.Player;
player.AffiliationArea?.RemoveItem(player); player.AffiliationArea?.RemoveItem(player);
player.GetParent().RemoveChild(player); player.GetParent().RemoveChild(player);
player.World = null; player.World = null;
@ -851,7 +857,7 @@ public partial class DungeonManager : Node2D
//如果关门了, 那么房间外的敌人就会丢失目标 //如果关门了, 那么房间外的敌人就会丢失目标
if (room.IsSeclusion) if (room.IsSeclusion)
{ {
var playerAffiliationArea = Player.Current.AffiliationArea; var playerAffiliationArea = CurrWorld.Player.AffiliationArea;
foreach (var enemy in CurrWorld.Enemy_InstanceList) foreach (var enemy in CurrWorld.Enemy_InstanceList)
{ {
//不与玩家处于同一个房间 //不与玩家处于同一个房间

View File

@ -141,10 +141,11 @@ public partial class RoomMapPanel : RoomMap
_needRefresh.Clear(); _needRefresh.Clear();
} }
if (Player.Current != null) var player = World.Current.Player;
if (player != null)
{ {
//更新地图中心点位置 //更新地图中心点位置
var playPosition = Player.Current.GetCenterPosition(); var playPosition = player.GetCenterPosition();
if (!_isMagnifyMap) if (!_isMagnifyMap)
{ {
S_Root.Instance.Position = CalcRootPosition(playPosition); S_Root.Instance.Position = CalcRootPosition(playPosition);
@ -155,7 +156,7 @@ public partial class RoomMapPanel : RoomMap
S_Mark.Instance.Position = S_DrawContainer.Instance.Size / 2 + _mapOffset; S_Mark.Instance.Position = S_DrawContainer.Instance.Size / 2 + _mapOffset;
} }
var area = Player.Current.AffiliationArea; var area = player.AffiliationArea;
//传送 //传送
if (_pressMapFlag && _mouseHoverRoom != null && if (_pressMapFlag && _mouseHoverRoom != null &&
area != null && !area.RoomInfo.IsSeclusion && area != null && !area.RoomInfo.IsSeclusion &&
@ -269,7 +270,7 @@ public partial class RoomMapPanel : RoomMap
var shaderMaterial = (ShaderMaterial)roomInfo.PreviewSprite.Material; var shaderMaterial = (ShaderMaterial)roomInfo.PreviewSprite.Material;
_originOutlineColor = shaderMaterial.GetShaderParameter("outline_color").AsColor(); _originOutlineColor = shaderMaterial.GetShaderParameter("outline_color").AsColor();
//玩家所在的房间门是否打开 //玩家所在的房间门是否打开
var area = Player.Current.AffiliationArea; var area = World.Current.Player.AffiliationArea;
if (area != null) if (area != null)
{ {
var isOpen = !area.RoomInfo.IsSeclusion; var isOpen = !area.RoomInfo.IsSeclusion;
@ -411,7 +412,7 @@ public partial class RoomMapPanel : RoomMap
_transmissionTween.TweenProperty(roomUI.S_Mask.Instance, "color", new Color(0, 0, 0), 0.3f); _transmissionTween.TweenProperty(roomUI.S_Mask.Instance, "color", new Color(0, 0, 0), 0.3f);
_transmissionTween.TweenCallback(Callable.From(() => _transmissionTween.TweenCallback(Callable.From(() =>
{ {
Player.Current.Position = position; World.Current.Player.Position = position;
})); }));
_transmissionTween.TweenInterval(0.2f); _transmissionTween.TweenInterval(0.2f);
_transmissionTween.TweenProperty(roomUI.S_Mask.Instance, "color", new Color(0, 0, 0, 0), 0.3f); _transmissionTween.TweenProperty(roomUI.S_Mask.Instance, "color", new Color(0, 0, 0, 0), 0.3f);

View File

@ -38,7 +38,7 @@ public class ActivePropBarHandler
public void Process(float delta) public void Process(float delta)
{ {
var prop = Player.Current?.ActivePropsPack.ActiveItem; var prop = World.Current.Player?.ActivePropsPack.ActiveItem;
if (prop != null) if (prop != null)
{ {
SetActivePropCount(prop.Count); SetActivePropCount(prop.Count);

View File

@ -63,7 +63,7 @@ public class InteractiveTipBarHandler
else else
{ {
var result = (CheckInteractiveResult)o; var result = (CheckInteractiveResult)o;
var interactiveItem = Player.Current.InteractiveItem; var interactiveItem = World.Current.Player.InteractiveItem;
//if (interactiveItem is Weapon) //if (interactiveItem is Weapon)
var icon = result.GetIcon(); var icon = result.GetIcon();
if (icon != null) if (icon != null)

View File

@ -67,7 +67,7 @@ public class LifeBarHandler
private void HandlerRefreshLife() private void HandlerRefreshLife()
{ {
var player = Player.Current; var player = World.Current.Player;
if (player.MaxHp % 2 != 0) if (player.MaxHp % 2 != 0)
{ {
Debug.LogError("玩家血量不是偶数!"); Debug.LogError("玩家血量不是偶数!");
@ -108,7 +108,7 @@ public class LifeBarHandler
private void HandlerRefreshGold() private void HandlerRefreshGold()
{ {
_bar.L_Gold.L_GoldText.Instance.Text = Player.Current.RoleState.Gold.ToString(); _bar.L_Gold.L_GoldText.Instance.Text = World.Current.Player.RoleState.Gold.ToString();
} }
} }

View File

@ -55,8 +55,8 @@ public class ReloadBarHandler
/// </summary> /// </summary>
public void OnCameraPositionUpdate(float delta) public void OnCameraPositionUpdate(float delta)
{ {
var player = Player.Current; var player = World.Current.Player;
var activeItem = player.WeaponPack.ActiveItem; var activeItem = player?.WeaponPack.ActiveItem;
if (activeItem != null && activeItem.Reloading && activeItem.Attribute.ShowReloadBar) if (activeItem != null && activeItem.Reloading && activeItem.Attribute.ShowReloadBar)
{ {
ShowBar(player.GlobalPosition, activeItem.ReloadProgress); ShowBar(player.GlobalPosition, activeItem.ReloadProgress);

View File

@ -25,7 +25,7 @@ public class WeaponBarHandler
public void Process(float delta) public void Process(float delta)
{ {
var weapon = Player.Current?.WeaponPack.ActiveItem; var weapon = World.Current.Player?.WeaponPack.ActiveItem;
if (weapon != null) if (weapon != null)
{ {
SetWeaponTexture(weapon.GetCurrentTexture()); SetWeaponTexture(weapon.GetCurrentTexture());

View File

@ -159,7 +159,7 @@ public partial class WeaponRoulettePanel : WeaponRoulette
//如果选中了物体 //如果选中了物体
if (ActiveWeapon != null) if (ActiveWeapon != null)
{ {
Player.Current.ExchangeWeaponByIndex(ActiveWeapon.PackageIndex); World.Current.Player.ExchangeWeaponByIndex(ActiveWeapon.PackageIndex);
} }
} }
@ -182,7 +182,7 @@ public partial class WeaponRoulettePanel : WeaponRoulette
//刷新页码 //刷新页码
private void RefreshSlotPage() private void RefreshSlotPage()
{ {
var current = Player.Current; var current = World.Current.Player;
if (current == null) if (current == null)
{ {
return; return;
@ -211,7 +211,7 @@ public partial class WeaponRoulettePanel : WeaponRoulette
//更新显示的武器 //更新显示的武器
private void RefreshWeapon() private void RefreshWeapon()
{ {
var current = Player.Current; var current = World.Current.Player;
if (current == null) //没有玩家对象,这是异常情况 if (current == null) //没有玩家对象,这是异常情况
{ {
foreach (var slotNode in _slotNodes) foreach (var slotNode in _slotNodes)