Browse Source

Merge pull request #507 from shangfengh/new

refactor:  use abstract instead of virtual
tags/v0.1.0
Changli Tang GitHub 2 years ago
parent
commit
897f3a6c65
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 70 additions and 79 deletions
  1. +2
    -2
      logic/GameClass/GameObj/Bullet/BombedBullet.cs
  2. +1
    -1
      logic/GameClass/GameObj/Bullet/Bullet.cs
  3. +1
    -1
      logic/GameClass/GameObj/Character/Character.Skill.cs
  4. +14
    -7
      logic/GameClass/GameObj/Character/Character.cs
  5. +5
    -5
      logic/GameClass/GameObj/GameObj.cs
  6. +19
    -0
      logic/GameClass/GameObj/Immovable.cs
  7. +1
    -2
      logic/GameClass/GameObj/Map/Chest.cs
  8. +1
    -2
      logic/GameClass/GameObj/Map/Door.cs
  9. +1
    -2
      logic/GameClass/GameObj/Map/Doorway.cs
  10. +1
    -2
      logic/GameClass/GameObj/Map/EmergencyExit.cs
  11. +1
    -2
      logic/GameClass/GameObj/Map/Generator.cs
  12. +1
    -2
      logic/GameClass/GameObj/Map/Wall.cs
  13. +1
    -2
      logic/GameClass/GameObj/Map/Window.cs
  14. +6
    -5
      logic/GameClass/GameObj/Moveable.cs
  15. +1
    -2
      logic/GameClass/GameObj/OutOfBoundBlock.cs
  16. +1
    -1
      logic/GameClass/GameObj/PickedProp.cs
  17. +1
    -1
      logic/GameClass/GameObj/Prop.cs
  18. +0
    -22
      logic/GameClass/GameObj/Tile.cs
  19. +3
    -3
      logic/Gaming/ActionManager.cs
  20. +4
    -10
      logic/Gaming/AttackManager.cs
  21. +1
    -1
      logic/Gaming/CharacterManager .cs
  22. +1
    -1
      logic/Gaming/Game.cs
  23. +1
    -1
      logic/Gaming/PropManager.cs
  24. +1
    -1
      logic/Preparation/Interface/IGameObj.cs
  25. +1
    -0
      logic/Preparation/Interface/IMoveable.cs
  26. +0
    -1
      logic/Server/CopyInfo.cs

+ 2
- 2
logic/GameClass/GameObj/Bullet/BombedBullet.cs View File

@@ -3,7 +3,7 @@
namespace GameClass.GameObj
{
// 为方便界面组做子弹爆炸特效,现引入“爆炸中的子弹”,在每帧发送给界面组
public sealed class BombedBullet : GameObj
public sealed class BombedBullet : Immovable
{
public override ShapeType Shape => ShapeType.Circle;
public override bool IsRigid => false;
@@ -15,7 +15,7 @@ namespace GameClass.GameObj
{
this.bulletHasBombed = bullet;
this.MappingID = bullet.ID;
this.FacingDirection = bullet.FacingDirection;
this.facingDirection = bullet.FacingDirection;
}
}
}

+ 1
- 1
logic/GameClass/GameObj/Bullet/Bullet.cs View File

@@ -44,7 +44,7 @@ namespace GameClass.GameObj
public Bullet(Character player, int radius, XY Position) :
base(Position, radius, GameObjType.Bullet)
{
this.CanMove = true;
this.canMove = true;
this.moveSpeed = this.Speed;
this.hasSpear = player.TryUseSpear();
this.Parent = player;


+ 1
- 1
logic/GameClass/GameObj/Character/Character.Skill.cs View File

@@ -57,7 +57,7 @@ namespace GameClass.GameObj
protected Character(XY initPos, int initRadius, CharacterType characterType) :
base(initPos, initRadius, GameObjType.Character)
{
this.CanMove = true;
this.canMove = true;
this.score = 0;
this.buffManager = new BuffManager();
this.occupation = OccupationFactory.FindIOccupation(characterType);


+ 14
- 7
logic/GameClass/GameObj/Character/Character.cs View File

@@ -2,9 +2,6 @@
using Preparation.Utility;
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Threading;

namespace GameClass.GameObj
{
@@ -58,10 +55,20 @@ namespace GameClass.GameObj
/// 进行一次攻击
/// </summary>
/// <returns>攻击操作发出的子弹</returns>
public Bullet? Attack(XY pos)
public Bullet? Attack(double angle)
{
if (TrySubBulletNum())
return BulletFactory.GetBullet(this, pos);
{
XY res = Position + new XY // 子弹紧贴人物生成。
(
(int)(Math.Abs((Radius + BulletFactory.BulletRadius(BulletOfPlayer)) * Math.Cos(angle))) * ((Math.Cos(angle) > 0) ? 1 : -1),
(int)(Math.Abs((Radius + BulletFactory.BulletRadius(BulletOfPlayer)) * Math.Sin(angle))) * ((Math.Sin(angle) > 0) ? 1 : -1)
);
Bullet? bullet = BulletFactory.GetBullet(this, res);
if (bullet == null) return null;
facingDirection = new(angle, bullet.BulletAttackRange);
return bullet;
}
else
return null;
}
@@ -362,9 +369,9 @@ namespace GameClass.GameObj
lock (gameObjLock)
{
playerState = playerStateType;
CanMove = false;
canMove = false;
IsResetting = true;
Position = GameData.PosWhoDie;
position = GameData.PosWhoDie;
}
}
#endregion


+ 5
- 5
logic/GameClass/GameObj/GameObj.cs View File

@@ -24,18 +24,18 @@ namespace GameClass.GameObj
public long ID { get; }

protected XY position;
public virtual XY Position { get; set; }
public abstract XY Position { get; }

protected XY facingDirection = new(1, 0);
public virtual XY FacingDirection { get; set; }
public abstract XY FacingDirection { get; }

protected bool canMove;
public abstract bool CanMove { get; }

public abstract bool IsRigid { get; }

public abstract ShapeType Shape { get; }

protected bool canMove;
public virtual bool CanMove { get; set; }

public int Radius { get; }

public virtual bool IgnoreCollideExecutor(IGameObj targetObj) => false;


+ 19
- 0
logic/GameClass/GameObj/Immovable.cs View File

@@ -0,0 +1,19 @@
using Preparation.Interface;
using Preparation.Utility;

namespace GameClass.GameObj
{
public abstract class Immovable : GameObj
{

public override XY Position => position;

public override XY FacingDirection => facingDirection;

public override bool CanMove => false;

public Immovable(XY initPos, int initRadius, GameObjType initType) : base(initPos, initRadius, initType)
{
}
}
}

+ 1
- 2
logic/GameClass/GameObj/Map/Chest.cs View File

@@ -5,12 +5,11 @@ namespace GameClass.GameObj
/// <summary>
/// 箱子
/// </summary>
public class Chest : Tile
public class Chest : Immovable
{
public Chest(XY initPos) :
base(initPos, GameData.numOfPosGridPerCell / 2, GameObjType.Chest)
{
this.CanMove = false;
}
public override bool IsRigid => true;
public override ShapeType Shape => ShapeType.Square;


+ 1
- 2
logic/GameClass/GameObj/Map/Door.cs View File

@@ -6,7 +6,7 @@ namespace GameClass.GameObj
/// <summary>
/// 门
/// </summary>
public class Door : Tile
public class Door : Immovable
{
public Door(XY initPos, PlaceType placeType) :
base(initPos, GameData.numOfPosGridPerCell / 2, GameObjType.Door)
@@ -24,7 +24,6 @@ namespace GameClass.GameObj
doorNum = 6;
break;
}
this.CanMove = false;
}

private readonly int doorNum;


+ 1
- 2
logic/GameClass/GameObj/Map/Doorway.cs View File

@@ -6,12 +6,11 @@ namespace GameClass.GameObj
/// <summary>
/// 出口
/// </summary>
public class Doorway : Tile
public class Doorway : Immovable
{
public Doorway(XY initPos) :
base(initPos, GameData.numOfPosGridPerCell / 2, GameObjType.Doorway)
{
this.CanMove = false;
}
public override bool IsRigid => true;
public override ShapeType Shape => ShapeType.Square;


+ 1
- 2
logic/GameClass/GameObj/Map/EmergencyExit.cs View File

@@ -6,12 +6,11 @@ namespace GameClass.GameObj
/// <summary>
/// 紧急出口
/// </summary>
public class EmergencyExit : Tile
public class EmergencyExit : Immovable
{
public EmergencyExit(XY initPos) :
base(initPos, GameData.numOfPosGridPerCell / 2, GameObjType.EmergencyExit)
{
this.CanMove = false;
}
public override bool IsRigid => true;
public override ShapeType Shape => ShapeType.Square;


+ 1
- 2
logic/GameClass/GameObj/Map/Generator.cs View File

@@ -5,12 +5,11 @@ namespace GameClass.GameObj
/// <summary>
/// 发电机
/// </summary>
public class Generator : Tile
public class Generator : Immovable
{
public Generator(XY initPos) :
base(initPos, GameData.numOfPosGridPerCell / 2, GameObjType.Generator)
{
this.CanMove = false;
}
public override bool IsRigid => true;
public override ShapeType Shape => ShapeType.Square;


+ 1
- 2
logic/GameClass/GameObj/Map/Wall.cs View File

@@ -5,12 +5,11 @@ namespace GameClass.GameObj
/// <summary>
/// 墙体
/// </summary>
public class Wall : Tile
public class Wall : Immovable
{
public Wall(XY initPos) :
base(initPos, GameData.numOfPosGridPerCell / 2, GameObjType.Wall)
{
this.CanMove = false;
}
public override bool IsRigid => true;
public override ShapeType Shape => ShapeType.Square;


+ 1
- 2
logic/GameClass/GameObj/Map/Window.cs View File

@@ -6,12 +6,11 @@ namespace GameClass.GameObj
/// <summary>
/// 窗
/// </summary>
public class Window : Tile
public class Window : Immovable
{
public Window(XY initPos) :
base(initPos, GameData.numOfPosGridPerCell / 2, GameObjType.Window)
{
this.CanMove = false;
}
public override bool IsRigid => true;
public override ShapeType Shape => ShapeType.Square;


+ 6
- 5
logic/GameClass/GameObj/Moveable.cs View File

@@ -73,12 +73,13 @@ namespace GameClass.GameObj
lock (moveReaderWriterLock)
return canMove;
}
set
}

public void ReSetCanMove(bool value)
{
lock (moveReaderWriterLock)
{
lock (moveReaderWriterLock)
{
canMove = value;
}
canMove = value;
}
}



+ 1
- 2
logic/GameClass/GameObj/OutOfBoundBlock.cs View File

@@ -6,12 +6,11 @@ namespace GameClass.GameObj
/// <summary>
/// 逻辑墙
/// </summary>
public class OutOfBoundBlock : GameObj, IOutOfBound
public class OutOfBoundBlock : Immovable, IOutOfBound
{
public OutOfBoundBlock(XY initPos) :
base(initPos, int.MaxValue, GameObjType.OutOfBoundBlock)
{
this.CanMove = false;
}

public override bool IsRigid => true;


+ 1
- 1
logic/GameClass/GameObj/PickedProp.cs View File

@@ -3,7 +3,7 @@ using System;
namespace GameClass.GameObj
{
// 为方便界面组做道具拾起特效,现引入“被捡起的道具”,在每帧发送给界面组
public class PickedProp : GameObj
public class PickedProp : Immovable
{
public override ShapeType Shape => ShapeType.Circle;
public override bool IsRigid => false;


+ 1
- 1
logic/GameClass/GameObj/Prop.cs View File

@@ -22,7 +22,7 @@ namespace GameClass.GameObj
public Prop(XY initPos, int radius = GameData.PropRadius) :
base(initPos, radius, GameObjType.Prop)
{
this.CanMove = false;
this.canMove = false;
this.moveSpeed = GameData.PropMoveSpeed;
}
}


+ 0
- 22
logic/GameClass/GameObj/Tile.cs View File

@@ -1,22 +0,0 @@
using Preparation.Interface;
using Preparation.Utility;

namespace GameClass.GameObj
{
/// <summary>
/// 一切游戏元素的总基类,与THUAI4不同,继承IMoveable接口(出于一切物体其实都是可运动的指导思想)——LHR
/// </summary>
public abstract class Tile : GameObj
{

public override XY Position => position;

public override XY FacingDirection => facingDirection;

public override bool CanMove => false;

public Tile(XY initPos, int initRadius, GameObjType initType) : base(initPos, initRadius, initType)
{
}
}
}

+ 3
- 3
logic/Gaming/ActionManager.cs View File

@@ -267,7 +267,7 @@ namespace Gaming
{
Prop prop = chestToOpen.PropInChest[i];
chestToOpen.PropInChest[i] = new NullProp();
prop.Position = player.Position;
prop.ReSetPos(player.Position);
gameMap.Add(prop);
}
}
@@ -323,7 +323,7 @@ namespace Gaming
return;
}

player.Position = windowToPlayer + windowForClimb.Position;
player.ReSetPos(windowToPlayer + windowForClimb.Position);
player.MoveSpeed = player.SpeedOfClimbingThroughWindows;

moveEngine.MoveObj(player, (int)(windowToPlayer.Length() * 3.0 * 1000 / player.MoveSpeed), (-1 * windowToPlayer).Angle());
@@ -339,7 +339,7 @@ namespace Gaming
)
.Start();
XY PosJumpOff = windowForClimb.Position - 2 * windowToPlayer;
player.Position = PosJumpOff;
player.ReSetPos(PosJumpOff);
player.MoveSpeed = player.ReCalculateBuff(BuffType.AddSpeed, player.OrgMoveSpeed, GameData.MaxSpeed, GameData.MinSpeed);
windowForClimb.WhoIsClimbing = null;
// gameMap.Remove(addWall);


+ 4
- 10
logic/Gaming/AttackManager.cs View File

@@ -33,7 +33,7 @@ namespace Gaming
Debugger.Output(obj, " end move at " + obj.Position.ToString() + " At time: " + Environment.TickCount64);
if (obj.CanMove && ((Bullet)obj).TypeOfBullet != BulletType.JumpyDumpty)
BulletBomb((Bullet)obj, null);
obj.CanMove = false;
obj.ReSetCanMove(false);
}
);
this.characterManager = characterManager;
@@ -66,7 +66,7 @@ namespace Gaming

public bool TryRemoveBullet(Bullet bullet)
{
bullet.CanMove = false;
bullet.ReSetCanMove(false);
if (gameMap.Remove(bullet))
{
if (bullet.BulletBombRange > 0)
@@ -172,20 +172,14 @@ namespace Gaming
Debugger.Output(player, player.CharacterType.ToString() + "Attack in " + player.BulletOfPlayer.ToString());

Debugger.Output(player, player.Position.ToString() + " " + player.Radius.ToString() + " " + BulletFactory.BulletRadius(player.BulletOfPlayer).ToString());
XY res = player.Position + new XY // 子弹紧贴人物生成。
(
(int)(Math.Abs((player.Radius + BulletFactory.BulletRadius(player.BulletOfPlayer)) * Math.Cos(angle))) * ((Math.Cos(angle) > 0) ? 1 : -1),
(int)(Math.Abs((player.Radius + BulletFactory.BulletRadius(player.BulletOfPlayer)) * Math.Sin(angle))) * ((Math.Sin(angle) > 0) ? 1 : -1)
);

Bullet? bullet = player.Attack(res);
Bullet? bullet = player.Attack(angle);

if (bullet != null)
{
player.FacingDirection = new(angle, bullet.BulletAttackRange);
Debugger.Output(bullet, "Attack in " + bullet.Position.ToString());
bullet.AP += player.TryAddAp() ? GameData.ApPropAdd : 0;
bullet.CanMove = true;
bullet.ReSetCanMove(true);
gameMap.Add(bullet);
moveEngine.MoveObj(bullet, (int)((bullet.BulletAttackRange - player.Radius - BulletFactory.BulletRadius(player.BulletOfPlayer)) * 1000 / bullet.MoveSpeed), angle); // 这里时间参数除出来的单位要是ms
if (bullet.CastTime > 0)


+ 1
- 1
logic/Gaming/CharacterManager .cs View File

@@ -407,7 +407,7 @@ namespace Gaming
Prop? prop = player.UseProp(i);
if (prop != null)
{
prop.Position = player.Position;
prop.ReSetPos(player.Position);
gameMap.Add(prop);
}
}


+ 1
- 1
logic/Gaming/Game.cs View File

@@ -316,7 +316,7 @@ namespace Gaming
{
foreach (Character player in gameMap.GameObjDict[GameObjType.Character])
{
player.CanMove = false;
player.ReSetCanMove(false);
}
}
gameMap.GameObjDict[keyValuePair.Key].Clear();


+ 1
- 1
logic/Gaming/PropManager.cs View File

@@ -124,7 +124,7 @@ namespace Gaming
if (prop.GetPropType() == PropType.Null)
return;

prop.Position = player.Position;
prop.ReSetPos(player.Position);
gameMap.Add(prop);
}



+ 1
- 1
logic/Preparation/Interface/IGameObj.cs View File

@@ -10,7 +10,7 @@ namespace Preparation.Interface
public XY FacingDirection { get; }
public bool IsRigid { get; }
public ShapeType Shape { get; }
public bool CanMove { get; set; }
public bool CanMove { get; }
public int Radius { get; } // if Square, Radius equals half length of one side
public bool IgnoreCollideExecutor(IGameObj targetObj); // 忽略碰撞,在具体类中实现
}


+ 1
- 0
logic/Preparation/Interface/IMoveable.cs View File

@@ -11,6 +11,7 @@ namespace Preparation.Interface
public bool IsResetting { get; set; } // reviving
public bool IsAvailable { get; }
public long MovingSetPos(XY moveVec);
public void ReSetCanMove(bool value);
public bool WillCollideWith(IGameObj? targetObj, XY nextPos) // 检查下一位置是否会和目标物碰撞
{
if (targetObj == null)


+ 0
- 1
logic/Server/CopyInfo.cs View File

@@ -268,7 +268,6 @@ namespace Server
Y = chest.Position.y
}
};
Debugger.Output(chest, chest.OpenStartTime.ToString());
int progress = (chest.WhoOpen != null) ? ((time - chest.OpenStartTime) * chest.WhoOpen.SpeedOfOpenChest) : 0;
msg.ChestMessage.Progress = (progress > GameData.degreeOfOpenedChest) ? GameData.degreeOfOpenedChest : progress;
return msg;


Loading…
Cancel
Save