From b9c1dbb5b0388cdc990be129d73fd8a1f557b7b4 Mon Sep 17 00:00:00 2001 From: lightyears Date: Tue, 21 Feb 2023 13:56:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BB=BA=E6=A8=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entities/GameSave.cs | 9 +++ Helpers/TimeHelper.cs | 7 +++ ModelData/BattleGoals.cs | 34 +++++++++++ {Entities => ModelData}/Characters.cs | 2 +- Models/Action.cs | 26 +++++++++ Models/Battle.cs | 24 ++++++++ Models/BattleCharacter.cs | 54 +++-------------- Models/BattleParty.cs | 15 +++++ Models/Character.cs | 16 ++--- Models/Effect.cs | 11 ++++ Models/Goal.cs | 20 +++++++ Models/Skill.cs | 11 ++++ Nodes/BattleCharacterNode.cs | 58 +++++++++++++++++++ .../BattleCharacterNode.tscn | 4 +- Scenes/MainScene.tscn | 2 +- Tests/BattleSceneTest.tscn | 6 +- Tests/GameSaves/GameSaves.cs | 16 +++++ 17 files changed, 254 insertions(+), 61 deletions(-) create mode 100644 Entities/GameSave.cs create mode 100644 ModelData/BattleGoals.cs rename {Entities => ModelData}/Characters.cs (50%) create mode 100644 Models/Action.cs create mode 100644 Models/Battle.cs create mode 100644 Models/BattleParty.cs create mode 100644 Models/Effect.cs create mode 100644 Models/Goal.cs create mode 100644 Models/Skill.cs create mode 100644 Nodes/BattleCharacterNode.cs rename Models/BattleCharacter.tscn => Nodes/BattleCharacterNode.tscn (87%) create mode 100644 Tests/GameSaves/GameSaves.cs diff --git a/Entities/GameSave.cs b/Entities/GameSave.cs new file mode 100644 index 0000000..b5bb60c --- /dev/null +++ b/Entities/GameSave.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace CMSGame +{ + public class GameSave + { + public List Characters; + } +} diff --git a/Helpers/TimeHelper.cs b/Helpers/TimeHelper.cs index adc90aa..d719f7e 100644 --- a/Helpers/TimeHelper.cs +++ b/Helpers/TimeHelper.cs @@ -2,6 +2,13 @@ namespace CMSGame { static class TimeHelper { + /// 获取自引擎启动后经过的时间。 + public static double GetTicks() + { + return Time.GetTicksMsec() / 1000.0; + } + + /// 将时间(单位为秒)格式化为字符串“时:分:秒.毫秒”。 public static string FormatTime(double time) { return TimeSpan.FromSeconds(time).ToString("c"); diff --git a/ModelData/BattleGoals.cs b/ModelData/BattleGoals.cs new file mode 100644 index 0000000..c95fcea --- /dev/null +++ b/ModelData/BattleGoals.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; + +namespace CMSGame +{ + public static class BattleGoals + { + public static readonly BattleGoal Escape = new() + { + Name = "保命要紧", + BasePriority = -50 + }; + + public static readonly BattleGoal SelfRegulatory = new() + { + Name = "自律行动", + BasePriority = 0 + }; + + public static readonly BattleGoal FollowOrder = new() + { + Name = "服从指令", + BasePriority = 50 + }; + + public static List AllGoals() + { + return new() { + Escape, + SelfRegulatory, + FollowOrder + }; + } + } +} diff --git a/Entities/Characters.cs b/ModelData/Characters.cs similarity index 50% rename from Entities/Characters.cs rename to ModelData/Characters.cs index 0f4348c..ed36632 100644 --- a/Entities/Characters.cs +++ b/ModelData/Characters.cs @@ -1,6 +1,6 @@ namespace CMSGame { - public class Characters + public static class Characters { } diff --git a/Models/Action.cs b/Models/Action.cs new file mode 100644 index 0000000..2bd95ca --- /dev/null +++ b/Models/Action.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; + +namespace CMSGame +{ + public abstract class Action + { + public string Name; + + public ActionTargetTypes TargetType; + + public List Targets; + + public IActionTarget Target => Targets.Count > 0 ? Targets[0] : null; + } + + public enum ActionTargetTypes + { + None, + Single, + Multiple + } + + public interface IActionTarget + { + } +} diff --git a/Models/Battle.cs b/Models/Battle.cs new file mode 100644 index 0000000..12bcaca --- /dev/null +++ b/Models/Battle.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; + +namespace CMSGame +{ + public class Battle + { + public List Parties; + + public BattleParty Attacker; + + public BattleParty Defender; + + public BattleParty PlayerParty; + + public Battle() + { + // load characters of the attacker and defender; + } + + public void Begin() + { + } + } +} diff --git a/Models/BattleCharacter.cs b/Models/BattleCharacter.cs index 7137b58..814137c 100644 --- a/Models/BattleCharacter.cs +++ b/Models/BattleCharacter.cs @@ -1,58 +1,22 @@ +using System.Collections.Generic; + namespace CMSGame { - public partial class BattleCharacter : CharacterBody3D + public class BattleCharacter { - [Signal] - public delegate void MousePressedEventHandler(Vector3 position); - - [Export] - public Texture SpriteTexture; - - public BattleFieldPosition BattleFieldPosition; + public List Goals; public Character Character; - public Sprite3D Sprite3D; - - public Label3D StatusLabel; - - public int ActionPoint; - - public double ActionPointGathering; - - public override void _Ready() - { - this.GetUniqueNode(ref Sprite3D, nameof(Sprite3D)); - this.GetUniqueNode(ref StatusLabel, nameof(StatusLabel)); - } - - public override void _Process(double delta) - { - UpdateStatus(delta); - UpdateUI(); - } - - public void UpdateStatus(double delta) - { - ActionPointGathering += delta; - ActionPoint += (int)ActionPointGathering / 10; - ActionPointGathering %= 10; - } - - public void UpdateUI() + public BattleCharacter(Character character) { - StatusLabel.Text = $"HP {120}\nAP {ActionPoint}"; + Character = character; + EstablishGoals(); } - public override void _InputEvent(Camera3D camera, InputEvent @event, Vector3 position, Vector3 normal, int shapeIdx) + private void EstablishGoals() { - if (@event is InputEventMouseButton mouseButtonEvent) - { - if (mouseButtonEvent.Pressed) - { - EmitSignal(SignalName.MousePressed, position); - } - } + Goals = BattleGoals.AllGoals(); } } } diff --git a/Models/BattleParty.cs b/Models/BattleParty.cs new file mode 100644 index 0000000..99df48d --- /dev/null +++ b/Models/BattleParty.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; + +namespace CMSGame +{ + public class BattleParty + { + public bool IsAttacker; + + public bool IsDefender; + + public bool IsPlayerParty; + + public List Characters; + } +} diff --git a/Models/Character.cs b/Models/Character.cs index 50df2dc..bb7df99 100644 --- a/Models/Character.cs +++ b/Models/Character.cs @@ -1,15 +1,15 @@ namespace CMSGame { - public partial class Character : Node + public class Character { - public int HealthPoint; + public string FamilyName; + + public string GivenName; - public override void _Ready() - { - } + public string Name => FamilyName + GivenName; + + public int HealthPoint; - public override void _Process(double delta) - { - } + public int MaxHealthPoint; } } diff --git a/Models/Effect.cs b/Models/Effect.cs new file mode 100644 index 0000000..c2ff08d --- /dev/null +++ b/Models/Effect.cs @@ -0,0 +1,11 @@ +namespace CMSGame +{ + public abstract class Effect + { + public string Name; + + public string Description; + + public abstract void Perform(Character character); + } +} diff --git a/Models/Goal.cs b/Models/Goal.cs new file mode 100644 index 0000000..a67675b --- /dev/null +++ b/Models/Goal.cs @@ -0,0 +1,20 @@ +namespace CMSGame +{ + public class Goal + { + public string Name; + + public bool IsValid; + + public int BasePriority; + } + + public class BattleGoal : Goal + { + } + + public class GoalModifier + { + + } +} diff --git a/Models/Skill.cs b/Models/Skill.cs new file mode 100644 index 0000000..46fb430 --- /dev/null +++ b/Models/Skill.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace CMSGame +{ + public abstract class Skill + { + public string Name; + + public List Effects; + } +} diff --git a/Nodes/BattleCharacterNode.cs b/Nodes/BattleCharacterNode.cs new file mode 100644 index 0000000..a7ec542 --- /dev/null +++ b/Nodes/BattleCharacterNode.cs @@ -0,0 +1,58 @@ +namespace CMSGame +{ + public partial class BattleCharacterNode : CharacterBody3D + { + [Signal] + public delegate void MousePressedEventHandler(Vector3 position); + + [Export] + public Texture SpriteTexture; + + public BattleFieldPosition BattleFieldPosition; + + public Character Character; + + public Sprite3D Sprite3D; + + public Label3D StatusLabel; + + public int ActionPoint; + + public double ActionPointGathering; + + public override void _Ready() + { + this.GetUniqueNode(ref Sprite3D, nameof(Sprite3D)); + this.GetUniqueNode(ref StatusLabel, nameof(StatusLabel)); + } + + public override void _Process(double delta) + { + UpdateStatus(delta); + UpdateUI(); + } + + public void UpdateStatus(double delta) + { + ActionPointGathering += delta; + ActionPoint += (int)ActionPointGathering / 10; + ActionPointGathering %= 10; + } + + public void UpdateUI() + { + StatusLabel.Text = $"HP {120}\nAP {ActionPoint}"; + } + + public override void _InputEvent(Camera3D camera, InputEvent @event, Vector3 position, Vector3 normal, int shapeIdx) + { + if (@event is InputEventMouseButton mouseButtonEvent) + { + if (mouseButtonEvent.Pressed) + { + EmitSignal(SignalName.MousePressed, position); + } + } + } + } +} diff --git a/Models/BattleCharacter.tscn b/Nodes/BattleCharacterNode.tscn similarity index 87% rename from Models/BattleCharacter.tscn rename to Nodes/BattleCharacterNode.tscn index 68ee959..46c530f 100644 --- a/Models/BattleCharacter.tscn +++ b/Nodes/BattleCharacterNode.tscn @@ -1,7 +1,7 @@ -[gd_scene load_steps=4 format=3 uid="uid://igk5375j1keq"] +[gd_scene load_steps=4 format=3 uid="uid://dje5jk73mjb6a"] [ext_resource type="Texture2D" uid="uid://cnilysgmgw8n4" path="res://Temp/Characters/1_19.png" id="1_o3tjt"] -[ext_resource type="Script" path="res://Models/BattleCharacter.cs" id="2_vbdi8"] +[ext_resource type="Script" path="res://Nodes/BattleCharacterNode.cs" id="2_vbdi8"] [sub_resource type="BoxShape3D" id="BoxShape3D_r28jb"] size = Vector3(0.84, 1.46, 0.17) diff --git a/Scenes/MainScene.tscn b/Scenes/MainScene.tscn index 7fc6b9a..0332f0e 100644 --- a/Scenes/MainScene.tscn +++ b/Scenes/MainScene.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=3 format=3 uid="uid://c3ovsoq6o7y3t"] [ext_resource type="Script" path="res://Scenes/MainScene.cs" id="1_kso8c"] -[ext_resource type="PackedScene" uid="uid://cslqihnfw0me2" path="res://Components/SettingsMenuPopup.tscn" id="2_d0nn6"] +[ext_resource type="PackedScene" path="res://Components/SettingsMenuPopup.tscn" id="2_d0nn6"] [node name="MainScene" type="Control"] layout_mode = 3 diff --git a/Tests/BattleSceneTest.tscn b/Tests/BattleSceneTest.tscn index 813b948..61e3877 100644 --- a/Tests/BattleSceneTest.tscn +++ b/Tests/BattleSceneTest.tscn @@ -1,8 +1,8 @@ -[gd_scene load_steps=10 format=3 uid="uid://6phl40durwor"] +[gd_scene load_steps=10 format=3 uid="uid://dgi0d8jybvlk0"] [ext_resource type="PackedScene" uid="uid://cp6aa655vykt1" path="res://Scenes/BattleScene.tscn" id="1_fdqdi"] [ext_resource type="Script" path="res://Tests/BattleSceneTest.cs" id="1_tuul4"] -[ext_resource type="PackedScene" uid="uid://igk5375j1keq" path="res://Models/BattleCharacter.tscn" id="3_nau0d"] +[ext_resource type="PackedScene" uid="uid://igk5375j1keq" path="res://Nodes/BattleCharacterNode.tscn" id="3_nau0d"] [ext_resource type="Texture2D" uid="uid://w6qckexp2he1" path="res://Temp/Characters/2_73.png" id="4_jnah0"] [ext_resource type="Texture2D" uid="uid://du6o3upum6lkr" path="res://Temp/Characters/3_0.png" id="5_4vahd"] [ext_resource type="Texture2D" uid="uid://cl11bl8lcnwha" path="res://Temp/Characters/4_2.png" id="6_6563q"] @@ -54,8 +54,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.44713, 0.524168, -12.3572) [node name="Sprite3D" parent="BattleScene/Characters/BattleCharacter7" index="2"] texture = ExtResource("9_wor4w") -[connection signal="MousePressed" from="BattleScene/Characters/BattleCharacter" to="." method="On_BattleCharacter_MousePressed"] - [editable path="BattleScene"] [editable path="BattleScene/Characters/BattleCharacter2"] [editable path="BattleScene/Characters/BattleCharacter3"] diff --git a/Tests/GameSaves/GameSaves.cs b/Tests/GameSaves/GameSaves.cs new file mode 100644 index 0000000..22b2aee --- /dev/null +++ b/Tests/GameSaves/GameSaves.cs @@ -0,0 +1,16 @@ +namespace CMSGame +{ + public static class GameSaves + { + public static readonly GameSave Demo1 = new() + { + Characters = new() { + new Character { + FamilyName = "腾", + GivenName = "牧心", + HealthPoint = 80 + } + } + }; + }; +}