diff --git a/logic/.gitignore b/logic/.gitignore index ec116cb..762b4b5 100644 --- a/logic/.gitignore +++ b/logic/.gitignore @@ -399,3 +399,6 @@ FodyWeavers.xsd #THUAI playback file *.thuaipb + +Client/ +CSharpInterface/ diff --git a/logic/GameClass/GameClass.csproj b/logic/GameClass/GameClass.csproj new file mode 100644 index 0000000..de8abd4 --- /dev/null +++ b/logic/GameClass/GameClass.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + + + + + + + + diff --git a/logic/GameClass/GameObj/Character.BuffManager.cs b/logic/GameClass/GameObj/Character.BuffManager.cs new file mode 100644 index 0000000..b580e9e --- /dev/null +++ b/logic/GameClass/GameObj/Character.BuffManager.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Threading; +using Preparation.Utility; +using Preparation.GameData; + +namespace GameClass.GameObj +{ + public partial class Character + { + private readonly BuffManeger buffManeger; + /// + /// 角色携带的buff管理器 + /// + private class BuffManeger + { + [StructLayout(LayoutKind.Explicit, Size = 8)] + private struct BuffValue // buff参数联合体类型,可能是int或double + { + [FieldOffset(0)] + public int iValue; + [FieldOffset(0)] + public double lfValue; + + public BuffValue(int intValue) + { + this.lfValue = 0.0; + this.iValue = intValue; + } + public BuffValue(double longFloatValue) + { + this.iValue = 0; + this.lfValue = longFloatValue; + } + } + + /// + /// buff列表 + /// + private readonly LinkedList[] buffList; + private readonly object[] buffListLock; + + private void AddBuff(BuffValue bf, int buffTime, BuffType buffType, Action ReCalculateFunc) + { + new Thread + ( + () => + { + LinkedListNode buffNode; + lock (buffListLock[(int)buffType]) + { + buffNode = buffList[(int)buffType].AddLast(bf); + } + ReCalculateFunc(); + Thread.Sleep(buffTime); + try + { + lock (buffListLock[(int)buffType]) + { + buffList[(int)buffType].Remove(buffNode); + } + } + catch + { + } + ReCalculateFunc(); + } + ) + { IsBackground = true }.Start(); + } + + private int ReCalculateFloatBuff(BuffType buffType, int orgVal, int maxVal, int minVal) + { + double times = 1.0; + lock (buffListLock[(int)buffType]) + { + foreach (var add in buffList[(int)buffType]) + { + times *= add.lfValue; + } + } + return Math.Max(Math.Min((int)Math.Round(orgVal * times), maxVal), minVal); + } + + public void AddMoveSpeed(double add, int buffTime, Action SetNewMoveSpeed, int orgMoveSpeed) => AddBuff(new BuffValue(add), buffTime, BuffType.AddSpeed, () => SetNewMoveSpeed(ReCalculateFloatBuff(BuffType.AddSpeed, orgMoveSpeed, GameData.MaxSpeed, GameData.MinSpeed))); + public bool HasFasterSpeed + { + get { + lock (buffListLock[(int)BuffType.AddSpeed]) + { + return buffList[(int)BuffType.AddSpeed].Count != 0; + } + } + } + + public void AddShield(int shieldTime) => AddBuff(new BuffValue(), shieldTime, BuffType.Shield, () => + {}); + public bool HasShield + { + get { + lock (buffListLock[(int)BuffType.Shield]) + { + return buffList[(int)BuffType.Shield].Count != 0; + } + } + } + + public void AddLIFE(int totelTime) => AddBuff(new BuffValue(), totelTime, BuffType.AddLIFE, () => + {}); + public bool HasLIFE + { + get { + lock (buffListLock[(int)BuffType.AddLIFE]) + { + return buffList[(int)BuffType.AddLIFE].Count != 0; + } + } + } + public bool TryActivatingLIFE() + { + if (HasLIFE) + { + lock (buffListLock[(int)BuffType.AddLIFE]) + { + buffList[(int)BuffType.AddLIFE].Clear(); + } + return true; + } + return false; + } + + public void AddSpear(int spearTime) => AddBuff(new BuffValue(), spearTime, BuffType.Spear, () => + {}); + public bool HasSpear + { + get { + lock (buffListLock[(int)BuffType.Spear]) + { + return buffList[(int)BuffType.Spear].Count != 0; + } + } + } + /// + /// 清除所有buff + /// + public void ClearAll() + { + for (int i = 0; i < buffList.Length; ++i) + { + lock (buffListLock[i]) + { + buffList[i].Clear(); + } + } + } + + public BuffManeger() + { + var buffTypeArray = Enum.GetValues(typeof(BuffType)); + buffList = new LinkedList[buffTypeArray.Length]; + buffListLock = new object[buffList.Length]; + int i = 0; + foreach (BuffType type in buffTypeArray) + { + buffList[i] = new LinkedList(); + buffListLock[i++] = new object(); + } + } + } +} +} diff --git a/logic/GameClass/GameObj/Character.SkillManager.cs b/logic/GameClass/GameObj/Character.SkillManager.cs new file mode 100644 index 0000000..2bd8c5f --- /dev/null +++ b/logic/GameClass/GameObj/Character.SkillManager.cs @@ -0,0 +1,51 @@ +using Preparation.Utility; +using System.Collections.Generic; +using System; + +namespace GameClass.GameObj +{ + public partial class Character + { + private delegate bool CharacterActiveSkill(Character player); // 返回值:是否成功释放了技能 + private delegate void CharacterPassiveSkill(Character player); + private readonly CharacterActiveSkill commonSkill; + private readonly ActiveSkillType commonSkillType; + public ActiveSkillType CommonSkillType => commonSkillType; + + private readonly CharacterType passiveSkillType; + public CharacterType PassiveSkillType => passiveSkillType; + public bool UseCommonSkill() + { + return commonSkill(this); + } + private int timeUntilCommonSkillAvailable = 0; // 还剩多少时间可以使用普通技能 + public int TimeUntilCommonSkillAvailable + { + get => timeUntilCommonSkillAvailable; + set { + lock (gameObjLock) + timeUntilCommonSkillAvailable = value < 0 ? 0 : value; + } + } + + readonly CharacterPassiveSkill passiveSkill; + public void UsePassiveSkill() + { + passiveSkill(this); + return; + } + public Character(XY initPos, int initRadius, PlaceType initPlace, CharacterType passiveSkillType, ActiveSkillType commonSkillType) : + base(initPos, initRadius, initPlace, GameObjType.Character) + { + this.CanMove = true; + this.score = 0; + this.propInventory = null; + this.buffManeger = new BuffManeger(); + + // UsePassiveSkill(); //创建player时开始被动技能,这一过程也可以放到gamestart时进行 + // 这可以放在AddPlayer中做 + + Debugger.Output(this, "constructed!"); + } + } +} diff --git a/logic/GameClass/GameObj/Map/Map.cs b/logic/GameClass/GameObj/Map/Map.cs new file mode 100644 index 0000000..c382099 --- /dev/null +++ b/logic/GameClass/GameObj/Map/Map.cs @@ -0,0 +1,156 @@ +using System.Collections.Generic; +using System.Threading; +using Preparation.Interface; +using Preparation.Utility; +using Preparation.GameData; +using System; + +namespace GameClass.GameObj +{ + public partial class Map : IMap + { + + private readonly Dictionary birthPointList; // 出生点列表 + public Dictionary BirthPointList => birthPointList; + + private Dictionary> gameObjDict; + public Dictionary> GameObjDict => gameObjDict; + private Dictionary gameObjLockDict; + public Dictionary GameObjLockDict => gameObjLockDict; + + public readonly uint[,] ProtoGameMap; + public PlaceType GetPlaceType(GameObj obj) + { + try + { + uint type = ProtoGameMap[obj.Position.x / GameData.numOfPosGridPerCell, obj.Position.y / GameData.numOfPosGridPerCell]; + if (type == 2) + return PlaceType.Grass1; + else if (type == 3) + return PlaceType.Grass2; + else if (type == 4) + return PlaceType.Grass3; + else + return PlaceType.Land; // 其他情况均返回land + } + catch + { + return PlaceType.Land; + } + } + + public PlaceType GetPlaceType(XY pos) + { + try + { + switch (ProtoGameMap[pos.x / GameData.numOfPosGridPerCell, pos.y / GameData.numOfPosGridPerCell]) + { + case 2: + return PlaceType.Grass1; + case 3: + return PlaceType.Grass2; + case 4: + return PlaceType.Grass3; + default: + return PlaceType.Land; + } + } + catch + { + return PlaceType.Land; + } + } + + public bool IsOutOfBound(IGameObj obj) + { + return obj.Position.x >= GameData.lengthOfMap - obj.Radius || obj.Position.x <= obj.Radius || obj.Position.y >= GameData.lengthOfMap - obj.Radius || obj.Position.y <= obj.Radius; + } + public IOutOfBound GetOutOfBound(XY pos) + { + return new OutOfBoundBlock(pos); + } + + public Character? FindPlayer(long playerID) + { + Character? player = null; + gameObjLockDict[GameObjIdx.Player].EnterReadLock(); + try + { + foreach (Character person in gameObjDict[GameObjIdx.Player]) + { + if (playerID == person.ID) + { + player = person; + break; + } + } + } + finally + { + gameObjLockDict[GameObjIdx.Player].ExitReadLock(); + } + return player; + } + public Map(uint[,] mapResource) + { + gameObjDict = new Dictionary>(); + gameObjLockDict = new Dictionary(); + foreach (GameObjIdx idx in Enum.GetValues(typeof(GameObjIdx))) + { + if (idx != GameObjIdx.None) + { + gameObjDict.Add(idx, new List()); + gameObjLockDict.Add(idx, new ReaderWriterLockSlim()); + } + } + + ProtoGameMap = new uint[mapResource.GetLength(0), mapResource.GetLength(1)]; + Array.Copy(mapResource, ProtoGameMap, mapResource.Length); + + birthPointList = new Dictionary(GameData.numOfBirthPoint); + + // 将出生点插入 + for (int i = 0; i < GameData.rows; ++i) + { + for (int j = 0; j < GameData.cols; ++j) + { + switch (mapResource[i, j]) + { + case (uint)MapInfoObjType.Wall: + { + GameObjLockDict[GameObjIdx.Map].EnterWriteLock(); + try + { + GameObjDict[GameObjIdx.Map].Add(new Wall(GameData.GetCellCenterPos(i, j))); + } + finally + { + GameObjLockDict[GameObjIdx.Map].ExitWriteLock(); + } + break; + } + case (uint)MapInfoObjType.BirthPoint1: + case (uint)MapInfoObjType.BirthPoint2: + case (uint)MapInfoObjType.BirthPoint3: + case (uint)MapInfoObjType.BirthPoint4: + case (uint)MapInfoObjType.BirthPoint5: + { + BirthPoint newBirthPoint = new BirthPoint(GameData.GetCellCenterPos(i, j)); + birthPointList.Add(MapInfo.BirthPointEnumToIdx((MapInfoObjType)mapResource[i, j]), newBirthPoint); + GameObjLockDict[GameObjIdx.Map].EnterWriteLock(); + try + { + GameObjDict[GameObjIdx.Map].Add(newBirthPoint); + } + finally + { + GameObjLockDict[GameObjIdx.Map].ExitWriteLock(); + } + break; + } + } + } + } + } + } +} diff --git a/logic/GameClass/GameObj/Map/MapGameTimer.cs b/logic/GameClass/GameObj/Map/MapGameTimer.cs new file mode 100644 index 0000000..f03500a --- /dev/null +++ b/logic/GameClass/GameObj/Map/MapGameTimer.cs @@ -0,0 +1,32 @@ +using System.Threading; +using Preparation.Interface; + +namespace GameClass.GameObj +{ + public partial class Map + { + // xfgg说:爱因斯坦说,每个坐标系都有与之绑定的时钟,(x, y, z, ict) 构成四维时空坐标,在洛伦兹变换下满足矢量性(狗头) + private readonly GameTimer timer = new(); + public ITimer Timer => timer; + public class GameTimer : ITimer + { + private bool isGaming = false; + public bool IsGaming => isGaming; + + readonly object isGamingLock = new(); + + public bool StartGame(int timeInMilliseconds) + { + lock (isGamingLock) + { + if (isGaming) + return false; + isGaming = true; + } + Thread.Sleep(timeInMilliseconds); + isGaming = false; + return true; + } + } + } +} diff --git a/logic/GameClass/GameObj/Map/MapInfo.cs b/logic/GameClass/GameObj/Map/MapInfo.cs new file mode 100644 index 0000000..20d0c66 --- /dev/null +++ b/logic/GameClass/GameObj/Map/MapInfo.cs @@ -0,0 +1,77 @@ +using Preparation.Utility; +using Preparation.GameData; + +namespace GameClass.GameObj +{ + public static class MapInfo + { + /// + /// 检测物体在哪;不能返回invisible。 + /// + /// + /// + + public static uint BirthPointEnumToIdx(MapInfoObjType birthPointEnum) + { + uint tmp = (uint)birthPointEnum; + // if (tmp < 5 || tmp > 12) throw new Exception("The parameter of BirthPointEnumToIdx is not a valid birth point enumeration value!"); + return tmp - 5; + } + /// + /// 50*50 + /// 1:Wall; 2:Grass1; 3:Grass2 ; 4:Grass3 ; 5~12:BirthPoint ; 13:GemWell + /// + public static uint[,] defaultMap = new uint[,] { + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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ameClass/GameObj/Map/Wall.cs new file mode 100644 index 0000000..b91e537 --- /dev/null +++ b/logic/GameClass/GameObj/Map/Wall.cs @@ -0,0 +1,19 @@ +using Preparation.Utility; +using Preparation.GameData; + +namespace GameClass.GameObj +{ + /// + /// 墙体 + /// + public class Wall : GameObj + { + public Wall(XY initPos) : + base(initPos, GameData.numOfPosGridPerCell / 2, PlaceType.Land, GameObjType.Wall) + { + this.CanMove = false; + } + public override bool IsRigid => true; + public override ShapeType Shape => ShapeType.Square; + } +} diff --git a/logic/GameClass/GameObj/OutOfBoundBlock.cs b/logic/GameClass/GameObj/OutOfBoundBlock.cs new file mode 100644 index 0000000..9ac2a84 --- /dev/null +++ b/logic/GameClass/GameObj/OutOfBoundBlock.cs @@ -0,0 +1,20 @@ +using Preparation.Interface; +using Preparation.Utility; + +namespace GameClass.GameObj +{ + /// + /// 逻辑墙 + /// + public class OutOfBoundBlock : GameObj, IOutOfBound + { + public OutOfBoundBlock(XY initPos) : + base(initPos, int.MaxValue, PlaceType.Land, GameObjType.OutOfBoundBlock) + { + this.CanMove = false; + } + + public override bool IsRigid => true; + public override ShapeType Shape => ShapeType.Square; + } +} diff --git a/logic/GameEngine/MoveEngine.cs b/logic/GameEngine/MoveEngine.cs index c7e07d3..f596c4e 100644 --- a/logic/GameEngine/MoveEngine.cs +++ b/logic/GameEngine/MoveEngine.cs @@ -64,7 +64,7 @@ namespace GameEngine ( () => { - if (!obj.IsAvailable&&gameTimer.IsGaming) //不能动就直接return,后面都是能动的情况 + if (!obj.IsAvailable && gameTimer.IsGaming) //不能动就直接return,后面都是能动的情况 return; lock (obj.MoveLock) obj.IsMoving = true; diff --git a/logic/Gaming/Gaming.csproj b/logic/Gaming/Gaming.csproj new file mode 100644 index 0000000..5d635c7 --- /dev/null +++ b/logic/Gaming/Gaming.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + + + + + + + + + diff --git a/logic/Preparation/GameData/GameData.cs b/logic/Preparation/GameData/GameData.cs index 0903b6d..0be6c40 100644 --- a/logic/Preparation/GameData/GameData.cs +++ b/logic/Preparation/GameData/GameData.cs @@ -33,6 +33,8 @@ namespace Preparation.GameData { return PosGridToCellX(pos1) == PosGridToCellX(pos2) && PosGridToCellY(pos1) == PosGridToCellY(pos2); } + + public static int numOfBirthPoint = 5; #endregion #region 角色相关 /// diff --git a/logic/Preparation/Interface/IOutOfBound.cs b/logic/Preparation/Interface/IOutOfBound.cs new file mode 100644 index 0000000..28219ce --- /dev/null +++ b/logic/Preparation/Interface/IOutOfBound.cs @@ -0,0 +1,8 @@ + +namespace Preparation.Interface +{ + public interface IOutOfBound : IGameObj + { + // 接口不定义内容,为引擎使用 + } +} diff --git a/logic/Preparation/Preparation.csproj b/logic/Preparation/Preparation.csproj new file mode 100644 index 0000000..4dd34fc --- /dev/null +++ b/logic/Preparation/Preparation.csproj @@ -0,0 +1,11 @@ + + + + Library + net6.0 + + + enable + + + diff --git a/logic/Preparation/Utility/EnumType.cs b/logic/Preparation/Utility/EnumType.cs index b21ff5e..35c481c 100644 --- a/logic/Preparation/Utility/EnumType.cs +++ b/logic/Preparation/Utility/EnumType.cs @@ -35,8 +35,6 @@ namespace Preparation.Utility Grass1 = 3, Grass2 = 4, Grass3 = 5, - Grass4 = 6, - Grass5 = 7, } public enum BulletType // 子弹类型 { @@ -93,3 +91,16 @@ namespace Preparation.Utility PickedProp = 5 } } +public enum MapInfoObjType +{ + Null = 0, + Wall = 1, + Grass1 = 2, + Grass2 = 3, + Grass3 = 4, + BirthPoint1 = 5, + BirthPoint2 = 6, + BirthPoint3 = 7, + BirthPoint4 = 8, + BirthPoint5 = 9, +} \ No newline at end of file diff --git a/logic/logic.sln b/logic/logic.sln index 51f61b6..a233cfa 100644 --- a/logic/logic.sln +++ b/logic/logic.sln @@ -5,6 +5,16 @@ VisualStudioVersion = 17.0.32014.148 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "Server\Server.csproj", "{D033B809-2FB7-4340-B8B4-DDA30D6CA6FF}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GameClass", "GameClass\GameClass.csproj", "{39D838F6-2B84-49E1-9CAF-1DFF22960B5D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GameEngine", "GameEngine\GameEngine.csproj", "{91448D70-61C3-499F-9B27-979E16DC9E64}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gaming", "Gaming\Gaming.csproj", "{BE9E3584-93C0-4E0F-8DAC-967CF4792709}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MapGenerator", "MapGenerator\MapGenerator.csproj", "{9BC673F1-14B1-4203-944D-474BD0F64EDC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Preparation", "Preparation\Preparation.csproj", "{E3DC4A37-8A83-40CC-AE47-68E70064C9DB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +25,26 @@ Global {D033B809-2FB7-4340-B8B4-DDA30D6CA6FF}.Debug|Any CPU.Build.0 = Debug|Any CPU {D033B809-2FB7-4340-B8B4-DDA30D6CA6FF}.Release|Any CPU.ActiveCfg = Release|Any CPU {D033B809-2FB7-4340-B8B4-DDA30D6CA6FF}.Release|Any CPU.Build.0 = Release|Any CPU + {39D838F6-2B84-49E1-9CAF-1DFF22960B5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {39D838F6-2B84-49E1-9CAF-1DFF22960B5D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {39D838F6-2B84-49E1-9CAF-1DFF22960B5D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {39D838F6-2B84-49E1-9CAF-1DFF22960B5D}.Release|Any CPU.Build.0 = Release|Any CPU + {91448D70-61C3-499F-9B27-979E16DC9E64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91448D70-61C3-499F-9B27-979E16DC9E64}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91448D70-61C3-499F-9B27-979E16DC9E64}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91448D70-61C3-499F-9B27-979E16DC9E64}.Release|Any CPU.Build.0 = Release|Any CPU + {BE9E3584-93C0-4E0F-8DAC-967CF4792709}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BE9E3584-93C0-4E0F-8DAC-967CF4792709}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BE9E3584-93C0-4E0F-8DAC-967CF4792709}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BE9E3584-93C0-4E0F-8DAC-967CF4792709}.Release|Any CPU.Build.0 = Release|Any CPU + {9BC673F1-14B1-4203-944D-474BD0F64EDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9BC673F1-14B1-4203-944D-474BD0F64EDC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9BC673F1-14B1-4203-944D-474BD0F64EDC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9BC673F1-14B1-4203-944D-474BD0F64EDC}.Release|Any CPU.Build.0 = Release|Any CPU + {E3DC4A37-8A83-40CC-AE47-68E70064C9DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E3DC4A37-8A83-40CC-AE47-68E70064C9DB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E3DC4A37-8A83-40CC-AE47-68E70064C9DB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E3DC4A37-8A83-40CC-AE47-68E70064C9DB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE